add ieee apps
This commit is contained in:
parent
09add96e22
commit
5ca0bc0a5c
2
.gitignore
vendored
2
.gitignore
vendored
@ -18,3 +18,5 @@ cscope.out
|
||||
/*.lib
|
||||
/romfs.img
|
||||
/boot_romfsimg.h
|
||||
/*/*/.built
|
||||
|
||||
|
4
Kconfig
4
Kconfig
@ -15,6 +15,10 @@ menu "Graphics Support"
|
||||
source "$APPSDIR/graphics/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "IEEE 802.15.4"
|
||||
source "$APPSDIR/ieee802154/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Interpreters"
|
||||
source "$APPSDIR/interpreters/Kconfig"
|
||||
endmenu
|
||||
|
2
Makefile
2
Makefile
@ -50,6 +50,7 @@ TOPDIR ?= $(APPDIR)/import
|
||||
CONFIGURED_APPS =
|
||||
SUBDIRS = examples graphics interpreters modbus builtin import nshlib
|
||||
SUBDIRS += netutils platform system
|
||||
SUBDIRS += ieee802154
|
||||
|
||||
# The list of configured directories is derived from NuttX configuration
|
||||
# file: The selected applications are enabled settings in the configuration
|
||||
@ -72,6 +73,7 @@ include netutils/Make.defs
|
||||
include nshlib/Make.defs
|
||||
include platform/Make.defs
|
||||
include system/Make.defs
|
||||
include ieee802154/Make.defs
|
||||
-include external/Make.defs
|
||||
|
||||
# INSTALLED_APPS is the list of currently available application directories. It
|
||||
|
7
ieee802154/Kconfig
Normal file
7
ieee802154/Kconfig
Normal file
@ -0,0 +1,7 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
source "$APPSDIR/ieee802154/coord/Kconfig"
|
||||
source "$APPSDIR/ieee802154/i8sak/Kconfig"
|
37
ieee802154/Make.defs
Normal file
37
ieee802154/Make.defs
Normal file
@ -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 <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 $(wildcard ieee802154/*/Make.defs)
|
78
ieee802154/Makefile
Normal file
78
ieee802154/Makefile
Normal file
@ -0,0 +1,78 @@
|
||||
############################################################################
|
||||
# apps/ieee802154/Makefile
|
||||
#
|
||||
# Copyright (C) 2014 Gregory Nutt. 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/.config # Current configuration
|
||||
|
||||
# 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
|
||||
|
||||
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
|
22
ieee802154/coord/Kconfig
Normal file
22
ieee802154/coord/Kconfig
Normal file
@ -0,0 +1,22 @@
|
||||
#
|
||||
# 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
|
||||
---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
|
39
ieee802154/coord/Make.defs
Normal file
39
ieee802154/coord/Make.defs
Normal file
@ -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 <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_COORD),y)
|
||||
CONFIGURED_APPS += ieee802154/coord
|
||||
endif
|
138
ieee802154/coord/Makefile
Normal file
138
ieee802154/coord/Makefile
Normal file
@ -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 <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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-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
|
162
ieee802154/coord/coord_main.c
Normal file
162
ieee802154/coord/coord_main.c
Normal file
@ -0,0 +1,162 @@
|
||||
/****************************************************************************
|
||||
* 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 <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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* 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 <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <nuttx/ieee802154/ieee802154.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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_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];
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
static struct ieee_coord_s g_coord;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void coord_initialize(struct ieee_coord_s *coord)
|
||||
{
|
||||
int i;
|
||||
coord->nclients = 0;
|
||||
for (i = 0; i < CONFIG_IEEE802154_COORD_MAXCLIENTS; i++)
|
||||
{
|
||||
coord->clients[i].pending.len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
static int coord_loop(FAR struct ieee_coord_s *coord, FAR char *dev, int chan, int panid)
|
||||
{
|
||||
uint8_t pan[2];
|
||||
int ret = OK;
|
||||
|
||||
pan[0] = panid >> 8;
|
||||
pan[1] = panid & 0xFF;
|
||||
|
||||
printf("starting %s on chan %d, panid %02X%02X", dev, chan, pan[0], pan[1]);
|
||||
|
||||
while(ret == OK)
|
||||
{
|
||||
ret = read(coord->fd, &coord->rxbuf, sizeof(struct ieee802154_packet_s));
|
||||
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* coord_main
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
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>");
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
chan = strtol(argv[2], NULL, 0);
|
||||
panid = strtol(argv[3], NULL, 0);
|
||||
|
||||
return coord_loop(&g_coord, argv[1], chan, panid);
|
||||
}
|
23
ieee802154/i8sak/Kconfig
Normal file
23
ieee802154/i8sak/Kconfig
Normal file
@ -0,0 +1,23 @@
|
||||
#
|
||||
# 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
|
||||
---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
|
||||
|
39
ieee802154/i8sak/Make.defs
Normal file
39
ieee802154/i8sak/Make.defs
Normal file
@ -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 <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_I8SAK),y)
|
||||
CONFIGURED_APPS += ieee802154/i8sak
|
||||
endif
|
138
ieee802154/i8sak/Makefile
Normal file
138
ieee802154/i8sak/Makefile
Normal file
@ -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 <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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-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 = 2048
|
||||
|
||||
# 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
|
483
ieee802154/i8sak/i8sak_main.c
Normal file
483
ieee802154/i8sak/i8sak_main.c
Normal file
@ -0,0 +1,483 @@
|
||||
/****************************************************************************
|
||||
* 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 <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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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 <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/ieee802154/ieee802154.h>
|
||||
#include <nuttx/ieee802154/ieee802154_dev.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct ieee802154_packet_s rxpacket;
|
||||
static struct ieee802154_packet_s txpacket;
|
||||
|
||||
int setchan(int fd, int chan)
|
||||
{
|
||||
int ret = ioctl(fd, MAC854IOCSCHAN, (unsigned long)chan );
|
||||
if (ret<0)
|
||||
{
|
||||
printf("MAC854IOCSCHAN failed\n");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int 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;
|
||||
}
|
||||
|
||||
int 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;
|
||||
}
|
||||
|
||||
int scan(int fd)
|
||||
{
|
||||
int chan,scan,oldchan;
|
||||
int ret = OK;
|
||||
uint8_t energy;
|
||||
uint8_t levels[16];
|
||||
|
||||
/* save original channel */
|
||||
|
||||
ret = ioctl(fd, MAC854IOCGCHAN, (unsigned long)&oldchan);
|
||||
if (ret)
|
||||
{
|
||||
printf("MAC854IOCGCHAN failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* do scan */
|
||||
|
||||
printf("Scanning channels ");
|
||||
memset(levels, 0, 16);
|
||||
for(scan=0;scan<256;scan++)
|
||||
{
|
||||
printf("."); fflush(stdout);
|
||||
for (chan=0; chan<16; chan++)
|
||||
{
|
||||
ret = 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;
|
||||
}
|
||||
if(energy > levels[chan])
|
||||
{
|
||||
levels[chan] = energy;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
for (chan=0;chan < 16; chan++)
|
||||
{
|
||||
printf("%2d : [%3d] ",chan+11, levels[chan]);
|
||||
energy = levels[chan] >> 3;
|
||||
while(energy-- > 0) printf("#");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* restore original channel */
|
||||
|
||||
ret = setchan(fd, oldchan);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name : status
|
||||
*
|
||||
* Description :
|
||||
* Show device status
|
||||
****************************************************************************/
|
||||
|
||||
static int status(int fd)
|
||||
{
|
||||
int ret,i;
|
||||
uint8_t panid[2], saddr[2], eaddr[8];
|
||||
int promisc, chan;
|
||||
struct ieee802154_cca_s cca;
|
||||
|
||||
/* Get information */
|
||||
|
||||
ret = ioctl(fd, MAC854IOCGPANID, (unsigned long)&panid);
|
||||
if (ret)
|
||||
{
|
||||
printf("MAC854IOCGPANID failed\n");
|
||||
return ret;
|
||||
}
|
||||
ret = ioctl(fd, MAC854IOCGCHAN, (unsigned long)&chan);
|
||||
if (ret)
|
||||
{
|
||||
printf("MAC854IOCGCHAN failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ioctl(fd, MAC854IOCGSADDR, (unsigned long)&saddr);
|
||||
if (ret)
|
||||
{
|
||||
printf("MAC854IOCGSADDR failed\n");
|
||||
return ret;
|
||||
}
|
||||
ret = ioctl(fd, MAC854IOCGEADDR, (unsigned long)&eaddr);
|
||||
if (ret)
|
||||
{
|
||||
printf("MAC854IOCGEADR failed\n");
|
||||
return ret;
|
||||
}
|
||||
ret = ioctl(fd, MAC854IOCGPROMISC, (unsigned long)&promisc);
|
||||
if (ret)
|
||||
{
|
||||
printf("MAC854IOCGPROMISC failed\n");
|
||||
return ret;
|
||||
}
|
||||
ret = ioctl(fd, MAC854IOCGCCA, (unsigned long)&cca);
|
||||
if (ret)
|
||||
{
|
||||
printf("MAC854IOCGCCA failed\n");
|
||||
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[0], panid[1], chan, 2350+(5*chan), saddr[0], saddr[1]);
|
||||
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(FAR struct ieee802154_packet_s *pack)
|
||||
{
|
||||
printf("Packet len=%d\n", pack->len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name : sniff
|
||||
*
|
||||
* Description :
|
||||
* Listen for all packets with a valid CRC on a given channel.
|
||||
****************************************************************************/
|
||||
|
||||
static int sniff(int fd, int chan)
|
||||
{
|
||||
int ret;
|
||||
ret = setchan(fd, chan);
|
||||
if (ret<0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
#if 0
|
||||
ret = ioctl(fd, MAC854IOCSPROMISC, TRUE);
|
||||
if (ret<0)
|
||||
{
|
||||
printf("Device is not an IEEE 802.15.4 interface!\n");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
printf("Listening on channel %d\n",chan);
|
||||
while (1)
|
||||
{
|
||||
ret = read(fd, &rxpacket, sizeof(struct ieee802154_packet_s));
|
||||
if(ret < 0)
|
||||
{
|
||||
if (errno == EAGAIN)
|
||||
{
|
||||
usleep(1000);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("read: errno=%d\n",errno);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Display packet */
|
||||
display(&rxpacket);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int tx(int fd, FAR struct ieee802154_packet_s *packet)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < packet->len; i++)
|
||||
{
|
||||
printf("%02X", packet->data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* usage
|
||||
****************************************************************************/
|
||||
|
||||
int usage(void)
|
||||
{
|
||||
printf("i8 <device> <op> <arg>\n"
|
||||
" scan\n"
|
||||
" dump\n"
|
||||
" stat\n"
|
||||
" chan <ch>\n"
|
||||
" edth <off|rssi>\n"
|
||||
" csth <off|corr>\n"
|
||||
" tx <hexpacket>\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\n");
|
||||
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 = scan(fd);
|
||||
}
|
||||
else if (!strcmp(argv[2], "dump"))
|
||||
{
|
||||
ret = ioctl(fd, 1000, 0);
|
||||
}
|
||||
else if (!strcmp(argv[2], "stat"))
|
||||
{
|
||||
ret = status(fd);
|
||||
}
|
||||
else if (!strcmp(argv[2], "chan"))
|
||||
{
|
||||
if(argc != 4)
|
||||
{
|
||||
ret = usage();
|
||||
}
|
||||
ret = setchan(fd, arg);
|
||||
}
|
||||
else if (!strcmp(argv[2], "edth"))
|
||||
{
|
||||
if(argc != 4)
|
||||
{
|
||||
goto usage;
|
||||
}
|
||||
ret = getcca(fd, &cca);
|
||||
if(!strcmp("off",argv[3]))
|
||||
{
|
||||
cca.use_ed = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cca.use_ed = 1;
|
||||
cca.edth = arg;
|
||||
}
|
||||
ret = setcca(fd, &cca);
|
||||
}
|
||||
else if (!strcmp(argv[2], "csth"))
|
||||
{
|
||||
if(argc != 4)
|
||||
{
|
||||
goto usage;
|
||||
}
|
||||
ret = getcca(fd, &cca);
|
||||
if(!strcmp("off",argv[3]))
|
||||
{
|
||||
cca.use_cs = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cca.use_cs = 1;
|
||||
cca.csth = arg;
|
||||
}
|
||||
ret = setcca(fd, &cca);
|
||||
}
|
||||
else if (!strcmp(argv[2], "snif"))
|
||||
{
|
||||
ret = sniff(fd,arg);
|
||||
}
|
||||
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)
|
||||
{
|
||||
txpacket.data[id++] = dat;
|
||||
ptr += 2;
|
||||
len -= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
data_error:
|
||||
printf("data error\n");
|
||||
ret = ERROR;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
txpacket.len = id;
|
||||
|
||||
ret = tx(fd,&txpacket);
|
||||
}
|
||||
else
|
||||
{
|
||||
usage:
|
||||
ret = usage();
|
||||
}
|
||||
|
||||
error:
|
||||
close(fd);
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user