Make kernel complib static
[mirror/winof/.git] / ulp / ipoib / ip_packet.h
1 /*\r
2  * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.\r
3  *\r
4  * This software is available to you under the OpenIB.org BSD license\r
5  * below:\r
6  *\r
7  *     Redistribution and use in source and binary forms, with or\r
8  *     without modification, are permitted provided that the following\r
9  *     conditions are met:\r
10  *\r
11  *      - Redistributions of source code must retain the above\r
12  *        copyright notice, this list of conditions and the following\r
13  *        disclaimer.\r
14  *\r
15  *      - Redistributions in binary form must reproduce the above\r
16  *        copyright notice, this list of conditions and the following\r
17  *        disclaimer in the documentation and/or other materials\r
18  *        provided with the distribution.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
27  * SOFTWARE.\r
28  *\r
29  * $Id$\r
30  */\r
31 \r
32 \r
33 #ifndef _IP_PACKET_H_\r
34 #define _IP_PACKET_H_\r
35 \r
36 \r
37 #include <complib/cl_types.h>\r
38 #include <complib/cl_byteswap.h>\r
39 \r
40 \r
41 #ifndef HW_ADDR_LEN\r
42 #define HW_ADDR_LEN             6\r
43 #endif  /* HW_ADDR_LEN */\r
44 \r
45 \r
46 #define ETH_PROT_TYPE_IP        CL_HTON16(0x800)\r
47 #define ETH_PROT_TYPE_ARP       CL_HTON16(0x806)\r
48 \r
49 \r
50 #include <complib/cl_packon.h>\r
51 /****s* IB Network Drivers/mac_addr_t\r
52 * NAME\r
53 *       mac_addr_t\r
54 *\r
55 * DESCRIPTION\r
56 *       Defines the ehternet MAC address.\r
57 *\r
58 * SYNOPSIS\r
59 */\r
60 typedef struct _mac_addr\r
61 {\r
62         uint8_t         addr[HW_ADDR_LEN];\r
63 \r
64 }       PACK_SUFFIX mac_addr_t;\r
65 /*\r
66 * FIELDS\r
67 *       addr\r
68 *               Byte array representing the MAC address.\r
69 *\r
70 * NOTES\r
71 *       The HW_ADDR_LEN value must be defined before including this header in order\r
72 *       to support various address lengths.  If not defined, the default length for\r
73 *       ethernet (6 bytes) is used.\r
74 *\r
75 * SEE ALSO\r
76 *       IB Network Drivers, arp_pkt_t, ip_hdr_t, tcp_hdr_t, udp_hdr_t\r
77 *********/\r
78 #include <complib/cl_packoff.h>\r
79 \r
80 \r
81 #include <complib/cl_packon.h>\r
82 /****s* IB Network Drivers/eth_hdr_t\r
83 * NAME\r
84 *       eth_hdr_t\r
85 *\r
86 * DESCRIPTION\r
87 *       Defines the ehternet header for IP packets.\r
88 *\r
89 * SYNOPSIS\r
90 */\r
91 typedef struct _eth_hdr\r
92 {\r
93         mac_addr_t      dst;\r
94         mac_addr_t      src;\r
95         net16_t         type;\r
96 \r
97 }       PACK_SUFFIX eth_hdr_t;\r
98 /*\r
99 * FIELDS\r
100 *       dst\r
101 *               Destination address\r
102 *\r
103 *       src\r
104 *               Source address\r
105 *\r
106 *       type\r
107 *               Ethernet protocol type\r
108 *\r
109 * NOTES\r
110 *       The HW_ADDR_LEN value must be defined before including this header in order\r
111 *       to support various address lengths.\r
112 *\r
113 * SEE ALSO\r
114 *       IB Network Drivers, arp_pkt_t, ip_hdr_t, tcp_hdr_t, udp_hdr_t\r
115 *********/\r
116 #include <complib/cl_packoff.h>\r
117 \r
118 \r
119 #define ARP_HW_TYPE_ETH         CL_HTON16(1)\r
120 #define ARP_HW_TYPE_IB          CL_HTON16(32)\r
121 \r
122 #define ARP_OP_REQ                      CL_HTON16(1)\r
123 #define ARP_OP_REP                      CL_HTON16(2)\r
124 \r
125 \r
126 #include <complib/cl_packon.h>\r
127 /****s* IB Network Drivers/arp_pkt_t\r
128 * NAME\r
129 *       arp_pkt_t\r
130 *\r
131 * DESCRIPTION\r
132 *       Defines the ARP packet for IP packets.\r
133 *\r
134 * SYNOPSIS\r
135 */\r
136 typedef struct _arp_pkt\r
137 {\r
138         net16_t         hw_type;\r
139         net16_t         prot_type;\r
140         uint8_t         hw_size;\r
141         uint8_t         prot_size;\r
142         net16_t         op;\r
143         mac_addr_t      src_hw;\r
144         net32_t         src_ip;\r
145         mac_addr_t      dst_hw;\r
146         net32_t         dst_ip;\r
147 \r
148 }       PACK_SUFFIX arp_pkt_t;\r
149 /*\r
150 * FIELDS\r
151 *       hw_type\r
152 *               Hardware type\r
153 *\r
154 *       prot_type\r
155 *               Protocol type.  See ETH_PROT_TYPE_XXX definitions.\r
156 *\r
157 *       hw_size\r
158 *               Size of the hardware address\r
159 *\r
160 *       prot_size\r
161 *               Size of the protocol address\r
162 *\r
163 *       op\r
164 *               ARP operation\r
165 *\r
166 *       src_hw\r
167 *               Source HW (MAC) address\r
168 *\r
169 *       src_ip\r
170 *               Source IP address\r
171 *\r
172 *       dst_hw\r
173 *               Destination HW (MAC) address\r
174 *\r
175 *       dst_ip\r
176 *               Destination IP address\r
177 *\r
178 * NOTES\r
179 *       The HW_ADDR_LEN value must be defined before including this header in order\r
180 *       to support various MAC address lengths.\r
181 *\r
182 * SEE ALSO\r
183 *       IB Network Drivers, eth_hdr_t, ip_hdr_t, tcp_hdr_t, udp_hdr_t\r
184 *********/\r
185 #include <complib/cl_packoff.h>\r
186 \r
187 \r
188 #define IP_PROT_IP                      4\r
189 #define IP_PROT_TCP                     6\r
190 #define IP_PROT_UDP                     17\r
191 \r
192 \r
193 #include <complib/cl_packon.h>\r
194 /****s* IB Network Drivers/ip_hdr_t\r
195 * NAME\r
196 *       ip_hdr_t\r
197 *\r
198 * DESCRIPTION\r
199 *       Defines the IP header for IP packets.\r
200 *\r
201 * SYNOPSIS\r
202 */\r
203 typedef struct _ip_hdr\r
204 {\r
205         uint8_t         ver_hl;\r
206         uint8_t         svc_type;\r
207         net16_t         length;\r
208         net16_t         id;\r
209         net16_t         offset;\r
210         uint8_t         ttl;\r
211         uint8_t         prot;\r
212         net16_t         chksum;\r
213         net32_t         src_ip;\r
214         net32_t         dst_ip;\r
215 \r
216 }       PACK_SUFFIX ip_hdr_t;\r
217 /*\r
218 * FIELDS\r
219 *       ver_hl\r
220 *               Header version and length.\r
221 *\r
222 *       svc_type\r
223 *               Service type.\r
224 *\r
225 *       length\r
226 *               Total length.\r
227 *\r
228 *       id\r
229 *               Packet identification.\r
230 *\r
231 *       offset\r
232 *               Fragment offset.\r
233 *\r
234 *       ttl\r
235 *               Time to live.\r
236 *\r
237 *       prot\r
238 *               Protocol.\r
239 *\r
240 *       chksum\r
241 *               Checksum.\r
242 *\r
243 *       src_ip\r
244 *               Source IP address\r
245 *\r
246 *       dst_ip\r
247 *               Destination IP address\r
248 *\r
249 * SEE ALSO\r
250 *       IB Network Drivers, eth_hdr_t, arp_pkt_t, tcp_hdr_t, udp_hdr_t\r
251 *********/\r
252 #include <complib/cl_packoff.h>\r
253 \r
254 \r
255 #include <complib/cl_packon.h>\r
256 /****s* IB Network Drivers/tcp_hdr_t\r
257 * NAME\r
258 *       tcp_hdr_t\r
259 *\r
260 * DESCRIPTION\r
261 *       Defines the IP header for IP packets.\r
262 *\r
263 * SYNOPSIS\r
264 */\r
265 typedef struct _tcp_hdr\r
266 {\r
267         net16_t         src_port;\r
268         net16_t         dst_port;\r
269         net32_t         seq_num;\r
270         net32_t         ack_num;\r
271         uint8_t         offset;\r
272         uint8_t         flags;\r
273         net16_t         window;\r
274         net16_t         chksum;\r
275         net16_t         urp;\r
276 \r
277 }       PACK_SUFFIX tcp_hdr_t;\r
278 /*\r
279 * FIELDS\r
280 *       src_port\r
281 *               Source port.\r
282 *\r
283 *       dst_port\r
284 *               Destination port.\r
285 *\r
286 *       seq_num\r
287 *               Sequence number.\r
288 *\r
289 *       ack_num\r
290 *               Acknowledge number.\r
291 *\r
292 *       offset\r
293 *               data offset.\r
294 *\r
295 *       flags\r
296 *               TCP flags.\r
297 *\r
298 *       window\r
299 *               Window number.\r
300 *\r
301 *       chksum\r
302 *               Checksum.\r
303 *\r
304 *       urp\r
305 *               Urgent pointer.\r
306 *\r
307 * SEE ALSO\r
308 *       IB Network Drivers, eth_hdr_t, arp_pkt_t, ip_hdr_t, udp_hdr_t\r
309 *********/\r
310 #include <complib/cl_packoff.h>\r
311 \r
312 \r
313 #include <complib/cl_packon.h>\r
314 /****s* IB Network Drivers/udp_hdr_t\r
315 * NAME\r
316 *       udp_hdr_t\r
317 *\r
318 * DESCRIPTION\r
319 *       Defines the IP header for IP packets.\r
320 *\r
321 * SYNOPSIS\r
322 */\r
323 typedef struct _udp_hdr\r
324 {\r
325         net16_t         src_port;\r
326         net16_t         dst_port;\r
327         net16_t         length;\r
328         net16_t         chksum;\r
329 \r
330 }       PACK_SUFFIX udp_hdr_t;\r
331 /*\r
332 * FIELDS\r
333 *       src_port\r
334 *               Source port.\r
335 *\r
336 *       dst_port\r
337 *               Destination port.\r
338 *\r
339 *       length\r
340 *               Length of datagram.\r
341 *\r
342 *       chksum\r
343 *               Checksum.\r
344 *\r
345 * SEE ALSO\r
346 *       IB Network Drivers, eth_hdr_t, arp_pkt_t, ip_hdr_t, tcp_hdr_t\r
347 *********/\r
348 #include <complib/cl_packoff.h>\r
349 \r
350 \r
351 #define DHCP_PORT_SERVER                CL_HTON16(67)\r
352 #define DHCP_PORT_CLIENT                CL_HTON16(68)\r
353 \r
354 #define DHCP_REQUEST                    1\r
355 #define DHCP_REPLY                              2\r
356 #define DHCP_HW_TYPE_ETH                1\r
357 #define DHCP_HW_TYPE_IB                 32\r
358 #define DHCP_OPT_PAD                    0\r
359 #define DHCP_OPT_END                    255\r
360 #define DHCP_OPT_MSG                    53\r
361 #define DHCP_OPT_CLIENT_ID              61\r
362 \r
363 #define DHCPDISCOVER                    1\r
364 #define DHCPOFFER                               2\r
365 #define DHCPREQUEST                             3\r
366 #define DHCPDECLINE                             4\r
367 #define DHCPACK                                 5\r
368 #define DHCPNAK                                 6\r
369 #define DHCPRELEASE                             7\r
370 #define DHCPINFORM                              8\r
371 \r
372 #define DHCP_FLAGS_BROADCAST    CL_HTON16(0x8000)\r
373 #define DHCP_COOKIE                             0x63538263\r
374 #define DHCP_OPTIONS_SIZE               312\r
375 #define DHCP_COOKIE_SIZE                4\r
376 \r
377 \r
378 /* Minimum DHCP size is without options (but with 4-byte magic cookie). */\r
379 #define DHCP_MIN_SIZE                   (sizeof(dhcp_pkt_t) + DHCP_COOKIE_SIZE - DHCP_OPTIONS_SIZE )\r
380 \r
381 #include <complib/cl_packon.h>\r
382 /****s* IB Network Drivers/dhcp_pkt_t\r
383 * NAME\r
384 *       dhcp_pkt_t\r
385 *\r
386 * DESCRIPTION\r
387 *       Defines the DHCP packet format as documented in RFC 2131\r
388 *       http://www.zvon.org/tmRFC/RFC2131/Output/index.html\r
389 *\r
390 * SYNOPSIS\r
391 */\r
392 typedef struct _dhcp_pkt\r
393 {\r
394         uint8_t         op;\r
395         uint8_t         htype;\r
396         uint8_t         hlen;\r
397         uint8_t         hops;\r
398         net32_t         xid;\r
399         net16_t         secs;\r
400         net16_t         flags;\r
401         net32_t         ciaddr;\r
402         net32_t         yiaddr;\r
403         net32_t         siaddr;\r
404         net32_t         giaddr;\r
405         uint8_t         chaddr[16];\r
406         uint8_t         sname[64];\r
407         uint8_t         file[128];\r
408         uint8_t         options[312];\r
409 \r
410 }       PACK_SUFFIX dhcp_pkt_t;\r
411 /*\r
412 * SEE ALSO\r
413 *       IB Network Drivers, eth_hdr_t, arp_pkt_t, ip_hdr_t, udp_hdr_t\r
414 *********/\r
415 #include <complib/cl_packoff.h>\r
416 \r
417 \r
418 #include <complib/cl_packon.h>\r
419 typedef struct _udp_pkt\r
420 {\r
421         udp_hdr_t       hdr;\r
422         dhcp_pkt_t      dhcp;\r
423 \r
424 }       PACK_SUFFIX udp_pkt_t;\r
425 \r
426 typedef struct _ip_pkt\r
427 {\r
428         ip_hdr_t                hdr;\r
429         union _ip_payload\r
430         {\r
431                 tcp_hdr_t       tcp;\r
432                 udp_pkt_t       udp;\r
433 \r
434         }       PACK_SUFFIX prot;\r
435 \r
436 }       PACK_SUFFIX ip_pkt_t;\r
437 \r
438 typedef struct _eth_pkt\r
439 {\r
440         eth_hdr_t       hdr;\r
441         union _eth_payload\r
442         {\r
443                 arp_pkt_t       arp;\r
444                 ip_pkt_t        ip;\r
445 \r
446         }       PACK_SUFFIX type;\r
447 \r
448 }       PACK_SUFFIX eth_pkt_t;\r
449 #include <complib/cl_packoff.h>\r
450 \r
451 \r
452 #endif  /* _IP_PACKET_H_ */\r