libiwinfo: ignore log messages from wpa_supplicant while scanning
wpa_supplicant may send log and event messages intermixed with the expected scan results. This makes "iwinfo wlan0 scan" and LuCI "site survey" display nothing when many AP's are around. Eliminate the CTRL-EVENT-BSS-ADDED events, interspersed log messages, lines with unexpected format. Increase timeout to handle the max number of channels (2.4, 3.6, 4.9, 5 GHz). Insure receive buffer is null-terminated. Signed-off-by: Jean-Pierre Tosoni <jp.tosoni@acksys.fr> SVN-Revision: 36888
This commit is contained in:
parent
f995c90329
commit
cb24c37858
1 changed files with 47 additions and 16 deletions
|
@ -540,16 +540,21 @@ static char * nl80211_wpactl_info(const char *ifname, const char *cmd,
|
||||||
{
|
{
|
||||||
send(sock, "ATTACH", 6, 0);
|
send(sock, "ATTACH", 6, 0);
|
||||||
|
|
||||||
if (nl80211_wpactl_recv(sock, buffer, sizeof(buffer)) <= 0)
|
if (nl80211_wpactl_recv(sock, buffer, sizeof(buffer)-1) <= 0)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
send(sock, cmd, strlen(cmd), 0);
|
send(sock, cmd, strlen(cmd), 0);
|
||||||
|
|
||||||
while( numtry++ < 5 )
|
/* we might have to scan up to 72 channels / 256ms per channel */
|
||||||
|
/* this makes up to 18.5s hence 10 tries */
|
||||||
|
while( numtry++ < 10 )
|
||||||
{
|
{
|
||||||
if (nl80211_wpactl_recv(sock, buffer, sizeof(buffer)) <= 0)
|
char *bracket;
|
||||||
|
|
||||||
|
/* make sure there is a terminating nul byte */
|
||||||
|
if (nl80211_wpactl_recv(sock, buffer, sizeof(buffer)-1) <= 0)
|
||||||
{
|
{
|
||||||
if (event)
|
if (event)
|
||||||
continue;
|
continue;
|
||||||
|
@ -559,6 +564,13 @@ static char * nl80211_wpactl_info(const char *ifname, const char *cmd,
|
||||||
|
|
||||||
if ((!event && buffer[0] != '<') || (event && strstr(buffer, event)))
|
if ((!event && buffer[0] != '<') || (event && strstr(buffer, event)))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* there may be more than max(numtry) BSS-ADDED events */
|
||||||
|
/* ignore them similar to wpa_cli */
|
||||||
|
if (buffer[0] == '<' &&
|
||||||
|
(bracket=strchr(buffer,'>')) != NULL &&
|
||||||
|
strncmp(bracket+1,"CTRL-EVENT-BSS-ADDED",20) == 0)
|
||||||
|
numtry--;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = buffer;
|
rv = buffer;
|
||||||
|
@ -1751,8 +1763,10 @@ static int nl80211_get_scanlist_cb(struct nl_msg *msg, void *arg)
|
||||||
|
|
||||||
if (caps & (1<<1))
|
if (caps & (1<<1))
|
||||||
sl->e->mode = IWINFO_OPMODE_ADHOC;
|
sl->e->mode = IWINFO_OPMODE_ADHOC;
|
||||||
else
|
else if (caps & (1<<0))
|
||||||
sl->e->mode = IWINFO_OPMODE_MASTER;
|
sl->e->mode = IWINFO_OPMODE_MASTER;
|
||||||
|
else
|
||||||
|
sl->e->mode = IWINFO_OPMODE_MESHPOINT;
|
||||||
|
|
||||||
if (caps & (1<<4))
|
if (caps & (1<<4))
|
||||||
sl->e->crypto.enabled = 1;
|
sl->e->crypto.enabled = 1;
|
||||||
|
@ -1852,14 +1866,26 @@ int nl80211_get_scanlist(const char *ifname, char *buf, int *len)
|
||||||
{
|
{
|
||||||
nl80211_get_quality_max(ifname, &qmax);
|
nl80211_get_quality_max(ifname, &qmax);
|
||||||
|
|
||||||
/* skip header line */
|
count = -1;
|
||||||
while (*res++ != '\n');
|
|
||||||
|
|
||||||
count = 0;
|
do {
|
||||||
|
if (res[0] == '<')
|
||||||
while (sscanf(res, "%17s %d %d %255s%*[ \t]%127[^\n]\n",
|
{
|
||||||
bssid, &freq, &rssi, cipher, ssid) > 0)
|
/* skip log lines */
|
||||||
{
|
goto nextline;
|
||||||
|
}
|
||||||
|
if (count < 0)
|
||||||
|
{
|
||||||
|
/* skip header line */
|
||||||
|
count++;
|
||||||
|
goto nextline;
|
||||||
|
}
|
||||||
|
if (sscanf(res, "%17s %d %d %255s%*[ \t]%127[^\n]\n",
|
||||||
|
bssid, &freq, &rssi, cipher, ssid) < 5)
|
||||||
|
{
|
||||||
|
/* skip malformed lines */
|
||||||
|
goto nextline;
|
||||||
|
}
|
||||||
/* BSSID */
|
/* BSSID */
|
||||||
e->mac[0] = strtol(&bssid[0], NULL, 16);
|
e->mac[0] = strtol(&bssid[0], NULL, 16);
|
||||||
e->mac[1] = strtol(&bssid[3], NULL, 16);
|
e->mac[1] = strtol(&bssid[3], NULL, 16);
|
||||||
|
@ -1872,7 +1898,10 @@ int nl80211_get_scanlist(const char *ifname, char *buf, int *len)
|
||||||
memcpy(e->ssid, ssid, min(strlen(ssid), sizeof(e->ssid) - 1));
|
memcpy(e->ssid, ssid, min(strlen(ssid), sizeof(e->ssid) - 1));
|
||||||
|
|
||||||
/* Mode (assume master) */
|
/* Mode (assume master) */
|
||||||
e->mode = IWINFO_OPMODE_MASTER;
|
if (strstr(cipher,"[MESH]"))
|
||||||
|
e->mode = IWINFO_OPMODE_MESHPOINT;
|
||||||
|
else
|
||||||
|
e->mode = IWINFO_OPMODE_MASTER;
|
||||||
|
|
||||||
/* Channel */
|
/* Channel */
|
||||||
e->channel = nl80211_freq2channel(freq);
|
e->channel = nl80211_freq2channel(freq);
|
||||||
|
@ -1904,16 +1933,18 @@ int nl80211_get_scanlist(const char *ifname, char *buf, int *len)
|
||||||
/* Crypto */
|
/* Crypto */
|
||||||
nl80211_get_scancrypto(cipher, &e->crypto);
|
nl80211_get_scancrypto(cipher, &e->crypto);
|
||||||
|
|
||||||
/* advance to next line */
|
|
||||||
while (*res && *res++ != '\n');
|
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
e++;
|
e++;
|
||||||
|
|
||||||
memset(ssid, 0, sizeof(ssid));
|
memset(ssid, 0, sizeof(ssid));
|
||||||
memset(bssid, 0, sizeof(bssid));
|
memset(bssid, 0, sizeof(bssid));
|
||||||
memset(cipher, 0, sizeof(cipher));
|
memset(cipher, 0, sizeof(cipher));
|
||||||
}
|
|
||||||
|
nextline:
|
||||||
|
/* advance to next line */
|
||||||
|
while( *res && *res++ != '\n' );
|
||||||
|
}
|
||||||
|
while( *res );
|
||||||
|
|
||||||
*len = count * sizeof(struct iwinfo_scanlist_entry);
|
*len = count * sizeof(struct iwinfo_scanlist_entry);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue