From 715a2bfe5d617ecaf0af91780a17488af71296d5 Mon Sep 17 00:00:00 2001 From: Alexandre M Date: Mon, 20 Jul 2020 09:21:02 +0000 Subject: [PATCH 1/4] fragment_fixing --- net/sixlowpan/sixlowpan_framelist.c | 168 +++++++++++++++++++++------- 1 file changed, 126 insertions(+), 42 deletions(-) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 2d7ecbe03a..2eeb3dce0a 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -119,18 +119,20 @@ ****************************************************************************/ static int sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr, + FAR uint32_t *headersz, FAR uint8_t *fptr) { /* Indicate the IPv6 dispatch and length */ +#if 0 fptr[g_frame_hdrlen] = SIXLOWPAN_DISPATCH_IPV6; g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN; +#endif /* Copy the IPv6 header and adjust pointers */ - memcpy(&fptr[g_frame_hdrlen], ipv6hdr, IPv6_HDRLEN); - g_frame_hdrlen += IPv6_HDRLEN; - g_uncomp_hdrlen += IPv6_HDRLEN; + /* Returne the size of the header */ + *headersz = IPv6_HDRLEN; return COMPRESS_HDR_INLINE; } @@ -170,7 +172,7 @@ static uint16_t sixlowpan_protosize(FAR const struct ipv6_hdr_s *ipv6hdr, #ifdef CONFIG_NET_UDP case IP_PROTO_UDP: - protosize = UDP_HDRLEN; + protosize = UDP_HDRLEN; // 8 bytes break; #endif @@ -383,6 +385,7 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, uint16_t pktlen; uint16_t paysize; uint16_t outlen = 0; + uint32_t ipv6_header_len = 0; uint8_t protosize; int ret; @@ -443,7 +446,7 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, #endif /* Pre-calculate frame header length. */ - + /* 21 for my case */ framer_hdrlen = sixlowpan_frame_hdrlen(radio, &meta); if (framer_hdrlen < 0) { @@ -456,8 +459,9 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, /* This sill be the initial offset into io_data. Valid data begins at * this offset and must be reflected in io_offset. */ - g_frame_hdrlen = framer_hdrlen; + + /* We have to leave some space to the the phy layer to integrate it's sdu */ iob->io_offset = framer_hdrlen; #ifndef CONFIG_NET_6LOWPAN_COMPRESSION_IPv6 @@ -466,8 +470,10 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, /* Try to compress the headers */ #if defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC1) + // TODO need to fix the ipv6 header size ret = sixlowpan_compresshdr_hc1(radio, ipv6, destmac, fptr); #elif defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC06) + // TODO need to fix the ipv6 header size ret = sixlowpan_compresshdr_hc06(radio, ipv6, destmac, fptr); #else # error No compression specified @@ -477,12 +483,10 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, #endif /* !CONFIG_NET_6LOWPAN_COMPRESSION_IPv6 */ { /* Small.. use IPv6 dispatch (no compression) */ - - ret = sixlowpan_compress_ipv6hdr(ipv6, fptr); + ret = sixlowpan_compress_ipv6hdr(ipv6, &ipv6_header_len, fptr); } /* Get the size of any uncompressed protocol headers */ - if (ret == COMPRESS_HDR_INLINE) { protosize = sixlowpan_protosize(ipv6, fptr); @@ -492,6 +496,7 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, /* Get the maximum packet size supported by this radio. */ + /** Should be 127 if IEEE802.14.5 */ ret = sixlowpan_radio_framelen(radio); if (ret < 0) { @@ -500,7 +505,6 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, } /* Limit to the maximum size supported by the IOBs */ - if (ret > CONFIG_IOB_BUFSIZE) { ret = CONFIG_IOB_BUFSIZE; @@ -510,6 +514,7 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, * in the payload. */ + /** This is set to 2 */ ret -= SIXLOWPAN_MAC_FCSSIZE; if (ret < MAX_MACHDR || ret > UINT16_MAX) { @@ -523,18 +528,97 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, * We may need to reserve space at the end of the frame for a 2-byte FCS */ - if (buflen > (framelen - g_frame_hdrlen - protosize)) + if (buflen > (framelen - framer_hdrlen - protosize - ipv6_header_len)) { +#if 0 + FAR uint8_t *frame1; + FAR struct iob_s *qhead; + FAR struct iob_s *qtail; + FAR struct sixlowpan_reassbuf_s *reass; + /* qhead will hold the generated frame list; frames will be * added at qtail. */ + FAR char first_packet [] = { + 0x61, 0xcc, 0x1a, 0xcd, 0xab, 0xa3, 0x02, 0x00, 0xff, 0xff, 0xd5, + 0xe2, 0x10, 0x00, 0xfa, 0xde, 0x00, 0xde, 0xad, 0xbe, 0xab, 0xc0, + 0x9c, 0x00, 0x01, /*0x41,*/ 0x61, 0x00, 0x00, 0x00, 0x00, 0x74, 0x11, + 0x40, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xbe, + 0xad, 0xde, 0x00, 0xde, 0xfa, 0x00, 0xfe, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x12, 0xe2, 0xd5, 0xff, 0xff, 0x00, 0x02, 0xa3, + 0x04, 0x01, 0x27, 0x0f, 0x00, 0x74, 0xc4, 0xf2, 0x81, 0x80, 0x00, + 0x00, 0x01, 0x05, 0x62, 0x00, 0x00, 0x0a, 0x00, 0x01, 0x01, 0x02, + 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x3c, 0x64, 0x64, 0x73, 0x3e, + 0x3c, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, + 0x74, 0x3e, 0x3c, 0x72, 0x74, 0x70, 0x73, 0x3e, 0x3c, 0x6e, 0x61, + 0x6d + }; + FAR char second_packet [] = { + 0x61, 0xcc, 0x1b, 0xcd, 0xab, 0xa3, 0x02, 0x00, 0xff, 0xff, 0xd5, + 0xe2, 0x10, 0x00, 0xfa, 0xde, 0x00, 0xde, 0xad, 0xbe, 0xab, 0xe0, + 0x9c, 0x00, 0x01, 0x0C, + 0x65, 0x3e, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x5f, 0x70, 0x75, + 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x72, 0x5f, 0x72, 0x63, 0x6c, + 0x3c, 0x2f, 0x6e, 0x61, 0x6d, 0x65, 0x3e, 0x3c, 0x2f, 0x72, 0x74, + 0x70, 0x73, 0x3e, 0x3c, 0x2f, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, + 0x69, 0x70, 0x61, 0x6e, 0x74, 0x3e, 0x3c, 0x2f, 0x64, 0x64, 0x73, + 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + reass = (FAR struct sixlowpan_reassbuf_s *)radio->r_dev.d_buf; + + iob = net_ioballoc(false); + qhead = iob; + qtail = iob; + iob->io_pktlen = sizeof(first_packet) + sizeof(second_packet); + iob->io_len = sizeof(first_packet); + iob->io_offset = framer_hdrlen; + PUTHOST16(&first_packet[21], SIXLOWPAN_FRAG_TAG, reass->rb_dgramtag); + memcpy(iob->io_data, first_packet, sizeof(first_packet)); + + iob = net_ioballoc(false); + iob->io_len = sizeof(second_packet); + PUTHOST16(&second_packet[21], SIXLOWPAN_FRAG_TAG, reass->rb_dgramtag); + memcpy(iob->io_data, second_packet, sizeof(second_packet)); + iob->io_offset = framer_hdrlen; + iob->io_flink = NULL; + qtail->io_flink = iob; + qtail = iob; + + iob = net_ioballoc(false); + iob->io_len = sizeof(third_packet); + iob->io_offset = 0; + PUTHOST16(&third_packet[21], SIXLOWPAN_FRAG_TAG, reass->rb_dgramtag); + memcpy(iob->io_data, third_packet, sizeof(third_packet)); + iob->io_offset = framer_hdrlen; + iob->io_flink = NULL; + qtail->io_flink = iob; + qtail = iob; + + ret = sixlowpan_frame_submit(radio, &meta, qhead); + for (iob = qhead; iob != NULL; iob = qhead) + { + /* Remove the IOB containing the frame from the list */ + + qhead = iob->io_flink; + iob->io_flink = NULL; + + /* And submit the frame to the MAC */ + + ninfo("Submitting frame\n"); + ret = sixlowpan_frame_submit(radio, &meta, iob); + if (ret < 0) + { + nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); + } + } + + reass->rb_dgramtag++; +#endif FAR struct sixlowpan_reassbuf_s *reass; FAR struct iob_s *qhead; FAR struct iob_s *qtail; - FAR uint8_t *frame1; FAR uint8_t *fragptr; - uint16_t frag1_hdrlen; /* Recover the reassembly buffer from the driver d_buf. */ @@ -555,10 +639,9 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, /* Move HC1/HC06/IPv6 header to make space for the FRAG1 header at the * beginning of the frame. */ - fragptr = fptr + framer_hdrlen; memmove(fragptr + SIXLOWPAN_FRAG1_HDR_LEN, fragptr, - g_frame_hdrlen - framer_hdrlen); + ipv6_header_len); /* Setup up the fragment header. * @@ -575,13 +658,11 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, * bytes for all subsequent headers. */ - pktlen = buflen + g_uncomp_hdrlen + protosize; + pktlen = buflen + ipv6_header_len + protosize; PUTHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE, ((SIXLOWPAN_DISPATCH_FRAG1 << 8) | pktlen)); PUTHOST16(fragptr, SIXLOWPAN_FRAG_TAG, reass->rb_dgramtag); - g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; - /* Copy any uncompressed protocol headers that must appear only in th * first fragment. */ @@ -589,19 +670,22 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, if (protosize > 0) { FAR uint8_t *src = (FAR uint8_t *)ipv6 + IPv6_HDRLEN; - memcpy(fptr + g_frame_hdrlen, src, protosize); + + memcpy(fptr + SIXLOWPAN_FRAG1_HDR_LEN + + ipv6_header_len + framer_hdrlen, src, protosize); } /* Copy payload and enqueue. NOTE that the size is a multiple of eight * bytes. */ - paysize = (framelen - g_frame_hdrlen) & ~7; - memcpy(fptr + g_frame_hdrlen + protosize, buf, paysize - protosize); + paysize = (framelen - framer_hdrlen - SIXLOWPAN_FRAG1_HDR_LEN) & ~7; + memcpy(fptr + framer_hdrlen + SIXLOWPAN_FRAG1_HDR_LEN + ipv6_header_len + protosize, + buf, paysize); /* Set outlen to what we already sent from the IP payload */ - iob->io_len = paysize + g_frame_hdrlen; + iob->io_len = paysize + framer_hdrlen + SIXLOWPAN_FRAG1_HDR_LEN; outlen = paysize; ninfo("First fragment: length %d, tag %d\n", @@ -622,11 +706,8 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, iob->io_pktlen = iob->io_len; /* Create following fragments */ - - frame1 = iob->io_data; - frag1_hdrlen = g_frame_hdrlen; - - while (outlen < (buflen + protosize)) +#if 1 + while (outlen < (buflen + protosize + ipv6_header_len)) { uint16_t fragn_hdrlen; @@ -651,19 +732,13 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, */ fragptr = fptr + framer_hdrlen; - memcpy(fragptr + SIXLOWPAN_FRAGN_HDR_LEN, - frame1 + framer_hdrlen + SIXLOWPAN_FRAG1_HDR_LEN, - frag1_hdrlen - framer_hdrlen); - fragn_hdrlen = frag1_hdrlen - SIXLOWPAN_FRAG1_HDR_LEN; - /* Setup up the FRAGN header after the frame header. */ - PUTHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE, ((SIXLOWPAN_DISPATCH_FRAGN << 8) | pktlen)); PUTHOST16(fragptr, SIXLOWPAN_FRAG_TAG, reass->rb_dgramtag); fragptr[SIXLOWPAN_FRAG_OFFSET] = outlen >> 3; - fragn_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; + fragn_hdrlen = framer_hdrlen + SIXLOWPAN_FRAGN_HDR_LEN; /* Copy payload and enqueue. * @@ -671,14 +746,13 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, */ paysize = (framelen - fragn_hdrlen) & SIXLOWPAN_DISPATCH_FRAG_MASK; - if (paysize > buflen - outlen + protosize) + if (paysize > (buflen + protosize + ipv6_header_len - outlen)) { /* Last fragment, truncate to the correct length */ - - paysize = buflen - outlen + protosize; + paysize = buflen + protosize + ipv6_header_len - outlen; } - - memcpy(fptr + fragn_hdrlen, buf + outlen - protosize, paysize); + // TODO check if here or not ipv6 is included + memcpy(fptr + fragn_hdrlen, buf + (outlen - protosize - ipv6_header_len), paysize); /* Set outlen to what we already sent from the IP payload */ @@ -710,6 +784,8 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, * frame which is not a fragment from this sequence from intervening. */ +#endif +#if 0 for (iob = qhead; iob != NULL; iob = qhead) { /* Remove the IOB containing the frame from the list */ @@ -726,7 +802,15 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); } } +#else + ninfo("Submitting frame\n"); + ret = sixlowpan_frame_submit(radio, &meta, qhead); + if (ret < 0) + { + nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); + } +#endif /* Update the datagram TAG value */ reass->rb_dgramtag++; @@ -744,13 +828,13 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, if (protosize > 0) { FAR uint8_t *src = (FAR uint8_t *)ipv6 + IPv6_HDRLEN; - memcpy(fptr + g_frame_hdrlen, src, protosize); + memcpy(fptr + framer_hdrlen + IPv6_HDRLEN, src, protosize); } /* Copy the payload into the frame. */ - memcpy(fptr + g_frame_hdrlen + protosize, buf, buflen); - iob->io_len = buflen + g_frame_hdrlen + protosize; + memcpy(fptr + framer_hdrlen + protosize + ipv6_header_len, buf, buflen); + iob->io_len = buflen + framer_hdrlen + ipv6_header_len + protosize; iob->io_pktlen = iob->io_len; ninfo("Non-fragmented: length %d\n", iob->io_len); From d1df584cc108645c08f894e1365ece9487660ccb Mon Sep 17 00:00:00 2001 From: Alexandre M Date: Wed, 22 Jul 2020 05:21:18 +0000 Subject: [PATCH 2/4] 6lowPAN: free packet if error --- net/sixlowpan/sixlowpan_framelist.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 2eeb3dce0a..9d8f2256ba 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -453,6 +453,7 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, /* Failed to determine the size of the header failed. */ nerr("ERROR: sixlowpan_frame_hdrlen() failed: %d\n", framer_hdrlen); + iob_free(iob); return framer_hdrlen; } @@ -501,6 +502,7 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, if (ret < 0) { nerr("ERROR: sixlowpan_radio_framelen() failed: %d\n", ret); + iob_free(iob); return ret; } @@ -519,6 +521,7 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, if (ret < MAX_MACHDR || ret > UINT16_MAX) { nerr("ERROR: Invalid frame size: %d\n", ret); + iob_free(iob); return ret; } From 1b545cd9637544b9e61bb7b35d6d6ab23c638535 Mon Sep 17 00:00:00 2001 From: Alexandre M Date: Wed, 22 Jul 2020 05:22:18 +0000 Subject: [PATCH 3/4] 6lowPAN: cleaning frame queueing --- net/sixlowpan/sixlowpan_framelist.c | 217 +++++++--------------------- 1 file changed, 55 insertions(+), 162 deletions(-) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 9d8f2256ba..6b469d5798 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -533,91 +533,6 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, if (buflen > (framelen - framer_hdrlen - protosize - ipv6_header_len)) { -#if 0 - FAR uint8_t *frame1; - FAR struct iob_s *qhead; - FAR struct iob_s *qtail; - FAR struct sixlowpan_reassbuf_s *reass; - - /* qhead will hold the generated frame list; frames will be - * added at qtail. - */ - FAR char first_packet [] = { - 0x61, 0xcc, 0x1a, 0xcd, 0xab, 0xa3, 0x02, 0x00, 0xff, 0xff, 0xd5, - 0xe2, 0x10, 0x00, 0xfa, 0xde, 0x00, 0xde, 0xad, 0xbe, 0xab, 0xc0, - 0x9c, 0x00, 0x01, /*0x41,*/ 0x61, 0x00, 0x00, 0x00, 0x00, 0x74, 0x11, - 0x40, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xbe, - 0xad, 0xde, 0x00, 0xde, 0xfa, 0x00, 0xfe, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x12, 0xe2, 0xd5, 0xff, 0xff, 0x00, 0x02, 0xa3, - 0x04, 0x01, 0x27, 0x0f, 0x00, 0x74, 0xc4, 0xf2, 0x81, 0x80, 0x00, - 0x00, 0x01, 0x05, 0x62, 0x00, 0x00, 0x0a, 0x00, 0x01, 0x01, 0x02, - 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x3c, 0x64, 0x64, 0x73, 0x3e, - 0x3c, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, - 0x74, 0x3e, 0x3c, 0x72, 0x74, 0x70, 0x73, 0x3e, 0x3c, 0x6e, 0x61, - 0x6d - }; - FAR char second_packet [] = { - 0x61, 0xcc, 0x1b, 0xcd, 0xab, 0xa3, 0x02, 0x00, 0xff, 0xff, 0xd5, - 0xe2, 0x10, 0x00, 0xfa, 0xde, 0x00, 0xde, 0xad, 0xbe, 0xab, 0xe0, - 0x9c, 0x00, 0x01, 0x0C, - 0x65, 0x3e, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x5f, 0x70, 0x75, - 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x72, 0x5f, 0x72, 0x63, 0x6c, - 0x3c, 0x2f, 0x6e, 0x61, 0x6d, 0x65, 0x3e, 0x3c, 0x2f, 0x72, 0x74, - 0x70, 0x73, 0x3e, 0x3c, 0x2f, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, - 0x69, 0x70, 0x61, 0x6e, 0x74, 0x3e, 0x3c, 0x2f, 0x64, 0x64, 0x73, - 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - - reass = (FAR struct sixlowpan_reassbuf_s *)radio->r_dev.d_buf; - - iob = net_ioballoc(false); - qhead = iob; - qtail = iob; - iob->io_pktlen = sizeof(first_packet) + sizeof(second_packet); - iob->io_len = sizeof(first_packet); - iob->io_offset = framer_hdrlen; - PUTHOST16(&first_packet[21], SIXLOWPAN_FRAG_TAG, reass->rb_dgramtag); - memcpy(iob->io_data, first_packet, sizeof(first_packet)); - - iob = net_ioballoc(false); - iob->io_len = sizeof(second_packet); - PUTHOST16(&second_packet[21], SIXLOWPAN_FRAG_TAG, reass->rb_dgramtag); - memcpy(iob->io_data, second_packet, sizeof(second_packet)); - iob->io_offset = framer_hdrlen; - iob->io_flink = NULL; - qtail->io_flink = iob; - qtail = iob; - - iob = net_ioballoc(false); - iob->io_len = sizeof(third_packet); - iob->io_offset = 0; - PUTHOST16(&third_packet[21], SIXLOWPAN_FRAG_TAG, reass->rb_dgramtag); - memcpy(iob->io_data, third_packet, sizeof(third_packet)); - iob->io_offset = framer_hdrlen; - iob->io_flink = NULL; - qtail->io_flink = iob; - qtail = iob; - - ret = sixlowpan_frame_submit(radio, &meta, qhead); - for (iob = qhead; iob != NULL; iob = qhead) - { - /* Remove the IOB containing the frame from the list */ - - qhead = iob->io_flink; - iob->io_flink = NULL; - - /* And submit the frame to the MAC */ - - ninfo("Submitting frame\n"); - ret = sixlowpan_frame_submit(radio, &meta, iob); - if (ret < 0) - { - nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); - } - } - - reass->rb_dgramtag++; -#endif FAR struct sixlowpan_reassbuf_s *reass; FAR struct iob_s *qhead; FAR struct iob_s *qtail; @@ -709,103 +624,83 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, iob->io_pktlen = iob->io_len; /* Create following fragments */ -#if 1 while (outlen < (buflen + protosize + ipv6_header_len)) - { - uint16_t fragn_hdrlen; + { + uint16_t fragn_hdrlen; - /* Allocate an IOB to hold the next fragment, waiting if - * necessary. - */ + /* Allocate an IOB to hold the next fragment, waiting if + * necessary. + */ - iob = net_ioballoc(false); - DEBUGASSERT(iob != NULL); + iob = net_ioballoc(false); + DEBUGASSERT(iob != NULL); - /* Initialize the IOB */ + /* Initialize the IOB */ - iob->io_flink = NULL; - iob->io_len = 0; - iob->io_offset = framer_hdrlen; - iob->io_pktlen = 0; - fptr = iob->io_data; + iob->io_flink = NULL; + iob->io_len = 0; + iob->io_offset = framer_hdrlen; + iob->io_pktlen = 0; + fptr = iob->io_data; - /* Copy the HC1/HC06/IPv6 header the frame header from first - * frame, into the correct location after the FRAGN header - * of subsequent frames. - */ + /* Copy the HC1/HC06/IPv6 header the frame header from first + * frame, into the correct location after the FRAGN header + * of subsequent frames. + */ - fragptr = fptr + framer_hdrlen; - /* Setup up the FRAGN header after the frame header. */ - PUTHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE, - ((SIXLOWPAN_DISPATCH_FRAGN << 8) | pktlen)); - PUTHOST16(fragptr, SIXLOWPAN_FRAG_TAG, reass->rb_dgramtag); - fragptr[SIXLOWPAN_FRAG_OFFSET] = outlen >> 3; + fragptr = fptr + framer_hdrlen; + /* Setup up the FRAGN header after the frame header. */ + PUTHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE, + ((SIXLOWPAN_DISPATCH_FRAGN << 8) | pktlen)); + PUTHOST16(fragptr, SIXLOWPAN_FRAG_TAG, reass->rb_dgramtag); + fragptr[SIXLOWPAN_FRAG_OFFSET] = outlen >> 3; - fragn_hdrlen = framer_hdrlen + SIXLOWPAN_FRAGN_HDR_LEN; + fragn_hdrlen = framer_hdrlen + SIXLOWPAN_FRAGN_HDR_LEN; - /* Copy payload and enqueue. - * - * Check for the last fragment. - */ + /* Copy payload and enqueue. + * + * Check for the last fragment. + */ - paysize = (framelen - fragn_hdrlen) & SIXLOWPAN_DISPATCH_FRAG_MASK; - if (paysize > (buflen + protosize + ipv6_header_len - outlen)) - { - /* Last fragment, truncate to the correct length */ - paysize = buflen + protosize + ipv6_header_len - outlen; - } - // TODO check if here or not ipv6 is included - memcpy(fptr + fragn_hdrlen, buf + (outlen - protosize - ipv6_header_len), paysize); + paysize = (framelen - fragn_hdrlen) & SIXLOWPAN_DISPATCH_FRAG_MASK; + if (paysize > (buflen + protosize + ipv6_header_len - outlen)) + { + /* Last fragment, truncate to the correct length */ + paysize = buflen + protosize + ipv6_header_len - outlen; + } + // TODO check if here or not ipv6 is included + memcpy(fptr + fragn_hdrlen, buf + (outlen - protosize - ipv6_header_len), paysize); - /* Set outlen to what we already sent from the IP payload */ + /* Set outlen to what we already sent from the IP payload */ - iob->io_len = paysize + fragn_hdrlen; - outlen += paysize; + iob->io_len = paysize + fragn_hdrlen; + outlen += paysize; - ninfo("Fragment offset=%d, paysize=%d, rb_dgramtag=%d\n", - outlen >> 3, paysize, reass->rb_dgramtag); + ninfo("Fragment offset=%d, paysize=%d, rb_dgramtag=%d\n", + outlen >> 3, paysize, reass->rb_dgramtag); - sixlowpan_dumpbuffer("Outgoing frame", - (FAR const uint8_t *)iob->io_data, - iob->io_len); + sixlowpan_dumpbuffer("Outgoing frame", + (FAR const uint8_t *)iob->io_data, + iob->io_len); - /* Add the next frame to the tail of the IOB queue */ + /* Add the next frame to the tail of the IOB queue */ - ninfo("Queuing frame io_len=%u io_offset=%u\n", - iob->io_len, iob->io_offset); + ninfo("Queuing frame io_len=%u io_offset=%u\n", + iob->io_len, iob->io_offset); - qtail->io_flink = iob; - qtail = iob; + qtail->io_flink = iob; + qtail = iob; - /* Keep track of the total amount of data queue */ + /* Keep track of the total amount of data queue */ - qhead->io_pktlen += iob->io_len; - } + qhead->io_pktlen += iob->io_len; + } - /* Submit all of the fragments to the MAC. We send all frames back- - * to-back like this to minimize any possible condition where some - * frame which is not a fragment from this sequence from intervening. + /* Submit all of the fragments to the MAC. We send all frames back- + * to-back like this to minimize any possible condition where some + * frame which is not a fragment from this sequence from intervening. */ -#endif -#if 0 - for (iob = qhead; iob != NULL; iob = qhead) - { - /* Remove the IOB containing the frame from the list */ - - qhead = iob->io_flink; - iob->io_flink = NULL; - - /* And submit the frame to the MAC */ - - ninfo("Submitting frame\n"); - ret = sixlowpan_frame_submit(radio, &meta, iob); - if (ret < 0) - { - nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); - } - } -#else ninfo("Submitting frame\n"); ret = sixlowpan_frame_submit(radio, &meta, qhead); if (ret < 0) @@ -813,9 +708,7 @@ int sixlowpan_queue_frames(FAR struct radio_driver_s *radio, nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); } -#endif /* Update the datagram TAG value */ - reass->rb_dgramtag++; } else From 36db0ccf98081ed96760f395dcd91b63ff975406 Mon Sep 17 00:00:00 2001 From: Alexandre M Date: Wed, 22 Jul 2020 05:33:17 +0000 Subject: [PATCH 4/4] 6lowPAN: fix and clean the 6lowpan defconfig for olimex stm32 e407 --- .../olimex-stm32-e407/uros_6lowpan/defconfig | 50 +++++++------------ 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/configs/olimex-stm32-e407/uros_6lowpan/defconfig b/configs/olimex-stm32-e407/uros_6lowpan/defconfig index cee4662d31..0c1edcc7b4 100644 --- a/configs/olimex-stm32-e407/uros_6lowpan/defconfig +++ b/configs/olimex-stm32-e407/uros_6lowpan/defconfig @@ -18,26 +18,13 @@ CONFIG_ARCH_BUTTONS=y CONFIG_ARCH_CHIP_STM32=y CONFIG_ARCH_CHIP_STM32F407ZG=y CONFIG_ARCH_STACKDUMP=y -CONFIG_BOARDCTL_USBDEVCTRL=y CONFIG_BOARD_LATE_INITIALIZE=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y CONFIG_C99_BOOL8=y -CONFIG_CDCACM=y -CONFIG_CDCACM_CONSOLE=y CONFIG_CLOCK_MONOTONIC=y -CONFIG_DEBUG_ERROR=y -CONFIG_DEBUG_FEATURES=y -CONFIG_DEBUG_INFO=y -CONFIG_DEBUG_NET=y -CONFIG_DEBUG_NET_ERROR=y -CONFIG_DEBUG_NET_INFO=y -CONFIG_DEBUG_NET_WARN=y -CONFIG_DEBUG_WARN=y -CONFIG_DEBUG_WIRELESS=y -CONFIG_DEBUG_WIRELESS_ERROR=y -CONFIG_DEBUG_WIRELESS_INFO=y -CONFIG_DEBUG_WIRELESS_WARN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y CONFIG_DRIVERS_IEEE802154=y CONFIG_DRIVERS_WIRELESS=y CONFIG_FS_PROCFS=y @@ -49,15 +36,18 @@ CONFIG_IEEE802154_MACDEV=y CONFIG_IEEE802154_MRF24J40=y CONFIG_IEEE802154_NETDEV=y CONFIG_INTELHEX_BINARY=y -CONFIG_IOB_BUFSIZE=128 -CONFIG_IOB_NBUFFERS=32 -CONFIG_IOB_NCHAINS=16 +CONFIG_IOB_BUFSIZE=256 +CONFIG_IOB_NBUFFERS=16 +CONFIG_IOB_NOTIFIER=y +CONFIG_IOB_NOTIFIER_DIV=1 +CONFIG_IRQCHAIN=y CONFIG_LIBC_FLOATINGPOINT=y CONFIG_LIBM=y CONFIG_LIB_BOARDCTL=y CONFIG_MAC802154_NTXDESC=32 CONFIG_MAX_TASKS=16 CONFIG_MAX_WDOGPARMS=2 +CONFIG_MM_FILL_ALLOCATIONS=y CONFIG_MM_REGIONS=2 CONFIG_NET=y CONFIG_NETDEVICES=y @@ -66,25 +56,23 @@ CONFIG_NETDEV_LATEINIT=y CONFIG_NETDEV_PHY_IOCTL=y CONFIG_NETDEV_STATISTICS=y CONFIG_NETDEV_WIRELESS_IOCTL=y -CONFIG_NETUTILS_TELNETD=y CONFIG_NET_6LOWPAN=y -CONFIG_NET_6LOWPAN_COMPRESSION_THRESHOLD=500 +CONFIG_NET_6LOWPAN_COMPRESSION_THRESHOLD=580 CONFIG_NET_6LOWPAN_EXTENDEDADDR=y +CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS=1 +CONFIG_NET_6LOWPAN_PKTSIZE=600 +CONFIG_NET_6LOWPAN_REASS_STATIC=y CONFIG_NET_BROADCAST=y -CONFIG_NET_ICMPv6=y -CONFIG_NET_ICMPv6_AUTOCONF=y -CONFIG_NET_ICMPv6_NEIGHBOR=y -CONFIG_NET_ICMPv6_ROUTER=y -CONFIG_NET_ICMPv6_SOCKET=y +CONFIG_NET_GUARDSIZE=128 CONFIG_NET_IPv6=y +CONFIG_NET_NACTIVESOCKETS=2 CONFIG_NET_PROMISCUOUS=y CONFIG_NET_ROUTE=y CONFIG_NET_SOCKOPTS=y CONFIG_NET_STATISTICS=y -CONFIG_NET_TCP=y -CONFIG_NET_TCPBACKLOG=y -CONFIG_NET_TCP_WRITE_BUFFERS=y CONFIG_NET_UDP=y +CONFIG_NET_UDP_CONNS=16 +CONFIG_NET_UDP_NWRBCHAINS=16 CONFIG_NET_UDP_WRITE_BUFFERS=y CONFIG_NFILE_DESCRIPTORS=8 CONFIG_NFILE_STREAMS=8 @@ -92,6 +80,7 @@ CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_LINELEN=64 CONFIG_NSH_READLINE=y +CONFIG_NSOCKET_DESCRIPTORS=2 CONFIG_PREALLOC_MQ_MSGS=4 CONFIG_PREALLOC_TIMERS=4 CONFIG_PREALLOC_WDOGS=16 @@ -107,19 +96,18 @@ CONFIG_START_DAY=6 CONFIG_START_MONTH=12 CONFIG_START_YEAR=2011 CONFIG_STM32_JTAG_SW_ENABLE=y -CONFIG_STM32_OTGFS=y CONFIG_STM32_PWR=y CONFIG_STM32_SPI1=y CONFIG_STM32_USART3=y CONFIG_SYSTEM_NSH=y -CONFIG_SYSTEM_PING6=y CONFIG_SYSTEM_SYSTEM=y CONFIG_UCLIBCXX=y +CONFIG_UDP_READAHEAD_NOTIFIER=y CONFIG_UROS=y CONFIG_UROS_6LOWPAN_EXAMPLE=y CONFIG_USART3_RXBUFSIZE=128 +CONFIG_USART3_SERIAL_CONSOLE=y CONFIG_USART3_TXBUFSIZE=512 -CONFIG_USBDEV=y CONFIG_USER_ENTRYPOINT="nsh_main" CONFIG_WIRELESS=y CONFIG_WIRELESS_IEEE802154=y