return *len ? 0 : -1;
}
+static int wpasupp_ssid_decode(const char *in, char *out, int outlen)
+{
+#define hex(x) \
+ (((x) >= 'a') ? ((x) - 'a' + 10) : \
+ (((x) >= 'A') ? ((x) - 'A' + 10) : ((x) - '0')))
+
+ int len = 0;
+
+ while (*in)
+ {
+ if (len + 1 >= outlen)
+ break;
+
+ switch (*in)
+ {
+ case '\\':
+ in++;
+ switch (*in)
+ {
+ case 'n':
+ out[len++] = '\n'; in++;
+ break;
+
+ case 'r':
+ out[len++] = '\r'; in++;
+ break;
+
+ case 't':
+ out[len++] = '\t'; in++;
+ break;
+
+ case 'e':
+ out[len++] = '\e'; in++;
+ break;
+
+ case 'x':
+ if (isxdigit(*(in+1)) && isxdigit(*(in+2)))
+ out[len++] = hex(*(in+1)) * 16 + hex(*(in+2));
+ in += 3;
+ break;
+
+ default:
+ out[len++] = *in++;
+ break;
+ }
+ break;
+
+ default:
+ out[len++] = *in++;
+ break;
+ }
+ }
+
+ if (outlen > len)
+ out[len] = '\0';
+
+ return len;
+}
+
static int nl80211_get_scanlist(const char *ifname, char *buf, int *len)
{
int freq, rssi, qmax, count, mode;
char *res;
- char ssid[128] = { 0 };
+ char ssid[129] = { 0 };
char bssid[18] = { 0 };
char cipher[256] = { 0 };
count++;
goto nextline;
}
- if (sscanf(res, "%17s %d %d %255s%*[ \t]%127[^\n]\n",
+ if (sscanf(res, "%17s %d %d %255s%*[ \t]%128[^\n]\n",
bssid, &freq, &rssi, cipher, ssid) < 5)
{
/* skip malformed lines */
e->mac[5] = strtol(&bssid[15], NULL, 16);
/* SSID */
- memcpy(e->ssid, ssid, min(strlen(ssid), sizeof(e->ssid) - 1));
+ wpasupp_ssid_decode(ssid, e->ssid, sizeof(e->ssid));
/* Mode (assume master) */
if (strstr(cipher,"[MESH]"))