6loWPAN: Change ordering of some operations so that the IOB is available at the time that headr compression is perfomed.
This commit is contained in:
parent
6464ebbc7f
commit
5a56d3cce7
@ -101,7 +101,7 @@
|
||||
*
|
||||
* Input Parameters:
|
||||
* ieee - Pointer to IEEE802.15.4 MAC driver structure.
|
||||
* ipv6 - Pointer to the IPv6 header to "compress"
|
||||
* destip - Pointer to the IPv6 header to "compress"
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
@ -109,7 +109,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR const struct ipv6_hdr_s *ipv6)
|
||||
FAR const struct ipv6_hdr_s *destip)
|
||||
{
|
||||
/* Indicate the IPv6 dispatch and length */
|
||||
|
||||
@ -118,7 +118,7 @@ static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
/* Copy the IPv6 header and adjust pointers */
|
||||
|
||||
memcpy(g_rimeptr + g_rime_hdrlen, ipv6, IPv6_HDRLEN);
|
||||
memcpy(g_rimeptr + g_rime_hdrlen, destip, IPv6_HDRLEN);
|
||||
g_rime_hdrlen += IPv6_HDRLEN;
|
||||
g_uncomp_hdrlen += IPv6_HDRLEN;
|
||||
}
|
||||
@ -166,7 +166,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
{
|
||||
FAR struct iob_s *iob;
|
||||
int framer_hdrlen;
|
||||
struct rimeaddr_s dest;
|
||||
struct rimeaddr_s bcastmac;
|
||||
uint16_t outlen = 0;
|
||||
|
||||
/* Initialize global data. Locking the network guarantees that we have
|
||||
@ -211,13 +211,24 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
if (destmac == NULL)
|
||||
{
|
||||
memset(&dest, 0, sizeof(struct rimeaddr_s));
|
||||
}
|
||||
else
|
||||
{
|
||||
rimeaddr_copy(&dest, (FAR const struct rimeaddr_s *)destmac);
|
||||
memset(&bcastmac, 0, sizeof(struct rimeaddr_s));
|
||||
destmac = &bcastmac;
|
||||
}
|
||||
|
||||
/* Pre-allocate the IOB to hold frame or the first fragment, waiting if
|
||||
* necessary.
|
||||
*/
|
||||
|
||||
iob = iob_alloc(false);
|
||||
DEBUGASSERT(iob != NULL);
|
||||
|
||||
/* Initialize the IOB */
|
||||
|
||||
iob->io_flink = NULL;
|
||||
iob->io_len = 0;
|
||||
iob->io_offset = 0;
|
||||
iob->io_pktlen = 0;
|
||||
|
||||
ninfo("Sending packet len %d\n", len);
|
||||
|
||||
#ifndef CONFIG_NET_6LOWPAN_COMPRESSION_IPv6
|
||||
@ -226,9 +237,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, &dest);
|
||||
sixlowpan_compresshdr_hc1(ieee, destip, destmac, iob);
|
||||
#elif defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC06)
|
||||
sixlowpan_compresshdr_hc06(ieee, &dest);
|
||||
sixlowpan_compresshdr_hc06(ieee, destip, destmac, iob);
|
||||
#else
|
||||
# error No compression specified
|
||||
#endif
|
||||
@ -243,7 +254,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
ninfo("Header of len %d\n", g_rime_hdrlen);
|
||||
|
||||
rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], &dest);
|
||||
rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], destmac);
|
||||
|
||||
/* Pre-calculate frame header length. */
|
||||
|
||||
@ -279,20 +290,8 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
ninfo("Fragmentation sending packet len %d\n", len);
|
||||
|
||||
/* Allocate an IOB to hold the first fragment, waiting if necessary. */
|
||||
|
||||
iob = iob_alloc(false);
|
||||
DEBUGASSERT(iob != NULL);
|
||||
|
||||
/* Initialize the IOB */
|
||||
|
||||
iob->io_flink = NULL;
|
||||
iob->io_len = 0;
|
||||
iob->io_offset = 0;
|
||||
iob->io_pktlen = 0;
|
||||
|
||||
/* Create 1st Fragment */
|
||||
/* Add the frame header */
|
||||
/* Add the frame header using the pre-allocated IOB. */
|
||||
|
||||
verify = sixlowpan_framecreate(ieee, iob, ieee->i_panid);
|
||||
DEBUGASSERT(verify == framer_hdrlen);
|
||||
@ -434,19 +433,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
|
||||
* and send in one frame.
|
||||
*/
|
||||
|
||||
/* Allocate an IOB to hold the frame, waiting if necessary. */
|
||||
|
||||
iob = iob_alloc(false);
|
||||
DEBUGASSERT(iob != NULL);
|
||||
|
||||
/* Initialize the IOB */
|
||||
|
||||
iob->io_flink = NULL;
|
||||
iob->io_len = 0;
|
||||
iob->io_offset = 0;
|
||||
iob->io_pktlen = 0;
|
||||
|
||||
/* Add the frame header */
|
||||
/* Add the frame header to the prealloated IOB. */
|
||||
|
||||
verify = sixlowpan_framecreate(ieee, iob, ieee->i_panid);
|
||||
DEBUGASSERT(vreify == framer_hdrlen);
|
||||
|
@ -203,8 +203,8 @@ void sixlowpan_hc06_initialize(void)
|
||||
*
|
||||
* Input Parameters:
|
||||
* ieee - A reference to the IEE802.15.4 network device state
|
||||
* ipv6 - The IPv6 header to be compressed
|
||||
* destaddr - L2 destination address, needed to compress the IP
|
||||
* destip - 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.
|
||||
*
|
||||
@ -214,7 +214,9 @@ void sixlowpan_hc06_initialize(void)
|
||||
****************************************************************************/
|
||||
|
||||
void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR struct rimeaddr_s *destaddr)
|
||||
FAR const struct ipv6_hdr_s *destip,
|
||||
FAR const struct rimeaddr_s *destmac,
|
||||
FAR struct iob_s *iob)
|
||||
{
|
||||
/* REVISIT: To be provided */
|
||||
}
|
||||
|
@ -114,8 +114,8 @@
|
||||
*
|
||||
* Input Parmeters:
|
||||
* ieee - A reference to the IEE802.15.4 network device state
|
||||
* ipv6 - The IPv6 header to be compressed
|
||||
* destaddr - L2 destination address, needed to compress the IP
|
||||
* destip - 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.
|
||||
*
|
||||
@ -125,21 +125,21 @@
|
||||
****************************************************************************/
|
||||
|
||||
void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR const struct ipv6_hdr_s *ipv6,
|
||||
FAR const struct rimeaddr_s *destaddr,
|
||||
FAR const struct ipv6_hdr_s *destip,
|
||||
FAR const struct rimeaddr_s *destmac,
|
||||
FAR struct iob_s *iob)
|
||||
{
|
||||
FAR uint8_t *hc1 = RIME_HC1_PTR;
|
||||
|
||||
/* Check if all the assumptions for full compression are valid */
|
||||
|
||||
if (ipv6->vtc != 0x60 || ipv6->tcflow != 0 || ipv6->flow != 0 ||
|
||||
!sixlowpan_islinklocal(&ipv6->srcipaddr) ||
|
||||
!sixlowpan_ismacbased(&ipv6->srcipaddr, &ieee->i_rimeaddr) ||
|
||||
!sixlowpan_islinklocal(&ipv6->destipaddr) ||
|
||||
!sixlowpan_ismacbased(&ipv6->destipaddr, destaddr) ||
|
||||
(ipv6->proto != IP_PROTO_ICMP6 && ipv6->proto != IP_PROTO_UDP &&
|
||||
ipv6->proto != IP_PROTO_TCP))
|
||||
if (destip->vtc != 0x60 || destip->tcflow != 0 || destip->flow != 0 ||
|
||||
!sixlowpan_islinklocal(&destip->srcipaddr) ||
|
||||
!sixlowpan_ismacbased(&destip->srcipaddr, &ieee->i_rimeaddr) ||
|
||||
!sixlowpan_islinklocal(&destip->destipaddr) ||
|
||||
!sixlowpan_ismacbased(&destip->destipaddr, destmac) ||
|
||||
(destip->proto != IP_PROTO_ICMP6 && destip->proto != IP_PROTO_UDP &&
|
||||
destip->proto != IP_PROTO_TCP))
|
||||
{
|
||||
/* IPV6 DISPATCH
|
||||
* Something cannot be compressed, use IPV6 DISPATCH,
|
||||
@ -148,7 +148,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
*g_rimeptr = SIXLOWPAN_DISPATCH_IPV6;
|
||||
g_rime_hdrlen += SIXLOWPAN_IPV6_HDR_LEN;
|
||||
memcpy(g_rimeptr + g_rime_hdrlen, ipv6, IPv6_HDRLEN);
|
||||
memcpy(g_rimeptr + g_rime_hdrlen, destip, IPv6_HDRLEN);
|
||||
g_rime_hdrlen += IPv6_HDRLEN;
|
||||
g_uncomp_hdrlen += IPv6_HDRLEN;
|
||||
}
|
||||
@ -161,13 +161,13 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
hc1[RIME_HC1_DISPATCH] = SIXLOWPAN_DISPATCH_HC1;
|
||||
g_uncomp_hdrlen += IPv6_HDRLEN;
|
||||
switch (ipv6->proto)
|
||||
switch (destip->proto)
|
||||
{
|
||||
case IP_PROTO_ICMP6:
|
||||
/* HC1 encoding and ttl */
|
||||
|
||||
hc1[RIME_HC1_ENCODING] = 0xfc;
|
||||
hc1[RIME_HC1_TTL] = ipv6->ttl;
|
||||
hc1[RIME_HC1_TTL] = destip->ttl;
|
||||
g_rime_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
|
||||
break;
|
||||
|
||||
@ -176,7 +176,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||
/* HC1 encoding and ttl */
|
||||
|
||||
hc1[RIME_HC1_ENCODING] = 0xfe;
|
||||
hc1[RIME_HC1_TTL] = ipv6->ttl;
|
||||
hc1[RIME_HC1_TTL] = destip->ttl;
|
||||
g_rime_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
|
||||
break;
|
||||
#endif /* CONFIG_NET_TCP */
|
||||
@ -206,7 +206,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||
/* HC_UDP encoding, ttl, src and dest ports, checksum */
|
||||
|
||||
hcudp[RIME_HC1_HC_UDP_UDP_ENCODING] = 0xe0;
|
||||
hcudp[RIME_HC1_HC_UDP_TTL] = ipv6->ttl;
|
||||
hcudp[RIME_HC1_HC_UDP_TTL] = destip->ttl;
|
||||
hcudp[RIME_HC1_HC_UDP_PORTS] =
|
||||
(uint8_t)((htons(udp->srcport) - SIXLOWPAN_UDP_PORT_MIN) << 4) +
|
||||
(uint8_t)((htons(udp->destport) - SIXLOWPAN_UDP_PORT_MIN));
|
||||
@ -221,7 +221,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||
/* HC1 encoding and ttl */
|
||||
|
||||
hc1[RIME_HC1_ENCODING] = 0xfa;
|
||||
hc1[RIME_HC1_TTL] = ipv6->ttl;
|
||||
hc1[RIME_HC1_TTL] = destip->ttl;
|
||||
g_rime_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
|
||||
}
|
||||
break;
|
||||
@ -257,24 +257,24 @@ 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 ipv6_hdr_s *ipv6 = IPv6BUF(&ieee->i_dev);
|
||||
FAR struct ipv6_hdr_s *destip = IPv6BUF(&ieee->i_dev);
|
||||
FAR uint8_t *hc1 = RIME_HC1_PTR;
|
||||
|
||||
/* Format the IPv6 header in the device d_buf */
|
||||
/* Set version, traffic clase, and flow label */
|
||||
|
||||
ipv6->vtc = 0x60; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
|
||||
ipv6->tcf = 0; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
|
||||
ipv6->flow = 0; /* 16-bit flow label (LS) */
|
||||
destip->vtc = 0x60; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
|
||||
destip->tcf = 0; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
|
||||
destip->flow = 0; /* 16-bit flow label (LS) */
|
||||
|
||||
/* Use stateless auto-configuration to set source and destination IP
|
||||
* addresses.
|
||||
*/
|
||||
|
||||
sixlowpan_ipfromrime(&g_pktaddrs[PACKETBUF_ADDR_SENDER],
|
||||
&ipv6->srcipaddr);
|
||||
&destip->srcipaddr);
|
||||
sixlowpan_ipfromrime(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER],
|
||||
&ipv6->destipaddr);
|
||||
&destip->destipaddr);
|
||||
g_uncomp_hdrlen += IPv6_HDRLEN;
|
||||
|
||||
/* len[], proto, and ttl depend on the encoding */
|
||||
@ -282,15 +282,15 @@ 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];
|
||||
destip->proto = IP_PROTO_ICMP6;
|
||||
destip->ttl = hc1[RIME_HC1_TTL];
|
||||
g_rime_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];
|
||||
destip->proto = IP_PROTO_TCP;
|
||||
destip->ttl = hc1[RIME_HC1_TTL];
|
||||
g_rime_hdrlen += SIXLOWPAN_HC1_HDR_LEN;
|
||||
break;
|
||||
#endif /* CONFIG_NET_TCP */
|
||||
@ -301,7 +301,7 @@ int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR struct udp_hdr_s *udp = UDPIPv6BUF(&ieee->i_dev);
|
||||
FAR uint8_t *hcudp = RIME_HC1_HC_UDP_PTR;
|
||||
|
||||
ipv6->proto = IP_PROTO_UDP;
|
||||
destip->proto = IP_PROTO_UDP;
|
||||
if ((hcudp[RIME_HC1_HC_UDP_HC1_ENCODING] & 0x01) != 0)
|
||||
{
|
||||
/* UDP header is compressed with HC_UDP */
|
||||
@ -315,7 +315,7 @@ int sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
/* IP TTL */
|
||||
|
||||
ipv6->ttl = hcudp[RIME_HC1_HC_UDP_TTL];
|
||||
destip->ttl = hcudp[RIME_HC1_HC_UDP_TTL];
|
||||
|
||||
/* UDP ports, len, checksum */
|
||||
|
||||
@ -347,25 +347,25 @@ 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 */
|
||||
destip->len[0] = 0;
|
||||
destip->len[1] = ieee->i_dev.d_len - g_rime_hdrlen + /* REVISIT */
|
||||
g_uncomp_hdrlen - IPv6_HDRLEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This is a 1st fragment */
|
||||
|
||||
ipv6->len[0] = (iplen - IPv6_HDRLEN) >> 8;
|
||||
ipv6->len[1] = (iplen - IPv6_HDRLEN) & 0x00FF;
|
||||
destip->len[0] = (iplen - IPv6_HDRLEN) >> 8;
|
||||
destip->len[1] = (iplen - IPv6_HDRLEN) & 0x00FF;
|
||||
}
|
||||
|
||||
/* length field in UDP header */
|
||||
|
||||
#if CONFIG_NET_UDP
|
||||
if (ipv6->proto == IP_PROTO_UDP)
|
||||
if (destip->proto == IP_PROTO_UDP)
|
||||
{
|
||||
FAR struct udp_hdr_s *udp = UDPIPv6BUF(&ieee->i_dev);
|
||||
memcpy(&udp->udplen, &ipv6->len[0], 2);
|
||||
memcpy(&udp->udplen, &destip->len[0], 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -416,7 +416,7 @@ struct iob_s; /* Forward reference */
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The IEEE802.15.4 MAC network driver interface.
|
||||
* ipv6 - IPv6 plus TCP or UDP headers.
|
||||
* destip - IPv6 plus TCP or UDP headers.
|
||||
* buf - Data to send
|
||||
* len - Length of data to send
|
||||
* raddr - The MAC address of the destination
|
||||
@ -434,7 +434,7 @@ struct iob_s; /* Forward reference */
|
||||
****************************************************************************/
|
||||
|
||||
int sixlowpan_send(FAR struct net_driver_s *dev,
|
||||
FAR const struct ipv6_hdr_s *ipv6, FAR const void *buf,
|
||||
FAR const struct ipv6_hdr_s *destip, FAR const void *buf,
|
||||
size_t len, FAR const struct rimeaddr_s *raddr,
|
||||
uint16_t timeout);
|
||||
|
||||
@ -560,8 +560,8 @@ void sixlowpan_hc06_initialize(void);
|
||||
*
|
||||
* Input Parameters:
|
||||
* ieee - A reference to the IEE802.15.4 network device state
|
||||
* ipv6 - The IPv6 header to be compressed
|
||||
* destaddr - L2 destination address, needed to compress the IP
|
||||
* destip - 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.
|
||||
*
|
||||
@ -572,8 +572,8 @@ void sixlowpan_hc06_initialize(void);
|
||||
|
||||
#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 rimeaddr_s *destaddr,
|
||||
FAR const struct ipv6_hdr_s *destip,
|
||||
FAR const struct rimeaddr_s *destmac,
|
||||
FAR struct iob_s *iob);
|
||||
#endif
|
||||
|
||||
@ -618,8 +618,8 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
|
||||
*
|
||||
* Input Parmeters:
|
||||
* ieee - A reference to the IEE802.15.4 network device state
|
||||
* ipv6 - The IPv6 header to be compressed
|
||||
* destaddr - L2 destination address, needed to compress the IP
|
||||
* destip - 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.
|
||||
*
|
||||
@ -630,8 +630,8 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
#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 rimeaddr_s *destaddr,
|
||||
FAR const struct ipv6_hdr_s *destip,
|
||||
FAR const struct rimeaddr_s *destmac,
|
||||
FAR struct iob_s *iob);
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user