This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new 2d27dc0ef0 simwifi: For scan results, parse and translate the Chinese ssid encoded by the wpa_cli. 2d27dc0ef0 is described below commit 2d27dc0ef02bada05c26c7da178e5a0b99132666 Author: liqinhui <liqin...@xiaomi.com> AuthorDate: Thu Oct 26 18:44:36 2023 +0800 simwifi: For scan results, parse and translate the Chinese ssid encoded by the wpa_cli. Because there is no pre-encoding length of the ssid, the ssid including the Chinese characters whose length is less than 32 after encoding cann't be translated. For example, the ssid name is `word人`. After encoding it is `world\xe4\xba\xba` and will not be decoded. Signed-off-by: liqinhui <liqin...@xiaomi.com> --- arch/sim/src/sim/sim_wifidriver.c | 152 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 147 insertions(+), 5 deletions(-) diff --git a/arch/sim/src/sim/sim_wifidriver.c b/arch/sim/src/sim/sim_wifidriver.c index 5a09b60755..bc0d6b4039 100644 --- a/arch/sim/src/sim/sim_wifidriver.c +++ b/arch/sim/src/sim/sim_wifidriver.c @@ -478,8 +478,142 @@ static int utf8_escape(char *outp, int out_size, return 0; } +static int hex2nibble(char c) +{ + if (c >= '0' && c <= '9') + { + return c - '0'; + } + + if (c >= 'a' && c <= 'f') + { + return c - 'a' + 10; + } + + if (c >= 'A' && c <= 'F') + { + return c - 'A' + 10; + } + + return -EINVAL; +} + +static int hex2byte(const char *hex) +{ + int a; + int b; + + a = hex2nibble(*hex++); + if (a < 0) + { + return -EINVAL; + } + + b = hex2nibble(*hex++); + if (b < 0) + { + return -EINVAL; + } + + return (a << 4) | b; +} + +static size_t wpa_ssid_decode(uint8_t *buf, size_t maxlen, const char *str) +{ + const char *pos = str; + size_t len = 0; + int val; + + while (*pos) + { + if (len + 1 >= maxlen) + { + break; + } + + switch (*pos) + { + case '\\': + pos++; + switch (*pos) + { + case '\\': + buf[len++] = '\\'; + pos++; + break; + case '"': + buf[len++] = '"'; + pos++; + break; + case 'n': + buf[len++] = '\n'; + pos++; + break; + case 'r': + buf[len++] = '\r'; + pos++; + break; + case 't': + buf[len++] = '\t'; + pos++; + break; + case 'e': + buf[len++] = '\033'; + pos++; + break; + case 'x': + pos++; + val = hex2byte(pos); + if (val < 0) + { + val = hex2num(*pos); + if (val < 0) + break; + buf[len++] = val; + pos++; + } + else + { + buf[len++] = val; + pos += 2; + } + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + val = *pos++ - '0'; + if (*pos >= '0' && *pos <= '7') + { + val = val * 8 + (*pos++ - '0'); + } + + if (*pos >= '0' && *pos <= '7') + { + val = val * 8 + (*pos++ - '0'); + } + + buf[len++] = val; + break; + default: + break; + } + break; + default: + buf[len++] = *pos++; + break; + } + } + + return len; +} + static int copy_scan_results(struct sim_scan_result_s *scan_req, - struct sim_bss_info_s *info) + struct sim_bss_info_s *info) { int need_len; char *pointer; @@ -560,7 +694,7 @@ static int copy_scan_results(struct sim_scan_result_s *scan_req, static int get_bss_info(struct sim_bss_info_s *bss_info, char *buf, int len) { unsigned char bssid[ETH_ALEN]; - char str[128]; + char str[256]; char *p = NULL; char *s = NULL; int i = 0; @@ -597,8 +731,16 @@ static int get_bss_info(struct sim_bss_info_s *bss_info, char *buf, int len) IEEE80211_CAP_PRIVACY : 0x01; break; case 4: /* ssid */ - memcpy(bss_info->ssid, str, p - s); - bss_info->ssid_len = p - s; + if (p - s > SSID_MAX_LEN) + { + bss_info->ssid_len = wpa_ssid_decode(bss_info->ssid, + SSID_MAX_LEN, str); + } + else + { + memcpy(bss_info->ssid, str, p - s); + bss_info->ssid_len = p - s; + } break; default: break; @@ -614,7 +756,7 @@ static int get_scan_results(struct sim_netdev_s *wifidev, int ret; int size = 4096; char *rbuf; - char bss[128]; + char bss[512]; char *p; char *s; struct sim_bss_info_s bss_info;