[06295a9] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[1493811] | 29 | /** @addtogroup ethip
|
---|
[06295a9] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * @brief
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #ifndef ETHIP_H_
|
---|
| 38 | #define ETHIP_H_
|
---|
| 39 |
|
---|
[1493811] | 40 | #include <adt/list.h>
|
---|
| 41 | #include <async.h>
|
---|
| 42 | #include <inet/iplink_srv.h>
|
---|
| 43 | #include <loc.h>
|
---|
| 44 | #include <sys/types.h>
|
---|
| 45 |
|
---|
[3d016ac] | 46 | #define MAC48_BROADCAST 0xffffffffffff
|
---|
| 47 |
|
---|
[56792a2] | 48 | typedef struct {
|
---|
| 49 | link_t addr_list;
|
---|
| 50 | iplink_srv_addr_t addr;
|
---|
| 51 | } ethip_link_addr_t;
|
---|
| 52 |
|
---|
| 53 | /** IEEE MAC-48 identifier */
|
---|
| 54 | typedef struct {
|
---|
| 55 | /** MAC Address (in lowest 48 bits) */
|
---|
| 56 | uint64_t addr;
|
---|
| 57 | } mac48_addr_t;
|
---|
| 58 |
|
---|
[06295a9] | 59 | typedef struct ethip_nic {
|
---|
| 60 | link_t nic_list;
|
---|
| 61 | service_id_t svc_id;
|
---|
| 62 | char *svc_name;
|
---|
| 63 | async_sess_t *sess;
|
---|
| 64 |
|
---|
| 65 | iplink_srv_t iplink;
|
---|
[bc38578] | 66 | service_id_t iplink_sid;
|
---|
[962f03b] | 67 |
|
---|
[56792a2] | 68 | /** MAC address */
|
---|
| 69 | mac48_addr_t mac_addr;
|
---|
[962f03b] | 70 | /** List of IP addresses configured on this link */
|
---|
| 71 | list_t addr_list; /* of ethip_link_addr_t */
|
---|
[06295a9] | 72 | } ethip_nic_t;
|
---|
| 73 |
|
---|
[1493811] | 74 | /** Ethernet frame */
|
---|
| 75 | typedef struct {
|
---|
| 76 | /** Destination Address */
|
---|
| 77 | mac48_addr_t dest;
|
---|
| 78 | /** Source Address */
|
---|
| 79 | mac48_addr_t src;
|
---|
| 80 | /** Ethertype or Length */
|
---|
| 81 | uint16_t etype_len;
|
---|
| 82 | /** Payload */
|
---|
| 83 | void *data;
|
---|
| 84 | /** Payload size */
|
---|
| 85 | size_t size;
|
---|
| 86 | } eth_frame_t;
|
---|
| 87 |
|
---|
[87e5658c] | 88 | /** ARP opcode */
|
---|
| 89 | typedef enum {
|
---|
| 90 | /** Request */
|
---|
| 91 | aop_request,
|
---|
| 92 | /** Reply */
|
---|
| 93 | aop_reply
|
---|
| 94 | } arp_opcode_t;
|
---|
| 95 |
|
---|
| 96 | /** ARP packet (for 48-bit MAC addresses and IPv4)
|
---|
| 97 | *
|
---|
| 98 | * Internal representation
|
---|
| 99 | */
|
---|
| 100 | typedef struct {
|
---|
| 101 | /** Opcode */
|
---|
| 102 | arp_opcode_t opcode;
|
---|
| 103 | /** Sender hardware address */
|
---|
| 104 | mac48_addr_t sender_hw_addr;
|
---|
| 105 | /** Sender protocol address */
|
---|
| 106 | iplink_srv_addr_t sender_proto_addr;
|
---|
| 107 | /** Target hardware address */
|
---|
| 108 | mac48_addr_t target_hw_addr;
|
---|
| 109 | /** Target protocol address */
|
---|
| 110 | iplink_srv_addr_t target_proto_addr;
|
---|
| 111 | } arp_eth_packet_t;
|
---|
| 112 |
|
---|
[f9d3dd4] | 113 | /** Address translation table element */
|
---|
| 114 | typedef struct {
|
---|
| 115 | link_t atrans_list;
|
---|
| 116 | iplink_srv_addr_t ip_addr;
|
---|
| 117 | mac48_addr_t mac_addr;
|
---|
| 118 | } ethip_atrans_t;
|
---|
| 119 |
|
---|
[06295a9] | 120 | extern int ethip_iplink_init(ethip_nic_t *);
|
---|
[1493811] | 121 | extern int ethip_received(iplink_srv_t *, void *, size_t);
|
---|
| 122 |
|
---|
[06295a9] | 123 | #endif
|
---|
| 124 |
|
---|
| 125 | /** @}
|
---|
| 126 | */
|
---|