From 7b2e0b460fe5e94249aa486707176bd9c3034fd3 Mon Sep 17 00:00:00 2001 From: gaosong Date: Mon, 28 Aug 2023 15:05:07 +0800 Subject: [PATCH] randomMac Signed-off-by: gaosong --- wifi/frameworks/js/napi/src/wifi_napi_device.cpp | 7 ++++--- wifi/frameworks/native/c_adapter/src/wifi_c_device.cpp | 2 ++ wifi/interfaces/kits/c/wifi_device_config.h | 2 ++ .../wifi_manage/wifi_p2p/p2p_state_machine.cpp | 6 ++++++ .../wifi_manage/wifi_sta/sta_state_machine.cpp | 6 ++++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/wifi/frameworks/js/napi/src/wifi_napi_device.cpp b/wifi/frameworks/js/napi/src/wifi_napi_device.cpp index c9aa4aa28..20ce3300e 100644 --- a/wifi/frameworks/js/napi/src/wifi_napi_device.cpp +++ b/wifi/frameworks/js/napi/src/wifi_napi_device.cpp @@ -479,7 +479,9 @@ static napi_value JsObjToDeviceConfig(const napi_env& env, const napi_value& obj /* "creatorUid" is not supported currently */ /* "disableReason" is not supported currently */ JsObjectToInt(env, object, "netId", cppConfig.networkId); - /* "randomMacType" is not supported currently */ + int randomMacType = static_cast(WifiPrivacyConfig::RANDOMMAC); + JsObjectToInt(env, object, "randomMacType", randomMacType); + cppConfig.wifiPrivacySetting = WifiPrivacyConfig(randomMacType); /* "randomMacAddr" is not supported currently */ int ipType = static_cast(AssignIpMethod::UNASSIGNED); JsObjectToInt(env, object, "ipType", ipType); @@ -1188,8 +1190,7 @@ static void DeviceConfigToJsArray(const napi_env& env, std::vector(vecDeviceConfigs[idx].wifiPrivacySetting), result); /* not supported currently */ SetValueUtf8String(env, "randomMacAddr", std::string("").c_str(), result); if (vecDeviceConfigs[idx].wifiIpConfig.assignMethod == AssignIpMethod::STATIC) { diff --git a/wifi/frameworks/native/c_adapter/src/wifi_c_device.cpp b/wifi/frameworks/native/c_adapter/src/wifi_c_device.cpp index 8039c03ab..f4b831a54 100644 --- a/wifi/frameworks/native/c_adapter/src/wifi_c_device.cpp +++ b/wifi/frameworks/native/c_adapter/src/wifi_c_device.cpp @@ -166,6 +166,7 @@ static OHOS::Wifi::ErrCode ConvertDeviceConfigFromC( deviceConfig.keyMgmt = GetKeyMgmtBySecType(config->securityType); deviceConfig.networkId = config->netId; deviceConfig.frequency = config->freq; + deviceConfig.wifiPrivacySetting = OHOS::Wifi::WifiPrivacyConfig(config->randomMacType); /* wapiPskType is not support, don't verify now */ if (config->ipType == DHCP) { deviceConfig.wifiIpConfig.assignMethod = OHOS::Wifi::AssignIpMethod::DHCP; @@ -197,6 +198,7 @@ static OHOS::Wifi::ErrCode ConvertDeviceConfigFromCpp(const OHOS::Wifi::WifiDevi result->securityType = GetSecTypeByKeyMgmt(deviceConfig.keyMgmt); result->netId = deviceConfig.networkId; result->freq = deviceConfig.frequency; + result->randomMacType = static_cast(deviceConfig.wifiPrivacySetting); /* wapiPskType is not support now */ if (deviceConfig.wifiIpConfig.assignMethod == OHOS::Wifi::AssignIpMethod::DHCP) { result->ipType = DHCP; diff --git a/wifi/interfaces/kits/c/wifi_device_config.h b/wifi/interfaces/kits/c/wifi_device_config.h index f6e325ce0..d8f5306b2 100644 --- a/wifi/interfaces/kits/c/wifi_device_config.h +++ b/wifi/interfaces/kits/c/wifi_device_config.h @@ -201,6 +201,8 @@ typedef struct WifiDeviceConfig { IpConfig staticIp; /* 1 for hidden config */ int isHiddenSsid; + /* randomMacType */ + int randomMacType; } WifiDeviceConfig; /** diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp index 2dd11e337..c4d9b7f82 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp @@ -647,6 +647,12 @@ void P2pStateMachine::ChangeConnectedStatus(P2pConnectedState connectedState) WIFI_LOGI("ChangeConnectedStatus, connectedState: %{public}d", connectedState); WifiP2pLinkedInfo p2pInfo; WifiSettings::GetInstance().GetP2pInfo(p2pInfo); + P2pConnectedState curP2pConnectedState = p2pInfo.GetConnectState(); + if (curP2pConnectedState == connectedState) { + WIFI_LOGD("The connection status is the same, ignore this status!"); + return; + } + p2pInfo.SetConnectState(connectedState); WifiSettings::GetInstance().SaveP2pInfo(p2pInfo); groupManager.SaveP2pInfo(p2pInfo); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp index 85698b9fb..ceb2f8802 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp @@ -1410,6 +1410,7 @@ bool StaStateMachine::SetRandomMac(int networkId) std::string lastMac; std::string currentMac; if (deviceConfig.wifiPrivacySetting == WifiPrivacyConfig::DEVICEMAC) { + WifiSettings::GetInstance().GetRealMacAddress(currentMac); } else { WifiStoreRandomMac randomMacInfo; std::vector scanInfoList; @@ -2116,13 +2117,18 @@ void StaStateMachine::ConnectToNetworkProcess(InternalMessage *msg) } std::string macAddr; + std::string realMacAddr; WifiSettings::GetInstance().GetMacAddress(macAddr); + WifiSettings::GetInstance().GetRealMacAddress(realMacAddr); linkedInfo.networkId = lastNetworkId; linkedInfo.bssid = bssid; linkedInfo.ssid = deviceConfig.ssid; + linkedInfo.macType = (macAddr == realMacAddr ? + static_cast(WifiPrivacyConfig::DEVICEMAC) : static_cast(WifiPrivacyConfig::RANDOMMAC)); linkedInfo.macAddress = macAddr; linkedInfo.ifHiddenSSID = deviceConfig.hiddenSSID; lastLinkedInfo.bssid = bssid; + lastLinkedInfo.macType = static_cast(deviceConfig.wifiPrivacySetting); lastLinkedInfo.macAddress = deviceConfig.macAddress; lastLinkedInfo.ifHiddenSSID = deviceConfig.hiddenSSID; SetWifiLinkedInfo(lastNetworkId);