diff --git a/configs/sim/sixlowpan/defconfig b/configs/sim/sixlowpan/defconfig index d3c4c9d54cb..adf330024f5 100644 --- a/configs/sim/sixlowpan/defconfig +++ b/configs/sim/sixlowpan/defconfig @@ -500,16 +500,14 @@ CONFIG_NET=y # # Driver buffer configuration # -CONFIG_NET_ETH_MTU=590 -CONFIG_NET_ETH_TCP_RECVWNDO=536 CONFIG_NET_GUARDSIZE=2 # # Data link support # -CONFIG_NET_MULTILINK=y +# CONFIG_NET_MULTILINK is not set # CONFIG_NET_USER_DEVFMT is not set -CONFIG_NET_ETHERNET=y +# CONFIG_NET_ETHERNET is not set CONFIG_NET_6LOWPAN=y # CONFIG_NET_LOOPBACK is not set # CONFIG_NET_TUN is not set @@ -884,6 +882,17 @@ CONFIG_EXAMPLES_NETTEST_IPv6=y # # Target IPv6 address # +# +# Client IPv6 address +# +CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_1=0xfe80 +CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_2=0x0000 +CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_3=0x0000 +CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_4=0x0000 +CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_5=0x1234 +CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_6=0x0000 +CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_7=0x0000 +CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_8=0x0000 CONFIG_EXAMPLES_NSH=y # CONFIG_EXAMPLES_NULL is not set # CONFIG_EXAMPLES_NX is not set @@ -1112,7 +1121,7 @@ CONFIG_NSH_IPv6NETMASK_1=0xffff CONFIG_NSH_IPv6NETMASK_2=0xffff CONFIG_NSH_IPv6NETMASK_3=0xffff CONFIG_NSH_IPv6NETMASK_4=0xffff -CONFIG_NSH_IPv6NETMASK_5=0xffff +CONFIG_NSH_IPv6NETMASK_5=0x0000 CONFIG_NSH_IPv6NETMASK_6=0x0000 CONFIG_NSH_IPv6NETMASK_7=0x0000 CONFIG_NSH_IPv6NETMASK_8=0x0000 diff --git a/include/nuttx/net/ip.h b/include/nuttx/net/ip.h index c7b606078b7..84df3520740 100644 --- a/include/nuttx/net/ip.h +++ b/include/nuttx/net/ip.h @@ -547,7 +547,7 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1, #define net_is_addr_loopback(a) \ ((a)[0] == 0 && (a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && (a)[7] == 0x0001) + (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && (a)[7] == HTONS(0x0001)) /**************************************************************************** * Name: net_is_addr_unspecified @@ -569,7 +569,7 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1, * ****************************************************************************/ -#define net_is_addr_mcast(a) (((a)[0] & 0xff00) == 0xff00) +#define net_is_addr_mcast(a) (((a)[0] & HTONS(0xff00)) == HTONS(0xff00)) /**************************************************************************** * Name: net_is_addr_linklocal_allnodes_mcast @@ -580,8 +580,8 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1, ****************************************************************************/ #define net_is_addr_linklocal_allnodes_mcast(a) \ - ((a)[0] == 0xff02 && (a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && (a)[7] == 0x0001) + ((a)[0] == HTONS(0xff02) && (a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ + (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && (a)[7] == HTONS(0x0001)) /**************************************************************************** * Name: net_is_addr_linklocal_allrouters_mcast @@ -592,8 +592,8 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1, ****************************************************************************/ #define net_is_addr_linklocal_allrouters_mcast(a) \ - ((a)[0] == 0xff02 && (a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && (a)[7] == 0x0002) + ((a)[0] == HTONS(0xff02) && (a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ + (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && (a)[7] == HTOS(0x0002)) /**************************************************************************** * Name: net_is_addr_linklocal @@ -603,7 +603,7 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1, * ****************************************************************************/ -#define net_is_addr_linklocal(a) ((a)[0] == 0xfe80) +#define net_is_addr_linklocal(a) ((a)[0] == HTONS(0xfe80)) /**************************************************************************** * Name: net_ipaddr_mask diff --git a/net/devif/devif_poll.c b/net/devif/devif_poll.c index bde0cabb7a2..235c58bcf28 100644 --- a/net/devif/devif_poll.c +++ b/net/devif/devif_poll.c @@ -58,6 +58,20 @@ #include "igmp/igmp.h" #include "sixlowpan/sixlowpan.h" +/**************************************************************************** + * Private Types + ****************************************************************************/ + +enum devif_packet_type +{ + DEVIF_PKT = 0, + DEVIF_ICMP, + DEVIF_IGMP, + DEVIF_TCP, + DEVIF_UDP, + DEVIF_ICMP6 +}; + /**************************************************************************** * Public Data ****************************************************************************/ @@ -74,6 +88,9 @@ systime_t g_polltime; * Function: devif_packet_conversion * * Description: + * Generic output conversion hook. Only needed for IEEE802.15.4 for now + * is a point where support for other conversions may be provided. + * * TCP output comes through three different mechansims. Either from: * * 1. TCP socket output. For the case of TCP output to an @@ -94,7 +111,8 @@ systime_t g_polltime; ****************************************************************************/ #ifdef CONFIG_NET_6LOWPAN -static inline void devif_packet_conversion(FAR struct net_driver_s *dev) +static void devif_packet_conversion(FAR struct net_driver_s *dev, + enum devif_packet_type pkttype) { #ifdef CONFIG_NET_MULTILINK /* Handle the case where multiple link layer protocols are supported */ @@ -104,14 +122,38 @@ static inline void devif_packet_conversion(FAR struct net_driver_s *dev) if (dev->d_len > 0) #endif { - /* Let 6loWPAN convert output into the IEEE802.15.4 frames */ + if (pkttype == DEVIF_TCP) + { + FAR struct ipv6_hdr_s *ipv6 = (FAR struct ipv6_hdr_s *)dev->d_buf; + + /* This packet came from a response to TCP polling and is directed + * to an IEEE802.15.4 device using 6loWPAN. Verify that the outgoing + * packet is IPv6 with TCP protocol. + */ + + if (ipv6->vtc == IPv6_VERSION && ipv6->proto == IP_PROTO_TCP) + { + /* Let 6loWPAN convert IPv6 TCP output into IEEE802.15.4 frames. */ + + sixlowpan_tcp_send(dev); + } + else + { + nerr("ERROR: IPv6 version or protocol error. Packet dropped\n"); + nerr(" IP version: %02x proocol: %u\n", + ipv6->vtc, ipv6->proto); + } + } + else + { + nerr("ERROR: Non-TCP packet dropped. Packet type: %u\n", pkttype); + } - sixlowpan_tcp_send(dev); dev->d_len = 0; } } #else -# define devif_packet_conversion(dev) +# define devif_packet_conversion(dev,pkttype) #endif /* CONFIG_NET_6LOWPAN */ /**************************************************************************** @@ -143,7 +185,7 @@ static int devif_poll_pkt_connections(FAR struct net_driver_s *dev, /* Perform any necessary conversions on outgoing packets */ - devif_packet_conversion(dev); + devif_packet_conversion(dev, DEVIF_PKT); /* Call back into the driver */ @@ -172,7 +214,7 @@ static inline int devif_poll_icmp(FAR struct net_driver_s *dev, /* Perform any necessary conversions on outgoing packets */ - devif_packet_conversion(dev); + devif_packet_conversion(dev, DEVIF_ICMP); /* Call back into the driver */ @@ -198,7 +240,7 @@ static inline int devif_poll_icmpv6(FAR struct net_driver_s *dev, /* Perform any necessary conversions on outgoing packets */ - devif_packet_conversion(dev); + devif_packet_conversion(dev, DEVIF_ICMP6); /* Call back into the driver */ @@ -228,7 +270,7 @@ static inline int devif_poll_igmp(FAR struct net_driver_s *dev, /* Perform any necessary conversions on outgoing packets */ - devif_packet_conversion(dev); + devif_packet_conversion(dev, DEVIF_IGMP); /* Call back into the driver */ @@ -265,7 +307,7 @@ static int devif_poll_udp_connections(FAR struct net_driver_s *dev, /* Perform any necessary conversions on outgoing packets */ - devif_packet_conversion(dev); + devif_packet_conversion(dev, DEVIF_UDP); /* Call back into the driver */ @@ -305,7 +347,7 @@ static inline int devif_poll_tcp_connections(FAR struct net_driver_s *dev, /* Perform any necessary conversions on outgoing packets */ - devif_packet_conversion(dev); + devif_packet_conversion(dev, DEVIF_TCP); /* Call back into the driver */ @@ -349,7 +391,7 @@ static inline int devif_poll_tcp_timer(FAR struct net_driver_s *dev, /* Perform any necessary conversions on outgoing packets */ - devif_packet_conversion(dev); + devif_packet_conversion(dev, DEVIF_TCP); /* Call back into the driver */ diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c index 80154c91faa..d7673507b73 100644 --- a/net/procfs/netdev_statistics.c +++ b/net/procfs/netdev_statistics.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/procfs/netdev_statistics.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include #include +#include #include "netdev/netdev.h" #include "utils/utils.h" @@ -106,6 +107,9 @@ static const linegen_t g_linegen[] = static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) { FAR struct net_driver_s *dev; +#ifdef CONFIG_NET_6LOWPAN + FAR struct ieee802154_driver_s *ieee; +#endif FAR const char *status; int len = 0; @@ -142,6 +146,30 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) break; #endif +#ifdef CONFIG_NET_6LOWPAN + case NET_LL_IEEE802154: + { + ieee = (FAR struct ieee802154_driver_s *)dev; + +#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:6loWPAN HWaddr %02x:%02x", + dev->d_ifname, + ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1]); +#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:6loWPAN HWaddr " + "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", + dev->d_ifname, + ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], + ieee->i_nodeaddr.u8[2], ieee->i_nodeaddr.u8[3], + ieee->i_nodeaddr.u8[4], ieee->i_nodeaddr.u8[5], + ieee->i_nodeaddr.u8[6], ieee->i_nodeaddr.u8[7]); +#endif + } + break; +#endif + #ifdef CONFIG_NET_LOOPBACK case NET_LL_LOOPBACK: len += snprintf(&netfile->line[len], NET_LINELEN - len, @@ -184,6 +212,26 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) "%s\tLink encap:Ethernet HWaddr %s at %s\n", dev->d_ifname, ether_ntoa(&dev->d_mac), status); +#elif defined(CONFIG_NET_6LOWPAN) + ieee = (FAR struct ieee802154_driver_s *)dev; + +#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:6loWPAN HWaddr %02x:%02x at %s", + dev->d_ifname, + ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], + status); +#else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ + len += snprintf(&netfile->line[len], NET_LINELEN - len, + "%s\tLink encap:6loWPAN HWaddr " + "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x at %s", + dev->d_ifname, + ieee->i_nodeaddr.u8[0], ieee->i_nodeaddr.u8[1], + ieee->i_nodeaddr.u8[2], ieee->i_nodeaddr.u8[3], + ieee->i_nodeaddr.u8[4], ieee->i_nodeaddr.u8[5], + ieee->i_nodeaddr.u8[6], ieee->i_nodeaddr.u8[7], + status); +#endif #elif defined(CONFIG_NET_LOOPBACK) len += snprintf(&netfile->line[len], NET_LINELEN - len, "%s\tLink encap:Local Loopback at %s\n", diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index d23a392e051..5caee4b8383 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -455,7 +455,8 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, uint8_t iphc1; uint8_t tmp; - ninfodumpbuffer("IPv6 before compression", ipv6, sizeof(struct ipv6_hdr_s)); + ninfodumpbuffer("IPv6 before compression", (FAR const uint8_t *)ipv6, + sizeof(struct ipv6_hdr_s)); g_hc06ptr = g_rimeptr + 2; diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index c6a83480d9c..4e8fc75d77e 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -243,7 +243,8 @@ */ #define SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(a) \ - ((((a)[4]) == 0x0000) && (((a)[5]) == 0x00ff) && (((a)[6]) == 0xfe00)) + ((((a)[4]) == 0x0000) && (((a)[5]) == HTONS(0x00ff)) && \ + (((a)[6]) == 0xfe00)) /* Check whether the 9-bit group-id of the compressed multicast address is * known. It is true if the 9-bit group is the all nodes or all routers @@ -265,27 +266,27 @@ #define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE(a) \ ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ - ((a)[7] == 0x0001 || (a)[7] == 0x0002)) + ((a)[7] == HTONS(0x0001) || (a)[7] == HTONS(0x0002))) /* FFXX:0000:0000:0000:0000:00XX:XXXX:XXXX */ #define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE48(a) \ ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (((a)[5] & 0xff00) == 0)) + (a)[4] == 0 && (((a)[5] & HTONS(0xff00)) == 0)) /* FFXX:0000:0000:0000:0000:0000:00XX:XXXX */ #define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE32(a) \ ((a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ - (a)[4] == 0 && (a)[5] == 0 && ((a)[6] & 0xff00) == 0) + (a)[4] == 0 && (a)[5] == 0 && ((a)[6] & HTONS(0xff00)) == 0) /* FF02:0000:0000:0000:0000:0000:0000:00XX */ #define SIXLOWPAN_IS_MCASTADDR_COMPRESSABLE8(a) \ - ((((a)[0] & 0x00ff) == 0x0002) && \ + ((((a)[0] & HTONS(0x00ff)) == HTONS(0x0002)) && \ (a)[1] == 0 && (a)[2] == 0 && (a)[3] == 0 && \ (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ - (((a)[7] & 0xff00) == 0x0000)) + (((a)[7] & HTONS(0xff00)) == 0x0000)) /* General helper macros ****************************************************/ diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index 933a7f63619..7beceee5c55 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -393,10 +393,10 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev) size_t hdrlen; hdrlen = IPv6_HDRLEN + TCP_HDRLEN; - if (hdrlen < dev->d_len) + if (hdrlen > dev->d_len) { nwarn("WARNING: Packet to small: Have %u need >%u\n", - dev->d_len, hdrlen); + dev->d_len, hdrlen); } else { diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index fae33fe2076..7dd4e9e35c9 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -116,7 +116,7 @@ void sixlowpan_ipfromrime(FAR const struct rimeaddr_s *rime, net_ipv6addr_t ipaddr) { memset(ipaddr, 0, sizeof(net_ipv6addr_t)); - ipaddr[0] = 0xfe80; + ipaddr[0] = HTONS(0xfe80); /* We consider only links with IEEE EUI-64 identifier or IEEE 48-bit MAC * addresses. NOTE: that CONFIG_NET_6LOWPAN_RIMEADDR_SIZE may be 2 or @@ -128,7 +128,7 @@ void sixlowpan_ipfromrime(FAR const struct rimeaddr_s *rime, */ memcpy(&ipaddr[4], rime, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); - ipaddr[4] ^= 0x0200; + ipaddr[4] ^= HTONS(0x0200); } /**************************************************************************** @@ -174,10 +174,10 @@ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, FAR const uint8_t *rimeptr = rime->u8; #if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 - return ((ipaddr[4] == (GETINT16(rimeptr, 0) ^ 0x0200)) && + return ((ipaddr[4] == htons((GETINT16(rimeptr, 0) ^ 0x0200))) && ipaddr[5] == 0 && ipaddr[6] == 0 && ipaddr[7] == 0); #else /* CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 */ - return ((ipaddr[4] == (GETINT16(rimeptr, 0) ^ 0x0200)) && + return ((ipaddr[4] == htons((GETINT16(rimeptr, 0) ^ 0x0200))) && ipaddr[5] == GETINT16(rimeptr, 2) && ipaddr[6] == GETINT16(rimeptr, 4) && ipaddr[7] == GETINT16(rimeptr, 6)); diff --git a/net/tcp/tcp_finddev.c b/net/tcp/tcp_finddev.c index ef6ae8f0d25..e3cf0b32884 100644 --- a/net/tcp/tcp_finddev.c +++ b/net/tcp/tcp_finddev.c @@ -250,7 +250,6 @@ int tcp_local_ipv6_device(FAR struct tcp_conn_s *conn) #else return tcp_find_ipv6_device(conn, NULL); #endif - } #endif /* CONFIG_NET_IPv6 */