diff --git a/.gitignore b/.gitignore index 64741c525..c8d8443fd 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ cscope.out /*.lib /romfs.img /boot_romfsimg.h +/*/*/.built + diff --git a/ieee802154/Kconfig b/ieee802154/Kconfig new file mode 100644 index 000000000..0121396b5 --- /dev/null +++ b/ieee802154/Kconfig @@ -0,0 +1,12 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +menu "IEEE 802.15.4 applications" + +source "$APPSDIR/ieee802154/common/Kconfig" +source "$APPSDIR/ieee802154/coord/Kconfig" +source "$APPSDIR/ieee802154/i8sak/Kconfig" + +endmenu #ieee 802.15.4 apps diff --git a/ieee802154/Make.defs b/ieee802154/Make.defs new file mode 100644 index 000000000..30e651189 --- /dev/null +++ b/ieee802154/Make.defs @@ -0,0 +1,37 @@ +############################################################################ +# apps/ieee802154/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2012, 2015 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 $(wildcard ieee802154/*/Make.defs) diff --git a/ieee802154/Makefile b/ieee802154/Makefile new file mode 100644 index 000000000..8c340caf9 --- /dev/null +++ b/ieee802154/Makefile @@ -0,0 +1,68 @@ +############################################################################ +# apps/ieee802154/Makefile +# +# Copyright (C) 2014 Gregory Nutt. 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. +# +############################################################################ + +-include $(TOPDIR)/.config # Current configuration + +# Sub-directories + +SUBDIRS = $(dir $(wildcard */Makefile)) + +all: nothing + +.PHONY: nothing context depend clean distclean + +define SDIR_template +$(1)_$(2): + $(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" +endef + +$(foreach SDIR, $(CNTXTDIRS), $(eval $(call SDIR_template,$(SDIR),context))) +$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),depend))) +$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),clean))) +$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),distclean))) + +nothing: + +install: + +context: $(foreach SDIR, $(CNTXTDIRS), $(SDIR)_context) + +depend: $(foreach SDIR, $(SUBDIRS), $(SDIR)_depend) + +clean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_clean) + +distclean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_distclean) + +-include Make.dep 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..e2f441c2c --- /dev/null +++ b/ieee802154/common/Makefile @@ -0,0 +1,105 @@ +############################################################################ +# 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_getchan.c +CSRCS += ieee802154_setpanid.c +CSRCS += ieee802154_seteaddr.c ieee802154_setsaddr.c +CSRCS += ieee802154_setpromisc.c ieee802154_setdevmode.c +CSRCS += ieee802154_setcca.c ieee802154_getcca.c +CSRCS += ieee802154_addrparse.c ieee802154_addrstore.c ieee802154_addrtostr.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_addrparse.c b/ieee802154/common/ieee802154_addrparse.c new file mode 100644 index 000000000..91ee37d12 --- /dev/null +++ b/ieee802154/common/ieee802154_addrparse.c @@ -0,0 +1,126 @@ +/**************************************************************************** + * ieee802154/common/ieee802154_addrparse.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_addrparse(FAR struct ieee802154_packet_s *packet, + FAR struct ieee802154_addr_s *dest, + FAR struct ieee802154_addr_s *src) +{ + uint8_t fc1, fc2, daddr, saddr; + int index=3; + + /* read fc */ + fc1 = packet->data[0]; + fc2 = packet->data[1]; + daddr = fc2 & IEEE802154_FC2_DADDR; + saddr = fc2 & IEEE802154_FC2_SADDR; + + /* decode dest addr */ + + if(daddr == IEEE802154_DADDR_SHORT) + { + memcpy(&dest->ia_panid, packet->data+index, 2); + index += 2; /* skip dest pan id */ + memcpy(&dest->ia_saddr, packet->data+index, 2); + index += 2; /* skip dest addr */ + dest->ia_len = 2; + } + else if(daddr == IEEE802154_DADDR_EXT) + { + memcpy(&dest->ia_panid, packet->data+index, 2); + index += 2; /* skip dest pan id */ + memcpy(dest->ia_eaddr, packet->data+index, 8); + index += 8; /* skip dest addr */ + dest->ia_len = 8; + } + else if(daddr == IEEE802154_DADDR_NONE) + { + dest->ia_len = 0; + } + else + { + return -EINVAL; + } + + /* decode source pan id according to compression */ + if( (saddr == IEEE802154_SADDR_SHORT) || (saddr == IEEE802154_SADDR_EXT) ) + { + if(fc1 & IEEE802154_FC1_INTRA) + { + src->ia_panid = dest->ia_panid; + } + else + { + memcpy(&src->ia_panid, packet->data+index, 2); + index += 2; /*skip dest pan id*/ + } + } + + /* decode source addr */ + + if(saddr == IEEE802154_SADDR_SHORT) + { + memcpy(&src->ia_saddr, packet->data+index, 2); + index += 2; /* skip dest addr */ + src->ia_len = 2; + } + else if(saddr == IEEE802154_SADDR_EXT) + { + memcpy(src->ia_eaddr, packet->data+index, 8); + index += 8; /* skip dest addr */ + src->ia_len = 8; + } + else if(saddr == IEEE802154_SADDR_NONE) + { + src->ia_len = 0; + } + else + { + return -EINVAL; + } + + return index; +} + diff --git a/ieee802154/common/ieee802154_addrstore.c b/ieee802154/common/ieee802154_addrstore.c new file mode 100644 index 000000000..6b3aef2df --- /dev/null +++ b/ieee802154/common/ieee802154_addrstore.c @@ -0,0 +1,128 @@ +/**************************************************************************** + * ieee802154/common/ieee802154_addrparse.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_addrstore(FAR struct ieee802154_packet_s *packet, + FAR struct ieee802154_addr_s *dest, + FAR struct ieee802154_addr_s *src) +{ + int index=3; //skip fc and seq + + /* encode dest addr */ + + if(dest == NULL || dest->ia_len == 0) + { + packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_DADDR) | IEEE802154_DADDR_NONE; + } + else + { + memcpy(packet->data+index, &dest->ia_panid, 2); + index += 2; /* skip dest pan id */ + if(dest->ia_len == 2) + { + memcpy(packet->data+index, &dest->ia_saddr, 2); + index += 2; /* skip dest addr */ + packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_DADDR) | IEEE802154_DADDR_SHORT; + } + else if(dest->ia_len == 8) + { + memcpy(packet->data+index, &dest->ia_panid, 2); + index += 2; /* skip dest pan id */ + memcpy(packet->data+index, dest->ia_eaddr, 8); + index += 8; /* skip dest addr */ + packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_DADDR) | IEEE802154_DADDR_EXT; + } + else + { + return -EINVAL; + } + } + + packet->data[0] &= ~IEEE802154_FC1_INTRA; + if( (dest != NULL && dest->ia_len != 0) && (src != NULL && src->ia_len != 0) ) + { + /* we have both adresses, encode source pan id according to compression */ + if( dest->ia_panid == src->ia_panid) + { + packet->data[0] |= IEEE802154_FC1_INTRA; + } + } + + + /* encode source addr */ + + if(src == NULL || src->ia_len==0) + { + packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_SADDR) | IEEE802154_SADDR_NONE; + } + else + { + /*add src pan id if it was not compressed before*/ + if(!(packet->data[0] & IEEE802154_FC1_INTRA)) + { + memcpy(packet->data+index, &src->ia_panid, 2); + index += 2; /*skip src pan id*/ + } + if(src->ia_len == 2) + { + memcpy(packet->data+index, &src->ia_saddr, 2); + index += 2; /* skip src addr */ + packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_SADDR) | IEEE802154_SADDR_SHORT; + } + else if(src->ia_len == 8) + { + memcpy(packet->data+index, src->ia_eaddr, 8); + index += 8; /* skip src addr */ + packet->data[1] = (packet->data[1] & ~IEEE802154_FC2_SADDR) | IEEE802154_SADDR_EXT; + } + else + { + return -EINVAL; + } + } + + return index; +} + diff --git a/ieee802154/common/ieee802154_addrtostr.c b/ieee802154/common/ieee802154_addrtostr.c new file mode 100644 index 000000000..743b2fd55 --- /dev/null +++ b/ieee802154/common/ieee802154_addrtostr.c @@ -0,0 +1,83 @@ +/**************************************************************************** + * ieee802154/common/ieee802154_addrtostr.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 + +int ieee802154_addrtostr(FAR char *buf, int len, FAR struct ieee802154_addr_s *addr) +{ +#ifndef CONFIG_BIG_ENDIAN + uint16_t panid = ((addr->ia_panid & 0xff)<<8) | ((addr->ia_panid>>8) & 0xff); +#else + uint16_t panid = addr->ia_panid; +#endif + + if(addr->ia_len == 0) + { + return snprintf(buf, len, "none"); + } + else if(addr->ia_len == 2) + { +#ifndef CONFIG_BIG_ENDIAN + uint16_t saddr = ((addr->ia_saddr & 0xff)<<8) | ((addr->ia_saddr>>8) & 0xff); +#else + uint16_t saddr = addr->ia_saddr; +#endif + return snprintf(buf, len, "%04X/%04X", panid, saddr); + } + else if(addr->ia_len == 8) + { + int i; + int off = snprintf(buf, len, "%04X/", panid); + for(i=0; i<8; i++) + { + off += snprintf(buf+off, len-off, "%02X", addr->ia_eaddr[i]); + } + return off; + } + else + { + return snprintf(buf,len,""); + } + return -1; +} + diff --git a/ieee802154/common/ieee802154_getcca.c b/ieee802154/common/ieee802154_getcca.c new file mode 100644 index 000000000..5df88e617 --- /dev/null +++ b/ieee802154/common/ieee802154_getcca.c @@ -0,0 +1,57 @@ +/**************************************************************************** + * ieee802154/common/ieee802154_getcca.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_getcca(int fd, FAR struct ieee802154_cca_s *cca) +{ + int ret = ioctl(fd, MAC854IOCGCCA, (unsigned long)cca ); + if (ret<0) + { + printf("MAC854IOCGCCA failed\n"); + } + return ret; +} + diff --git a/ieee802154/common/ieee802154_getchan.c b/ieee802154/common/ieee802154_getchan.c new file mode 100644 index 000000000..93bede8a2 --- /dev/null +++ b/ieee802154/common/ieee802154_getchan.c @@ -0,0 +1,57 @@ +/**************************************************************************** + * ieee802154/common/ieee802154_getchan.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_getchan(int fd, FAR uint8_t *chan) +{ + int ret = ioctl(fd, MAC854IOCGCHAN, (unsigned long)chan ); + if (ret<0) + { + printf("MAC854IOCGCHAN failed\n"); + } + return ret; +} + diff --git a/ieee802154/common/ieee802154_setcca.c b/ieee802154/common/ieee802154_setcca.c new file mode 100644 index 000000000..32515b879 --- /dev/null +++ b/ieee802154/common/ieee802154_setcca.c @@ -0,0 +1,56 @@ +/**************************************************************************** + * 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 +#include + +int ieee802154_setcca(int fd, FAR struct ieee802154_cca_s *cca) +{ + int ret = ioctl(fd, MAC854IOCSCCA, (unsigned long)cca ); + if (ret<0) + { + printf("MAC854IOCSCCA failed\n"); + } + return ret; +} 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_setdevmode.c b/ieee802154/common/ieee802154_setdevmode.c new file mode 100644 index 000000000..6eae328b4 --- /dev/null +++ b/ieee802154/common/ieee802154_setdevmode.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * ieee802154/common/ieee802154_setdevmode.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_setdevmode(int fd, uint8_t devmode) +{ + int ret = ioctl(fd, MAC854IOCSDEVMODE, (unsigned long)devmode ); + if (ret<0) + { + printf("MAC854IOCSDEVMODE 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..a820c77fe --- /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, MAC854IOCSSADDR, (unsigned long)saddr ); + if (ret<0) + { + printf("MAC854IOCSSADDR failed\n"); + } + return ret; +} diff --git a/ieee802154/coord/Kconfig b/ieee802154/coord/Kconfig new file mode 100644 index 000000000..61b84979b --- /dev/null +++ b/ieee802154/coord/Kconfig @@ -0,0 +1,23 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +config IEEE802154_COORD + bool "Generic IEEE 802.15.4 coordinator" + default n + select IEEE802154_COMMON + ---help--- + Enable the IEEE 802.15.4 generic coordinator + +if IEEE802154_COORD + +config IEEE802154_COORD_PROGNAME + string "Program name" + default "coord" + depends on BUILD_KERNEL + ---help--- + This is the name of the program that will be use when the NSH ELF + program is installed. + +endif diff --git a/ieee802154/coord/Make.defs b/ieee802154/coord/Make.defs new file mode 100644 index 000000000..6df3e7b4a --- /dev/null +++ b/ieee802154/coord/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# apps/ieee802154/coord/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2015 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_COORD),y) +CONFIGURED_APPS += ieee802154/coord +endif diff --git a/ieee802154/coord/Makefile b/ieee802154/coord/Makefile new file mode 100644 index 000000000..5dc604f78 --- /dev/null +++ b/ieee802154/coord/Makefile @@ -0,0 +1,138 @@ +############################################################################ +# apps/ieee802154/coord/Makefile +# +# Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. +# Copyright (C) 2014-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. +# +############################################################################ + +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +# Built-in application info + +APPNAME = coord +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 + +# Generic Coordinator + +ASRCS = +CSRCS = +MAINSRC = coord_main.c + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) +MAINOBJ = $(MAINSRC:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) $(MAINSRC) +OBJS = $(AOBJS) $(COBJS) + +ifneq ($(CONFIG_BUILD_KERNEL),y) + OBJS += $(MAINOBJ) +endif + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\libapps$(LIBEXT) +else + BIN = ../../libapps$(LIBEXT) +endif +endif + +ifeq ($(WINTOOL),y) + INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}" +else + INSTALL_DIR = $(BIN_DIR) +endif + +CONFIG_IEEE802154_COORD_PROGNAME ?= coord$(EXEEXT) +PROGNAME = $(CONFIG_IEEE802154_COORD_PROGNAME) + +ROOTDEPPATH = --dep-path . + +# Common build + +VPATH = + +all: .built +.PHONY: clean depend distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + @touch .built + +ifeq ($(CONFIG_BUILD_KERNEL),y) +$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ) + @echo "LD: $(PROGNAME)" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS) + $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME) + +install: $(BIN_DIR)$(DELIM)$(PROGNAME) + +else +install: + +endif + +ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) +$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile + $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) + +context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat +else +context: +endif + +.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/coord/coord_main.c b/ieee802154/coord/coord_main.c new file mode 100644 index 000000000..1ef7d174a --- /dev/null +++ b/ieee802154/coord/coord_main.c @@ -0,0 +1,447 @@ +/**************************************************************************** + * apps/ieee802154/coord/coord_main.c + * + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-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. + * + ****************************************************************************/ + +/* Application description + * + * The coordinator is a central node in any IEEE 802.15.4 wireless network. + * It listens for clients and dispatches short addresses. It stores data from + * source clients and makes it available to destination clients. + * Also, in beacon enabled networks, it broadcasts beacons frames and + * manages guaranteed time slots. + * On non-beacon enabled networks, it sends a beacon only when a beacon + * request is received. + * + * This coordinator is generic. It does not interpret the contents of data + * frames. It only interprets command frames to manage client associations + * and data dispatch. + * + * There is no support for mesh networking (coord/coord traffic and packet + * forwarding). + * + * There is no support either for data security (yet). + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ +#ifndef CONFIG_IEEE802154_COORD_MAXCLIENTS +#define CONFIG_IEEE802154_COORD_MAXCLIENTS 8 +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct ieee_client_s +{ + uint8_t eaddr[8]; /* client extended address */ + uint8_t saddr[2]; /* client short address */ + struct ieee802154_packet_s pending; /* pending packet for device */ +}; + +struct ieee_frame_s +{ + struct ieee802154_packet_s packet; + struct ieee802154_addr_s dest; + struct ieee802154_addr_s src; + uint8_t seq; + uint8_t plen; + uint8_t *payload; +}; + +struct ieee_coord_s +{ + int fd; /* Device handle */ + uint8_t chan; /* PAN channel */ + struct ieee802154_addr_s addr; /* coord own address */ + uint8_t nclients; /* Number of coordinated clients */ + struct ieee_frame_s rxbuf; /* General rx buffer */ + struct ieee_frame_s txbuf; /* General tx buffer */ + struct ieee_client_s clients[CONFIG_IEEE802154_COORD_MAXCLIENTS]; + uint8_t macBSN; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ +static struct ieee_coord_s g_coord; + +/**************************************************************************** + * coord_beacon + ****************************************************************************/ + +static int coord_beacon(FAR struct ieee_coord_s *coord) +{ + FAR struct ieee_frame_s *rx = &coord->rxbuf; + printf("Beacon!\n"); + return 0; +} + +/**************************************************************************** + * coord_data + ****************************************************************************/ + +static int coord_data(FAR struct ieee_coord_s *coord) +{ + printf("Data!\n"); + return 0; +} + +/**************************************************************************** + * coord_ack + ****************************************************************************/ + +static int coord_ack(FAR struct ieee_coord_s *coord) +{ + printf("Ack!\n"); + return 0; +} + +/**************************************************************************** + * coord_command_beacon_req + ****************************************************************************/ + +static int coord_command_beacon_req(FAR struct ieee_coord_s *coord) +{ + FAR struct ieee_frame_s *rx = &coord->rxbuf; + FAR struct ieee802154_packet_s *tx = &coord->txbuf.packet; + int i; + + printf("Beacon request\n"); + + /* check command */ + + /* build response */ + tx->len = 0; + + /* frame control */ + tx->data[tx->len++] = 0x00; /* beacon, no ack */ + tx->data[tx->len++] = 0x00; /* updated later */ + + /* seq */ + tx->data[tx->len++] = coord->macBSN; + coord->macBSN++; + + /* adressing */ + tx->len = ieee802154_addrstore(tx, NULL, &coord->addr); + + /* superframe spec */ + tx->data[tx->len++] = 0xff; + tx->data[tx->len++] = 0xcf; + + /* GTS fields */ + tx->data[tx->len++] = 0x00; + + /* pending addresses */ + tx->data[tx->len++] = 0x00; + + /* payload */ + tx->data[tx->len++] = 'F'; + tx->data[tx->len++] = '4'; + tx->data[tx->len++] = 'G'; + tx->data[tx->len++] = 'R'; + tx->data[tx->len++] = 'X'; + tx->data[tx->len++] = '/'; + tx->data[tx->len++] = '0'; + + printf("Beacon: "); + for(i=0;ilen;i++) printf("%02X", tx->data[i]); + printf("\n"); + return write(coord->fd, tx, sizeof(struct ieee802154_packet_s)); +} + +/**************************************************************************** + * coord_command + ****************************************************************************/ + +static int coord_command(FAR struct ieee_coord_s *coord) +{ + FAR struct ieee_frame_s *rx = &coord->rxbuf; + uint8_t cmd = rx->payload[0]; + + printf("Command %02X!\n",cmd); + + switch(cmd) + { + case IEEE802154_CMD_ASSOC_REQ : break; + case IEEE802154_CMD_ASSOC_RSP : break; + case IEEE802154_CMD_DIS_NOT : break; + case IEEE802154_CMD_DATA_REQ : break; + case IEEE802154_CMD_PANID_CONF_NOT : break; + case IEEE802154_CMD_ORPHAN_NOT : break; + case IEEE802154_CMD_BEACON_REQ : return coord_command_beacon_req(coord); break; + case IEEE802154_CMD_COORD_REALIGN : break; + case IEEE802154_CMD_GTS_REQ : break; + } + return 0; +} + +/**************************************************************************** + * coord_manage + ****************************************************************************/ + +static int coord_manage(FAR struct ieee_coord_s *coord) +{ + /* Decode frame type */ + uint8_t fc1, ftype; + int hlen; + char buf[IEEE802154_ADDRSTRLEN+1]; + + FAR struct ieee_frame_s *rx = &coord->rxbuf; + int i; + + + fc1 = rx->packet.data[0]; + rx->seq = rx->packet.data[2]; + + hlen = ieee802154_addrparse(&rx->packet, &rx->dest, &rx->src); + if(hlen<0) + { + printf("invalid packet\n"); + return 1; + } + + rx->payload = rx->packet.data + hlen; + rx->plen = rx->packet.len - hlen; + + ftype = fc1 & IEEE802154_FC1_FTYPE; + + ieee802154_addrtostr(buf,sizeof(buf),&rx->src); + printf("[%s -> ", buf); + ieee802154_addrtostr(buf,sizeof(buf),&rx->dest); + printf("%s] ", buf); + + for(i=0; iplen; i++) printf("%02X", rx->payload[i]); + printf("\n"); + + 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 volatile int gRun; +static pthread_t gDaemonPid; + +void task_signal(int sig) +{ + gRun = 0; +} + +/**************************************************************************** + * coord_initialize + ****************************************************************************/ + +static void coord_initialize(FAR struct ieee_coord_s *coord, FAR char *dev, FAR char *chan, FAR char *panid) +{ + int i; + coord->nclients = 0; + for (i = 0; i < CONFIG_IEEE802154_COORD_MAXCLIENTS; i++) + { + coord->clients[i].pending.len = 0; + } + coord->chan = strtol(chan , NULL, 0); + + coord->addr.ia_len = 2; + coord->addr.ia_panid = strtol(panid, NULL, 0); + coord->addr.ia_saddr = 0x0001; + + coord->fd = open(dev, O_RDWR); + +} + +#define ACTION_STOP 1 +#define ACTION_PANID 2 + +struct message +{ + int action; + unsigned long param; +}; + +struct message g_message; + +/**************************************************************************** + * coord_task + ****************************************************************************/ +int coord_task(int s_argc, char **s_argv) +{ + FAR struct ieee_frame_s *rx = &g_coord.rxbuf; + int ret; + + coord_initialize(&g_coord, s_argv[3], s_argv[4], s_argv[5]); + + printf("IEEE 802.15.4 Coordinator started, chan %d, panid %04X, argc %d\n", g_coord.chan, g_coord.addr.ia_panid, s_argc); + + ieee802154_setchan (g_coord.fd , g_coord.chan ); + ieee802154_setsaddr(g_coord.fd , g_coord.addr.ia_saddr); + ieee802154_setpanid(g_coord.fd , g_coord.addr.ia_panid); + ieee802154_setdevmode(g_coord.fd, IEEE802154_MODE_PANCOORD); + + if(g_coord.fd<0) + { + fprintf(stderr, "cannot open %s, errno=%d\n", s_argv[3], errno); + exit(ERROR); + } + gRun = 1; + + while(gRun) + { + ret = read(g_coord.fd, &rx->packet, sizeof(struct ieee802154_packet_s)); + if(ret > 0) + { + coord_manage(&g_coord); + } + if(ret < 0) + { + if(errno==4) //EINTR, signal received + { + switch(g_message.action) + { + case ACTION_STOP: + gRun = 0; + break; + + case ACTION_PANID: + g_coord.addr.ia_panid = (uint16_t)g_message.param; + ieee802154_setpanid(g_coord.fd, g_coord.addr.ia_panid); + break; + + default: + printf("received unknown message\n"); + } + } + } + } + + printf("IEEE 802.15.4 Coordinator stopped\n"); + return 0; +} + +/**************************************************************************** + * coord_main +11 ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int coord_main(int argc, FAR char *argv[]) +#endif +{ + + if(argc < 2) + { + printf("coord start | stop | panid\n"); + exit(1); + } + + if(!strcmp(argv[1], "start")) + { + if(argc != 5) + { + printf("coord start \n"); + exit(EXIT_FAILURE); + } + if(gRun) + { + printf("Already started.\n"); + exit(EXIT_FAILURE); + } + printf("IEEE 802.15.4 Coordinator starting...\n"); + gDaemonPid = task_create("coord", SCHED_PRIORITY_DEFAULT, + 1024, + coord_task, argv); + } + else if(!strcmp(argv[1], "stop")) + { + if(!gRun) + { +norun: + printf("Not started.\n"); + exit(EXIT_FAILURE); + } + printf("IEEE 802.15.4 Coordinator stopping...\n"); + g_message.action = ACTION_STOP; + kill(gDaemonPid, SIGUSR1); + } + else if(!strcmp(argv[1], "status")) + { + printf("IEEE 802.15.4 Coordinator %s.\n", gRun?"started":"stopped"); + } + else if(!strcmp(argv[1], "panid")) + { + if(argc != 3) + { + printf("coord panid \n"); + exit(EXIT_FAILURE); + } + if(!gRun) + { + goto norun; + } + g_message.action = ACTION_PANID; + g_message.param = strtol(argv[2], NULL, 0); + kill(gDaemonPid, SIGUSR1); + } + return EXIT_SUCCESS; +} diff --git a/ieee802154/i8sak/Kconfig b/ieee802154/i8sak/Kconfig new file mode 100644 index 000000000..fb11839ba --- /dev/null +++ b/ieee802154/i8sak/Kconfig @@ -0,0 +1,24 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +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 + +if IEEE802154_I8SAK + +config IEEE802154_I8SAK_PROGNAME + string "Program name" + default "i8" + depends on BUILD_KERNEL + ---help--- + This is the name of the program that will be use when the NSH ELF + program is installed. + +endif + diff --git a/ieee802154/i8sak/Make.defs b/ieee802154/i8sak/Make.defs new file mode 100644 index 000000000..28f871e65 --- /dev/null +++ b/ieee802154/i8sak/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# apps/ieee802154/i8sak/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2015 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_I8SAK),y) +CONFIGURED_APPS += ieee802154/i8sak +endif diff --git a/ieee802154/i8sak/Makefile b/ieee802154/i8sak/Makefile new file mode 100644 index 000000000..37fcd8dd0 --- /dev/null +++ b/ieee802154/i8sak/Makefile @@ -0,0 +1,138 @@ +############################################################################ +# apps/ieee802154/i8sak/Makefile +# +# Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. +# Copyright (C) 2014-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. +# +############################################################################ + +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +# IEEE 802.15.4 SAK (swiss army knife ) + +APPNAME = i8 +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 4096 + +# IEEE 802.15.4 SAK (Swiss Army Knife) + +ASRCS = +CSRCS = +MAINSRC = i8sak_main.c + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) +MAINOBJ = $(MAINSRC:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) $(MAINSRC) +OBJS = $(AOBJS) $(COBJS) + +ifneq ($(CONFIG_BUILD_KERNEL),y) + OBJS += $(MAINOBJ) +endif + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\libapps$(LIBEXT) +else + BIN = ../../libapps$(LIBEXT) +endif +endif + +ifeq ($(WINTOOL),y) + INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}" +else + INSTALL_DIR = $(BIN_DIR) +endif + +CONFIG_EXAMPLES_IEEEDUMP_PROGNAME ?= ieeedump$(EXEEXT) +PROGNAME = $(CONFIG_EXAMPLES_IEEEDUMP_PROGNAME) + +ROOTDEPPATH = --dep-path . + +# Common build + +VPATH = + +all: .built +.PHONY: clean depend distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + @touch .built + +ifeq ($(CONFIG_BUILD_KERNEL),y) +$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ) + @echo "LD: $(PROGNAME)" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS) + $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME) + +install: $(BIN_DIR)$(DELIM)$(PROGNAME) + +else +install: + +endif + +ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) +$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile + $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) + +context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat +else +context: +endif + +.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/i8sak/i8sak_main.c b/ieee802154/i8sak/i8sak_main.c new file mode 100644 index 000000000..b4dbc025c --- /dev/null +++ b/ieee802154/i8sak/i8sak_main.c @@ -0,0 +1,598 @@ +/**************************************************************************** + * ieee802154/i8sak/i8sak_main.c + * IEEE 802.15.4 Swiss Army Knife + * + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-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. + * + ****************************************************************************/ + +/**************************************************************************** + * This app can be used to control an IEEE 802.15.4 device from command line. + * Example valid ieee802154 packets: + * + * Beacon request, seq number 01: + * xx xx 01 + * + * Simple data packet + * from long address xx to long address yy, pan id pp for src and dest + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct ieee802154_packet_s gRxPacket; +static struct ieee802154_packet_s gTxPacket; + +uint8_t levels[16]; +uint8_t disp[16]; + +int energy_scan(int fd) +{ + int ret = OK; + uint8_t chan, energy; + + printf("\n"); + + /* do scan */ + memset(disp,0,16); + + while(1) + { + for (chan=0; chan<16; chan++) + { + ret = ieee802154_setchan(fd, chan+11); + if (ret<0) + { + printf("Device is not an IEEE 802.15.4 interface!\n"); + return ret; + } + ret = ioctl(fd, MAC854IOCGED, (unsigned long)&energy); + if (ret<0) + { + printf("Device is not an IEEE 802.15.4 interface!\n"); + return ret; + } + + levels[chan] = energy; + } + + /* compute max with decay */ + + for (chan=0; chan<16; chan++) + { + if(levels[chan] > disp[chan]) + { + disp[chan] = levels[chan]; + } + else + { + if(disp[chan] > 0) disp[chan] -= 1; + } + } + + for (chan=0;chan < 16; chan++) + { + printf("%2d : [%3d] ",chan+11, disp[chan]); + energy = disp[chan] >> 3; + while(energy-- > 0) printf("#"); + printf(" \n"); + } + + /* move cursor 17 lines up : http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html */ + printf("\x1B[16A"); + } + + return ret; +} + +/**************************************************************************** + * Name : status + * + * Description : + * Show device status + ****************************************************************************/ + +static int status(int fd) +{ + int ret,i; + uint8_t chan, eaddr[8]; + uint16_t panid, saddr; + bool promisc; + struct ieee802154_cca_s cca; + + /* Get information */ + + ret = ioctl(fd, MAC854IOCGPANID, (unsigned long)&panid); + if (ret) + { + printf("MAC854IOCGPANID failed\n"); + return ret; + } + + ret = ieee802154_getchan(fd, &chan); + if (ret) + { + return ret; + } + + ret = ioctl(fd, MAC854IOCGSADDR, (unsigned long)&saddr); + if (ret) + { + printf("MAC854IOCGSADDR failed\n"); + return ret; + } + ret = ioctl(fd, MAC854IOCGEADDR, (unsigned long)&eaddr[0]); + if (ret) + { + printf("MAC854IOCGEADR failed\n"); + return ret; + } + ret = ioctl(fd, MAC854IOCGPROMISC, (unsigned long)&promisc); + if (ret) + { + printf("MAC854IOCGPROMISC failed\n"); + return ret; + } + ret = ieee802154_getcca(fd, &cca); + if (ret) + { + return ret; + } +#if 0 + ret = ioctl(fd, MAC854IOCGORDER, (unsigned long)&order); + if (ret) + { + printf("MAC854IOCGORDER failed\n"); + return ret; + } +#endif + /* Display */ + + printf("PANID %02X%02X CHAN %2d (%d MHz)\nSADDR %02X%02X EADDR ", + panid>>8, panid&0xFF, (int)chan, 2350+(5*chan), saddr>>8, saddr&0xFF); + for (i=0; i<8; i++) + { + printf("%02X", eaddr[i]); + } + printf("\nCCA: "); + if (cca.use_ed) + { + printf("ED (%d) ", cca.edth); + } + if (cca.use_cs) + { + printf("CS (%d)", cca.csth); + } + printf("\nPromisc: %s\n", promisc?"Yes":"No"); + return 0; +} + +/**************************************************************************** + * Name : display + * + * Description : + * Display a single packet + ****************************************************************************/ + +static int display(uint8_t chan, FAR struct ieee802154_packet_s *pack, bool verbose) +{ + int i; + int hlen=0, dhlen=0; + char buf[IEEE802154_ADDRSTRLEN+1]; + struct ieee802154_addr_s dest,src; + + hlen = ieee802154_addrparse(pack, &dest, &src); + + dhlen = hlen; + if(hlen>pack->len) dhlen = 0; + + printf("chan=%2d rssi=%3u lqi=%3u len=%3u ", chan, pack->rssi, pack->lqi, pack->len - dhlen); + + if(hlen<0) + { + printf("[invalid header] "); + dhlen = 0; + } + else + { + ieee802154_addrtostr(buf,sizeof(buf),&src); + printf("[%s -> ", buf); + ieee802154_addrtostr(buf,sizeof(buf),&dest); + printf("%s] ", buf); + } + + for (i = 0; i < pack->len - dhlen; i++) + { + printf("%02X", pack->data[i+dhlen]); + } + printf("\n"); + return 0; +} + +/**************************************************************************** + * Name : sniff + * + * Description : + * Listen for all packets with a valid CRC on a given channel. + ****************************************************************************/ +struct sniffargs +{ + int fd; + int verbose; +}; + +static void* sniff(void *arg) +{ + int ret; + struct sniffargs *sa = (struct sniffargs*)arg; + int fd = sa->fd; + uint8_t chan; + + printf("Listening...\n"); + while (1) + { + ret = read(fd, &gRxPacket, sizeof(struct ieee802154_packet_s)); + if(ret < 0) + { + if (errno == EAGAIN) + { + continue; + } + if (errno == EINTR) + { + printf("read: interrupted\n"); + break; + } + else + { + printf("read: errno=%d\n",errno); + break; + } + } + + /* Display packet */ + chan=0; + ieee802154_getchan(fd, &chan); + display(chan, &gRxPacket, sa->verbose); + } + + + return (void*)ret; +} + +/**************************************************************************** + * Name : tx + * + * Description : + * Transmit a frame. + ****************************************************************************/ + +static int tx(int fd, FAR struct ieee802154_packet_s *pack, int verbose) +{ + int i,ret; + + if(verbose) + { + for (i = 0; i < pack->len; i++) + { + printf("%02X", pack->data[i]); + } + fflush(stdout); + } + ret = write(fd, pack, sizeof(struct ieee802154_packet_s)); + if(ret==OK) + { + if(verbose) printf(" OK\n"); + } + else + { + printf(" write: errno=%d\n",errno); + } + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * usage + ****************************************************************************/ + +int usage(void) +{ + printf("i8 []\n" + " scan Energy scan\n" + " beacons [single] Aactive scan [on cur chan]\n" + " dump Show device registers\n" + " chan Select current channel\n" + " snif Listen for packets\n" + " stat Device status\n" + " pa Enable/Disable external RF amplifiers\n" + " edth Select Energy detection rx threshold\n" + " csth Select preamble correlation rx threshold\n" + " tx Transmit a raw packet\n" + ); + return ERROR; +} + +/**************************************************************************** + * i8_main + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int i8_main(int argc, char *argv[]) +#endif +{ + int fd; + int ret = OK; + unsigned long arg=0; + struct ieee802154_cca_s cca; + + printf("IEEE packet sniffer/dumper argc=%d\n",argc); + if (argc<3) + { + return usage(); + } + + if (argc>=4) + { + arg = atol(argv[3]); + } + /* open device */ + + fd = open(argv[1], O_RDWR); + if (fd<0) + { + printf("cannot open %s, errno=%d\n", argv[1], errno); + ret = errno; + goto exit; + } + + /* get mode */ + if (!strcmp(argv[2], "scan")) + { + ret = energy_scan(fd); + } + else if (!strcmp(argv[2], "dump")) + { + ret = ioctl(fd, 1000, 0); + } + else if (!strcmp(argv[2], "pa")) + { + if(argc != 4) + { + goto usage; + } + if(!strcmp(argv[3],"off")) + { + ret = ioctl(fd, 1001, 0); + } + else if(!strcmp(argv[3],"on")) + { + ret = ioctl(fd, 1001, 1); + } + else + { + goto usage; + } + } + else if (!strcmp(argv[2], "stat")) + { + ret = status(fd); + } + else if (!strcmp(argv[2], "chan")) + { + if(argc != 4) + { + goto usage; + } + ret = ieee802154_setchan(fd, arg); + } + else if (!strcmp(argv[2], "edth")) + { + if(argc != 4) + { + goto usage; + } + ret = ieee802154_getcca(fd, &cca); + if(!strcmp("off",argv[3])) + { + cca.use_ed = 0; + } + else + { + cca.use_ed = 1; + cca.edth = arg; + } + ret = ieee802154_setcca(fd, &cca); + } + else if (!strcmp(argv[2], "csth")) + { + if(argc != 4) + { + goto usage; + } + ret = ieee802154_getcca(fd, &cca); + if(!strcmp("off",argv[3])) + { + cca.use_cs = 0; + } + else + { + cca.use_cs = 1; + cca.csth = arg; + } + ret = ieee802154_setcca(fd, &cca); + } + else if (!strcmp(argv[2], "snif")) + { + struct sniffargs args; + + ret = ieee802154_setpromisc(fd, TRUE); + + args.fd = fd; + args.verbose = FALSE; + ret = (int)sniff(&args); + + ret = ieee802154_setpromisc(fd, FALSE); + + } + else if (!strcmp(argv[2], "tx")) + { + int id=0; + int len = strlen(argv[3]); + FAR char *ptr = argv[3]; + + if (len & 1) + { + goto data_error; + } + + /* decode hex packet */ + + while (id<125 && len>0) + { + int dat; + if (sscanf(ptr, "%2x", &dat)==1) + { + gTxPacket.data[id++] = dat; + ptr += 2; + len -= 2; + } + else + { +data_error: + printf("data error\n"); + ret = ERROR; + goto error; + } + } + gTxPacket.len = id; + + ret = tx(fd, &gTxPacket, TRUE); + } + else if (!strcmp(argv[2], "beacons")) + { + struct sniffargs args; + struct ieee802154_addr_s dest; + pthread_t pth; + int i,single = FALSE; + uint8_t ch; + + if(argc==4 && !strcmp(argv[3], "single") ) + { + single = TRUE; + } + + args.fd = fd; + args.verbose = FALSE; + + pthread_create(&pth, NULL, sniff, &args); + + //beacon request + gTxPacket.len = 0; + gTxPacket.data[gTxPacket.len++] = 0x03; //mac command, no ack, no panid compression + gTxPacket.data[gTxPacket.len++] = 0x00; //short destination address, no source address + gTxPacket.data[gTxPacket.len++] = 0; //seq + dest.ia_len = 2; + dest.ia_panid = 0xFFFF; + dest.ia_saddr = 0xFFFF; + + gTxPacket.len = ieee802154_addrstore(&gTxPacket, &dest, NULL); + + gTxPacket.data[gTxPacket.len++] = IEEE802154_CMD_BEACON_REQ; + if(!single) + { + ch = 11; + } + i=0; + while(1) + { + if(!single) + { + ieee802154_setchan(fd, ch); + } + ieee802154_getchan(fd, &ch); + printf("chan=%2d seq=%2X ...\r", (int)ch, i); fflush(stdout); + gTxPacket.data[2] = i; //seq + tx(fd, &gTxPacket, FALSE); + sleep(1); + i++; + if(i==256) + { + i=0; + } + if(!single) + { + ch++; + if(ch==27) ch=11; + } + } + pthread_kill(pth, SIGUSR1); + } + else + { +usage: + ret = usage(); + } + +error: + close(fd); +exit: + return ret; +} + diff --git a/include/ieee802154/ieee802154.h b/include/ieee802154/ieee802154.h new file mode 100644 index 000000000..d506ded7a --- /dev/null +++ b/include/ieee802154/ieee802154.h @@ -0,0 +1,71 @@ +/**************************************************************************** + * 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 + +struct ieee802154_addr_s +{ + uint8_t ia_len; /* structure length NOT including panid, so 2/8*/ + uint16_t ia_panid; + union { + uint16_t _ia_saddr; + uint8_t _ia_eaddr[8]; + } ia_addr; +#define ia_saddr ia_addr._ia_saddr +#define ia_eaddr ia_addr._ia_eaddr +}; +#define IEEE802154_ADDRSTRLEN 22 /* (4+1+8*2) */ + +int ieee802154_setchan (int fd, uint8_t chan); +int ieee802154_getchan (int fd, FAR uint8_t *chan); + +int ieee802154_setpanid (int fd, uint16_t panid); +int ieee802154_setsaddr (int fd, uint16_t saddr); +int ieee802154_seteaddr (int fd, FAR uint8_t *chan); +int ieee802154_setpromisc(int fd, bool promisc); +int ieee802154_setdevmode(int fd, uint8_t devmode); + +int ieee802154_setcca(int fd, FAR struct ieee802154_cca_s *cca); +int ieee802154_getcca(int fd, FAR struct ieee802154_cca_s *cca); + +int ieee802154_addrparse(FAR struct ieee802154_packet_s *inPacket, FAR struct ieee802154_addr_s *dest, FAR struct ieee802154_addr_s *src); +int ieee802154_addrstore(FAR struct ieee802154_packet_s *inPacket, FAR struct ieee802154_addr_s *dest, FAR struct ieee802154_addr_s *src); +int ieee802154_addrtostr(FAR char *buf, int len, FAR struct ieee802154_addr_s *addr); + +#endif /*__APPS_INCLUDE_IEEE802154_IEEE802154_H */