00001 /* 00002 * Copyright (c) 2009 Lukas Mejdrech 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * - Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * - The name of the author may not be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00019 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00020 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00037 #ifndef NET_ETH_H_ 00038 #define NET_ETH_H_ 00039 00040 #include <fibril_synch.h> 00041 #include <ipc/services.h> 00042 00043 #include <net/device.h> 00044 #include <adt/measured_strings.h> 00045 00047 #define ETH_ADDR 6 00048 00050 #define ETH_PREAMBLE 0x55 00051 00053 #define ETH_SFD 0xD5 00054 00056 #define IEEE_8023_2_UI 0x03 00057 00061 typedef struct eth_header_snap eth_header_snap_t; 00062 00066 typedef struct eth_header_lsap eth_header_lsap_t; 00067 00071 typedef struct eth_ieee_lsap eth_ieee_lsap_t; 00072 00076 typedef struct eth_snap eth_snap_t; 00077 00081 typedef struct eth_preamble eth_preamble_t; 00082 00086 typedef struct eth_header eth_header_t; 00087 00089 struct eth_ieee_lsap { 00094 uint8_t dsap; 00095 00100 uint8_t ssap; 00101 00106 uint8_t ctrl; 00107 } __attribute__ ((packed)); 00108 00110 struct eth_snap { 00112 uint8_t protocol[3]; 00113 00118 uint16_t ethertype; 00119 } __attribute__ ((packed)); 00120 00125 struct eth_preamble { 00130 uint8_t preamble[7]; 00131 00137 uint8_t sfd; 00138 } __attribute__ ((packed)); 00139 00141 struct eth_header { 00143 uint8_t destination_address[ETH_ADDR]; 00145 uint8_t source_address[ETH_ADDR]; 00146 00151 uint16_t ethertype; 00152 } __attribute__ ((packed)); 00153 00155 struct eth_header_lsap { 00157 eth_header_t header; 00158 00167 eth_ieee_lsap_t lsap; 00168 } __attribute__ ((packed)); 00169 00171 struct eth_header_snap { 00173 eth_header_t header; 00174 00183 eth_ieee_lsap_t lsap; 00184 00186 eth_snap_t snap; 00187 } __attribute__ ((packed)); 00188 00190 typedef uint32_t eth_fcs_t; 00191 00195 typedef struct eth_globals eth_globals_t; 00196 00200 typedef struct eth_device eth_device_t; 00201 00205 typedef struct eth_proto eth_proto_t; 00206 00211 DEVICE_MAP_DECLARE(eth_devices, eth_device_t); 00212 00217 INT_MAP_DECLARE(eth_protos, eth_proto_t); 00218 00220 struct eth_device { 00222 device_id_t device_id; 00224 services_t service; 00226 int phone; 00228 size_t mtu; 00229 00235 int flags; 00236 00238 measured_string_t *addr; 00239 00241 uint8_t *addr_data; 00242 }; 00243 00245 struct eth_proto { 00247 services_t service; 00249 int protocol; 00251 int phone; 00252 }; 00253 00255 struct eth_globals { 00257 int net_phone; 00259 fibril_rwlock_t devices_lock; 00261 eth_devices_t devices; 00263 fibril_rwlock_t protos_lock; 00264 00269 eth_protos_t protos; 00270 00272 measured_string_t *broadcast_addr; 00273 }; 00274 00275 #endif 00276