6LoWPAN: Eliminate a global variable.

This commit is contained in:
Gregory Nutt 2017-06-25 16:09:09 -06:00
parent 5a8668b362
commit 95795f9b8a
6 changed files with 83 additions and 71 deletions

View File

@ -514,7 +514,13 @@ Configurations
retransmissions, and to work with TCP dynamic windowing.
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:
The following configurations have been tested:

View File

@ -122,8 +122,8 @@
*
****************************************************************************/
static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr,
FAR uint8_t *fptr)
static int sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr,
FAR uint8_t *fptr)
{
/* 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);
g_frame_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;
/* Do we already have an encoded protocol header? If not, it needs to
* coped as raw data in the fist packet of a fragement.
*/
/* Copy the following protocol header, */
if (!g_have_protohdr)
{
/* Copy the following protocol header, */
switch (ipv6hdr->proto)
{
switch (ipv6hdr->proto)
{
#ifdef CONFIG_NET_TCP
case IP_PROTO_TCP:
{
FAR struct tcp_hdr_s *tcp =
&((FAR struct ipv6tcp_hdr_s *)ipv6hdr)->tcp;
case IP_PROTO_TCP:
{
FAR struct tcp_hdr_s *tcp =
&((FAR struct ipv6tcp_hdr_s *)ipv6hdr)->tcp;
/* The TCP header length is encoded in the top 4 bits of the
* tcpoffset field (in units of 32-bit words).
*/
/* The TCP header length is encoded in the top 4 bits of the
* tcpoffset field (in units of 32-bit words).
*/
protosize = ((uint16_t)tcp->tcpoffset >> 4) << 2;
}
break;
protosize = ((uint16_t)tcp->tcpoffset >> 4) << 2;
}
break;
#endif
#ifdef CONFIG_NET_UDP
case IP_PROTO_UDP:
protosize = UDP_HDRLEN;
break;
case IP_PROTO_UDP:
protosize = UDP_HDRLEN;
break;
#endif
#ifdef CONFIG_NET_ICMPv6
case IP_PROTO_ICMP6:
protosize = ICMPv6_HDRLEN;
break;
case IP_PROTO_ICMP6:
protosize = ICMPv6_HDRLEN;
break;
#endif
default:
nwarn("WARNING: Unrecognized proto: %u\n", ipv6hdr->proto);
return 0;
}
}
default:
nwarn("WARNING: Unrecognized proto: %u\n", ipv6hdr->proto);
protosize = 0;
break;
}
return protosize;
}
@ -260,7 +256,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
g_uncomp_hdrlen = 0;
g_frame_hdrlen = 0;
g_have_protohdr = false;
protosize = 0;
/* Reset frame meta data */
@ -381,9 +377,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, fptr);
ret = sixlowpan_compresshdr_hc1(ieee, destip, destmac, fptr);
#elif defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC06)
sixlowpan_compresshdr_hc06(ieee, destip, destmac, fptr);
ret = sixlowpan_compresshdr_hc06(ieee, destip, destmac, fptr);
#else
# error No compression specified
#endif
@ -393,14 +389,17 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
{
/* 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 */
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 */

View File

@ -67,8 +67,4 @@ uint8_t g_uncomp_hdrlen;
uint8_t g_frame_hdrlen;
/* g_have_protohdr: true=Protocal header copied. */
bool g_have_protohdr;
#endif /* CONFIG_NET_6LOWPAN */

View File

@ -587,20 +587,22 @@ void sixlowpan_hc06_initialize(void)
* fptr - Pointer to frame to be compressed.
*
* 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,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr)
int sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr)
{
FAR uint8_t *iphc = fptr + g_frame_hdrlen;
FAR struct sixlowpan_addrcontext_s *addrcontext;
uint8_t iphc0;
uint8_t iphc1;
uint8_t tmp;
int ret = COMPRESS_HDR_INLINE;
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);
g_hc06ptr += 2;
g_uncomp_hdrlen += UDP_HDRLEN;
g_have_protohdr = true;
ret = COMPRESS_HDR_ELIDED;
}
#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",
fptr, g_frame_hdrlen, iphc[0], iphc[1], iphc[2], g_hc06ptr);
return;
return ret;
}
/****************************************************************************

View File

@ -140,16 +140,18 @@ static void sixlowpan_uncompress_addr(FAR const struct ieee802154_addr_s *addr,
* fptr - Pointer to frame to be compressed.
*
* 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,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr)
int sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr)
{
FAR uint8_t *hc1 = fptr + g_frame_hdrlen;
int ret = COMPRESS_HDR_INLINE;
/* 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_have_protohdr = true;
ret = COMPRESS_HDR_ELIDED;
}
break;
#endif /* CONFIG_NET_UDP */
@ -281,6 +283,8 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
break;
}
}
return ret;
}
/****************************************************************************

View File

@ -119,6 +119,13 @@
} \
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 ********************************************************************/
#ifdef CONFIG_NET_6LOWPAN_DUMPBUFFER
@ -209,10 +216,6 @@ extern uint8_t g_uncomp_hdrlen;
extern uint8_t g_frame_hdrlen;
/* g_have_protohdr: true=Protocal header copied. */
extern bool g_have_protohdr;
/****************************************************************************
* Public Types
****************************************************************************/
@ -422,15 +425,16 @@ void sixlowpan_hc06_initialize(void);
* fptr - Pointer to frame to be compressed.
*
* 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
void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr);
int sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr);
#endif
/****************************************************************************
@ -485,15 +489,16 @@ void sixlowpan_uncompresshdr_hc06(FAR const struct ieee802154_data_ind_s *ind,
* fptr - Pointer to frame to be compressed.
*
* 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
void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr);
int sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6,
FAR const struct sixlowpan_tagaddr_s *destmac,
FAR uint8_t *fptr);
#endif
/****************************************************************************