6loWPAN: Fix a few UDP-related issues.
This commit is contained in:
parent
b4e01ecbf9
commit
494d996826
@ -146,7 +146,7 @@ static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee,
|
||||
*
|
||||
* Input Parameters:
|
||||
* ieee - The IEEE802.15.4 MAC driver instance
|
||||
* ipv6hdr - IPv6 header followed by TCP or UDP header.
|
||||
* ipv6hdr - IPv6 header followed by TCP, UDP, or ICMPv6 header.
|
||||
* buf - Beginning of the packet packet to send (with IPv6 + protocol
|
||||
* headers)
|
||||
* buflen - Length of data to send (include IPv6 and protocol headers)
|
||||
|
@ -116,7 +116,8 @@
|
||||
*
|
||||
* Input Parmeters:
|
||||
* ieee - A reference to the IEE802.15.4 network device state
|
||||
* ipv6 - The IPv6 header to be compressed
|
||||
* ipv6 - The IPv6 header followd by TCP, UDP, or ICMPv6 header to be
|
||||
* compressed
|
||||
* destmac - L2 destination address, needed to compress the IP
|
||||
* destination field
|
||||
* fptr - Pointer to frame to be compressed.
|
||||
@ -189,7 +190,8 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||
#if CONFIG_NET_UDP
|
||||
case IP_PROTO_UDP:
|
||||
{
|
||||
FAR struct udp_hdr_s *udp = UDPIPv6BUF(&ieee->i_dev);
|
||||
FAR struct udp_hdr_s *udp =
|
||||
&(((FAR struct ipv6udp_hdr_s *)ipv6)->udp);
|
||||
|
||||
/* Try to compress UDP header (we do only full compression).
|
||||
* This is feasible if both src and dest ports are between
|
||||
@ -199,10 +201,10 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||
|
||||
ninfo("local/remote port %u/%u\n", udp->srcport, udp->destport);
|
||||
|
||||
if (htons(udp->srcport) >= CONFIG_NET_6LOWPAN_MINPORT &&
|
||||
htons(udp->srcport) < (CONFIG_NET_6LOWPAN_MINPORT + 16) &&
|
||||
htons(udp->destport) >= CONFIG_NET_6LOWPAN_MINPORT &&
|
||||
htons(udp->destport) < (CONFIG_NET_6LOWPAN_MINPORT + 16))
|
||||
if (ntohs(udp->srcport) >= CONFIG_NET_6LOWPAN_MINPORT &&
|
||||
ntohs(udp->srcport) < (CONFIG_NET_6LOWPAN_MINPORT + 16) &&
|
||||
ntohs(udp->destport) >= CONFIG_NET_6LOWPAN_MINPORT &&
|
||||
ntohs(udp->destport) < (CONFIG_NET_6LOWPAN_MINPORT + 16))
|
||||
{
|
||||
FAR uint8_t *hcudp = fptr + g_frame_hdrlen;
|
||||
|
||||
@ -215,8 +217,8 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
|
||||
hcudp[RIME_HC1_HC_UDP_UDP_ENCODING] = 0xe0;
|
||||
hcudp[RIME_HC1_HC_UDP_TTL] = ipv6->ttl;
|
||||
hcudp[RIME_HC1_HC_UDP_PORTS] =
|
||||
(uint8_t)((htons(udp->srcport) - CONFIG_NET_6LOWPAN_MINPORT) << 4) +
|
||||
(uint8_t)((htons(udp->destport) - CONFIG_NET_6LOWPAN_MINPORT));
|
||||
(uint8_t)((ntohs(udp->srcport) - CONFIG_NET_6LOWPAN_MINPORT) << 4) +
|
||||
(uint8_t)((ntohs(udp->destport) - CONFIG_NET_6LOWPAN_MINPORT));
|
||||
|
||||
memcpy(&hcudp[RIME_HC1_HC_UDP_CHKSUM], &udp->udpchksum, 2);
|
||||
|
||||
|
@ -327,6 +327,22 @@ struct ipv6icmp_hdr_s
|
||||
struct icmpv6_iphdr_s icmp;
|
||||
};
|
||||
|
||||
/* IPv6 + TCP or UDP or ICMPv6 header */
|
||||
|
||||
union ipv6_hdr_u
|
||||
{
|
||||
struct ipv6_hdr_s ipv6;
|
||||
#ifdef CONFIG_NET_TCP
|
||||
struct ipv6tcp_hdr_s ipv6tcp;
|
||||
#endif
|
||||
#ifdef CONFIG_NET_UDP
|
||||
struct ipv6udp_hdr_s ipv6udp;
|
||||
#endif
|
||||
#ifdef CONFIG_NET_ICMPv6
|
||||
struct ipv6icmp_hdr_s ipv6icmp
|
||||
#endif
|
||||
};
|
||||
|
||||
/* IEEE802.15.4 Frame Definitions *******************************************/
|
||||
/* The IEEE 802.15.4 frame has a number of constant/fixed fields that can be
|
||||
* counted to make frame construction and max payload calculations easier.
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <semaphore.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
@ -82,10 +83,10 @@ struct sixlowpan_send_s
|
||||
int s_result; /* The result of the transfer */
|
||||
uint16_t s_timeout; /* Send timeout in deciseconds */
|
||||
systime_t s_time; /* Last send time for determining timeout */
|
||||
FAR const struct ipv6_hdr_s *s_ipv6hdr; /* IPv6 header, followed by UDP or TCP header. */
|
||||
FAR const struct rimeaddr_s *s_destmac; /* Destination MAC address */
|
||||
FAR const void *s_buf; /* Data to send */
|
||||
size_t s_len; /* Length of data in buf */
|
||||
FAR const union ipv6_hdr_u s_ipv6hdr; /* IPv6 header, followed by UDP, TCP, or ICMPv6 header. */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@ -176,12 +177,12 @@ static uint16_t send_interrupt(FAR struct net_driver_s *dev,
|
||||
{
|
||||
DEBUGASSERT((flags & WPAN_POLL) != 0);
|
||||
|
||||
/* Transfer the frame listto the IEEE802.15.4 MAC device */
|
||||
/* Transfer the frame list to the IEEE802.15.4 MAC device */
|
||||
|
||||
sinfo->s_result =
|
||||
sixlowpan_queue_frames((FAR struct ieee802154_driver_s *)dev,
|
||||
sinfo->s_ipv6hdr, sinfo->s_buf, sinfo->s_len,
|
||||
sinfo->s_destmac);
|
||||
&sinfo->s_ipv6hdr.ipv6, sinfo->s_buf,
|
||||
sinfo->s_len, sinfo->s_destmac);
|
||||
|
||||
flags &= ~WPAN_POLL;
|
||||
neighbor_reachable(dev);
|
||||
@ -217,6 +218,56 @@ end_wait:
|
||||
return flags;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sixlowpan_ipv6_copy
|
||||
*
|
||||
* Description:
|
||||
* Make a copy of the IPv6 + {TCP, UDP, ICMPv6} header structure.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ipv6hdr - IPv6 header followed by TCP or UDP header.
|
||||
* sinfo - Send state structure reference
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void sixlowpan_ipv6_copy(FAR const struct ipv6_hdr_s *ipv6hdr,
|
||||
FAR struct sixlowpan_send_s *sinfo)
|
||||
{
|
||||
size_t structsize;
|
||||
|
||||
switch (ipv6hdr->proto)
|
||||
{
|
||||
#ifdef CONFIG_NET_TCP
|
||||
case IP_PROTO_TCP:
|
||||
structsize = sizeof(struct ipv6tcp_hdr_s);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_UDP
|
||||
case IP_PROTO_UDP:
|
||||
structsize = sizeof(struct ipv6udp_hdr_s);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6
|
||||
case IP_PROTO_ICMP6:
|
||||
structsize = sizeof(struct ipv6icmp_hdr_s);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
nwarn("WARNING: Unrecognized proto: %u\n", ipv6hdr->proto);
|
||||
structsize = sizeof(struct ipv6_hdr_s);
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy((FAR void *)&sinfo->s_ipv6hdr, (FAR const void *)ipv6hdr,
|
||||
structsize);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -271,11 +322,12 @@ int sixlowpan_send(FAR struct net_driver_s *dev,
|
||||
sinfo.s_result = -EBUSY;
|
||||
sinfo.s_timeout = timeout;
|
||||
sinfo.s_time = clock_systimer();
|
||||
sinfo.s_ipv6hdr = ipv6hdr;
|
||||
sinfo.s_destmac = destmac;
|
||||
sinfo.s_buf = buf;
|
||||
sinfo.s_len = len;
|
||||
|
||||
sixlowpan_ipv6_copy(ipv6hdr, &sinfo);
|
||||
|
||||
net_lock();
|
||||
if (len > 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user