1 /* Copyright (c) 2010 The Regents of the University of California
2 * Barret Rhoden <brho@cs.berkeley.edu>
3 * David Zhu <yuzhu@cs.berkeley.edu>
4 * See LICENSE for details.
6 * Arch independent networking infrastructure */
11 #include <bits/netinet.h>
16 /* A few other useful standard defines. Note the IP header can change size. */
17 #define ETH_HDR_SZ 14 // without padding, 16 with padding
19 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
22 #define IP_ETH_TYPE 0x0800
23 #define ETHTYPE_IP IP_ETH_TYPE
24 #define ETHTYPE_ARP 0x0806
27 /* ROS defaults: They really should be netif specific*/
28 #define DEFAULT_TTL 64
29 #define DEFAULT_MTU 1500
30 // is this network order already?
31 #define LOCAL_IP_ADDR (struct in_addr) {0x0A000002} //lookout for address order
34 /* Don't forget the bytes are in network order */
36 /* might want to pad to increase access speed? */
40 /* might be an optional 802.1q tag here */
41 } __attribute__((packed));
43 #define IP_RF 0x8000 /* reserved fragment flag */
44 #define IP_DF 0x4000 /* dont fragment flag */
45 #define IP_MF 0x2000 /* more fragments flag */
46 #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
48 #define PACK_STRUCT_FIELD(x) x __attribute__((packed))
50 /* For the bit-enumerated fields, note that you need to read "backwards" through
51 * the byte (first bits in memory are the "LSB" of the byte). Can't seem to be
52 * able to do it with flags/fragments (3/13 bits each...). */
54 /* TODO: Are these accesses slower? */
59 /* ip header id is used for fragmentation reassembly */
60 uint16_t id; // 1 index this?
61 /* flags controlling fragmentation(do not fragment etc) */
63 /* statically set to a constatnt right now */
69 /* Options could be here (depends on the hdr length) */
70 } __attribute__((packed));
77 } __attribute__((packed));
80 PACK_STRUCT_FIELD(uint16_t src);
81 PACK_STRUCT_FIELD(uint16_t dest);
82 PACK_STRUCT_FIELD(uint32_t seqno);
83 PACK_STRUCT_FIELD(uint32_t ackno);
84 PACK_STRUCT_FIELD(uint16_t _hdrlen_rsvd_flags);
85 PACK_STRUCT_FIELD(uint16_t wnd);
86 PACK_STRUCT_FIELD(uint16_t chksum);
87 PACK_STRUCT_FIELD(uint16_t urgp);
88 } __attribute__((packed));
90 /* src and dst are in network order*/
91 uint16_t inet_chksum_pseudo(struct pbuf *p, uint32_t src, uint32_t dest, uint8_t proto, uint16_t proto_len);
92 uint16_t __ip_checksum(void *buf, unsigned int len, uint32_t sum);
93 uint16_t ip_checksum(struct ip_hdr *ip_hdr);
94 uint16_t udp_checksum(struct ip_hdr *ip_hdr, struct udp_hdr *udp_hdr);
96 // TODO: Move this to a better location
97 void dumppacket(unsigned char *buff, size_t len);
98 #endif /* ROS_KERN_NET_H */