Merged nuttx/apps into master

This commit is contained in:
Juha Niskanen 2017-05-08 09:11:51 +03:00
commit e87e8f7db0
16 changed files with 491 additions and 484 deletions

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* apps/include/wireless/wapi.h * apps/include/wireless/wapi.h
* *
* Copyright (C) 2011, 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Adapted for Nuttx from WAPI: * Adapted for Nuttx from WAPI:
@ -9,27 +9,40 @@
* Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com> * Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com>
* All rights reserved. * All rights reserved.
* *
* And includes WPA supplicant logic contributed by:
*
* Author: Simon Piriou <spiriou31@gmail.com>
*
* Which was adapted to NuttX from driver_ext.h
*
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
*
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions
* are met:
* *
* - Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright
* this list of conditions and the following disclaimer. * 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.
* *
* - Redistributions in binary form must reproduce the above copyright * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* notice, this list of conditions and the following disclaimer in the * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* documentation and/or other materials provided with the distribution. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * POSSIBILITY OF SUCH DAMAGE.
* 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.
* *
****************************************************************************/ ****************************************************************************/
@ -57,41 +70,59 @@
#define WAPI_PROC_LINE_SIZE 1024 #define WAPI_PROC_LINE_SIZE 1024
/* Select options to successfully open a socket in this nework configuration. */
/* 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_WAPI SOCK_DGRAM
#else
# define SOCK_WAPI SOCK_STREAM
#endif
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
/* Generic linked list (dummy) decleration. (No definition!) */
typedef struct wapi_list_t wapi_list_t;
/* Frequency flags. */ /* Frequency flags. */
typedef enum enum wapi_freq_flag_e
{ {
WAPI_FREQ_AUTO = IW_FREQ_AUTO, WAPI_FREQ_AUTO = IW_FREQ_AUTO,
WAPI_FREQ_FIXED = IW_FREQ_FIXED WAPI_FREQ_FIXED = IW_FREQ_FIXED
} wapi_freq_flag_t; };
/* Route target types. */ /* Route target types. */
typedef enum enum wapi_route_target_e
{ {
WAPI_ROUTE_TARGET_NET, /* The target is a network. */ WAPI_ROUTE_TARGET_NET, /* The target is a network. */
WAPI_ROUTE_TARGET_HOST /* The target is a host. */ WAPI_ROUTE_TARGET_HOST /* The target is a host. */
} wapi_route_target_t; };
/* ESSID flags. */ /* ESSID flags. */
typedef enum enum wapi_essid_flag_e
{ {
WAPI_ESSID_ON, WAPI_ESSID_ON,
WAPI_ESSID_OFF WAPI_ESSID_OFF
} wapi_essid_flag_t; };
/* Supported operation modes. */ /* Supported operation modes. */
typedef enum enum wapi_mode_e
{ {
WAPI_MODE_AUTO = IW_MODE_AUTO, /* Driver decides. */ WAPI_MODE_AUTO = IW_MODE_AUTO, /* Driver decides. */
WAPI_MODE_ADHOC = IW_MODE_ADHOC, /* Single cell network. */ WAPI_MODE_ADHOC = IW_MODE_ADHOC, /* Single cell network. */
@ -101,7 +132,7 @@ typedef enum
WAPI_MODE_SECOND = IW_MODE_SECOND, /* Secondary master/repeater, backup. */ WAPI_MODE_SECOND = IW_MODE_SECOND, /* Secondary master/repeater, backup. */
WAPI_MODE_MONITOR = IW_MODE_MONITOR, /* Passive monitor, listen only. */ WAPI_MODE_MONITOR = IW_MODE_MONITOR, /* Passive monitor, listen only. */
WAPI_MODE_MESH = IW_MODE_MESH /* Mesh (IEEE 802.11s) network */ WAPI_MODE_MESH = IW_MODE_MESH /* Mesh (IEEE 802.11s) network */
} wapi_mode_t; };
/* Bitrate flags. /* Bitrate flags.
* *
@ -109,51 +140,51 @@ typedef enum
* (IW_BITRATE_BROADCAST) bitrate flags are not supported. * (IW_BITRATE_BROADCAST) bitrate flags are not supported.
*/ */
typedef enum enum wapi_bitrate_flag_e
{ {
WAPI_BITRATE_AUTO, WAPI_BITRATE_AUTO,
WAPI_BITRATE_FIXED WAPI_BITRATE_FIXED
} wapi_bitrate_flag_t; };
/* Transmit power (txpower) flags. */ /* Transmit power (txpower) flags. */
typedef enum enum wapi_txpower_flag_e
{ {
WAPI_TXPOWER_DBM, /* Value is in dBm. */ WAPI_TXPOWER_DBM, /* Value is in dBm. */
WAPI_TXPOWER_MWATT, /* Value is in mW. */ WAPI_TXPOWER_MWATT, /* Value is in mW. */
WAPI_TXPOWER_RELATIVE /* Value is in arbitrary units. */ WAPI_TXPOWER_RELATIVE /* Value is in arbitrary units. */
} wapi_txpower_flag_t; };
/* Linked list container for strings. */ /* Linked list container for strings. */
typedef struct wapi_string_t struct wapi_string_s
{ {
FAR struct wapi_string_t *next; FAR struct wapi_string_s *next;
FAR char *data; FAR char *data;
} wapi_string_t; };
/* Linked list container for scan results. */ /* Linked list container for scan results. */
typedef struct wapi_scan_info_t struct wapi_scan_info_s
{ {
FAR struct wapi_scan_info_t *next; FAR struct wapi_scan_info_s *next;
struct ether_addr ap; struct ether_addr ap;
int has_essid; int has_essid;
char essid[WAPI_ESSID_MAX_SIZE + 1]; char essid[WAPI_ESSID_MAX_SIZE + 1];
wapi_essid_flag_t essid_flag; enum wapi_essid_flag_e essid_flag;
int has_freq; int has_freq;
double freq; double freq;
int has_mode; int has_mode;
wapi_mode_t mode; enum wapi_mode_e mode;
int has_bitrate; int has_bitrate;
int bitrate; int bitrate;
} wapi_scan_info_t; };
/* Linked list container for routing table rows. */ /* Linked list container for routing table rows. */
typedef struct wapi_route_info_t struct wapi_route_info_s
{ {
FAR struct wapi_route_info_t *next; FAR struct wapi_route_info_s *next;
FAR char *ifname; FAR char *ifname;
struct in_addr dest; struct in_addr dest;
struct in_addr gw; struct in_addr gw;
@ -166,22 +197,63 @@ typedef struct wapi_route_info_t
unsigned int mtu; unsigned int mtu;
unsigned int window; unsigned int window;
unsigned int irtt; unsigned int irtt;
} wapi_route_info_t; };
/* A generic linked list container. For functions taking wapi_list_t type of /* A generic linked list container. For functions taking struct wapi_list_s
* argument, caller is resposible for releasing allocated memory. * type of argument, caller is resposible for releasing allocated memory.
*/ */
struct wapi_list_t struct wapi_list_s
{ {
union wapi_list_head_t union wapi_list_head_t
{ {
FAR wapi_string_t *string; FAR struct wapi_string_s *string;
FAR wapi_scan_info_t *scan; FAR struct wapi_scan_info_s *scan;
FAR wapi_route_info_t *route; FAR struct wapi_route_info_s *route;
} head; } head;
}; };
/* WPA **********************************************************************/
enum wpa_alg_e
{
WPA_ALG_NONE = 0,
WPA_ALG_WEP,
WPA_ALG_TKIP,
WPA_ALG_CCMP,
WPA_ALG_IGTK,
WPA_ALG_PMK,
WPA_ALG_GCMP,
WPA_ALG_SMS4,
WPA_ALG_KRK,
WPA_ALG_GCMP_256,
WPA_ALG_CCMP_256,
WPA_ALG_BIP_GMAC_128,
WPA_ALG_BIP_GMAC_256,
WPA_ALG_BIP_CMAC_256
};
/* This structure provides the wireless configuration to
* wpa_driver_wext_associate().
*/
struct wpa_wconfig_s
{
uint8_t sta_mode; /* Mode of operation, e.g. IW_MODE_INFRA */
uint8_t auth_wpa; /* IW_AUTH_WPA_VERSION values, e.g.
* IW_AUTH_WPA_VERSION_WPA2 */
uint8_t cipher_mode; /* IW_AUTH_PAIRWISE_CIPHER and
* IW_AUTH_GROUP_CIPHER values, e.g.,
* IW_AUTH_CIPHER_CCMP */
uint8_t alg; /* See enum wpa_alg_e above, e.g.
* WPA_ALG_CCMP */
uint8_t ssidlen; /* Length of the SSID */
uint8_t phraselen; /* Length of the passphrase */
FAR const char *ifname; /* E.g., "wlan0" */
FAR const uint8_t *ssid; /* E.g., "myApSSID" */
FAR const uint8_t *passphrase; /* E.g., "mySSIDpassphrase" */
};
/**************************************************************************** /****************************************************************************
* Public Data * Public Data
****************************************************************************/ ****************************************************************************/
@ -229,7 +301,7 @@ EXTERN FAR const char *g_wapi_txpower_flags[];
* *
****************************************************************************/ ****************************************************************************/
int wapi_get_ifup(int sock, const char *ifname, int *is_up); int wapi_get_ifup(int sock, FAR const char *ifname, FAR int *is_up);
/**************************************************************************** /****************************************************************************
* Name: wapi_set_ifup * Name: wapi_set_ifup
@ -239,7 +311,7 @@ int wapi_get_ifup(int sock, const char *ifname, int *is_up);
* *
****************************************************************************/ ****************************************************************************/
int wapi_set_ifup(int sock, const char *ifname); int wapi_set_ifup(int sock, FAR const char *ifname);
/**************************************************************************** /****************************************************************************
* Name: wapi_set_ifdown * Name: wapi_set_ifdown
@ -249,7 +321,7 @@ int wapi_set_ifup(int sock, const char *ifname);
* *
****************************************************************************/ ****************************************************************************/
int wapi_set_ifdown(int sock, const char *ifname); int wapi_set_ifdown(int sock, FAR const char *ifname);
/**************************************************************************** /****************************************************************************
* Name: wapi_get_ip * Name: wapi_get_ip
@ -259,7 +331,7 @@ int wapi_set_ifdown(int sock, const char *ifname);
* *
****************************************************************************/ ****************************************************************************/
int wapi_get_ip(int sock, const char *ifname, struct in_addr *addr); int wapi_get_ip(int sock, FAR const char *ifname, struct in_addr *addr);
/**************************************************************************** /****************************************************************************
* Name: wapi_set_ip * Name: wapi_set_ip
@ -269,7 +341,8 @@ int wapi_get_ip(int sock, const char *ifname, struct in_addr *addr);
* *
****************************************************************************/ ****************************************************************************/
int wapi_set_ip(int sock, const char *ifname, const struct in_addr *addr); int wapi_set_ip(int sock, FAR const char *ifname,
FAR const struct in_addr *addr);
/**************************************************************************** /****************************************************************************
* Name: wapi_get_netmask * Name: wapi_get_netmask
@ -279,7 +352,8 @@ int wapi_set_ip(int sock, const char *ifname, const struct in_addr *addr);
* *
****************************************************************************/ ****************************************************************************/
int wapi_get_netmask(int sock, const char *ifname, struct in_addr *addr); int wapi_get_netmask(int sock, FAR const char *ifname,
FAR struct in_addr *addr);
/**************************************************************************** /****************************************************************************
* Name: wapi_set_netmask * Name: wapi_set_netmask
@ -289,7 +363,8 @@ int wapi_get_netmask(int sock, const char *ifname, struct in_addr *addr);
* *
****************************************************************************/ ****************************************************************************/
int wapi_set_netmask(int sock, const char *ifname, const struct in_addr *addr); int wapi_set_netmask(int sock, FAR const char *ifname,
FAR const struct in_addr *addr);
/**************************************************************************** /****************************************************************************
* Name: wapi_add_route_gw * Name: wapi_add_route_gw
@ -300,7 +375,7 @@ int wapi_set_netmask(int sock, const char *ifname, const struct in_addr *addr);
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_ROUTE #ifdef CONFIG_NET_ROUTE
int wapi_add_route_gw(int sock, wapi_route_target_t targettype, int wapi_add_route_gw(int sock, enum wapi_route_target_e targettype,
FAR const struct in_addr *target, FAR const struct in_addr *target,
FAR const struct in_addr *netmask, FAR const struct in_addr *netmask,
FAR const struct in_addr *gw); FAR const struct in_addr *gw);
@ -315,7 +390,7 @@ int wapi_add_route_gw(int sock, wapi_route_target_t targettype,
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_ROUTE #ifdef CONFIG_NET_ROUTE
int wapi_del_route_gw(int sock, wapi_route_target_t targettype, int wapi_del_route_gw(int sock, enum wapi_route_target_e targettype,
FAR const struct in_addr *target, FAR const struct in_addr *target,
FAR const struct in_addr *netmask, FAR const struct in_addr *netmask,
FAR const struct in_addr *gw); FAR const struct in_addr *gw);
@ -330,7 +405,7 @@ int wapi_del_route_gw(int sock, wapi_route_target_t targettype,
****************************************************************************/ ****************************************************************************/
int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq, int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq,
FAR wapi_freq_flag_t *flag); FAR enum wapi_freq_flag_e *flag);
/**************************************************************************** /****************************************************************************
* Name: wapi_set_freq * Name: wapi_set_freq
@ -341,7 +416,7 @@ int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq,
****************************************************************************/ ****************************************************************************/
int wapi_set_freq(int sock, FAR const char *ifname, double freq, int wapi_set_freq(int sock, FAR const char *ifname, double freq,
wapi_freq_flag_t flag); enum wapi_freq_flag_e flag);
/**************************************************************************** /****************************************************************************
* Name: wapi_freq2chan * Name: wapi_freq2chan
@ -384,7 +459,7 @@ int wapi_chan2freq(int sock, FAR const char *ifname, int chan,
****************************************************************************/ ****************************************************************************/
int wapi_get_essid(int sock, FAR const char *ifname, FAR char *essid, int wapi_get_essid(int sock, FAR const char *ifname, FAR char *essid,
FAR wapi_essid_flag_t *flag); FAR enum wapi_essid_flag_e *flag);
/**************************************************************************** /****************************************************************************
* Name: wapi_set_essid * Name: wapi_set_essid
@ -397,7 +472,7 @@ int wapi_get_essid(int sock, FAR const char *ifname, FAR char *essid,
****************************************************************************/ ****************************************************************************/
int wapi_set_essid(int sock, FAR const char *ifname, FAR const char *essid, int wapi_set_essid(int sock, FAR const char *ifname, FAR const char *essid,
wapi_essid_flag_t flag); enum wapi_essid_flag_e flag);
/**************************************************************************** /****************************************************************************
* Name: wapi_get_mode * Name: wapi_get_mode
@ -407,7 +482,7 @@ int wapi_set_essid(int sock, FAR const char *ifname, FAR const char *essid,
* *
****************************************************************************/ ****************************************************************************/
int wapi_get_mode(int sock, FAR const char *ifname, FAR wapi_mode_t *mode); int wapi_get_mode(int sock, FAR const char *ifname, FAR enum wapi_mode_e *mode);
/**************************************************************************** /****************************************************************************
* Name: wapi_set_mode * Name: wapi_set_mode
@ -417,7 +492,7 @@ int wapi_get_mode(int sock, FAR const char *ifname, FAR wapi_mode_t *mode);
* *
****************************************************************************/ ****************************************************************************/
int wapi_set_mode(int sock, FAR const char *ifname, wapi_mode_t mode); int wapi_set_mode(int sock, FAR const char *ifname, enum wapi_mode_e mode);
/**************************************************************************** /****************************************************************************
* Name: wapi_make_broad_ether * Name: wapi_make_broad_ether
@ -473,7 +548,7 @@ int wapi_set_ap(int sock, FAR const char *ifname,
****************************************************************************/ ****************************************************************************/
int wapi_get_bitrate(int sock, FAR const char *ifname, int wapi_get_bitrate(int sock, FAR const char *ifname,
FAR int *bitrate, FAR wapi_bitrate_flag_t *flag); FAR int *bitrate, FAR enum wapi_bitrate_flag_e *flag);
/**************************************************************************** /****************************************************************************
* Name: wapi_set_bitrate * Name: wapi_set_bitrate
@ -484,7 +559,7 @@ int wapi_get_bitrate(int sock, FAR const char *ifname,
****************************************************************************/ ****************************************************************************/
int wapi_set_bitrate(int sock, FAR const char *ifname, int bitrate, int wapi_set_bitrate(int sock, FAR const char *ifname, int bitrate,
wapi_bitrate_flag_t flag); enum wapi_bitrate_flag_e flag);
/**************************************************************************** /****************************************************************************
* Name: wapi_dbm2mwatt * Name: wapi_dbm2mwatt
@ -515,7 +590,7 @@ int wapi_mwatt2dbm(int mwatt);
****************************************************************************/ ****************************************************************************/
int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power, int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power,
FAR wapi_txpower_flag_t *flag); FAR enum wapi_txpower_flag_e *flag);
/**************************************************************************** /****************************************************************************
* Name: wapi_set_txpower * Name: wapi_set_txpower
@ -526,7 +601,7 @@ int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power,
****************************************************************************/ ****************************************************************************/
int wapi_set_txpower(int sock, FAR const char *ifname, int power, int wapi_set_txpower(int sock, FAR const char *ifname, int power,
wapi_txpower_flag_t flag); enum wapi_txpower_flag_e flag);
/**************************************************************************** /****************************************************************************
* Name: wapi_make_socket * Name: wapi_make_socket
@ -550,7 +625,7 @@ int wapi_make_socket(void);
* *
****************************************************************************/ ****************************************************************************/
int wapi_scan_init(int sock, const char *ifname); int wapi_scan_init(int sock, FAR const char *ifname);
/**************************************************************************** /****************************************************************************
* Name: wapi_scan_stat * Name: wapi_scan_stat
@ -572,11 +647,93 @@ int wapi_scan_stat(int sock, FAR const char *ifname);
* Collects the results of a scan process. * Collects the results of a scan process.
* *
* Input Parameters: * Input Parameters:
* aps - Pushes collected wapi_scan_info_t into this list. * aps - Pushes collected struct wapi_scan_info_s into this list.
* *
****************************************************************************/ ****************************************************************************/
int wapi_scan_coll(int sock, FAR const char *ifname, FAR wapi_list_t *aps); int wapi_scan_coll(int sock, FAR const char *ifname, FAR struct wapi_list_s *aps);
/************************************************************************************
* Name: wpa_driver_wext_set_ssid
*
* Description:
* Set SSID, SIOCSIWESSID
*
* Input Parameters:
* sockfd - Opened network socket
* ifname - Interface name
* ssid - SSID
* ssid_len - Length of SSID (0..32)
*
* Returned Value:
* 0 on success, -1 on failure
*
************************************************************************************/
int wpa_driver_wext_set_ssid(int sockfd, FAR const char *ifname,
FAR const uint8_t *ssid, size_t ssid_len);
/************************************************************************************
* Name: wpa_driver_wext_set_mode
*
* Description:
* Set wireless mode (infra/adhoc), SIOCSIWMODE
*
* Input Parameters:
* sockfd - Opened network socket
* ifname - Interface name
* mode - 0 = infra/BSS (associate with an AP), 1 = adhoc/IBSS
*
* Returned Value:
* 0 on success, -1 on failure
*
************************************************************************************/
int wpa_driver_wext_set_mode(int sockfd, FAR const char *ifname, int mode);
/************************************************************************************
* Name: wpa_driver_wext_set_key_ext
*
* Description:
*
* Input Parameters:
* sockfd - Opened network socket
* ifname - Interface name
*
* Returned Value:
*
************************************************************************************/
int wpa_driver_wext_set_key_ext(int sockfd, FAR const char *ifname, enum wpa_alg_e alg,
FAR const uint8_t *key, size_t key_len);
/************************************************************************************
* Name: wpa_driver_wext_associate
*
* Description:
*
* Input Parameters:
* wconfig - Describes the wireless configuration.
*
* Returned Value:
*
************************************************************************************/
int wpa_driver_wext_associate(FAR struct wpa_wconfig_s *wconfig);
/************************************************************************************
* Name: wpa_driver_wext_set_auth_param
*
* Description:
*
* Input Parameters:
*
* Returned Value:
*
************************************************************************************/
int wpa_driver_wext_set_auth_param(int sockfd, FAR const char *ifname,
int idx, uint32_t value);
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus

@ -1465,6 +1465,56 @@ config NSH_PANID
---help--- ---help---
Select the PAN ID to join upon initialization. Select the PAN ID to join upon initialization.
menu "WAPI Configuration"
depends on NET && WIRELESS_WAPI
config NSH_WAPI_STAMODE
int "Wireless mode of operation"
default 2
range 0 8
---help---
Mode of operation. See the IW_MODE_* definitions in
include/nuttx/wireless/wireless. The default value corresponds to
IW_MODE_INFRA
config NSH_WAPI_AUTHWPA
hex "IW_AUTH_WPA_VERSION value"
default 0x00000004
range 0x00000001 0x00000004
---help---
IW_AUTH_WPA_VERSION values. See the IW_AUTH_WPA_VERSION_* definitions
in include/nuttx/wireless/wireless. The default value corresponds to
IW_AUTH_WPA_VERSION_WPA2. NOTE that this is a bit-encoded field. The
only valid values are 0x00000001, 0x00000002, and 0x00000004
config NSH_WAPI_CIPHERMODE
hex " IW_AUTH_PAIRWISE_CIPHER and IW_AUTH_GROUP_CIPHER values"
default 0x00000008
range 0x00000001 0x00000010
---help---
IW_AUTH_PAIRWISE_CIPHER and IW_AUTH_GROUP_CIPHER values. See the
IW_AUTH_CIPHER_* definitions in include/nuttx/wireless/wireless.
The default value corresponds to IW_AUTH_CIPHER_CCMP. NOTE that
this is a bit-encoded field. The only valid values are 0x00000001,
0x00000002,0x00000004, ... 0x00000010
config NSH_WAPI_ALG;
int "Algorithm"
default 3
range 0 13
---help---
Algorithm. See enum wpa_alg_e in apps/include/wireless/wapi.h. The
default corresponds to WPA_ALG_CCMP.
config NSH_WAPI_SSID
string "SSID"
default "myApSSID"
config NSH_WAPI_PASSPHRASE
string "Passprhase"
default "mySSIDpassphrase"
endmenu # WAPI Configuration
endif # NSH_NETINIT endif # NSH_NETINIT
config NSH_MAX_ROUNDTRIP config NSH_MAX_ROUNDTRIP

@ -74,6 +74,9 @@ endif
ifeq ($(CONFIG_NET),y) ifeq ($(CONFIG_NET),y)
CSRCS += nsh_netinit.c nsh_netcmds.c CSRCS += nsh_netinit.c nsh_netcmds.c
ifeq ($(CONFIG_WIRELESS_WAPI),y)
CSRCS += nsh_associate.c
endif
ifeq ($(CONFIG_NET_ROUTE),y) ifeq ($(CONFIG_NET_ROUTE),y)
CSRCS += nsh_routecmds.c CSRCS += nsh_routecmds.c
endif endif

@ -943,9 +943,9 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
FAR char **argv, FAR const char *redirfile, int oflags); FAR char **argv, FAR const char *redirfile, int oflags);
#endif #endif
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON)
/* Working directory support */ /* Working directory support */
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON)
FAR const char *nsh_getcwd(void); FAR const char *nsh_getcwd(void);
FAR char *nsh_getfullpath(FAR struct nsh_vtbl_s *vtbl, FAR char *nsh_getfullpath(FAR struct nsh_vtbl_s *vtbl,
FAR const char *relpath); FAR const char *relpath);
@ -957,9 +957,15 @@ void nsh_freefullpath(FAR char *fullpath);
void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg, void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg,
const uint8_t *buffer, ssize_t nbytes); const uint8_t *buffer, ssize_t nbytes);
/* USB debug support */ #ifdef CONFIG_WIRELESS_WAPI
/* Wireless */
int nsh_associate(FAR const char *ifname);
#endif
#ifdef CONFIG_NSH_USBDEV_TRACE #ifdef CONFIG_NSH_USBDEV_TRACE
/* USB debug support */
void nsh_usbtrace(void); void nsh_usbtrace(void);
#endif #endif

@ -1,14 +1,8 @@
/**************************************************************************** /****************************************************************************
* apps/include/wireless/wapi.h * apps/nshlib/nsh_associate.c
* WPA Supplicant - wext exported functions
* *
* Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Simon Piriou <spiriou31@gmail.com> * Author: Gregory Nutt <gnutt@nuttx.org>
* Gregory Nutt <gnutt@nuttx.org>
*
* Adapted to NuttX from driver_ext.h
*
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -37,68 +31,57 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
************************************************************************************/ ****************************************************************************/
#ifndef __APPS_INCLUDE_WIRELESS_WEXT_H /****************************************************************************
#define __APPS_INCLUDE_WIRELESS_WEXT_H
/************************************************************************************
* Included Files * Included Files
************************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h>
/************************************************************************************ #include <unistd.h>
* Pre-processor Definitions #include <string.h>
************************************************************************************/
#ifdef CONFIG_NET_UDP #include <nuttx/wireless/wireless.h>
# define NETLIB_SOCK_IOCTL SOCK_DGRAM
#else
# define NETLIB_SOCK_IOCTL SOCK_STREAM
#endif
#define SSID_MAX_LEN 32 #include "wireless/wapi.h"
#define PF_INETX PF_INET #include "nsh.h"
/************************************************************************************ #ifdef CONFIG_WIRELESS_WAPI
* Public Types
************************************************************************************/
enum wpa_alg /****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_associate
****************************************************************************/
int nsh_associate(FAR const char *ifname)
{ {
WPA_ALG_NONE, static const char ssid[] = CONFIG_NSH_WAPI_SSID;
WPA_ALG_WEP, static const char passphrase[] = CONFIG_NSH_WAPI_PASSPHRASE;
WPA_ALG_TKIP, struct wpa_wconfig_s wconfig;
WPA_ALG_CCMP, int ret;
WPA_ALG_IGTK,
WPA_ALG_PMK,
WPA_ALG_GCMP,
WPA_ALG_SMS4,
WPA_ALG_KRK,
WPA_ALG_GCMP_256,
WPA_ALG_CCMP_256,
WPA_ALG_BIP_GMAC_128,
WPA_ALG_BIP_GMAC_256,
WPA_ALG_BIP_CMAC_256
};
/************************************************************************************ /* Set up the network configuration */
* Public Function Prototypes
************************************************************************************/
int wpa_driver_wext_set_ssid(int sockfd, FAR char *ifname, wconfig.sta_mode = CONFIG_NSH_WAPI_STAMODE;
FAR const uint8_t *ssid, size_t ssid_len); wconfig.auth_wpa = CONFIG_NSH_WAPI_AUTHWPA;
wconfig.cipher_mode = CONFIG_NSH_WAPI_CIPHERMODE;
wconfig.ifname = ifname;
wconfig.ssid = (FAR const uint8_t *)ssid;
wconfig.passphrase = (FAR const uint8_t *)passphrase;
int wpa_driver_wext_set_mode(int sockfd, FAR char *ifname, int mode); wconfig.ssidlen = strlen(ssid);
wconfig.phraselen = strlen(passphrase);
int wpa_driver_wext_set_key_ext(int sockfd, FAR char *ifname, enum wpa_alg alg, /* Associate */
FAR const uint8_t *key, size_t key_len);
int wpa_driver_wext_associate(void); sleep(2);
ret = wpa_driver_wext_associate(&wconfig);
sleep(2);
return ret;
}
int wpa_driver_wext_set_auth_param(int sockfd, FAR char *ifname, #endif /* CONFIG_WIRELESS_WAPI */
int idx, uint32_t value);
#endif /* __APPS_INCLUDE_WIRELESS_WEXT_H */

@ -80,10 +80,6 @@
# include "netutils/ntpclient.h" # include "netutils/ntpclient.h"
#endif #endif
#ifdef CONFIG_WIRELESS_WEXT
# include "wireless/wext.h"
#endif
#include "nsh.h" #include "nsh.h"
#ifdef CONFIG_NSH_NETINIT #ifdef CONFIG_NSH_NETINIT
@ -367,12 +363,10 @@ static void nsh_netinit_configure(void)
netlib_getmacaddr(NET_DEVNAME, mac); netlib_getmacaddr(NET_DEVNAME, mac);
#ifdef CONFIG_WIRELESS_WEXT #ifdef CONFIG_WIRELESS_WAPI
/* Associate the wlan */ /* Associate the wlan */
sleep(2); nsh_associate(NET_DEVNAME);
wpa_driver_wext_associate();
sleep(2);
#endif #endif
/* Set up the DHCPC modules */ /* Set up the DHCPC modules */

@ -35,7 +35,7 @@
ifeq ($(CONFIG_WIRELESS_WAPI),y) ifeq ($(CONFIG_WIRELESS_WAPI),y)
CSRCS = network.c util.c wireless.c CSRCS = network.c util.c wireless.c driver_wext.c
ifeq ($(CONFIG_WIRELESS_WAPI_CMDTOOL),y) ifeq ($(CONFIG_WIRELESS_WAPI_CMDTOOL),y)
MAINSRC = wapi.c MAINSRC = wapi.c

@ -1,12 +1,13 @@
/************************************************************************************ /************************************************************************************
* apps/include/graphics/wext.c * apps/wireless/wapi/src/driver_wext.c
* Driver interaction with generic Wireless Extensions * Driver interaction with generic Wireless Extensions
* *
* Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Simon Piriou <spiriou31@gmail.com> * Author: Simon Piriou <spiriou31@gmail.com>
* Gregory Nutt <gnutt@nuttx.org> * Gregory Nutt <gnutt@nuttx.org>
* *
* Adapted to NuttX from driver_ext.c * Adapted for NuttX from the driver_ext.c of WPA suplicant written originally
* by Jouni Malinen
* *
* Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi> * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
* *
@ -58,53 +59,16 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <debug.h> #include <debug.h>
#include "wireless/wext.h" #include "wireless/wapi.h"
/************************************************************************************ /************************************************************************************
* Public Functions * Public Functions
************************************************************************************/ ************************************************************************************/
/************************************************************************************
* Name: wpa_driver_wext_set_auth_param
*
* Description:
*
* Input Parameters:
*
* Returned Value:
*
************************************************************************************/
int wpa_driver_wext_set_auth_param(int sockfd, FAR char *ifname, int idx,
uint32_t value)
{
struct iwreq iwr;
int errcode;
int ret = 0;
memset(&iwr, 0, sizeof(iwr));
strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
iwr.u.param.flags = idx & IW_AUTH_INDEX;
iwr.u.param.value = value;
if (ioctl(sockfd, SIOCSIWAUTH, (unsigned long)&iwr) < 0)
{
errcode = errno;
if (errcode != EOPNOTSUPP)
{
nerr("ERROR: SIOCSIWAUTH(param %d value 0x%x) failed: %d)",
idx, value, errcode);
}
ret = errcode == EOPNOTSUPP ? -2 : -1;
}
return ret;
}
/************************************************************************************ /************************************************************************************
* Name: wpa_driver_wext_set_ssid * Name: wpa_driver_wext_set_ssid
* *
@ -122,14 +86,16 @@ int wpa_driver_wext_set_auth_param(int sockfd, FAR char *ifname, int idx,
* *
************************************************************************************/ ************************************************************************************/
int wpa_driver_wext_set_ssid(int sockfd, FAR char *ifname, FAR const uint8_t *ssid, int wpa_driver_wext_set_ssid(int sockfd, FAR const char *ifname,
size_t ssid_len) FAR const uint8_t *ssid, size_t ssid_len)
{ {
struct iwreq iwr; struct iwreq iwr;
int ret = 0; int ret = 0;
char buf[33]; char buf[33];
if (ssid_len > SSID_MAX_LEN) DEBUGASSERT(ifname != NULL && ssid != NULL && ssid_len > 0);
if (ssid_len > WAPI_ESSID_MAX_SIZE)
{ {
return -1; return -1;
} }
@ -155,6 +121,45 @@ int wpa_driver_wext_set_ssid(int sockfd, FAR char *ifname, FAR const uint8_t *s
return ret; return ret;
} }
/************************************************************************************
* Name: wpa_driver_wext_set_mode
*
* Description:
* Set wireless mode (infra/adhoc), SIOCSIWMODE
*
* Input Parameters:
* sockfd - Opened network socket
* ifname - Interface name
* mode - 0 = infra/BSS (associate with an AP), 1 = adhoc/IBSS
*
* Returned Value:
* 0 on success, -1 on failure
*
************************************************************************************/
int wpa_driver_wext_set_mode(int sockfd, FAR const char *ifname, int mode)
{
struct iwreq iwr;
int ret = -1;
DEBUGASSERT(ifname != NULL);
memset(&iwr, 0, sizeof(iwr));
strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
iwr.u.mode = mode;
if (ioctl(sockfd, SIOCSIWMODE, (unsigned long)&iwr) == 0)
{
ret = 0;
goto done;
}
nerr("ERROR: ioctl[SIOCSIWMODE]: %d", errno);
done:
return ret;
}
/************************************************************************************ /************************************************************************************
* Name: wpa_driver_wext_set_key_ext * Name: wpa_driver_wext_set_key_ext
* *
@ -168,13 +173,15 @@ int wpa_driver_wext_set_ssid(int sockfd, FAR char *ifname, FAR const uint8_t *s
* *
************************************************************************************/ ************************************************************************************/
int wpa_driver_wext_set_key_ext(int sockfd, FAR char *ifname, enum wpa_alg alg, int wpa_driver_wext_set_key_ext(int sockfd, FAR const char *ifname, enum wpa_alg_e alg,
FAR const uint8_t *key, size_t key_len) FAR const uint8_t *key, size_t key_len)
{ {
struct iwreq iwr; struct iwreq iwr;
int ret = 0; int ret = 0;
struct iw_encode_ext *ext; struct iw_encode_ext *ext;
DEBUGASSERT(ifname != NULL && key != NULL && key_len > 0);
ext = malloc(sizeof(*ext) + key_len); ext = malloc(sizeof(*ext) + key_len);
if (ext == NULL) if (ext == NULL)
{ {
@ -233,42 +240,29 @@ int wpa_driver_wext_set_key_ext(int sockfd, FAR char *ifname, enum wpa_alg alg,
* Description: * Description:
* *
* Input Parameters: * Input Parameters:
* wconfig - Describes the wireless configuration.
* *
* Returned Value: * Returned Value:
* *
************************************************************************************/ ************************************************************************************/
int wpa_driver_wext_associate(void) int wpa_driver_wext_associate(FAR struct wpa_wconfig_s *wconfig)
{ {
int ret;
int sockfd;
struct iwreq req; struct iwreq req;
int sockfd;
int ret;
int sta_mode = IW_MODE_INFRA; DEBUGASSERT(wconfig != NULL);
// IW_AUTH_WPA_VERSION_DISABLED ninfo("sta_mode=%u auth_wpa=%08x cipher_mode=%08x\n",
// IW_AUTH_WPA_VERSION_WPA wconfig->sta_mode, wconfig->auth_wpa, wconfig->cipher_mode);
ninfo("ifname=%s ssid[%u]=%s passphrase[%u]=%s\n",
int auth_wpa = IW_AUTH_WPA_VERSION_WPA2; wconfig->ifname, wconfig->ssidlen, wconfig->ssid, wconfig->phraselen,
wconfig->passphrase);
// IW_AUTH_CIPHER_NONE
// IW_AUTH_CIPHER_WEP40
// IW_AUTH_CIPHER_TKIP
// IW_AUTH_CIPHER_WEP104
int cipher_mode = IW_AUTH_CIPHER_CCMP;
enum wpa_alg alg = WPA_ALG_CCMP;
char ifname[] = "wlan0";
const uint8_t ssid[] = "myApSSID";
const uint8_t passphrase[] = "mySSIDpassphrase";
ninfo("Entry\n");
/* Get a socket (only so that we get access to the INET subsystem) */ /* Get a socket (only so that we get access to the INET subsystem) */
sockfd = socket(PF_INETX, NETLIB_SOCK_IOCTL, 0); sockfd = socket(PF_INETX, SOCK_WAPI, 0);
if (sockfd < 0) if (sockfd < 0)
{ {
return sockfd; return sockfd;
@ -276,44 +270,47 @@ int wpa_driver_wext_associate(void)
/* Put the driver name into the request */ /* Put the driver name into the request */
strncpy(req.ifr_name, ifname, IFNAMSIZ); strncpy(req.ifr_name, wconfig->ifname, IFNAMSIZ);
if (wpa_driver_wext_set_mode(sockfd, ifname, sta_mode) < 0) ret = wpa_driver_wext_set_mode(sockfd, wconfig->ifname, wconfig->sta_mode);
if (ret < 0)
{ {
nerr("Fail set sta mode\n"); nerr("ERROR: Fail set sta mode: %d\n", ret);
goto close_socket;
}
ret = wpa_driver_wext_set_auth_param(sockfd, wconfig->ifname,
IW_AUTH_WPA_VERSION,
wconfig->auth_wpa);
if (ret < 0)
{
nerr("ERROR: Fail set wpa version: %d\n", ret);
goto close_socket;
}
ret = wpa_driver_wext_set_auth_param(sockfd, wconfig->ifname,
IW_AUTH_CIPHER_PAIRWISE,
wconfig->cipher_mode);
if (ret < 0)
{
nerr("ERROR: Fail set cipher mode: %d\n", ret);
goto close_socket;
}
ret = wpa_driver_wext_set_key_ext(sockfd, wconfig->ifname, wconfig->alg,
wconfig->passphrase, wconfig->phraselen);
if (ret < 0)
{
nerr("ERROR: Fail set key: %d\n", ret);
ret = -1; ret = -1;
goto close_socket; goto close_socket;
} }
if (wpa_driver_wext_set_auth_param(sockfd, ifname, IW_AUTH_WPA_VERSION, ret = wpa_driver_wext_set_ssid(sockfd, wconfig->ifname, wconfig->ssid,
auth_wpa) < 0) wconfig->ssidlen);
if (ret < 0)
{ {
nerr("Fail set wpa version\n"); nerr("ERROR: Fail set ssid: %d\n", ret);
ret = -1;
goto close_socket;
}
if (wpa_driver_wext_set_auth_param(sockfd, ifname,
IW_AUTH_CIPHER_PAIRWISE, cipher_mode) < 0)
{
nerr("Fail set cipher mode\n");
ret = -1;
goto close_socket;
}
if (wpa_driver_wext_set_key_ext(sockfd, ifname, alg, passphrase,
sizeof(passphrase)-1))
{
nerr("Fail set key\n");
ret = -1;
goto close_socket;
}
if (wpa_driver_wext_set_ssid(sockfd, ifname, ssid, sizeof(ssid)-1) < 0)
{
nerr("Fail set ssid\n");
ret = -1;
goto close_socket;
} }
close_socket: close_socket:
@ -322,38 +319,42 @@ close_socket:
} }
/************************************************************************************ /************************************************************************************
* Name: wpa_driver_wext_set_mode * Name: wpa_driver_wext_set_auth_param
* *
* Description: * Description:
* Set wireless mode (infra/adhoc), SIOCSIWMODE
* *
* Input Parameters: * Input Parameters:
* sockfd - Opened network socket
* ifname - Interface name
* mode - 0 = infra/BSS (associate with an AP), 1 = adhoc/IBSS
* *
* Returned Value: * Returned Value:
* 0 on success, -1 on failure
* *
************************************************************************************/ ************************************************************************************/
int wpa_driver_wext_set_mode(int sockfd, FAR char *ifname, int mode) int wpa_driver_wext_set_auth_param(int sockfd, FAR const char *ifname, int idx,
uint32_t value)
{ {
struct iwreq iwr; struct iwreq iwr;
int ret = -1; int errcode;
int ret = 0;
DEBUGASSERT(ifname != NULL);
memset(&iwr, 0, sizeof(iwr)); memset(&iwr, 0, sizeof(iwr));
strncpy(iwr.ifr_name, ifname, IFNAMSIZ); strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
iwr.u.mode = mode; iwr.u.param.flags = idx & IW_AUTH_INDEX;
iwr.u.param.value = value;
if (ioctl(sockfd, SIOCSIWMODE, (unsigned long)&iwr) == 0) if (ioctl(sockfd, SIOCSIWAUTH, (unsigned long)&iwr) < 0)
{ {
ret = 0; errcode = errno;
goto done; if (errcode != EOPNOTSUPP)
{
nerr("ERROR: SIOCSIWAUTH(param %d value 0x%x) failed: %d)",
idx, value, errcode);
}
ret = errcode == EOPNOTSUPP ? -2 : -1;
} }
nerr("ERROR: ioctl[SIOCSIWMODE]: %d", errno);
done:
return ret; return ret;
} }

@ -104,7 +104,7 @@ static int wapi_set_addr(int sock, FAR const char *ifname, int cmd,
#ifdef CONFIG_NET_ROUTE #ifdef CONFIG_NET_ROUTE
static int wapi_act_route_gw(int sock, int act, static int wapi_act_route_gw(int sock, int act,
wapi_route_target_t targettype, enum wapi_route_target_e targettype,
FAR const struct in_addr *target, FAR const struct in_addr *target,
FAR const struct in_addr *netmask, FAR const struct in_addr *netmask,
FAR const struct in_addr *gw) FAR const struct in_addr *gw)
@ -325,7 +325,7 @@ int wapi_set_netmask(int sock, FAR const char *ifname,
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_ROUTE #ifdef CONFIG_NET_ROUTE
int wapi_add_route_gw(int sock, wapi_route_target_t targettype, int wapi_add_route_gw(int sock, enum wapi_route_target_e targettype,
FAR const struct in_addr *target, FAR const struct in_addr *target,
FAR const struct in_addr *netmask, FAR const struct in_addr *netmask,
FAR const struct in_addr *gw) FAR const struct in_addr *gw)
@ -343,7 +343,7 @@ int wapi_add_route_gw(int sock, wapi_route_target_t targettype,
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_ROUTE #ifdef CONFIG_NET_ROUTE
int wapi_del_route_gw(int sock, wapi_route_target_t targettype, int wapi_del_route_gw(int sock, enum wapi_route_target_e targettype,
FAR const struct in_addr *target, FAR const struct in_addr *target,
FAR const struct in_addr *netmask, FAR const struct in_addr *netmask,
FAR const struct in_addr *gw) FAR const struct in_addr *gw)

@ -51,27 +51,6 @@
* Pre-processor Definitions * 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_WAPI SOCK_DGRAM
#else
# define SOCK_WAPI SOCK_STREAM
#endif
/* Size of the command buffer */ /* Size of the command buffer */
#define WAPI_IOCTL_COMMAND_NAMEBUFSIZ 24 #define WAPI_IOCTL_COMMAND_NAMEBUFSIZ 24

@ -227,20 +227,20 @@ static void wapi_show_cmd(int sock, FAR const char *ifname)
struct in_addr addr; struct in_addr addr;
double freq; double freq;
wapi_freq_flag_t freq_flag; enum wapi_freq_flag_e freq_flag;
char essid[WAPI_ESSID_MAX_SIZE + 1]; char essid[WAPI_ESSID_MAX_SIZE + 1];
wapi_essid_flag_t essid_flag; enum wapi_essid_flag_e essid_flag;
wapi_mode_t mode; enum wapi_mode_e mode;
struct ether_addr ap; struct ether_addr ap;
int bitrate; int bitrate;
wapi_bitrate_flag_t bitrate_flag; enum wapi_bitrate_flag_e bitrate_flag;
int txpower; int txpower;
wapi_txpower_flag_t txpower_flag; enum wapi_txpower_flag_e txpower_flag;
int ret; int ret;
@ -450,13 +450,13 @@ static void wapi_freq_cmd(int sock, FAR const char *ifname,
FAR const char *freqstr, FAR const char *flagstr) FAR const char *freqstr, FAR const char *flagstr)
{ {
double frequency; double frequency;
wapi_freq_flag_t freq_flag; enum wapi_freq_flag_e freq_flag;
int ret; int ret;
/* Convert input strings to values */ /* Convert input strings to values */
frequency = wapi_str2double(freqstr); frequency = wapi_str2double(freqstr);
freq_flag = (wapi_freq_flag_t)wapi_str2ndx(flagstr, g_wapi_freq_flags, freq_flag = (enum wapi_freq_flag_e)wapi_str2ndx(flagstr, g_wapi_freq_flags,
IW_FREQ_NFLAGS); IW_FREQ_NFLAGS);
/* Set the frequency */ /* Set the frequency */
@ -482,12 +482,12 @@ static void wapi_freq_cmd(int sock, FAR const char *ifname,
static void wapi_essid_cmd(int sock, FAR const char *ifname, static void wapi_essid_cmd(int sock, FAR const char *ifname,
FAR const char *essid, FAR const char *flagstr) FAR const char *essid, FAR const char *flagstr)
{ {
wapi_essid_flag_t essid_flag; enum wapi_essid_flag_e essid_flag;
int ret; int ret;
/* Convert input strings to values */ /* Convert input strings to values */
essid_flag = (wapi_essid_flag_t)wapi_str2ndx(flagstr, g_wapi_essid_flags, 2); essid_flag = (enum wapi_essid_flag_e)wapi_str2ndx(flagstr, g_wapi_essid_flags, 2);
/* Set the ESSID */ /* Set the ESSID */
@ -512,12 +512,12 @@ static void wapi_essid_cmd(int sock, FAR const char *ifname,
static void wapi_mode_cmd(int sock, FAR const char *ifname, static void wapi_mode_cmd(int sock, FAR const char *ifname,
FAR const char *modestr) FAR const char *modestr)
{ {
wapi_mode_t mode; enum wapi_mode_e mode;
int ret; int ret;
/* Convert input strings to values */ /* Convert input strings to values */
mode = (wapi_mode_t)wapi_str2ndx(modestr, g_wapi_modes, IW_MODE_NFLAGS); mode = (enum wapi_mode_e)wapi_str2ndx(modestr, g_wapi_modes, IW_MODE_NFLAGS);
/* Set operating mode */ /* Set operating mode */
@ -576,14 +576,14 @@ static void wapi_bitrate_cmd(int sock, FAR const char *ifname,
FAR const char *ratestr, FAR const char *flagstr) FAR const char *ratestr, FAR const char *flagstr)
{ {
wapi_bitrate_flag_t bitrate_flag; enum wapi_bitrate_flag_e bitrate_flag;
int bitrate; int bitrate;
int ret; int ret;
/* Convert input strings to values */ /* Convert input strings to values */
bitrate = wapi_str2int(ratestr); bitrate = wapi_str2int(ratestr);
bitrate_flag = (wapi_bitrate_flag_t) bitrate_flag = (enum wapi_bitrate_flag_e)
wapi_str2ndx(flagstr, g_wapi_bitrate_flags, 2); wapi_str2ndx(flagstr, g_wapi_bitrate_flags, 2);
/* Set bitrate */ /* Set bitrate */
@ -609,14 +609,14 @@ static void wapi_bitrate_cmd(int sock, FAR const char *ifname,
static void wapi_txpower_cmd(int sock, FAR const char *ifname, static void wapi_txpower_cmd(int sock, FAR const char *ifname,
FAR const char *pwrstr, FAR const char *flagstr) FAR const char *pwrstr, FAR const char *flagstr)
{ {
wapi_txpower_flag_t txpower_flag; enum wapi_txpower_flag_e txpower_flag;
int txpower; int txpower;
int ret; int ret;
/* Convert input strings to values */ /* Convert input strings to values */
txpower = wapi_str2int(pwrstr); txpower = wapi_str2int(pwrstr);
txpower_flag = (wapi_txpower_flag_t) txpower_flag = (enum wapi_txpower_flag_e)
wapi_str2ndx(flagstr, g_wapi_txpower_flags, IW_TXPOW_NFLAGS); wapi_str2ndx(flagstr, g_wapi_txpower_flags, IW_TXPOW_NFLAGS);
/* Set txpower */ /* Set txpower */
@ -643,8 +643,8 @@ static void wapi_scan_cmd(int sock, FAR const char *ifname)
{ {
int sleepdur = 1; int sleepdur = 1;
int sleeptries = 5; int sleeptries = 5;
wapi_list_t list; struct wapi_list_s list;
FAR wapi_scan_info_t *info; FAR struct wapi_scan_info_s *info;
int ret; int ret;
/* Start scan */ /* Start scan */
@ -670,7 +670,7 @@ static void wapi_scan_cmd(int sock, FAR const char *ifname)
/* Collect results */ /* Collect results */
bzero(&list, sizeof(wapi_list_t)); bzero(&list, sizeof(struct wapi_list_s));
ret = wapi_scan_coll(sock, ifname, &list); ret = wapi_scan_coll(sock, ifname, &list);
if (ret < 0) if (ret < 0)
{ {
@ -693,7 +693,7 @@ static void wapi_scan_cmd(int sock, FAR const char *ifname)
info = list.head.scan; info = list.head.scan;
while (info) while (info)
{ {
FAR wapi_scan_info_t *temp; FAR struct wapi_scan_info_s *temp;
temp = info->next; temp = info->next;
free(info); free(info);

@ -161,7 +161,7 @@ static inline void wapi_float2freq(double floatfreq, struct iw_freq *freq)
* *
****************************************************************************/ ****************************************************************************/
static int wapi_parse_mode(int iw_mode, FAR wapi_mode_t *wapi_mode) static int wapi_parse_mode(int iw_mode, FAR enum wapi_mode_e *wapi_mode)
{ {
switch (iw_mode) switch (iw_mode)
{ {
@ -234,9 +234,9 @@ return -ENOSYS;
* *
****************************************************************************/ ****************************************************************************/
static int wapi_scan_event(FAR struct iw_event *event, FAR wapi_list_t *list) static int wapi_scan_event(FAR struct iw_event *event, FAR struct wapi_list_s *list)
{ {
FAR wapi_scan_info_t *info; FAR struct wapi_scan_info_s *info;
/* Get current "wapi_info_t". */ /* Get current "wapi_info_t". */
@ -248,11 +248,11 @@ static int wapi_scan_event(FAR struct iw_event *event, FAR wapi_list_t *list)
{ {
case SIOCGIWAP: case SIOCGIWAP:
{ {
wapi_scan_info_t *temp; struct wapi_scan_info_s *temp;
/* Allocate a new cell. */ /* Allocate a new cell. */
temp = malloc(sizeof(wapi_scan_info_t)); temp = malloc(sizeof(struct wapi_scan_info_s));
if (!temp) if (!temp)
{ {
WAPI_STRERROR("malloc()"); WAPI_STRERROR("malloc()");
@ -261,7 +261,7 @@ static int wapi_scan_event(FAR struct iw_event *event, FAR wapi_list_t *list)
/* Reset it. */ /* Reset it. */
bzero(temp, sizeof(wapi_scan_info_t)); bzero(temp, sizeof(struct wapi_scan_info_s));
/* Save cell identifier. */ /* Save cell identifier. */
@ -333,7 +333,7 @@ static int wapi_scan_event(FAR struct iw_event *event, FAR wapi_list_t *list)
****************************************************************************/ ****************************************************************************/
int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq, int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq,
FAR wapi_freq_flag_t *flag) FAR enum wapi_freq_flag_e *flag)
{ {
struct iwreq wrq; struct iwreq wrq;
int ret; int ret;
@ -384,7 +384,7 @@ int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq,
****************************************************************************/ ****************************************************************************/
int wapi_set_freq(int sock, FAR const char *ifname, double freq, int wapi_set_freq(int sock, FAR const char *ifname, double freq,
wapi_freq_flag_t flag) enum wapi_freq_flag_e flag)
{ {
struct iwreq wrq; struct iwreq wrq;
int ret; int ret;
@ -551,7 +551,7 @@ int wapi_chan2freq(int sock, FAR const char *ifname, int chan,
****************************************************************************/ ****************************************************************************/
int wapi_get_essid(int sock, FAR const char *ifname, FAR char *essid, int wapi_get_essid(int sock, FAR const char *ifname, FAR char *essid,
FAR wapi_essid_flag_t *flag) FAR enum wapi_essid_flag_e *flag)
{ {
struct iwreq wrq; struct iwreq wrq;
int ret; int ret;
@ -590,7 +590,7 @@ int wapi_get_essid(int sock, FAR const char *ifname, FAR char *essid,
****************************************************************************/ ****************************************************************************/
int wapi_set_essid(int sock, FAR const char *ifname, FAR const char *essid, int wapi_set_essid(int sock, FAR const char *ifname, FAR const char *essid,
wapi_essid_flag_t flag) enum wapi_essid_flag_e flag)
{ {
char buf[WAPI_ESSID_MAX_SIZE + 1]; char buf[WAPI_ESSID_MAX_SIZE + 1];
struct iwreq wrq; struct iwreq wrq;
@ -623,7 +623,7 @@ int wapi_set_essid(int sock, FAR const char *ifname, FAR const char *essid,
* *
****************************************************************************/ ****************************************************************************/
int wapi_get_mode(int sock, FAR const char *ifname, FAR wapi_mode_t *mode) int wapi_get_mode(int sock, FAR const char *ifname, FAR enum wapi_mode_e *mode)
{ {
struct iwreq wrq; struct iwreq wrq;
int ret; int ret;
@ -653,7 +653,7 @@ int wapi_get_mode(int sock, FAR const char *ifname, FAR wapi_mode_t *mode)
* *
****************************************************************************/ ****************************************************************************/
int wapi_set_mode(int sock, FAR const char *ifname, wapi_mode_t mode) int wapi_set_mode(int sock, FAR const char *ifname, enum wapi_mode_e mode)
{ {
struct iwreq wrq; struct iwreq wrq;
int ret; int ret;
@ -772,7 +772,7 @@ int wapi_set_ap(int sock, FAR const char *ifname,
****************************************************************************/ ****************************************************************************/
int wapi_get_bitrate(int sock, FAR const char *ifname, int wapi_get_bitrate(int sock, FAR const char *ifname,
FAR int *bitrate, FAR wapi_bitrate_flag_t *flag) FAR int *bitrate, FAR enum wapi_bitrate_flag_e *flag)
{ {
struct iwreq wrq; struct iwreq wrq;
int ret; int ret;
@ -815,7 +815,7 @@ int wapi_get_bitrate(int sock, FAR const char *ifname,
****************************************************************************/ ****************************************************************************/
int wapi_set_bitrate(int sock, FAR const char *ifname, int bitrate, int wapi_set_bitrate(int sock, FAR const char *ifname, int bitrate,
wapi_bitrate_flag_t flag) enum wapi_bitrate_flag_e flag)
{ {
struct iwreq wrq; struct iwreq wrq;
int ret; int ret;
@ -870,7 +870,7 @@ int wapi_mwatt2dbm(int mwatt)
****************************************************************************/ ****************************************************************************/
int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power, int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power,
FAR wapi_txpower_flag_t *flag) FAR enum wapi_txpower_flag_e *flag)
{ {
struct iwreq wrq; struct iwreq wrq;
int ret; int ret;
@ -931,7 +931,7 @@ int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power,
****************************************************************************/ ****************************************************************************/
int wapi_set_txpower(int sock, FAR const char *ifname, int power, int wapi_set_txpower(int sock, FAR const char *ifname, int power,
wapi_txpower_flag_t flag) enum wapi_txpower_flag_e flag)
{ {
struct iwreq wrq; struct iwreq wrq;
int ret; int ret;
@ -1054,11 +1054,11 @@ int wapi_scan_stat(int sock, FAR const char *ifname)
* Collects the results of a scan process. * Collects the results of a scan process.
* *
* Input Parameters: * Input Parameters:
* aps - Pushes collected wapi_scan_info_t into this list. * aps - Pushes collected struct wapi_scan_info_s into this list.
* *
****************************************************************************/ ****************************************************************************/
int wapi_scan_coll(int sock, FAR const char *ifname, FAR wapi_list_t *aps) int wapi_scan_coll(int sock, FAR const char *ifname, FAR struct wapi_list_s *aps)
{ {
FAR char *buf; FAR char *buf;
int buflen; int buflen;

@ -1,6 +0,0 @@
/.built
/.depend
/Make.dep
/*.src
/*.obj
/*.lst

@ -1,16 +0,0 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
menuconfig WIRELESS_WEXT
bool "Driver WEXT"
default n
depends on NET && DRIVERS_WIRELESS
---help---
The driver_wext logic from the WPA suplicant written originally
by Jouni Malinen
if WIRELESS_WEXT
endif

@ -1,40 +0,0 @@
############################################################################
# apps/wireless/wext/Make.defs
# Adds selected applications to apps/ build
#
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
ifeq ($(CONFIG_WIRELESS_WEXT),y)
CONFIGURED_APPS += wireless/wext
endif

@ -1,104 +0,0 @@
############################################################################
# apps/wireless/wext/Makefile
#
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
# 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
ASRCS =
CSRCS = wext.c
MAINSRC =
VPATH = .
DEPPATH = --dep-path .
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
BIN = ..\..\libapps$(LIBEXT)
else
ifeq ($(WINTOOL),y)
BIN = ..\\..\\libapps$(LIBEXT)
else
BIN = ../../libapps$(LIBEXT)
endif
endif
# 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
install:
context:
# Create dependencies
.depend: Makefile $(SRCS)
$(Q) $(MKDEP) $(DEPPATH) "$(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: