KallistiOS  2.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
net.h
Go to the documentation of this file.
1 /* KallistiOS 2.0.0
2 
3  include/kos/net.h
4  Copyright (C) 2002 Dan Potter
5  Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Lawrence Sebald
6 
7 */
8 
9 /** \file kos/net.h
10  \brief Network support.
11 
12  This file contains declarations related to networking support. KOS' built-in
13  network stack supports UDP over IPv4, and to some degree has some basic IPv6
14  support as well. This will change over time, hopefully leaving us with full
15  TCP and UDP support both over IPv4 and IPv6.
16 
17  \author Lawrence Sebald
18  \author Dan Potter
19 */
20 
21 #ifndef __KOS_NET_H
22 #define __KOS_NET_H
23 
24 #include <sys/cdefs.h>
25 __BEGIN_DECLS
26 
27 #include <arch/types.h>
28 #include <sys/queue.h>
29 #include <netinet/in.h>
30 
31 /* All functions in this header return < 0 on failure, and 0 on success. */
32 
33 
34 
35 /** \brief Structure describing one usable network device.
36 
37  Each usable network device should have one of these describing it. These
38  must be registered to the network layer before the device is useable.
39 
40  \headerfile kos/net.h
41 */
42 typedef struct knetif {
43  /** \brief Device list handle (not a function!) */
44  LIST_ENTRY(knetif) if_list;
45 
46  /** \brief Device name ("bba", "la", etc) */
47  const char *name;
48 
49  /** \brief Long description of the device */
50  const char *descr;
51 
52  /** \brief Unit index (starts at zero and counts upwards for multiple
53  network devices of the same type) */
54  int index;
55 
56  /** \brief Internal device ID (for whatever the driver wants) */
58 
59  /** \brief Interface flags */
61 
62  /** \brief The device's MAC address */
64 
65  /** \brief The device's IP address (if any) */
67 
68  /** \brief The device's netmask */
70 
71  /** \brief The device's gateway's IP address */
73 
74  /** \brief The device's broadcast address */
76 
77  /** \brief The device's DNS server address */
78  uint8 dns[4];
79 
80  /** \brief The device's MTU */
81  int mtu;
82 
83  /** \brief The device's Link-local IPv6 address */
85 
86  /** \brief Any further IPv6 addresses the device has.
87  The first address in this list will always be used, unless otherwise
88  specified. */
91 
92  /** \brief The device's gateway's IPv6 address */
94 
95  /** \brief Default MTU over IPv6 */
97 
98  /** \brief Default hop limit over IPv6 */
99  int hop_limit;
100 
101  /* All of the following callback functions should return a negative
102  value on failure, and a zero or positive value on success. Some
103  functions have special values, as noted. */
104 
105  /** \brief Attempt to detect the device.
106  \param self The network device in question.
107  \return 0 on success, <0 on failure.
108  */
109  int (*if_detect)(struct knetif * self);
110 
111  /** \brief Initialize the device.
112  \param self The network device in question.
113  \return 0 on success, <0 on failure.
114  */
115  int (*if_init)(struct knetif * self);
116 
117  /** \brief Shutdown the device.
118  \param self The network device in question.
119  \return 0 on success, <0 on failure.
120  */
121  int (*if_shutdown)(struct knetif * self);
122 
123  /** \brief Start the device (after init or stop).
124  \param self The network device in question.
125  \return 0 on success, <0 on failure.
126  */
127  int (*if_start)(struct knetif * self);
128 
129  /** \brief Stop (hibernate) the device.
130  \param self The network device in question.
131  \return 0 on success, <0 on failure
132  */
133  int (*if_stop)(struct knetif * self);
134 
135  /** \brief Queue a packet for transmission.
136  \param self The network device in question.
137  \param data The packet to transmit.
138  \param len The length of the packet in bytes.
139  \param blocking 1 if we should block if needed, 0 otherwise.
140  \retval NETIF_TX_OK On success.
141  \retval NETIF_TX_ERROR On general failure.
142  \retval NETIF_TX_AGAIN If non-blocking and we must block to send.
143  */
144  int (*if_tx)(struct knetif * self, const uint8 * data, int len,
145  int blocking);
146 
147  /** \brief Commit any queued output packets.
148  \param self The network device in question.
149  \return 0 on success, <0 on failure.
150  */
151  int (*if_tx_commit)(struct knetif * self);
152 
153  /** \brief Poll for queued receive packets, if neccessary.
154  \param self The network device in question.
155  \return 0 on success, <0 on failure.
156  */
157  int (*if_rx_poll)(struct knetif * self);
158 
159  /** \brief Set flags; you should generally manipulate flags through here so
160  that the driver gets a chance to act on the info.
161  \param self The network device in question.
162  \param flags_and Bitmask to and with the flags.
163  \param flags_or Bitmask to or with the flags.
164  */
165  int (*if_set_flags)(struct knetif * self, uint32 flags_and, uint32 flags_or);
166 
167  /** \brief Set the device's multicast list.
168  \param self The network device in question.
169  \param list The list of MAC addresses (6 * count bytes).
170  \param count The number of addresses in list.
171  */
172  int (*if_set_mc)(struct knetif *self, const uint8 *list, int count);
173 } netif_t;
174 
175 /** \defgroup net_flags Flags for netif_t
176  @{
177 */
178 #define NETIF_NO_FLAGS 0x00000000 /**< \brief No flags set */
179 #define NETIF_REGISTERED 0x00000001 /**< \brief Is it registered? */
180 #define NETIF_DETECTED 0x00000002 /**< \brief Is it detected? */
181 #define NETIF_INITIALIZED 0x00000004 /**< \brief Has it been initialized? */
182 #define NETIF_RUNNING 0x00000008 /**< \brief Has start() been called? */
183 #define NETIF_PROMISC 0x00010000 /**< \brief Promiscuous mode */
184 #define NETIF_NEEDSPOLL 0x01000000 /**< \brief Needs to be polled for input */
185 /** @} */
186 
187 /* Return types for if_tx */
188 #define NETIF_TX_OK 0 /**< \brief Tx success */
189 #define NETIF_TX_ERROR -1 /**< \brief Tx general error */
190 #define NETIF_TX_AGAIN -2 /**< \brief Retry Tx later */
191 
192 /* Blocking types */
193 #define NETIF_NOBLOCK 0 /**< \brief Don't block for Tx */
194 #define NETIF_BLOCK 1 /**< \brief Blocking is OK for Tx */
195 
196 /* \cond */
197 /* Define the list type */
198 LIST_HEAD(netif_list, knetif);
199 
200 #ifdef PACKED
201 #undef PACKED
202 #endif
203 
204 #define PACKED __attribute__((packed))
205 /* \endcond */
206 
207 /** \brief IPv4 Packet header.
208  \headerfile kos/net.h
209 */
210 typedef struct ip_hdr_s {
211  uint8 version_ihl; /**< \brief IP version and header length */
212  uint8 tos; /**< \brief Type of Service */
213  uint16 length; /**< \brief Length */
214  uint16 packet_id; /**< \brief Packet ID */
215  uint16 flags_frag_offs; /**< \brief Flags and fragment offset */
216  uint8 ttl; /**< \brief Time to live */
217  uint8 protocol; /**< \brief IP protocol */
218  uint16 checksum; /**< \brief IP checksum */
219  uint32 src; /**< \brief Source IP address */
220  uint32 dest; /**< \brief Destination IP address */
221 } PACKED ip_hdr_t;
222 
223 /** \brief IPv6 Packet header.
224  \headerfile kos/net.h
225 */
226 typedef struct ipv6_hdr_s {
227  uint8 version_lclass; /**< \brief Version and low-order class
228  byte */
229  uint8 hclass_lflow; /**< \brief High-order class byte, low-order
230  flow byte */
231  uint16 lclass; /**< \brief Low-order class byte */
232  uint16 length; /**< \brief Length */
233  uint8 next_header; /**< \brief Next header type */
234  uint8 hop_limit; /**< \brief Hop limit */
235  struct in6_addr src_addr; /**< \brief Source IP address */
236  struct in6_addr dst_addr; /**< \brief Destination IP address */
237 } PACKED ipv6_hdr_t;
238 
239 #undef PACKED
240 
241 
242 /***** net_arp.c **********************************************************/
243 
244 /** \brief Init ARP.
245  \retval 0 On success (no error conditions defined).
246 */
247 int net_arp_init();
248 
249 /** \brief Shutdown ARP. */
250 void net_arp_shutdown();
251 
252 /** \brief Garbage collect timed out ARP entries.
253 
254  This will be done periodically as ARP lookups are requested.
255 
256  \retval 0 On success (no error conditions defined).
257 */
258 int net_arp_gc();
259 
260 /** \brief Add an entry to the ARP cache manually.
261 
262  \param nif The network device in use.
263  \param mac The MAC address of the entry.
264  \param ip The IPv4 address of the entry.
265  \param timestamp The entry's timestamp. Set to 0 for a permanent
266  entry, otherwise set to jiffies.
267  \retval 0 On success (no error conditions defined).
268 */
269 int net_arp_insert(netif_t *nif, const uint8 mac[6], const uint8 ip[4],
270  uint32 timestamp);
271 
272 /** \brief Look up an entry from the ARP cache.
273 
274  If no entry is found, then an ARP query will be sent and an error will be
275  returned. If you specify a packet with the call, it will be sent when the
276  reply comes in.
277 
278  \param nif The network device in use.
279  \param ip_in The IP address to lookup.
280  \param mac_out Storage for the MAC address, if found.
281  \param pkt A simple IPv4 header, if you want to send one when a
282  response comes in (if not found immediately).
283  \param data Packet data to go with the header.
284  \param data_size The size of data.
285  \retval 0 On success.
286  \retval -1 A query is outstanding for that address.
287  \retval -2 Address not found, query generated.
288 */
289 int net_arp_lookup(netif_t *nif, const uint8 ip_in[4], uint8 mac_out[6],
290  const ip_hdr_t *pkt, const uint8 *data, int data_size);
291 
292 /** \brief Do a reverse ARP lookup.
293 
294  This function looks for an IP for a given mac address; note that if this
295  fails, you have no recourse.
296 
297  \param nif The network device in use.
298  \param ip_out Storage for the IPv4 address.
299  \param mac_in The MAC address to look up.
300  \retval 0 On success.
301  \retval -1 On failure.
302 */
303 int net_arp_revlookup(netif_t *nif, uint8 ip_out[4], const uint8 mac_in[6]);
304 
305 /** \brief Receive an ARP packet and process it (called by net_input).
306  \param nif The network device in use.
307  \param pkt The packet received.
308  \param len The length of the packet.
309  \retval 0 On success (no error conditions defined).
310 */
311 int net_arp_input(netif_t *nif, const uint8 *pkt, int len);
312 
313 /** \brief Generate an ARP who-has query on the given device.
314  \param nif The network device to use.
315  \param ip The IP to query.
316  \retval 0 On success (no error conditions defined).
317 */
318 int net_arp_query(netif_t *nif, const uint8 ip[4]);
319 
320 
321 /***** net_input.c *********************************************************/
322 
323 /** \brief Network input callback type.
324  \param nif The network device in use.
325  \param pkt The packet received.
326  \param len The length of the packet, in bytes.
327  \return 0 on success, <0 on failure.
328 */
329 typedef int (*net_input_func)(netif_t *nif, const uint8 *pkt, int len);
330 
331 /** \brief Where will input packets be routed? */
333 
334 /** \brief Device drivers should call this function to submit packets received
335  in the background.
336 
337  This function may or may not return immidiately but it won't take an
338  infinitely long time (so it's safe to call inside interrupt handlers).
339 
340  \param device The network device submitting packets.
341  \param data The packet to submit.
342  \param len The length of the packet, in bytes.
343  \return 0 on success, <0 on failure.
344 */
345 int net_input(netif_t *device, const uint8 *data, int len);
346 
347 /** \brief Setup a network input target.
348  \param t The new target callback.
349  \return The old target.
350 */
352 
353 /***** net_icmp.c *********************************************************/
354 
355 /** \brief ICMPv4 echo reply callback type.
356  \param ip The IPv4 address the reply is from.
357  \param seq The sequence number of the packet.
358  \param delta_us The time difference, in microseconds.
359  \param ttl The TTL value in the packet.
360  \param data Any data in the packet.
361  \param len The length of the data, in bytes.
362 */
363 typedef void (*net_echo_cb)(const uint8 *ip, uint16 seq, uint64 delta_us,
364  uint8 ttl, const uint8 *data, int len);
365 
366 /** \brief Where will we handle possibly notifying the user of ping replies? */
368 
369 /** \brief Send an ICMP Echo packet to the specified IP.
370  \param net The network device to use.
371  \param ipaddr The IPv4 address to send to.
372  \param ident A packet identifier.
373  \param seq A packet sequence number.
374  \param data Data to send with the packet.
375  \param size The size of the data to send.
376  \return 0 on success, <0 on failure.
377 */
378 int net_icmp_send_echo(netif_t *net, const uint8 ipaddr[4], uint16 ident,
379  uint16 seq, const uint8 *data, int size);
380 
381 /* Valid values for the code in the net_icmp_send_dest_unreach() function. */
382 #define ICMP_PROTOCOL_UNREACHABLE 2 /**< \brief Protocol unreachable */
383 #define ICMP_PORT_UNREACHABLE 3 /**< \brief Port unreachable */
384 
385 /** \brief Send an ICMP Destination Unreachable packet in reply to the given
386  message.
387  \param net The network device to use.
388  \param code The type of message this is.
389  \param msg The message that caused this error.
390  \return 0 on success, <0 on failure.
391 */
392 int net_icmp_send_dest_unreach(netif_t *net, uint8 code, const uint8 *msg);
393 
394 /* Valid values for the code in the net_icmp_send_time_exceeded() function. */
395 #define ICMP_REASSEMBLY_TIME_EXCEEDED 1 /**< \brief Reassembly time gone */
396 
397 /** \brief Send an ICMP Time Exceeded packet in reply to the given message.
398  \param net The network device to use.
399  \param code The type of message this is.
400  \param msg The message that caused this error.
401  \return 0 on success, <0 on failure.
402 */
403 int net_icmp_send_time_exceeded(netif_t *net, uint8 code, const uint8 *msg);
404 
405 /***** net_ipv4.c *********************************************************/
406 
407 /** \brief IPv4 statistics structure.
408 
409  This structure holds some basic statistics about the IPv4 layer of the
410  stack, and can be retrieved with the appropriate function.
411 
412  \headerfile kos/net.h
413 */
414 typedef struct net_ipv4_stats {
415  uint32 pkt_sent; /** \brief Packets sent out successfully */
416  uint32 pkt_send_failed; /** \brief Packets that failed to send */
417  uint32 pkt_recv; /** \brief Packets received successfully */
418  uint32 pkt_recv_bad_size; /** \brief Packets of a bad size */
419  uint32 pkt_recv_bad_chksum; /** \brief Packets with a bad checksum */
420  uint32 pkt_recv_bad_proto; /** \brief Packets with an unknown proto */
422 
423 /** \brief Retrieve statistics from the IPv4 layer.
424  \return The net_ipv4_stats_t structure.
425 */
427 
428 /** \brief Create a 32-bit IP address, based on the individual numbers
429  contained within the IP.
430  \param addr Array of IP address octets.
431  \return The address, in host byte order.
432 */
433 uint32 net_ipv4_address(const uint8 addr[4]);
434 
435 /** \brief Parse an IP address that is packet into a uint32 into an array of
436  the individual bytes.
437  \param addr The full address, in host byte order.
438  \param out The output buffer.
439 */
440 void net_ipv4_parse_address(uint32 addr, uint8 out[4]);
441 
442 /***** net_icmp6.c ********************************************************/
443 
444 /** \brief ICMPv6 echo reply callback type.
445  \param ip The IPv6 address the reply is from.
446  \param seq The sequence number of the packet.
447  \param delta_us The time difference, in microseconds.
448  \param hlim The hop limit value in the packet.
449  \param data Any data in the packet.
450  \param len The length of the data, in bytes.
451 */
452 typedef void (*net6_echo_cb)(const struct in6_addr *ip, uint16 seq,
453  uint64 delta_us, uint8 hlim, const uint8 *data,
454  int len);
455 
456 /** \brief Where will we handle possibly notifying the user of ping replies? */
458 
459 /** \brief Send an ICMPv6 Echo (PING6) packet to the specified device.
460  \param net The network device to use.
461  \param dst The address to send to.
462  \param ident A packet identifier.
463  \param seq A packet sequence number.
464  \param data Data to send with the packet.
465  \param size Length of the data, in bytes.
466  \return 0 on success, <0 on failure.
467 */
468 int net_icmp6_send_echo(netif_t *net, const struct in6_addr *dst, uint16 ident,
469  uint16 seq, const uint8 *data, int size);
470 
471 /** \brief Send a Neighbor Solicitation packet on the specified device.
472  \param net The network device to use.
473  \param dst The destination address.
474  \param target The target address.
475  \param dupdet 1 if this is for duplicate detection.
476  \return 0 on success, <0 on failure.
477 */
478 int net_icmp6_send_nsol(netif_t *net, const struct in6_addr *dst,
479  const struct in6_addr *target, int dupdet);
480 
481 /** \brief Send a Neighbor Advertisement packet on the specified device.
482  \param net The network device to use.
483  \param dst The destination address.
484  \param target The target address.
485  \param sol 1 if solicited, 0 otherwise.
486  \return 0 on success, <0 on failure.
487 */
488 int net_icmp6_send_nadv(netif_t *net, const struct in6_addr *dst,
489  const struct in6_addr *target, int sol);
490 
491 /** \brief Send a Router Solicitation request on the specified interface.
492  \param net The network device to use.
493  \return 0 on success, <0 on failure.
494 */
495 int net_icmp6_send_rsol(netif_t *net);
496 
497 /* Destination Unreachable codes -- only port unreachable really makes sense */
498 #define ICMP6_DEST_UNREACH_NO_ROUTE 0 /**< \brief No route available */
499 #define ICMP6_DEST_UNREACH_PROHIBITED 1 /**< \brief Access prohibited */
500 #define ICMP6_DEST_UNREACH_BEYOND_SCOPE 2 /**< \brief Gone beyond scope */
501 #define ICMP6_DEST_UNREACH_ADDR_UNREACH 3 /**< \brief Address unreachable */
502 #define ICMP6_DEST_UNREACH_PORT_UNREACH 4 /**< \brief Port unreachable */
503 #define ICMP6_DEST_UNREACH_FAIL_EGRESS 5 /**< \brief Egress failure */
504 #define ICMP6_DEST_UNREACH_BAD_ROUTE 6 /**< \brief Bad route specified */
505 
506 /** \brief Send a destination unreachable packet on the specified interface.
507  \param net The network device to use.
508  \param code The type of message this is.
509  \param ppkt The message that caused this error.
510  \param psz Size of the original message.
511  \return 0 on success, <0 on failure.
512 */
513 int net_icmp6_send_dest_unreach(netif_t *net, uint8 code, const uint8 *ppkt,
514  int psz);
515 
516 /* Time Exceeded codes -- only fragment reassembly time exceeded makes sense */
517 #define ICMP6_TIME_EXCEEDED_HOPS_EXC 0 /**< \brief Hops exceeded */
518 #define ICMP6_TIME_EXCEEDED_FRAGMENT 1 /**< \brief Reassembly time gone */
519 
520 /** \brief Send a time exceeded message on the specified interface.
521  \param net The network device to use.
522  \param code The error code.
523  \param ppkt The message that caused this error.
524  \param psz Size of the original packet.
525  \return 0 on success, <0 on failure.
526 */
527 int net_icmp6_send_time_exceeded(netif_t *net, uint8 code, const uint8 *ppkt,
528  int psz);
529 
530 /* Parameter Problem codes */
531 #define ICMP6_PARAM_PROB_BAD_HEADER 0 /**< \brief Malformed header */
532 #define ICMP6_PARAM_PROB_UNK_HEADER 1 /**< \brief Unknown header */
533 #define ICMP6_PARAM_PROB_UNK_OPTION 2 /**< \brief Unknown header option */
534 
535 /** \brief Send an ICMPv6 Parameter Problem about the given packet.
536  \param net The network device to use.
537  \param code The error code.
538  \param ptr Where in the packet is the error?
539  \param ppkt The message that caused the error.
540  \param psz Size of the original packet.
541  \return 0 on success, <0 on failure.
542 */
543 int net_icmp6_send_param_prob(netif_t *net, uint8 code, uint32 ptr,
544  const uint8 *ppkt, int psz);
545 
546 /***** net_ipv6.c *********************************************************/
547 
548 /** \brief IPv6 statistics structure.
549 
550  This structure holds some basic statistics about the IPv6 layer of the
551  stack, and can be retrieved with the appropriate function.
552 
553  \headerfile kos/net.h
554 */
555 typedef struct net_ipv6_stats {
556  uint32 pkt_sent; /**< \brief Packets sent out successfully */
557  uint32 pkt_send_failed; /**< \brief Packets that failed to send */
558  uint32 pkt_recv; /**< \brief Packets received successfully */
559  uint32 pkt_recv_bad_size; /**< \brief Packets of a bad size */
560  uint32 pkt_recv_bad_proto; /**< \brief Packets with an unknown proto */
561  uint32 pkt_recv_bad_ext; /**< \brief Packets with an unknown hdr */
563 
564 /** \brief Retrieve statistics from the IPv6 layer.
565  \return The global IPv6 stats structure.
566 */
568 
569 /***** net_ndp.c **********************************************************/
570 
571 /** \brief Init NDP.
572  \retval 0 On success (no error conditions defined).
573 */
574 int net_ndp_init();
575 
576 /** \brief Shutdown NDP. */
577 void net_ndp_shutdown();
578 
579 /** \brief Garbage collect timed out NDP entries.
580  This will be called periodically as NDP queries come in.
581 */
582 void net_ndp_gc();
583 
584 /** \brief Add an entry to the NDP cache.
585  \param nif The network device in question.
586  \param mac The MAC address for the entry.
587  \param ip The IPv6 address for the entry.
588  \param unsol Was this unsolicited?
589  \return 0 on success, <0 on failure.
590 */
591 int net_ndp_insert(netif_t *nif, const uint8 mac[6], const struct in6_addr *ip,
592  int unsol);
593 
594 /** \brief Look up an entry from the NDP cache.
595 
596  If no entry is found, then an NDP query will be sent and an error will be
597  returned. If you specify a packet with the call, it will be sent when the
598  reply comes in.
599 
600  \param net The network device to use.
601  \param ip The IPv6 address to query.
602  \param mac_out Storage for the MAC address on success.
603  \param pkt A simple IPv6 header, if you want to send a packet
604  when a reply comes in.
605  \param data Anything that comes after the header.
606  \param data_size The size of data.
607  \return 0 on success, <0 on failure.
608 */
609 int net_ndp_lookup(netif_t *net, const struct in6_addr *ip, uint8 mac_out[6],
610  const ipv6_hdr_t *pkt, const uint8 *data, int data_size);
611 
612 /***** net_udp.c **********************************************************/
613 
614 /** \brief UDP statistics structure.
615 
616  This structure holds some basic statistics about the UDP layer of the stack,
617  and can be retrieved with the appropriate function.
618 
619  \headerfile kos/net.h
620 */
621 typedef struct net_udp_stats {
622  uint32 pkt_sent; /**< \brief Packets sent out successfully */
623  uint32 pkt_send_failed; /**< \brief Packets that failed to send */
624  uint32 pkt_recv; /**< \brief Packets received successfully */
625  uint32 pkt_recv_bad_size; /**< \brief Packets of a bad size */
626  uint32 pkt_recv_bad_chksum; /**< \brief Packets with a bad checksum */
627  uint32 pkt_recv_no_sock; /**< \brief Packets with to a closed port */
629 
630 /** \brief Retrieve statistics from the UDP layer.
631  \return The global UDP stats struct.
632 */
634 
635 /** \brief Init UDP.
636  \retval 0 On success (no error conditions defined).
637 */
638 int net_udp_init();
639 
640 /** \brief Shutdown UDP. */
641 void net_udp_shutdown();
642 
643 /***** net_tcp.c **********************************************************/
644 
645 /** \brief Init TCP.
646  \retval 0 On success (no error conditions defined).
647 */
648 int net_tcp_init();
649 
650 /** \brief Shutdown TCP. */
651 void net_tcp_shutdown();
652 
653 /***** net_crc.c **********************************************************/
654 
655 /** \brief Calculate a "little-endian" CRC-32 over a block of data.
656  \param data The data to calculate over.
657  \param size The size of the data, in bytes.
658  \return The calculated CRC-32.
659 */
660 uint32 net_crc32le(const uint8 *data, int size);
661 
662 /** \brief Calculate a "big-endian" CRC-32 over a block of data.
663  \param data The data to calculate over.
664  \param size The size of the data, in bytes.
665  \return The calculated CRC-32.
666 */
667 uint32 net_crc32be(const uint8 *data, int size);
668 
669 /** \brief Calculate a CRC16-CCITT over a block of data.
670  \param data The data to calculate over.
671  \param size The size of the data, in bytes.
672  \param start The value to start with. This could be a previous
673  return value from this function (if continuing a
674  previous calculation) or some initial seed value
675  (typically 0xFFFF or 0x0000).
676  \return The calculated CRC16-CCITT.
677  \note Based on code found online at
678  http://www.ccsinfo.com/forum/viewtopic.php?t=24977
679 */
680 uint16 net_crc16ccitt(const uint8 *data, int size, uint16 start);
681 
682 /***** net_multicast.c ****************************************************/
683 
684 /** \brief Add a entry to our multicast list.
685 
686  This function will auto-commit the multicast list to the network interface
687  in the process.
688 
689  \param mac The MAC address to add.
690  \return 0 on success, <0 on failure.
691 */
692 int net_multicast_add(const uint8 mac[6]);
693 
694 /** \brief Delete a entry from our multicast list.
695 
696  This function will auto-commit the multicast list to the network interface
697  in the process.
698 
699  \param mac The MAC address to add.
700  \return 0 on success, <0 on failure.
701 */
702 int net_multicast_del(const uint8 mac[6]);
703 
704 /** \brief Check if an address is on the multicast list.
705  \param mac The MAC address to check for.
706  \retval 0 The address is not in the list.
707  \retval 1 The address is in the list.
708  \retval -1 On error.
709 */
710 int net_multicast_check(const uint8 mac[6]);
711 
712 /** \brief Init multicast support.
713  \return 0 on success, !0 on error.
714 */
715 int net_multicast_init();
716 
717 /** \brief Shutdown multicast support. */
719 
720 /***** net_core.c *********************************************************/
721 
722 /** \brief Interface list; note: do not manipulate directly! */
723 extern struct netif_list net_if_list;
724 
725 /** \brief Function to retrieve the interface list.
726 
727  Do not manipulate what this returns to you!
728 
729  \return The network interface list.
730 */
731 struct netif_list * net_get_if_list();
732 
733 /** \brief The default network device, used with sockets (read-only). */
734 extern netif_t *net_default_dev;
735 
736 /** \brief Set our default device to an arbitrary device.
737  \param n The device to set as default.
738  \return The old default device.
739 */
741 
742 /** \brief Register a network device.
743  \param device The device to register.
744  \return 0 on success, <0 on failure.
745 */
746 int net_reg_device(netif_t *device);
747 
748 /** \brief Unregister a network device.
749  \param device The device to unregister.
750  \return 0 on success, <0 on failure.
751 */
752 int net_unreg_device(netif_t *device);
753 
754 /** \brief Init network support.
755  \return 0 on success, <0 on failure.
756 */
757 int net_init();
758 
759 /** \brief Shutdown network support. */
760 void net_shutdown();
761 
762 __END_DECLS
763 
764 #endif /* __KOS_NET_H */
765