Support for the Ethernet-Audio device
[akaros.git] / kern / include / net.h
1 /* Copyright (c) 2010 The Regents of the University of California
2  * Barret Rhoden <brho@cs.berkeley.edu>
3  * See LICENSE for details.
4  *
5  * Arch independent networking infrastructure */
6
7 #ifndef ROS_KERN_NET_H
8 #define ROS_KERN_NET_H
9
10 #include <bits/netinet.h>
11
12 /* A few other useful standard defines.  Note the IP header can change size. */
13 #define ETH_HDR_SZ 14
14 #define UDP_HDR_SZ 8
15 #define IP_ETH_TYPE 0x0800
16
17 /* ROS defaults: */
18 #define DEFAULT_TTL 64
19
20 /* Don't forget the bytes are in network order */
21 struct ethernet_hdr {
22         uint8_t                                         dst_mac[6];
23         uint8_t                                         src_mac[6];
24         uint16_t                                        eth_type;
25         /* might be an optional 802.1q tag here */
26 };
27
28 /* For the bit-enumerated fields, note that you need to read "backwards" through
29  * the byte (first bits in memory are the "LSB" of the byte).  Can't seem to be
30  * able to do it with flags/fragments (3/13 bits each...). */
31 struct ip_hdr {
32         unsigned                                        hdr_len : 4;
33         unsigned                                        version : 4;
34         uint8_t                                         tos;
35         uint16_t                                        packet_len;
36         uint16_t                                        id;
37         uint16_t                                        flags_frags;
38         uint8_t                                         ttl;
39         uint8_t                                         protocol;
40         uint16_t                                        checksum;
41         uint32_t                                        src_addr;
42         uint32_t                                        dst_addr;
43         /* Options could be here (depends on the hdr length) */
44 } __attribute__((packed));
45
46 struct udp_hdr {
47         uint16_t                                        src_port;
48         uint16_t                                        dst_port;
49         uint16_t                                        length;
50         uint16_t                                        checksum;
51 };
52
53 uint16_t __ip_checksum(void *buf, unsigned int len, uint32_t sum);
54 uint16_t ip_checksum(struct ip_hdr *ip_hdr);
55 uint16_t udp_checksum(struct ip_hdr *ip_hdr, struct udp_hdr *udp_hdr);
56
57 #endif /* ROS_KERN_NET_H */