| [21580dd] | 1 | /*
|
|---|
| 2 | * Copyright (c) 2009 Lukas Mejdrech
|
|---|
| 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 |
|
|---|
| 29 | /** @addtogroup eth
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | /** @file
|
|---|
| [6067284] | 34 | * Ethernet module.
|
|---|
| [21580dd] | 35 | */
|
|---|
| 36 |
|
|---|
| [6067284] | 37 | #ifndef NET_ETH_H_
|
|---|
| 38 | #define NET_ETH_H_
|
|---|
| [21580dd] | 39 |
|
|---|
| 40 | #include <fibril_synch.h>
|
|---|
| 41 | #include <ipc/services.h>
|
|---|
| 42 |
|
|---|
| [e526f08] | 43 | #include <net/device.h>
|
|---|
| [849ed54] | 44 | #include <adt/measured_strings.h>
|
|---|
| [21580dd] | 45 |
|
|---|
| [fe8dfa6] | 46 | /** Ethernet address length. */
|
|---|
| 47 | #define ETH_ADDR 6
|
|---|
| 48 |
|
|---|
| 49 | /** Ethernet header preamble value. */
|
|---|
| 50 | #define ETH_PREAMBLE 0x55
|
|---|
| 51 |
|
|---|
| 52 | /** Ethernet header start of frame value. */
|
|---|
| 53 | #define ETH_SFD 0xD5
|
|---|
| 54 |
|
|---|
| 55 | /** IEEE 802.2 unordered information control field. */
|
|---|
| 56 | #define IEEE_8023_2_UI 0x03
|
|---|
| 57 |
|
|---|
| 58 | /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions.
|
|---|
| 59 | * @see eth_header_snap
|
|---|
| 60 | */
|
|---|
| 61 | typedef struct eth_header_snap eth_header_snap_t;
|
|---|
| 62 |
|
|---|
| 63 | /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions.
|
|---|
| 64 | * @see eth_header_lsap
|
|---|
| 65 | */
|
|---|
| 66 | typedef struct eth_header_lsap eth_header_lsap_t;
|
|---|
| 67 |
|
|---|
| 68 | /** Type definition of the Ethernet header LSAP extension.
|
|---|
| 69 | * @see eth_ieee_lsap
|
|---|
| 70 | */
|
|---|
| 71 | typedef struct eth_ieee_lsap eth_ieee_lsap_t;
|
|---|
| 72 |
|
|---|
| 73 | /** Type definition of the Ethernet header SNAP extension.
|
|---|
| 74 | * @see eth_snap
|
|---|
| 75 | */
|
|---|
| 76 | typedef struct eth_snap eth_snap_t;
|
|---|
| 77 |
|
|---|
| 78 | /** Type definition of the Ethernet header preamble.
|
|---|
| 79 | * @see preamble
|
|---|
| 80 | */
|
|---|
| 81 | typedef struct eth_preamble eth_preamble_t;
|
|---|
| 82 |
|
|---|
| 83 | /** Type definition of the Ethernet header.
|
|---|
| 84 | * @see eth_header
|
|---|
| 85 | */
|
|---|
| 86 | typedef struct eth_header eth_header_t;
|
|---|
| 87 |
|
|---|
| 88 | /** Ethernet header Link Service Access Point extension. */
|
|---|
| 89 | struct eth_ieee_lsap {
|
|---|
| 90 | /**
|
|---|
| 91 | * Destination Service Access Point identifier.
|
|---|
| 92 | * The possible values are assigned by an IEEE committee.
|
|---|
| 93 | */
|
|---|
| 94 | uint8_t dsap;
|
|---|
| 95 |
|
|---|
| 96 | /**
|
|---|
| 97 | * Source Service Access Point identifier.
|
|---|
| 98 | * The possible values are assigned by an IEEE committee.
|
|---|
| 99 | */
|
|---|
| 100 | uint8_t ssap;
|
|---|
| 101 |
|
|---|
| 102 | /**
|
|---|
| 103 | * Control parameter.
|
|---|
| 104 | * The possible values are assigned by an IEEE committee.
|
|---|
| 105 | */
|
|---|
| 106 | uint8_t ctrl;
|
|---|
| 107 | } __attribute__ ((packed));
|
|---|
| 108 |
|
|---|
| 109 | /** Ethernet header SNAP extension. */
|
|---|
| 110 | struct eth_snap {
|
|---|
| 111 | /** Protocol identifier or organization code. */
|
|---|
| 112 | uint8_t protocol[3];
|
|---|
| 113 |
|
|---|
| 114 | /**
|
|---|
| 115 | * Ethernet protocol identifier in the network byte order (big endian).
|
|---|
| 116 | * @see ethernet_protocols.h
|
|---|
| 117 | */
|
|---|
| 118 | uint16_t ethertype;
|
|---|
| 119 | } __attribute__ ((packed));
|
|---|
| 120 |
|
|---|
| 121 | /** Ethernet header preamble.
|
|---|
| 122 | *
|
|---|
| 123 | * Used for dummy devices.
|
|---|
| 124 | */
|
|---|
| 125 | struct eth_preamble {
|
|---|
| 126 | /**
|
|---|
| 127 | * Controlling preamble used for the frame transmission synchronization.
|
|---|
| 128 | * All should be set to ETH_PREAMBLE.
|
|---|
| 129 | */
|
|---|
| 130 | uint8_t preamble[7];
|
|---|
| 131 |
|
|---|
| 132 | /**
|
|---|
| 133 | * Start of Frame Delimiter used for the frame transmission
|
|---|
| 134 | * synchronization.
|
|---|
| 135 | * Should be set to ETH_SFD.
|
|---|
| 136 | */
|
|---|
| 137 | uint8_t sfd;
|
|---|
| 138 | } __attribute__ ((packed));
|
|---|
| 139 |
|
|---|
| 140 | /** Ethernet header. */
|
|---|
| 141 | struct eth_header {
|
|---|
| 142 | /** Destination host Ethernet address (MAC address). */
|
|---|
| 143 | uint8_t destination_address[ETH_ADDR];
|
|---|
| 144 | /** Source host Ethernet address (MAC address). */
|
|---|
| 145 | uint8_t source_address[ETH_ADDR];
|
|---|
| 146 |
|
|---|
| 147 | /**
|
|---|
| 148 | * Ethernet protocol identifier in the network byte order (big endian).
|
|---|
| 149 | * @see ethernet_protocols.h
|
|---|
| 150 | */
|
|---|
| 151 | uint16_t ethertype;
|
|---|
| 152 | } __attribute__ ((packed));
|
|---|
| 153 |
|
|---|
| 154 | /** Ethernet header IEEE 802.3 + 802.2 extension. */
|
|---|
| 155 | struct eth_header_lsap {
|
|---|
| 156 | /** Ethernet header. */
|
|---|
| 157 | eth_header_t header;
|
|---|
| 158 |
|
|---|
| 159 | /**
|
|---|
| 160 | * LSAP extension.
|
|---|
| 161 | * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being
|
|---|
| 162 | * used.
|
|---|
| 163 | * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet
|
|---|
| 164 | * without any extensions is being used and the frame content starts
|
|---|
| 165 | * rigth after the two fields.
|
|---|
| 166 | */
|
|---|
| 167 | eth_ieee_lsap_t lsap;
|
|---|
| 168 | } __attribute__ ((packed));
|
|---|
| 169 |
|
|---|
| 170 | /** Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. */
|
|---|
| 171 | struct eth_header_snap {
|
|---|
| 172 | /** Ethernet header. */
|
|---|
| 173 | eth_header_t header;
|
|---|
| 174 |
|
|---|
| 175 | /**
|
|---|
| 176 | * LSAP extension.
|
|---|
| 177 | * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being
|
|---|
| 178 | * used.
|
|---|
| 179 | * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet
|
|---|
| 180 | * without any extensions is being used and the frame content starts
|
|---|
| 181 | * rigth after the two fields.
|
|---|
| 182 | */
|
|---|
| 183 | eth_ieee_lsap_t lsap;
|
|---|
| 184 |
|
|---|
| 185 | /** SNAP extension. */
|
|---|
| 186 | eth_snap_t snap;
|
|---|
| 187 | } __attribute__ ((packed));
|
|---|
| 188 |
|
|---|
| 189 | /** Ethernet Frame Check Sequence. */
|
|---|
| 190 | typedef uint32_t eth_fcs_t;
|
|---|
| 191 |
|
|---|
| [21580dd] | 192 | /** Type definition of the Ethernet global data.
|
|---|
| [6067284] | 193 | * @see eth_globals
|
|---|
| [21580dd] | 194 | */
|
|---|
| [6067284] | 195 | typedef struct eth_globals eth_globals_t;
|
|---|
| [21580dd] | 196 |
|
|---|
| 197 | /** Type definition of the Ethernet device specific data.
|
|---|
| [6067284] | 198 | * @see eth_device
|
|---|
| [21580dd] | 199 | */
|
|---|
| [6067284] | 200 | typedef struct eth_device eth_device_t;
|
|---|
| [21580dd] | 201 |
|
|---|
| 202 | /** Type definition of the Ethernet protocol specific data.
|
|---|
| [6067284] | 203 | * @see eth_proto
|
|---|
| [21580dd] | 204 | */
|
|---|
| [6067284] | 205 | typedef struct eth_proto eth_proto_t;
|
|---|
| [21580dd] | 206 |
|
|---|
| 207 | /** Ethernet device map.
|
|---|
| [6067284] | 208 | * Maps devices to the Ethernet device specific data.
|
|---|
| 209 | * @see device.h
|
|---|
| [21580dd] | 210 | */
|
|---|
| [6067284] | 211 | DEVICE_MAP_DECLARE(eth_devices, eth_device_t);
|
|---|
| [21580dd] | 212 |
|
|---|
| 213 | /** Ethernet protocol map.
|
|---|
| [6067284] | 214 | * Maps protocol identifiers to the Ethernet protocol specific data.
|
|---|
| 215 | * @see int_map.h
|
|---|
| [21580dd] | 216 | */
|
|---|
| [6067284] | 217 | INT_MAP_DECLARE(eth_protos, eth_proto_t);
|
|---|
| [21580dd] | 218 |
|
|---|
| [6067284] | 219 | /** Ethernet device specific data. */
|
|---|
| 220 | struct eth_device {
|
|---|
| 221 | /** Device identifier. */
|
|---|
| [aadf01e] | 222 | device_id_t device_id;
|
|---|
| [6067284] | 223 | /** Device driver service. */
|
|---|
| [aadf01e] | 224 | services_t service;
|
|---|
| [6067284] | 225 | /** Driver phone. */
|
|---|
| [aadf01e] | 226 | int phone;
|
|---|
| [6067284] | 227 | /** Maximal transmission unit. */
|
|---|
| [aadf01e] | 228 | size_t mtu;
|
|---|
| [6067284] | 229 |
|
|---|
| 230 | /**
|
|---|
| 231 | * Various device flags.
|
|---|
| 232 | * @see ETH_DUMMY
|
|---|
| 233 | * @see ETH_MODE_MASK
|
|---|
| [21580dd] | 234 | */
|
|---|
| [aadf01e] | 235 | int flags;
|
|---|
| [6067284] | 236 |
|
|---|
| 237 | /** Actual device hardware address. */
|
|---|
| [4eca056] | 238 | measured_string_t *addr;
|
|---|
| [854151c] | 239 |
|
|---|
| [6067284] | 240 | /** Actual device hardware address data. */
|
|---|
| [854151c] | 241 | uint8_t *addr_data;
|
|---|
| [21580dd] | 242 | };
|
|---|
| 243 |
|
|---|
| [6067284] | 244 | /** Ethernet protocol specific data. */
|
|---|
| 245 | struct eth_proto {
|
|---|
| 246 | /** Protocol service. */
|
|---|
| [aadf01e] | 247 | services_t service;
|
|---|
| [6067284] | 248 | /** Protocol identifier. */
|
|---|
| [aadf01e] | 249 | int protocol;
|
|---|
| [6067284] | 250 | /** Protocol module phone. */
|
|---|
| [aadf01e] | 251 | int phone;
|
|---|
| [21580dd] | 252 | };
|
|---|
| 253 |
|
|---|
| [6067284] | 254 | /** Ethernet global data. */
|
|---|
| 255 | struct eth_globals {
|
|---|
| 256 | /** Networking module phone. */
|
|---|
| [aadf01e] | 257 | int net_phone;
|
|---|
| [6067284] | 258 | /** Safety lock for devices. */
|
|---|
| [aadf01e] | 259 | fibril_rwlock_t devices_lock;
|
|---|
| [6067284] | 260 | /** All known Ethernet devices. */
|
|---|
| [aadf01e] | 261 | eth_devices_t devices;
|
|---|
| [6067284] | 262 | /** Safety lock for protocols. */
|
|---|
| [aadf01e] | 263 | fibril_rwlock_t protos_lock;
|
|---|
| [6067284] | 264 |
|
|---|
| 265 | /**
|
|---|
| 266 | * Protocol map.
|
|---|
| 267 | * Service phone map for each protocol.
|
|---|
| [21580dd] | 268 | */
|
|---|
| [aadf01e] | 269 | eth_protos_t protos;
|
|---|
| [6067284] | 270 |
|
|---|
| 271 | /** Broadcast device hardware address. */
|
|---|
| [4eca056] | 272 | measured_string_t *broadcast_addr;
|
|---|
| [21580dd] | 273 | };
|
|---|
| 274 |
|
|---|
| 275 | #endif
|
|---|
| 276 |
|
|---|
| 277 | /** @}
|
|---|
| 278 | */
|
|---|