no chagne random mac when dataclone

Signed-off-by: WangYusen <wangyusen8@huawei.com>
This commit is contained in:
WangYusen 2024-11-09 21:00:37 +08:00
parent ea65fdcaf8
commit d766e6aab3
7 changed files with 88 additions and 7 deletions

View File

@ -186,6 +186,33 @@ struct StationInfo {
int bssidType; /* bssid type */
std::string ipAddr; /* Device IP address */
};
struct HotspotMacConfig {
inline void SetCallingBundleName(std::string &bundleName)
{
callingBundleName = bundleName;
}
inline std::string GetCallingBundleName() const
{
return callingBundleName;
}
inline void SetRandomMac(std::string &mac)
{
randomMac = mac;
}
inline std::string GetRandomMac() const
{
return randomMac;
}
private:
std::string callingBundleName;
std::string randomMac;
};
} // namespace Wifi
} // namespace OHOS
#endif

View File

@ -429,16 +429,36 @@ void ApStartedState::ProcessCmdSetHotspotIdleTimeout(InternalMessagePtr msg)
void ApStartedState::SetRandomMac() const
{
HotspotMacConfig macConfig;
WifiConfigCenter::GetInstance().GetHotspotMacConfig(macConfig, m_id);
std::string macAddress;
WifiRandomMacHelper::GenerateRandomMacAddress(macAddress);
if (MacAddress::IsValidMac(macAddress.c_str())) {
bool isDataClone = macConfig.GetCallingBundleName() ==
WifiSettings::GetInstance().GetPackageName("DATA_CLONE").c_str();
if (isDataClone && !macConfig.GetRandomMac().empty()) {
macAddress = macConfig.GetRandomMac();
} else {
WifiRandomMacHelper::GenerateRandomMacAddress(macAddress);
}
do {
if (!MacAddress::IsValidMac(macAddress.c_str())) {
WIFI_LOGE("%{public}s: macAddress is invalid", __func__);
break;
}
if (WifiApHalInterface::GetInstance().SetConnectMacAddr(
WifiConfigCenter::GetInstance().GetApIfaceName(), macAddress) != WIFI_HAL_OPT_OK) {
LOGE("%{public}s: failed to set ap MAC address:%{private}s", __func__, macAddress.c_str());
WIFI_LOGE("%{public}s: failed to set ap MAC address:%{private}s", __func__, macAddress.c_str());
break;
}
} else {
LOGE("%{public}s: macAddress is invalid", __func__);
}
if (isDataClone && macConfig.GetRandomMac().empty()) {
macConfig.SetRandomMac(macAddress);
WifiConfigCenter::GetInstance().SetHotspotMacConfig(macConfig, m_id);
}
return;
} while (0);
}
bool ApStartedState::SetCountry()

View File

@ -409,6 +409,16 @@ ErrCode WifiHotspotServiceImpl::EnableHotspot(const ServiceType type)
return errCode;
}
std::string bundleName = "";
if (!GetBundleNameByUid(GetCallingUid(), bundleName)) {
WIFI_LOGE("GetBundleNameByUid failed");
}
WIFI_LOGI("%{public}s calling inst %{public}d EnableHotspot", bundleName.c_str(), m_id);
HotspotMacConfig config;
WifiConfigCenter::GetInstance().GetHotspotMacConfig(config, m_id);
config.SetCallingBundleName(bundleName);
WifiConfigCenter::GetInstance().SetHotspotMacConfig(config, m_id);
return WifiManager::GetInstance().GetWifiTogglerManager()->SoftapToggled(1, m_id);
}

View File

@ -1391,5 +1391,22 @@ std::set<int> WifiConfigCenter::GetAllWifiLinkedNetworkId()
}
return wifiLinkedNetworkId;
}
int WifiConfigCenter::SetHotspotMacConfig(const HotspotMacConfig &config, int id)
{
std::unique_lock<std::mutex> lock(mApMutex);
mHotspotMacConfig[id] = config;
return 0;
}
int WifiConfigCenter::GetHotspotMacConfig(HotspotMacConfig &config, int id)
{
std::unique_lock<std::mutex> lock(mApMutex);
auto iter = mHotspotMacConfig.find(id);
if (iter != mHotspotMacConfig.end()) {
config = iter->second;
}
return 0;
}
} // namespace Wifi
} // namespace OHOS

View File

@ -321,6 +321,10 @@ public:
void RemoveMacAddrPairInfo(WifiMacAddrInfoType type, std::string bssid);
void UpdateLinkedInfo(int instId = 0);
int SetHotspotMacConfig(const HotspotMacConfig &config, int id = 0);
int GetHotspotMacConfig(HotspotMacConfig &config, int id = 0);
private:
WifiConfigCenter();
std::string GetPairMacAddress(std::map<WifiMacAddrInfo, std::string>& macAddrInfoMap,
@ -373,6 +377,7 @@ private:
std::map <int, std::atomic<int>> mHotspotState;
std::map<int, PowerModel> powerModel;
std::map<std::string, StationInfo> mConnectStationInfo;
std::map<int, HotspotMacConfig> mHotspotMacConfig;
// P2P
std::mutex mP2pMutex;

View File

@ -347,7 +347,7 @@ private:
WifiConfigFileImpl<HotspotConfig> mSavedHotspotConfig;
std::map<std::string, StationInfo> mBlockListInfo;
WifiConfigFileImpl<StationInfo> mSavedBlockInfo;
// P2P
std::mutex mP2pMutex;
std::vector<WifiP2pGroupInfo> mGroupInfoList;

View File

@ -147,6 +147,8 @@
"OHOS::Wifi::WifiConfigCenter::SetApMidState(OHOS::Wifi::WifiOprMidState, int)";
"OHOS::Wifi::WifiConfigCenter::GetHotspotState(int)";
"OHOS::Wifi::WifiConfigCenter::SetHotspotState(int, int)";
"OHOS::Wifi::WifiConfigCenter::SetHotspotMacConfig(OHOS::Wifi::HotspotMacConfig const&, int)";
"OHOS::Wifi::WifiConfigCenter::GetHotspotMacConfig(OHOS::Wifi::HotspotMacConfig&, int)";
"OHOS::Wifi::WifiConfigCenter::SetPowerModel(OHOS::Wifi::PowerModel const&, int)";
"OHOS::Wifi::WifiConfigCenter::GetPowerModel(OHOS::Wifi::PowerModel&, int)";
"OHOS::Wifi::WifiConfigCenter::GetStationList(std::__h::vector<OHOS::Wifi::StationInfo, std::__h::allocator<OHOS::Wifi::StationInfo>>&, int)";