6loWPAN: Fix a pointer initialization problem.

This commit is contained in:
Gregory Nutt 2017-04-04 07:22:59 -06:00
parent 9daf0dca0c
commit 88fd667603
6 changed files with 137 additions and 132 deletions

View file

@ -102,6 +102,7 @@
* Input Parameters:
* ieee - Pointer to IEEE802.15.4 MAC driver structure.
* destip - Pointer to the IPv6 header to "compress"
* fptr - Pointer to the beginning of the frame under construction
*
* Returned Value:
* None
@ -109,17 +110,18 @@
****************************************************************************/
static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *destip)
FAR const struct ipv6_hdr_s *destip,
FAR uint8_t *fptr)
{
/* Indicate the IPv6 dispatch and length */
*g_rimeptr = SIXLOWPAN_DISPATCH_IPV6;
g_rime_hdrlen += SIXLOWPAN_IPV6_HDR_LEN;
*fptr = SIXLOWPAN_DISPATCH_IPV6;
g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN;
/* Copy the IPv6 header and adjust pointers */
memcpy(g_rimeptr + g_rime_hdrlen, destip, IPv6_HDRLEN);
g_rime_hdrlen += IPv6_HDRLEN;
memcpy(fptr + g_frame_hdrlen, destip, IPv6_HDRLEN);
g_frame_hdrlen += IPv6_HDRLEN;
g_uncomp_hdrlen += IPv6_HDRLEN;
}
@ -165,6 +167,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
FAR const struct rimeaddr_s *destmac)
{
FAR struct iob_s *iob;
FAR uint8_t *fptr;
int framer_hdrlen;
struct rimeaddr_s bcastmac;
uint16_t outlen = 0;
@ -175,9 +178,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
FRAME_RESET();
g_uncomp_hdrlen = 0;
g_rime_hdrlen = 0;
/* REVISIT: Do I need this rimeptr? */
g_rimeptr = &ieee->i_dev.d_buf[PACKETBUF_HDR_SIZE];
g_frame_hdrlen = 0;
/* Reset rime buffer, packet buffer metatadata */
@ -228,6 +229,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
iob->io_len = 0;
iob->io_offset = 0;
iob->io_pktlen = 0;
fptr = iob->io_data;
ninfo("Sending packet len %d\n", len);
@ -237,9 +239,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
/* Try to compress the headers */
#if defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC1)
sixlowpan_compresshdr_hc1(ieee, destip, destmac, iob);
sixlowpan_compresshdr_hc1(ieee, destip, destmac, fptr);
#elif defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC06)
sixlowpan_compresshdr_hc06(ieee, destip, destmac, iob);
sixlowpan_compresshdr_hc06(ieee, destip, destmac, fptr);
#else
# error No compression specified
#endif
@ -249,10 +251,10 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
{
/* Small.. use IPv6 dispatch (no compression) */
sixlowpan_compress_ipv6hdr(ieee, destip);
sixlowpan_compress_ipv6hdr(ieee, destip, fptr);
}
ninfo("Header of len %d\n", g_rime_hdrlen);
ninfo("Header of len %d\n", g_frame_hdrlen);
rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], destmac);
@ -271,7 +273,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
if ((int)len - (int)g_uncomp_hdrlen >
(int)CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen -
(int)g_rime_hdrlen)
(int)g_frame_hdrlen)
{
#if CONFIG_NET_6LOWPAN_FRAG
/* ieee->i_framelist will hold the generated frames; frames will be
@ -299,7 +301,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
/* Move HC1/HC06/IPv6 header */
memmove(g_rimeptr + SIXLOWPAN_FRAG1_HDR_LEN, g_rimeptr, g_rime_hdrlen);
memmove(fptr + SIXLOWPAN_FRAG1_HDR_LEN, fptr, g_frame_hdrlen);
/* Setup up the fragment header.
*
@ -316,20 +318,20 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
* bytes for all subsequent headers.
*/
PUTINT16(RIME_FRAG_PTR, RIME_FRAG_DISPATCH_SIZE,
PUTINT16(fptr, RIME_FRAG_DISPATCH_SIZE,
((SIXLOWPAN_DISPATCH_FRAG1 << 8) | len));
PUTINT16(RIME_FRAG_PTR, RIME_FRAG_TAG, ieee->i_dgramtag);
PUTINT16(fptr, RIME_FRAG_TAG, ieee->i_dgramtag);
ieee->i_dgramtag++;
/* Copy payload and enqueue */
g_rime_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN;
g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN;
g_rime_payloadlen =
(CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - g_rime_hdrlen) & 0xf8;
(CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - g_frame_hdrlen) & 0xf8;
memcpy(g_rimeptr + g_rime_hdrlen,
memcpy(fptr + g_frame_hdrlen,
(FAR uint8_t *)destip + g_uncomp_hdrlen, g_rime_payloadlen);
iob->io_len += g_rime_payloadlen + g_rime_hdrlen;
iob->io_len += g_rime_payloadlen + g_frame_hdrlen;
/* Set outlen to what we already sent from the IP payload */
@ -349,7 +351,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
/* Create following fragments */
g_rime_hdrlen = SIXLOWPAN_FRAGN_HDR_LEN;
g_frame_hdrlen = SIXLOWPAN_FRAGN_HDR_LEN;
while (outlen < len)
{
@ -366,6 +368,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
iob->io_len = 0;
iob->io_offset = 0;
iob->io_pktlen = 0;
fptr = iob->io_data;
/* Add the frame header */
@ -375,14 +378,14 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
/* Move HC1/HC06/IPv6 header */
memmove(g_rimeptr + SIXLOWPAN_FRAGN_HDR_LEN, g_rimeptr, g_rime_hdrlen);
memmove(fptr + SIXLOWPAN_FRAGN_HDR_LEN, fptr, g_frame_hdrlen);
/* Setup up the fragment header */
PUTINT16(RIME_FRAG_PTR, RIME_FRAG_DISPATCH_SIZE,
PUTINT16(fptr, RIME_FRAG_DISPATCH_SIZE,
((SIXLOWPAN_DISPATCH_FRAGN << 8) | len));
PUTINT16(RIME_FRAG_PTR, RIME_FRAG_TAG, ieee->i_dgramtag);
RIME_FRAG_PTR[RIME_FRAG_OFFSET] = outlen >> 3;
PUTINT16(fptr, RIME_FRAG_TAG, ieee->i_dgramtag);
fptr[RIME_FRAG_OFFSET] = outlen >> 3;
/* Copy payload and enqueue */
@ -395,12 +398,12 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
else
{
g_rime_payloadlen =
(CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - g_rime_hdrlen) & 0xf8;
(CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - g_frame_hdrlen) & 0xf8;
}
memcpy(g_rimeptr + g_rime_hdrlen, (FAR uint8_t *)destip + outlen,
memcpy(fptr + g_frame_hdrlen, (FAR uint8_t *)destip + outlen,
g_rime_payloadlen);
iob->io_len = g_rime_payloadlen + g_rime_hdrlen;
iob->io_len = g_rime_payloadlen + g_frame_hdrlen;
/* Set outlen to what we already sent from the IP payload */
@ -441,9 +444,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
/* Copy the payload and queue */
memcpy(g_rimeptr + g_rime_hdrlen, (FAR uint8_t *)destip + g_uncomp_hdrlen,
memcpy(fptr + g_frame_hdrlen, (FAR uint8_t *)destip + g_uncomp_hdrlen,
len - g_uncomp_hdrlen);
iob->io_len = len - g_uncomp_hdrlen + g_rime_hdrlen;
iob->io_len = len - g_uncomp_hdrlen + g_frame_hdrlen;
/* Add the first frame to the IOB queue */

View file

@ -54,14 +54,6 @@
* during that processing
*/
/* A pointer to the rime buffer.
*
* We initialize it to the beginning of the rime buffer, then access
* different fields by updating the offset ieee->g_rime_hdrlen.
*/
FAR uint8_t *g_rimeptr;
/* The length of the payload in the Rime buffer.
*
* The payload is what comes after the compressed or uncompressed headers
@ -77,12 +69,12 @@ uint8_t g_rime_payloadlen;
uint8_t g_uncomp_hdrlen;
/* g_rime_hdrlen is the total length of (the processed) 6lowpan headers
/* g_frame_hdrlen is the total length of (the processed) 6lowpan headers
* (fragment headers, IPV6 or HC1, HC2, and HC1 and HC2 non compressed
* fields).
*/
uint8_t g_rime_hdrlen;
uint8_t g_frame_hdrlen;
/* Offset first available byte for the payload after header region. */

View file

@ -437,7 +437,7 @@ void sixlowpan_hc06_initialize(void)
* ipv6 - The IPv6 header to be compressed
* destmac - L2 destination address, needed to compress the IP
* destination field
* iob - The IOB into which the compressed header should be saved.
* fptr - Pointer to frame data payload.
*
* Returned Value:
* None
@ -447,9 +447,9 @@ void sixlowpan_hc06_initialize(void)
void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct rimeaddr_s *destmac,
FAR struct iob_s *iob)
FAR uint8_t *fptr)
{
FAR uint8_t *iphc = RIME_IPHC_BUF;
FAR uint8_t *iphc = fptr + g_frame_hdrlen;
FAR struct sixlowpan_addrcontext_s *addrcontext;
uint8_t iphc0;
uint8_t iphc1;
@ -458,7 +458,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
ninfodumpbuffer("IPv6 before compression", (FAR const uint8_t *)ipv6,
sizeof(struct ipv6_hdr_s));
g_hc06ptr = g_rimeptr + 2;
g_hc06ptr = fptr + 2;
/* As we copy some bit-length fields, in the IPHC encoding bytes,
* we sometimes use |=
@ -803,12 +803,12 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
}
#endif /* CONFIG_NET_UDP */
/* Before the g_rime_hdrlen operation */
/* Before the g_frame_hdrlen operation */
iphc[0] = iphc0;
iphc[1] = iphc1;
g_rime_hdrlen = g_hc06ptr - g_rimeptr;
g_frame_hdrlen = g_hc06ptr - fptr;
return;
}
@ -822,14 +822,16 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
* This function is called by the input function when the dispatch is HC06.
* We process the packet in the rime buffer, uncompress the header fields,
* and copy the result in the sixlowpan buffer. At the end of the
* decompression, g_rime_hdrlen and g_uncompressed_hdrlen are set to the
* decompression, g_frame_hdrlen and g_uncompressed_hdrlen are set to the
* appropriate values
*
* Input Parmeters:
* ieee - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a first
* fragment.
* ieee - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a first
* fragment.
* iob - Pointer to the IOB containing the received frame.
* payptr - Pointer to the frame data payload.
*
* Returned Value:
* None
@ -837,17 +839,18 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
****************************************************************************/
void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
uint16_t iplen)
uint16_t iplen, FAR struct iob_s *iob,
FAR char *payptr)
{
FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(ieee);
FAR uint8_t *iphc = RIME_IPHC_BUF;
FAR uint8_t *iphc = payptr + g_frame_hdrlen;
uint8_t iphc0;
uint8_t iphc1;
uint8_t tmp;
/* At least two byte will be used for the encoding */
g_hc06ptr = g_rimeptr + g_rime_hdrlen + 2;
g_hc06ptr = payptr + g_frame_hdrlen + 2;
iphc0 = iphc[0];
iphc1 = iphc[1];
@ -1153,7 +1156,7 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
}
}
g_rime_hdrlen = g_hc06ptr - g_rimeptr;
g_frame_hdrlen = g_hc06ptr - payptr;
/* IP length field. */
@ -1162,7 +1165,8 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
/* This is not a fragmented packet */
ipv6->len[0] = 0;
ipv6->len[1] = ieee->i_dev.d_len - g_rime_hdrlen + g_uncomp_hdrlen - IPv6_HDRLEN;
ipv6->len[1] = iob->io_len - g_frame_hdrlen + g_uncomp_hdrlen -
IPv6_HDRLEN;
}
else
{

View file

@ -119,7 +119,7 @@
* ipv6 - The IPv6 header to be compressed
* destmac - L2 destination address, needed to compress the IP
* destination field
* iob - The IOB into which the compressed header should be saved.
* fptr - Pointer to frame data payload.
*
* Returned Value:
* None
@ -129,9 +129,9 @@
void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct rimeaddr_s *destmac,
FAR struct iob_s *iob)
FAR uint8_t *fptr)
{
FAR uint8_t *hc1 = RIME_HC1_PTR;
FAR uint8_t *hc1 = fptr + g_frame_hdrlen;
/* Check if all the assumptions for full compression are valid */
@ -148,10 +148,10 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
* compress nothing, copy IPv6 header in rime buffer
*/
*g_rimeptr = SIXLOWPAN_DISPATCH_IPV6;
g_rime_hdrlen += SIXLOWPAN_IPV6_HDR_LEN;
memcpy(g_rimeptr + g_rime_hdrlen, ipv6, IPv6_HDRLEN);
g_rime_hdrlen += IPv6_HDRLEN;
*fptr = SIXLOWPAN_DISPATCH_IPV6;
g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN;
memcpy(fptr + g_frame_hdrlen, ipv6, IPv6_HDRLEN);
g_frame_hdrlen += IPv6_HDRLEN;
g_uncomp_hdrlen += IPv6_HDRLEN;
}
else
@ -170,7 +170,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
hc1[RIME_HC1_ENCODING] = 0xfc;
hc1[RIME_HC1_TTL] = ipv6->ttl;
g_rime_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
break;
#if CONFIG_NET_TCP
@ -179,7 +179,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
hc1[RIME_HC1_ENCODING] = 0xfe;
hc1[RIME_HC1_TTL] = ipv6->ttl;
g_rime_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
break;
#endif /* CONFIG_NET_TCP */
@ -201,7 +201,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
htons(udp->destport) >= CONFIG_NET_6LOWPAN_MINPORT &&
htons(udp->destport) < (CONFIG_NET_6LOWPAN_MINPORT + 16))
{
FAR uint8_t *hcudp = RIME_HC1_HC_UDP_PTR;
FAR uint8_t *hcudp = fptr + g_frame_hdrlen;
/* HC1 encoding */
@ -217,7 +217,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
memcpy(&hcudp[RIME_HC1_HC_UDP_CHKSUM], &udp->udpchksum, 2);
g_rime_hdrlen += SIXLOWPAN_HC1_HC_UDP_HDR_LEN;
g_frame_hdrlen += SIXLOWPAN_HC1_HC_UDP_HDR_LEN;
g_uncomp_hdrlen += UDP_HDRLEN;
}
else
@ -226,7 +226,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
hc1[RIME_HC1_ENCODING] = 0xfa;
hc1[RIME_HC1_TTL] = ipv6->ttl;
g_rime_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
}
}
break;
@ -244,14 +244,16 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
* This function is called by the input function when the dispatch is
* HC1. It processes the packet in the rime buffer, uncompresses the
* header fields, and copies the result in the sixlowpan buffer. At the
* end of the decompression, g_rime_hdrlen and uncompressed_hdr_len
* end of the decompression, g_frame_hdrlen and uncompressed_hdr_len
* are set to the appropriate values
*
* Input Parameters:
* ieee - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a 1st
* fragment.
* ieee - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a 1st
* fragment.
* iob - Pointer to the IOB containing the received frame.
* payptr - Pointer to the frame data payload.
*
* Returned Value:
* Zero (OK) is returned on success, on failure a negater errno value is
@ -260,10 +262,11 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
****************************************************************************/
int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
uint16_t iplen)
uint16_t iplen, FAR struct iob_s *iob,
FAR uint8_t *payptr)
{
FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(&ieee->i_dev);
FAR uint8_t *hc1 = RIME_HC1_PTR;
FAR uint8_t *hc1 = payptr + g_frame_hdrlen;
/* Format the IPv6 header in the device d_buf */
/* Set version, traffic clase, and flow label */
@ -287,16 +290,16 @@ int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
switch (hc1[RIME_HC1_ENCODING] & 0x06)
{
case SIXLOWPAN_HC1_NH_ICMP6:
ipv6->proto = IP_PROTO_ICMP6;
ipv6->ttl = hc1[RIME_HC1_TTL];
g_rime_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
ipv6->proto = IP_PROTO_ICMP6;
ipv6->ttl = hc1[RIME_HC1_TTL];
g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
break;
#if CONFIG_NET_TCP
case SIXLOWPAN_HC1_NH_TCP:
ipv6->proto = IP_PROTO_TCP;
ipv6->ttl = hc1[RIME_HC1_TTL];
g_rime_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
ipv6->proto = IP_PROTO_TCP;
ipv6->ttl = hc1[RIME_HC1_TTL];
g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
break;
#endif /* CONFIG_NET_TCP */
@ -304,7 +307,7 @@ int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
case SIXLOWPAN_HC1_NH_UDP:
{
FAR struct udp_hdr_s *udp = UDPIPv6BUF(&ieee->i_dev);
FAR uint8_t *hcudp = RIME_HC1_HC_UDP_PTR;
FAR uint8_t *hcudp = payptr + g_frame_hdrlen;
ipv6->proto = IP_PROTO_UDP;
if ((hcudp[RIME_HC1_HC_UDP_HC1_ENCODING] & 0x01) != 0)
@ -332,11 +335,11 @@ int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
memcpy(&udp->udpchksum, &hcudp[RIME_HC1_HC_UDP_CHKSUM], 2);
g_uncomp_hdrlen += UDP_HDRLEN;
g_rime_hdrlen += SIXLOWPAN_HC1_HC_UDP_HDR_LEN;
g_frame_hdrlen += SIXLOWPAN_HC1_HC_UDP_HDR_LEN;
}
else
{
g_rime_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
}
}
break;
@ -353,8 +356,8 @@ int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
/* This is not a fragmented packet */
ipv6->len[0] = 0;
ipv6->len[1] = ieee->i_dev.d_len - g_rime_hdrlen + /* REVISIT */
g_uncomp_hdrlen - IPv6_HDRLEN;
ipv6->len[1] = iob->io_len - g_frame_hdrlen + g_uncomp_hdrlen -
IPv6_HDRLEN;
}
else
{
@ -364,9 +367,9 @@ int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
ipv6->len[1] = (iplen - IPv6_HDRLEN) & 0x00FF;
}
/* length field in UDP header */
#if CONFIG_NET_UDP
/* Length field in UDP header */
if (ipv6->proto == IP_PROTO_UDP)
{
FAR struct udp_hdr_s *udp = UDPIPv6BUF(&ieee->i_dev);

View file

@ -121,7 +121,8 @@
static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
FAR struct iob_s *iob)
{
FAR uint8_t *hc1 = RIME_HC1_PTR;
FAR uint8_t *payptr; /* Pointer to the frame payload */
FAR uint8_t *hc1; /* Convenience pointer to HC1 data */
uint16_t fragsize = 0; /* Size of the IP packet (read from fragment) */
uint8_t fragoffset = 0; /* Offset of the fragment in the IP packet */
@ -140,11 +141,11 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
*/
g_uncomp_hdrlen = 0;
g_rime_hdrlen = 0;
g_frame_hdrlen = 0;
/* The MAC puts the 15.4 payload inside the RIME data buffer */
g_rimeptr = &iob->io_data[PACKETBUF_HDR_SIZE];
payptr = &iob->io_data[PACKETBUF_HDR_SIZE];
#if CONFIG_NET_6LOWPAN_FRAG
/* If reassembly timed out, cancel it */
@ -161,7 +162,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
* we look for is the fragmentation header
*/
switch ((GETINT16(RIME_FRAG_PTR, RIME_FRAG_DISPATCH_SIZE) & 0xf800) >> 8)
switch ((GETINT16(payptr, RIME_FRAG_DISPATCH_SIZE) & 0xf800) >> 8)
{
/* First fragment of new reassembly */
@ -170,13 +171,13 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
/* Set up for the reassembly */
fragoffset = 0;
fragsize = GETINT16(RIME_FRAG_PTR, RIME_FRAG_DISPATCH_SIZE) & 0x07ff;
fragtag = GETINT16(RIME_FRAG_PTR, RIME_FRAG_TAG);
fragsize = GETINT16(payptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff;
fragtag = GETINT16(payptr, RIME_FRAG_TAG);
ninfo("FRAG1: size %d, tag %d, offset %d\n",
fragsize, fragtag, fragoffset);
g_rime_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN;
g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN;
/* Indicate the first fragment of the reassembly */
@ -189,17 +190,17 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
{
/* Set offset, tag, size. Offset is in units of 8 bytes. */
fragoffset = RIME_FRAG_PTR[RIME_FRAG_OFFSET];
fragtag = GETINT16(RIME_FRAG_PTR, RIME_FRAG_TAG);
fragsize = GETINT16(RIME_FRAG_PTR, RIME_FRAG_DISPATCH_SIZE) & 0x07ff;
fragoffset = payptr[RIME_FRAG_OFFSET];
fragtag = GETINT16(payptr, RIME_FRAG_TAG);
fragsize = GETINT16(payptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff;
ninfo("FRAGN: size %d, tag %d, offset %d\n",
fragsize, fragtag, fragoffset);
g_rime_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN;
g_frame_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN;
ninfo("islastfrag?: i_accumlen %d g_rime_payloadlen %d fragsize %d\n",
ieee->i_accumlen, iob->io_len - g_rime_hdrlen, fragsize);
ieee->i_accumlen, iob->io_len - g_frame_hdrlen, fragsize);
/* Indicate that this frame is a another fragment for reassembly */
@ -211,7 +212,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
* bytes at the end. We must be liberal in what we accept.
*/
if (ieee->i_accumlen + iob->io_len - g_rime_hdrlen >= fragsize)
if (ieee->i_accumlen + iob->io_len - g_frame_hdrlen >= fragsize)
{
islastfrag = true;
}
@ -339,11 +340,13 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
/* Process next dispatch and headers */
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
hc1 = payptr + g_frame_hdrlen;
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
if ((hc1[RIME_HC1_DISPATCH] & SIXLOWPAN_DISPATCH_IPHC_MASK) == SIXLOWPAN_DISPATCH_IPHC)
{
ninfo("IPHC Dispatch\n");
sixlowpan_uncompresshdr_hc06(ieee, fragsize);
sixlowpan_uncompresshdr_hc06(ieee, fragsize, iob, payptr);
}
else
#endif /* CONFIG_NET_6LOWPAN_COMPRESSION_HC06 */
@ -352,22 +355,22 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_HC1)
{
ninfo("HC1 Dispatch\n");
sixlowpan_uncompresshdr_hc1(ieee, fragsize);
sixlowpan_uncompresshdr_hc1(ieee, fragsize, iob, payptr);
}
else
#endif /* CONFIG_NET_6LOWPAN_COMPRESSION_HC1 */
if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_IPV6)
{
ninfo("IPV6 Dispatch\n");
g_rime_hdrlen += SIXLOWPAN_IPV6_HDR_LEN;
g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN;
/* Put uncompressed IP header in d_buf. */
memcpy(ieee->i_dev.d_buf, g_rimeptr + g_rime_hdrlen, IPv6_HDRLEN);
memcpy(ieee->i_dev.d_buf, payptr + g_frame_hdrlen, IPv6_HDRLEN);
/* Update g_uncomp_hdrlen and g_rime_hdrlen. */
/* Update g_uncomp_hdrlen and g_frame_hdrlen. */
g_rime_hdrlen += IPv6_HDRLEN;
g_frame_hdrlen += IPv6_HDRLEN;
g_uncomp_hdrlen += IPv6_HDRLEN;
}
else
@ -384,17 +387,17 @@ copypayload:
/* Copy "payload" from the rime buffer to the d_buf. If this frame is a
* first fragment or not part of a fragmented packet, we have already
* copied the compressed headers, g_uncomp_hdrlen and g_rime_hdrlen are
* copied the compressed headers, g_uncomp_hdrlen and g_frame_hdrlen are
* non-zerio, fragoffset is.
*/
if (ieee->i_dev.d_len < g_rime_hdrlen)
if (ieee->i_dev.d_len < g_frame_hdrlen)
{
ninfo("SIXLOWPAN: packet dropped due to header > total packet\n");
return OK;
}
g_rime_payloadlen = ieee->i_dev.d_len - g_rime_hdrlen;
g_rime_payloadlen = ieee->i_dev.d_len - g_frame_hdrlen;
/* Sanity-check size of incoming packet to avoid buffer overflow */
@ -408,7 +411,7 @@ copypayload:
}
memcpy((FAR uint8_t *)ieee->i_dev.d_buf + g_uncomp_hdrlen +
(int)(fragoffset << 3), g_rimeptr + g_rime_hdrlen,
(int)(fragoffset << 3), payptr + g_frame_hdrlen,
g_rime_payloadlen);
#if CONFIG_NET_6LOWPAN_FRAG

View file

@ -100,21 +100,16 @@
* bytes for all subsequent headers.
*/
#define RIME_FRAG_PTR g_rimeptr
#define RIME_FRAG_DISPATCH_SIZE 0 /* 16 bit */
#define RIME_FRAG_TAG 2 /* 16 bit */
#define RIME_FRAG_OFFSET 4 /* 8 bit */
/* Define the Rime buffer as a byte array */
#define RIME_IPHC_BUF (g_rimeptr + g_rime_hdrlen)
#define RIME_HC1_PTR (g_rimeptr + g_rime_hdrlen)
#define RIME_HC1_DISPATCH 0 /* 8 bit */
#define RIME_HC1_ENCODING 1 /* 8 bit */
#define RIME_HC1_TTL 2 /* 8 bit */
#define RIME_HC1_HC_UDP_PTR (g_rimeptr + g_rime_hdrlen)
#define RIME_HC1_HC_UDP_DISPATCH 0 /* 8 bit */
#define RIME_HC1_HC_UDP_HC1_ENCODING 1 /* 8 bit */
#define RIME_HC1_HC_UDP_UDP_ENCODING 2 /* 8 bit */
@ -408,7 +403,7 @@ struct frame802154_s
/* A pointer to the rime buffer.
*
* We initialize it to the beginning of the rime buffer, then access
* different fields by updating the offset ieee->g_rime_hdrlen.
* different fields by updating the offset ieee->g_frame_hdrlen.
*/
extern FAR uint8_t *g_rimeptr;
@ -428,12 +423,12 @@ extern uint8_t g_rime_payloadlen;
extern uint8_t g_uncomp_hdrlen;
/* g_rime_hdrlen is the total length of (the processed) 6lowpan headers
/* g_frame_hdrlen is the total length of (the processed) 6lowpan headers
* (fragment headers, IPV6 or HC1, HC2, and HC1 and HC2 non compressed
* fields).
*/
extern uint8_t g_rime_hdrlen;
extern uint8_t g_frame_hdrlen;
/* Offset first available byte for the payload after header region. */
@ -621,7 +616,7 @@ void sixlowpan_hc06_initialize(void);
* ipv6 - The IPv6 header to be compressed
* destmac - L2 destination address, needed to compress the IP
* destination field
* iob - The IOB into which the compressed header should be saved.
* fptr - Pointer to frame data payload.
*
* Returned Value:
* None
@ -632,7 +627,7 @@ void sixlowpan_hc06_initialize(void);
void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct rimeaddr_s *destmac,
FAR struct iob_s *iob);
FAR uint8_t *fptr);
#endif
/****************************************************************************
@ -645,14 +640,16 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
* This function is called by the input function when the dispatch is HC06.
* We process the packet in the rime buffer, uncompress the header fields,
* and copy the result in the sixlowpan buffer. At the end of the
* decompression, g_rime_hdrlen and g_uncompressed_hdrlen are set to the
* decompression, g_frame_hdrlen and g_uncompressed_hdrlen are set to the
* appropriate values
*
* Input Parmeters:
* ieee - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a first
* fragment.
* ieee - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a first
* fragment.
* iob - Pointer to the IOB containing the received frame.
* payptr - Pointer to the frame data payload.
*
* Returned Value:
* None
@ -661,7 +658,8 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
uint16_t iplen);
uint16_t iplen, FAR struct iob_s *iob,
FAR uint8_t *payptr);
#endif
/****************************************************************************
@ -679,7 +677,6 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
* ipv6 - The IPv6 header to be compressed
* destmac - L2 destination address, needed to compress the IP
* destination field
* iob - The IOB into which the compressed header should be saved.
*
* Returned Value:
* None
@ -690,7 +687,7 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct rimeaddr_s *destmac,
FAR struct iob_s *iob);
FAR uint8_t *fptr);
#endif
/****************************************************************************
@ -702,7 +699,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
* This function is called by the input function when the dispatch is
* HC1. It processes the packet in the rime buffer, uncompresses the
* header fields, and copies the result in the sixlowpan buffer. At the
* end of the decompression, g_rime_hdrlen and uncompressed_hdr_len
* end of the decompression, g_frame_hdrlen and uncompressed_hdr_len
* are set to the appropriate values
*
* Input Parameters:
@ -710,6 +707,8 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a first
* fragment.
* iob - Pointer to the IOB containing the received frame.
* payptr - Pointer to the frame data payload.
*
* Returned Value:
* None
@ -718,7 +717,8 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
uint16_t ip_len);
uint16_t ip_len, FAR struct iob_s *iob,
FAR uint8_t *payptr);
#endif
/****************************************************************************