From db1e12512200bd571d92b6c422b40a780d490c5e Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Fri, 7 Aug 2015 16:58:45 +0200 Subject: [PATCH] add common ieee library for all apps. working on coordinator. --- ieee802154/Kconfig | 1 + ieee802154/Makefile | 12 +- ieee802154/common/Kconfig | 11 ++ ieee802154/common/Make.defs | 40 ++++ ieee802154/common/Makefile | 102 ++++++++++ ieee802154/common/ieee802154_setchan.c | 55 ++++++ ieee802154/common/ieee802154_seteaddr.c | 55 ++++++ ieee802154/common/ieee802154_setpanid.c | 55 ++++++ ieee802154/common/ieee802154_setpromisc.c | 56 ++++++ ieee802154/common/ieee802154_setsaddr.c | 55 ++++++ ieee802154/coord/Kconfig | 1 + ieee802154/coord/coord_main.c | 217 +++++++++++++++++++--- ieee802154/i8sak/Kconfig | 1 + include/ieee802154/ieee802154.h | 48 +++++ 14 files changed, 673 insertions(+), 36 deletions(-) create mode 100644 ieee802154/common/Kconfig create mode 100644 ieee802154/common/Make.defs create mode 100644 ieee802154/common/Makefile create mode 100644 ieee802154/common/ieee802154_setchan.c create mode 100644 ieee802154/common/ieee802154_seteaddr.c create mode 100644 ieee802154/common/ieee802154_setpanid.c create mode 100644 ieee802154/common/ieee802154_setpromisc.c create mode 100644 ieee802154/common/ieee802154_setsaddr.c create mode 100644 include/ieee802154/ieee802154.h diff --git a/ieee802154/Kconfig b/ieee802154/Kconfig index a491e6289..213550783 100644 --- a/ieee802154/Kconfig +++ b/ieee802154/Kconfig @@ -3,5 +3,6 @@ # see misc/tools/kconfig-language.txt. # +source "$APPSDIR/ieee802154/common/Kconfig" source "$APPSDIR/ieee802154/coord/Kconfig" source "$APPSDIR/ieee802154/i8sak/Kconfig" diff --git a/ieee802154/Makefile b/ieee802154/Makefile index dd4067914..8c340caf9 100644 --- a/ieee802154/Makefile +++ b/ieee802154/Makefile @@ -37,17 +37,7 @@ # Sub-directories -SUBDIRS = coord i8sak - -# Sub-directories that might need context setup. Directories may need -# context setup for a variety of reasons, but the most common is because -# the example may be built as an NSH built-in function. - -CNTXTDIRS = - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -CNTXTDIRS += coord i8sak -endif +SUBDIRS = $(dir $(wildcard */Makefile)) all: nothing diff --git a/ieee802154/common/Kconfig b/ieee802154/common/Kconfig new file mode 100644 index 000000000..c214543ed --- /dev/null +++ b/ieee802154/common/Kconfig @@ -0,0 +1,11 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +config IEEE802154_COMMON + bool "Common IEEE 802.15.4 library routines" + default n + ---help--- + Some common library routines for ieee 802.15.4 apps + diff --git a/ieee802154/common/Make.defs b/ieee802154/common/Make.defs new file mode 100644 index 000000000..421300973 --- /dev/null +++ b/ieee802154/common/Make.defs @@ -0,0 +1,40 @@ +############################################################################ +# apps/nshlib/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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 NuttX 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 COPYRIGHT HOLDERS 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 +# COPYRIGHT OWNER 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. +# +############################################################################ + +ifeq ($(CONFIG_IEEE802154_COMMON),y) +CONFIGURED_APPS += ieee802154/common +endif + diff --git a/ieee802154/common/Makefile b/ieee802154/common/Makefile new file mode 100644 index 000000000..045d2b1f5 --- /dev/null +++ b/ieee802154/common/Makefile @@ -0,0 +1,102 @@ +############################################################################ +# apps/nshlib/Makefile +# +# Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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 NuttX 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 COPYRIGHT HOLDERS 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 +# COPYRIGHT OWNER 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. +# +############################################################################ + +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +# NSH Library + +ASRCS = +CSRCS = ieee802154_setchan.c ieee802154_setpanid.c +CSRCS += ieee802154_seteaddr.c ieee802154_setsaddr.c +CSRCS += ieee802154_setpromisc.c + +# + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\libapps$(LIBEXT) +else + BIN = ../../libapps$(LIBEXT) +endif +endif + +ROOTDEPPATH = --dep-path . +VPATH = + +# Build targets + +all: .built +.PHONY: context .depend depend clean distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + @touch .built + +install: + +context: + +.depend: Makefile $(SRCS) + @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + @touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep + diff --git a/ieee802154/common/ieee802154_setchan.c b/ieee802154/common/ieee802154_setchan.c new file mode 100644 index 000000000..b1f1d3d50 --- /dev/null +++ b/ieee802154/common/ieee802154_setchan.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * ieee802154/common/ieee802154_setchan.c + * + * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * 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 NuttX 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT OWNER 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +int ieee802154_setchan(int fd, uint8_t chan) +{ + int ret = ioctl(fd, MAC854IOCSCHAN, (unsigned long)chan ); + if (ret<0) + { + printf("MAC854IOCSCHAN failed\n"); + } + return ret; +} diff --git a/ieee802154/common/ieee802154_seteaddr.c b/ieee802154/common/ieee802154_seteaddr.c new file mode 100644 index 000000000..251f4234a --- /dev/null +++ b/ieee802154/common/ieee802154_seteaddr.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * ieee802154/common/ieee802154_eaddr.c + * + * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * 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 NuttX 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT OWNER 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +int ieee802154_seteaddr(int fd, uint8_t *eaddr) +{ + int ret = ioctl(fd, MAC854IOCSEADDR, (unsigned long)eaddr ); + if (ret<0) + { + printf("MAC854IOCSEADDR failed\n"); + } + return ret; +} diff --git a/ieee802154/common/ieee802154_setpanid.c b/ieee802154/common/ieee802154_setpanid.c new file mode 100644 index 000000000..4fd2a862c --- /dev/null +++ b/ieee802154/common/ieee802154_setpanid.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * ieee802154/common/ieee802154_setpanid.c + * + * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * 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 NuttX 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT OWNER 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +int ieee802154_setpanid(int fd, uint16_t panid) +{ + int ret = ioctl(fd, MAC854IOCSPANID, (unsigned long)panid ); + if (ret<0) + { + printf("MAC854IOCSPANID failed\n"); + } + return ret; +} diff --git a/ieee802154/common/ieee802154_setpromisc.c b/ieee802154/common/ieee802154_setpromisc.c new file mode 100644 index 000000000..1ba2cc9c1 --- /dev/null +++ b/ieee802154/common/ieee802154_setpromisc.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * ieee802154/common/ieee802154_setpromisc.c + * + * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * 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 NuttX 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT OWNER 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +int ieee802154_setpromisc(int fd, bool promisc) +{ + int ret = ioctl(fd, MAC854IOCSPROMISC, (unsigned long)promisc ); + if (ret<0) + { + printf("MAC854IOCSPROMISC failed\n"); + } + return ret; +} diff --git a/ieee802154/common/ieee802154_setsaddr.c b/ieee802154/common/ieee802154_setsaddr.c new file mode 100644 index 000000000..7ca225897 --- /dev/null +++ b/ieee802154/common/ieee802154_setsaddr.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * ieee802154/common/ieee802154_setsaddr.c + * + * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * 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 NuttX 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT OWNER 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include + +int ieee802154_setsaddr(int fd, uint16_t saddr) +{ + int ret = ioctl(fd, MAC854IOCSCHAN, (unsigned long)saddr ); + if (ret<0) + { + printf("MAC854IOCSSADDR failed\n"); + } + return ret; +} diff --git a/ieee802154/coord/Kconfig b/ieee802154/coord/Kconfig index ef7c5148b..61b84979b 100644 --- a/ieee802154/coord/Kconfig +++ b/ieee802154/coord/Kconfig @@ -6,6 +6,7 @@ config IEEE802154_COORD bool "Generic IEEE 802.15.4 coordinator" default n + select IEEE802154_COMMON ---help--- Enable the IEEE 802.15.4 generic coordinator diff --git a/ieee802154/coord/coord_main.c b/ieee802154/coord/coord_main.c index a4bc706f0..48f9ad5eb 100644 --- a/ieee802154/coord/coord_main.c +++ b/ieee802154/coord/coord_main.c @@ -61,9 +61,13 @@ #include #include #include +#include +#include #include +#include + /**************************************************************************** * Definitions ****************************************************************************/ @@ -82,14 +86,29 @@ struct ieee_client_s struct ieee802154_packet_s pending; /* pending packet for device */ }; +struct ieee_frame_s +{ + struct ieee802154_packet_s packet; + uint8_t fc1; + uint8_t fc2; + uint8_t seq; + uint8_t *dpanid; + uint8_t *daddr; + uint8_t daddrlen; + uint8_t *spanid; + uint8_t *saddr; + uint8_t saddrlen; + uint8_t *payload; +}; + struct ieee_coord_s { - int fd; /* Device handle */ - uint8_t chan; /* PAN channel */ - uint8_t panid[2]; /* PAN ID */ - uint8_t nclients; /* Number of coordinated clients */ - struct ieee802154_packet_s rxbuf; /* General rx buffer */ - struct ieee_client_s clients[CONFIG_IEEE802154_COORD_MAXCLIENTS]; + int fd; /* Device handle */ + uint8_t chan; /* PAN channel */ + uint16_t panid; /* PAN ID */ + uint8_t nclients; /* Number of coordinated clients */ + struct ieee_frame_s rxbuf; /* General rx buffer */ + struct ieee_client_s clients[CONFIG_IEEE802154_COORD_MAXCLIENTS]; }; /**************************************************************************** @@ -98,10 +117,10 @@ struct ieee_coord_s static struct ieee_coord_s g_coord; /**************************************************************************** - * Private Functions + * coord_initialize ****************************************************************************/ -static void coord_initialize(struct ieee_coord_s *coord) +static void coord_initialize(FAR struct ieee_coord_s *coord, FAR char *dev, FAR char *chan, FAR char *panid) { int i; coord->nclients = 0; @@ -109,26 +128,173 @@ static void coord_initialize(struct ieee_coord_s *coord) { coord->clients[i].pending.len = 0; } + coord->chan = strtol(chan , NULL, 0); + coord->panid = strtol(panid, NULL, 0); + + coord->fd = open(dev, O_RDWR); + } /**************************************************************************** - * Public Functions + * coord_main ****************************************************************************/ -static int coord_loop(FAR struct ieee_coord_s *coord, FAR char *dev, int chan, int panid) +static int coord_beacon(FAR struct ieee_coord_s *coord) { - uint8_t pan[2]; - int ret = OK; + printf("Beacon!\n"); + return 0; +} - pan[0] = panid >> 8; - pan[1] = panid & 0xFF; +/**************************************************************************** + * coord_main + ****************************************************************************/ - printf("starting %s on chan %d, panid %02X%02X", dev, chan, pan[0], pan[1]); +static int coord_data(FAR struct ieee_coord_s *coord) +{ + printf("Data!\n"); + return 0; +} - while(ret == OK) +/**************************************************************************** + * coord_main + ****************************************************************************/ + +static int coord_ack(FAR struct ieee_coord_s *coord) +{ + printf("Ack!\n"); + return 0; +} + +/**************************************************************************** + * coord_main + ****************************************************************************/ + +static int coord_command(FAR struct ieee_coord_s *coord) +{ + printf("Command!\n"); + return 0; +} + +/**************************************************************************** + * coord_main + ****************************************************************************/ + +static int coord_manage(FAR struct ieee_coord_s *coord) +{ + /* Decode frame type */ + uint8_t ftype, saddr, daddr; + int index; + + FAR struct ieee_frame_s *rx = &coord->rxbuf; + int i; + + for(i=0; ipacket.len; i++) printf("%02X", rx->packet.data[i]); + printf("\n"); + + rx->fc1 = rx->packet.data[0]; + rx->fc2 = rx->packet.data[1]; + rx->seq = rx->packet.data[2]; + + ftype = rx->fc1 & IEEE802154_FC1_FTYPE; + daddr = rx->fc2 & IEEE802154_FC2_DADDR; + saddr = rx->fc2 & IEEE802154_FC2_SADDR; + + index = 3; + + if(daddr == IEEE802154_DADDR_SHORT) { - ret = read(coord->fd, &coord->rxbuf, sizeof(struct ieee802154_packet_s)); + rx->dpanid = rx->packet.data+index; + index += 2; /* skip dest pan id */ + rx->daddr = rx->packet.data+index; + index += 2; /* skip dest addr */ + rx->daddrlen = 2; + } + else if(daddr == IEEE802154_DADDR_EXT) + { + rx->dpanid = rx->packet.data+index; + index += 2; /* skip dest pan id */ + rx->daddr = rx->packet.data+index; + index += 8; /* skip dest addr */ + rx->daddrlen = 8; + } + else + { + rx->dpanid = NULL; + rx->daddr = NULL; + rx->daddrlen = 0; + } + if(saddr == IEEE802154_SADDR_SHORT) + { + if(rx->fc1 & IEEE802154_FC1_INTRA) + { + rx->spanid = rx->dpanid; + } + else + { + rx->spanid = rx->packet.data+index; + index += 2; /*skip dest pan id*/ + } + rx->saddr = rx->packet.data+index; + index += 2; /* skip dest addr */ + rx->saddrlen = 2; + } + else if(saddr == IEEE802154_SADDR_EXT) + { + if(rx->fc1 & IEEE802154_FC1_INTRA) + { + rx->spanid = rx->dpanid; + } + else + { + rx->spanid = rx->packet.data+index; + index += 2; /*skip dest pan id*/ + } + rx->saddr = rx->packet.data+index; + index += 8; /* skip dest addr */ + rx->saddrlen = 8; + } + else + { + rx->spanid = NULL; + rx->saddr = NULL; + rx->saddrlen = 0; + } + + printf("SADDR len %d DADDR len %d\n", rx->saddrlen, rx->daddrlen); + switch(ftype) + { + case IEEE802154_FRAME_BEACON : coord_beacon (coord); break; + case IEEE802154_FRAME_DATA : coord_data (coord); break; + case IEEE802154_FRAME_ACK : coord_ack (coord); break; + case IEEE802154_FRAME_COMMAND: coord_command(coord); break; + default : fprintf(stderr, "unknown frame type!"); + } + return 0; +} + +/**************************************************************************** + * coord_loop + ****************************************************************************/ + +static int coord_loop(FAR struct ieee_coord_s *coord) +{ + int ret = 1; + FAR struct ieee_frame_s *rx = &coord->rxbuf; + + printf("starting on chan %d, panid %04X\n", coord->chan, coord->panid); + + ieee802154_setchan (coord->fd, coord->chan ); + ieee802154_setpanid(coord->fd, coord->panid); + //ieee802154_setpromisc(coord->fd, TRUE); + + while(ret > 0) + { + ret = read(coord->fd, &rx->packet, sizeof(struct ieee802154_packet_s)); + if(ret > 0) + { + coord_manage(coord); + } } return OK; } @@ -143,20 +309,21 @@ int main(int argc, FAR char *argv[]) int coord_main(int argc, FAR char *argv[]) #endif { - int chan; - int panid; - - coord_initialize(&g_coord); printf("IEEE 802.15.4 Coordinator start\n"); if (argc<4) { - printf("coord "); + printf("coord [0x]\n"); return ERROR; } - chan = strtol(argv[2], NULL, 0); - panid = strtol(argv[3], NULL, 0); - return coord_loop(&g_coord, argv[1], chan, panid); + coord_initialize(&g_coord, argv[1], argv[2], argv[3]); + if(g_coord.fd<0) + { + fprintf(stderr, "cannot open %s, errno=%d\n", argv[1], errno); + exit(ERROR); + } + + return coord_loop(&g_coord); } diff --git a/ieee802154/i8sak/Kconfig b/ieee802154/i8sak/Kconfig index 95bae3d3b..fb11839ba 100644 --- a/ieee802154/i8sak/Kconfig +++ b/ieee802154/i8sak/Kconfig @@ -6,6 +6,7 @@ config IEEE802154_I8SAK bool "IEEE 802.15.4 Swiss Army Knife" default n + select IEEE802154_COMMON ---help--- Enable the IEEE 802.15.4 Swiss Army Knife diff --git a/include/ieee802154/ieee802154.h b/include/ieee802154/ieee802154.h new file mode 100644 index 000000000..6d4602db6 --- /dev/null +++ b/include/ieee802154/ieee802154.h @@ -0,0 +1,48 @@ +/**************************************************************************** + * apps/include/ieee802154/ieee802154.h + * + * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * 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 NuttX 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT OWNER 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. + * + ****************************************************************************/ + +#ifndef __APPS_INCLUDE_IEEE802154_IEEE802154_H +#define __APPS_INCLUDE_IEEE802154_IEEE802154_H + +#include +#include + +int ieee802154_setchan (int fd, uint8_t chan); +int ieee802154_setpanid (int fd, uint16_t panid); +int ieee802154_setsaddr (int fd, uint16_t saddr); +int ieee802154_seteaddr (int fd, uint8_t *chan); +int ieee802154_setpromisc(int fd, bool promisc); + +#endif /*__APPS_INCLUDE_IEEE802154_IEEE802154_H */