source: mainline/uspace/srv/net/nil/eth/eth.h@ 612af1a0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 612af1a0 was 609243f4, checked in by Martin Decky <martin@…>, 14 years ago

cherrypick general networking improvements from lp:~helenos-nicf/helenos/nicf (after sanitization)
remove obsolete networking drivers
this renders the networking non-functional for the time being

  • Property mode set to 100644
File size: 7.1 KB
RevLine 
[21580dd]1/*
2 * Copyright (c) 2009 Lukas Mejdrech
[609243f4]3 * Copyright (c) 2011 Radim Vansa
[21580dd]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup eth
31 * @{
32 */
33
34/** @file
[6067284]35 * Ethernet module.
[21580dd]36 */
37
[6067284]38#ifndef NET_ETH_H_
39#define NET_ETH_H_
[21580dd]40
[6b82009]41#include <async.h>
[21580dd]42#include <fibril_synch.h>
43#include <ipc/services.h>
[e526f08]44#include <net/device.h>
[849ed54]45#include <adt/measured_strings.h>
[609243f4]46#include <devman.h>
[21580dd]47
[fe8dfa6]48/** Ethernet address length. */
49#define ETH_ADDR 6
50
51/** Ethernet header preamble value. */
52#define ETH_PREAMBLE 0x55
53
54/** Ethernet header start of frame value. */
55#define ETH_SFD 0xD5
56
57/** IEEE 802.2 unordered information control field. */
58#define IEEE_8023_2_UI 0x03
59
60/** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions.
61 * @see eth_header_snap
62 */
63typedef struct eth_header_snap eth_header_snap_t;
64
65/** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions.
66 * @see eth_header_lsap
67 */
68typedef struct eth_header_lsap eth_header_lsap_t;
69
70/** Type definition of the Ethernet header LSAP extension.
71 * @see eth_ieee_lsap
72 */
73typedef struct eth_ieee_lsap eth_ieee_lsap_t;
74
75/** Type definition of the Ethernet header SNAP extension.
76 * @see eth_snap
77 */
78typedef struct eth_snap eth_snap_t;
79
80/** Type definition of the Ethernet header preamble.
81 * @see preamble
82 */
83typedef struct eth_preamble eth_preamble_t;
84
85/** Type definition of the Ethernet header.
86 * @see eth_header
87 */
88typedef struct eth_header eth_header_t;
89
90/** Ethernet header Link Service Access Point extension. */
91struct eth_ieee_lsap {
92 /**
93 * Destination Service Access Point identifier.
94 * The possible values are assigned by an IEEE committee.
95 */
96 uint8_t dsap;
97
98 /**
99 * Source Service Access Point identifier.
100 * The possible values are assigned by an IEEE committee.
101 */
102 uint8_t ssap;
103
104 /**
105 * Control parameter.
106 * The possible values are assigned by an IEEE committee.
107 */
108 uint8_t ctrl;
109} __attribute__ ((packed));
110
111/** Ethernet header SNAP extension. */
112struct eth_snap {
113 /** Protocol identifier or organization code. */
114 uint8_t protocol[3];
115
116 /**
117 * Ethernet protocol identifier in the network byte order (big endian).
118 * @see ethernet_protocols.h
119 */
120 uint16_t ethertype;
121} __attribute__ ((packed));
122
123/** Ethernet header preamble.
124 *
125 * Used for dummy devices.
126 */
127struct eth_preamble {
128 /**
129 * Controlling preamble used for the frame transmission synchronization.
130 * All should be set to ETH_PREAMBLE.
131 */
132 uint8_t preamble[7];
133
134 /**
135 * Start of Frame Delimiter used for the frame transmission
136 * synchronization.
137 * Should be set to ETH_SFD.
138 */
139 uint8_t sfd;
140} __attribute__ ((packed));
141
142/** Ethernet header. */
143struct eth_header {
144 /** Destination host Ethernet address (MAC address). */
145 uint8_t destination_address[ETH_ADDR];
146 /** Source host Ethernet address (MAC address). */
147 uint8_t source_address[ETH_ADDR];
148
149 /**
150 * Ethernet protocol identifier in the network byte order (big endian).
151 * @see ethernet_protocols.h
152 */
153 uint16_t ethertype;
154} __attribute__ ((packed));
155
156/** Ethernet header IEEE 802.3 + 802.2 extension. */
157struct eth_header_lsap {
158 /** Ethernet header. */
159 eth_header_t header;
160
161 /**
162 * LSAP extension.
163 * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being
164 * used.
165 * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet
166 * without any extensions is being used and the frame content starts
167 * rigth after the two fields.
168 */
169 eth_ieee_lsap_t lsap;
170} __attribute__ ((packed));
171
172/** Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. */
173struct eth_header_snap {
174 /** Ethernet header. */
175 eth_header_t header;
176
177 /**
178 * LSAP extension.
179 * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being
180 * used.
181 * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet
182 * without any extensions is being used and the frame content starts
183 * rigth after the two fields.
184 */
185 eth_ieee_lsap_t lsap;
186
187 /** SNAP extension. */
188 eth_snap_t snap;
189} __attribute__ ((packed));
190
191/** Ethernet Frame Check Sequence. */
192typedef uint32_t eth_fcs_t;
193
[21580dd]194/** Type definition of the Ethernet global data.
[6067284]195 * @see eth_globals
[21580dd]196 */
[6067284]197typedef struct eth_globals eth_globals_t;
[21580dd]198
199/** Type definition of the Ethernet device specific data.
[6067284]200 * @see eth_device
[21580dd]201 */
[6067284]202typedef struct eth_device eth_device_t;
[21580dd]203
204/** Type definition of the Ethernet protocol specific data.
[6067284]205 * @see eth_proto
[21580dd]206 */
[6067284]207typedef struct eth_proto eth_proto_t;
[21580dd]208
209/** Ethernet device map.
[6067284]210 * Maps devices to the Ethernet device specific data.
211 * @see device.h
[21580dd]212 */
[6067284]213DEVICE_MAP_DECLARE(eth_devices, eth_device_t);
[21580dd]214
215/** Ethernet protocol map.
[6067284]216 * Maps protocol identifiers to the Ethernet protocol specific data.
217 * @see int_map.h
[21580dd]218 */
[6067284]219INT_MAP_DECLARE(eth_protos, eth_proto_t);
[21580dd]220
[6067284]221/** Ethernet device specific data. */
222struct eth_device {
223 /** Device identifier. */
[609243f4]224 nic_device_id_t device_id;
225 /** Device handle */
226 devman_handle_t handle;
[6b82009]227 /** Driver session. */
228 async_sess_t *sess;
[6067284]229 /** Maximal transmission unit. */
[aadf01e]230 size_t mtu;
[6067284]231
232 /**
233 * Various device flags.
234 * @see ETH_DUMMY
235 * @see ETH_MODE_MASK
[21580dd]236 */
[aadf01e]237 int flags;
[6067284]238
239 /** Actual device hardware address. */
[609243f4]240 nic_address_t addr;
[21580dd]241};
242
[6067284]243/** Ethernet protocol specific data. */
244struct eth_proto {
245 /** Protocol service. */
[aadf01e]246 services_t service;
[6067284]247 /** Protocol identifier. */
[aadf01e]248 int protocol;
[6b82009]249 /** Protocol module session. */
250 async_sess_t *sess;
[21580dd]251};
252
[6067284]253/** Ethernet global data. */
254struct eth_globals {
[6b82009]255 /** Networking module session. */
256 async_sess_t *net_sess;
[6067284]257 /** Safety lock for devices. */
[aadf01e]258 fibril_rwlock_t devices_lock;
[6067284]259 /** All known Ethernet devices. */
[aadf01e]260 eth_devices_t devices;
[6067284]261 /** Safety lock for protocols. */
[aadf01e]262 fibril_rwlock_t protos_lock;
[6067284]263
264 /**
265 * Protocol map.
[6b82009]266 * Service map for each protocol.
[21580dd]267 */
[aadf01e]268 eth_protos_t protos;
[6067284]269
270 /** Broadcast device hardware address. */
[609243f4]271 uint8_t broadcast_addr[ETH_ADDR];
[21580dd]272};
273
274#endif
275
276/** @}
277 */
Note: See TracBrowser for help on using the repository browser.