diff --git a/include/wireless/ieee802154.h b/include/wireless/ieee802154.h new file mode 100644 index 000000000..a8242c662 --- /dev/null +++ b/include/wireless/ieee802154.h @@ -0,0 +1,208 @@ +/**************************************************************************** + * apps/include/wireless/ieee802154.h + * + * Copyright(C) 2015 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __APPS_INCLUDE_WIRELESS_IEEE802154_H +#define __APPS_INCLUDE_WIRELESS_IEEE802154_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* libradio *****************************************************************/ +/* Character driver IOCTL helpers */ + +int ieee802154_setchan(int fd, uint8_t chan); +int ieee802154_getchan(int fd, FAR uint8_t *chan); + +int ieee802154_setpanid(int fd, uint16_t panid); +int ieee802154_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 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); +int ieee802154_getdevmode(int fd, FAR uint8_t *devmode); + +int ieee802154_settxpwr(int fd, int32_t txpwr); +int ieee802154_gettxpwr(int fd, FAR int32_t *txpwr); + +int ieee802154_setcca(int fd, FAR struct ieee802154_cca_s *cca); +int ieee802154_getcca(int fd, FAR struct ieee802154_cca_s *cca); + +int ieee802154_energydetect(int fd, FAR bool *energy); + +#ifdef CONFIG_NET_6LOWPAN +/* Netork driver IOCTL helpers */ + +int sixlowpan_setchan(int sock, FAR const char *ifname, uint8_t chan); +int sixlowpan_getchan(int sock, FAR const char *ifname, FAR uint8_t *chan); + +int sixlowpan_setpanid(int sock, FAR const char *ifname, uint16_t panid); +int sixlowpan_getpanid(int sock, FAR const char *ifname, + FAR uint16_t *panid); + +int sixlowpan_setsaddr(int sock, FAR const char *ifname, uint16_t saddr); +int sixlowpan_getsaddr(int sock, FAR const char *ifname, + FAR uint16_t *saddr); + +int sixlowpan_seteaddr(int sock, FAR const char *ifname, + FAR const uint8_t *eaddr); +int sixlowpan_geteaddr(int sock, FAR const char *ifname, + FAR uint8_t *eaddr); + +int sixlowpan_setpromisc(int sock, FAR const char *ifname, bool promisc); +int sixlowpan_getpromisc(int sock, FAR const char *ifname, + FAR bool *promisc); + +int sixlowpan_setdevmode(int sock, FAR const char *ifname, uint8_t devmode); +int sixlowpan_getdevmode(int sock, FAR const char *ifname, + FAR uint8_t *devmode); + +int sixlowpan_settxpwr(int sock, FAR const char *ifname, int32_t txpwr); +int sixlowpan_gettxpwr(int sock, FAR const char *ifname, + FAR int32_t *txpwr); + +int sixlowpan_setcca(int sock, FAR const char *ifname, + FAR struct ieee802154_cca_s *cca); +int sixlowpan_getcca(int sock, FAR const char *ifname, + FAR struct ieee802154_cca_s *cca); + +int sixlowpan_energydetect(int sock, FAR const char *ifname, + FAR bool *energy); +#endif /* CONFIG_NET_6LOWPAN*/ + +/* libmac *******************************************************************/ +/* Character driver IOCTL helpers */ + +#if 0 +int ieee802154_mcps_register(int fd, + FAR struct ieee802154_mcps_register_s *info); +int ieee802154_mlme_register(int fd, + FAR struct ieee802154_mlme_register_s *info); +#endif +int ieee802154_assoc_req(int fd, FAR struct ieee802154_assoc_req_s *req); +int ieee802154_assoc_resp(int fd, FAR struct ieee802154_assoc_resp_s *resp); +int ieee802154_disassoc_req(int fd, + FAR struct ieee802154_disassoc_req_s *req); +int ieee802154_get_req(int fd, FAR struct ieee802154_get_req_s *req); +int ieee802154_gts_req(int fd, FAR struct ieee802154_gts_req_s *req); +int ieee802154_orphan_resp(int fd, + FAR struct ieee802154_orphan_resp_s *resp); +int ieee802154_rxenable_req(int fd, + FAR struct ieee802154_rxenable_req_s *req); +int ieee802154_scan_req(int fd, FAR struct ieee802154_scan_req_s *req); +int ieee802154_set_req(int fd, FAR struct ieee802154_set_req_s *req); +int ieee802154_start_req(int fd, FAR struct ieee802154_start_req_s *req); +int ieee802154_sync_req(int fd, FAR struct ieee802154_sync_req_s *req); +int ieee802154_poll_req(int fd, FAR struct ieee802154_poll_req_s *req); +#if 0 +int ieee802154_dps_req(int fd, FAR struct ieee802154_dps_req_s *req); +int ieee802154_sounding_req(int fd, + FAR struct ieee802154_sounding_req_s *req); +int ieee802154_calibrate_req(int fd, + FAR struct ieee802154_calibrate_req_s *req); +#endif + +#ifdef CONFIG_NET_6LOWPAN +/* Netork driver IOCTL helpers */ + +#if 0 +int sixlowpan_mcps_register(int fd, FAR const char *ifname, + FAR const struct ieee802154_mcps_register_s *info); +int sixlowpan_mlme_register(int fd, FAR const char *ifname, + FAR const struct ieee802154_mlme_register_s *info); +#endif +int sixlowpan_assoc_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_assoc_req_s *req); +int sixlowpan_assoc_resp(int sock, FAR const char *ifname, + FAR struct ieee802154_assoc_resp_s *resp); +int sixlowpan_disassoc_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_disassoc_req_s *req); +int sixlowpan_get_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_get_req_s *req); +int sixlowpan_gts_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_gts_req_s *req); +int sixlowpan_orphan_resp(int sock, FAR const char *ifname, + FAR struct ieee802154_orphan_resp_s *resp); +int sixlowpan_rxenable_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_rxenable_req_s *req); +int sixlowpan_scan_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_scan_req_s *req); +int sixlowpan_set_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_set_req_s *req); +int sixlowpan_start_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_start_req_s *req); +int sixlowpan_sync_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_sync_req_s *req); +int sixlowpan_poll_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_poll_req_s *req); +#if 0 +int sixlowpan_dps_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_dps_req_s *req); +int sixlowpan_sounding_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_sounding_req_s *req); +int sixlowpan_calibrate_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_calibrate_req_s *req); +#endif +#endif /* CONFIG_NET_6LOWPAN*/ + +/* libutils *****************************************************************/ + +int ieee802154_addrparse(FAR struct ieee802154_packet_s *inpacket, + FAR struct ieee802154_addr_s *dest, + FAR struct ieee802154_addr_s *src); +int ieee802154_addrstore(FAR struct ieee802154_packet_s *inpacket, + FAR struct ieee802154_addr_s *dest, + FAR struct ieee802154_addr_s *src); +int ieee802154_addrtostr(FAR char *buf, int len, + FAR struct ieee802154_addr_s *addr); + +#endif /*__APPS_INCLUDE_WIRELESS_IEEE802154_H */ diff --git a/include/wireless/iwpan.h b/include/wireless/iwpan.h new file mode 100644 index 000000000..b56f06a9f --- /dev/null +++ b/include/wireless/iwpan.h @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/include/wireless/iwpan.h + * + * Copyright (C) 2017 Verge Inc. All rights reserved. + * Author: Anthony Merlino + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - 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. + * + * 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_WIRELESS_IWPAN_H +#define __APPS_INCLUDE_WIRELESS_IWPAN_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + + #ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototyppes + ****************************************************************************/ + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __APPS_INCLUDE_WIRELESS_IWPAN_H */ + diff --git a/netutils/netlib/Kconfig b/netutils/netlib/Kconfig index 48cd20a50..9d7884bba 100644 --- a/netutils/netlib/Kconfig +++ b/netutils/netlib/Kconfig @@ -7,6 +7,8 @@ config NETUTILS_NETLIB bool "Network support library" default n depends on NET + select IEEE802154_LIBRADIO if DRIVERS_IEEE802154 + select IEEE802154_LIBMAC if WIRELESS_IEEE802154 ---help--- Enable support for the network support library. diff --git a/netutils/netlib/netlib_getpanid.c b/netutils/netlib/netlib_getpanid.c index 9325b8395..2efa430b4 100644 --- a/netutils/netlib/netlib_getpanid.c +++ b/netutils/netlib/netlib_getpanid.c @@ -46,6 +46,7 @@ #include #include +#include "wireless/ieee802154.h" #include "netutils/netlib.h" #if defined(CONFIG_NET_6LOWPAN) && CONFIG_NSOCKET_DESCRIPTORS > 0 @@ -80,13 +81,10 @@ int netlib_getpanid(FAR const char *ifname, FAR uint16_t *panid) int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0); if (sockfd >= 0) { - /* Put the driver name into the request */ -#warning Missing logic - /* Perform the ioctl to get the current PAN ID */ + /* Use the helper provided in libradio */ + ret = sixlowpan_getpanid(sockfd, ifname, panid); close(sockfd); - - /* Reuturn the current PAN ID */ } } diff --git a/netutils/netlib/netlib_setpanid.c b/netutils/netlib/netlib_setpanid.c index a227c7a19..fb3277d49 100644 --- a/netutils/netlib/netlib_setpanid.c +++ b/netutils/netlib/netlib_setpanid.c @@ -46,6 +46,7 @@ #include #include +#include "wireless/ieee802154.h" #include "netutils/netlib.h" #if defined(CONFIG_NET_6LOWPAN) && CONFIG_NSOCKET_DESCRIPTORS > 0 @@ -80,12 +81,9 @@ int netlib_setpanid(FAR const char *ifname, uint16_t panid) int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0); if (sockfd >= 0) { - /* Put the driver name into the request */ -# warning Missing Logic - /* Put the new PAN ID into the request */ - - /* Perform the ioctl to set the new PAN ID */ + /* Use the helper provided in libradio */ + ret = sixlowpan_setpanid(sockfd, ifname, panid); close(sockfd); } } diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index 13b63f337..1276f0cc3 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -5,7 +5,9 @@ menu "IEEE 802.15.4 applications" -source "$APPSDIR/wireless/ieee802154/common/Kconfig" +source "$APPSDIR/wireless/ieee802154/libradio/Kconfig" +source "$APPSDIR/wireless/ieee802154/libmac/Kconfig" +source "$APPSDIR/wireless/ieee802154/libutils/Kconfig" source "$APPSDIR/wireless/ieee802154/coord/Kconfig" source "$APPSDIR/wireless/ieee802154/i8sak/Kconfig" diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index ecb59032c..f41bb5124 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# apps/wireless/ieee802154/Make.defs +# apps/wireless/ieee802154/libradio/Make.defs # Adds selected applications to apps/ build # # Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. diff --git a/wireless/ieee802154/Makefile b/wireless/ieee802154/Makefile index d9b70ee44..289ab6aed 100644 --- a/wireless/ieee802154/Makefile +++ b/wireless/ieee802154/Makefile @@ -1,7 +1,7 @@ ############################################################################ # apps/wireless/ieee802154/Makefile # -# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. # Author: Sebastien Lorquet # # Redistribution and use in source and binary forms, with or without diff --git a/wireless/ieee802154/coord/Kconfig b/wireless/ieee802154/coord/Kconfig index 61b84979b..325a6fe5d 100644 --- a/wireless/ieee802154/coord/Kconfig +++ b/wireless/ieee802154/coord/Kconfig @@ -6,7 +6,8 @@ config IEEE802154_COORD bool "Generic IEEE 802.15.4 coordinator" default n - select IEEE802154_COMMON + select IEEE802154_LIBRADIO + select IEEE802154_LIBUTILS ---help--- Enable the IEEE 802.15.4 generic coordinator diff --git a/wireless/ieee802154/coord/coord_main.c b/wireless/ieee802154/coord/coord_main.c index fe0247a47..a644cbeff 100644 --- a/wireless/ieee802154/coord/coord_main.c +++ b/wireless/ieee802154/coord/coord_main.c @@ -71,7 +71,7 @@ #include #include -#include "ieee802154/ieee802154.h" +#include "wireless/ieee802154.h" /**************************************************************************** * Pre-processor Definitions @@ -238,15 +238,32 @@ static int coord_command(FAR struct ieee_coord_s *coord) switch (cmd) { - case IEEE802154_CMD_ASSOC_REQ : break; - case IEEE802154_CMD_ASSOC_RSP : break; - case IEEE802154_CMD_DISASSOC_NOT : break; - case IEEE802154_CMD_DATA_REQ : break; - case IEEE802154_CMD_PANID_CONF_NOT : break; - case IEEE802154_CMD_ORPHAN_NOT : break; - case IEEE802154_CMD_BEACON_REQ : return coord_command_beacon_req(coord); break; - case IEEE802154_CMD_COORD_REALIGN : break; - case IEEE802154_CMD_GTS_REQ : break; + case IEEE802154_CMD_ASSOC_REQ: + break; + + case IEEE802154_CMD_ASSOC_RESP: + break; + + case IEEE802154_CMD_DISASSOC_NOT: + break; + + case IEEE802154_CMD_DATA_REQ: + break; + + case IEEE802154_CMD_PANID_CONF_NOT: + break; + + case IEEE802154_CMD_ORPHAN_NOT: + break; + + case IEEE802154_CMD_BEACON_REQ: + return coord_command_beacon_req(coord); + + case IEEE802154_CMD_COORD_REALIGN: + break; + + case IEEE802154_CMD_GTS_REQ: + break; } return 0; @@ -298,11 +315,25 @@ static int coord_manage(FAR struct ieee_coord_s *coord) 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!"); + 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!"); + break; } return 0; @@ -334,9 +365,9 @@ static void coord_initialize(FAR struct ieee_coord_s *coord, FAR char *dev, coord->chan = strtol(chan , NULL, 0); - coord->addr.ia_mode = IEEE802154_ADDRMODE_SHORT; - coord->addr.ia_panid = strtol(panid, NULL, 0); - coord->addr.ia_saddr = 0x0001; + coord->addr.mode = IEEE802154_ADDRMODE_SHORT; + coord->addr.panid = strtol(panid, NULL, 0); + coord->addr.saddr = 0x0001; coord->fd = open(dev, O_RDWR); } @@ -353,11 +384,11 @@ int coord_task(int s_argc, char **s_argv) coord_initialize(&g_coord, s_argv[3], s_argv[4], s_argv[5]); printf("IEEE 802.15.4 Coordinator started, chan %d, panid %04X, argc %d\n", - g_coord.chan, g_coord.addr.ia_panid, s_argc); + g_coord.chan, g_coord.addr.panid, s_argc); ieee802154_setchan (g_coord.fd , g_coord.chan ); - ieee802154_setsaddr(g_coord.fd , g_coord.addr.ia_saddr); - ieee802154_setpanid(g_coord.fd , g_coord.addr.ia_panid); + ieee802154_setsaddr(g_coord.fd , g_coord.addr.saddr); + ieee802154_setpanid(g_coord.fd , g_coord.addr.panid); ieee802154_setdevmode(g_coord.fd, IEEE802154_MODE_PANCOORD); if (g_coord.fd < 0) @@ -386,12 +417,13 @@ int coord_task(int s_argc, char **s_argv) break; case ACTION_PANID: - g_coord.addr.ia_panid = (uint16_t)g_message.param; - ieee802154_setpanid(g_coord.fd, g_coord.addr.ia_panid); + g_coord.addr.panid = (uint16_t)g_message.param; + ieee802154_setpanid(g_coord.fd, g_coord.addr.panid); break; default: - printf("received unknown message\n"); + printf("Received unknown message\n"); + break; } } } diff --git a/wireless/ieee802154/i8sak/Kconfig b/wireless/ieee802154/i8sak/Kconfig index fb11839ba..43b27e31b 100644 --- a/wireless/ieee802154/i8sak/Kconfig +++ b/wireless/ieee802154/i8sak/Kconfig @@ -6,7 +6,8 @@ config IEEE802154_I8SAK bool "IEEE 802.15.4 Swiss Army Knife" default n - select IEEE802154_COMMON + select IEEE802154_LIBRADIO + select IEEE802154_LIBUTILS ---help--- Enable the IEEE 802.15.4 Swiss Army Knife diff --git a/wireless/ieee802154/i8sak/i8sak_main.c b/wireless/ieee802154/i8sak/i8sak_main.c index fdc946cc5..931b3d847 100644 --- a/wireless/ieee802154/i8sak/i8sak_main.c +++ b/wireless/ieee802154/i8sak/i8sak_main.c @@ -2,7 +2,7 @@ * apps/wireless/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, 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2014-2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet * @@ -62,7 +62,7 @@ #include #include -#include "ieee802154/ieee802154.h" +#include "wireless/ieee802154.h" /**************************************************************************** * Private Types @@ -94,8 +94,10 @@ uint8_t g_disp[16]; int energy_scan(int fd) { + union ieee802154_radioarg_u arg; + uint8_t chan; + uint8_t energy; int ret = OK; - uint8_t chan, energy; printf("\n"); @@ -114,14 +116,15 @@ int energy_scan(int fd) return ret; } - ret = ioctl(fd, PHY802154IOC_ENERGYDETECT, (unsigned long)&energy); + ret = ioctl(fd, PHY802154IOC_ENERGYDETECT, + (unsigned long)((uintptr_t)&arg)); if (ret < 0) { printf("Device is not an IEEE 802.15.4 interface!\n"); return ret; } - g_levels[chan] = energy; + g_levels[chan] = arg.energy; } /* Compute max with decay */ @@ -146,7 +149,7 @@ int energy_scan(int fd) printf("%2d : [%3d] ",chan+11, g_disp[chan]); energy = g_disp[chan] >> 3; - while(energy-- > 0) + while (energy-- > 0) { printf("#"); } @@ -171,63 +174,66 @@ int energy_scan(int fd) static int status(int fd) { - int ret,i; - uint8_t chan, eaddr[8]; - uint16_t panid, saddr; - bool promisc; + union ieee802154_radioarg_u arg; struct ieee802154_cca_s cca; + uint8_t eaddr[EADDR_SIZE]; + uint8_t chan; + uint16_t panid; + uint16_t saddr; + bool promisc; + int ret; + int i; /* Get information */ - ret = ioctl(fd, PHY802154IOC_GET_PANID, (unsigned long)&panid); + ret = ioctl(fd, PHY802154IOC_GET_PANID, (unsigned long)((uintptr_t)&arg)); if (ret) { printf("PHY802154IOC_GET_PANID failed\n"); return ret; } + panid = arg.panid; + ret = ieee802154_getchan(fd, &chan); if (ret) { return ret; } - ret = ioctl(fd, PHY802154IOC_GET_SADDR, (unsigned long)&saddr); + ret = ioctl(fd, PHY802154IOC_GET_SADDR, (unsigned long)((uintptr_t)&arg)); if (ret) { printf("PHY802154IOC_GET_SADDR failed\n"); return ret; } - ret = ioctl(fd, PHY802154IOC_GET_EADDR, (unsigned long)&eaddr[0]); + saddr = arg.saddr; + + ret = ioctl(fd, PHY802154IOC_GET_EADDR, (unsigned long)((uintptr_t)&arg)); if (ret) { printf("PHY802154IOC_GET_EADDR failed\n"); return ret; } - ret = ioctl(fd, PHY802154IOC_GET_PROMISC, (unsigned long)&promisc); + memcpy(eaddr, arg.eaddr, EADDR_SIZE); + + ret = ioctl(fd, PHY802154IOC_GET_PROMISC, (unsigned long)((uintptr_t)&arg)); if (ret) { printf("PHY802154IOC_GET_PROMISC failed\n"); return ret; } + promisc = arg.promisc; + ret = ieee802154_getcca(fd, &cca); if (ret) { return ret; } -#if 0 - ret = ioctl(fd, MAC854IOCGORDER, (unsigned long)&order); - if (ret) - { - printf("MAC854IOCGORDER failed\n"); - return ret; - } -#endif - /* Display */ printf("PANID %02X%02X CHAN %2d (%d MHz)\nSADDR %02X%02X EADDR ", @@ -422,10 +428,10 @@ int main(int argc, FAR char *argv[]) int i8_main(int argc, char *argv[]) #endif { + struct ieee802154_cca_s cca; + unsigned long arg = 0; int fd; int ret = OK; - unsigned long arg=0; - struct ieee802154_cca_s cca; printf("IEEE packet sniffer/dumper argc=%d\n", argc); @@ -605,9 +611,9 @@ data_error: g_txpacket.data[g_txpacket.len++] = 0x03; /* Mac command, no ack, no panid compression */ g_txpacket.data[g_txpacket.len++] = 0x00; /* Short destination address, no source address */ g_txpacket.data[g_txpacket.len++] = 0; /* seq */ - dest.ia_mode = IEEE802154_ADDRMODE_SHORT; - dest.ia_panid = 0xFFFF; - dest.ia_saddr = 0xFFFF; + dest.mode = IEEE802154_ADDRMODE_SHORT; + dest.panid = 0xFFFF; + dest.saddr = 0xFFFF; g_txpacket.len = ieee802154_addrstore(&g_txpacket, &dest, NULL); diff --git a/wireless/ieee802154/common/.gitignore b/wireless/ieee802154/libmac/.gitignore similarity index 100% rename from wireless/ieee802154/common/.gitignore rename to wireless/ieee802154/libmac/.gitignore diff --git a/wireless/ieee802154/libmac/Kconfig b/wireless/ieee802154/libmac/Kconfig new file mode 100644 index 000000000..5cffa639d --- /dev/null +++ b/wireless/ieee802154/libmac/Kconfig @@ -0,0 +1,11 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +config IEEE802154_LIBMAC + bool "IEEE 802.15.4 MAC library routines" + default n + ---help--- + Some MAC library routines for ieee 802.15.4 apps + diff --git a/wireless/ieee802154/common/Make.defs b/wireless/ieee802154/libmac/Make.defs similarity index 90% rename from wireless/ieee802154/common/Make.defs rename to wireless/ieee802154/libmac/Make.defs index 89c2b702b..06201a756 100644 --- a/wireless/ieee802154/common/Make.defs +++ b/wireless/ieee802154/libmac/Make.defs @@ -1,8 +1,8 @@ ############################################################################ -# apps/wireless/ieee802154/Make.defs +# apps/wireless/ieee802154/libradio/Make.defs # Adds selected applications to apps/ build # -# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Copyright (C) 2016-17 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -34,7 +34,7 @@ # ############################################################################ -ifeq ($(CONFIG_IEEE802154_COMMON),y) -CONFIGURED_APPS += wireless/ieee802154/common +ifeq ($(CONFIG_IEEE802154_LIBMAC),y) +CONFIGURED_APPS += wireless/ieee802154/libmac endif diff --git a/wireless/ieee802154/libmac/Makefile b/wireless/ieee802154/libmac/Makefile new file mode 100644 index 000000000..b2e3c59ce --- /dev/null +++ b/wireless/ieee802154/libmac/Makefile @@ -0,0 +1,110 @@ +############################################################################ +# apps/wireless/ieee802154/libmac/Makefile +# +# 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. +# +############################################################################ + +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +# libmac source files + +ASRCS = +CSRCS = ieee802154_assocreq.c ieee802154_assocresp.c ieee802154_disassocreq.c +CSRCS += ieee802154_getreq.c ieee802154_gtsreq.c ieee802154_orphanresp.c +CSRCS += ieee802154_resetreq.c ieee802154_rxenabreq.c ieee802154_scanreq.c +CSRCS += ieee802154_setreq.c ieee802154_startreq.c ieee802154_syncreq.c +CSRCS += ieee802154_pollreq.c + +ifeq ($(CONFIG_NET_6LOWPAN),y) +CSRCS += sixlowpan_assocreq.c sixlowpan_assocresp.c sixlowpan_disassocreq.c +CSRCS += sixlowpan_getreq.c sixlowpan_gtsreq.c sixlowpan_orphanresp.c +CSRCS += sixlowpan_resetreq.c sixlowpan_rxenabreq.c sixlowpan_scanreq.c +CSRCS += sixlowpan_setreq.c sixlowpan_startreq.c sixlowpan_syncreq.c +CSRCS += sixlowpan_pollreq.c +endif + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\..\\libapps$(LIBEXT) +else + BIN = ../../../libapps$(LIBEXT) +endif +endif + +ROOTDEPPATH = --dep-path . +VPATH = + +# Build targets + +all: .built +.PHONY: context .depend depend clean distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + @touch .built + +install: + +context: + +.depend: Makefile $(SRCS) + @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + @touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep + diff --git a/wireless/ieee802154/libmac/ieee802154_assocreq.c b/wireless/ieee802154/libmac/ieee802154_assocreq.c new file mode 100644 index 000000000..3549da35d --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_assocreq.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_assocreq.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_assoc_req(int fd, FAR struct ieee802154_assoc_req_s *req) +{ + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_ASSOC_REQUEST, (unsigned long)((uintptr_t)req)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_ASSOC_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/ieee802154_assocresp.c b/wireless/ieee802154/libmac/ieee802154_assocresp.c new file mode 100644 index 000000000..c98c34274 --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_assocresp.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_assocresp.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_assoc_resp(int fd, FAR struct ieee802154_assoc_resp_s *resp) +{ + union ieee802154_macarg_u arg; + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_ASSOC_RESPONSE, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_ASSOC_RESPONSE failed: %d\n", ret); + return ret; + } + + memcpy(resp, &arg.assocresp, sizeof(struct ieee802154_assoc_resp_s)); + return OK; +} diff --git a/wireless/ieee802154/libmac/ieee802154_disassocreq.c b/wireless/ieee802154/libmac/ieee802154_disassocreq.c new file mode 100644 index 000000000..fa743c175 --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_disassocreq.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_assocreq.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_disassoc_req(int fd, FAR struct ieee802154_disassoc_req_s *req) +{ + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_DISASSOC_REQUEST, (unsigned long)((uintptr_t)req)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_DISASSOC_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/ieee802154_getreq.c b/wireless/ieee802154/libmac/ieee802154_getreq.c new file mode 100644 index 000000000..a5caaa3ca --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_getreq.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_getreq.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_get_req(int fd, FAR struct ieee802154_get_req_s *req) +{ + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_GET_REQUEST, (unsigned long)((uintptr_t)req)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_GET_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/ieee802154_gtsreq.c b/wireless/ieee802154/libmac/ieee802154_gtsreq.c new file mode 100644 index 000000000..9911e4ee9 --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_gtsreq.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_gtsreq.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_gts_req(int fd, FAR struct ieee802154_gts_req_s *req) +{ + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_GTS_REQUEST, (unsigned long)((uintptr_t)req)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_GTS_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/ieee802154_orphanresp.c b/wireless/ieee802154/libmac/ieee802154_orphanresp.c new file mode 100644 index 000000000..195cd4e89 --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_orphanresp.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_orphanresp.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_orphan_resp(int fd, FAR struct ieee802154_orphan_resp_s *resp) +{ + union ieee802154_macarg_u arg; + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_ORPHAN_RESPONSE, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_ORPHAN_RESPONSE failed: %d\n", ret); + return ret; + } + + memcpy(resp, &arg.orphanresp, sizeof(struct ieee802154_orphan_resp_s)); + return OK; +} diff --git a/wireless/ieee802154/libmac/ieee802154_pollreq.c b/wireless/ieee802154/libmac/ieee802154_pollreq.c new file mode 100644 index 000000000..fb5e712f3 --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_pollreq.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_pollreq.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_poll_req(int fd, FAR struct ieee802154_poll_req_s *req) +{ + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_POLL_REQUEST, (unsigned long)((uintptr_t)req)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_POLL_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/ieee802154_resetreq.c b/wireless/ieee802154/libmac/ieee802154_resetreq.c new file mode 100644 index 000000000..e5f970112 --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_resetreq.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_resetreq.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_reset_req(int fd, FAR struct ieee802154_reset_req_s *req) +{ + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_RESET_REQUEST, (unsigned long)((uintptr_t)req)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_RESET_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/ieee802154_rxenabreq.c b/wireless/ieee802154/libmac/ieee802154_rxenabreq.c new file mode 100644 index 000000000..720d7f949 --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_rxenabreq.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_rxenabreq.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_rxenable_req(int fd, FAR struct ieee802154_rxenable_req_s *req) +{ + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_RXENABLE_REQUEST, (unsigned long)((uintptr_t)req)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_RXENABLE_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/ieee802154_scanreq.c b/wireless/ieee802154/libmac/ieee802154_scanreq.c new file mode 100644 index 000000000..d494eba8f --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_scanreq.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_scanreq.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_scan_req(int fd, FAR struct ieee802154_scan_req_s *req) +{ + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_SCAN_REQUEST, (unsigned long)((uintptr_t)req)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_SCAN_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/ieee802154_setreq.c b/wireless/ieee802154/libmac/ieee802154_setreq.c new file mode 100644 index 000000000..d33c9390a --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_setreq.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_setreq.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_set_req(int fd, FAR struct ieee802154_set_req_s *req) +{ + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_SET_REQUEST, (unsigned long)((uintptr_t)req)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_SET_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/ieee802154_startreq.c b/wireless/ieee802154/libmac/ieee802154_startreq.c new file mode 100644 index 000000000..8b408be13 --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_startreq.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_startreq.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_start_req(int fd, FAR struct ieee802154_start_req_s *req) +{ + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_START_REQUEST, (unsigned long)((uintptr_t)req)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_START_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/ieee802154_syncreq.c b/wireless/ieee802154/libmac/ieee802154_syncreq.c new file mode 100644 index 000000000..5ae1b95b4 --- /dev/null +++ b/wireless/ieee802154/libmac/ieee802154_syncreq.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/ieee802154_syncreq.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_sync_req(int fd, FAR struct ieee802154_sync_req_s *req) +{ + int ret; + + ret = ioctl(fd, MAC802154IOC_MLME_SYNC_REQUEST, (unsigned long)((uintptr_t)req)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_SYNC_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_assocreq.c b/wireless/ieee802154/libmac/sixlowpan_assocreq.c new file mode 100644 index 000000000..1e110e1f2 --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_assocreq.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_assocreq.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 sixlowpan_assoc_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_assoc_req_s *req) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.assocreq, req, sizeof(struct ieee802154_assoc_req_s)); + + ret = ioctl(sock, MAC802154IOC_MLME_ASSOC_REQUEST, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_ASSOC_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_assocresp.c b/wireless/ieee802154/libmac/sixlowpan_assocresp.c new file mode 100644 index 000000000..27af6e0cc --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_assocresp.c @@ -0,0 +1,76 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_assocresp.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 sixlowpan_assoc_resp(int sock, FAR const char *ifname, + FAR struct ieee802154_assoc_resp_s *resp) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + + ret = ioctl(sock, MAC802154IOC_MLME_ASSOC_RESPONSE, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_ASSOC_RESPONSE failed: %d\n", ret); + return ret; + } + + memcpy(resp, &arg.u.assocresp, sizeof(struct ieee802154_assoc_resp_s)); + return OK; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_disassocreq.c b/wireless/ieee802154/libmac/sixlowpan_disassocreq.c new file mode 100644 index 000000000..1586cde44 --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_disassocreq.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_disassocreq.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 sixlowpan_desassoc_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_disassoc_req_s *req) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.disassocreq, req, sizeof(struct ieee802154_disassoc_req_s)); + + ret = ioctl(sock, MAC802154IOC_MLME_DISASSOC_REQUEST, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_DISASSOC_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_getreq.c b/wireless/ieee802154/libmac/sixlowpan_getreq.c new file mode 100644 index 000000000..2ec3fa8d2 --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_getreq.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_getreq.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 sixlowpan_get_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_get_req_s *req) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.getreq, req, sizeof(struct ieee802154_get_req_s)); + + ret = ioctl(sock, MAC802154IOC_MLME_GET_REQUEST, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_GET_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_gtsreq.c b/wireless/ieee802154/libmac/sixlowpan_gtsreq.c new file mode 100644 index 000000000..08177a98a --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_gtsreq.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_gtsreq.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 sixlowpan_gts_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_gts_req_s *req) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.gtsreq, req, sizeof(struct ieee802154_gts_req_s)); + + ret = ioctl(sock, MAC802154IOC_MLME_GTS_REQUEST, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_GTS_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_orphanresp.c b/wireless/ieee802154/libmac/sixlowpan_orphanresp.c new file mode 100644 index 000000000..6851664ab --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_orphanresp.c @@ -0,0 +1,76 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_orphanresp.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 sixlowpan_orphan_resp(int sock, FAR const char *ifname, + FAR struct ieee802154_orphan_resp_s *resp) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + + ret = ioctl(sock, MAC802154IOC_MLME_ORPHAN_RESPONSE, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_ORPHAN_RESPONSE failed: %d\n", ret); + return ret; + } + + memcpy(resp, &arg.u.orphanresp, sizeof(struct ieee802154_orphan_resp_s)); + return OK; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_pollreq.c b/wireless/ieee802154/libmac/sixlowpan_pollreq.c new file mode 100644 index 000000000..2c5fab1e5 --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_pollreq.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_pollreq.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 sixlowpan_poll_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_poll_req_s *req) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.pollreq, req, sizeof(struct ieee802154_poll_req_s)); + + ret = ioctl(sock, MAC802154IOC_MLME_POLL_REQUEST, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_POLL_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_resetreq.c b/wireless/ieee802154/libmac/sixlowpan_resetreq.c new file mode 100644 index 000000000..e05b0773c --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_resetreq.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_resetreq.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 sixlowpan_reset_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_reset_req_s *req) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.resetreq, req, sizeof(struct ieee802154_reset_req_s)); + + ret = ioctl(sock, MAC802154IOC_MLME_RESET_REQUEST, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_RESET_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_rxenabreq.c b/wireless/ieee802154/libmac/sixlowpan_rxenabreq.c new file mode 100644 index 000000000..d3ac25eb8 --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_rxenabreq.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_rxenabreq.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 sixlowpan_rxenable_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_rxenable_req_s *req) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.rxenabreq, req, sizeof(struct ieee802154_rxenable_req_s)); + + ret = ioctl(sock, MAC802154IOC_MLME_RXENABLE_REQUEST, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_RXENABLE_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_scanreq.c b/wireless/ieee802154/libmac/sixlowpan_scanreq.c new file mode 100644 index 000000000..17934f4b9 --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_scanreq.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_scanreq.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 sixlowpan_scan_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_scan_req_s *req) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.scanreq, req, sizeof(struct ieee802154_scan_req_s)); + + ret = ioctl(sock, MAC802154IOC_MLME_SCAN_REQUEST, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_SCAN_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_setreq.c b/wireless/ieee802154/libmac/sixlowpan_setreq.c new file mode 100644 index 000000000..7d033c5c8 --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_setreq.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_setreq.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 sixlowpan_set_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_set_req_s *req) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.setreq, req, sizeof(struct ieee802154_set_req_s)); + + ret = ioctl(sock, MAC802154IOC_MLME_SET_REQUEST, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_SET_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_startreq.c b/wireless/ieee802154/libmac/sixlowpan_startreq.c new file mode 100644 index 000000000..fcf825bde --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_startreq.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_startreq.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 sixlowpan_start_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_start_req_s *req) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.startreq, req, sizeof(struct ieee802154_start_req_s)); + + ret = ioctl(sock, MAC802154IOC_MLME_START_REQUEST, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_START_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libmac/sixlowpan_syncreq.c b/wireless/ieee802154/libmac/sixlowpan_syncreq.c new file mode 100644 index 000000000..819785cfa --- /dev/null +++ b/wireless/ieee802154/libmac/sixlowpan_syncreq.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libmac/sixlowpan_syncreq.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 sixlowpan_sync_req(int sock, FAR const char *ifname, + FAR const struct ieee802154_sync_req_s *req) +{ + struct ieee802154_netmac_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.syncreq, req, sizeof(struct ieee802154_sync_req_s)); + + ret = ioctl(sock, MAC802154IOC_MLME_SYNC_REQUEST, + (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "MAC802154IOC_MLME_SYNC_REQUEST failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libradio/.gitignore b/wireless/ieee802154/libradio/.gitignore new file mode 100644 index 000000000..fa1ec7579 --- /dev/null +++ b/wireless/ieee802154/libradio/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.obj +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src diff --git a/wireless/ieee802154/libradio/Kconfig b/wireless/ieee802154/libradio/Kconfig new file mode 100644 index 000000000..146f49043 --- /dev/null +++ b/wireless/ieee802154/libradio/Kconfig @@ -0,0 +1,11 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +config IEEE802154_LIBRADIO + bool "IEEE 802.15.4 radio library routines" + default n + ---help--- + Some radio library routines for ieee 802.15.4 apps + diff --git a/wireless/ieee802154/libradio/Make.defs b/wireless/ieee802154/libradio/Make.defs new file mode 100644 index 000000000..f138e1260 --- /dev/null +++ b/wireless/ieee802154/libradio/Make.defs @@ -0,0 +1,40 @@ +############################################################################ +# apps/wireless/ieee802154/libradio/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2016-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. +# +############################################################################ + +ifeq ($(CONFIG_IEEE802154_LIBRADIO),y) +CONFIGURED_APPS += wireless/ieee802154/libradio +endif + diff --git a/wireless/ieee802154/libradio/Makefile b/wireless/ieee802154/libradio/Makefile new file mode 100644 index 000000000..12c47557c --- /dev/null +++ b/wireless/ieee802154/libradio/Makefile @@ -0,0 +1,118 @@ +############################################################################ +# apps/wireless/ieee802154/libradio/Makefile +# +# Copyright (C) 2016-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 + +# libradio source files + +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_setpromisc.c ieee802154_getpromisc.c +CSRCS += ieee802154_setdevmode.c ieee802154_getdevmode.c +CSRCS += ieee802154_settxpwr.c ieee802154_gettxpwr.c +CSRCS += ieee802154_setcca.c ieee802154_getcca.c +CSRCS += ieee802154_energydetect.c + +ifeq ($(CONFIG_NET_6LOWPAN),y) +CSRCS += sixlowpan_setchan.c sixlowpan_getchan.c +CSRCS += sixlowpan_setpanid.c sixlowpan_getpanid.c +CSRCS += sixlowpan_setsaddr.c sixlowpan_getsaddr.c +CSRCS += sixlowpan_seteaddr.c sixlowpan_geteaddr.c +CSRCS += sixlowpan_setpromisc.c sixlowpan_getpromisc.c +CSRCS += sixlowpan_setdevmode.c sixlowpan_getdevmode.c +CSRCS += sixlowpan_settxpwr.c sixlowpan_gettxpwr.c +CSRCS += sixlowpan_setcca.c sixlowpan_getcca.c +CSRCS += sixlowpan_energydetect.c +endif + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\..\\libapps$(LIBEXT) +else + BIN = ../../../libapps$(LIBEXT) +endif +endif + +ROOTDEPPATH = --dep-path . +VPATH = + +# Build targets + +all: .built +.PHONY: context .depend depend clean distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + @touch .built + +install: + +context: + +.depend: Makefile $(SRCS) + @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + @touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep + diff --git a/wireless/ieee802154/libradio/ieee802154_energydetect.c b/wireless/ieee802154/libradio/ieee802154_energydetect.c new file mode 100644 index 000000000..9a8f0b5d9 --- /dev/null +++ b/wireless/ieee802154/libradio/ieee802154_energydetect.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/ieee802154_energydetect.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_energydetect(int fd, FAR bool *energy) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = ioctl(fd, PHY802154IOC_ENERGYDETECT, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_ENERGYDETECT failed: %d\n", ret); + return ret; + } + + *energy = arg.energy; + return OK; +} diff --git a/wireless/ieee802154/common/ieee802154_getcca.c b/wireless/ieee802154/libradio/ieee802154_getcca.c similarity index 83% rename from wireless/ieee802154/common/ieee802154_getcca.c rename to wireless/ieee802154/libradio/ieee802154_getcca.c index bd8bf15e1..ca9f1e77b 100644 --- a/wireless/ieee802154/common/ieee802154_getcca.c +++ b/wireless/ieee802154/libradio/ieee802154_getcca.c @@ -1,6 +1,7 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_getcca.c + * apps/wireless/ieee802154/libradio/ieee802154_getcca.c * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet * @@ -38,13 +39,17 @@ ****************************************************************************/ #include + +#include #include #include -#include -#include +#include +#include +#include #include -#include "ieee802154/ieee802154.h" + +#include "wireless/ieee802154.h" /**************************************************************************** * Public Functions @@ -52,11 +57,17 @@ int ieee802154_getcca(int fd, FAR struct ieee802154_cca_s *cca) { - int ret = ioctl(fd, PHY802154IOC_GET_CCA, (unsigned long)cca ); + union ieee802154_radioarg_u arg; + int ret; + + ret = ioctl(fd, PHY802154IOC_GET_CCA, (unsigned long)((uintptr_t)&arg)); if (ret < 0) { - printf("PHY802154IOC_GET_CCA failed\n"); + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_CCA failed\n", ret); + return ret; } - return ret; + memcpy(cca, &arg.cca, sizeof(struct ieee802154_cca_s)); + return OK; } diff --git a/wireless/ieee802154/common/ieee802154_getchan.c b/wireless/ieee802154/libradio/ieee802154_getchan.c similarity index 84% rename from wireless/ieee802154/common/ieee802154_getchan.c rename to wireless/ieee802154/libradio/ieee802154_getchan.c index 389a899d4..2d367dc4b 100644 --- a/wireless/ieee802154/common/ieee802154_getchan.c +++ b/wireless/ieee802154/libradio/ieee802154_getchan.c @@ -1,6 +1,7 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_getchan.c + * apps/wireless/ieee802154/libradio/ieee802154_getchan.c * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet * @@ -38,13 +39,16 @@ ****************************************************************************/ #include + +#include #include #include -#include -#include +#include +#include #include -#include "ieee802154/ieee802154.h" + +#include "wireless/ieee802154.h" /**************************************************************************** * Public Functions @@ -52,11 +56,17 @@ int ieee802154_getchan(int fd, FAR uint8_t *chan) { - int ret = ioctl(fd, PHY802154IOC_GET_CHAN, (unsigned long)chan); + union ieee802154_radioarg_u arg; + int ret; + + ret = ioctl(fd, PHY802154IOC_GET_CHAN, (unsigned long)((uintptr_t)&arg)); if (ret < 0) { - printf("PHY802154IOC_GET_CHAN failed\n"); + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_CHAN failed: %d\n", ret); + return ret; } - return ret; + *chan = arg.channel; + return OK; } diff --git a/wireless/ieee802154/libradio/ieee802154_getdevmode.c b/wireless/ieee802154/libradio/ieee802154_getdevmode.c new file mode 100644 index 000000000..d02f89959 --- /dev/null +++ b/wireless/ieee802154/libradio/ieee802154_getdevmode.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/ieee802154_getdevmode.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_getdevmode(int fd, FAR uint8_t *devmode) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = ioctl(fd, PHY802154IOC_GET_DEVMODE, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_DEVMODE failed: %d\n", ret); + return ret; + } + + *devmode = arg.devmode; + return OK; +} diff --git a/wireless/ieee802154/libradio/ieee802154_geteaddr.c b/wireless/ieee802154/libradio/ieee802154_geteaddr.c new file mode 100644 index 000000000..7cf824b3d --- /dev/null +++ b/wireless/ieee802154/libradio/ieee802154_geteaddr.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * 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; + + ret = ioctl(fd, PHY802154IOC_GET_EADDR, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_EADDR failed: %d\n", ret); + return ret; + } + + memcpy(eaddr, arg.eaddr, EADDR_SIZE); + return OK; +} diff --git a/wireless/ieee802154/libradio/ieee802154_getpanid.c b/wireless/ieee802154/libradio/ieee802154_getpanid.c new file mode 100644 index 000000000..c9efdb5c8 --- /dev/null +++ b/wireless/ieee802154/libradio/ieee802154_getpanid.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/ieee802154_getpanid.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_getpanid(int fd, FAR uint16_t *panid) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = ioctl(fd, PHY802154IOC_GET_PANID, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_PANID failed: %d\n", ret); + return ret; + } + + *panid = arg.panid; + return OK; +} diff --git a/wireless/ieee802154/libradio/ieee802154_getpromisc.c b/wireless/ieee802154/libradio/ieee802154_getpromisc.c new file mode 100644 index 000000000..dbdc2a382 --- /dev/null +++ b/wireless/ieee802154/libradio/ieee802154_getpromisc.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * 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; + + ret = ioctl(fd, PHY802154IOC_GET_PROMISC, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_PROMISC failed: %d\n", ret); + return ret; + } + + *promisc = arg.promisc; + return OK; +} diff --git a/wireless/ieee802154/libradio/ieee802154_getsaddr.c b/wireless/ieee802154/libradio/ieee802154_getsaddr.c new file mode 100644 index 000000000..d82b59d4e --- /dev/null +++ b/wireless/ieee802154/libradio/ieee802154_getsaddr.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * 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; + + ret = ioctl(fd, PHY802154IOC_GET_SADDR, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_SADDR failed: %d\n", ret); + return ret; + } + + *saddr = arg.saddr; + return OK; +} diff --git a/wireless/ieee802154/libradio/ieee802154_gettxpwr.c b/wireless/ieee802154/libradio/ieee802154_gettxpwr.c new file mode 100644 index 000000000..5717e4ef3 --- /dev/null +++ b/wireless/ieee802154/libradio/ieee802154_gettxpwr.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/ieee802154_gettxpwr.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_gettxpwr(int fd, FAR int32_t *txpwr) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = ioctl(fd, PHY802154IOC_GET_TXPWR, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_TXPWR failed: %d\n", ret); + return ret; + } + + *txpwr = arg.txpwr; + return OK; +} diff --git a/wireless/ieee802154/common/ieee802154_setcca.c b/wireless/ieee802154/libradio/ieee802154_setcca.c similarity index 84% rename from wireless/ieee802154/common/ieee802154_setcca.c rename to wireless/ieee802154/libradio/ieee802154_setcca.c index 5f257341a..2b9da93f5 100644 --- a/wireless/ieee802154/common/ieee802154_setcca.c +++ b/wireless/ieee802154/libradio/ieee802154_setcca.c @@ -1,6 +1,7 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_setchan.c + * apps/wireless/ieee802154/libradio/ieee802154_setchan.c * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet * @@ -38,13 +39,17 @@ ****************************************************************************/ #include + +#include #include #include -#include +#include +#include + #include #include -#include "ieee802154/ieee802154.h" +#include "wireless/ieee802154.h" /**************************************************************************** * Public Functions @@ -52,10 +57,16 @@ int ieee802154_setcca(int fd, FAR struct ieee802154_cca_s *cca) { - int ret = ioctl(fd, PHY802154IOC_SET_CCA, (unsigned long)cca ); + union ieee802154_radioarg_u arg; + int ret; + + memcpy(&arg.cca, cca, sizeof(struct ieee802154_cca_s)); + + ret = ioctl(fd, PHY802154IOC_SET_CCA, (unsigned long)((uintptr_t)&arg)); if (ret < 0) { - printf("PHY802154IOC_SET_CCA failed\n"); + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_CCA failed: %d\n", ret); } return ret; diff --git a/wireless/ieee802154/common/ieee802154_setchan.c b/wireless/ieee802154/libradio/ieee802154_setchan.c similarity index 85% rename from wireless/ieee802154/common/ieee802154_setchan.c rename to wireless/ieee802154/libradio/ieee802154_setchan.c index df371f6cc..c5b47017f 100644 --- a/wireless/ieee802154/common/ieee802154_setchan.c +++ b/wireless/ieee802154/libradio/ieee802154_setchan.c @@ -1,6 +1,7 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_setchan.c + * apps/wireless/ieee802154/libradio/ieee802154_setchan.c * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet * @@ -38,12 +39,16 @@ ****************************************************************************/ #include + +#include #include #include -#include +#include + #include #include -#include "ieee802154/ieee802154.h" + +#include "wireless/ieee802154.h" /**************************************************************************** * Public Functions @@ -51,10 +56,16 @@ int ieee802154_setchan(int fd, uint8_t chan) { - int ret = ioctl(fd, PHY802154IOC_SET_CHAN, (unsigned long)chan ); + union ieee802154_radioarg_u arg; + int ret; + + arg.channel = chan; + + ret = ioctl(fd, PHY802154IOC_SET_CHAN, (unsigned long)((uintptr_t)&arg)); if (ret < 0) { - printf("PHY802154IOC_SET_CHAN failed\n"); + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_CHAN failed: %d\n", ret); } return ret; diff --git a/wireless/ieee802154/common/ieee802154_setdevmode.c b/wireless/ieee802154/libradio/ieee802154_setdevmode.c similarity index 85% rename from wireless/ieee802154/common/ieee802154_setdevmode.c rename to wireless/ieee802154/libradio/ieee802154_setdevmode.c index 318fd80d9..59d3851dd 100644 --- a/wireless/ieee802154/common/ieee802154_setdevmode.c +++ b/wireless/ieee802154/libradio/ieee802154_setdevmode.c @@ -1,6 +1,7 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_setdevmode.c + * apps/wireless/ieee802154/libradio/ieee802154_setdevmode.c * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet * @@ -38,12 +39,16 @@ ****************************************************************************/ #include + +#include #include #include -#include +#include + #include #include -#include "ieee802154/ieee802154.h" + +#include "wireless/ieee802154.h" /**************************************************************************** * Public Functions @@ -51,10 +56,16 @@ int ieee802154_setdevmode(int fd, uint8_t devmode) { - int ret = ioctl(fd, PHY802154IOC_SET_DEVMODE, (unsigned long)devmode ); + union ieee802154_radioarg_u arg; + int ret; + + arg.devmode = devmode; + + ret = ioctl(fd, PHY802154IOC_SET_DEVMODE, (unsigned long)((uintptr_t)&arg)); if (ret < 0) { - printf("PHY802154IOC_SET_DEVMODE failed\n"); + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_DEVMODE failed: %d\n", ret); } return ret; diff --git a/wireless/ieee802154/common/ieee802154_seteaddr.c b/wireless/ieee802154/libradio/ieee802154_seteaddr.c similarity index 82% rename from wireless/ieee802154/common/ieee802154_seteaddr.c rename to wireless/ieee802154/libradio/ieee802154_seteaddr.c index f4e3024a7..a5dbcdc48 100644 --- a/wireless/ieee802154/common/ieee802154_seteaddr.c +++ b/wireless/ieee802154/libradio/ieee802154_seteaddr.c @@ -1,6 +1,7 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_eaddr.c + * apps/wireless/ieee802154/libradio/ieee802154_eaddr.c * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet * @@ -38,23 +39,34 @@ ****************************************************************************/ #include + +#include #include #include -#include +#include +#include + #include #include -#include "ieee802154/ieee802154.h" + +#include "wireless/ieee802154.h" /**************************************************************************** * Public Functions ****************************************************************************/ -int ieee802154_seteaddr(int fd, uint8_t *eaddr) +int ieee802154_seteaddr(int fd, FAR const uint8_t *eaddr) { - int ret = ioctl(fd, PHY802154IOC_SET_EADDR, (unsigned long)eaddr ); + union ieee802154_radioarg_u arg; + int ret; + + memcpy(arg.eaddr, eaddr, EADDR_SIZE); + + ret = ioctl(fd, PHY802154IOC_SET_EADDR, (unsigned long)((uintptr_t)&arg)); if (ret < 0) { - printf("PHY802154IOC_SET_EADDR failed\n"); + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_EADDR failed: %d\n", ret); } return ret; diff --git a/wireless/ieee802154/common/ieee802154_setpanid.c b/wireless/ieee802154/libradio/ieee802154_setpanid.c similarity index 79% rename from wireless/ieee802154/common/ieee802154_setpanid.c rename to wireless/ieee802154/libradio/ieee802154_setpanid.c index 20a0c3932..7f5b92204 100644 --- a/wireless/ieee802154/common/ieee802154_setpanid.c +++ b/wireless/ieee802154/libradio/ieee802154_setpanid.c @@ -1,6 +1,7 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_setpanid.c + * apps/wireless/ieee802154/libradio/ieee802154_setpanid.c * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet * @@ -38,19 +39,33 @@ ****************************************************************************/ #include + +#include #include #include -#include +#include + #include #include -#include "ieee802154/ieee802154.h" + +#include "wireless/ieee802154.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ int ieee802154_setpanid(int fd, uint16_t panid) { - int ret = ioctl(fd, PHY802154IOC_SET_PANID, (unsigned long)panid ); + union ieee802154_radioarg_u arg; + int ret; + + arg.panid = panid; + + ret = ioctl(fd, PHY802154IOC_SET_PANID, (unsigned long)((uintptr_t)&arg)); if (ret < 0) { - printf("PHY802154IOC_SET_PANID failed\n"); + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_PANID failed: %d\n", ret); } return ret; diff --git a/wireless/ieee802154/common/ieee802154_setpromisc.c b/wireless/ieee802154/libradio/ieee802154_setpromisc.c similarity index 85% rename from wireless/ieee802154/common/ieee802154_setpromisc.c rename to wireless/ieee802154/libradio/ieee802154_setpromisc.c index 00d0854ba..f972dcaf8 100644 --- a/wireless/ieee802154/common/ieee802154_setpromisc.c +++ b/wireless/ieee802154/libradio/ieee802154_setpromisc.c @@ -1,6 +1,7 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_setpromisc.c + * apps/wireless/ieee802154/libradio/ieee802154_setpromisc.c * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet * @@ -38,13 +39,17 @@ ****************************************************************************/ #include + +#include #include #include #include -#include +#include + #include #include -#include "ieee802154/ieee802154.h" + +#include "wireless/ieee802154.h" /**************************************************************************** * Public Functions @@ -52,10 +57,16 @@ int ieee802154_setpromisc(int fd, bool promisc) { - int ret = ioctl(fd, PHY802154IOC_SET_PROMISC, (unsigned long)promisc ); + union ieee802154_radioarg_u arg; + int ret; + + arg.promisc = promisc; + + ret = ioctl(fd, PHY802154IOC_SET_PROMISC, (unsigned long)((uintptr_t)&arg)); if (ret < 0) { - printf("PHY802154IOC_SET_PROMISC failed\n"); + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_PROMISC failed: %d\n", ret); } return ret; diff --git a/wireless/ieee802154/common/ieee802154_setsaddr.c b/wireless/ieee802154/libradio/ieee802154_setsaddr.c similarity index 85% rename from wireless/ieee802154/common/ieee802154_setsaddr.c rename to wireless/ieee802154/libradio/ieee802154_setsaddr.c index d68e8455d..03d015058 100644 --- a/wireless/ieee802154/common/ieee802154_setsaddr.c +++ b/wireless/ieee802154/libradio/ieee802154_setsaddr.c @@ -1,6 +1,7 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_setsaddr.c + * apps/wireless/ieee802154/libradio/ieee802154_setsaddr.c * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet * @@ -38,12 +39,16 @@ ****************************************************************************/ #include + +#include #include #include -#include +#include + #include #include -#include "ieee802154/ieee802154.h" + +#include "wireless/ieee802154.h" /**************************************************************************** * Public Functions @@ -51,10 +56,16 @@ int ieee802154_setsaddr(int fd, uint16_t saddr) { - int ret = ioctl(fd, PHY802154IOC_SET_SADDR, (unsigned long)saddr ); + union ieee802154_radioarg_u arg; + int ret; + + arg.saddr = saddr; + + ret = ioctl(fd, PHY802154IOC_SET_SADDR, (unsigned long)((uintptr_t)&arg)); if (ret < 0) { - printf("PHY802154IOC_SET_SADDR failed\n"); + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_SADDR failed: %d\n", ret); } return ret; diff --git a/wireless/ieee802154/libradio/ieee802154_settxpwr.c b/wireless/ieee802154/libradio/ieee802154_settxpwr.c new file mode 100644 index 000000000..2a285ecce --- /dev/null +++ b/wireless/ieee802154/libradio/ieee802154_settxpwr.c @@ -0,0 +1,71 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/ieee802154_settxpwr.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_settxpwr(int fd, int32_t txpwr) +{ + union ieee802154_radioarg_u arg; + int ret; + + arg.txpwr = txpwr; + + ret = ioctl(fd, PHY802154IOC_SET_TXPWR, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_TXPWR failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_energydetect.c b/wireless/ieee802154/libradio/sixlowpan_energydetect.c new file mode 100644 index 000000000..9527a00d4 --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_energydetect.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_energydetect.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 sixlowpan_energydetect(int sock, FAR const char *ifname, FAR bool *energy) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + + ret = ioctl(sock, PHY802154IOC_ENERGYDETECT, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_ENERGYDETECT failed: %d\n", ret); + return ret; + } + + *energy = arg.u.energy; + return OK; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_getcca.c b/wireless/ieee802154/libradio/sixlowpan_getcca.c new file mode 100644 index 000000000..83a38871e --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_getcca.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_getcca.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 sixlowpan_getcca(int sock, FAR const char *ifname, + FAR struct ieee802154_cca_s *cca) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + + ret = ioctl(sock, PHY802154IOC_GET_CCA, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_CCA failed: %d\n", ret); + return ret; + } + + memcpy(cca, &arg.u.cca, sizeof(struct ieee802154_cca_s)); + return OK; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_getchan.c b/wireless/ieee802154/libradio/sixlowpan_getchan.c new file mode 100644 index 000000000..6f0a5f5e6 --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_getchan.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_getchan.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 sixlowpan_getchan(int sock, FAR const char *ifname, FAR uint8_t *chan) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + + ret = ioctl(sock, PHY802154IOC_GET_CHAN, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_CHAN failed: %d\n", ret); + return ret; + } + + *chan = arg.u.channel; + return OK; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_getdevmode.c b/wireless/ieee802154/libradio/sixlowpan_getdevmode.c new file mode 100644 index 000000000..71256beff --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_getdevmode.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_getdevmode.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 sixlowpan_getdevmode(int sock, FAR const char *ifname, + FAR uint8_t *devmode) +{ + struct ieee802154_netradio_s arg; + int ret; + + ret = ioctl(sock, PHY802154IOC_GET_DEVMODE, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_DEVMODE failed: %d\n", ret); + return ret; + } + + *devmode = arg.u.devmode; + return OK; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_geteaddr.c b/wireless/ieee802154/libradio/sixlowpan_geteaddr.c new file mode 100644 index 000000000..9e89aab17 --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_geteaddr.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_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 sixlowpan_geteaddr(int sock, FAR const char *ifname, FAR uint8_t *eaddr) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + + ret = ioctl(sock, PHY802154IOC_GET_EADDR, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_EADDR failed: %d\n", ret); + return ret; + } + + memcpy(eaddr, arg.u.eaddr, EADDR_SIZE); + return OK; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_getpanid.c b/wireless/ieee802154/libradio/sixlowpan_getpanid.c new file mode 100644 index 000000000..88c0342e4 --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_getpanid.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_getpanid.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 sixlowpan_getpanid(int sock, FAR const char *ifname, FAR uint16_t *panid) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + + ret = ioctl(sock, PHY802154IOC_GET_PANID, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_PANID failed: %d\n", ret); + return ret; + } + + *panid = arg.u.panid; + return OK; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_getpromisc.c b/wireless/ieee802154/libradio/sixlowpan_getpromisc.c new file mode 100644 index 000000000..c12d215e4 --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_getpromisc.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_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 + +#include "wireless/ieee802154.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int sixlowpan_getpromisc(int sock, FAR const char *ifname, FAR bool *promisc) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + + ret = ioctl(sock, PHY802154IOC_GET_PROMISC, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_PROMISC failed: %d\n", ret); + return ret; + } + + *promisc = arg.u.promisc; + return OK; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_getsaddr.c b/wireless/ieee802154/libradio/sixlowpan_getsaddr.c new file mode 100644 index 000000000..c089ddd5f --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_getsaddr.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_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 + +#include "wireless/ieee802154.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int sixlowpan_getsaddr(int sock, FAR const char *ifname, FAR uint16_t *saddr) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + + ret = ioctl(sock, PHY802154IOC_GET_SADDR, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_SADDR failed: %d\n", ret); + return ret; + } + + *saddr = arg.u.saddr; + return OK; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_gettxpwr.c b/wireless/ieee802154/libradio/sixlowpan_gettxpwr.c new file mode 100644 index 000000000..5627b66f4 --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_gettxpwr.c @@ -0,0 +1,74 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_gettxpwr.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 sixlowpan_gettxpwr(int sock, FAR const char *ifname, FAR int32_t *txpwr) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + + ret = ioctl(sock, PHY802154IOC_GET_TXPWR, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_GET_TXPWR failed: %d\n", ret); + return ret; + } + + *txpwr = arg.u.txpwr; + return OK; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_setcca.c b/wireless/ieee802154/libradio/sixlowpan_setcca.c new file mode 100644 index 000000000..3a881f730 --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_setcca.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_setchan.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 sixlowpan_setcca(int sock, FAR const char *ifname, FAR struct ieee802154_cca_s *cca) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(&arg.u.cca, cca, sizeof(struct ieee802154_cca_s)); + + ret = ioctl(sock, PHY802154IOC_SET_CCA, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_CCA failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_setchan.c b/wireless/ieee802154/libradio/sixlowpan_setchan.c new file mode 100644 index 000000000..afddb862d --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_setchan.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_setchan.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 sixlowpan_setchan(int sock, FAR const char *ifname, uint8_t chan) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + arg.u.channel = chan; + + ret = ioctl(sock, PHY802154IOC_SET_CHAN, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_CHAN failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_setdevmode.c b/wireless/ieee802154/libradio/sixlowpan_setdevmode.c new file mode 100644 index 000000000..a96639f6a --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_setdevmode.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_setdevmode.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 sixlowpan_setdevmode(int sock, FAR const char *ifname, uint8_t devmode) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + arg.u.devmode = devmode; + + ret = ioctl(sock, PHY802154IOC_SET_DEVMODE, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_DEVMODE failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_seteaddr.c b/wireless/ieee802154/libradio/sixlowpan_seteaddr.c new file mode 100644 index 000000000..3a2dbd4dc --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_seteaddr.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_seteaddr.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 sixlowpan_seteaddr(int sock, FAR const char *ifname, FAR const uint8_t *eaddr) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + memcpy(arg.u.eaddr, eaddr, EADDR_SIZE); + + ret = ioctl(sock, PHY802154IOC_SET_EADDR, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_EADDR failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_setpanid.c b/wireless/ieee802154/libradio/sixlowpan_setpanid.c new file mode 100644 index 000000000..195730bee --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_setpanid.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_setpanid.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 sixlowpan_setpanid(int sock, FAR const char *ifname, uint16_t panid) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + arg.u.panid = panid; + + ret = ioctl(sock, PHY802154IOC_SET_PANID, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_PANID failed: %d\n", ret); + } + + return ret; +} diff --git a/include/ieee802154/ieee802154.h b/wireless/ieee802154/libradio/sixlowpan_setpromisc.c similarity index 59% rename from include/ieee802154/ieee802154.h rename to wireless/ieee802154/libradio/sixlowpan_setpromisc.c index 99a39cccd..45e23dcea 100644 --- a/include/ieee802154/ieee802154.h +++ b/wireless/ieee802154/libradio/sixlowpan_setpromisc.c @@ -1,8 +1,8 @@ /**************************************************************************** - * apps/include/ieee802154/ieee802154.h + * apps/wireless/ieee802154/libradio/sixlowpan_setpromisc.c * - * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. - * Author: Sebastien Lorquet + * 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 @@ -33,29 +33,42 @@ * ****************************************************************************/ -#ifndef __APPS_INCLUDE_IEEE802154_IEEE802154_H -#define __APPS_INCLUDE_IEEE802154_IEEE802154_H +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include + +#include #include #include +#include +#include +#include +#include #include -#include -int ieee802154_setchan (int fd, uint8_t chan); -int ieee802154_getchan (int fd, FAR uint8_t *chan); +#include "wireless/ieee802154.h" -int ieee802154_setpanid (int fd, uint16_t panid); -int ieee802154_setsaddr (int fd, uint16_t saddr); -int ieee802154_seteaddr (int fd, FAR uint8_t *chan); -int ieee802154_setpromisc(int fd, bool promisc); -int ieee802154_setdevmode(int fd, uint8_t devmode); +/**************************************************************************** + * Public Functions + ****************************************************************************/ -int ieee802154_setcca(int fd, FAR struct ieee802154_cca_s *cca); -int ieee802154_getcca(int fd, FAR struct ieee802154_cca_s *cca); +int sixlowpan_setpromisc(int sock, FAR const char *ifname, bool promisc) +{ + struct ieee802154_netradio_s arg; + int ret; -int ieee802154_addrparse(FAR struct ieee802154_packet_s *inPacket, FAR struct ieee802154_addr_s *dest, FAR struct ieee802154_addr_s *src); -int ieee802154_addrstore(FAR struct ieee802154_packet_s *inPacket, FAR struct ieee802154_addr_s *dest, FAR struct ieee802154_addr_s *src); -int ieee802154_addrtostr(FAR char *buf, int len, FAR struct ieee802154_addr_s *addr); + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + arg.u.promisc = promisc; -#endif /*__APPS_INCLUDE_IEEE802154_IEEE802154_H */ + ret = ioctl(sock, PHY802154IOC_SET_PROMISC, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_PROMISC failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_setsaddr.c b/wireless/ieee802154/libradio/sixlowpan_setsaddr.c new file mode 100644 index 000000000..173e18d80 --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_setsaddr.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_setsaddr.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 sixlowpan_setsaddr(int sock, FAR const char *ifname, uint16_t saddr) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + arg.u.saddr = saddr; + + ret = ioctl(sock, PHY802154IOC_SET_SADDR, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_SADDR failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libradio/sixlowpan_settxpwr.c b/wireless/ieee802154/libradio/sixlowpan_settxpwr.c new file mode 100644 index 000000000..8a82d7c8e --- /dev/null +++ b/wireless/ieee802154/libradio/sixlowpan_settxpwr.c @@ -0,0 +1,73 @@ +/**************************************************************************** + * apps/wireless/ieee802154/libradio/sixlowpan_settxpwr.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 sixlowpan_settxpwr(int sock, FAR const char *ifname, int32_t txpwr) +{ + struct ieee802154_netradio_s arg; + int ret; + + strncpy(arg.ifr_name, ifname, IFNAMSIZ); + arg.u.txpwr = txpwr; + + ret = ioctl(sock, PHY802154IOC_SET_TXPWR, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + ret = -errno; + fprintf(stderr, "PHY802154IOC_SET_TXPWR failed: %d\n", ret); + } + + return ret; +} diff --git a/wireless/ieee802154/libutils/.gitignore b/wireless/ieee802154/libutils/.gitignore new file mode 100644 index 000000000..fa1ec7579 --- /dev/null +++ b/wireless/ieee802154/libutils/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.obj +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src diff --git a/wireless/ieee802154/common/Kconfig b/wireless/ieee802154/libutils/Kconfig similarity index 89% rename from wireless/ieee802154/common/Kconfig rename to wireless/ieee802154/libutils/Kconfig index c214543ed..03b609f62 100644 --- a/wireless/ieee802154/common/Kconfig +++ b/wireless/ieee802154/libutils/Kconfig @@ -3,7 +3,7 @@ # see misc/tools/kconfig-language.txt. # -config IEEE802154_COMMON +config IEEE802154_LIBUTILS bool "Common IEEE 802.15.4 library routines" default n ---help--- 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/common/Makefile b/wireless/ieee802154/libutils/Makefile similarity index 84% rename from wireless/ieee802154/common/Makefile rename to wireless/ieee802154/libutils/Makefile index d5ce28b98..a68617662 100644 --- a/wireless/ieee802154/common/Makefile +++ b/wireless/ieee802154/libutils/Makefile @@ -1,7 +1,7 @@ ############################################################################ -# apps/wireless/ieee802154/Makefile +# apps/wireless/ieee802154/libradio/Makefile # -# Copyright (C) 2011-2013 Gregory Nutt. All rights reserved. +# Copyright (C) 2016-2-17 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -37,18 +37,11 @@ -include $(TOPDIR)/Make.defs include $(APPDIR)/Make.defs -# NSH Library +# libutils source files ASRCS = -CSRCS = ieee802154_setchan.c ieee802154_getchan.c -CSRCS += ieee802154_setpanid.c -CSRCS += ieee802154_seteaddr.c ieee802154_setsaddr.c -CSRCS += ieee802154_setpromisc.c ieee802154_setdevmode.c -CSRCS += ieee802154_setcca.c ieee802154_getcca.c CSRCS += ieee802154_addrparse.c ieee802154_addrstore.c ieee802154_addrtostr.c -# - AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) @@ -56,12 +49,12 @@ SRCS = $(ASRCS) $(CSRCS) OBJS = $(AOBJS) $(COBJS) ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\..\libapps$(LIBEXT) + BIN = ..\..\..\libapps$(LIBEXT) else ifeq ($(WINTOOL),y) - BIN = ..\\..\\..\\libapps$(LIBEXT) + BIN = ..\\..\\..\\libapps$(LIBEXT) else - BIN = ../../../libapps$(LIBEXT) + BIN = ../../../libapps$(LIBEXT) endif endif diff --git a/wireless/ieee802154/common/ieee802154_addrparse.c b/wireless/ieee802154/libutils/ieee802154_addrparse.c similarity index 80% rename from wireless/ieee802154/common/ieee802154_addrparse.c rename to wireless/ieee802154/libutils/ieee802154_addrparse.c index 9f3e9cce1..3dce1e5e7 100644 --- a/wireless/ieee802154/common/ieee802154_addrparse.c +++ b/wireless/ieee802154/libutils/ieee802154_addrparse.c @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_addrparse.c + * apps/wireless/ieee802154/libutils/ieee802154_addrparse.c * * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet @@ -38,13 +38,15 @@ ****************************************************************************/ #include + #include #include #include #include #include -#include "ieee802154/ieee802154.h" + +#include "wireless/ieee802154.h" /**************************************************************************** * Public Functions @@ -62,31 +64,31 @@ int ieee802154_addrparse(FAR struct ieee802154_packet_s *packet, frame_ctrl = packet->data[0]; frame_ctrl |= packet->data[1] << 8; - dest->ia_mode = (frame_ctrl & IEEE802154_FRAMECTRL_DADDR) - >> IEEE802154_FRAMECTRL_SHIFT_DADDR; + dest->mode = (frame_ctrl & IEEE802154_FRAMECTRL_DADDR) + >> IEEE802154_FRAMECTRL_SHIFT_DADDR; - src->ia_mode = (frame_ctrl & IEEE802154_FRAMECTRL_SADDR) - >> IEEE802154_FRAMECTRL_SHIFT_SADDR; + src->mode = (frame_ctrl & IEEE802154_FRAMECTRL_SADDR) + >> IEEE802154_FRAMECTRL_SHIFT_SADDR; /* Decode dest addr */ - switch (dest->ia_mode) + switch (dest->mode) { case IEEE802154_ADDRMODE_SHORT: { - memcpy(&dest->ia_panid, packet->data+index, 2); + memcpy(&dest->panid, packet->data+index, 2); index += 2; /* Skip dest pan id */ - memcpy(&dest->ia_saddr, packet->data+index, 2); + memcpy(&dest->saddr, packet->data+index, 2); index += 2; /* Skip dest addr */ } break; case IEEE802154_ADDRMODE_EXTENDED: { - memcpy(&dest->ia_panid, packet->data+index, 2); + memcpy(&dest->panid, packet->data+index, 2); index += 2; /* Skip dest pan id */ - memcpy(dest->ia_eaddr, packet->data+index, 8); + memcpy(dest->eaddr, packet->data+index, 8); index += 8; /* Skip dest addr */ } break; @@ -98,36 +100,36 @@ int ieee802154_addrparse(FAR struct ieee802154_packet_s *packet, return -EINVAL; } - if ((src->ia_mode == IEEE802154_ADDRMODE_SHORT) || - (src->ia_mode == IEEE802154_ADDRMODE_EXTENDED)) + if ((src->mode == IEEE802154_ADDRMODE_SHORT) || + (src->mode == IEEE802154_ADDRMODE_EXTENDED)) { /* If PANID compression, src PAN ID is same as dest */ if(frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP) { - src->ia_panid = dest->ia_panid; + src->panid = dest->panid; } else { - memcpy(&src->ia_panid, packet->data+index, 2); + memcpy(&src->panid, packet->data+index, 2); index += 2; /*skip dest pan id*/ } } /* Decode source addr */ - switch (src->ia_mode) + switch (src->mode) { case IEEE802154_ADDRMODE_SHORT: { - memcpy(&src->ia_saddr, packet->data+index, 2); + memcpy(&src->saddr, packet->data+index, 2); index += 2; /* Skip src addr */ } break; case IEEE802154_ADDRMODE_EXTENDED: { - memcpy(src->ia_eaddr, packet->data+index, 8); + memcpy(src->eaddr, packet->data+index, 8); index += 8; /* Skip src addr */ } break; diff --git a/wireless/ieee802154/common/ieee802154_addrstore.c b/wireless/ieee802154/libutils/ieee802154_addrstore.c similarity index 79% rename from wireless/ieee802154/common/ieee802154_addrstore.c rename to wireless/ieee802154/libutils/ieee802154_addrstore.c index b0b92b485..31115530e 100644 --- a/wireless/ieee802154/common/ieee802154_addrstore.c +++ b/wireless/ieee802154/libutils/ieee802154_addrstore.c @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_addrparse.c + * apps/wireless/ieee802154/libutils/ieee802154_addrparse.c * * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet @@ -44,7 +44,7 @@ #include #include -#include "ieee802154/ieee802154.h" +#include "wireless/ieee802154.h" /**************************************************************************** * Public Functions @@ -68,7 +68,7 @@ int ieee802154_addrstore(FAR struct ieee802154_packet_s *packet, /* Encode dest addr */ - if(dest == NULL || dest->ia_mode == IEEE802154_ADDRMODE_NONE) + if(dest == NULL || dest->mode == IEEE802154_ADDRMODE_NONE) { /* Set the destination address mode to none */ @@ -76,23 +76,23 @@ int ieee802154_addrstore(FAR struct ieee802154_packet_s *packet, } else { - memcpy(packet->data+index, &dest->ia_panid, 2); + memcpy(packet->data+index, &dest->panid, 2); index += 2; /* Skip dest pan id */ /* Set the dest address mode field */ - frame_ctrl |= dest->ia_mode << IEEE802154_FRAMECTRL_SHIFT_DADDR; + frame_ctrl |= dest->mode << IEEE802154_FRAMECTRL_SHIFT_DADDR; - if(dest->ia_mode == IEEE802154_ADDRMODE_SHORT) + if(dest->mode == IEEE802154_ADDRMODE_SHORT) { - memcpy(packet->data+index, &dest->ia_saddr, 2); + memcpy(packet->data+index, &dest->saddr, 2); index += 2; /* Skip dest addr */ } - else if(dest->ia_mode == IEEE802154_ADDRMODE_EXTENDED) + else if(dest->mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(packet->data+index, &dest->ia_panid, 2); + memcpy(packet->data+index, &dest->panid, 2); index += 2; /* Skip dest pan id */ - memcpy(packet->data+index, dest->ia_eaddr, 8); + memcpy(packet->data+index, dest->eaddr, 8); index += 8; /* Skip dest addr */ } else @@ -105,12 +105,12 @@ int ieee802154_addrstore(FAR struct ieee802154_packet_s *packet, frame_ctrl &= ~IEEE802154_FRAMECTRL_PANIDCOMP; - if( (dest != NULL && dest->ia_mode != IEEE802154_ADDRMODE_NONE) && - (src != NULL && src->ia_mode != IEEE802154_ADDRMODE_NONE) ) + if( (dest != NULL && dest->mode != IEEE802154_ADDRMODE_NONE) && + (src != NULL && src->mode != IEEE802154_ADDRMODE_NONE) ) { /* We have both adresses, encode source pan id according to compression */ - if( dest->ia_panid == src->ia_panid) + if( dest->panid == src->panid) { frame_ctrl |= IEEE802154_FRAMECTRL_PANIDCOMP; } @@ -122,7 +122,7 @@ int ieee802154_addrstore(FAR struct ieee802154_packet_s *packet, /* Encode source addr */ - if(src == NULL || src->ia_mode == IEEE802154_ADDRMODE_NONE) + if(src == NULL || src->mode == IEEE802154_ADDRMODE_NONE) { /* Set the source address mode to none */ @@ -134,22 +134,22 @@ int ieee802154_addrstore(FAR struct ieee802154_packet_s *packet, if(!(frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP)) { - memcpy(packet->data+index, &src->ia_panid, 2); + memcpy(packet->data+index, &src->panid, 2); index += 2; /*skip src pan id*/ } /* Set the source address mode field */ - frame_ctrl |= src->ia_mode << IEEE802154_FRAMECTRL_SHIFT_SADDR; + frame_ctrl |= src->mode << IEEE802154_FRAMECTRL_SHIFT_SADDR; - if(src->ia_mode == IEEE802154_ADDRMODE_SHORT) + if(src->mode == IEEE802154_ADDRMODE_SHORT) { - memcpy(packet->data+index, &src->ia_saddr, 2); + memcpy(packet->data+index, &src->saddr, 2); index += 2; /* Skip src addr */ } - else if(src->ia_mode == IEEE802154_ADDRMODE_EXTENDED) + else if(src->mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(packet->data+index, src->ia_eaddr, 8); + memcpy(packet->data+index, src->eaddr, 8); index += 8; /* Skip src addr */ } else diff --git a/wireless/ieee802154/common/ieee802154_addrtostr.c b/wireless/ieee802154/libutils/ieee802154_addrtostr.c similarity index 82% rename from wireless/ieee802154/common/ieee802154_addrtostr.c rename to wireless/ieee802154/libutils/ieee802154_addrtostr.c index f2f291d2b..42c9ed02a 100644 --- a/wireless/ieee802154/common/ieee802154_addrtostr.c +++ b/wireless/ieee802154/libutils/ieee802154_addrtostr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/wireless/ieee802154/common/ieee802154_addrtostr.c + * apps/wireless/ieee802154/libutils/ieee802154_addrtostr.c * * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet @@ -42,7 +42,7 @@ #include #include -#include "ieee802154/ieee802154.h" +#include "wireless/ieee802154.h" /**************************************************************************** * Public Functions @@ -52,32 +52,32 @@ int ieee802154_addrtostr(FAR char *buf, int len, FAR struct ieee802154_addr_s *addr) { #ifndef CONFIG_BIG_ENDIAN - uint16_t panid = ((addr->ia_panid & 0xff) << 8) | ((addr->ia_panid >> 8) & 0xff); + uint16_t panid = ((addr->panid & 0xff) << 8) | ((addr->panid >> 8) & 0xff); #else - uint16_t panid = addr->ia_panid; + uint16_t panid = addr->panid; #endif - if (addr->ia_mode == IEEE802154_ADDRMODE_NONE) + if (addr->mode == IEEE802154_ADDRMODE_NONE) { return snprintf(buf, len, "none"); } - else if (addr->ia_mode == IEEE802154_ADDRMODE_SHORT) + else if (addr->mode == IEEE802154_ADDRMODE_SHORT) { #ifndef CONFIG_BIG_ENDIAN - uint16_t saddr = ((addr->ia_saddr & 0xff) << 8) | ((addr->ia_saddr >> 8) & 0xff); + uint16_t saddr = ((addr->saddr & 0xff) << 8) | ((addr->saddr >> 8) & 0xff); #else - uint16_t saddr = addr->ia_saddr; + uint16_t saddr = addr->saddr; #endif return snprintf(buf, len, "%04X/%04X", panid, saddr); } - else if (addr->ia_mode == IEEE802154_ADDRMODE_EXTENDED) + else if (addr->mode == IEEE802154_ADDRMODE_EXTENDED) { int i; int off = snprintf(buf, len, "%04X/", panid); for (i = 0; i < 8; i++) { - off += snprintf(buf + off, len -off, "%02X", addr->ia_eaddr[i]); + off += snprintf(buf + off, len -off, "%02X", addr->eaddr[i]); } return off; diff --git a/wireless/iwpan/Kconfig b/wireless/iwpan/Kconfig new file mode 100644 index 000000000..d06eddb20 --- /dev/null +++ b/wireless/iwpan/Kconfig @@ -0,0 +1,35 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +menuconfig WIRELESS_IWPAN + bool "IEEE 802.15.4 Command Line Tool" + default n + depends on NET && DRIVERS_WIRELESS + select IEEE802154_LIBMAC + select IEEE802154_LIBRADIO + select IEEE802154_LIBUTILS + ---help--- + IWPAN is a tool similar to wapi and inspired by iwpan on Linux that can + be used to manage 802.15.4 PAN. + +if WIRELESS_IWPAN + +config WIRELESS_IWPAN_PROGNAME + string "Program Name" + default "iwpan" + depends on BUILD_KERNEL + ---help--- + This is the name of the program that will be use when the NSH ELF + program is installed. + +config WIRELESS_IWPAN_STACKSIZE + int "Stack Size (bytes)" + default 2048 + +config WIRELESS_IWPAN_PRIORITY + int "Command Priority" + default 100 + +endif diff --git a/wireless/iwpan/Make.defs b/wireless/iwpan/Make.defs new file mode 100644 index 000000000..f265ef8b6 --- /dev/null +++ b/wireless/iwpan/Make.defs @@ -0,0 +1,41 @@ +############################################################################ +# apps/wireless/iwpan/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# Author: Anthony Merlino +# +# 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_WIRELESS_IWPAN),y) +CONFIGURED_APPS += wireless/iwpan +endif + diff --git a/wireless/iwpan/Makefile b/wireless/iwpan/Makefile new file mode 100644 index 000000000..68f1fe039 --- /dev/null +++ b/wireless/iwpan/Makefile @@ -0,0 +1,150 @@ +############################################################################ +# apps/wireless/iwpan/Makefile +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# Author: Anthony Merlino +# +# 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. +# +############################################################################ + +# TODO, this makefile should run make under the app dirs, instead of +# sourcing the Make.defs! + +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +# IEEE802.11 Wapi Application + +CONFIG_WIRELESS_IWPAN_PRIORITY ?= 100 +CONFIG_WIRELESS_IWPAN_STACKSIZE ?= 2048 + +APPNAME = iwpan +PRIORITY = $(CONFIG_WIRELESS_IWPAN_PRIORITY) +STACKSIZE = $(CONFIG_WIRELESS_IWPAN_STACKSIZE) + +ASRCS = +CSRCS = +MAINSRC = + +VPATH = . + +include $(APPDIR)/wireless/iwpan/src/Make.defs + +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_IWPAN_PROGNAME ?= iwpan$(EXEEXT) +PROGNAME = $(CONFIG_IWPAN_PROGNAME) + +ROOTDEPPATH = --dep-path . + +# Common build + +all: .built +.PHONY: context depend clean distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + $(Q) 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 + +# Register application + +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 + +# Create dependencies + +.depend: Makefile $(SRCS) + $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep +.PHONY: preconfig +preconfig: diff --git a/wireless/iwpan/src/Make.defs b/wireless/iwpan/src/Make.defs new file mode 100644 index 000000000..e7577e3ac --- /dev/null +++ b/wireless/iwpan/src/Make.defs @@ -0,0 +1,47 @@ +############################################################################ +# apps/wireless/iwpan/src/Make.defs +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# Author: Anthony Merlino +# +# 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_WIRELESS_IWPAN),y) + +CSRCS = +MAINSRC = iwpan.c + +DEPPATH += --dep-path src +VPATH += :src +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/wireless/iwpan/src} + +endif + diff --git a/wireless/iwpan/src/iwpan.c b/wireless/iwpan/src/iwpan.c new file mode 100644 index 000000000..bd3abf969 --- /dev/null +++ b/wireless/iwpan/src/iwpan.c @@ -0,0 +1,774 @@ +/**************************************************************************** + * apps/wireless/iwpan/src/iwpan.c + * + * Copyright (C) 2017 Verge Inc. All rights reserved. + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Anthony Merlino + * Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - 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. + * + * 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 "wireless/ieee802154.h" +#include "wireless/iwpan.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* The address family that we used to create the socket really does not + * matter. It should, however, be valid in the current configuration. + */ + +#if defined(CONFIG_NET_IPv4) +# define PF_INETX PF_INET +#elif defined(CONFIG_NET_IPv6) +# define PF_INETX PF_INET6 +#endif + +/* SOCK_DGRAM is the preferred socket type to use when we just want a + * socket for performing driver ioctls. However, we can't use SOCK_DRAM + * if UDP is disabled. + */ + +#ifdef CONFIG_NET_UDP +# define SOCK_IWPAN SOCK_DGRAM +#else +# define SOCK_IWPAN SOCK_STREAM +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* Describes one command */ + +struct iwpan_command_s +{ + FAR const char *name; + uint8_t noptions; + CODE void *handler; +}; + +/* Generic form of a command handler */ + +typedef void (*cmd1_t)(int sock, FAR const char *arg1); +typedef void (*cmd2_t)(int sock, FAR const char *arg1, + FAR const char *arg2); +typedef void (*cmd3_t)(int sock, FAR const char *arg1, + FAR const char *arg2, FAR const char *arg3); + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static void iwpan_show_cmd(int sock, FAR const char *ifname); +static void iwpan_cca_cmd(int sock, FAR const char *ifname, + FAR const char *ccastr); +static void iwpan_chan_cmd(int sock, FAR const char *ifname, + FAR const char *chanstr); +static void iwpan_devmode_cmd(int sock, FAR const char *ifname, + FAR const char *modstr); +static void iwpan_eaddr_cmd(int sock, FAR const char *ifname, + FAR const char *addrstr); +static void iwpan_panid_cmd(int sock, FAR const char *ifname, + FAR const char *panstr); +static void iwpan_promisc_cmd(int sock, FAR const char *ifname, + FAR const char *boolstr); +static void iwpan_saddr_cmd(int sock, FAR const char *ifname, + FAR const char *addrstr); +static void iwpan_txpwr_cmd(int sock, FAR const char *ifname, + FAR const char *pwrstr); + +static void iwpan_showusage(FAR const char *progname, int exitcode); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct iwpan_command_s g_iwpan_commands[] = +{ + {"help", 0, (CODE void *)NULL}, + {"show", 1, (CODE void *)iwpan_show_cmd}, + {"cca", 2, (CODE void *)iwpan_cca_cmd}, + {"chan", 2, (CODE void *)iwpan_chan_cmd}, + {"devmode", 2, (CODE void *)iwpan_devmode_cmd}, + {"eaddr", 2, (CODE void *)iwpan_eaddr_cmd}, + {"panid", 2, (CODE void *)iwpan_panid_cmd}, + {"promisc", 2, (CODE void *)iwpan_promisc_cmd}, + {"saddr", 2, (CODE void *)iwpan_saddr_cmd}, + {"txpwr", 2, (CODE void *)iwpan_txpwr_cmd}, +}; + +#define NCOMMANDS (sizeof(g_iwpan_commands) / sizeof(struct iwpan_command_s)) + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: iwpan_str2long + * + * Description: + * Convert a string to an integer value + * + ****************************************************************************/ + +static long iwpan_str2long(FAR const char *str) +{ + FAR char *endptr; + long value; + + value = strtol(str, &endptr, 0); + if (*endptr != '\0') + { + fprintf(stderr, "ERROR: Garbage after numeric argument\n"); + exit(EXIT_FAILURE); + } + + if (value > INT_MAX || value < INT_MIN) + { + fprintf(stderr, "ERROR: Integer value out of range\n"); + return LONG_MAX; + exit(EXIT_FAILURE); + } + + return value; +} + +/**************************************************************************** + * Name: iwpan_str2luint8 + * + * Description: + * Convert a string to an integer value + * + ****************************************************************************/ + +static uint8_t iwpan_str2luint8(FAR const char *str) +{ + long value = iwpan_str2long(str); + if (value < 0 || value > UINT8_MAX) + { + fprintf(stderr, "ERROR: 8-bit value out of range\n"); + exit(EXIT_FAILURE); + } + + return (uint8_t)value; +} + +/**************************************************************************** + * Name: iwpan_str2luint16 + * + * Description: + * Convert a string to an integer value + * + ****************************************************************************/ + +static uint16_t iwpan_str2luint16(FAR const char *str) +{ + long value = iwpan_str2long(str); + if (value < 0 || value > UINT16_MAX) + { + fprintf(stderr, "ERROR: 16-bit value out of range\n"); + exit(EXIT_FAILURE); + } + + return (uint8_t)value; +} + +/**************************************************************************** + * Name: iwpan_char2nibble + * + * Description: + * Convert an hexadecimal character to a 4-bit nibble. + * + ****************************************************************************/ + +static uint8_t iwpan_char2nibble(char ch) +{ + if (ch >= '0' && ch <= '9') + { + return ch - '0'; + } + else if (ch >= 'a' && ch <= 'f') + { + return ch - 'a' + 10; + } + else if (ch >= 'A' && ch <= 'F') + { + return ch - 'A' + 10; + } + else if (ch == '\0') + { + fprintf(stderr, "ERROR: Unexpected end hex\n"); + exit(EXIT_FAILURE); + } + else + { + fprintf(stderr, "ERROR: Unexpected character in hex value: %02x\n", ch); + exit(EXIT_FAILURE); + } +} + +/**************************************************************************** + * Name: iwpan_str2eaddr + * + * Description: + * Convert a string 8-byte EADAR array. + * + ****************************************************************************/ + +static void iwpan_str2eaddr(FAR const char *str, FAR uint8_t *eaddr) +{ + FAR const char *src = str; + uint8_t bvalue; + char ch; + int i; + + for (i = 0; i < 8; i++) + { + ch = (char)*src++; + bvalue = iwpan_char2nibble(ch) << 4; + + ch = (char)*src++; + bvalue |= iwpan_char2nibble(ch); + + *eaddr++ = bvalue; + + if (i < 7) + { + ch = (char)*src++; + if (ch != ':') + { + fprintf(stderr, "ERROR: Missing colon separator: %s\n", str); + fprintf(stderr, " Expected xx:xx:xx:xx:xx:xx:xx:xx\n"); + exit(EXIT_FAILURE); + } + } + } +} + +/**************************************************************************** + * Name: iwpan_str2bool + * + * Description: + * Convert a boolean name to a boolean value. + * + ****************************************************************************/ + +static bool iwpan_str2bool(FAR const char *str) +{ + if (strcasecmp(str, "true") == 0) + { + return true; + } + else if (strcasecmp(str, "false") == 0) + { + return false; + } + else + { + fprintf(stderr, "ERROR: Invalid boolean name: %s\n", str); + fprintf(stderr, " Expected true or false\n"); + exit(EXIT_FAILURE); + } +} + +/**************************************************************************** + * Name: iwpan_show_cmd + * + * Description: + * Show all radio device settings + * + ****************************************************************************/ + +static void iwpan_show_cmd(int sock, FAR const char *ifname) +{ + uint8_t eaddr[EADDR_SIZE] = + { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff + }; + + union + { + struct ieee802154_cca_s cca; + uint8_t b; + } u; + + int32_t txpwr = INT32_MAX; + uint16_t saddr = UINT16_MAX; + uint16_t panid = UINT16_MAX; + uint8_t chan = UINT8_MAX; + uint8_t devmode = UINT8_MAX; + bool promisc = false; + bool energy = false; + int ret; + + u.b = 0xff; + + /* Read all parameters from the radio */ + + ret = sixlowpan_getchan(sock, ifname, &chan); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_getchan() failed: %d\n", ret); + } + + ret = sixlowpan_getpanid(sock, ifname, &panid); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_getpanid() failed: %d\n", ret); + } + + ret = sixlowpan_getsaddr(sock, ifname, &saddr); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_getsaddr() failed: %d\n", ret); + } + + ret = sixlowpan_geteaddr(sock, ifname, eaddr); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_geteaddr() failed: %d\n", ret); + } + + ret = sixlowpan_getpromisc(sock, ifname, &promisc); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_getpromisc() failed: %d\n", ret); + } + + ret = sixlowpan_getdevmode(sock, ifname, &devmode); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_getdevmode() failed: %d\n", ret); + } + + ret = sixlowpan_gettxpwr(sock, ifname, &txpwr); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_gettxpwr() failed: %d\n", ret); + } + + ret = sixlowpan_getcca(sock, ifname, &u.cca); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_getcca() failed: %d\n", ret); + } + + ret = sixlowpan_energydetect(sock, ifname, &energy); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_energydetect() failed: %d\n", ret); + } + + /* And generate the output */ + + fprintf(stderr, "\nRadio Settings (%s):\n", ifname); + fprintf(stderr, " chan: %u\n", chan); + fprintf(stderr, " saddr: %04x\n", saddr); + fprintf(stderr, " eaddr: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", + eaddr[0], eaddr[1], eaddr[2], eaddr[3], eaddr[4], eaddr[5], + eaddr[6], eaddr[7]); + fprintf(stderr, " panid: %04x\n", panid); + fprintf(stderr, " devmode: %u\n", devmode); + fprintf(stderr, " promisc: %s\n", promisc ? "true" : "false"); + fprintf(stderr, " cca: %02x\n", u.b); + fprintf(stderr, " txpwr: %ld\n", (long)txpwr); + fprintf(stderr, " ernergy: %s\n", energy ? "true" : "false"); +} + +/**************************************************************************** + * Name: iwpan_cca_cmd + * + * Description: + * Set radio device Clear Channel Assessment (CCA) thresholds. + * + ****************************************************************************/ + +static void iwpan_cca_cmd(int sock, FAR const char *ifname, + FAR const char *ccastr) +{ + union + { + struct ieee802154_cca_s cca; + uint8_t b; + } u; + int ret; + + /* Convert input strings to values */ + + u.b = iwpan_str2luint8(ccastr); + + /* Set the CCA */ + + ret = sixlowpan_setcca(sock, ifname, &u.cca); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_setcca() failed: %d\n", ret); + } +} + +/**************************************************************************** + * Name: iwpan_chan_cmd + * + * Description: + * Set radio device channel + * + ****************************************************************************/ + +static void iwpan_chan_cmd(int sock, FAR const char *ifname, + FAR const char *chanstr) +{ + uint8_t chan; + int ret; + + /* Convert input strings to values */ + + chan = iwpan_str2luint8(chanstr); + + /* Set the channel */ + + ret = sixlowpan_setchan(sock, ifname, chan); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_setchan() failed: %d\n", ret); + } +} + +/**************************************************************************** + * Name: iwpan_devmode_cmd + * + * Description: + * Set radio device mode + * + ****************************************************************************/ + +static void iwpan_devmode_cmd(int sock, FAR const char *ifname, + FAR const char *modestr) +{ + uint8_t devmode; + int ret; + + /* Convert input strings to values */ + + devmode = iwpan_str2luint8(modestr); + + /* Set the devmode */ + + ret = sixlowpan_setdevmode(sock, ifname, devmode); + if (ret < 0) + { + fprintf(stderr, "ERROR:int sixlowpan_setdevmode() failed: %d\n", ret); + } +} + +/**************************************************************************** + * Name: iwpan_eaddr_cmd + * + * Description: + * Set radio device extended address + * + * + ****************************************************************************/ + +static void iwpan_eaddr_cmd(int sock, FAR const char *ifname, + FAR const char *addrstr) +{ + uint8_t eaddr[EADDR_SIZE]; + int ret; + + /* Convert input strings to values */ + + iwpan_str2eaddr(addrstr, eaddr); + + /* Set the extended address */ + + ret = sixlowpan_seteaddr(sock, ifname, eaddr); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_seteaddr() failed: %d\n", ret); + } +} + +/**************************************************************************** + * Name: iwpan_panid_cmd + * + * Description: + * Set radio device PAN ID. + * + * + ****************************************************************************/ + +static void iwpan_panid_cmd(int sock, FAR const char *ifname, + FAR const char *panstr) +{ + uint16_t panid; + int ret; + + /* Convert input strings to values */ + + panid = iwpan_str2luint16(panstr); + + /* Set the PAN ID */ + + ret = sixlowpan_setpanid(sock, ifname, panid); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_setpanid() failed: %d\n", ret); + } +} + +/**************************************************************************** + * Name: iwpan_promisc_cmd + * + * Description: + * Set radio device PAN ID. + * + * + ****************************************************************************/ + +static void iwpan_promisc_cmd(int sock, FAR const char *ifname, + FAR const char *boolstr) +{ + bool promisc; + int ret; + + /* Convert input strings to values */ + + promisc = iwpan_str2bool(boolstr); + + /* Set the promisc */ + + ret = sixlowpan_setpromisc(sock, ifname, promisc); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_setpromisc() failed: %d\n", ret); + } +} + +/**************************************************************************** + * Name: iwpan_saddr_cmd + * + * Description: + * Set radio device short address + * + ****************************************************************************/ + +static void iwpan_saddr_cmd(int sock, FAR const char *ifname, + FAR const char *addrstr) +{ + uint16_t saddr; + int ret; + + /* Convert input strings to values */ + + saddr = iwpan_str2luint16(addrstr); + + /* Set the short address */ + + ret = sixlowpan_setsaddr(sock, ifname, saddr); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_setsaddr() failed: %d\n", ret); + } +} + +/**************************************************************************** + * Name: iwpan_txpwr_cmd + * + * Description: + * Set radio device TX power + * + ****************************************************************************/ + +static void iwpan_txpwr_cmd(int sock, FAR const char *ifname, + FAR const char *pwrstr) +{ + long txpwr; + int ret; + + /* Convert input strings to values */ + + txpwr = iwpan_str2long(pwrstr); + + /* Set the TX power */ + + ret = sixlowpan_settxpwr(sock, ifname, (int32_t)txpwr); + if (ret < 0) + { + fprintf(stderr, "ERROR: sixlowpan_settxpwr() failed: %d\n", ret); + } +} + +/**************************************************************************** + * Name: iwpan_showusage + * + * Description: + * Show program usage. + * + ****************************************************************************/ + +static void iwpan_showusage(FAR const char *progname, int exitcode) +{ + fprintf(stderr, "Usage:\n", progname); + fprintf(stderr, "\t%s [OPTIONS]\n", progname); + fprintf(stderr, "\nWhere supported commands an [OPTIONS] appear below\n"); + fprintf(stderr, "\nRadio Query:\n"); + fprintf(stderr, "\t%s show \n", progname); + fprintf(stderr, "\nRadio Settings:\n"); + fprintf(stderr, "\t%s cca \n", progname); + fprintf(stderr, "\t%s chan \n", progname); + fprintf(stderr, "\t%s devmode \n", progname); + fprintf(stderr, "\t%s eaddr \n", progname); + fprintf(stderr, "\t%s panid \n", progname); + fprintf(stderr, "\t%s promisc \n", progname); + fprintf(stderr, "\t%s saddr \n", progname); + fprintf(stderr, "\t%s txpwr \n", progname); + fprintf(stderr, "\nMAC Commands:\n"); + fprintf(stderr, "\t%s assoc TBD\n", progname); + fprintf(stderr, "\t%s disassoc TBD\n", progname); + fprintf(stderr, "\t%s get TBD\n", progname); + fprintf(stderr, "\t%s gts TBD\n", progname); + fprintf(stderr, "\t%s poll TBD\n", progname); + fprintf(stderr, "\t%s rxenab TBD\n", progname); + fprintf(stderr, "\t%s scan TBD\n", progname); + fprintf(stderr, "\t%s set TBD\n", progname); + fprintf(stderr, "\t%s start TBD\n", progname); + fprintf(stderr, "\t%s sync TBD\n", progname); + fprintf(stderr, "\nWhere:\n"); + fprintf(stderr, "\t must be entered as xx:xx:xx:xx:xx:xx:xx\n"); + exit(exitcode); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int iwpan_main(int argc, char *argv[]) +#endif +{ + FAR const char *cmdname; + FAR const struct iwpan_command_s *iwpancmd; + int sock; + int i; + + /* Get the command */ + + if (argc < 2) + { + fprintf(stderr, "ERROR: Missing command\n"); + iwpan_showusage(argv[0], EXIT_FAILURE); + } + + cmdname = argv[1]; + + /* Find the command in the g_iwpan_command[] list */ + + iwpancmd = NULL; + for (i = 0; i < NCOMMANDS; i++) + { + FAR const struct iwpan_command_s *cmd = &g_iwpan_commands[i]; + if (strcmp(cmdname, cmd->name) == 0) + { + iwpancmd = cmd; + break; + } + } + + if (iwpancmd == NULL) + { + fprintf(stderr, "ERROR: Unsupported command: %s\n", cmdname); + iwpan_showusage(argv[0], EXIT_FAILURE); + } + + if (iwpancmd->noptions + 2 < argc) + { + fprintf(stderr, "ERROR: Garbage at end of command ignored\n"); + } + else if (iwpancmd->noptions + 2 > argc) + { + fprintf(stderr, "ERROR: Missing required command options: %s\n", + cmdname); + iwpan_showusage(argv[0], EXIT_FAILURE); + } + + /* Special case the help command which has no arguments, no handler, + * and does not need a socket. + */ + + if (iwpancmd->handler == NULL) + { + iwpan_showusage(argv[0], EXIT_SUCCESS); + } + + /* Create a communication socket */ + + sock = socket(PF_INETX, SOCK_IWPAN, 0); + if (sock < 0) + { + fprintf(stderr, "ERROR: iwpan_make_socket() failed: %d\n", sock); + return EXIT_FAILURE; + } + + /* Dispatch the command handling */ + + switch (iwpancmd->noptions) + { + default: + case 0: + fprintf(stderr, "ERROR: Internal craziness\n"); + iwpan_showusage(argv[0], EXIT_FAILURE); + + case 1: + ((cmd1_t)iwpancmd->handler)(sock, argv[2]); + break; + + case 2: + ((cmd2_t)iwpancmd->handler)(sock, argv[2], argv[3]); + break; + + case 3: + ((cmd3_t)iwpancmd->handler)(sock, argv[2], argv[3], argv[4]); + break; + } + + /* Close communication socket */ + + close(sock); + return EXIT_SUCCESS; +} diff --git a/wireless/wapi/Kconfig b/wireless/wapi/Kconfig index 249a1593d..bb76675a9 100644 --- a/wireless/wapi/Kconfig +++ b/wireless/wapi/Kconfig @@ -4,7 +4,7 @@ # menuconfig WIRELESS_WAPI - bool "IEEE802.11 Configuration Library" + bool "IEEE 802.11 Configuration Library" default n depends on NET && DRIVERS_WIRELESS && EXPERIMENTAL ---help--- @@ -14,7 +14,7 @@ menuconfig WIRELESS_WAPI if WIRELESS_WAPI config WIRELESS_WAPI_CMDTOOL - bool "IEEE802.11 Command Line Tool" + bool "IEEE 802.11 Command Line Tool" default n ---help--- By default, Wapi is build as only a library. If this option is diff --git a/wireless/wapi/src/network.c b/wireless/wapi/src/network.c index bc472b9ff..2de7bc37c 100644 --- a/wireless/wapi/src/network.c +++ b/wireless/wapi/src/network.c @@ -1,7 +1,7 @@ /**************************************************************************** * apps/wireless/wapi/examples/network.c * - * Copyright (C) 2011, 2017Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Adapted for Nuttx from WAPI: diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c index f2065e8b6..dd07b1b7e 100644 --- a/wireless/wapi/src/wapi.c +++ b/wireless/wapi/src/wapi.c @@ -62,7 +62,7 @@ struct wapi_command_s CODE void *handler; }; -/* Generic form of a commnd handler */ +/* Generic form of a command handler */ typedef void (*cmd1_t)(int sock, FAR const char *arg1); typedef void (*cmd2_t)(int sock, FAR const char *arg1,