mirror of
https://gitee.com/openharmony/communication_wifi.git
synced 2024-11-23 15:10:16 +00:00
!3105 [master] 解决p2p无法上报连接成功状态和pc无法连接OpenHarmony设备问题
Merge pull request !3105 from kangwei/kw_master_20241011
This commit is contained in:
commit
5cb0500cac
@ -83,6 +83,7 @@ static ErrCode GroupInfosToJs(const napi_env& env, const WifiP2pGroupInfo& group
|
||||
}
|
||||
}
|
||||
SetValueUtf8String(env, "goIpAddress", groupInfo.GetGoIpAddress().c_str(), result);
|
||||
SetValueUtf8String(env, "gcIpAddress", groupInfo.GetGcIpAddress().c_str(), result);
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -599,6 +599,7 @@ void WifiP2pProxy::ReadWifiP2pDeviceData(MessageParcel &reply, WifiP2pDevice &de
|
||||
device.SetWpsConfigMethod(reply.ReadInt32());
|
||||
device.SetDeviceCapabilitys(reply.ReadInt32());
|
||||
device.SetGroupCapabilitys(reply.ReadInt32());
|
||||
device.SetGroupAddress(reply.ReadString());
|
||||
}
|
||||
|
||||
void WifiP2pProxy::WriteWifiP2pGroupData(MessageParcel &data, const WifiP2pGroupInfo &info) const
|
||||
@ -635,6 +636,7 @@ void WifiP2pProxy::ReadWifiP2pGroupData(MessageParcel &reply, WifiP2pGroupInfo &
|
||||
info.SetP2pGroupStatus(static_cast<P2pGroupStatus>(reply.ReadInt32()));
|
||||
info.SetNetworkId(reply.ReadInt32());
|
||||
info.SetGoIpAddress(reply.ReadString());
|
||||
info.SetGcIpAddress(reply.ReadString());
|
||||
|
||||
constexpr int MAX_SIZE = 512;
|
||||
int size = reply.ReadInt32();
|
||||
|
@ -111,6 +111,7 @@ typedef struct WifiP2pGroupInfo {
|
||||
WifiP2pDevice clientDevices[MAX_DEVICES_NUM];
|
||||
int clientDevicesSize; /* the true size of clientDevices array */
|
||||
char goIpAddress[IP_ADDR_STR_LEN];
|
||||
char gcIpAddress[IP_ADDR_STR_LEN];
|
||||
} WifiP2pGroupInfo;
|
||||
|
||||
typedef struct WifiP2pLinkedInfo {
|
||||
|
@ -648,6 +648,7 @@ static void DealP2pDeviceInfoCbk(int event, Context *context)
|
||||
}
|
||||
if (event == AP_STA_DISCONNECTED_EVENT || event == AP_STA_CONNECTED_EVENT) {
|
||||
WriteStr(context, cbmsg->msg.deviceInfo.p2pDeviceAddress);
|
||||
WriteStr(context, cbmsg->msg.deviceInfo.p2pGroupAddress);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -243,7 +243,8 @@ bool GroupFormedState::ProcessDisconnectEvt(const InternalMessagePtr msg) const
|
||||
WIFI_LOGE("Disconnect:Failed to obtain client information.");
|
||||
return EXECUTED;
|
||||
}
|
||||
|
||||
WIFI_LOGI("ProcessDisconnectEvt device disconnected, deviceAddr: %{private}s, groupAddr: %{private}s",
|
||||
device.GetDeviceAddress().c_str(), device.GetGroupAddress().c_str());
|
||||
IpPool::ReleaseIp(device.GetDeviceAddress());
|
||||
device.SetP2pDeviceStatus(P2pDeviceStatus::PDS_AVAILABLE);
|
||||
deviceManager.UpdateDeviceStatus(device); // used for peers change event querying device infos
|
||||
@ -253,7 +254,7 @@ bool GroupFormedState::ProcessDisconnectEvt(const InternalMessagePtr msg) const
|
||||
WIFI_LOGE("Connect: remove client info faild");
|
||||
}
|
||||
auto iter = std::find(p2pStateMachine.curClientList.begin(),
|
||||
p2pStateMachine.curClientList.end(), device.GetDeviceAddress());
|
||||
p2pStateMachine.curClientList.end(), device.GetDeviceAddress());
|
||||
if (iter != p2pStateMachine.curClientList.end()) {
|
||||
p2pStateMachine.curClientList.erase(iter);
|
||||
} else {
|
||||
@ -278,13 +279,15 @@ bool GroupFormedState::ProcessConnectEvt(const InternalMessagePtr msg) const
|
||||
WIFI_LOGE("Connect:Failed to obtain client information.");
|
||||
return EXECUTED;
|
||||
}
|
||||
|
||||
WIFI_LOGI("GroupFormedState ProcessConnectEvt deviceAddr: %{private}s, groupAddr: %{private}s",
|
||||
device.GetDeviceAddress().c_str(), device.GetGroupAddress().c_str());
|
||||
if (WifiErrorNo::WIFI_HAL_OPT_OK !=
|
||||
WifiP2PHalInterface::GetInstance().SetP2pGroupIdle(groupManager.GetCurrentGroup().GetInterface(), 0)) {
|
||||
WIFI_LOGE("fail to set GO Idle time.");
|
||||
}
|
||||
device.SetP2pDeviceStatus(P2pDeviceStatus::PDS_CONNECTED);
|
||||
deviceManager.UpdateDeviceStatus(device);
|
||||
deviceManager.UpdateGroupAddress(device);
|
||||
WifiP2pDevice memberPeer = deviceManager.GetDevices(device.GetDeviceAddress());
|
||||
if (memberPeer.IsValid()) {
|
||||
memberPeer.SetP2pDeviceStatus(P2pDeviceStatus::PDS_CONNECTED);
|
||||
|
@ -340,6 +340,7 @@ void P2pMonitor::WpaEventDeviceFound(const HalP2pDeviceFound &deviceInfo) const
|
||||
WIFI_LOGE("Missing device name!");
|
||||
return;
|
||||
}
|
||||
device.SetGroupAddress(deviceInfo.srcAddress);
|
||||
device.SetDeviceAddress(deviceInfo.p2pDeviceAddress);
|
||||
device.SetPrimaryDeviceType(deviceInfo.primaryDeviceType);
|
||||
device.SetDeviceCapabilitys(deviceInfo.deviceCapabilities);
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "wifi_common_util.h"
|
||||
#include "arp_checker.h"
|
||||
#include "mac_address.h"
|
||||
#include "wifi_settings.h"
|
||||
|
||||
DEFINE_WIFILOG_P2P_LABEL("P2pStateMachine");
|
||||
#define P2P_PREFIX_LEN 4
|
||||
@ -339,29 +340,21 @@ void P2pStateMachine::SetWifiP2pInfoWhenGroupFormed(const std::string &groupOwne
|
||||
groupManager.SaveP2pInfo(p2pInfo);
|
||||
}
|
||||
|
||||
ErrCode P2pStateMachine::AddClientInfo(std::vector<GcInfo> &gcInfos)
|
||||
bool P2pStateMachine::IsMatchClientDevice(std::vector<GcInfo> &gcInfos, WifiP2pDevice &device, GcInfo &gcInfo)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_gcJoinmutex);
|
||||
WifiP2pGroupInfo groupInfo = groupManager.GetCurrentGroup();
|
||||
if (!groupInfo.IsGroupOwner()) {
|
||||
return ErrCode::WIFI_OPT_FAILED;
|
||||
}
|
||||
std::vector<OHOS::Wifi::WifiP2pDevice> deviceList;
|
||||
if (deviceManager.GetDevicesList(deviceList) <= 0) {
|
||||
WIFI_LOGE("deviceList.size <=0 ");
|
||||
return WIFI_OPT_FAILED;
|
||||
WIFI_LOGE("deviceList.size <= 0 ");
|
||||
return false;
|
||||
}
|
||||
WifiP2pDevice curDev;
|
||||
GcInfo curGc;
|
||||
|
||||
bool isFound = false;
|
||||
for (auto iterClientList : curClientList) {
|
||||
for (auto iterDeviceList : deviceList) {
|
||||
if (iterDeviceList.GetDeviceAddress() == iterClientList) {
|
||||
curDev = iterDeviceList;
|
||||
auto p2pDeviceMac = curDev.GetDeviceAddress();
|
||||
auto p2pGroupMac = curDev.GetGroupAddress();
|
||||
curGc = MatchDevInGcInfos(p2pDeviceMac, p2pGroupMac, gcInfos);
|
||||
isFound = !(curGc.ip.empty());
|
||||
for (auto iterClientAddress : curClientList) {
|
||||
for (auto iterDevice : deviceList) {
|
||||
if (iterDevice.GetDeviceAddress() == iterClientAddress) {
|
||||
device = iterDevice;
|
||||
gcInfo = MatchDevInGcInfos(device.GetDeviceAddress(), device.GetGroupAddress(), gcInfos);
|
||||
isFound = !(gcInfo.ip.empty());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -369,20 +362,42 @@ ErrCode P2pStateMachine::AddClientInfo(std::vector<GcInfo> &gcInfos)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isFound) {
|
||||
return isFound;
|
||||
}
|
||||
|
||||
ErrCode P2pStateMachine::AddClientInfo(std::vector<GcInfo> &gcInfos)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_gcJoinmutex);
|
||||
WifiP2pGroupInfo groupInfo = groupManager.GetCurrentGroup();
|
||||
if (!groupInfo.IsGroupOwner()) {
|
||||
WIFI_LOGE("this device is not Group owner");
|
||||
return ErrCode::WIFI_OPT_FAILED;
|
||||
} else {
|
||||
auto iter = std::find(curClientList.begin(), curClientList.end(), curDev.GetDeviceAddress().c_str());
|
||||
}
|
||||
WifiP2pDevice device;
|
||||
GcInfo gcInfo;
|
||||
if (!IsMatchClientDevice(gcInfos, device, gcInfo)) {
|
||||
WIFI_LOGE("current connected device not found the Gc");
|
||||
return ErrCode::WIFI_OPT_FAILED;
|
||||
}
|
||||
auto iter = std::find(curClientList.begin(), curClientList.end(), device.GetDeviceAddress().c_str());
|
||||
if (iter != curClientList.end()) {
|
||||
curClientList.erase(iter);
|
||||
}
|
||||
|
||||
WifiP2pLinkedInfo linkedInfo;
|
||||
WifiConfigCenter::GetInstance().GetP2pInfo(linkedInfo);
|
||||
linkedInfo.ClearClientInfo();
|
||||
linkedInfo.AddClientInfoList(curGc.mac, curGc.ip, curDev.GetDeviceName());
|
||||
|
||||
std::string gcDeviceAddr = device.GetDeviceAddress();
|
||||
std::string gcHostName = device.GetDeviceName();
|
||||
groupInfo.SetGcIpAddress(gcInfo.ip);
|
||||
groupManager.SetCurrentGroup(WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO, groupInfo);
|
||||
linkedInfo.AddClientInfoList(gcDeviceAddr, gcInfo.ip, gcHostName);
|
||||
if (WifiConfigCenter::GetInstance().SaveP2pInfo(linkedInfo) == 0) {
|
||||
groupManager.SaveP2pInfo(linkedInfo);
|
||||
BroadcastP2pGcJoinGroup(curGc);
|
||||
GcInfo joinGc;
|
||||
joinGc.ip = gcInfo.ip;
|
||||
joinGc.host = device.GetDeviceName();
|
||||
joinGc.mac = device.GetDeviceAddress();
|
||||
BroadcastP2pGcJoinGroup(joinGc);
|
||||
return ErrCode::WIFI_OPT_SUCCESS;
|
||||
}
|
||||
return ErrCode::WIFI_OPT_FAILED;
|
||||
|
@ -422,6 +422,7 @@ private:
|
||||
virtual void NotifyUserInvitationReceivedMessage();
|
||||
virtual ErrCode AddClientInfo(std::vector<GcInfo> &gcInfos);
|
||||
virtual ErrCode RemoveClientInfo(std::string mac);
|
||||
virtual bool IsMatchClientDevice(std::vector<GcInfo> &gcInfos, WifiP2pDevice &device, GcInfo &gcInfo);
|
||||
|
||||
private:
|
||||
virtual void P2pConnectByShowingPin(const WifiP2pConfigInternal &config) const;
|
||||
|
@ -125,6 +125,7 @@ bool WifiP2pDeviceManager::UpdateDeviceSupplicantInf(const WifiP2pDevice &device
|
||||
it->SetWpsConfigMethod(device.GetWpsConfigMethod());
|
||||
it->SetDeviceCapabilitys(device.GetDeviceCapabilitys());
|
||||
it->SetGroupCapabilitys(device.GetGroupCapabilitys());
|
||||
it->SetGroupAddress(device.GetGroupAddress());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -136,6 +137,9 @@ bool WifiP2pDeviceManager::UpdateDeviceSupplicantInf(const WifiP2pDevice &device
|
||||
device.GetDeviceAddress(), "");
|
||||
#endif
|
||||
/* add its if not found . be careful of the return value */
|
||||
LOGI("UpdateDeviceSupplicantInf deviceAddr: %{private}s, groupAddr: %{private}s, deviceName: %{private}s",
|
||||
updateDevice.GetDeviceAddress().c_str(), updateDevice.GetGroupAddress().c_str(),
|
||||
updateDevice.GetDeviceName().c_str());
|
||||
p2pDevices.push_back(updateDevice);
|
||||
return true;
|
||||
}
|
||||
|
@ -432,11 +432,12 @@ ErrCode WifiP2pServiceImpl::CreateGroup(const WifiP2pConfig &config)
|
||||
}
|
||||
uint32_t passLen = config.GetPassphrase().length();
|
||||
if ((!config.GetPassphrase().empty()) &&
|
||||
(passLen < WIFI_P2P_PASSPHRASE_MIN_LEN || passLen > WIFI_P2P_PASSPHRASE_MAX_LEN)) {
|
||||
(passLen < WIFI_P2P_PASSPHRASE_MIN_LEN || passLen > WIFI_P2P_PASSPHRASE_MAX_LEN)) {
|
||||
WIFI_LOGE("CreateGroup:VerifyPassphrase length failed!");
|
||||
return WIFI_OPT_INVALID_PARAM;
|
||||
}
|
||||
if (CheckMacIsValid(config.GetDeviceAddress()) != 0) {
|
||||
if ((!config.GetDeviceAddress().empty()) &&
|
||||
(CheckMacIsValid(config.GetDeviceAddress()) != 0)) {
|
||||
WIFI_LOGE("CreateGroup:VerifyDeviceAddress failed!");
|
||||
return WIFI_OPT_INVALID_PARAM;
|
||||
}
|
||||
|
@ -671,6 +671,7 @@ void WifiP2pStub::WriteWifiP2pDeviceData(MessageParcel &reply, const WifiP2pDevi
|
||||
reply.WriteInt32(device.GetWpsConfigMethod());
|
||||
reply.WriteInt32(device.GetDeviceCapabilitys());
|
||||
reply.WriteInt32(device.GetGroupCapabilitys());
|
||||
reply.WriteString(device.GetGroupAddress());
|
||||
}
|
||||
|
||||
bool WifiP2pStub::ReadWifiP2pGroupData(MessageParcel &data, WifiP2pGroupInfo &info)
|
||||
@ -712,6 +713,7 @@ void WifiP2pStub::WriteWifiP2pGroupData(MessageParcel &reply, const WifiP2pGroup
|
||||
reply.WriteInt32(static_cast<int>(info.GetP2pGroupStatus()));
|
||||
reply.WriteInt32(info.GetNetworkId());
|
||||
reply.WriteString(info.GetGoIpAddress());
|
||||
reply.WriteString(info.GetGcIpAddress());
|
||||
std::vector<WifiP2pDevice> deviceVec = info.GetClientDevices();
|
||||
reply.WriteInt32(deviceVec.size());
|
||||
for (auto it = deviceVec.begin(); it != deviceVec.end(); ++it) {
|
||||
@ -1099,4 +1101,4 @@ void WifiP2pStub::OnHid2dIsWideBandwidthSupported(
|
||||
}
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user