From ed7098df371177ce967cd70594aab6a208344070 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Apr 2017 08:10:13 -0600 Subject: [PATCH] wireless/ieee802154: Add more IOCTL wrapper functions. --- include/wireless/ieee802154.h | 9 +- wireless/ieee802154/libradio/Makefile | 5 +- .../ieee802154/libradio/ieee802154_geteaddr.c | 71 ++++++++++++++ .../ieee802154/libradio/ieee802154_getpanid.c | 3 +- .../libradio/ieee802154_getpromisc.c | 70 +++++++++++++ .../ieee802154/libradio/ieee802154_getsaddr.c | 70 +++++++++++++ .../ieee802154/libradio/ieee802154_seteaddr.c | 2 +- wireless/ieee802154/libutils/Kconfig | 11 +++ wireless/ieee802154/libutils/Make.defs | 40 ++++++++ wireless/ieee802154/libutils/Makefile | 98 +++++++++++++++++++ 10 files changed, 371 insertions(+), 8 deletions(-) create mode 100644 wireless/ieee802154/libradio/ieee802154_geteaddr.c create mode 100644 wireless/ieee802154/libradio/ieee802154_getpromisc.c create mode 100644 wireless/ieee802154/libradio/ieee802154_getsaddr.c create mode 100644 wireless/ieee802154/libutils/Kconfig create mode 100644 wireless/ieee802154/libutils/Make.defs create mode 100644 wireless/ieee802154/libutils/Makefile diff --git a/include/wireless/ieee802154.h b/include/wireless/ieee802154.h index 1cc645cb4..d82c5ef0b 100644 --- a/include/wireless/ieee802154.h +++ b/include/wireless/ieee802154.h @@ -59,10 +59,13 @@ int ieee802154_setpanid(int fd, uint16_t panid); int ieee802154_getpanid(int fd, FAR uint16_t *panid); int ieee802154_setsaddr(int fd, uint16_t saddr); +int ieee802154_getsaddr(int fd, FAR uint16_t *saddr); -int ieee802154_seteaddr(int fd, FAR uint8_t *chan); +int ieee802154_seteaddr(int fd, FAR const uint8_t *eaddr); +int ieee802154_geteaddr(int fd, FAR uint8_t *eaddr); int ieee802154_setpromisc(int fd, bool promisc); +int ieee802154_getpromisc(int fd, FAR bool *promisc); int ieee802154_setdevmode(int fd, uint8_t devmode); @@ -71,10 +74,10 @@ int ieee802154_getcca(int fd, FAR struct ieee802154_cca_s *cca); /* libutils */ -int ieee802154_addrparse(FAR struct ieee802154_packet_s *inPacket, +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, +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, diff --git a/wireless/ieee802154/libradio/Makefile b/wireless/ieee802154/libradio/Makefile index 4f3ec9314..0853ba19d 100644 --- a/wireless/ieee802154/libradio/Makefile +++ b/wireless/ieee802154/libradio/Makefile @@ -42,9 +42,10 @@ include $(APPDIR)/Make.defs ASRCS = CSRCS = ieee802154_setchan.c ieee802154_getchan.c CSRCS += ieee802154_setpanid.c ieee802154_getpanid.c +CSRCS += ieee802154_setsaddr.c ieee802154_getsaddr.c CSRCS += ieee802154_seteaddr.c ieee802154_geteaddr.c -CSRCS += ieee802154_setsaddr.c -CSRCS += ieee802154_setpromisc.c ieee802154_setdevmode.c +CSRCS += ieee802154_setpromisc.c ieee802154_getpromisc.c +CSRCS += ieee802154_setdevmode.c CSRCS += ieee802154_setcca.c ieee802154_getcca.c AOBJS = $(ASRCS:.S=$(OBJEXT)) diff --git a/wireless/ieee802154/libradio/ieee802154_geteaddr.c b/wireless/ieee802154/libradio/ieee802154_geteaddr.c new file mode 100644 index 000000000..c0e8585ed --- /dev/null +++ b/wireless/ieee802154/libradio/ieee802154_geteaddr.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/ieee802154_geteaddr.c + * + * Copyright (C) 2017 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "wireless/ieee802154.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int ieee802154_geteaddr(int fd, FAR uint8_t *eaddr) +{ + union ieee802154_radioarg_u arg; + + int ret = ioctl(fd, PHY802154IOC_GET_EADDR, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + int errcode = errno; + printf("PHY802154IOC_GET_EADDR failed: %d\n", errcode); + } + + memcpy(eaddr, arg.eaddr, EADDR_SIZE); + return ret; +} diff --git a/wireless/ieee802154/libradio/ieee802154_getpanid.c b/wireless/ieee802154/libradio/ieee802154_getpanid.c index db2ac0b96..7618dbef5 100644 --- a/wireless/ieee802154/libradio/ieee802154_getpanid.c +++ b/wireless/ieee802154/libradio/ieee802154_getpanid.c @@ -2,8 +2,7 @@ * apps/wireless/ieee802154/libradio/ieee802154_getpanid.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. - * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. - * Author: Sebastien Lorquet + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/wireless/ieee802154/libradio/ieee802154_getpromisc.c b/wireless/ieee802154/libradio/ieee802154_getpromisc.c new file mode 100644 index 000000000..9d9a8b0e6 --- /dev/null +++ b/wireless/ieee802154/libradio/ieee802154_getpromisc.c @@ -0,0 +1,70 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/ieee802154_getpromisc.c + * + * Copyright (C) 2017 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "wireless/ieee802154.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int ieee802154_getpromisc(int fd, FAR bool *promisc) +{ + union ieee802154_radioarg_u arg; + + int ret = ioctl(fd, PHY802154IOC_GET_PROMISC, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + int errcode = errno; + printf("PHY802154IOC_GET_PROMISC failed: %d\n", errcode); + } + + *promisc = arg.promisc; + return ret; +} diff --git a/wireless/ieee802154/libradio/ieee802154_getsaddr.c b/wireless/ieee802154/libradio/ieee802154_getsaddr.c new file mode 100644 index 000000000..95326945e --- /dev/null +++ b/wireless/ieee802154/libradio/ieee802154_getsaddr.c @@ -0,0 +1,70 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/ieee802154_getsaddr.c + * + * Copyright (C) 2017 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "wireless/ieee802154.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int ieee802154_getsaddr(int fd, FAR uint16_t *saddr) +{ + union ieee802154_radioarg_u arg; + + int ret = ioctl(fd, PHY802154IOC_GET_SADDR, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + int errcode = errno; + printf("PHY802154IOC_GET_SADDR failed: %d\n", errcode); + } + + *saddr = arg.saddr; + return ret; +} diff --git a/wireless/ieee802154/libradio/ieee802154_seteaddr.c b/wireless/ieee802154/libradio/ieee802154_seteaddr.c index 3df83a761..a0139309c 100644 --- a/wireless/ieee802154/libradio/ieee802154_seteaddr.c +++ b/wireless/ieee802154/libradio/ieee802154_seteaddr.c @@ -54,7 +54,7 @@ * Public Functions ****************************************************************************/ -int ieee802154_seteaddr(int fd, uint8_t *eaddr) +int ieee802154_seteaddr(int fd, FAR const uint8_t *eaddr) { union ieee802154_radioarg_u arg; diff --git a/wireless/ieee802154/libutils/Kconfig b/wireless/ieee802154/libutils/Kconfig new file mode 100644 index 000000000..03b609f62 --- /dev/null +++ b/wireless/ieee802154/libutils/Kconfig @@ -0,0 +1,11 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +config IEEE802154_LIBUTILS + bool "Common IEEE 802.15.4 library routines" + default n + ---help--- + Some common library routines for ieee 802.15.4 apps + diff --git a/wireless/ieee802154/libutils/Make.defs b/wireless/ieee802154/libutils/Make.defs new file mode 100644 index 000000000..69f987078 --- /dev/null +++ b/wireless/ieee802154/libutils/Make.defs @@ -0,0 +1,40 @@ +############################################################################ +# apps/wireless/ieee802154/libutils/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2016-2017 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_LIBUTILS),y) +CONFIGURED_APPS += wireless/ieee802154/libutils +endif + diff --git a/wireless/ieee802154/libutils/Makefile b/wireless/ieee802154/libutils/Makefile new file mode 100644 index 000000000..a68617662 --- /dev/null +++ b/wireless/ieee802154/libutils/Makefile @@ -0,0 +1,98 @@ +############################################################################ +# apps/wireless/ieee802154/libradio/Makefile +# +# Copyright (C) 2016-2-17 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 + +# libutils source files + +ASRCS = +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 +