From 867368b929bd236499406a0f6e59343c859ed7c5 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Thu, 5 Dec 2013 18:21:06 +0000 Subject: [PATCH 1/9] Basic NETSTACK_CONF_RADIO based on kernel 802.15.4 --- cpu/native/net/linuxradio-drv.c | 179 ++++++++++++++++++++++ cpu/native/net/linuxradio-drv.h | 8 + platform/minimal-net/Makefile.minimal-net | 2 +- platform/native/Makefile.native | 2 +- 4 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 cpu/native/net/linuxradio-drv.c create mode 100644 cpu/native/net/linuxradio-drv.h diff --git a/cpu/native/net/linuxradio-drv.c b/cpu/native/net/linuxradio-drv.c new file mode 100644 index 000000000..aa94e9e08 --- /dev/null +++ b/cpu/native/net/linuxradio-drv.c @@ -0,0 +1,179 @@ +#include "contiki.h" + +#include "linuxradio-drv.h" + +#include "net/packetbuf.h" +#include "net/netstack.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEBUG 0 +#if DEBUG +#include +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif + +static int sockfd = -1; +static char *sockbuf; +static int buflen; + +#if 0 +static void my_memmove(char *s1, char *s2, int len) +{ + int i; + for(i=0; i 256) { + return 0; + } + memcpy(sockbuf, payload, payload_len); + buflen = payload_len; + + return 0; +} + +static int +transmit(unsigned short transmit_len) +{ + int sent=0; + sent = send(sockfd, sockbuf, buflen, 0); + if(sent < 0) { + perror ("linuxradio send()"); + } + buflen = 0; + return RADIO_TX_OK; +} + +static int +my_send(const void *payload, unsigned short payload_len) +{ + int ret = -1; + + PRINTF("PREPARE & TRANSMIT %u bytes\n", payload_len); + + if(prepare(payload, payload_len)) { + return ret; + } + + ret = transmit(payload_len); + + return ret; +} + +static int +my_read(void *buf, unsigned short buf_len) +{ + return 0; +} + +static int +channel_clear(void) +{ + return 1; +} + +static int +receiving_packet(void) +{ + return 0; +} + +static int +pending_packet(void) +{ + return 0; +} + +static int +set_fd(fd_set *rset, fd_set *wset) +{ + FD_SET(sockfd, rset); + return 1; +} + +static void +handle_fd(fd_set *rset, fd_set *wset) +{ + if(FD_ISSET(sockfd, rset)) { + int bytes = read(sockfd, sockbuf, 256); + buflen = bytes; + PRINTF("linuxradio: read %d bytes\n", bytes); + memcpy(packetbuf_dataptr(), sockbuf, bytes); + packetbuf_set_datalen(bytes); + NETSTACK_RDC.input(); + } +} + +static const struct select_callback linuxradio_sock_callback = { set_fd, handle_fd }; + +static int +on(void) +{ + sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IEEE802154)); + if(sockfd < 0) { + perror ("linuxradio socket()"); + return 0; + } else { + struct ifreq ifr; + strncpy((char *)ifr.ifr_name, "wpan0", IFNAMSIZ); // TODO: make interface configurable + ioctl(sockfd, SIOCGIFINDEX, &ifr); + + struct sockaddr_ll sll; + sll.sll_family = AF_PACKET; + sll.sll_ifindex = ifr.ifr_ifindex; + sll.sll_protocol = htons(ETH_P_IEEE802154); + + if(bind(sockfd, (struct sockaddr *)&sll, sizeof(sll)) < 0) { + perror("linuxradio bind()"); + return 0; + } + + select_set_callback(sockfd, &linuxradio_sock_callback); + return 1; + } +} + +static int +off(void) +{ + close(sockfd); + sockfd = -1; + return 1; +} + +const struct radio_driver linuxradio_driver = + { + init, + prepare, + transmit, + my_send, + my_read, + channel_clear, + receiving_packet, + pending_packet, + on, + off, + }; diff --git a/cpu/native/net/linuxradio-drv.h b/cpu/native/net/linuxradio-drv.h new file mode 100644 index 000000000..5952a3eb2 --- /dev/null +++ b/cpu/native/net/linuxradio-drv.h @@ -0,0 +1,8 @@ +#ifndef __LINUXRADIO_DRV_H__ +#define __LINUXRADIO_DRV_H__ + +#include "dev/radio.h" + +extern const struct radio_driver linuxradio_driver; + +#endif diff --git a/platform/minimal-net/Makefile.minimal-net b/platform/minimal-net/Makefile.minimal-net index dd7632d92..2c2399617 100644 --- a/platform/minimal-net/Makefile.minimal-net +++ b/platform/minimal-net/Makefile.minimal-net @@ -14,7 +14,7 @@ CONTIKI_TARGET_SOURCEFILES = contiki-main.c clock.c leds.c leds-arch.c cfs-posix ifeq ($(HOST_OS),Windows) CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c else -CONTIKI_TARGET_SOURCEFILES += tapdev-drv.c tapdev.c tapdev6.c +CONTIKI_TARGET_SOURCEFILES += tapdev-drv.c tapdev.c tapdev6.c linuxradio-drv.c endif CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) diff --git a/platform/native/Makefile.native b/platform/native/Makefile.native index 198dbabee..504c91a3a 100644 --- a/platform/native/Makefile.native +++ b/platform/native/Makefile.native @@ -17,7 +17,7 @@ ifeq ($(HOST_OS),Windows) CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c TARGET_LIBFILES = /lib/w32api/libws2_32.a /lib/w32api/libiphlpapi.a else -CONTIKI_TARGET_SOURCEFILES += tapdev-drv.c +CONTIKI_TARGET_SOURCEFILES += tapdev-drv.c linuxradio-drv.c #math ifneq ($(CONTIKI_WITH_IPV6),1) CONTIKI_TARGET_SOURCEFILES += tapdev.c From 8a068f8512f84bc718e764225c09892452241dc1 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Fri, 6 Dec 2013 11:25:23 +0000 Subject: [PATCH 2/9] Cleaned up linuxradiodrv code --- cpu/native/net/linuxradio-drv.c | 64 ++++++++++++++++++++++----------- cpu/native/net/linuxradio-drv.h | 35 ++++++++++++++++++ 2 files changed, 79 insertions(+), 20 deletions(-) diff --git a/cpu/native/net/linuxradio-drv.c b/cpu/native/net/linuxradio-drv.c index aa94e9e08..f0f254536 100644 --- a/cpu/native/net/linuxradio-drv.c +++ b/cpu/native/net/linuxradio-drv.c @@ -1,3 +1,38 @@ +/* + * Copyright (c) 2013, Google + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Author: Vladimir Pouzanov + * + */ + #include "contiki.h" #include "linuxradio-drv.h" @@ -26,27 +61,19 @@ static int sockfd = -1; static char *sockbuf; static int buflen; -#if 0 -static void my_memmove(char *s1, char *s2, int len) -{ - int i; - for(i=0; i 256) { + if (payload_len > MAX_PACKET_SIZE) { return 0; } memcpy(sockbuf, payload, payload_len); @@ -60,8 +87,8 @@ transmit(unsigned short transmit_len) { int sent=0; sent = send(sockfd, sockbuf, buflen, 0); - if(sent < 0) { - perror ("linuxradio send()"); + if (sent < 0) { + perror("linuxradio send()"); } buflen = 0; return RADIO_TX_OK; @@ -72,9 +99,7 @@ my_send(const void *payload, unsigned short payload_len) { int ret = -1; - PRINTF("PREPARE & TRANSMIT %u bytes\n", payload_len); - - if(prepare(payload, payload_len)) { + if (prepare(payload, payload_len)) { return ret; } @@ -117,10 +142,9 @@ set_fd(fd_set *rset, fd_set *wset) static void handle_fd(fd_set *rset, fd_set *wset) { - if(FD_ISSET(sockfd, rset)) { + if (FD_ISSET(sockfd, rset)) { int bytes = read(sockfd, sockbuf, 256); buflen = bytes; - PRINTF("linuxradio: read %d bytes\n", bytes); memcpy(packetbuf_dataptr(), sockbuf, bytes); packetbuf_set_datalen(bytes); NETSTACK_RDC.input(); @@ -133,7 +157,7 @@ static int on(void) { sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IEEE802154)); - if(sockfd < 0) { + if (sockfd < 0) { perror ("linuxradio socket()"); return 0; } else { @@ -146,7 +170,7 @@ on(void) sll.sll_ifindex = ifr.ifr_ifindex; sll.sll_protocol = htons(ETH_P_IEEE802154); - if(bind(sockfd, (struct sockaddr *)&sll, sizeof(sll)) < 0) { + if (bind(sockfd, (struct sockaddr *)&sll, sizeof(sll)) < 0) { perror("linuxradio bind()"); return 0; } diff --git a/cpu/native/net/linuxradio-drv.h b/cpu/native/net/linuxradio-drv.h index 5952a3eb2..fddf38d01 100644 --- a/cpu/native/net/linuxradio-drv.h +++ b/cpu/native/net/linuxradio-drv.h @@ -1,3 +1,38 @@ +/* + * Copyright (c) 2013, Google + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Author: Vladimir Pouzanov + * + */ + #ifndef __LINUXRADIO_DRV_H__ #define __LINUXRADIO_DRV_H__ From beef4f5d5d90e08a731c23aa0816ab790cf45480 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Sat, 25 Jan 2014 17:13:15 +0000 Subject: [PATCH 3/9] Added better error handling to linuxradiodrv transmit() --- cpu/native/net/linuxradio-drv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cpu/native/net/linuxradio-drv.c b/cpu/native/net/linuxradio-drv.c index f0f254536..0b30a5989 100644 --- a/cpu/native/net/linuxradio-drv.c +++ b/cpu/native/net/linuxradio-drv.c @@ -89,6 +89,7 @@ transmit(unsigned short transmit_len) sent = send(sockfd, sockbuf, buflen, 0); if (sent < 0) { perror("linuxradio send()"); + return RADIO_TX_ERR; } buflen = 0; return RADIO_TX_OK; From 5fed4a3f1ce54df8bba152f97ac75cbb205a47fd Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Sat, 25 Jan 2014 17:13:49 +0000 Subject: [PATCH 4/9] Using MAX_PACKET_SIZE where appropriate in linuxradiodrv --- cpu/native/net/linuxradio-drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/native/net/linuxradio-drv.c b/cpu/native/net/linuxradio-drv.c index 0b30a5989..9718b4d42 100644 --- a/cpu/native/net/linuxradio-drv.c +++ b/cpu/native/net/linuxradio-drv.c @@ -144,7 +144,7 @@ static void handle_fd(fd_set *rset, fd_set *wset) { if (FD_ISSET(sockfd, rset)) { - int bytes = read(sockfd, sockbuf, 256); + int bytes = read(sockfd, sockbuf, MAX_PACKET_SIZE); buflen = bytes; memcpy(packetbuf_dataptr(), sockbuf, bytes); packetbuf_set_datalen(bytes); From 113d9761f7c7162227e6f14d91037680a682b6a7 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Sat, 25 Jan 2014 17:16:01 +0000 Subject: [PATCH 5/9] Better failure handling in linuxradiodrv --- cpu/native/net/linuxradio-drv.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cpu/native/net/linuxradio-drv.c b/cpu/native/net/linuxradio-drv.c index 9718b4d42..9275c1379 100644 --- a/cpu/native/net/linuxradio-drv.c +++ b/cpu/native/net/linuxradio-drv.c @@ -67,6 +67,9 @@ static int init(void) { sockbuf = malloc(MAX_PACKET_SIZE); + if (sockbuf == 0) { + return 1; + } return 0; } @@ -163,8 +166,13 @@ on(void) return 0; } else { struct ifreq ifr; - strncpy((char *)ifr.ifr_name, "wpan0", IFNAMSIZ); // TODO: make interface configurable - ioctl(sockfd, SIOCGIFINDEX, &ifr); + // TODO: interface should not be hard-coded + strncpy((char *)ifr.ifr_name, "wpan0", IFNAMSIZ); + int err = ioctl(sockfd, SIOCGIFINDEX, &ifr); + if (err == -1) { + perror ("linuxradio ioctl()"); + return 0; + } struct sockaddr_ll sll; sll.sll_family = AF_PACKET; From 43a327df5ad48e5095d806130cb00c9d7d6d6f0f Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Sat, 25 Jan 2014 17:16:54 +0000 Subject: [PATCH 6/9] Cleaned up and re-formatted source of linuxradiodrv --- cpu/native/net/linuxradio-drv.c | 69 ++++++++++++++------------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/cpu/native/net/linuxradio-drv.c b/cpu/native/net/linuxradio-drv.c index 9275c1379..237cb2b64 100644 --- a/cpu/native/net/linuxradio-drv.c +++ b/cpu/native/net/linuxradio-drv.c @@ -67,16 +67,15 @@ static int init(void) { sockbuf = malloc(MAX_PACKET_SIZE); - if (sockbuf == 0) { + if(sockbuf == 0) { return 1; } return 0; } - static int prepare(const void *payload, unsigned short payload_len) { - if (payload_len > MAX_PACKET_SIZE) { + if(payload_len > MAX_PACKET_SIZE) { return 0; } memcpy(sockbuf, payload, payload_len); @@ -84,26 +83,24 @@ prepare(const void *payload, unsigned short payload_len) return 0; } - static int transmit(unsigned short transmit_len) { - int sent=0; + int sent = 0; sent = send(sockfd, sockbuf, buflen, 0); - if (sent < 0) { + if(sent < 0) { perror("linuxradio send()"); return RADIO_TX_ERR; } buflen = 0; return RADIO_TX_OK; } - static int my_send(const void *payload, unsigned short payload_len) { int ret = -1; - if (prepare(payload, payload_len)) { + if(prepare(payload, payload_len)) { return ret; } @@ -111,42 +108,36 @@ my_send(const void *payload, unsigned short payload_len) return ret; } - static int my_read(void *buf, unsigned short buf_len) { return 0; } - static int channel_clear(void) { return 1; } - static int receiving_packet(void) { return 0; } - static int pending_packet(void) { return 0; } - static int set_fd(fd_set *rset, fd_set *wset) { FD_SET(sockfd, rset); return 1; } - static void handle_fd(fd_set *rset, fd_set *wset) { - if (FD_ISSET(sockfd, rset)) { + if(FD_ISSET(sockfd, rset)) { int bytes = read(sockfd, sockbuf, MAX_PACKET_SIZE); buflen = bytes; memcpy(packetbuf_dataptr(), sockbuf, bytes); @@ -154,32 +145,32 @@ handle_fd(fd_set *rset, fd_set *wset) NETSTACK_RDC.input(); } } - static const struct select_callback linuxradio_sock_callback = { set_fd, handle_fd }; static int on(void) { + struct ifreq ifr; + int err; + struct sockaddr_ll sll; + sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IEEE802154)); - if (sockfd < 0) { - perror ("linuxradio socket()"); + if(sockfd < 0) { + perror("linuxradio socket()"); return 0; } else { - struct ifreq ifr; - // TODO: interface should not be hard-coded + /* TODO: interface should not be hard-coded */ strncpy((char *)ifr.ifr_name, "wpan0", IFNAMSIZ); - int err = ioctl(sockfd, SIOCGIFINDEX, &ifr); - if (err == -1) { - perror ("linuxradio ioctl()"); + err = ioctl(sockfd, SIOCGIFINDEX, &ifr); + if(err == -1) { + perror("linuxradio ioctl()"); return 0; } - - struct sockaddr_ll sll; sll.sll_family = AF_PACKET; sll.sll_ifindex = ifr.ifr_ifindex; sll.sll_protocol = htons(ETH_P_IEEE802154); - if (bind(sockfd, (struct sockaddr *)&sll, sizeof(sll)) < 0) { + if(bind(sockfd, (struct sockaddr *)&sll, sizeof(sll)) < 0) { perror("linuxradio bind()"); return 0; } @@ -188,7 +179,6 @@ on(void) return 1; } } - static int off(void) { @@ -196,17 +186,16 @@ off(void) sockfd = -1; return 1; } - const struct radio_driver linuxradio_driver = - { - init, - prepare, - transmit, - my_send, - my_read, - channel_clear, - receiving_packet, - pending_packet, - on, - off, - }; +{ + init, + prepare, + transmit, + my_send, + my_read, + channel_clear, + receiving_packet, + pending_packet, + on, + off, +}; From 52c90519d9c855bca57718ee9e23666898e4c5d9 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Wed, 19 Feb 2014 17:04:00 +0000 Subject: [PATCH 7/9] Fixed missing #includes and restricted linuxradiodrv compilation to linux --- cpu/native/net/linuxradio-drv.c | 7 +++++++ platform/minimal-net/contiki-conf.h | 12 +++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cpu/native/net/linuxradio-drv.c b/cpu/native/net/linuxradio-drv.c index 237cb2b64..da645762f 100644 --- a/cpu/native/net/linuxradio-drv.c +++ b/cpu/native/net/linuxradio-drv.c @@ -35,11 +35,15 @@ #include "contiki.h" +#ifdef linux + #include "linuxradio-drv.h" #include "net/packetbuf.h" #include "net/netstack.h" +#include +#include #include #include #include @@ -145,6 +149,7 @@ handle_fd(fd_set *rset, fd_set *wset) NETSTACK_RDC.input(); } } + static const struct select_callback linuxradio_sock_callback = { set_fd, handle_fd }; static int @@ -199,3 +204,5 @@ const struct radio_driver linuxradio_driver = on, off, }; + +#endif diff --git a/platform/minimal-net/contiki-conf.h b/platform/minimal-net/contiki-conf.h index e736b363d..1e15adc7c 100644 --- a/platform/minimal-net/contiki-conf.h +++ b/platform/minimal-net/contiki-conf.h @@ -36,6 +36,12 @@ #include #include +struct select_callback { + int (* set_fd)(fd_set *fdr, fd_set *fdw); + void (* handle_fd)(fd_set *fdr, fd_set *fdw); +}; +int select_set_callback(int fd, const struct select_callback *callback); + #define CC_CONF_REGISTER_ARGS 1 #define CC_CONF_FUNCTION_POINTER_ARGS 1 #define CC_CONF_FASTCALL @@ -88,9 +94,9 @@ typedef unsigned short uip_stats_t; */ #define WEBSERVER_CONF_STATUSPAGE 1 -/* RPL currently works only on Windows. *nix would require converting the tun interface to two pcap tees. */ +/* RPL currently works only on Windows. *nix would require converting the tun interface to two pcap tees. */ //#define RPL_BORDER_ROUTER 0 -#endif +#endif #if UIP_CONF_IPV6_RPL /* RPL motes use the uip.c link layer address or optionally the harded coded address (but without the prefix!) @@ -121,7 +127,7 @@ typedef unsigned short uip_stats_t; * e.g. the jackdaw RNDIS <-> repeater. Then RPL will configure on the radio network and the RF motes will * be reached through bbbb::. * Possibly minimal-net RPL motes could also be added to this interface? - * + * */ #undef UIP_CONF_ROUTER #define UIP_CONF_ROUTER 1 From 4c8618e6baed479a7dbf24b96a528043b62cef64 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Sat, 1 Mar 2014 10:30:41 +0000 Subject: [PATCH 8/9] Extracted linuxradio device name to contiki-conf --- cpu/native/net/linuxradio-drv.c | 3 +-- platform/minimal-net/contiki-conf.h | 2 ++ platform/native/contiki-conf.h | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cpu/native/net/linuxradio-drv.c b/cpu/native/net/linuxradio-drv.c index da645762f..9f78e9cf1 100644 --- a/cpu/native/net/linuxradio-drv.c +++ b/cpu/native/net/linuxradio-drv.c @@ -164,8 +164,7 @@ on(void) perror("linuxradio socket()"); return 0; } else { - /* TODO: interface should not be hard-coded */ - strncpy((char *)ifr.ifr_name, "wpan0", IFNAMSIZ); + strncpy((char *)ifr.ifr_name, NETSTACK_CONF_LINUXRADIO_DEV, IFNAMSIZ); err = ioctl(sockfd, SIOCGIFINDEX, &ifr); if(err == -1) { perror("linuxradio ioctl()"); diff --git a/platform/minimal-net/contiki-conf.h b/platform/minimal-net/contiki-conf.h index 1e15adc7c..6b6b58e4a 100644 --- a/platform/minimal-net/contiki-conf.h +++ b/platform/minimal-net/contiki-conf.h @@ -174,6 +174,8 @@ typedef unsigned short uip_stats_t; #define UIP_CONF_DS6_AADDR_NBU 0 #endif /* NETSTACK_CONF_WITH_IPV6 */ +#define NETSTACK_CONF_LINUXRADIO_DEV "wpan0" + typedef unsigned long clock_time_t; #define CLOCK_CONF_SECOND 1000 #define INFINITE_TIME ULONG_MAX diff --git a/platform/native/contiki-conf.h b/platform/native/contiki-conf.h index 5ce72c09e..b3c15d48c 100644 --- a/platform/native/contiki-conf.h +++ b/platform/native/contiki-conf.h @@ -101,6 +101,8 @@ typedef unsigned short uip_stats_t; #define NETSTACK_CONF_NETWORK sicslowpan_driver +#define NETSTACK_CONF_LINUXRADIO_DEV "wpan0" + #define UIP_CONF_ROUTER 1 #define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06 From bd1b7d981438fb589e27ad6bf5c818175db2eac7 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Sat, 1 Mar 2014 10:37:10 +0000 Subject: [PATCH 9/9] Fixed linuxradio compilation issues with native and minimal-net --- cpu/native/net/linuxradio-drv.c | 3 ++- platform/minimal-net/contiki-conf.h | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cpu/native/net/linuxradio-drv.c b/cpu/native/net/linuxradio-drv.c index 9f78e9cf1..f07861f86 100644 --- a/cpu/native/net/linuxradio-drv.c +++ b/cpu/native/net/linuxradio-drv.c @@ -34,8 +34,9 @@ */ #include "contiki.h" +#include "contiki-conf.h" -#ifdef linux +#if defined(linux) && UIP_CONF_IPV6 #include "linuxradio-drv.h" diff --git a/platform/minimal-net/contiki-conf.h b/platform/minimal-net/contiki-conf.h index 6b6b58e4a..bbc44642b 100644 --- a/platform/minimal-net/contiki-conf.h +++ b/platform/minimal-net/contiki-conf.h @@ -35,6 +35,9 @@ #include #include +#ifndef WIN32_LEAN_AND_MEAN +#include +#endif struct select_callback { int (* set_fd)(fd_set *fdr, fd_set *fdw); @@ -157,6 +160,8 @@ typedef unsigned short uip_stats_t; /* Not used but avoids compile errors while sicslowpan.c is being developed */ #define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06 +#define NETSTACK_CONF_LINUXRADIO_DEV "wpan0" + #define UIP_CONF_UDP 1 #define UIP_CONF_TCP 1 @@ -174,8 +179,6 @@ typedef unsigned short uip_stats_t; #define UIP_CONF_DS6_AADDR_NBU 0 #endif /* NETSTACK_CONF_WITH_IPV6 */ -#define NETSTACK_CONF_LINUXRADIO_DEV "wpan0" - typedef unsigned long clock_time_t; #define CLOCK_CONF_SECOND 1000 #define INFINITE_TIME ULONG_MAX