34 #include "net/ipv6/uipbuf.h" 39 static uint16_t uipbuf_attrs[UIPBUF_ATTR_MAX];
40 static uint16_t uipbuf_default_attrs[UIPBUF_ATTR_MAX];
53 uipbuf_add_ext_hdr(int16_t len)
55 if(len + uip_len <= UIP_LINK_MTU && len + uip_len >= 0 && len +
uip_ext_len >= 0) {
65 uipbuf_set_len(uint16_t len)
76 uipbuf_set_len_field(
struct uip_ip_hdr *hdr, uint16_t len)
78 hdr->len[0] = (len >> 8);
79 hdr->len[1] = (len & 0xff);
83 uipbuf_get_len_field(
struct uip_ip_hdr *hdr)
85 return ((uint16_t)(hdr->len[0]) << 8) + hdr->len[1];
91 uipbuf_get_next_header(uint8_t *buffer, uint16_t size, uint8_t *protocol,
bool start)
95 uint8_t *next_header = NULL;
96 struct uip_ip_hdr *ipbuf = NULL;
97 struct uip_ext_hdr *curr_ext = NULL;
98 struct uip_ext_hdr *next_ext = NULL;
102 ipbuf = (
struct uip_ip_hdr *)buffer;
103 *protocol = ipbuf->proto;
104 curr_hdr_len = UIP_IPH_LEN;
107 curr_ext = (
struct uip_ext_hdr *)buffer;
108 *protocol = curr_ext->next;
110 curr_hdr_len = (curr_ext->len << 3) + 8;
114 if(curr_hdr_len > size) {
117 next_header = buffer + curr_hdr_len;
120 if(uip_is_proto_ext_hdr(*protocol)) {
121 next_ext = (
struct uip_ext_hdr *)next_header;
122 next_hdr_len = (next_ext->len << 3) + 8;
124 if(*protocol == UIP_PROTO_TCP) {
125 next_hdr_len = UIP_TCPH_LEN;
126 }
else if(*protocol == UIP_PROTO_UDP) {
127 next_hdr_len = UIP_UDPH_LEN;
128 }
else if(*protocol == UIP_PROTO_ICMP6) {
129 next_hdr_len = UIP_ICMPH_LEN;
134 if(next_hdr_len == 0 || curr_hdr_len + next_hdr_len > size) {
144 uipbuf_get_last_header(uint8_t *buffer, uint16_t size, uint8_t *protocol)
148 nbuf = uipbuf_get_next_header(buffer, size, protocol,
true);
149 while(nbuf != NULL && uip_is_proto_ext_hdr(*protocol)) {
151 nbuf = uipbuf_get_next_header(nbuf, size - (nbuf - buffer), protocol,
false);
159 uipbuf_search_header(uint8_t *buffer, uint16_t size, uint8_t protocol)
164 nbuf = uipbuf_get_next_header(buffer, size, &next_proto,
true);
165 while(nbuf != NULL && next_proto != protocol && uip_is_proto_ext_hdr(next_proto)) {
167 nbuf = uipbuf_get_next_header(nbuf, size - (nbuf - buffer), &next_proto,
false);
170 if(next_proto == protocol) {
183 uipbuf_get_attr(uint8_t type)
185 if(type < UIPBUF_ATTR_MAX) {
186 return uipbuf_attrs[type];
192 uipbuf_set_attr(uint8_t type, uint16_t value)
194 if(type < UIPBUF_ATTR_MAX) {
195 uipbuf_attrs[type] = value;
202 uipbuf_set_default_attr(uint8_t type, uint16_t value)
204 if(type < UIPBUF_ATTR_MAX) {
205 uipbuf_default_attrs[type] = value;
212 uipbuf_clear_attr(
void)
215 memcpy(uipbuf_attrs, uipbuf_default_attrs,
sizeof(uipbuf_attrs));
219 uipbuf_set_attr_flag(uint16_t flag)
222 uipbuf_attrs[UIPBUF_ATTR_FLAGS] |= flag;
226 uipbuf_clr_attr_flag(uint16_t flag)
228 uipbuf_attrs[UIPBUF_ATTR_FLAGS] &= ~flag;
232 uipbuf_is_attr_flag(uint16_t flag)
234 return (uipbuf_attrs[UIPBUF_ATTR_FLAGS] & flag) == flag;
240 memset(uipbuf_default_attrs, 0,
sizeof(uipbuf_default_attrs));
242 uipbuf_set_default_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS,
246 uipbuf_set_default_attr(UIPBUF_ATTR_LLSEC_LEVEL,
247 UIPBUF_ATTR_LLSEC_LEVEL_MAC_DEFAULT);
uint8_t uip_last_proto
The final protocol after IPv6 extension headers: UIP_PROTO_TCP, UIP_PROTO_UDP or UIP_PROTO_ICMP6.
uint16_t uip_len
The length of the packet in the uip_buf buffer.
#define UIP_MAX_MAC_TRANSMISSIONS_UNDEFINED
This is the default value of MAC-layer transmissons for uIPv6.
#define UIP_LINK_MTU
The maximum transmission unit at the IP Layer.
static void start(void)
Start measurement.
uint16_t uip_ext_len
The length of the extension headers.
Header file for the uIP TCP/IP stack.