Merge branch 'release-4.1' into contrib/coap-block2-offset
This commit is contained in:
commit
5e753f73d0
@ -1115,13 +1115,10 @@ coap_set_header_size1(coap_message_t *coap_pkt, uint32_t size)
|
||||
int
|
||||
coap_get_payload(coap_message_t *coap_pkt, const uint8_t **payload)
|
||||
{
|
||||
if(coap_pkt->payload) {
|
||||
if(payload != NULL) {
|
||||
*payload = coap_pkt->payload;
|
||||
return coap_pkt->payload_len;
|
||||
} else {
|
||||
*payload = NULL;
|
||||
return 0;
|
||||
}
|
||||
return coap_pkt->payload != NULL ? coap_pkt->payload_len : 0;
|
||||
}
|
||||
int
|
||||
coap_set_payload(coap_message_t *coap_pkt, const void *payload, size_t length)
|
||||
|
@ -97,6 +97,7 @@
|
||||
|
||||
/* define the buffer as a byte array */
|
||||
#define PACKETBUF_IPHC_BUF ((uint8_t *)(packetbuf_ptr + packetbuf_hdr_len))
|
||||
#define PACKETBUF_PAYLOAD_END ((uint8_t *)(packetbuf_ptr + mac_max_payload))
|
||||
|
||||
#define PACKETBUF_6LO_PTR (packetbuf_ptr + packetbuf_hdr_len)
|
||||
#define PACKETBUF_6LO_DISPATCH 0 /* 8 bit */
|
||||
@ -197,6 +198,11 @@ static int packetbuf_payload_len;
|
||||
*/
|
||||
static uint8_t uncomp_hdr_len;
|
||||
|
||||
/**
|
||||
* mac_max_payload is the maimum payload space on the MAC frame.
|
||||
*/
|
||||
static int mac_max_payload;
|
||||
|
||||
/**
|
||||
* The current page (RFC 4944)
|
||||
*/
|
||||
@ -663,8 +669,9 @@ uncompress_addr(uip_ipaddr_t *ipaddr, uint8_t const prefix[],
|
||||
* compress the IID.
|
||||
* \param link_destaddr L2 destination address, needed to compress IP
|
||||
* dest
|
||||
* \return 1 if success, else 0
|
||||
*/
|
||||
static void
|
||||
static int
|
||||
compress_hdr_iphc(linkaddr_t *link_destaddr)
|
||||
{
|
||||
uint8_t tmp, iphc0, iphc1, *next_hdr, *next_nhc;
|
||||
@ -681,7 +688,23 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
|
||||
LOG_DBG_("\n");
|
||||
}
|
||||
|
||||
/* Macro used only internally, during header compression. Checks if there
|
||||
* is sufficient space in packetbuf before writing any further. */
|
||||
#define CHECK_BUFFER_SPACE(writelen) do { \
|
||||
if(hc06_ptr + (writelen) >= PACKETBUF_PAYLOAD_END) { \
|
||||
LOG_WARN("Not enough packetbuf space to compress header (%u bytes, %u left). Aborting.\n", \
|
||||
(unsigned)(writelen), (unsigned)(PACKETBUF_PAYLOAD_END - hc06_ptr)); \
|
||||
return 0; \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
hc06_ptr = PACKETBUF_IPHC_BUF + 2;
|
||||
|
||||
/* Check if there is enough space for the compressed IPv6 header, in the
|
||||
* worst case (least compressed case). Extension headers and transport
|
||||
* layer will be checked when they are compressed. */
|
||||
CHECK_BUFFER_SPACE(38);
|
||||
|
||||
/*
|
||||
* As we copy some bit-length fields, in the IPHC encoding bytes,
|
||||
* we sometimes use |=
|
||||
@ -910,11 +933,13 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
|
||||
NHC byte extra - before the next header here. This is due to
|
||||
next not being elided in that case. */
|
||||
if(!IS_COMPRESSABLE_PROTO(*next_hdr)) {
|
||||
CHECK_BUFFER_SPACE(1);
|
||||
hc06_ptr++;
|
||||
LOG_INFO("Keeping the next header in this ext hdr: %d\n",
|
||||
ext_hdr->next);
|
||||
}
|
||||
/* copy the ext-hdr into the hc06 buffer */
|
||||
CHECK_BUFFER_SPACE(len);
|
||||
memcpy(hc06_ptr, ext_hdr, len);
|
||||
/* modify the len to octets */
|
||||
ext_hdr = (struct uip_ext_hdr *) hc06_ptr;
|
||||
@ -944,6 +969,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
|
||||
/* we can compress 12 bits of both source and dest */
|
||||
*next_nhc = SICSLOWPAN_NHC_UDP_CS_P_11;
|
||||
LOG_INFO("IPHC: remove 12 b of both source & dest with prefix 0xFOB\n");
|
||||
CHECK_BUFFER_SPACE(1);
|
||||
*hc06_ptr =
|
||||
(uint8_t)((UIP_HTONS(udp_buf->srcport) -
|
||||
SICSLOWPAN_UDP_4_BIT_PORT_MIN) << 4) +
|
||||
@ -954,6 +980,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
|
||||
/* we can compress 8 bits of dest, leave source. */
|
||||
*next_nhc = SICSLOWPAN_NHC_UDP_CS_P_01;
|
||||
LOG_INFO("IPHC: leave source, remove 8 bits of dest with prefix 0xF0\n");
|
||||
CHECK_BUFFER_SPACE(3);
|
||||
memcpy(hc06_ptr, &udp_buf->srcport, 2);
|
||||
*(hc06_ptr + 2) =
|
||||
(uint8_t)((UIP_HTONS(udp_buf->destport) -
|
||||
@ -963,6 +990,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
|
||||
/* we can compress 8 bits of src, leave dest. Copy compressed port */
|
||||
*next_nhc = SICSLOWPAN_NHC_UDP_CS_P_10;
|
||||
LOG_INFO("IPHC: remove 8 bits of source with prefix 0xF0, leave dest. hch: %i\n", *next_nhc);
|
||||
CHECK_BUFFER_SPACE(3);
|
||||
*hc06_ptr =
|
||||
(uint8_t)((UIP_HTONS(udp_buf->srcport) -
|
||||
SICSLOWPAN_UDP_8_BIT_PORT_MIN));
|
||||
@ -972,10 +1000,12 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
|
||||
/* we cannot compress. Copy uncompressed ports, full checksum */
|
||||
*next_nhc = SICSLOWPAN_NHC_UDP_CS_P_00;
|
||||
LOG_INFO("IPHC: cannot compress UDP headers\n");
|
||||
CHECK_BUFFER_SPACE(4);
|
||||
memcpy(hc06_ptr, &udp_buf->srcport, 4);
|
||||
hc06_ptr += 4;
|
||||
}
|
||||
/* always inline the checksum */
|
||||
CHECK_BUFFER_SPACE(2);
|
||||
memcpy(hc06_ptr, &udp_buf->udpchksum, 2);
|
||||
hc06_ptr += 2;
|
||||
uncomp_hdr_len += UIP_UDPH_LEN;
|
||||
@ -1006,6 +1036,8 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
|
||||
}
|
||||
|
||||
packetbuf_hdr_len = hc06_ptr - packetbuf_ptr;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
@ -1477,7 +1509,6 @@ static uint8_t
|
||||
output(const linkaddr_t *localdest)
|
||||
{
|
||||
int framer_hdrlen;
|
||||
int max_payload;
|
||||
|
||||
/* The MAC address of the destination of the packet */
|
||||
linkaddr_t dest;
|
||||
@ -1513,6 +1544,20 @@ output(const linkaddr_t *localdest)
|
||||
packetbuf_set_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS,
|
||||
uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS));
|
||||
|
||||
/* Calculate NETSTACK_FRAMER's header length, that will be added in the NETSTACK_MAC */
|
||||
#ifndef SICSLOWPAN_USE_FIXED_HDRLEN
|
||||
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &dest);
|
||||
framer_hdrlen = NETSTACK_FRAMER.length();
|
||||
if(framer_hdrlen < 0) {
|
||||
/* Framing failed, we assume the maximum header length */
|
||||
framer_hdrlen = SICSLOWPAN_FIXED_HDRLEN;
|
||||
}
|
||||
#else /* USE_FRAMER_HDRLEN */
|
||||
framer_hdrlen = SICSLOWPAN_FIXED_HDRLEN;
|
||||
#endif /* USE_FRAMER_HDRLEN */
|
||||
|
||||
mac_max_payload = MAC_MAX_PAYLOAD - framer_hdrlen;
|
||||
|
||||
/* Try to compress the headers */
|
||||
#if SICSLOWPAN_COMPRESSION == SICSLOWPAN_COMPRESSION_IPV6
|
||||
compress_hdr_ipv6(&dest);
|
||||
@ -1526,26 +1571,14 @@ output(const linkaddr_t *localdest)
|
||||
}
|
||||
#endif /* SICSLOWPAN_COMPRESSION == SICSLOWPAN_COMPRESSION_6LORH */
|
||||
#if SICSLOWPAN_COMPRESSION >= SICSLOWPAN_COMPRESSION_IPHC
|
||||
compress_hdr_iphc(&dest);
|
||||
if(compress_hdr_iphc(&dest) == 0) {
|
||||
/* Warning should already be issued by function above */
|
||||
return 0;
|
||||
}
|
||||
#endif /* SICSLOWPAN_COMPRESSION >= SICSLOWPAN_COMPRESSION_IPHC */
|
||||
LOG_INFO("output: header of len %d\n", packetbuf_hdr_len);
|
||||
|
||||
/* Calculate NETSTACK_FRAMER's header length, that will be added in the NETSTACK_MAC.
|
||||
* We calculate it here only to make a better decision of whether the outgoing packet
|
||||
* needs to be fragmented or not. */
|
||||
#ifndef SICSLOWPAN_USE_FIXED_HDRLEN
|
||||
packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &dest);
|
||||
framer_hdrlen = NETSTACK_FRAMER.length();
|
||||
if(framer_hdrlen < 0) {
|
||||
/* Framing failed, we assume the maximum header length */
|
||||
framer_hdrlen = SICSLOWPAN_FIXED_HDRLEN;
|
||||
}
|
||||
#else /* USE_FRAMER_HDRLEN */
|
||||
framer_hdrlen = SICSLOWPAN_FIXED_HDRLEN;
|
||||
#endif /* USE_FRAMER_HDRLEN */
|
||||
|
||||
max_payload = MAC_MAX_PAYLOAD - framer_hdrlen;
|
||||
if((int)uip_len - (int)uncomp_hdr_len > max_payload - (int)packetbuf_hdr_len) {
|
||||
if((int)uip_len - (int)uncomp_hdr_len > mac_max_payload - (int)packetbuf_hdr_len) {
|
||||
#if SICSLOWPAN_CONF_FRAG
|
||||
/* Number of bytes processed. */
|
||||
uint16_t processed_ip_out_len;
|
||||
@ -1560,7 +1593,7 @@ output(const linkaddr_t *localdest)
|
||||
* IPv6/IPHC/HC_UDP dispatchs/headers.
|
||||
* The following fragments contain only the fragn dispatch.
|
||||
*/
|
||||
int estimated_fragments = ((int)uip_len) / (max_payload - SICSLOWPAN_FRAGN_HDR_LEN) + 1;
|
||||
int estimated_fragments = ((int)uip_len) / (mac_max_payload - SICSLOWPAN_FRAGN_HDR_LEN) + 1;
|
||||
int freebuf = queuebuf_numfree() - 1;
|
||||
LOG_INFO("uip_len: %d, fragments: %d, free bufs: %d\n", uip_len, estimated_fragments, freebuf);
|
||||
if(freebuf < estimated_fragments) {
|
||||
@ -1590,8 +1623,17 @@ output(const linkaddr_t *localdest)
|
||||
|
||||
/* Copy payload and send */
|
||||
packetbuf_hdr_len += SICSLOWPAN_FRAG1_HDR_LEN;
|
||||
packetbuf_payload_len = (max_payload - packetbuf_hdr_len) & 0xfffffff8;
|
||||
packetbuf_payload_len = (mac_max_payload - packetbuf_hdr_len) & 0xfffffff8;
|
||||
LOG_INFO_("(len %d, tag %d)\n", packetbuf_payload_len, frag_tag);
|
||||
|
||||
if(packetbuf_payload_len < 0) {
|
||||
/* The current implementation requires that all headers fit in the first
|
||||
* fragment. Here is a corner case where the header did fit packetbuf
|
||||
* but do no longer fit after truncating for a length multiple of 8. */
|
||||
LOG_WARN("compressed header does not fit first fragment\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(packetbuf_ptr + packetbuf_hdr_len,
|
||||
(uint8_t *)UIP_IP_BUF + uncomp_hdr_len, packetbuf_payload_len);
|
||||
packetbuf_set_datalen(packetbuf_payload_len + packetbuf_hdr_len);
|
||||
@ -1626,7 +1668,7 @@ output(const linkaddr_t *localdest)
|
||||
/* uip_htons((SICSLOWPAN_DISPATCH_FRAGN << 8) | uip_len); */
|
||||
SET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_DISPATCH_SIZE,
|
||||
((SICSLOWPAN_DISPATCH_FRAGN << 8) | uip_len));
|
||||
packetbuf_payload_len = (max_payload - packetbuf_hdr_len) & 0xfffffff8;
|
||||
packetbuf_payload_len = (mac_max_payload - packetbuf_hdr_len) & 0xfffffff8;
|
||||
while(processed_ip_out_len < uip_len) {
|
||||
LOG_INFO("output: fragment ");
|
||||
PACKETBUF_FRAG_PTR[PACKETBUF_FRAG_OFFSET] = processed_ip_out_len >> 3;
|
||||
|
@ -395,9 +395,15 @@ process_dio_from_current_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the DIO sender is on an older version of the DAG, ignore it. The node
|
||||
will eventually hear the global repair and catch up. */
|
||||
/* If the DIO sender is on an older version of the DAG, do not process it
|
||||
* further. The sender will eventually hear the global repair and catch up. */
|
||||
if(rpl_lollipop_greater_than(curr_instance.dag.version, dio->version)) {
|
||||
if(dio->rank == ROOT_RANK) {
|
||||
/* Before returning, if the DIO was from the root, an old DAG versions
|
||||
* likely incidates a root reboot. Reset our DIO timer to make sure the
|
||||
* root hears our version ASAP, and in turn triggers a global repair. */
|
||||
rpl_timers_dio_reset("Heard old version from root");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -412,10 +418,12 @@ process_dio_from_current_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
|
||||
* Must come first, as it might remove all neighbors, and we then need
|
||||
* to re-add this source of the DIO to the neighbor table */
|
||||
if(rpl_lollipop_greater_than(dio->version, curr_instance.dag.version)) {
|
||||
if(curr_instance.dag.rank == ROOT_RANK) { /* The root should not hear newer versions */
|
||||
if(curr_instance.dag.rank == ROOT_RANK) {
|
||||
/* The root should not hear newer versions unless it just rebooted */
|
||||
LOG_ERR("inconsistent DIO version (current: %u, received: %u), initiate global repair\n",
|
||||
curr_instance.dag.version, dio->version);
|
||||
curr_instance.dag.version = dio->version; /* Update version and trigger global repair */
|
||||
/* Update version and trigger global repair */
|
||||
curr_instance.dag.version = dio->version;
|
||||
rpl_global_repair("Inconsistent DIO version");
|
||||
} else {
|
||||
LOG_WARN("new DIO version (current: %u, received: %u), apply global repair\n",
|
||||
|
Loading…
Reference in New Issue
Block a user