diff --git a/src/platform/Ameba/ConfigurationManagerImpl.cpp b/src/platform/Ameba/ConfigurationManagerImpl.cpp index 8d67c147029300..2b09edc1050f9f 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.cpp +++ b/src/platform/Ameba/ConfigurationManagerImpl.cpp @@ -136,7 +136,15 @@ CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) int i = 0; wifi_get_mac_address(temp); - sscanf(temp, "%02x:%02x:%02x:%02x:%02x:%02x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); + + char * token = strtok(temp, ":"); + while (token != NULL) + { + mac[i] = (uint32_t) strtol(token, NULL, 16); + token = strtok(NULL, ":"); + i++; + } + for (i = 0; i < ETH_ALEN; i++) buf[i] = mac[i] & 0xFF; diff --git a/src/platform/Ameba/ConnectivityManagerImpl.cpp b/src/platform/Ameba/ConnectivityManagerImpl.cpp index 579122441349a3..10fd2798e5ff29 100644 --- a/src/platform/Ameba/ConnectivityManagerImpl.cpp +++ b/src/platform/Ameba/ConnectivityManagerImpl.cpp @@ -800,19 +800,96 @@ void ConnectivityManagerImpl::DHCPProcess(void) CHIP_ERROR ConnectivityManagerImpl::_GetWiFiSecurityType(uint8_t & securityType) { - securityType = 0; + unsigned int _auth_type; + unsigned short _security = 0; + rtw_wifi_setting_t setting; + +#ifdef CONFIG_PLATFORM_8721D + if (wext_get_enc_ext("wlan0", &_security, &setting.key_idx, setting.password) < 0) + { + securityType = 0; + } + else + { + switch (_security) + { + case IW_ENCODE_ALG_NONE: + setting.security_type = RTW_SECURITY_OPEN; + break; + case IW_ENCODE_ALG_WEP: + setting.security_type = RTW_SECURITY_WEP_PSK; + break; + case IW_ENCODE_ALG_TKIP: + setting.security_type = RTW_SECURITY_WPA_TKIP_PSK; + break; + case IW_ENCODE_ALG_CCMP: + setting.security_type = RTW_SECURITY_WPA2_AES_PSK; + break; + default: + break; + } + securityType = setting.security_type; + } +#else + wext_get_enc_ext("wlan0", &_security, &setting.key_idx, setting.password); + if (wext_get_auth_type("wlan0", &_auth_type) < 0) + { + securityType = 0; + } + else + { + switch (_security) + { + case IW_ENCODE_ALG_NONE: + setting.security_type = RTW_SECURITY_OPEN; + break; + case IW_ENCODE_ALG_WEP: + setting.security_type = RTW_SECURITY_WEP_PSK; + break; + case IW_ENCODE_ALG_TKIP: + if (_auth_type == WPA_SECURITY) + setting.security_type = RTW_SECURITY_WPA_TKIP_PSK; + else if (_auth_type == WPA2_SECURITY) + setting.security_type = RTW_SECURITY_WPA2_TKIP_PSK; + break; + case IW_ENCODE_ALG_CCMP: + if (_auth_type == WPA_SECURITY) + setting.security_type = RTW_SECURITY_WPA_AES_PSK; + else if (_auth_type == WPA2_SECURITY) + setting.security_type = RTW_SECURITY_WPA2_AES_PSK; + else if (_auth_type == WPA3_SECURITY) + setting.security_type = RTW_SECURITY_WPA3_AES_PSK; + break; + default: + break; + } + securityType = setting.security_type; + } +#endif + return CHIP_NO_ERROR; } CHIP_ERROR ConnectivityManagerImpl::_GetWiFiChannelNumber(uint16_t & channelNumber) { - channelNumber = 0; + unsigned char channel; + + if (wext_get_channel("wlan0", &channel) < 0) + channelNumber = 0; + else + channelNumber = (uint16_t) channel; + return CHIP_NO_ERROR; } CHIP_ERROR ConnectivityManagerImpl::_GetWiFiRssi(int8_t & rssi) { - rssi = 0; + int _rssi = 0; + if (wifi_get_rssi(&_rssi) < 0) + rssi = 0; + else + rssi = _rssi; + return CHIP_NO_ERROR; }