Wapi simplify (#1)

apps/wireless/wapi:  Simplify usage of command line.  Remove duplicate extensions
This commit is contained in:
Xiang Xiao 2019-12-31 10:39:53 -06:00 committed by patacongo
parent 0536c5b523
commit 49c997501a
4 changed files with 80 additions and 201 deletions

View File

@ -116,8 +116,8 @@ enum wapi_route_target_e
enum wapi_essid_flag_e enum wapi_essid_flag_e
{ {
WAPI_ESSID_ON, WAPI_ESSID_OFF,
WAPI_ESSID_OFF WAPI_ESSID_ON
}; };
/* Supported operation modes. */ /* Supported operation modes. */
@ -653,44 +653,6 @@ int wapi_scan_stat(int sock, FAR const char *ifname);
int wapi_scan_coll(int sock, FAR const char *ifname, FAR struct wapi_list_s *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 * Name: wpa_driver_wext_set_key_ext
* *

View File

@ -69,97 +69,6 @@
* Public Functions * Public Functions
************************************************************************************/ ************************************************************************************/
/************************************************************************************
* 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)
{
struct iwreq iwr;
int ret = 0;
char buf[33];
DEBUGASSERT(ifname != NULL && ssid != NULL && ssid_len > 0);
if (ssid_len > WAPI_ESSID_MAX_SIZE)
{
return -1;
}
memset(&iwr, 0, sizeof(iwr));
strncpy(iwr.ifr_name, ifname, IFNAMSIZ);
/* flags: 1 = ESSID is active, 0 = not (promiscuous) */
iwr.u.essid.flags = (ssid_len != 0);
memset(buf, 0, sizeof(buf));
memcpy(buf, ssid, ssid_len);
iwr.u.essid.pointer = (caddr_t) buf;
iwr.u.essid.length = ssid_len;
if (ioctl(sockfd, SIOCSIWESSID, (unsigned long)&iwr) < 0)
{
nerr("ERROR: ioctl[SIOCSIWESSID]: %d", errno);
ret = -1;
}
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
* *
@ -272,7 +181,7 @@ int wpa_driver_wext_associate(FAR struct wpa_wconfig_s *wconfig)
strncpy(req.ifr_name, wconfig->ifname, IFNAMSIZ); strncpy(req.ifr_name, wconfig->ifname, IFNAMSIZ);
ret = wpa_driver_wext_set_mode(sockfd, wconfig->ifname, wconfig->sta_mode); ret = wapi_set_mode(sockfd, wconfig->ifname, wconfig->sta_mode);
if (ret < 0) if (ret < 0)
{ {
nerr("ERROR: Fail set sta mode: %d\n", ret); nerr("ERROR: Fail set sta mode: %d\n", ret);
@ -306,8 +215,8 @@ int wpa_driver_wext_associate(FAR struct wpa_wconfig_s *wconfig)
goto close_socket; goto close_socket;
} }
ret = wpa_driver_wext_set_ssid(sockfd, wconfig->ifname, wconfig->ssid, ret = wapi_set_essid(sockfd, wconfig->ifname,
wconfig->ssidlen); (FAR const char *)wconfig->ssid, WAPI_ESSID_ON);
if (ret < 0) if (ret < 0)
{ {
nerr("ERROR: Fail set ssid: %d\n", ret); nerr("ERROR: Fail set ssid: %d\n", ret);

View File

@ -38,6 +38,7 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -76,8 +77,7 @@ typedef void (*cmd3_t)(int sock, FAR const char *arg1,
static int wapi_str2int(FAR const char *str); static int wapi_str2int(FAR const char *str);
static double wapi_str2double(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, 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_show_cmd(int sock, FAR const char *ifname);
static void wapi_ip_cmd(int sock, FAR const char *ifname, static void wapi_ip_cmd(int sock, FAR const char *ifname,
@ -185,12 +185,18 @@ static double wapi_str2double(FAR const char *str)
* *
****************************************************************************/ ****************************************************************************/
static unsigned int wapi_str2ndx(FAR const char *name, FAR const char **list, static unsigned int wapi_str2ndx(FAR const char *name, FAR const char **list)
unsigned int listlen)
{ {
unsigned int ndx; unsigned int ndx;
for (ndx = 0; ndx < listlen; ndx++) /* Check the first character is enough, all prefix with WAPI_* */
if (isdigit(name[0]))
{
return atoi(name);
}
for (ndx = 0; list[ndx]; ndx++)
{ {
if (strcmp(name, list[ndx]) == 0) if (strcmp(name, list[ndx]) == 0)
{ {
@ -200,9 +206,9 @@ static unsigned int wapi_str2ndx(FAR const char *name, FAR const char **list,
WAPI_ERROR("ERROR: Invalid option string: %s\n", name); WAPI_ERROR("ERROR: Invalid option string: %s\n", name);
WAPI_ERROR(" Valid options include:\n"); WAPI_ERROR(" Valid options include:\n");
for (ndx = 0; ndx < listlen; ndx++) for (ndx = 0; list[ndx]; ndx++)
{ {
WAPI_ERROR(" - %s\n", list[ndx]); WAPI_ERROR(" - [%d] %s\n", ndx, list[ndx]);
} }
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -456,8 +462,7 @@ static void wapi_freq_cmd(int sock, FAR const char *ifname,
/* Convert input strings to values */ /* Convert input strings to values */
frequency = wapi_str2double(freqstr); frequency = wapi_str2double(freqstr);
freq_flag = (enum wapi_freq_flag_e)wapi_str2ndx(flagstr, g_wapi_freq_flags, freq_flag = (enum wapi_freq_flag_e)wapi_str2ndx(flagstr, g_wapi_freq_flags);
IW_FREQ_NFLAGS);
/* Set the frequency */ /* Set the frequency */
@ -487,7 +492,7 @@ static void wapi_essid_cmd(int sock, FAR const char *ifname,
/* Convert input strings to values */ /* Convert input strings to values */
essid_flag = (enum wapi_essid_flag_e)wapi_str2ndx(flagstr, g_wapi_essid_flags, 2); essid_flag = (enum wapi_essid_flag_e)wapi_str2ndx(flagstr, g_wapi_essid_flags);
/* Set the ESSID */ /* Set the ESSID */
@ -517,7 +522,7 @@ static void wapi_mode_cmd(int sock, FAR const char *ifname,
/* Convert input strings to values */ /* Convert input strings to values */
mode = (enum wapi_mode_e)wapi_str2ndx(modestr, g_wapi_modes, IW_MODE_NFLAGS); mode = (enum wapi_mode_e)wapi_str2ndx(modestr, g_wapi_modes);
/* Set operating mode */ /* Set operating mode */
@ -584,7 +589,7 @@ static void wapi_bitrate_cmd(int sock, FAR const char *ifname,
bitrate = wapi_str2int(ratestr); bitrate = wapi_str2int(ratestr);
bitrate_flag = (enum wapi_bitrate_flag_e) bitrate_flag = (enum wapi_bitrate_flag_e)
wapi_str2ndx(flagstr, g_wapi_bitrate_flags, 2); wapi_str2ndx(flagstr, g_wapi_bitrate_flags);
/* Set bitrate */ /* Set bitrate */
@ -617,7 +622,7 @@ static void wapi_txpower_cmd(int sock, FAR const char *ifname,
txpower = wapi_str2int(pwrstr); txpower = wapi_str2int(pwrstr);
txpower_flag = (enum wapi_txpower_flag_e) txpower_flag = (enum wapi_txpower_flag_e)
wapi_str2ndx(flagstr, g_wapi_txpower_flags, IW_TXPOW_NFLAGS); wapi_str2ndx(flagstr, g_wapi_txpower_flags);
/* Set txpower */ /* Set txpower */
@ -650,7 +655,11 @@ static void wapi_scan_cmd(int sock, FAR const char *ifname)
/* Start scan */ /* Start scan */
ret = wapi_scan_init(sock, ifname); ret = wapi_scan_init(sock, ifname);
WAPI_ERROR("ERROR: wapi_scan_init() failed: %d\n", ret); if (ret < 0)
{
WAPI_ERROR("ERROR: wapi_scan_init() failed: %d\n", ret);
return;
}
/* Wait for completion */ /* Wait for completion */
@ -658,8 +667,11 @@ static void wapi_scan_cmd(int sock, FAR const char *ifname)
{ {
sleep(sleepdur); sleep(sleepdur);
ret = wapi_scan_stat(sock, ifname); ret = wapi_scan_stat(sock, ifname);
WAPI_ERROR("ERROR: wapi_scan_stat() failed: %d, sleeptries: %d\n", if (ret < 0)
ret, sleeptries); {
WAPI_ERROR("ERROR: wapi_scan_stat() failed: %d, sleeptries: %d\n",
ret, sleeptries);
}
} }
while (--sleeptries > 0 && ret > 0); while (--sleeptries > 0 && ret > 0);
@ -716,46 +728,46 @@ static void wapi_showusage(FAR const char *progname, int exitcode)
{ {
int i; int i;
fprintf(stderr, "Usage: %s show <ifname>\n", progname); fprintf(stderr, "Usage: %s show <ifname>\n", progname);
fprintf(stderr, " %s scan <ifname>\n", progname); fprintf(stderr, " %s scan <ifname>\n", progname);
fprintf(stderr, " %s ip <ifname> <IP address>\n", progname); fprintf(stderr, " %s ip <ifname> <IP address>\n", progname);
fprintf(stderr, " %s mask <ifname> <mask>\n", progname); fprintf(stderr, " %s mask <ifname> <mask>\n", progname);
fprintf(stderr, " %s freq <ifname> <frequency> <flag>\n", progname); fprintf(stderr, " %s freq <ifname> <frequency> <index/flag>\n", progname);
fprintf(stderr, " %s essid <ifname> <essid> <flag>\n", progname); fprintf(stderr, " %s essid <ifname> <essid> <index/flag>\n", progname);
fprintf(stderr, " %s mode <ifname> <ifname> <mode>\n", progname); fprintf(stderr, " %s mode <ifname> <ifname> <index/mode>\n", progname);
fprintf(stderr, " %s ap <ifname> <ifname> <MAC address>\n", progname); fprintf(stderr, " %s ap <ifname> <ifname> <MAC address>\n", progname);
fprintf(stderr, " %s bitrate <ifname> <bitrate> <flag>\n", progname); fprintf(stderr, " %s bitrate <ifname> <bitrate> <index/flag>\n", progname);
fprintf(stderr, " %s txpower <ifname> <txpower> <flag>\n", progname); fprintf(stderr, " %s txpower <ifname> <txpower> <index/flag>\n", progname);
fprintf(stderr, " %s help\n", progname); fprintf(stderr, " %s help\n", progname);
fprintf(stderr, "\nFrequency Flags:\n"); fprintf(stderr, "\nFrequency Flags:\n");
for (i = 0; i < IW_FREQ_NFLAGS; i++) for (i = 0; g_wapi_freq_flags[i]; i++)
{ {
fprintf(stderr, " %s\n", g_wapi_freq_flags[i]); fprintf(stderr, " [%d] %s\n", i, g_wapi_freq_flags[i]);
} }
fprintf(stderr, "\nESSID Flags:\n"); fprintf(stderr, "\nESSID Flags:\n");
for (i = 0; i < 2; i++) for (i = 0; g_wapi_essid_flags[i]; i++)
{ {
fprintf(stderr, " %s\n", g_wapi_essid_flags[i]); fprintf(stderr, " [%d] %s\n", i, g_wapi_essid_flags[i]);
} }
fprintf(stderr, "\nOperating Modes:\n"); fprintf(stderr, "\nOperating Modes:\n");
for (i = 0; i < IW_MODE_NFLAGS; i++) for (i = 0; g_wapi_modes[i]; i++)
{ {
fprintf(stderr, " %s\n", g_wapi_modes[i]); fprintf(stderr, " [%d] %s\n", i, g_wapi_modes[i]);
} }
fprintf(stderr, "\nBitrate Flags:\n"); fprintf(stderr, "\nBitrate Flags:\n");
for (i = 0; i < 2; i++) for (i = 0; g_wapi_bitrate_flags[i]; i++)
{ {
fprintf(stderr, " %s\n", g_wapi_bitrate_flags[i]); fprintf(stderr, " [%d] %s\n", i, g_wapi_bitrate_flags[i]);
} }
fprintf(stderr, "\nTX power Flags:\n"); fprintf(stderr, "\nTX power Flags:\n");
for (i = 0; i < IW_TXPOW_NFLAGS; i++) for (i = 0; g_wapi_txpower_flags[i]; i++)
{ {
fprintf(stderr, " %s\n", g_wapi_txpower_flags[i]); fprintf(stderr, " [%d] %s\n", i, g_wapi_txpower_flags[i]);
} }
exit(exitcode); exit(exitcode);

View File

@ -72,15 +72,17 @@ struct wapi_event_stream_s
FAR const char *g_wapi_freq_flags[] = FAR const char *g_wapi_freq_flags[] =
{ {
"WAPI_FREQ_AUTO", "WAPI_FREQ_AUTO",
"WAPI_FREQ_FIXED" "WAPI_FREQ_FIXED",
NULL
}; };
/* ESSID */ /* ESSID */
FAR const char *g_wapi_essid_flags[] = FAR const char *g_wapi_essid_flags[] =
{ {
"WAPI_ESSID_OFF",
"WAPI_ESSID_ON", "WAPI_ESSID_ON",
"WAPI_ESSID_OFF" NULL
}; };
/* Operating Mode */ /* Operating Mode */
@ -94,7 +96,8 @@ FAR const char *g_wapi_modes[] =
"WAPI_MODE_REPEAT", "WAPI_MODE_REPEAT",
"WAPI_MODE_SECOND", "WAPI_MODE_SECOND",
"WAPI_MODE_MONITOR", "WAPI_MODE_MONITOR",
"WAPI_MODE_MESH" "WAPI_MODE_MESH",
NULL
}; };
/* Bit Rate */ /* Bit Rate */
@ -102,7 +105,8 @@ FAR const char *g_wapi_modes[] =
FAR const char *g_wapi_bitrate_flags[] = FAR const char *g_wapi_bitrate_flags[] =
{ {
"WAPI_BITRATE_AUTO", "WAPI_BITRATE_AUTO",
"WAPI_BITRATE_FIXED" "WAPI_BITRATE_FIXED",
NULL
}; };
/* Transmit Power */ /* Transmit Power */
@ -111,7 +115,8 @@ FAR const char *g_wapi_txpower_flags[] =
{ {
"WAPI_TXPOWER_DBM", "WAPI_TXPOWER_DBM",
"WAPI_TXPOWER_MWATT", "WAPI_TXPOWER_MWATT",
"WAPI_TXPOWER_RELATIVE" "WAPI_TXPOWER_RELATIVE",
NULL
}; };
/**************************************************************************** /****************************************************************************
@ -222,9 +227,6 @@ static void wapi_event_stream_init(FAR struct wapi_event_stream_s *stream,
static int wapi_event_stream_extract(FAR struct wapi_event_stream_s *stream, static int wapi_event_stream_extract(FAR struct wapi_event_stream_s *stream,
FAR struct iw_event *iwe) FAR struct iw_event *iwe)
{ {
#warning Missing logic
// return iw_extract_event_stream((struct stream_descr *)stream, iwe, 0);
int ret; int ret;
struct iw_event *iwe_stream; struct iw_event *iwe_stream;
@ -385,7 +387,7 @@ static int wapi_scan_event(FAR struct iw_event *event, FAR struct wapi_list_s *l
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 enum wapi_freq_flag_e *flag) FAR enum wapi_freq_flag_e *flag)
{ {
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
WAPI_VALIDATE_PTR(freq); WAPI_VALIDATE_PTR(freq);
@ -436,7 +438,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,
enum wapi_freq_flag_e flag) enum wapi_freq_flag_e flag)
{ {
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
/* Set freq. */ /* Set freq. */
@ -482,7 +484,7 @@ int wapi_set_freq(int sock, FAR const char *ifname, double freq,
int wapi_freq2chan(int sock, FAR const char *ifname, double freq, int wapi_freq2chan(int sock, FAR const char *ifname, double freq,
FAR int *chan) FAR int *chan)
{ {
struct iwreq wrq; struct iwreq wrq = {};
char buf[sizeof(struct iw_range) * 2]; char buf[sizeof(struct iw_range) * 2];
int ret; int ret;
@ -544,7 +546,7 @@ int wapi_freq2chan(int sock, FAR const char *ifname, double freq,
int wapi_chan2freq(int sock, FAR const char *ifname, int chan, int wapi_chan2freq(int sock, FAR const char *ifname, int chan,
FAR double *freq) FAR double *freq)
{ {
struct iwreq wrq; struct iwreq wrq = {};
char buf[sizeof(struct iw_range) * 2]; char buf[sizeof(struct iw_range) * 2];
int ret; int ret;
@ -603,7 +605,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 enum wapi_essid_flag_e *flag) FAR enum wapi_essid_flag_e *flag)
{ {
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
WAPI_VALIDATE_PTR(essid); WAPI_VALIDATE_PTR(essid);
@ -643,7 +645,7 @@ int wapi_set_essid(int sock, FAR const char *ifname, FAR const char *essid,
enum wapi_essid_flag_e 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 = {};
int ret; int ret;
/* Prepare request. */ /* Prepare request. */
@ -675,7 +677,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 enum wapi_mode_e *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;
WAPI_VALIDATE_PTR(mode); WAPI_VALIDATE_PTR(mode);
@ -705,7 +707,7 @@ int wapi_get_mode(int sock, FAR const char *ifname, FAR enum wapi_mode_e *mode)
int wapi_set_mode(int sock, FAR const char *ifname, enum wapi_mode_e 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;
wrq.u.mode = mode; wrq.u.mode = mode;
@ -762,7 +764,7 @@ int wapi_make_null_ether(FAR struct ether_addr *sa)
int wapi_get_ap(int sock, FAR const char *ifname, FAR struct ether_addr *ap) int wapi_get_ap(int sock, FAR const char *ifname, FAR struct ether_addr *ap)
{ {
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
WAPI_VALIDATE_PTR(ap); WAPI_VALIDATE_PTR(ap);
@ -793,7 +795,7 @@ int wapi_get_ap(int sock, FAR const char *ifname, FAR struct ether_addr *ap)
int wapi_set_ap(int sock, FAR const char *ifname, int wapi_set_ap(int sock, FAR const char *ifname,
FAR const struct ether_addr *ap) FAR const struct ether_addr *ap)
{ {
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
WAPI_VALIDATE_PTR(ap); WAPI_VALIDATE_PTR(ap);
@ -824,7 +826,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 enum wapi_bitrate_flag_e *flag) FAR int *bitrate, FAR enum wapi_bitrate_flag_e *flag)
{ {
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
WAPI_VALIDATE_PTR(bitrate); WAPI_VALIDATE_PTR(bitrate);
@ -867,7 +869,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,
enum wapi_bitrate_flag_e flag) enum wapi_bitrate_flag_e flag)
{ {
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
wrq.u.bitrate.value = bitrate; wrq.u.bitrate.value = bitrate;
@ -922,7 +924,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 enum wapi_txpower_flag_e *flag) FAR enum wapi_txpower_flag_e *flag)
{ {
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
WAPI_VALIDATE_PTR(power); WAPI_VALIDATE_PTR(power);
@ -983,7 +985,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,
enum wapi_txpower_flag_e flag) enum wapi_txpower_flag_e flag)
{ {
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
/* Construct the request. */ /* Construct the request. */
@ -1029,13 +1031,9 @@ int wapi_set_txpower(int sock, FAR const char *ifname, int power,
int wapi_scan_init(int sock, const char *ifname) int wapi_scan_init(int sock, const char *ifname)
{ {
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
wrq.u.data.pointer = NULL;
wrq.u.data.flags = 0;
wrq.u.data.length = 0;
strncpy(wrq.ifr_name, ifname, IFNAMSIZ); strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCSIWSCAN, (unsigned long)((uintptr_t)&wrq)); ret = ioctl(sock, SIOCSIWSCAN, (unsigned long)((uintptr_t)&wrq));
if (ret < 0) if (ret < 0)
@ -1061,13 +1059,11 @@ int wapi_scan_init(int sock, const char *ifname)
int wapi_scan_stat(int sock, FAR const char *ifname) int wapi_scan_stat(int sock, FAR const char *ifname)
{ {
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
char buf; char buf;
wrq.u.data.pointer = &buf; wrq.u.data.pointer = &buf;
wrq.u.data.flags = 0;
wrq.u.data.length = 0;
strncpy(wrq.ifr_name, ifname, IFNAMSIZ); strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
if ((ret = ioctl(sock, SIOCGIWSCAN, (unsigned long)((uintptr_t)&wrq))) < 0) if ((ret = ioctl(sock, SIOCGIWSCAN, (unsigned long)((uintptr_t)&wrq))) < 0)
@ -1112,7 +1108,7 @@ 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;
struct iwreq wrq; struct iwreq wrq = {};
int ret; int ret;
WAPI_VALIDATE_PTR(aps); WAPI_VALIDATE_PTR(aps);