wireless/wapi: Improve error reporting IOCTL failures.

This commit is contained in:
Gregory Nutt 2017-04-26 12:34:50 -06:00
parent 4d09ebcaec
commit b9a552013f
6 changed files with 98 additions and 35 deletions

View File

@ -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 */

View File

@ -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 */

View File

@ -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;

View File

@ -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( \

View File

@ -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 */

View File

@ -42,6 +42,7 @@
#include <stdlib.h>
#include <strings.h>
#include <math.h>
#include <errno.h>
#include <nuttx/net/arp.h>
#include <nuttx/wireless/wireless.h>
@ -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. */