Merge remote-tracking branch 'origin/master' into ieee802154

This commit is contained in:
Gregory Nutt 2017-04-13 08:16:19 -06:00
commit 920b060878
3 changed files with 119 additions and 115 deletions

View File

@ -60,16 +60,20 @@ static void cleanup(FAR void * data)
FAR struct sync_s *sync = (FAR struct sync_s *) data; FAR struct sync_s *sync = (FAR struct sync_s *) data;
int status; int status;
/* Note: pthread_cond_wait() will release the mutex while it waits on /* Note: The behavior of canceling pthread_cond_wait() with asynchronous
* condition value. So a EPERM error is not a failure. * cancellation is not defined. On NuttX we get EPERM here, but application
* code must not rely on this.
*/ */
status = pthread_mutex_unlock(&sync->lock); status = pthread_mutex_unlock(&sync->lock);
#ifndef CONFIG_CANCELLATION_POINTS
if (status == EPERM) if (status == EPERM)
{ {
printf("pthread_cleanup: thread did not have mutex locked: %d\n", status); printf("pthread_cleanup: thread did not have mutex locked: %d\n", status);
return;
} }
else if (status != 0) #endif
if (status != 0)
{ {
printf("pthread_cleanup: ERROR pthread_mutex_unlock in cleanup handler. " printf("pthread_cleanup: ERROR pthread_mutex_unlock in cleanup handler. "
"Status: %d\n", status); "Status: %d\n", status);
@ -138,6 +142,7 @@ static void test_cleanup(void)
printf("pthread_cleanup: ERROR pthread_join returned wrong result: %p\n", result); printf("pthread_cleanup: ERROR pthread_join returned wrong result: %p\n", result);
} }
#ifdef CONFIG_CANCELLATION_POINTS
/* Do some operations on lock in order to check if it is in usable state. */ /* Do some operations on lock in order to check if it is in usable state. */
status = pthread_mutex_trylock(&sync.lock); status = pthread_mutex_trylock(&sync.lock);
@ -151,6 +156,7 @@ static void test_cleanup(void)
{ {
printf("pthread_cleanup: ERROR pthread_mutex_unlock, status=%d\n", status); printf("pthread_cleanup: ERROR pthread_mutex_unlock, status=%d\n", status);
} }
#endif
} }
/**************************************************************************** /****************************************************************************

View File

@ -47,29 +47,74 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define WAPI_IOCTL_STRERROR(cmd) \ #ifdef DEBUG_WIRELESS_ERROR
fprintf( \ # ifdef CONFIG_LIBC_STRERROR
stderr, "%s:%d:%s():ioctl(%s): %s\n", \ # define WAPI_IOCTL_STRERROR(cmd) \
__FILE__, __LINE__, __func__, \ fprintf( \
wapi_ioctl_command_name(cmd), strerror(errno)) stderr, "%s:%d:%s():ioctl(%s): %s\n", \
__FILE__, __LINE__, __func__, \
wapi_ioctl_command_name(cmd), strerror(errno))
#define WAPI_STRERROR(fmt, ...) \ # define WAPI_STRERROR(fmt, ...) \
fprintf( \ fprintf( \
stderr, "%s:%d:%s():" fmt ": %s\n", \ stderr, "%s:%d:%s():" fmt ": %s\n", \
__FILE__, __LINE__, __func__, \ __FILE__, __LINE__, __func__, \
## __VA_ARGS__, strerror(errno)) ## __VA_ARGS__, strerror(errno))
# else
# define WAPI_IOCTL_STRERROR(cmd) \
fprintf( \
stderr, "%s:%d:%s():ioctl(%s): %d\n", \
__FILE__, __LINE__, __func__, \
wapi_ioctl_command_name(cmd), errno)
#define WAPI_ERROR(fmt, ...) \ # define WAPI_STRERROR(fmt, ...) \
fprintf( \ fprintf( \
stderr, "%s:%d:%s(): " fmt , \ stderr, "%s:%d:%s():" fmt ": %d\n", \
__FILE__, __LINE__, __func__, ## __VA_ARGS__) __FILE__, __LINE__, __func__, \
## __VA_ARGS__, errno)
# endif
# define WAPI_ERROR(fmt, ...) \
fprintf( \
stderr, "%s:%d:%s(): " fmt , \
__FILE__, __LINE__, __func__, ## __VA_ARGS__)
#else
# ifdef CONFIG_LIBC_STRERROR
# define WAPI_IOCTL_STRERROR(cmd) \
fprintf( \
stderr, "ioctl(%s): %s\n", \
wapi_ioctl_command_name(cmd), strerror(errno))
# define WAPI_STRERROR(fmt, ...) \
fprintf( \
stderr, fmt ": %s\n", \
## __VA_ARGS__, strerror(errno))
# else
# define WAPI_IOCTL_STRERROR(cmd) \
fprintf( \
stderr, "ioctl(%s): %d\n", \
wapi_ioctl_command_name(cmd), errno)
# define WAPI_STRERROR(fmt, ...) \
fprintf( \
stderr, fmt ": %d\n", \
## __VA_ARGS__, errno)
# endif
# define WAPI_ERROR(fmt, ...) \
fprintf( \
stderr, fmt , \
## __VA_ARGS__)
#endif
#define WAPI_VALIDATE_PTR(ptr) \ #define WAPI_VALIDATE_PTR(ptr) \
if (!ptr) \ if (ptr == NULL) \
{ \ { \
WAPI_ERROR("Null pointer: %s.\n", #ptr); \ WAPI_ERROR("Null pointer: %p\n", ptr); \
return -1; \ return -EINVAL; \
} }
/**************************************************************************** /****************************************************************************
* Public Function Prototypes * Public Function Prototypes

View File

@ -76,6 +76,8 @@ 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,
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,
@ -114,7 +116,7 @@ static const struct wapi_command_s g_wapi_commands[] =
{"mode", 2, (CODE void *)wapi_mode_cmd}, {"mode", 2, (CODE void *)wapi_mode_cmd},
{"ap", 2, (CODE void *)wapi_ap_cmd}, {"ap", 2, (CODE void *)wapi_ap_cmd},
{"bitrate", 3, (CODE void *)wapi_bitrate_cmd}, {"bitrate", 3, (CODE void *)wapi_bitrate_cmd},
{"txpower", 2, (CODE void *)wapi_txpower_cmd}, {"txpower", 3, (CODE void *)wapi_txpower_cmd},
}; };
#define NCOMMANDS (sizeof(g_wapi_commands) / sizeof(struct wapi_command_s)) #define NCOMMANDS (sizeof(g_wapi_commands) / sizeof(struct wapi_command_s))
@ -175,6 +177,37 @@ static double wapi_str2double(FAR const char *str)
return value; return value;
} }
/****************************************************************************
* Name: wapi_str2ndx
*
* Description:
* Return the index of a string in a list of strings
*
****************************************************************************/
static unsigned int wapi_str2ndx(FAR const char *name, FAR const char **list,
unsigned int listlen)
{
unsigned int ndx;
for (ndx = 0; ndx < listlen; ndx++)
{
if (strcmp(name, list[ndx]) == 0)
{
return ndx;
}
}
WAPI_ERROR("ERROR: Invalid option string: %s\n", name);
WAPI_ERROR(" Valid options include:\n");
for (ndx = 0; ndx < listlen; ndx++)
{
WAPI_ERROR(" - %s\n", list[ndx]);
}
exit(EXIT_FAILURE);
}
/**************************************************************************** /****************************************************************************
* Name: wapi_show_cmd * Name: wapi_show_cmd
* *
@ -418,29 +451,13 @@ static void wapi_freq_cmd(int sock, FAR const char *ifname,
{ {
double frequency; double frequency;
wapi_freq_flag_t freq_flag; wapi_freq_flag_t freq_flag;
bool found = false;
int ret; int ret;
int i;
/* 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,
for (i = 0; i < IW_FREQ_NFLAGS; i++) IW_FREQ_NFLAGS);
{
if (strcmp(flagstr, g_wapi_freq_flags[i]) == 0)
{
freq_flag = (wapi_freq_flag_t)i;
found = true;
break;
}
}
if (!found)
{
WAPI_ERROR("ERROR: Invalid frequency flag: %s\n", flagstr);
exit(EXIT_FAILURE);
}
/* Set the frequency */ /* Set the frequency */
@ -466,27 +483,11 @@ 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; wapi_essid_flag_t essid_flag;
bool found = false;
int ret; int ret;
int i;
/* Convert input strings to values */ /* Convert input strings to values */
for (i = 0; i < 2; i++) essid_flag = (wapi_essid_flag_t)wapi_str2ndx(flagstr, g_wapi_essid_flags, 2);
{
if (strcmp(flagstr, g_wapi_essid_flags[i]) == 0)
{
essid_flag = (wapi_essid_flag_t)i;
found = true;
break;
}
}
if (!found)
{
WAPI_ERROR("ERROR: Invalid ESSID flag: %s\n", flagstr);
exit(EXIT_FAILURE);
}
/* Set the ESSID */ /* Set the ESSID */
@ -512,27 +513,11 @@ static void wapi_mode_cmd(int sock, FAR const char *ifname,
FAR const char *modestr) FAR const char *modestr)
{ {
wapi_mode_t mode; wapi_mode_t mode;
bool found = false;
int ret; int ret;
int i;
/* Convert input strings to values */ /* Convert input strings to values */
for (i = 0; i < IW_MODE_NFLAGS; i++) mode = (wapi_mode_t)wapi_str2ndx(modestr, g_wapi_modes, IW_MODE_NFLAGS);
{
if (strcmp(modestr, g_wapi_modes[i]) == 0)
{
mode = (wapi_mode_t)i;
found = true;
break;
}
}
if (!found)
{
WAPI_ERROR("ERROR: Invalid operating mode: %s\n", modestr);
exit(EXIT_FAILURE);
}
/* Set operating mode */ /* Set operating mode */
@ -592,30 +577,14 @@ static void wapi_bitrate_cmd(int sock, FAR const char *ifname,
{ {
wapi_bitrate_flag_t bitrate_flag; wapi_bitrate_flag_t bitrate_flag;
bool found = false;
int bitrate; int bitrate;
int ret; int ret;
int i;
/* Convert input strings to values */ /* Convert input strings to values */
bitrate = wapi_str2int(ratestr); bitrate = wapi_str2int(ratestr);
bitrate_flag = (wapi_bitrate_flag_t)
for (i = 0; i < 2; i++) wapi_str2ndx(flagstr, g_wapi_bitrate_flags, 2);
{
if (strcmp(flagstr, g_wapi_bitrate_flags[i]) == 0)
{
bitrate_flag = (wapi_bitrate_flag_t)i;
found = true;
break;
}
}
if (!found)
{
WAPI_ERROR("ERROR: Invalid bitrate flag: %s\n", flagstr);
exit(EXIT_FAILURE);
}
/* Set bitrate */ /* Set bitrate */
@ -641,30 +610,14 @@ 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; wapi_txpower_flag_t txpower_flag;
bool found = false;
int txpower; int txpower;
int ret; int ret;
int i;
/* Convert input strings to values */ /* Convert input strings to values */
txpower = wapi_str2int(pwrstr); txpower = wapi_str2int(pwrstr);
txpower_flag = (wapi_txpower_flag_t)
for (i = 0; i < IW_TXPOW_NFLAGS; i++) wapi_str2ndx(flagstr, g_wapi_txpower_flags, IW_TXPOW_NFLAGS);
{
if (strcmp(flagstr, g_wapi_txpower_flags[i]) == 0)
{
txpower_flag = (wapi_txpower_flag_t)i;
found = true;
break;
}
}
if (!found)
{
WAPI_ERROR("ERROR: Invalid TX power flag: %s\n", flagstr);
exit(EXIT_FAILURE);
}
/* Set txpower */ /* Set txpower */
@ -728,7 +681,7 @@ static void wapi_scan_cmd(int sock, FAR const char *ifname)
for (info = list.head.scan; info; info = info->next) for (info = list.head.scan; info; info = info->next)
{ {
printf(">> %02x:%02x:%02x:%02x:%02x:%02x %s\n", printf(" %02x:%02x:%02x:%02x:%02x:%02x %s\n",
info->ap.ether_addr_octet[0], info->ap.ether_addr_octet[1], info->ap.ether_addr_octet[0], info->ap.ether_addr_octet[1],
info->ap.ether_addr_octet[2], info->ap.ether_addr_octet[3], info->ap.ether_addr_octet[2], info->ap.ether_addr_octet[3],
info->ap.ether_addr_octet[4], info->ap.ether_addr_octet[5], info->ap.ether_addr_octet[4], info->ap.ether_addr_octet[5],