add common ieee library for all apps. working on coordinator.
This commit is contained in:
parent
b9ae8069b7
commit
db1e125122
@ -3,5 +3,6 @@
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
source "$APPSDIR/ieee802154/common/Kconfig"
|
||||
source "$APPSDIR/ieee802154/coord/Kconfig"
|
||||
source "$APPSDIR/ieee802154/i8sak/Kconfig"
|
||||
|
@ -37,17 +37,7 @@
|
||||
|
||||
# Sub-directories
|
||||
|
||||
SUBDIRS = coord i8sak
|
||||
|
||||
# Sub-directories that might need context setup. Directories may need
|
||||
# context setup for a variety of reasons, but the most common is because
|
||||
# the example may be built as an NSH built-in function.
|
||||
|
||||
CNTXTDIRS =
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
CNTXTDIRS += coord i8sak
|
||||
endif
|
||||
SUBDIRS = $(dir $(wildcard */Makefile))
|
||||
|
||||
all: nothing
|
||||
|
||||
|
11
ieee802154/common/Kconfig
Normal file
11
ieee802154/common/Kconfig
Normal file
@ -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
|
||||
|
40
ieee802154/common/Make.defs
Normal file
40
ieee802154/common/Make.defs
Normal file
@ -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 <gnutt@nuttx.org>
|
||||
#
|
||||
# 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
|
||||
|
102
ieee802154/common/Makefile
Normal file
102
ieee802154/common/Makefile
Normal file
@ -0,0 +1,102 @@
|
||||
############################################################################
|
||||
# apps/nshlib/Makefile
|
||||
#
|
||||
# Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/.config
|
||||
-include $(TOPDIR)/Make.defs
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# NSH Library
|
||||
|
||||
ASRCS =
|
||||
CSRCS = ieee802154_setchan.c ieee802154_setpanid.c
|
||||
CSRCS += ieee802154_seteaddr.c ieee802154_setsaddr.c
|
||||
CSRCS += ieee802154_setpromisc.c
|
||||
|
||||
#
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
BIN = ..\..\libapps$(LIBEXT)
|
||||
else
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = ..\\..\\libapps$(LIBEXT)
|
||||
else
|
||||
BIN = ../../libapps$(LIBEXT)
|
||||
endif
|
||||
endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
VPATH =
|
||||
|
||||
# Build targets
|
||||
|
||||
all: .built
|
||||
.PHONY: context .depend depend clean distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
.built: $(OBJS)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
@touch .built
|
||||
|
||||
install:
|
||||
|
||||
context:
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
||||
|
55
ieee802154/common/ieee802154_setchan.c
Normal file
55
ieee802154/common/ieee802154_setchan.c
Normal file
@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
* ieee802154/common/ieee802154_setchan.c
|
||||
*
|
||||
* Copyright (C) 2015 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/ieee802154/ieee802154_dev.h>
|
||||
|
||||
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;
|
||||
}
|
55
ieee802154/common/ieee802154_seteaddr.c
Normal file
55
ieee802154/common/ieee802154_seteaddr.c
Normal file
@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
* ieee802154/common/ieee802154_eaddr.c
|
||||
*
|
||||
* Copyright (C) 2015 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/ieee802154/ieee802154_dev.h>
|
||||
|
||||
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;
|
||||
}
|
55
ieee802154/common/ieee802154_setpanid.c
Normal file
55
ieee802154/common/ieee802154_setpanid.c
Normal file
@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
* ieee802154/common/ieee802154_setpanid.c
|
||||
*
|
||||
* Copyright (C) 2015 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/ieee802154/ieee802154_dev.h>
|
||||
|
||||
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;
|
||||
}
|
56
ieee802154/common/ieee802154_setpromisc.c
Normal file
56
ieee802154/common/ieee802154_setpromisc.c
Normal file
@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
* ieee802154/common/ieee802154_setpromisc.c
|
||||
*
|
||||
* Copyright (C) 2015 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/ieee802154/ieee802154_dev.h>
|
||||
|
||||
int ieee802154_setpromisc(int fd, bool promisc)
|
||||
{
|
||||
int ret = ioctl(fd, MAC854IOCSPROMISC, (unsigned long)promisc );
|
||||
if (ret<0)
|
||||
{
|
||||
printf("MAC854IOCSPROMISC failed\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
55
ieee802154/common/ieee802154_setsaddr.c
Normal file
55
ieee802154/common/ieee802154_setsaddr.c
Normal file
@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
* ieee802154/common/ieee802154_setsaddr.c
|
||||
*
|
||||
* Copyright (C) 2015 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/ieee802154/ieee802154_dev.h>
|
||||
|
||||
int ieee802154_setsaddr(int fd, uint16_t saddr)
|
||||
{
|
||||
int ret = ioctl(fd, MAC854IOCSCHAN, (unsigned long)saddr );
|
||||
if (ret<0)
|
||||
{
|
||||
printf("MAC854IOCSSADDR failed\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
config IEEE802154_COORD
|
||||
bool "Generic IEEE 802.15.4 coordinator"
|
||||
default n
|
||||
select IEEE802154_COMMON
|
||||
---help---
|
||||
Enable the IEEE 802.15.4 generic coordinator
|
||||
|
||||
|
@ -61,9 +61,13 @@
|
||||
#include <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/ieee802154/ieee802154.h>
|
||||
|
||||
#include <apps/ieee802154/ieee802154.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
@ -82,14 +86,29 @@ struct ieee_client_s
|
||||
struct ieee802154_packet_s pending; /* pending packet for device */
|
||||
};
|
||||
|
||||
struct ieee_frame_s
|
||||
{
|
||||
struct ieee802154_packet_s packet;
|
||||
uint8_t fc1;
|
||||
uint8_t fc2;
|
||||
uint8_t seq;
|
||||
uint8_t *dpanid;
|
||||
uint8_t *daddr;
|
||||
uint8_t daddrlen;
|
||||
uint8_t *spanid;
|
||||
uint8_t *saddr;
|
||||
uint8_t saddrlen;
|
||||
uint8_t *payload;
|
||||
};
|
||||
|
||||
struct ieee_coord_s
|
||||
{
|
||||
int fd; /* Device handle */
|
||||
uint8_t chan; /* PAN channel */
|
||||
uint8_t panid[2]; /* PAN ID */
|
||||
uint8_t nclients; /* Number of coordinated clients */
|
||||
struct ieee802154_packet_s rxbuf; /* General rx buffer */
|
||||
struct ieee_client_s clients[CONFIG_IEEE802154_COORD_MAXCLIENTS];
|
||||
int fd; /* Device handle */
|
||||
uint8_t chan; /* PAN channel */
|
||||
uint16_t panid; /* PAN ID */
|
||||
uint8_t nclients; /* Number of coordinated clients */
|
||||
struct ieee_frame_s rxbuf; /* General rx buffer */
|
||||
struct ieee_client_s clients[CONFIG_IEEE802154_COORD_MAXCLIENTS];
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@ -98,10 +117,10 @@ struct ieee_coord_s
|
||||
static struct ieee_coord_s g_coord;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
* coord_initialize
|
||||
****************************************************************************/
|
||||
|
||||
static void coord_initialize(struct ieee_coord_s *coord)
|
||||
static void coord_initialize(FAR struct ieee_coord_s *coord, FAR char *dev, FAR char *chan, FAR char *panid)
|
||||
{
|
||||
int i;
|
||||
coord->nclients = 0;
|
||||
@ -109,26 +128,173 @@ static void coord_initialize(struct ieee_coord_s *coord)
|
||||
{
|
||||
coord->clients[i].pending.len = 0;
|
||||
}
|
||||
coord->chan = strtol(chan , NULL, 0);
|
||||
coord->panid = strtol(panid, NULL, 0);
|
||||
|
||||
coord->fd = open(dev, O_RDWR);
|
||||
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
* coord_main
|
||||
****************************************************************************/
|
||||
|
||||
static int coord_loop(FAR struct ieee_coord_s *coord, FAR char *dev, int chan, int panid)
|
||||
static int coord_beacon(FAR struct ieee_coord_s *coord)
|
||||
{
|
||||
uint8_t pan[2];
|
||||
int ret = OK;
|
||||
printf("Beacon!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
pan[0] = panid >> 8;
|
||||
pan[1] = panid & 0xFF;
|
||||
/****************************************************************************
|
||||
* coord_main
|
||||
****************************************************************************/
|
||||
|
||||
printf("starting %s on chan %d, panid %02X%02X", dev, chan, pan[0], pan[1]);
|
||||
static int coord_data(FAR struct ieee_coord_s *coord)
|
||||
{
|
||||
printf("Data!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
while(ret == OK)
|
||||
/****************************************************************************
|
||||
* coord_main
|
||||
****************************************************************************/
|
||||
|
||||
static int coord_ack(FAR struct ieee_coord_s *coord)
|
||||
{
|
||||
printf("Ack!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* coord_main
|
||||
****************************************************************************/
|
||||
|
||||
static int coord_command(FAR struct ieee_coord_s *coord)
|
||||
{
|
||||
printf("Command!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* coord_main
|
||||
****************************************************************************/
|
||||
|
||||
static int coord_manage(FAR struct ieee_coord_s *coord)
|
||||
{
|
||||
/* Decode frame type */
|
||||
uint8_t ftype, saddr, daddr;
|
||||
int index;
|
||||
|
||||
FAR struct ieee_frame_s *rx = &coord->rxbuf;
|
||||
int i;
|
||||
|
||||
for(i=0; i<rx->packet.len; i++) printf("%02X", rx->packet.data[i]);
|
||||
printf("\n");
|
||||
|
||||
rx->fc1 = rx->packet.data[0];
|
||||
rx->fc2 = rx->packet.data[1];
|
||||
rx->seq = rx->packet.data[2];
|
||||
|
||||
ftype = rx->fc1 & IEEE802154_FC1_FTYPE;
|
||||
daddr = rx->fc2 & IEEE802154_FC2_DADDR;
|
||||
saddr = rx->fc2 & IEEE802154_FC2_SADDR;
|
||||
|
||||
index = 3;
|
||||
|
||||
if(daddr == IEEE802154_DADDR_SHORT)
|
||||
{
|
||||
ret = read(coord->fd, &coord->rxbuf, sizeof(struct ieee802154_packet_s));
|
||||
rx->dpanid = rx->packet.data+index;
|
||||
index += 2; /* skip dest pan id */
|
||||
rx->daddr = rx->packet.data+index;
|
||||
index += 2; /* skip dest addr */
|
||||
rx->daddrlen = 2;
|
||||
}
|
||||
else if(daddr == IEEE802154_DADDR_EXT)
|
||||
{
|
||||
rx->dpanid = rx->packet.data+index;
|
||||
index += 2; /* skip dest pan id */
|
||||
rx->daddr = rx->packet.data+index;
|
||||
index += 8; /* skip dest addr */
|
||||
rx->daddrlen = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
rx->dpanid = NULL;
|
||||
rx->daddr = NULL;
|
||||
rx->daddrlen = 0;
|
||||
}
|
||||
|
||||
if(saddr == IEEE802154_SADDR_SHORT)
|
||||
{
|
||||
if(rx->fc1 & IEEE802154_FC1_INTRA)
|
||||
{
|
||||
rx->spanid = rx->dpanid;
|
||||
}
|
||||
else
|
||||
{
|
||||
rx->spanid = rx->packet.data+index;
|
||||
index += 2; /*skip dest pan id*/
|
||||
}
|
||||
rx->saddr = rx->packet.data+index;
|
||||
index += 2; /* skip dest addr */
|
||||
rx->saddrlen = 2;
|
||||
}
|
||||
else if(saddr == IEEE802154_SADDR_EXT)
|
||||
{
|
||||
if(rx->fc1 & IEEE802154_FC1_INTRA)
|
||||
{
|
||||
rx->spanid = rx->dpanid;
|
||||
}
|
||||
else
|
||||
{
|
||||
rx->spanid = rx->packet.data+index;
|
||||
index += 2; /*skip dest pan id*/
|
||||
}
|
||||
rx->saddr = rx->packet.data+index;
|
||||
index += 8; /* skip dest addr */
|
||||
rx->saddrlen = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
rx->spanid = NULL;
|
||||
rx->saddr = NULL;
|
||||
rx->saddrlen = 0;
|
||||
}
|
||||
|
||||
printf("SADDR len %d DADDR len %d\n", rx->saddrlen, rx->daddrlen);
|
||||
switch(ftype)
|
||||
{
|
||||
case IEEE802154_FRAME_BEACON : coord_beacon (coord); break;
|
||||
case IEEE802154_FRAME_DATA : coord_data (coord); break;
|
||||
case IEEE802154_FRAME_ACK : coord_ack (coord); break;
|
||||
case IEEE802154_FRAME_COMMAND: coord_command(coord); break;
|
||||
default : fprintf(stderr, "unknown frame type!");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* coord_loop
|
||||
****************************************************************************/
|
||||
|
||||
static int coord_loop(FAR struct ieee_coord_s *coord)
|
||||
{
|
||||
int ret = 1;
|
||||
FAR struct ieee_frame_s *rx = &coord->rxbuf;
|
||||
|
||||
printf("starting on chan %d, panid %04X\n", coord->chan, coord->panid);
|
||||
|
||||
ieee802154_setchan (coord->fd, coord->chan );
|
||||
ieee802154_setpanid(coord->fd, coord->panid);
|
||||
//ieee802154_setpromisc(coord->fd, TRUE);
|
||||
|
||||
while(ret > 0)
|
||||
{
|
||||
ret = read(coord->fd, &rx->packet, sizeof(struct ieee802154_packet_s));
|
||||
if(ret > 0)
|
||||
{
|
||||
coord_manage(coord);
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
@ -143,20 +309,21 @@ int main(int argc, FAR char *argv[])
|
||||
int coord_main(int argc, FAR char *argv[])
|
||||
#endif
|
||||
{
|
||||
int chan;
|
||||
int panid;
|
||||
|
||||
coord_initialize(&g_coord);
|
||||
printf("IEEE 802.15.4 Coordinator start\n");
|
||||
|
||||
if (argc<4)
|
||||
{
|
||||
printf("coord <dev> <chan> <panid>");
|
||||
printf("coord <dev> <chan> [0x]<panid>\n");
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
chan = strtol(argv[2], NULL, 0);
|
||||
panid = strtol(argv[3], NULL, 0);
|
||||
|
||||
return coord_loop(&g_coord, argv[1], chan, panid);
|
||||
coord_initialize(&g_coord, argv[1], argv[2], argv[3]);
|
||||
if(g_coord.fd<0)
|
||||
{
|
||||
fprintf(stderr, "cannot open %s, errno=%d\n", argv[1], errno);
|
||||
exit(ERROR);
|
||||
}
|
||||
|
||||
return coord_loop(&g_coord);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
config IEEE802154_I8SAK
|
||||
bool "IEEE 802.15.4 Swiss Army Knife"
|
||||
default n
|
||||
select IEEE802154_COMMON
|
||||
---help---
|
||||
Enable the IEEE 802.15.4 Swiss Army Knife
|
||||
|
||||
|
48
include/ieee802154/ieee802154.h
Normal file
48
include/ieee802154/ieee802154.h
Normal file
@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
* apps/include/ieee802154/ieee802154.h
|
||||
*
|
||||
* Copyright (C) 2015 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
*
|
||||
* 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 <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int ieee802154_setchan (int fd, uint8_t chan);
|
||||
int ieee802154_setpanid (int fd, uint16_t panid);
|
||||
int ieee802154_setsaddr (int fd, uint16_t saddr);
|
||||
int ieee802154_seteaddr (int fd, uint8_t *chan);
|
||||
int ieee802154_setpromisc(int fd, bool promisc);
|
||||
|
||||
#endif /*__APPS_INCLUDE_IEEE802154_IEEE802154_H */
|
Loading…
x
Reference in New Issue
Block a user