mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 14:27:37 +08:00
6LoWPAN: Eliminate a global variable.
This commit is contained in:
@@ -514,7 +514,13 @@ Configurations
|
|||||||
retransmissions, and to work with TCP dynamic windowing.
|
retransmissions, and to work with TCP dynamic windowing.
|
||||||
|
|
||||||
2017-05-25: After some rather extensive debug, the TCP test was made
|
2017-05-25: After some rather extensive debug, the TCP test was made
|
||||||
to with (HC06 and short addressing).
|
to with (HC06 and short addressing). Initial testing with HC06
|
||||||
|
and extended addressing failed. Server reports
|
||||||
|
|
||||||
|
Binding to IPv6 Address: 0000:0000:0000:0000:0000:0000:0000:0000
|
||||||
|
server: Accepting connections on port 61616
|
||||||
|
|
||||||
|
But the client fails to connect.
|
||||||
|
|
||||||
Test Matrix:
|
Test Matrix:
|
||||||
The following configurations have been tested:
|
The following configurations have been tested:
|
||||||
|
|||||||
@@ -122,8 +122,8 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr,
|
static int sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr,
|
||||||
FAR uint8_t *fptr)
|
FAR uint8_t *fptr)
|
||||||
{
|
{
|
||||||
/* Indicate the IPv6 dispatch and length */
|
/* Indicate the IPv6 dispatch and length */
|
||||||
|
|
||||||
@@ -135,6 +135,8 @@ static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr,
|
|||||||
memcpy(&fptr[g_frame_hdrlen], ipv6hdr, IPv6_HDRLEN);
|
memcpy(&fptr[g_frame_hdrlen], ipv6hdr, IPv6_HDRLEN);
|
||||||
g_frame_hdrlen += IPv6_HDRLEN;
|
g_frame_hdrlen += IPv6_HDRLEN;
|
||||||
g_uncomp_hdrlen += IPv6_HDRLEN;
|
g_uncomp_hdrlen += IPv6_HDRLEN;
|
||||||
|
|
||||||
|
return COMPRESS_HDR_INLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -151,48 +153,42 @@ static uint16_t sixlowpan_protosize(FAR const struct ipv6_hdr_s *ipv6hdr,
|
|||||||
{
|
{
|
||||||
uint16_t protosize;
|
uint16_t protosize;
|
||||||
|
|
||||||
/* Do we already have an encoded protocol header? If not, it needs to
|
/* Copy the following protocol header, */
|
||||||
* coped as raw data in the fist packet of a fragement.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!g_have_protohdr)
|
switch (ipv6hdr->proto)
|
||||||
{
|
{
|
||||||
/* Copy the following protocol header, */
|
|
||||||
|
|
||||||
switch (ipv6hdr->proto)
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_NET_TCP
|
#ifdef CONFIG_NET_TCP
|
||||||
case IP_PROTO_TCP:
|
case IP_PROTO_TCP:
|
||||||
{
|
{
|
||||||
FAR struct tcp_hdr_s *tcp =
|
FAR struct tcp_hdr_s *tcp =
|
||||||
&((FAR struct ipv6tcp_hdr_s *)ipv6hdr)->tcp;
|
&((FAR struct ipv6tcp_hdr_s *)ipv6hdr)->tcp;
|
||||||
|
|
||||||
/* The TCP header length is encoded in the top 4 bits of the
|
/* The TCP header length is encoded in the top 4 bits of the
|
||||||
* tcpoffset field (in units of 32-bit words).
|
* tcpoffset field (in units of 32-bit words).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protosize = ((uint16_t)tcp->tcpoffset >> 4) << 2;
|
protosize = ((uint16_t)tcp->tcpoffset >> 4) << 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NET_UDP
|
#ifdef CONFIG_NET_UDP
|
||||||
case IP_PROTO_UDP:
|
case IP_PROTO_UDP:
|
||||||
protosize = UDP_HDRLEN;
|
protosize = UDP_HDRLEN;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NET_ICMPv6
|
#ifdef CONFIG_NET_ICMPv6
|
||||||
case IP_PROTO_ICMP6:
|
case IP_PROTO_ICMP6:
|
||||||
protosize = ICMPv6_HDRLEN;
|
protosize = ICMPv6_HDRLEN;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
nwarn("WARNING: Unrecognized proto: %u\n", ipv6hdr->proto);
|
nwarn("WARNING: Unrecognized proto: %u\n", ipv6hdr->proto);
|
||||||
return 0;
|
protosize = 0;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return protosize;
|
return protosize;
|
||||||
}
|
}
|
||||||
@@ -260,7 +256,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
|||||||
|
|
||||||
g_uncomp_hdrlen = 0;
|
g_uncomp_hdrlen = 0;
|
||||||
g_frame_hdrlen = 0;
|
g_frame_hdrlen = 0;
|
||||||
g_have_protohdr = false;
|
protosize = 0;
|
||||||
|
|
||||||
/* Reset frame meta data */
|
/* Reset frame meta data */
|
||||||
|
|
||||||
@@ -381,9 +377,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
|||||||
/* Try to compress the headers */
|
/* Try to compress the headers */
|
||||||
|
|
||||||
#if defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC1)
|
#if defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC1)
|
||||||
sixlowpan_compresshdr_hc1(ieee, destip, destmac, fptr);
|
ret = sixlowpan_compresshdr_hc1(ieee, destip, destmac, fptr);
|
||||||
#elif defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC06)
|
#elif defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC06)
|
||||||
sixlowpan_compresshdr_hc06(ieee, destip, destmac, fptr);
|
ret = sixlowpan_compresshdr_hc06(ieee, destip, destmac, fptr);
|
||||||
#else
|
#else
|
||||||
# error No compression specified
|
# error No compression specified
|
||||||
#endif
|
#endif
|
||||||
@@ -393,14 +389,17 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
|||||||
{
|
{
|
||||||
/* Small.. use IPv6 dispatch (no compression) */
|
/* Small.. use IPv6 dispatch (no compression) */
|
||||||
|
|
||||||
sixlowpan_compress_ipv6hdr(destip, fptr);
|
ret = sixlowpan_compress_ipv6hdr(destip, fptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ninfo("Header of length %d\n", g_frame_hdrlen);
|
|
||||||
|
|
||||||
/* Get the size of any uncompressed protocol headers */
|
/* Get the size of any uncompressed protocol headers */
|
||||||
|
|
||||||
protosize = sixlowpan_protosize(destip, fptr);
|
if (ret == COMPRESS_HDR_INLINE)
|
||||||
|
{
|
||||||
|
protosize = sixlowpan_protosize(destip, fptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
ninfo("Header of length=%u protosize=%u\n", g_frame_hdrlen, protosize);
|
||||||
|
|
||||||
/* Check if we need to fragment the packet into several frames */
|
/* Check if we need to fragment the packet into several frames */
|
||||||
|
|
||||||
|
|||||||
@@ -67,8 +67,4 @@ uint8_t g_uncomp_hdrlen;
|
|||||||
|
|
||||||
uint8_t g_frame_hdrlen;
|
uint8_t g_frame_hdrlen;
|
||||||
|
|
||||||
/* g_have_protohdr: true=Protocal header copied. */
|
|
||||||
|
|
||||||
bool g_have_protohdr;
|
|
||||||
|
|
||||||
#endif /* CONFIG_NET_6LOWPAN */
|
#endif /* CONFIG_NET_6LOWPAN */
|
||||||
|
|||||||
@@ -587,20 +587,22 @@ void sixlowpan_hc06_initialize(void)
|
|||||||
* fptr - Pointer to frame to be compressed.
|
* fptr - Pointer to frame to be compressed.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* On success the indications of the defines COMPRESS_HDR_* are returned.
|
||||||
|
* A negated errno value is returned on failure.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
|
int sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
|
||||||
FAR const struct ipv6_hdr_s *ipv6,
|
FAR const struct ipv6_hdr_s *ipv6,
|
||||||
FAR const struct sixlowpan_tagaddr_s *destmac,
|
FAR const struct sixlowpan_tagaddr_s *destmac,
|
||||||
FAR uint8_t *fptr)
|
FAR uint8_t *fptr)
|
||||||
{
|
{
|
||||||
FAR uint8_t *iphc = fptr + g_frame_hdrlen;
|
FAR uint8_t *iphc = fptr + g_frame_hdrlen;
|
||||||
FAR struct sixlowpan_addrcontext_s *addrcontext;
|
FAR struct sixlowpan_addrcontext_s *addrcontext;
|
||||||
uint8_t iphc0;
|
uint8_t iphc0;
|
||||||
uint8_t iphc1;
|
uint8_t iphc1;
|
||||||
uint8_t tmp;
|
uint8_t tmp;
|
||||||
|
int ret = COMPRESS_HDR_INLINE;
|
||||||
|
|
||||||
ninfo("fptr=%p g_frame_hdrlen=%u iphc=%p\n", fptr, g_frame_hdrlen, iphc);
|
ninfo("fptr=%p g_frame_hdrlen=%u iphc=%p\n", fptr, g_frame_hdrlen, iphc);
|
||||||
|
|
||||||
@@ -956,7 +958,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
|
|||||||
memcpy(g_hc06ptr, &udp->udpchksum, 2);
|
memcpy(g_hc06ptr, &udp->udpchksum, 2);
|
||||||
g_hc06ptr += 2;
|
g_hc06ptr += 2;
|
||||||
g_uncomp_hdrlen += UDP_HDRLEN;
|
g_uncomp_hdrlen += UDP_HDRLEN;
|
||||||
g_have_protohdr = true;
|
ret = COMPRESS_HDR_ELIDED;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_NET_UDP */
|
#endif /* CONFIG_NET_UDP */
|
||||||
|
|
||||||
@@ -970,7 +972,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
|
|||||||
ninfo("fptr=%p g_frame_hdrlen=%u iphc=%02x:%02x:%02x g_hc06ptr=%p\n",
|
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);
|
fptr, g_frame_hdrlen, iphc[0], iphc[1], iphc[2], g_hc06ptr);
|
||||||
|
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -140,16 +140,18 @@ static void sixlowpan_uncompress_addr(FAR const struct ieee802154_addr_s *addr,
|
|||||||
* fptr - Pointer to frame to be compressed.
|
* fptr - Pointer to frame to be compressed.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* On success the indications of the defines COMPRESS_HDR_* are returned.
|
||||||
|
* A negated errno value is returned on failure.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
int sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||||
FAR const struct ipv6_hdr_s *ipv6,
|
FAR const struct ipv6_hdr_s *ipv6,
|
||||||
FAR const struct sixlowpan_tagaddr_s *destmac,
|
FAR const struct sixlowpan_tagaddr_s *destmac,
|
||||||
FAR uint8_t *fptr)
|
FAR uint8_t *fptr)
|
||||||
{
|
{
|
||||||
FAR uint8_t *hc1 = fptr + g_frame_hdrlen;
|
FAR uint8_t *hc1 = fptr + g_frame_hdrlen;
|
||||||
|
int ret = COMPRESS_HDR_INLINE;
|
||||||
|
|
||||||
/* Check if all the assumptions for full compression are valid */
|
/* Check if all the assumptions for full compression are valid */
|
||||||
|
|
||||||
@@ -266,7 +268,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
|||||||
g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
|
g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_have_protohdr = true;
|
ret = COMPRESS_HDR_ELIDED;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* CONFIG_NET_UDP */
|
#endif /* CONFIG_NET_UDP */
|
||||||
@@ -281,6 +283,8 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -119,6 +119,13 @@
|
|||||||
} \
|
} \
|
||||||
while(0)
|
while(0)
|
||||||
|
|
||||||
|
/* Return values ************************************************************/
|
||||||
|
|
||||||
|
/* Sucessful return values from header compression logic */
|
||||||
|
|
||||||
|
#define COMPRESS_HDR_INLINE 0 /* L2 header not compressed */
|
||||||
|
#define COMPRESS_HDR_ELIDED 1 /* L2 header compressed */
|
||||||
|
|
||||||
/* Debug ********************************************************************/
|
/* Debug ********************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_6LOWPAN_DUMPBUFFER
|
#ifdef CONFIG_NET_6LOWPAN_DUMPBUFFER
|
||||||
@@ -209,10 +216,6 @@ extern uint8_t g_uncomp_hdrlen;
|
|||||||
|
|
||||||
extern uint8_t g_frame_hdrlen;
|
extern uint8_t g_frame_hdrlen;
|
||||||
|
|
||||||
/* g_have_protohdr: true=Protocal header copied. */
|
|
||||||
|
|
||||||
extern bool g_have_protohdr;
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -422,15 +425,16 @@ void sixlowpan_hc06_initialize(void);
|
|||||||
* fptr - Pointer to frame to be compressed.
|
* fptr - Pointer to frame to be compressed.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* On success the indications of the defines COMPRESS_HDR_* are returned.
|
||||||
|
* A negated errno value is returned on failure.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
|
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
|
||||||
void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
|
int sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
|
||||||
FAR const struct ipv6_hdr_s *ipv6,
|
FAR const struct ipv6_hdr_s *ipv6,
|
||||||
FAR const struct sixlowpan_tagaddr_s *destmac,
|
FAR const struct sixlowpan_tagaddr_s *destmac,
|
||||||
FAR uint8_t *fptr);
|
FAR uint8_t *fptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -485,15 +489,16 @@ void sixlowpan_uncompresshdr_hc06(FAR const struct ieee802154_data_ind_s *ind,
|
|||||||
* fptr - Pointer to frame to be compressed.
|
* fptr - Pointer to frame to be compressed.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* On success the indications of the defines COMPRESS_HDR_* are returned.
|
||||||
|
* A negated errno value is returned on failure.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
|
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
|
||||||
void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
int sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||||
FAR const struct ipv6_hdr_s *ipv6,
|
FAR const struct ipv6_hdr_s *ipv6,
|
||||||
FAR const struct sixlowpan_tagaddr_s *destmac,
|
FAR const struct sixlowpan_tagaddr_s *destmac,
|
||||||
FAR uint8_t *fptr);
|
FAR uint8_t *fptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user