diff options
author | iabdalkader <i.abdalkader@gmail.com> | 2021-11-17 17:32:09 +0200 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-11-19 15:41:26 +1100 |
commit | b65d17fced77f9c6ca19d4b9df9de7f679de5019 (patch) | |
tree | b7880585a82d2860b9d33c5b5023d281a3f118a3 | |
parent | 841eeb158e1d43ba34e4ee629143e10a2c4505ff (diff) |
drivers/ninaw10: Fix BSSID byte order, and add null byte to ESSID.
- Fix the BSSID byte order from scan and netinfo.
- Make sure ESSID from netinfo is null terminated.
-rw-r--r-- | drivers/ninaw10/nina_wifi_drv.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/drivers/ninaw10/nina_wifi_drv.c b/drivers/ninaw10/nina_wifi_drv.c index 70f1a4264..48127c076 100644 --- a/drivers/ninaw10/nina_wifi_drv.c +++ b/drivers/ninaw10/nina_wifi_drv.c @@ -344,6 +344,14 @@ static int nina_send_command_read_vals(uint32_t cmd, uint32_t nargs, return 0; } +static void nina_fix_mac_addr(uint8_t *mac) { + for (int i = 0; i < 3; i++) { + uint8_t b = mac[i]; + mac[i] = mac[5 - i]; + mac[5 - i] = b; + } +} + int nina_init(void) { // Initialize the BSP. nina_bsp_init(); @@ -541,12 +549,18 @@ int nina_netinfo(nina_netinfo_t *netinfo) { return -1; } + // Null terminate SSID. + netinfo->ssid[MIN((NINA_MAX_SSID_LEN - 1), ssid_len)] = 0; + if (nina_send_command_read_vals(NINA_CMD_GET_BSSID, 1, ARG_8BITS, NINA_ARGS(ARG_BYTE(0xFF)), 1, ARG_8BITS, NINA_VALS({&bssid_len, &netinfo->bssid})) != 0) { return -1; } + // The MAC address is read in reverse from the firmware. + nina_fix_mac_addr(netinfo->bssid); + return 0; } @@ -630,6 +644,9 @@ int nina_scan(nina_scan_callback_t scan_callback, void *arg, uint32_t timeout) { return -1; } + // The MAC address is read in reverse from the firmware. + nina_fix_mac_addr(scan_result.bssid); + scan_callback(&scan_result, arg); } |