Watt-32 tcp/ip  2.2 dev-rel.10
pcsed.h
Go to the documentation of this file.
1 
6 #ifndef _w32_PCSED_H
7 #define _w32_PCSED_H
8 
12 #define HW_TYPE_ETHER 1 /* Ether >= 10MB */
13 #define HW_TYPE_ETHER_3MB 2 /* Ether = 3MB */
14 #define HW_TYPE_AX25 3 /* Amateur packet-radio */
15 #define HW_TYPE_TOKEN 6 /* IEEE 802 Networks */
16 #define HW_TYPE_ARCNET 7 /* 2.5 MBit ARCNET */
17 #define HW_TYPE_APPLETALK 8 /* Not at all supported */
18 #define HW_TYPE_FDDI 10 /* Not really supported */
19 
20 #include <sys/pack_on.h> /* align structs on byte boundaries */
21 
26 typedef struct eth_Header {
27  eth_address destination;
28  eth_address source;
29  WORD type;
30  } eth_Header;
31 
36 typedef struct eth_Packet {
37  eth_Header head;
38  BYTE data [ETH_MAX_DATA];
39  } eth_Packet;
40 
41 
46 typedef struct vlan_Header {
47  eth_address destination;
48  eth_address source;
49  WORD proto; /* 0x8100 */
50  WORD tci;
51  WORD encap_proto;
52  } vlan_Header;
53 
58 typedef struct vlan_Packet {
59  vlan_Header head; /* 18 */
60  BYTE data [VLAN_MAX_DATA]; /* 1496 */
61  } vlan_Packet;
62 
63 
68 typedef struct tok_Header {
69  /* MAC header.
70  */
71  BYTE accessCtrl;
72  BYTE frameCtrl;
73  mac_address destination;
74  mac_address source;
75 
76  /* 2-18 bytes of Routing Information (RIF) may be present here.
77  * We discard it anyway (see fix_tok_head()).
78  */
79 
80  /* LLC header.
81  */
82  BYTE DSAP;
83  BYTE SSAP;
84  BYTE ctrl;
85 
86  /* SNAP extension.
87  */
88  BYTE org[3];
89  WORD type;
90  } tok_Header;
91 
96 typedef struct tok_Packet {
97  tok_Header head;
98  BYTE data [TOK_MAX_DATA];
99  } tok_Packet;
100 
105 typedef struct llc_Header {
106  BYTE DSAP;
107  BYTE SSAP;
108  union {
109  BYTE u_ctl;
110  WORD is_ctl;
111  struct {
112  BYTE snap_ui;
113  BYTE snap_pi[5];
114  } snap;
115  struct {
116  BYTE snap_ui;
117  BYTE snap_orgcode[3];
118  BYTE snap_ethertype[2];
119  } snap_ether;
120  } ctl;
121  } llc_Header;
122 
126 #define TR_AC 0x10 /* Access Control; Frame bit (not token) */
127 #define TR_FC 0x40 /* Frame Control; LLC header follows */
128 #define TR_DSAP 0xAA /* DSAP field; SNAP follows LLC */
129 #define TR_SSAP 0xAA /* SSAP field; SNAP follows LLC */
130 #define TR_CTRL 0x03 /* Unnumbered Information */
131 #define TR_ORG 0x00 /* Organisation Code or Protocol Id */
132 
133 
138 typedef struct fddi_Header {
139  BYTE frameCtrl;
140  eth_address destination;
141  eth_address source;
142  BYTE DSAP;
143  BYTE SSAP;
144  BYTE ctrl;
145  BYTE org[3];
146  WORD type;
147  } fddi_Header;
148 
153 typedef struct fddi_Packet {
154  fddi_Header head;
155  BYTE data [FDDI_MAX_DATA];
156  } fddi_Packet;
157 
158 #define FDDI_FC 0x40 /* See above */
159 #define FDDI_DSAP 0xAA
160 #define FDDI_SSAP 0xAA
161 #define FDDI_CTRL 0x03
162 #define FDDI_ORG 0x00
163 
164 
169 typedef struct arcnet_Header {
170  BYTE source;
171  BYTE destination;
172  BYTE type;
173  BYTE flags;
174  WORD sequence;
175 
176  /* Only present in exception packets (flags == 0xFF)
177  */
178  BYTE type2; /* same as 'type' */
179  BYTE flags2;
180  WORD sequence2;
181  } arcnet_Header;
182 
183 #define ARC_HDRLEN 6 /* normal header length */
184 #define ARC_TYPE_OFS 2
185 
190 typedef struct arcnet_Packet {
191  arcnet_Header head;
192  BYTE data [ARCNET_MAX_DATA];
193  } arcnet_Packet;
194 
195 
200 typedef union link_Packet {
201  struct eth_Packet eth; /* _pktdevclass = PDCLASS_ETHER */
202  struct tok_Packet tok; /* _pktdevclass = PDCLASS_TOKEN (_RIF) */
203  struct fddi_Packet fddi; /* _pktdevclass = PDCLASS_FDDI */
204  struct arcnet_Packet arc; /* _pktdevclass = PDCLASS_ARCNET */
205  struct ip_Packet ip; /* _pktdevclass = PDCLASS_PPP/PDCLASS_SLIP */
206  struct vlan_Packet vlan; /* not supported */
207  } link_Packet;
208 
209 #include <sys/pack_off.h> /* restore default packing */
210 
212  struct {
213  unsigned size; /* frame-size of last Rx */
214  struct ulong_long tstamp; /* timestamp of last Tx */
215  } tx;
216  struct {
217  unsigned size; /* frame-size of last Rx */
218  struct ulong_long tstamp; /* timestamp of last Rx 1st upcall */
219  } rx;
220  };
221 
222 extern struct _eth_last_info _eth_last;
223 
224 extern BOOL _ip_recursion, _eth_is_init;
226 extern BYTE _eth_mac_len;
227 extern const char *_eth_not_init;
228 
229 extern mac_address _eth_addr; /* Current MAC-address (not AX-25) */
230 extern mac_address _eth_real_addr; /* MAC-addr before _eth_set_addr() */
231 extern mac_address _eth_loop_addr; /* CF:00:00:00:00:00 */
232 extern mac_address _eth_brdcast; /* FF:FF:FF:FF:FF:FF */
233 
234 #if defined(USE_MULTICAST)
235  #include "pcigmp.h"
236 
237  BOOL _eth_join_mcast_group (const struct MultiCast *mc);
238  BOOL _eth_leave_mcast_group (const struct MultiCast *mc);
239 #endif
240 
241 /*
242  * Return pointer to hardware source address of
243  * an IP packet. For Ethernet:
244  *
245  * struct eth_Packet {
246  * BYTE dest [6]; <- -14
247  * BYTE src [6]; <- -8
248  * WORD type;
249  * BYTE data [1500]; <- ip
250  * };
251  *
252  * For Token-Ring:
253  * struct tok_Packet {
254  * BYTE AC, FC; <- -22
255  * BYTE dest [6];
256  * BYTE src [6]; <- -14
257  * BYTE DSAP, SSAP, ctrl;
258  * BYTE org [3];
259  * WORD type;
260  * BYTE data [1500]; <- ip
261  *
262  * These macros and functions should never be called for serial protocols
263  * except that it doesn't hurt to use MAC_SRC() for all driver classes.
264  */
265 
266 #if defined(NOT_USED)
267  /* Slower, but safer method. The ATTR_NORETURN() is for the cases
268  * where these used functions are used wrongly. In which case we exit().
269  */
270  extern void *_eth_mac_hdr (const in_Header *ip) ATTR_NORETURN();
271  extern void *_eth_mac_dst (const in_Header *ip) ATTR_NORETURN();
272  extern void *_eth_mac_src (const in_Header *ip) ATTR_NORETURN();
273  extern WORD _eth_mac_typ (const in_Header *ip) ATTR_NORETURN();
274 
275  #define MAC_HDR(ip) _eth_mac_hdr(ip)
276  #define MAC_DST(ip) _eth_mac_dst(ip)
277  #define MAC_SRC(ip) _eth_mac_src(ip)
278  #define MAC_TYP(ip) _eth_mac_typ(ip)
279 #else
280  #define MAC_HDR(ip) (void*) ((BYTE*)(ip) - _pkt_ip_ofs)
281 
282  #define MAC_DST(ip) (void*) ((BYTE*)(ip) - \
283  (_pktdevclass == PDCLASS_TOKEN ? _pkt_ip_ofs-2 : \
284  _pktdevclass == PDCLASS_ARCNET ? _pkt_ip_ofs-1 : \
285  _pktdevclass == PDCLASS_FDDI ? _pkt_ip_ofs-5 : \
286  _pkt_ip_ofs))
287 
288  #define MAC_SRC(ip) (void*) ((BYTE*)(ip) - \
289  (_pktdevclass == PDCLASS_TOKEN ? _pkt_ip_ofs-8 : \
290  _pktdevclass == PDCLASS_ARCNET ? _pkt_ip_ofs : \
291  _pktdevclass == PDCLASS_FDDI ? _pkt_ip_ofs-7 : \
292  _pkt_ip_ofs-6))
293 
294  #define MAC_TYP(ip) (*(WORD*) ((BYTE*)(ip) - \
295  (_pktdevclass == PDCLASS_ARCNET ? _pkt_ip_ofs-2 : 2)))
296 #endif
297 
298 /*
299  * Macros to set or clear peer's source MAC-address stored in
300  * the _udp_Socket / _tcp_Socket.
301  * Only used on passive (listening) udp/tcp sockets.
302  * We don't use arp_resolve() because of reentrancy problems.
303  * But if inbound packets come from a different gateway than
304  * outbound packets, then we're toast..
305  */
306 #define SET_PEER_MAC_ADDR(tcb,ip) do { \
307  if (!_pktserial) \
308  memcpy (&(tcb)->his_ethaddr[0], MAC_SRC(ip), 6); \
309  } while (0)
310 
311 #define CLR_PEER_MAC_ADDR(tcb) do { \
312  if (!_pktserial) \
313  memset (&(tcb)->his_ethaddr[0], 0, 6); \
314  } while (0)
315 
316 #endif
BOOL _eth_is_init
we are initialised
Definition: pcsed.c:55
Multicast internal structure.
Definition: pcigmp.h:115
BOOL _eth_SwsVpkt
for DOS and Win32 programs
Definition: pcsed.c:58
BOOL _eth_wanpacket
for Win32 using an WanPacket adapter
Definition: pcsed.c:60
BOOL _eth_ndis3pkt
for DOS-programs only
Definition: pcsed.c:57
mac_address _eth_addr
Local link-layer source address.
Definition: pcsed.c:50
struct _eth_last_info _eth_last
Sizes and timestamps of last packet recv/sent.
Definition: pcsed.c:68
void * _eth_mac_src(const in_Header *ip) ATTR_NORETURN()
Return pointer to MAC source address of an IP packet.
Definition: pcsed.c:1178
Definition: ip.h:67
BOOL _eth_join_mcast_group(const struct MultiCast *mc)
Joins a multicast group (at the physical layer).
Definition: pcsed.c:1248
mac_address _eth_brdcast
Link-layer broadcast address.
Definition: pcsed.c:51
BYTE _eth_mac_len
Size of a MAC address.
Definition: pcsed.c:54
BOOL _eth_leave_mcast_group(const struct MultiCast *mc)
Leaves a multicast group (at the physical layer)
Definition: pcsed.c:1324
BOOL _eth_winpcap
for Win32 using an WinPcap adapter (default)
Definition: pcsed.c:61
void * _eth_mac_dst(const in_Header *ip) ATTR_NORETURN()
Return pointer to MAC destination address of an IP packet.
Definition: pcsed.c:1148
WORD _eth_mac_typ(const in_Header *ip) ATTR_NORETURN()
Return value of protocol-type given an IP packet.
Definition: pcsed.c:1208
void * _eth_mac_hdr(const in_Header *ip) ATTR_NORETURN()
Return pointer to MAC header start address of an IP packet.
Definition: pcsed.c:1131
mac_address _eth_real_addr
Our real MAC address.
Definition: pcsed.c:53
mac_address _eth_loop_addr
Link-layer loopback address.
Definition: pcsed.c:52
BOOL _eth_airpcap
for Win32 using the AirPcap adapter
Definition: pcsed.c:59
BOOL _ip_recursion
avoid recursion in arp_resolve()
Definition: pcsed.c:56