6loWPAN: Fix more frame offsets. Reorder some logic that was appropriate only for IPv6 dispatch.

This commit is contained in:
Gregory Nutt 2017-04-08 09:34:30 -06:00
parent fe722e44b9
commit 143b8f9591
5 changed files with 35 additions and 70 deletions

View file

@ -112,6 +112,8 @@
static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr,
FAR uint8_t *fptr)
{
uint16_t protosize;
/* Indicate the IPv6 dispatch and length */
fptr[g_frame_hdrlen] = SIXLOWPAN_DISPATCH_IPV6;
@ -122,31 +124,8 @@ static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr,
memcpy(&fptr[g_frame_hdrlen] , ipv6hdr, IPv6_HDRLEN);
g_frame_hdrlen += IPv6_HDRLEN;
g_uncomp_hdrlen += IPv6_HDRLEN;
}
/****************************************************************************
* Name: sixlowpan_copy_protohdr
*
* Description:
* The IPv6 header should have already been processed (as reflected in the
* g_uncomphdrlen). But we probably still need to copy the following
* protocol header.
*
* Input Parameters:
* ipv6hdr - Pointer to the IPv6 header to "compress"
* fptr - Pointer to the beginning of the frame under construction
*
* Returned Value:
* None. But g_frame_hdrlen and g_uncomp_hdrlen updated.
*
****************************************************************************/
static void sixlowpan_copy_protohdr(FAR const struct ipv6_hdr_s *ipv6hdr,
FAR uint8_t *fptr)
{
uint16_t protosize;
/* What is the total size of the IPv6 + protocol header? */
/* Copy the following protocol header, */
switch (ipv6hdr->proto)
{
@ -397,10 +376,6 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN;
/* Copy protocol header that follows the IPv6 header */
sixlowpan_copy_protohdr(destip, fptr);
/* Copy payload and enqueue. NOTE that the size is a multiple of eight
* bytes.
*/
@ -527,10 +502,6 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
DEBUGASSERT(verify == framer_hdrlen);
UNUSED(verify);
/* Copy protocol header that follows the IPv6 header */
sixlowpan_copy_protohdr(destip, fptr);
/* Copy the payload and queue */
memcpy(fptr + g_frame_hdrlen, buf, buflen);

View file

@ -440,7 +440,7 @@ void sixlowpan_hc06_initialize(void)
* ipv6 - The IPv6 header to be compressed
* destmac - L2 destination address, needed to compress the IP
* destination field
* fptr - Pointer to frame data payload.
* fptr - Pointer to frame to be compressed.
*
* Returned Value:
* None
@ -840,7 +840,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
* 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.
* fptr - Pointer to frame to be compressed.
*
* Returned Value:
* None
@ -849,7 +849,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
uint16_t iplen, FAR struct iob_s *iob,
FAR uint8_t *payptr)
FAR uint8_t *fptr)
{
FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(ieee);
FAR uint8_t *iphc;
@ -857,18 +857,18 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
uint8_t iphc1;
uint8_t tmp;
/* payptr points to IPHC. At least two byte will be used for the encoding. */
/* iphc points to IPHC. At least two byte will be used for the encoding. */
iphc = payptr;
iphc = fptr + g_frame_hdrlen;
iphc0 = iphc[0];
iphc1 = iphc[1];
/* g_hc96ptr points to just after the 2-byte minimum IPHC */
g_hc06ptr = payptr + 2;
g_hc06ptr = iphc + 2;
ninfo("payptr=%p g_frame_hdrlen=%u iphc=%02x:%02x:%02x g_hc06ptr=%p\n",
payptr, g_frame_hdrlen, iphc[0], iphc[1], iphc[2], g_hc06ptr);
ninfo("fptr=%p g_frame_hdrlen=%u iphc=%02x:%02x:%02x g_hc06ptr=%p\n",
fptr, g_frame_hdrlen, iphc[0], iphc[1], iphc[2], g_hc06ptr);
/* Another if the CID flag is set */
@ -1171,7 +1171,7 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
}
}
g_frame_hdrlen = g_hc06ptr - payptr;
g_frame_hdrlen = g_hc06ptr - fptr;
/* IP length field. */

View file

@ -258,7 +258,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
* 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.
* fptr - Pointer to frame to be uncompressed.
*
* Returned Value:
* Zero (OK) is returned on success, on failure a negater errno value is
@ -268,10 +268,10 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
uint16_t iplen, FAR struct iob_s *iob,
FAR uint8_t *payptr)
FAR uint8_t *fptr)
{
FAR struct ipv6_hdr_s *ipv6 = IPv6BUF(&ieee->i_dev);
FAR uint8_t *hc1 = payptr + g_frame_hdrlen;
FAR uint8_t *hc1 = fptr + g_frame_hdrlen;
/* Format the IPv6 header in the device d_buf */
/* Set version, traffic clase, and flow label */
@ -312,7 +312,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 = payptr + g_frame_hdrlen;
FAR uint8_t *hcudp = fptr + g_frame_hdrlen;
ipv6->proto = IP_PROTO_UDP;
if ((hcudp[RIME_HC1_HC_UDP_HC1_ENCODING] & 0x01) != 0)

View file

@ -224,6 +224,7 @@ int sixlowpan_recv_hdrlen(FAR const uint8_t *fptr)
static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
FAR struct iob_s *iob)
{
FAR uint8_t *fptr; /* Convenience pointer to beginning of the frame */
FAR uint8_t *hc1; /* Convenience pointer to HC1 data */
uint16_t fragsize = 0; /* Size of the IP packet (read from fragment) */
uint16_t paysize; /* Size of the data payload */
@ -242,7 +243,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
* This size includes both fragmentation and FCF headers.
*/
hdrsize = sixlowpan_recv_hdrlen(iob->io_data);
fptr = iob->io_data;
hdrsize = sixlowpan_recv_hdrlen(fptr);
if (hdrsize < 0)
{
nwarn("Invalid IEEE802.15.2 header: %d\n", hdrsize);
@ -262,7 +264,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
* already includes the fragementation header, if presetn.
*/
switch ((GETINT16(iob->io_data, RIME_FRAG_DISPATCH_SIZE) & 0xf800) >> 8)
switch ((GETINT16(fptr, RIME_FRAG_DISPATCH_SIZE) & 0xf800) >> 8)
{
/* First fragment of new reassembly */
@ -270,8 +272,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
{
/* Set up for the reassembly */
fragsize = GETINT16(iob->io_data, RIME_FRAG_DISPATCH_SIZE) & 0x07ff;
fragtag = GETINT16(iob->io_data, RIME_FRAG_TAG);
fragsize = GETINT16(fptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff;
fragtag = GETINT16(fptr, RIME_FRAG_TAG);
ninfo("FRAG1: fragsize=%d fragtag=%d fragoffset=%d\n",
fragsize, fragtag, fragoffset);
@ -287,9 +289,9 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
{
/* Set offset, tag, size. Offset is in units of 8 bytes. */
fragoffset = iob->io_data[RIME_FRAG_OFFSET];
fragtag = GETINT16(iob->io_data, RIME_FRAG_TAG);
fragsize = GETINT16(iob->io_data, RIME_FRAG_DISPATCH_SIZE) & 0x07ff;
fragoffset = fptr[RIME_FRAG_OFFSET];
fragtag = GETINT16(fptr, RIME_FRAG_TAG);
fragsize = GETINT16(fptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff;
ninfo("FRAGN: fragsize=%d fragtag=%d fragoffset=%d\n",
fragsize, fragtag, fragoffset);
@ -429,19 +431,16 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
/* Process next dispatch and headers */
hc1 = &iob->io_data[g_frame_hdrlen];
hc1 = fptr + g_frame_hdrlen;
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
if ((hc1[RIME_HC1_DISPATCH] & SIXLOWPAN_DISPATCH_IPHC_MASK) == SIXLOWPAN_DISPATCH_IPHC)
{
FAR uint8_t *payptr;
ninfo("IPHC Dispatch\n");
/* Payload starts after the IEEE802.15.4 header(s) */
payptr = &iob->io_data[g_frame_hdrlen];
sixlowpan_uncompresshdr_hc06(ieee, fragsize, iob, payptr);
sixlowpan_uncompresshdr_hc06(ieee, fragsize, iob, fptr);
}
else
#endif /* CONFIG_NET_6LOWPAN_COMPRESSION_HC06 */
@ -449,14 +448,11 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_HC1)
{
FAR uint8_t *payptr;
ninfo("HC1 Dispatch\n");
/* Payload starts after the IEEE802.15.4 header(s) */
payptr = &iob->io_data[g_frame_hdrlen];
sixlowpan_uncompresshdr_hc1(ieee, fragsize, iob, payptr);
sixlowpan_uncompresshdr_hc1(ieee, fragsize, iob, fptr);
}
else
#endif /* CONFIG_NET_6LOWPAN_COMPRESSION_HC1 */
@ -470,7 +466,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
/* Put uncompressed IP header in d_buf. */
memcpy(ipv6, iob->io_data + g_frame_hdrlen, IPv6_HDRLEN);
memcpy(ipv6, fptr + g_frame_hdrlen, IPv6_HDRLEN);
/* Update g_uncomp_hdrlen and g_frame_hdrlen. */
@ -527,8 +523,7 @@ copypayload:
}
memcpy(ieee->i_dev.d_buf + g_uncomp_hdrlen + (fragoffset << 3),
iob->io_data + g_frame_hdrlen,
paysize);
fptr + g_frame_hdrlen, paysize);
#ifdef CONFIG_NET_6LOWPAN_FRAG
/* Update ieee->i_accumlen if the frame is a fragment, ieee->i_pktlen
@ -690,8 +685,7 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee)
FRAME_IOB_REMOVE(ieee, iob);
DEBUGASSERT(iob != NULL);
sixlowpan_dumpbuffer("Incoming frame",
(FAR const uint8_t *)iob->io_data, iob->io_len);
sixlowpan_dumpbuffer("Incoming frame", iob->io_data, iob->io_len);
/* Process the frame, decompressing it into the packet buffer */

View file

@ -641,7 +641,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
* 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.
* fptr - Pointer to frame to be uncompressed.
*
* Returned Value:
* None
@ -651,7 +651,7 @@ 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, FAR struct iob_s *iob,
FAR uint8_t *payptr);
FAR uint8_t *fptr);
#endif
/****************************************************************************
@ -701,7 +701,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
* 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.
* fptr - Pointer to frame to be uncompressed.
*
* Returned Value:
* None
@ -711,7 +711,7 @@ 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, FAR struct iob_s *iob,
FAR uint8_t *payptr);
FAR uint8_t *fptr);
#endif
/****************************************************************************