From 06b71add8412c539e7d55c301d026ee18fbb8691 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Mon, 22 Nov 2021 12:45:03 +0800 Subject: [PATCH] Update ConnectivityManagerImpl and ConfigurationManagerImpl --- .../Ameba/ConfigurationManagerImpl.cpp | 10 ++- .../Ameba/ConnectivityManagerImpl.cpp | 85 ++++++++++++++++++- 2 files changed, 91 insertions(+), 4 deletions(-) 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..8ca3e21be339e8 100644 --- a/src/platform/Ameba/ConnectivityManagerImpl.cpp +++ b/src/platform/Ameba/ConnectivityManagerImpl.cpp @@ -800,19 +800,98 @@ 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 = EMBER_ZCL_SECURITY_TYPE_NONE; + break; + case IW_ENCODE_ALG_WEP: + setting.security_type = EMBER_ZCL_SECURITY_TYPE_WEP; + break; + case IW_ENCODE_ALG_TKIP: + setting.security_type = EMBER_ZCL_SECURITY_TYPE_WPA; + break; + case IW_ENCODE_ALG_CCMP: + setting.security_type = EMBER_ZCL_SECURITY_TYPE_WPA2; + break; + default: + setting.security_type = EMBER_ZCL_SECURITY_TYPE_UNSPECIFIED; + 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 = EMBER_ZCL_SECURITY_TYPE_NONE; + break; + case IW_ENCODE_ALG_WEP: + setting.security_type = EMBER_ZCL_SECURITY_TYPE_WEP; + break; + case IW_ENCODE_ALG_TKIP: + if (_auth_type == WPA_SECURITY) + setting.security_type = EMBER_ZCL_SECURITY_TYPE_WPA; + else if (_auth_type == WPA2_SECURITY) + setting.security_type = EMBER_ZCL_SECURITY_TYPE_WPA2; + break; + case IW_ENCODE_ALG_CCMP: + if (_auth_type == WPA_SECURITY) + setting.security_type = EMBER_ZCL_SECURITY_TYPE_WPA; + else if (_auth_type == WPA2_SECURITY) + setting.security_type = EMBER_ZCL_SECURITY_TYPE_WPA2; + else if (_auth_type == WPA3_SECURITY) + setting.security_type = EMBER_ZCL_SECURITY_TYPE_WPA3; + break; + default: + setting.security_type = EMBER_ZCL_SECURITY_TYPE_UNSPECIFIED; + 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; }