mirror of
https://gitee.com/openharmony/communication_wifi.git
synced 2024-12-04 21:47:00 +00:00
no chagne random mac when dataclone
Signed-off-by: WangYusen <wangyusen8@huawei.com>
This commit is contained in:
parent
ea65fdcaf8
commit
d766e6aab3
@ -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
|
@ -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()
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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)";
|
||||
|
Loading…
Reference in New Issue
Block a user