From 925cde7632d21ebb7bd458f81ec90589e8f670f4 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 1/2] Update ConnectivityManagerImpl and ConfigurationManagerImpl --- .../Ameba/ConfigurationManagerImpl.cpp | 9 ++- .../Ameba/ConnectivityManagerImpl.cpp | 75 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/platform/Ameba/ConfigurationManagerImpl.cpp b/src/platform/Ameba/ConfigurationManagerImpl.cpp index 8d67c147029300..a027f52bf0c60d 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.cpp +++ b/src/platform/Ameba/ConfigurationManagerImpl.cpp @@ -136,7 +136,14 @@ 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..2d5e388090fb2e 100644 --- a/src/platform/Ameba/ConnectivityManagerImpl.cpp +++ b/src/platform/Ameba/ConnectivityManagerImpl.cpp @@ -800,19 +800,94 @@ void ConnectivityManagerImpl::DHCPProcess(void) CHIP_ERROR ConnectivityManagerImpl::_GetWiFiSecurityType(uint8_t & securityType) { + 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) { + 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) { + int _rssi = 0; + if(wifi_get_rssi(&_rssi) < 0) rssi = 0; + else + rssi = _rssi; + return CHIP_NO_ERROR; } From 8c6faf3504ceb92462cdafae25be57298cfe0ce4 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 22 Nov 2021 05:04:04 +0000 Subject: [PATCH 2/2] Restyled by clang-format --- .../Ameba/ConfigurationManagerImpl.cpp | 7 +- .../Ameba/ConnectivityManagerImpl.cpp | 64 ++++++++++--------- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/platform/Ameba/ConfigurationManagerImpl.cpp b/src/platform/Ameba/ConfigurationManagerImpl.cpp index a027f52bf0c60d..2b09edc1050f9f 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.cpp +++ b/src/platform/Ameba/ConfigurationManagerImpl.cpp @@ -137,10 +137,11 @@ CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) wifi_get_mac_address(temp); - char *token = strtok(temp, ":"); - while(token != NULL) { + char * token = strtok(temp, ":"); + while (token != NULL) + { mac[i] = (uint32_t) strtol(token, NULL, 16); - token = strtok(NULL, ":"); + token = strtok(NULL, ":"); i++; } diff --git a/src/platform/Ameba/ConnectivityManagerImpl.cpp b/src/platform/Ameba/ConnectivityManagerImpl.cpp index 2d5e388090fb2e..10fd2798e5ff29 100644 --- a/src/platform/Ameba/ConnectivityManagerImpl.cpp +++ b/src/platform/Ameba/ConnectivityManagerImpl.cpp @@ -805,13 +805,14 @@ CHIP_ERROR ConnectivityManagerImpl::_GetWiFiSecurityType(uint8_t & securityType) rtw_wifi_setting_t setting; #ifdef CONFIG_PLATFORM_8721D - if(wext_get_enc_ext("wlan0", &_security, &setting.key_idx, setting.password) < 0) + if (wext_get_enc_ext("wlan0", &_security, &setting.key_idx, setting.password) < 0) { securityType = 0; } else { - switch(_security){ + switch (_security) + { case IW_ENCODE_ALG_NONE: setting.security_type = RTW_SECURITY_OPEN; break; @@ -833,33 +834,34 @@ CHIP_ERROR ConnectivityManagerImpl::_GetWiFiSecurityType(uint8_t & securityType) wext_get_enc_ext("wlan0", &_security, &setting.key_idx, setting.password); if (wext_get_auth_type("wlan0", &_auth_type) < 0) { - securityType = 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; + 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; } @@ -872,10 +874,10 @@ CHIP_ERROR ConnectivityManagerImpl::_GetWiFiChannelNumber(uint16_t & channelNumb { unsigned char channel; - if(wext_get_channel("wlan0", &channel) < 0) - channelNumber = 0; + if (wext_get_channel("wlan0", &channel) < 0) + channelNumber = 0; else - channelNumber = (uint16_t)channel; + channelNumber = (uint16_t) channel; return CHIP_NO_ERROR; } @@ -883,8 +885,8 @@ CHIP_ERROR ConnectivityManagerImpl::_GetWiFiChannelNumber(uint16_t & channelNumb CHIP_ERROR ConnectivityManagerImpl::_GetWiFiRssi(int8_t & rssi) { int _rssi = 0; - if(wifi_get_rssi(&_rssi) < 0) - rssi = 0; + if (wifi_get_rssi(&_rssi) < 0) + rssi = 0; else rssi = _rssi;