diff --git a/ChangeLog b/ChangeLog index 878c036e54..b0e42092ed 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11523,4 +11523,6 @@ data buffers (2016-02-22). * fs/fat: Add an option to force all transfers to be performed indirectly using the FAT file system's internal sector buffers (2016-02-22). + * net/: Add basic support for IEEE 802.15-4 sockets. Compiles but still + missing a few things (2016-02-25). diff --git a/configs b/configs index b5ee355239..3f48fbde14 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit b5ee35523986bd879009b829723b1c85e1b4662e +Subproject commit 3f48fbde14b07c116c06411209767def1056a9bb diff --git a/net/ieee802154/Kconfig b/net/ieee802154/Kconfig index 3a31761693..0062c29fcd 100644 --- a/net/ieee802154/Kconfig +++ b/net/ieee802154/Kconfig @@ -8,12 +8,41 @@ menu "IEEE802.15-4 Configuration" config NET_IEEE802154 bool "IEEE802.15-4 support" default n - depends on EXPERIMENTAL + depends on EXPERIMENTAL && NET_IPv6 ---help--- Enable IEEE802.15-4 protocol socket support if NET_IEEE802154 +config NET_IEEE802154_MTU + int "IEEE 802.15-4 packet buffer size (MTU)" + default 1294 if NET_IPv6 + default 590 if !NET_IPv6 + depends on NET_ETHERNET + range 590 1518 + ---help--- + Packet buffer size. This size includes the TCP/UDP payload plus the + size of TCP/UDP header, the IP header, and the IEEE 802.15-4 header. + This value is normally referred to as the MTU (Maximum Transmission + Unit); the payload is the MSS (Maximum Segment Size). + + IPv4 hosts are required to be able to handle an MSS of at least + 536 octets, resulting in a minimum buffer size of 536+20+20+xx = + xx. REVISIT! + + IPv6 hosts are required to be able to handle an MSS of 1220 octets, + resulting in a minimum buffer size of of 1220+20+40+xx = xx. REVISIT! + +config IEEE802154_TCP_RECVWNDO + int "EEE 802.15-4 TCP receive window size" + default 1220 if NET_IPv6 + default 536 if !NET_IPv6 + depends on NET_ETHERNET && NET_TCP + ---help--- + The size of the advertised receiver's window. Should be set low + (i.e., to the size of the MSS) if the application is slow to process + incoming data, or high (32768 bytes) if the application processes + data quickly. REVISIT! endif # NET_IEEE802154 endmenu # IEEE802.15-4 Configuration diff --git a/net/ieee802154/Make.defs b/net/ieee802154/Make.defs index 93d849eff7..de55524501 100644 --- a/net/ieee802154/Make.defs +++ b/net/ieee802154/Make.defs @@ -39,7 +39,7 @@ ifeq ($(CONFIG_NET_IEEE802154),y) # Include IEEE802.15-4 file in the build -# NET_CSRCS += +# NET_CSRCS += # Include the ieee802154 directory in the build diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index b850dc109f..29a20c747d 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -61,23 +61,22 @@ * Pre-processor Definitions ****************************************************************************/ -#define NETDEV_ETH_FORMAT "eth%d" -#define NETDEV_LO_FORMAT "lo" -#define NETDEV_SLIP_FORMAT "sl%d" -#define NETDEV_TUN_FORMAT "tun%d" +#define NETDEV_ETH_FORMAT "eth%d" +#define NETDEV_LO_FORMAT "lo" +#define NETDEV_IEEE802154_FORMAT "wpan%d" +#define NETDEV_SLIP_FORMAT "sl%d" +#define NETDEV_TUN_FORMAT "tun%d" #if defined(CONFIG_NET_SLIP) # define NETDEV_DEFAULT_FORMAT NETDEV_SLIP_FORMAT #elif defined(CONFIG_NET_ETHERNET) # define NETDEV_DEFAULT_FORMAT NETDEV_ETH_FORMAT +#elif defined(CONFIG_NET_IEEE802154) +# define NETDEV_DEFAULT_FORMAT NETDEV_IEEE802154_FORMAT #else /* if defined(CONFIG_NET_LOOPBACK) */ # define NETDEV_DEFAULT_FORMAT NETDEV_LO_FORMAT #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - /**************************************************************************** * Private Data ****************************************************************************/ @@ -217,8 +216,14 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) #ifdef CONFIG_NET_IEEE802154 case NET_LL_IEEE802154: /* IEEE802.15-4 */ - nlldbg("ERROR: IEEE 802.15-4 not yet supported\n"); - return -ENOSYS; +# warning Missing IEEE 802.15-4 logic: Header length + //dev->d_llhdrlen = ???; + dev->d_mtu = CONFIG_NET_IEEE802154_MTU; +#ifdef CONFIG_NET_TCP + dev->d_recvwndo = CONFIG_NET_IEEE802154_TCP_RECVWNDO; +#endif + devfmt = NETDEV_IEEE802154_FORMAT; + break; #endif #ifdef CONFIG_NET_SLIP diff --git a/net/socket/net_close.c b/net/socket/net_close.c index 8d657583bd..c4d8cfff85 100644 --- a/net/socket/net_close.c +++ b/net/socket/net_close.c @@ -301,12 +301,12 @@ static inline void netclose_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154); #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/socket/net_sendfile.c b/net/socket/net_sendfile.c index a8b7b9f162..e286cb2af7 100644 --- a/net/socket/net_sendfile.c +++ b/net/socket/net_sendfile.c @@ -175,7 +175,8 @@ static uint16_t ack_interrupt(FAR struct net_driver_s *dev, FAR void *pvconn, if (IFF_IS_IPv6(dev->d_flags)) #endif { - DEBUGASSERT(pstate->snd_sock == PF_INET6); + DEBUGASSERT(pstate->snd_sock == PF_INET6 || + pstate->snd_sock == PF_IEEE802154); tcp = TCPIPv6BUF; } #endif /* CONFIG_NET_IPv6 */ @@ -514,12 +515,14 @@ static inline void sendfile_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index a6921315fd..a02a1e3acc 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -1024,7 +1024,7 @@ static inline void recvfrom_udpsender(struct net_driver_s *dev, struct recvfrom_ * class of addresses, the IPv4-mapped IPv6 addresses. */ - if (conn->domain == PF_INET6) + if (conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) { FAR struct sockaddr_in6 *infrom6 = (FAR struct sockaddr_in6 *)infrom; FAR socklen_t *fromlen = pstate->rf_fromlen; @@ -1350,12 +1350,12 @@ static inline void recvfrom_udp_rxnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_INET6) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver of the receive ready */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || psock->s_domain == PF_INET6); #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_rxnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else @@ -1892,6 +1892,9 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, #ifdef CONFIG_NET_IPv6 case PF_INET6: +#ifdef CONFIG_NET_IEEE802145 + case PF_IEEE802154: +#endif { minlen = sizeof(struct sockaddr_in6); } diff --git a/net/socket/socket.c b/net/socket/socket.c index 93fd41a278..cfe84fdc7e 100644 --- a/net/socket/socket.c +++ b/net/socket/socket.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/socket/socket.c * - * Copyright (C) 2007-2009, 2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2012, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -250,7 +250,7 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock) int ret; int err; - /* Only PF_INET, PF_INET6 or PF_PACKET domains supported */ + /* Only PF_INET, PF_INET6, PF_PACKET, PF_IEEE802154 domains supported */ switch (domain) { @@ -265,6 +265,9 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock) #ifdef CONFIG_NET_IPv6 case PF_INET6: +#ifdef CONFIG_NET_IEEE802154 + case PF_IEEE802154: +#endif #ifdef CONFIG_NET_LOCAL ipdomain = true; #endif diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 2f3284d709..27692fcce4 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -149,7 +149,7 @@ struct tcp_conn_s uint8_t sndseq[4]; /* The sequence number that was last sent by us */ uint8_t crefs; /* Reference counts on this instance */ #if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6) - uint8_t domain; /* IP domain: PF_INET or PF_INET6 */ + uint8_t domain; /* IP domain: PF_INET, PF_INET6, or PF_IEEE802154 */ #endif uint8_t sa; /* Retransmission time-out calculation state * variable */ diff --git a/net/tcp/tcp_accept.c b/net/tcp/tcp_accept.c index 102f8c2213..6bb1bd3d8a 100644 --- a/net/tcp/tcp_accept.c +++ b/net/tcp/tcp_accept.c @@ -139,7 +139,9 @@ static inline void accept_tcpsender(FAR struct socket *psock, { FAR struct sockaddr_in6 *inaddr = (FAR struct sockaddr_in6 *)addr; - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + inaddr->sin6_family = AF_INET6; inaddr->sin6_port = conn->rport; net_ipv6addr_copy(inaddr->sin6_addr.s6_addr, conn->u.ipv6.raddr); diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index 6cc9950fc0..ab579a042f 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -977,6 +977,8 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev, domain = ipv6 ? PF_INET6 : PF_INET; #elif defined(CONFIG_NET_IPv4) domain = PF_INET; +#elif defined(CONFIG_NET_IEEE802154) + domain = PF_IEEE80254; #else /* defined(CONFIG_NET_IPv6) */ domain = PF_INET6; #endif diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 077a1dbe2e..bf14e81434 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -241,11 +241,13 @@ static inline void send_ipselect(FAR struct net_driver_s *dev, tcp_ipv4_select(dev); } - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ { /* Select the IPv6 domain */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + tcp_ipv4_select(dev); } } @@ -857,12 +859,14 @@ static inline void send_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index 7c0faac458..3d77aea3c6 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -190,11 +190,13 @@ static inline void tcpsend_ipselect(FAR struct net_driver_s *dev, tcp_ipv4_select(dev); } - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ { /* Select the IPv6 domain */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + tcp_ipv4_select(dev); } } @@ -637,12 +639,14 @@ static inline void send_txnotify(FAR struct socket *psock, #ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv4 - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ #endif /* CONFIG_NET_IPv4 */ { /* Notify the device driver that send data is available */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + #ifdef CONFIG_NETDEV_MULTINIC netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr); #else diff --git a/net/udp/udp.h b/net/udp/udp.h index 91447d2596..621cf927ac 100644 --- a/net/udp/udp.h +++ b/net/udp/udp.h @@ -85,7 +85,7 @@ struct udp_conn_s union ip_binding_u u; /* IP address binding */ uint16_t lport; /* Bound local port number (network byte order) */ uint16_t rport; /* Remote port number (network byte order) */ - uint8_t domain; /* IP domain: PF_INET or PF_INET6 */ + uint8_t domain; /* IP domain: PF_INET, PF_INET6, or PF_IEEE802145 */ uint8_t ttl; /* Default time-to-live */ uint8_t crefs; /* Reference counts on this instance */ diff --git a/net/udp/udp_callback.c b/net/udp/udp_callback.c index 0492fb5bb8..2ae9923d31 100644 --- a/net/udp/udp_callback.c +++ b/net/udp/udp_callback.c @@ -134,7 +134,7 @@ static uint16_t udp_datahandler(FAR struct net_driver_s *dev, FAR struct udp_con * class of addresses, the IPv4-mapped IPv6 addresses. */ - if (conn->domain == PF_INET6) + if (conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) { FAR struct udp_hdr_s *udp = UDPIPv6BUF; FAR struct ipv6_hdr_s *ipv6 = IPv6BUF; diff --git a/net/udp/udp_psock_sendto.c b/net/udp/udp_psock_sendto.c index 71fbe55af1..60cc465496 100644 --- a/net/udp/udp_psock_sendto.c +++ b/net/udp/udp_psock_sendto.c @@ -188,11 +188,13 @@ static inline void sendto_ipselect(FAR struct net_driver_s *dev, udp_ipv4_select(dev); } - else /* if (psock->s_domain == PF_INET6) */ + else /* if (psock->s_domain == PF_INET6 || psock->s_domain == PF_IEEE802154) */ { /* Select the IPv6 domain */ - DEBUGASSERT(psock->s_domain == PF_INET6); + DEBUGASSERT(psock->s_domain == PF_INET6 || + psock->s_domain == PF_IEEE802154); + udp_ipv4_select(dev); } } diff --git a/net/udp/udp_send.c b/net/udp/udp_send.c index 6bc010d997..f24abc284d 100644 --- a/net/udp/udp_send.c +++ b/net/udp/udp_send.c @@ -121,7 +121,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET || - (conn->domain == PF_INET6 && + ((conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) && ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr))) #endif { @@ -147,7 +147,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) net_ipv4addr_hdrcopy(ipv4->srcipaddr, &dev->d_ipaddr); #ifdef CONFIG_NET_IPv6 - if (conn->domain == PF_INET6 && + if ((conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) && ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr)) { in_addr_t raddr = ip6_get_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr); @@ -241,7 +241,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_IPv4 #ifdef CONFIG_NET_IPv6 if (conn->domain == PF_INET || - (conn->domain == PF_INET6 && + ((conn->domain == PF_INET6 || conn->domain == PF_IEEE802154) && ip6_is_ipv4addr((FAR struct in6_addr *)conn->u.ipv6.raddr))) #endif {