From d9a02dd742705c1fe1fc5283d64b44819ccbeaaf Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Apr 2017 16:34:50 -0600 Subject: [PATCH 01/11] apps/wireless/wapi: Consolidate some duplicate logic. --- wireless/wapi/src/wapi.c | 131 ++++++++++++--------------------------- 1 file changed, 38 insertions(+), 93 deletions(-) diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c index 09f6538ef..60f00a3b9 100644 --- a/wireless/wapi/src/wapi.c +++ b/wireless/wapi/src/wapi.c @@ -114,7 +114,7 @@ static const struct wapi_command_s g_wapi_commands[] = {"mode", 2, (CODE void *)wapi_mode_cmd}, {"ap", 2, (CODE void *)wapi_ap_cmd}, {"bitrate", 3, (CODE void *)wapi_bitrate_cmd}, - {"txpower", 2, (CODE void *)wapi_txpower_cmd}, + {"txpower", 3, (CODE void *)wapi_txpower_cmd}, }; #define NCOMMANDS (sizeof(g_wapi_commands) / sizeof(struct wapi_command_s)) @@ -175,6 +175,31 @@ static double wapi_str2double(FAR const char *str) return value; } +/**************************************************************************** + * Name: wapi_str2ndx + * + * Description: + * Return the index of a string in a list of strings + * + ****************************************************************************/ + +static unsigned int wapi_str2ndx(FAR const char *name, FAR const char **list, + unsigned int listlen) +{ + unsigned int ndx; + + for (ndx = 0; ndx < listlen; ndx++) + { + if (strcmp(name, list[ndx]) == 0) + { + return ndx; + } + } + + WAPI_ERROR("ERROR: Invalid string: %s\n", name); + exit(EXIT_FAILURE); +} + /**************************************************************************** * Name: wapi_show_cmd * @@ -418,29 +443,13 @@ static void wapi_freq_cmd(int sock, FAR const char *ifname, { double frequency; wapi_freq_flag_t freq_flag; - bool found = false; int ret; - int i; /* Convert input strings to values */ frequency = wapi_str2double(freqstr); - - for (i = 0; i < IW_FREQ_NFLAGS; i++) - { - if (strcmp(flagstr, g_wapi_freq_flags[i]) == 0) - { - freq_flag = (wapi_freq_flag_t)i; - found = true; - break; - } - } - - if (!found) - { - WAPI_ERROR("ERROR: Invalid frequency flag: %s\n", flagstr); - exit(EXIT_FAILURE); - } + freq_flag = (wapi_freq_flag_t)wapi_str2ndx(flagstr, g_wapi_freq_flags, + IW_FREQ_NFLAGS); /* Set the frequency */ @@ -466,28 +475,12 @@ static void wapi_essid_cmd(int sock, FAR const char *ifname, FAR const char *essid, FAR const char *flagstr) { wapi_essid_flag_t essid_flag; - bool found = false; int ret; - int i; /* Convert input strings to values */ - for (i = 0; i < 2; i++) - { - if (strcmp(flagstr, g_wapi_essid_flags[i]) == 0) - { - essid_flag = (wapi_essid_flag_t)i; - found = true; - break; - } - } - - if (!found) - { - WAPI_ERROR("ERROR: Invalid ESSID flag: %s\n", flagstr); - exit(EXIT_FAILURE); - } - + essid_flag = (wapi_essid_flag_t)wapi_str2ndx(flagstr, g_wapi_essid_flags, 2); + /* Set the ESSID */ ret = wapi_set_essid(sock, ifname, essid, essid_flag); @@ -512,27 +505,11 @@ static void wapi_mode_cmd(int sock, FAR const char *ifname, FAR const char *modestr) { wapi_mode_t mode; - bool found = false; int ret; - int i; /* Convert input strings to values */ - for (i = 0; i < IW_MODE_NFLAGS; i++) - { - if (strcmp(modestr, g_wapi_modes[i]) == 0) - { - mode = (wapi_mode_t)i; - found = true; - break; - } - } - - if (!found) - { - WAPI_ERROR("ERROR: Invalid operating mode: %s\n", modestr); - exit(EXIT_FAILURE); - } + mode = (wapi_mode_t)wapi_str2ndx(modestr, g_wapi_modes, IW_MODE_NFLAGS); /* Set operating mode */ @@ -592,30 +569,14 @@ static void wapi_bitrate_cmd(int sock, FAR const char *ifname, { wapi_bitrate_flag_t bitrate_flag; - bool found = false; int bitrate; int ret; - int i; /* Convert input strings to values */ - bitrate = wapi_str2int(ratestr); - - for (i = 0; i < 2; i++) - { - if (strcmp(flagstr, g_wapi_bitrate_flags[i]) == 0) - { - bitrate_flag = (wapi_bitrate_flag_t)i; - found = true; - break; - } - } - - if (!found) - { - WAPI_ERROR("ERROR: Invalid bitrate flag: %s\n", flagstr); - exit(EXIT_FAILURE); - } + bitrate = wapi_str2int(ratestr); + bitrate_flag = (wapi_bitrate_flag_t) + wapi_str2ndx(flagstr, g_wapi_bitrate_flags, 2); /* Set bitrate */ @@ -641,30 +602,14 @@ static void wapi_txpower_cmd(int sock, FAR const char *ifname, FAR const char *pwrstr, FAR const char *flagstr) { wapi_txpower_flag_t txpower_flag; - bool found = false; int txpower; int ret; - int i; /* Convert input strings to values */ - txpower = wapi_str2int(pwrstr); - - for (i = 0; i < IW_TXPOW_NFLAGS; i++) - { - if (strcmp(flagstr, g_wapi_txpower_flags[i]) == 0) - { - txpower_flag = (wapi_txpower_flag_t)i; - found = true; - break; - } - } - - if (!found) - { - WAPI_ERROR("ERROR: Invalid TX power flag: %s\n", flagstr); - exit(EXIT_FAILURE); - } + txpower = wapi_str2int(pwrstr); + txpower_flag = (wapi_txpower_flag_t) + wapi_str2ndx(flagstr, g_wapi_txpower_flags, IW_TXPOW_NFLAGS); /* Set txpower */ @@ -728,7 +673,7 @@ static void wapi_scan_cmd(int sock, FAR const char *ifname) for (info = list.head.scan; info; info = info->next) { - printf(">> %02x:%02x:%02x:%02x:%02x:%02x %s\n", + printf(" %02x:%02x:%02x:%02x:%02x:%02x %s\n", info->ap.ether_addr_octet[0], info->ap.ether_addr_octet[1], info->ap.ether_addr_octet[2], info->ap.ether_addr_octet[3], info->ap.ether_addr_octet[4], info->ap.ether_addr_octet[5], From 65d59f84582a002d862b879bd7f7286cc2bfcdf0 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Wed, 12 Apr 2017 06:47:07 -0600 Subject: [PATCH 02/11] examples/ostest: clarify when pthread clean-up test mutex need to remain usable --- examples/ostest/pthread_cleanup.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/ostest/pthread_cleanup.c b/examples/ostest/pthread_cleanup.c index 54650823f..61c11f0f8 100644 --- a/examples/ostest/pthread_cleanup.c +++ b/examples/ostest/pthread_cleanup.c @@ -60,16 +60,20 @@ static void cleanup(FAR void * data) FAR struct sync_s *sync = (FAR struct sync_s *) data; int status; - /* Note: pthread_cond_wait() will release the mutex while it waits on - * condition value. So a EPERM error is not a failure. + /* Note: The behavior of canceling pthread_cond_wait() with asynchronous + * cancellation is not defined. On NuttX we get EPERM here, but application + * code must not rely on this. */ status = pthread_mutex_unlock(&sync->lock); +#ifndef CONFIG_CANCELLATION_POINTS if (status == EPERM) { printf("pthread_cleanup: thread did not have mutex locked: %d\n", status); + return; } - else if (status != 0) +#endif + if (status != 0) { printf("pthread_cleanup: ERROR pthread_mutex_unlock in cleanup handler. " "Status: %d\n", status); @@ -138,6 +142,7 @@ static void test_cleanup(void) printf("pthread_cleanup: ERROR pthread_join returned wrong result: %p\n", result); } +#ifdef CONFIG_CANCELLATION_POINTS /* Do some operations on lock in order to check if it is in usable state. */ status = pthread_mutex_trylock(&sync.lock); @@ -151,6 +156,7 @@ static void test_cleanup(void) { printf("pthread_cleanup: ERROR pthread_mutex_unlock, status=%d\n", status); } +#endif } /**************************************************************************** From 58da85523dcc3aa005400283fcd18db379a7d5cc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 12 Apr 2017 07:09:37 -0600 Subject: [PATCH 03/11] wireless/wapi: Improve some output. --- wireless/wapi/src/util.h | 83 +++++++++++++++++++++++++++++++--------- wireless/wapi/src/wapi.c | 10 ++++- 2 files changed, 73 insertions(+), 20 deletions(-) diff --git a/wireless/wapi/src/util.h b/wireless/wapi/src/util.h index 50de0b6eb..e7c304f7f 100644 --- a/wireless/wapi/src/util.h +++ b/wireless/wapi/src/util.h @@ -47,29 +47,74 @@ * Pre-processor Definitions ****************************************************************************/ -#define WAPI_IOCTL_STRERROR(cmd) \ - fprintf( \ - stderr, "%s:%d:%s():ioctl(%s): %s\n", \ - __FILE__, __LINE__, __func__, \ - wapi_ioctl_command_name(cmd), strerror(errno)) +#ifdef DEBUG_WIRELESS_ERROR +# ifdef CONFIG_LIBC_STRERROR +# define WAPI_IOCTL_STRERROR(cmd) \ + fprintf( \ + stderr, "%s:%d:%s():ioctl(%s): %s\n", \ + __FILE__, __LINE__, __func__, \ + wapi_ioctl_command_name(cmd), strerror(errno)) -#define WAPI_STRERROR(fmt, ...) \ - fprintf( \ - stderr, "%s:%d:%s():" fmt ": %s\n", \ - __FILE__, __LINE__, __func__, \ - ## __VA_ARGS__, strerror(errno)) +# define WAPI_STRERROR(fmt, ...) \ + fprintf( \ + stderr, "%s:%d:%s():" fmt ": %s\n", \ + __FILE__, __LINE__, __func__, \ + ## __VA_ARGS__, strerror(errno)) +# else +# define WAPI_IOCTL_STRERROR(cmd) \ + fprintf( \ + stderr, "%s:%d:%s():ioctl(%s): %d\n", \ + __FILE__, __LINE__, __func__, \ + wapi_ioctl_command_name(cmd), errno) -#define WAPI_ERROR(fmt, ...) \ - fprintf( \ - stderr, "%s:%d:%s(): " fmt , \ - __FILE__, __LINE__, __func__, ## __VA_ARGS__) +# define WAPI_STRERROR(fmt, ...) \ + fprintf( \ + stderr, "%s:%d:%s():" fmt ": %d\n", \ + __FILE__, __LINE__, __func__, \ + ## __VA_ARGS__, errno) +# endif + +# define WAPI_ERROR(fmt, ...) \ + fprintf( \ + stderr, "%s:%d:%s(): " fmt , \ + __FILE__, __LINE__, __func__, ## __VA_ARGS__) + +#else +# ifdef CONFIG_LIBC_STRERROR +# define WAPI_IOCTL_STRERROR(cmd) \ + fprintf( \ + stderr, "ioctl(%s): %s\n", \ + wapi_ioctl_command_name(cmd), strerror(errno)) + +# define WAPI_STRERROR(fmt, ...) \ + fprintf( \ + stderr, fmt ": %s\n", \ + ## __VA_ARGS__, strerror(errno)) +# else +# define WAPI_IOCTL_STRERROR(cmd) \ + fprintf( \ + stderr, "ioctl(%s): %d\n", \ + wapi_ioctl_command_name(cmd), errno) + +# define WAPI_STRERROR(fmt, ...) \ + fprintf( \ + stderr, fmt ": %d\n", \ + ## __VA_ARGS__, errno) +# endif + +# define WAPI_ERROR(fmt, ...) \ + fprintf( \ + stderr, fmt , \ + ## __VA_ARGS__) + +#endif #define WAPI_VALIDATE_PTR(ptr) \ - if (!ptr) \ - { \ - WAPI_ERROR("Null pointer: %s.\n", #ptr); \ - return -1; \ - } + if (ptr == NULL) \ + { \ + WAPI_ERROR("Null pointer: %p\n", ptr); \ + return -EINVAL; \ + } /**************************************************************************** * Public Function Prototypes diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c index 60f00a3b9..a5f53c2d2 100644 --- a/wireless/wapi/src/wapi.c +++ b/wireless/wapi/src/wapi.c @@ -76,6 +76,8 @@ typedef void (*cmd3_t)(int sock, FAR const char *arg1, static int wapi_str2int(FAR const char *str); static double wapi_str2double(FAR const char *str); +static unsigned int wapi_str2ndx(FAR const char *name, FAR const char **list, + unsigned int listlen); static void wapi_show_cmd(int sock, FAR const char *ifname); static void wapi_ip_cmd(int sock, FAR const char *ifname, @@ -196,7 +198,13 @@ static unsigned int wapi_str2ndx(FAR const char *name, FAR const char **list, } } - WAPI_ERROR("ERROR: Invalid string: %s\n", name); + WAPI_ERROR("ERROR: Invalid option string: %s\n", name); + WAPI_ERROR(" Valid options include:\n"); + for (ndx = 0; ndx < listlen; ndx++) + { + WAPI_ERROR(" - %s\n", list[ndx]); + } + exit(EXIT_FAILURE); } From 9a493045271d785dba2d7c5afe3713394a0e393a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Apr 2017 07:24:15 -0600 Subject: [PATCH 04/11] examples/hidkbd: Add some missing configuration settings. --- examples/hidkbd/Kconfig | 16 ++++++++++++++++ examples/hidkbd/Makefile | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/hidkbd/Kconfig b/examples/hidkbd/Kconfig index 3f2bc7a5d..c48ca98fe 100644 --- a/examples/hidkbd/Kconfig +++ b/examples/hidkbd/Kconfig @@ -11,6 +11,22 @@ config EXAMPLES_HIDKBD if EXAMPLES_HIDKBD +config EXAMPLES_HIDKBD_PROGNAME + string "Program name" + default "hidkbd" + depends on BUILD_KERNEL + ---help--- + This is the name of the program that will be use when the Nettest + program is installed. + +config EXAMPLES_HIDKBD_STACKSIZE + int "Task stack size" + default 2048 + +config EXAMPLES_HIDKBD_DEFPRIO + int "Task priority" + default 100 + config EXAMPLES_HIDKBD_DEVNAME string "Keyboard Device Name" default "/dev/kbda" diff --git a/examples/hidkbd/Makefile b/examples/hidkbd/Makefile index deed9c074..d49ee2aff 100644 --- a/examples/hidkbd/Makefile +++ b/examples/hidkbd/Makefile @@ -37,11 +37,11 @@ # USB Host HID keyboard Example -CONFIG_EXAMPLES_HIDKBD_PRIORITY ?= SCHED_PRIORITY_DEFAULT +CONFIG_EXAMPLES_HIDKBD_DEFPRIO ?= 100 CONFIG_EXAMPLES_HIDKBD_STACKSIZE ?= 2048 APPNAME = hidkbd -PRIORITY = $(CONFIG_EXAMPLES_HIDKBD_PRIORITY) +PRIORITY = $(CONFIG_EXAMPLES_HIDKBD_DEFPRIO) STACKSIZE = $(CONFIG_EXAMPLES_HIDKBD_STACKSIZE) # Hello, World! Example From 6b75120352f65c9fc4d20f55a783704b882f70ed Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Mon, 20 Apr 2015 17:46:21 +0900 Subject: [PATCH 05/11] NSH library: Fix open flags in nsh_codeccmd.c Jira: PDFW15IS-2824 Signed-off-by: Masayuki Ishikawa --- nshlib/nsh_codeccmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nshlib/nsh_codeccmd.c b/nshlib/nsh_codeccmd.c index da273e9e7..20b3947bb 100644 --- a/nshlib/nsh_codeccmd.c +++ b/nshlib/nsh_codeccmd.c @@ -314,9 +314,9 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv, fullpath = nsh_getfullpath(vtbl, localfile); - /* Open the local file for writing */ + /* Open the local file for reading */ - fd = open(fullpath, O_RDONLY|O_TRUNC, 0644); + fd = open(fullpath, O_RDONLY); if (fd < 0) { nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO); From c2bdd49421d3d1bc2d3cc9365862246cb55a0864 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 19 Apr 2017 18:10:19 -0600 Subject: [PATCH 06/11] netlib and NSH: Add logic to set the IEEE802.15.4 PAN ID. --- include/netutils/netlib.h | 2 + netutils/netlib/Makefile | 3 +- netutils/netlib/netlib_getpanid.c | 109 +++++++++++++++++++++++++++ netutils/netlib/netlib_setnodeaddr.c | 2 +- netutils/netlib/netlib_setpanid.c | 109 +++++++++++++++++++++++++++ nshlib/Kconfig | 9 +++ nshlib/nsh_netinit.c | 5 +- 7 files changed, 236 insertions(+), 3 deletions(-) create mode 100644 netutils/netlib/netlib_getpanid.c create mode 100644 netutils/netlib/netlib_setpanid.c diff --git a/include/netutils/netlib.h b/include/netutils/netlib.h index 4e1ff9fa6..46225819c 100644 --- a/include/netutils/netlib.h +++ b/include/netutils/netlib.h @@ -117,7 +117,9 @@ int netlib_getmacaddr(FAR const char *ifname, FAR uint8_t *macaddr); #ifdef CONFIG_NET_6LOWPAN /* Get IEEE802.15.4 MAC driver node address */ +int netlib_getpanid(FAR const char *ifname, FAR uint16_t *panid); int netlib_setnodeaddr(FAR const char *ifname, FAR const uint8_t *nodeaddr); +int netlib_setpanid(FAR const char *ifname, uint16_t panid); bool netlib_nodeaddrconv(FAR const char *hwstr, FAR uint8_t *hw); #endif diff --git a/netutils/netlib/Makefile b/netutils/netlib/Makefile index b5a8f96d2..a2233036e 100644 --- a/netutils/netlib/Makefile +++ b/netutils/netlib/Makefile @@ -87,7 +87,8 @@ CSRCS += netlib_setmacaddr.c netlib_getmacaddr.c endif ifeq ($(CONFIG_NET_6LOWPAN),y) -CSRCS += netlib_setnodeaddr.c netlib_nodeaddrconv.c +CSRCS += netlib_getpanid.c netlib_setnodeaddr.c netlib_setpanid.c +CSRCS += netlib_nodeaddrconv.c endif # IGMP support diff --git a/netutils/netlib/netlib_getpanid.c b/netutils/netlib/netlib_getpanid.c new file mode 100644 index 000000000..cd0a5ba67 --- /dev/null +++ b/netutils/netlib/netlib_getpanid.c @@ -0,0 +1,109 @@ +/**************************************************************************** + * netutils/netlib/netlib_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 + +#include +#include + +#include "netutils/netlib.h" + +#if defined(CONFIG_NET_6LOWPAN) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netlib_getpanid + * + * Description: + * Return the current PAN ID + * + * Parameters: + * ifname The name of the interface to use + * panid The location to return the current PAN ID + * + * Return: + * 0 on success; -1 on failure. errno will be set on failure. + * + ****************************************************************************/ + +int netlib_getpanid(FAR const char *ifname, FAR uint16_t *panid) +{ + int ret = ERROR; + + if (ifname != NULL && panid != NULL) + { + /* Get a socket (only so that we get access to the INET subsystem) */ + + int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0); + if (sockfd >= 0) + { + struct sixlowpan_req_s req; + + /* Put the driver name into the request */ + + strncpy(req.ifr_name, ifname, IFNAMSIZ); + + /* Perform the ioctl to get the current PAN ID */ + + ret = ioctl(sockfd, SIOCGWPANID, (unsigned long)((uintptr_t)&req)); + close(sockfd); + + /* Reuturn the current PAN ID */ + + *panid = req.u.panid.panid; + } + } + + return ret; +} + +#endif /* CONFIG_NET_6LOWPAN && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/netutils/netlib/netlib_setnodeaddr.c b/netutils/netlib/netlib_setnodeaddr.c index 436591eb9..81e8f88d8 100644 --- a/netutils/netlib/netlib_setnodeaddr.c +++ b/netutils/netlib/netlib_setnodeaddr.c @@ -96,7 +96,7 @@ int netlib_setnodeaddr(FAR const char *ifname, FAR const uint8_t *nodeaddr) req.ifr_hwaddr.sa_family = AF_INET6; memcpy(&req.ifr_hwaddr.sa_data, nodeaddr, NET_6LOWPAN_RIMEADDR_SIZE); - /* Perform the ioctl to set the MAC address */ + /* Perform the ioctl to set the node address */ ret = ioctl(sockfd, SIOCSIFHWADDR, (unsigned long)&req); close(sockfd); diff --git a/netutils/netlib/netlib_setpanid.c b/netutils/netlib/netlib_setpanid.c new file mode 100644 index 000000000..9ec7e988a --- /dev/null +++ b/netutils/netlib/netlib_setpanid.c @@ -0,0 +1,109 @@ +/**************************************************************************** + * netutils/netlib/netlib_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 + +#include +#include + +#include "netutils/netlib.h" + +#if defined(CONFIG_NET_6LOWPAN) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netlib_setpanid + * + * Description: + * Join the specified PAN ID + * + * Parameters: + * ifname The name of the interface to use + * panid The PAN ID to join + * + * Return: + * 0 on success; -1 on failure. errno will be set on failure. + * + ****************************************************************************/ + +int netlib_setpanid(FAR const char *ifname, uint16_t panid) +{ + int ret = ERROR; + + if (ifname != NULL) + { + /* Get a socket (only so that we get access to the INET subsystem) */ + + int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0); + if (sockfd >= 0) + { + struct sixlowpan_req_s req; + + /* Put the driver name into the request */ + + strncpy(req.ifr_name, ifname, IFNAMSIZ); + + /* Put the new PAN ID into the request */ + + req.u.panid.panid = panid; + + /* Perform the ioctl to set the new PAN ID */ + + ret = ioctl(sockfd, SIOCSWPANID, (unsigned long)((uintptr_t)&req)); + close(sockfd); + } + } + + return ret; +} + +#endif /* CONFIG_NET_6LOWPAN && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nshlib/Kconfig b/nshlib/Kconfig index 0a603c733..b402b5ac0 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -1456,6 +1456,15 @@ config NSH_MACADDR MAC address must provided with this selection. endif # NSH_NOMAC + +config NSH_PANID + hex "6loWPAN PAN ID" + default 0xface + depends on NET_6LOWPAN + range 0x0000 0xffff + ---help--- + Select the PAN ID to join upon initialization. + endif # NSH_NETINIT config NSH_MAX_ROUNDTRIP diff --git a/nshlib/nsh_netinit.c b/nshlib/nsh_netinit.c index f1f1f557f..fd2159f1f 100644 --- a/nshlib/nsh_netinit.c +++ b/nshlib/nsh_netinit.c @@ -295,8 +295,11 @@ static void nsh_netinit_configure(void) /* Set the 6loWPAN node address */ - netlib_setnodeaddr(NET_DEVNAME, nodeaddr); + (void)netlib_setnodeaddr(NET_DEVNAME, nodeaddr); + /* Set the 6loWPAN PAN ID */ + + (void)netlib_setpanid(NET_DEVNAME, CONFIG_NSH_PANID); #endif /* CONFIG_NET_ETHERNET */ #endif /* CONFIG_NSH_NOMAC && HAVE_MAC */ From adc1b27051b557bb85d033e1ce2eec6b27393bb3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Apr 2017 14:12:46 -0600 Subject: [PATCH 07/11] Remove the 6loWPAN PANID IOCTLs they are redundant. --- netutils/netlib/netlib_getpanid.c | 15 +-------------- netutils/netlib/netlib_setpanid.c | 15 +-------------- 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/netutils/netlib/netlib_getpanid.c b/netutils/netlib/netlib_getpanid.c index cd0a5ba67..9325b8395 100644 --- a/netutils/netlib/netlib_getpanid.c +++ b/netutils/netlib/netlib_getpanid.c @@ -46,12 +46,6 @@ #include #include -#include -#include - -#include -#include - #include "netutils/netlib.h" #if defined(CONFIG_NET_6LOWPAN) && CONFIG_NSOCKET_DESCRIPTORS > 0 @@ -86,20 +80,13 @@ int netlib_getpanid(FAR const char *ifname, FAR uint16_t *panid) int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0); if (sockfd >= 0) { - struct sixlowpan_req_s req; - /* Put the driver name into the request */ - - strncpy(req.ifr_name, ifname, IFNAMSIZ); - +#warning Missing logic /* Perform the ioctl to get the current PAN ID */ - ret = ioctl(sockfd, SIOCGWPANID, (unsigned long)((uintptr_t)&req)); close(sockfd); /* Reuturn the current PAN ID */ - - *panid = req.u.panid.panid; } } diff --git a/netutils/netlib/netlib_setpanid.c b/netutils/netlib/netlib_setpanid.c index 9ec7e988a..a227c7a19 100644 --- a/netutils/netlib/netlib_setpanid.c +++ b/netutils/netlib/netlib_setpanid.c @@ -46,12 +46,6 @@ #include #include -#include -#include - -#include -#include - #include "netutils/netlib.h" #if defined(CONFIG_NET_6LOWPAN) && CONFIG_NSOCKET_DESCRIPTORS > 0 @@ -86,19 +80,12 @@ int netlib_setpanid(FAR const char *ifname, uint16_t panid) int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0); if (sockfd >= 0) { - struct sixlowpan_req_s req; - /* Put the driver name into the request */ - - strncpy(req.ifr_name, ifname, IFNAMSIZ); - +# warning Missing Logic /* Put the new PAN ID into the request */ - req.u.panid.panid = panid; - /* Perform the ioctl to set the new PAN ID */ - ret = ioctl(sockfd, SIOCSWPANID, (unsigned long)((uintptr_t)&req)); close(sockfd); } } From ad608c705c0973453066a9ea01c3a368d4cee0f7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 25 Apr 2017 08:25:23 -0600 Subject: [PATCH 08/11] nshlib: nsh_netcmds.c should include netlib.h even if neither TCP nor UDP are enabled --- nshlib/nsh_netcmds.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c index 35f19354e..4ca8a1293 100644 --- a/nshlib/nsh_netcmds.c +++ b/nshlib/nsh_netcmds.c @@ -83,19 +83,16 @@ #include #endif -#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) && \ - !defined(CONFIG_DISABLE_SIGNALS) +#ifdef CONFIG_NETUTILS_NETLIB # include "netutils/netlib.h" #endif #if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 # include "netutils/netlib.h" -# include "netutils/tftp.h" #endif #if defined(CONFIG_NET_TCP) && CONFIG_NFILE_DESCRIPTORS > 0 # ifndef CONFIG_NSH_DISABLE_WGET -# include "netutils/netlib.h" # include "netutils/webclient.h" # endif #endif From 1c05e26ef6e8e66cbf1dafeb9d13035078f9956b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 25 Apr 2017 11:16:51 -0600 Subject: [PATCH 09/11] apps/wireless/wapi: Correct an error in dependency generation. --- wireless/wapi/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wireless/wapi/Makefile b/wireless/wapi/Makefile index 03de538c9..c32d89fc6 100644 --- a/wireless/wapi/Makefile +++ b/wireless/wapi/Makefile @@ -54,6 +54,7 @@ CSRCS = MAINSRC = VPATH = . +DEPPATH = --dep-path . include $(APPDIR)/wireless/wapi/src/Make.defs @@ -87,8 +88,6 @@ endif CONFIG_WAPI_PROGNAME ?= wapi$(EXEEXT) PROGNAME = $(CONFIG_WAPI_PROGNAME) -ROOTDEPPATH = --dep-path . - # Common build all: .built @@ -131,7 +130,7 @@ endif # Create dependencies .depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep $(Q) touch $@ depend: .depend From 4d09ebcaec99d760908834e3860d654819752d76 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Wed, 26 Apr 2017 10:32:20 -0600 Subject: [PATCH 10/11] examples: random: avoid stack overflows --- examples/random/Makefile | 2 +- examples/random/random_main.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/random/Makefile b/examples/random/Makefile index 5e4231259..78ca31d91 100644 --- a/examples/random/Makefile +++ b/examples/random/Makefile @@ -39,7 +39,7 @@ APPNAME = rand PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 1024 +STACKSIZE = 2048 ASRCS = CSRCS = diff --git a/examples/random/random_main.c b/examples/random/random_main.c index 6abcaaa97..f3d6cbffe 100644 --- a/examples/random/random_main.c +++ b/examples/random/random_main.c @@ -92,12 +92,16 @@ int rand_main(int argc, char *argv[]) if (argc > 1) { - nsamples = atoi(argv[1]); + nsamples = atoi(argv[1]); } /* Clip the number of samples to the configured buffer size */ - if (nsamples > CONFIG_EXAMPLES_MAXSAMPLES) + if (nsamples < 0) + { + nsamples = 0; + } + else if (nsamples > CONFIG_EXAMPLES_MAXSAMPLES) { nsamples = CONFIG_EXAMPLES_MAXSAMPLES; } @@ -124,14 +128,14 @@ int rand_main(int argc, char *argv[]) if (nread < 0) { int errcode = errno; - fprintf(stderr, "ERROR: Read from /dev/randon failed: %d\n", errcode); + fprintf(stderr, "ERROR: Read from /dev/random failed: %d\n", errcode); (void)close(fd); exit(EXIT_FAILURE); } if (nread != nsamples * sizeof(uint32_t)) { - fprintf(stderr, "ERROR: Read from /dev/randon only produced %d bytes\n", + fprintf(stderr, "ERROR: Read from /dev/random only produced %d bytes\n", (int)nread); (void)close(fd); exit(EXIT_FAILURE); From b9a552013f7ab5ba5f00c925794256ef0e07b87a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Apr 2017 12:34:50 -0600 Subject: [PATCH 11/11] wireless/wapi: Improve error reporting IOCTL failures. --- netutils/netlib/netlib_getessid.c | 2 +- netutils/netlib/netlib_setessid.c | 2 +- wireless/wapi/src/network.c | 36 ++++++++++++--- wireless/wapi/src/util.h | 16 +++---- wireless/wapi/src/wapi.c | 2 +- wireless/wapi/src/wireless.c | 75 +++++++++++++++++++++++-------- 6 files changed, 98 insertions(+), 35 deletions(-) diff --git a/netutils/netlib/netlib_getessid.c b/netutils/netlib/netlib_getessid.c index 4243a8b19..dcf63d97b 100644 --- a/netutils/netlib/netlib_getessid.c +++ b/netutils/netlib/netlib_getessid.c @@ -108,7 +108,7 @@ int netlib_getessid(FAR const char *ifname, FAR char *essid, size_t idlen) /* Put the driver name into the request */ memset(&req, 0, sizeof(struct iwreq)); - strncpy(req.ifrn_name, ifname, IFNAMSIZ); + strncpy(req.ifr_name, ifname, IFNAMSIZ); /* Put pointer to receive the ESSID into the request */ diff --git a/netutils/netlib/netlib_setessid.c b/netutils/netlib/netlib_setessid.c index 436465f8d..4cf03071b 100644 --- a/netutils/netlib/netlib_setessid.c +++ b/netutils/netlib/netlib_setessid.c @@ -106,7 +106,7 @@ int netlib_setessid(FAR const char *ifname, FAR const char *essid) /* Put the driver name into the request */ - strncpy(req.ifrn_name, ifname, IFNAMSIZ); + strncpy(req.ifr_name, ifname, IFNAMSIZ); /* Put the new ESSID into the request */ diff --git a/wireless/wapi/src/network.c b/wireless/wapi/src/network.c index a2e2a1b9a..bc472b9ff 100644 --- a/wireless/wapi/src/network.c +++ b/wireless/wapi/src/network.c @@ -71,7 +71,9 @@ static int wapi_get_addr(int sock, FAR const char *ifname, int cmd, } else { - WAPI_IOCTL_STRERROR(cmd); + int errcode = errno; + WAPI_IOCTL_STRERROR(cmd, errcode); + ret = -errcode; } return ret; @@ -92,7 +94,9 @@ static int wapi_set_addr(int sock, FAR const char *ifname, int cmd, strncpy(ifr.ifr_name, ifname, IFNAMSIZ); if ((ret = ioctl(sock, cmd, (unsigned long)((uintptr_t)&ifr))) < 0) { - WAPI_IOCTL_STRERROR(cmd); + int errcode = errno; + WAPI_IOCTL_STRERROR(cmd, errcode); + ret = -errcode; } return ret; @@ -141,7 +145,9 @@ static int wapi_act_route_gw(int sock, int act, if ((ret = ioctl(sock, act, (unsigned long)((uintptr_t)&rt))) < 0) { - WAPI_IOCTL_STRERROR(act); + int errcode = errno; + WAPI_IOCTL_STRERROR(act, errcode); + ret = -errcode; } return ret; @@ -177,7 +183,9 @@ int wapi_get_ifup(int sock, FAR const char *ifname, FAR int *is_up) } else { - WAPI_IOCTL_STRERROR(SIOCGIFFLAGS); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIFFLAGS, errcode); + ret = -errcode; } return ret; @@ -201,10 +209,18 @@ int wapi_set_ifup(int sock, FAR const char *ifname) { ifr.ifr_flags |= (IFF_UP | IFF_RUNNING); ret = ioctl(sock, SIOCSIFFLAGS, (unsigned long)((uintptr_t)&ifr)); + if (ret < 0) + { + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCSIFFLAGS, errcode); + ret = -errcode; + } } else { - WAPI_IOCTL_STRERROR(SIOCGIFFLAGS); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIFFLAGS, errcode); + ret = -errcode; } return ret; @@ -228,10 +244,18 @@ int wapi_set_ifdown(int sock, FAR const char *ifname) { ifr.ifr_flags &= ~IFF_UP; ret = ioctl(sock, SIOCSIFFLAGS, (unsigned long)((uintptr_t)&ifr)); + if (ret < 0) + { + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCSIFFLAGS, errcode); + ret = -errcode; + } } else { - WAPI_IOCTL_STRERROR(SIOCGIFFLAGS); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIFFLAGS, errcode); + ret = -errcode; } return ret; diff --git a/wireless/wapi/src/util.h b/wireless/wapi/src/util.h index e7c304f7f..02e0d65f1 100644 --- a/wireless/wapi/src/util.h +++ b/wireless/wapi/src/util.h @@ -49,11 +49,11 @@ #ifdef DEBUG_WIRELESS_ERROR # ifdef CONFIG_LIBC_STRERROR -# define WAPI_IOCTL_STRERROR(cmd) \ +# define WAPI_IOCTL_STRERROR(cmd,errcode) \ fprintf( \ stderr, "%s:%d:%s():ioctl(%s): %s\n", \ __FILE__, __LINE__, __func__, \ - wapi_ioctl_command_name(cmd), strerror(errno)) + wapi_ioctl_command_name(cmd), strerror(errcode)) # define WAPI_STRERROR(fmt, ...) \ fprintf( \ @@ -61,11 +61,11 @@ __FILE__, __LINE__, __func__, \ ## __VA_ARGS__, strerror(errno)) # else -# define WAPI_IOCTL_STRERROR(cmd) \ +# define WAPI_IOCTL_STRERROR(cmd,errcode) \ fprintf( \ stderr, "%s:%d:%s():ioctl(%s): %d\n", \ __FILE__, __LINE__, __func__, \ - wapi_ioctl_command_name(cmd), errno) + wapi_ioctl_command_name(cmd), errcode) # define WAPI_STRERROR(fmt, ...) \ fprintf( \ @@ -81,20 +81,20 @@ #else # ifdef CONFIG_LIBC_STRERROR -# define WAPI_IOCTL_STRERROR(cmd) \ +# define WAPI_IOCTL_STRERROR(cmd,errcode) \ fprintf( \ stderr, "ioctl(%s): %s\n", \ - wapi_ioctl_command_name(cmd), strerror(errno)) + wapi_ioctl_command_name(cmd), strerror(errcode)) # define WAPI_STRERROR(fmt, ...) \ fprintf( \ stderr, fmt ": %s\n", \ ## __VA_ARGS__, strerror(errno)) # else -# define WAPI_IOCTL_STRERROR(cmd) \ +# define WAPI_IOCTL_STRERROR(cmd,errcode) \ fprintf( \ stderr, "ioctl(%s): %d\n", \ - wapi_ioctl_command_name(cmd), errno) + wapi_ioctl_command_name(cmd), errcode) # define WAPI_STRERROR(fmt, ...) \ fprintf( \ diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c index a5f53c2d2..f2065e8b6 100644 --- a/wireless/wapi/src/wapi.c +++ b/wireless/wapi/src/wapi.c @@ -269,7 +269,7 @@ static void wapi_show_cmd(int sock, FAR const char *ifname) } else { - printf(" NetMask: %s", inet_ntoa(addr)); + printf(" NetMask: %s\n", inet_ntoa(addr)); } /* Get frequency */ diff --git a/wireless/wapi/src/wireless.c b/wireless/wapi/src/wireless.c index 36bac9600..2546ed54b 100644 --- a/wireless/wapi/src/wireless.c +++ b/wireless/wapi/src/wireless.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -341,7 +342,14 @@ int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq, WAPI_VALIDATE_PTR(flag); strncpy(wrq.ifr_name, ifname, IFNAMSIZ); - if ((ret = ioctl(sock, SIOCGIWFREQ, (unsigned long)((uintptr_t)&wrq))) >= 0) + ret = ioctl(sock, SIOCGIWFREQ, (unsigned long)((uintptr_t)&wrq)); + if (ret < 0) + { + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIWFREQ, errcode); + ret = -errcode; + } + else { /* Set flag. */ @@ -402,7 +410,9 @@ int wapi_set_freq(int sock, FAR const char *ifname, double freq, ret = ioctl(sock, SIOCSIWFREQ, (unsigned long)((uintptr_t)&wrq)); if (ret < 0) { - WAPI_IOCTL_STRERROR(SIOCSIWFREQ); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCSIWFREQ, errcode); + ret = -errcode; } return ret; @@ -462,7 +472,9 @@ int wapi_freq2chan(int sock, FAR const char *ifname, double freq, } else { - WAPI_IOCTL_STRERROR(SIOCGIWRANGE); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIWRANGE, errcode); + ret = -errcode; } return ret; @@ -518,7 +530,9 @@ int wapi_chan2freq(int sock, FAR const char *ifname, int chan, } else { - WAPI_IOCTL_STRERROR(SIOCGIWRANGE); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIWRANGE, errcode); + ret = -errcode; } return ret; @@ -553,7 +567,9 @@ int wapi_get_essid(int sock, FAR const char *ifname, FAR char *essid, ret = ioctl(sock, SIOCGIWESSID, (unsigned long)((uintptr_t)&wrq)); if (ret < 0) { - WAPI_IOCTL_STRERROR(SIOCGIWESSID); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIWESSID, errcode); + ret = -errcode; } else { @@ -591,7 +607,9 @@ int wapi_set_essid(int sock, FAR const char *ifname, FAR const char *essid, ret = ioctl(sock, SIOCSIWESSID, (unsigned long)((uintptr_t)&wrq)); if (ret < 0) { - WAPI_IOCTL_STRERROR(SIOCSIWESSID); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCSIWESSID, errcode); + ret = -errcode; } return ret; @@ -619,7 +637,9 @@ int wapi_get_mode(int sock, FAR const char *ifname, FAR wapi_mode_t *mode) } else { - WAPI_IOCTL_STRERROR(SIOCGIWMODE); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIWMODE, errcode); + ret = -errcode; } return ret; @@ -644,7 +664,9 @@ int wapi_set_mode(int sock, FAR const char *ifname, wapi_mode_t mode) ret = ioctl(sock, SIOCSIWMODE, (unsigned long)((uintptr_t)&wrq)); if (ret < 0) { - WAPI_IOCTL_STRERROR(SIOCSIWMODE); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCSIWMODE, errcode); + ret = -errcode; } return ret; @@ -702,7 +724,9 @@ int wapi_get_ap(int sock, FAR const char *ifname, FAR struct ether_addr *ap) } else { - WAPI_IOCTL_STRERROR(SIOCGIWAP); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIWAP, errcode); + ret = -errcode; } return ret; @@ -731,7 +755,9 @@ int wapi_set_ap(int sock, FAR const char *ifname, ret = ioctl(sock, SIOCSIWAP, (unsigned long)((uintptr_t)&wrq)); if (ret < 0) { - WAPI_IOCTL_STRERROR(SIOCSIWAP); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCSIWAP, errcode); + ret = -errcode; } return ret; @@ -772,7 +798,9 @@ int wapi_get_bitrate(int sock, FAR const char *ifname, } else { - WAPI_IOCTL_STRERROR(SIOCGIWRATE); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIWRATE, errcode); + ret = -errcode; } return ret; @@ -799,7 +827,9 @@ int wapi_set_bitrate(int sock, FAR const char *ifname, int bitrate, ret = ioctl(sock, SIOCSIWRATE, (unsigned long)((uintptr_t)&wrq)); if (ret < 0) { - WAPI_IOCTL_STRERROR(SIOCSIWRATE); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCSIWRATE, errcode); + ret = -errcode; } return ret; @@ -884,7 +914,9 @@ int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power, } else { - WAPI_IOCTL_STRERROR(SIOCGIWTXPOW); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIWTXPOW, errcode); + ret = -errcode; } return ret; @@ -928,7 +960,9 @@ int wapi_set_txpower(int sock, FAR const char *ifname, int power, ret = ioctl(sock, SIOCSIWTXPOW, (unsigned long)((uintptr_t)&wrq)); if (ret < 0) { - WAPI_IOCTL_STRERROR(SIOCSIWTXPOW); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCSIWTXPOW, errcode); + ret = -errcode; } return ret; @@ -956,7 +990,9 @@ int wapi_scan_init(int sock, const char *ifname) ret = ioctl(sock, SIOCSIWSCAN, (unsigned long)((uintptr_t)&wrq)); if (ret < 0) { - WAPI_IOCTL_STRERROR(SIOCSIWSCAN); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCSIWSCAN, errcode); + ret = -errcode; } return ret; @@ -1003,7 +1039,9 @@ int wapi_scan_stat(int sock, FAR const char *ifname) } else { - WAPI_IOCTL_STRERROR(SIOCGIWSCAN); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIWSCAN, errcode); + ret = -errcode; } return ret; @@ -1069,9 +1107,10 @@ alloc: if (ret < 0) { - WAPI_IOCTL_STRERROR(SIOCGIWSCAN); + int errcode = errno; + WAPI_IOCTL_STRERROR(SIOCGIWSCAN, errcode); free(buf); - return ret; + return -errcode; } /* We have the results, process them. */