mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-28 03:10:48 +00:00
commit
c36946f460
@ -74,6 +74,7 @@ ohos_static_library("wifi_direct") {
|
||||
"$wifi_direct_path/command/connect_command.cpp",
|
||||
"$wifi_direct_path/command/command_factory.cpp",
|
||||
"$wifi_direct_path/command/disconnect_command.cpp",
|
||||
"$wifi_direct_path/command/force_disconnect_command.cpp",
|
||||
"$wifi_direct_path/command/negotiate_command.cpp",
|
||||
"$wifi_direct_path/command/processor_selector_factory.cpp",
|
||||
"$wifi_direct_path/command/simple_processor_selector.cpp",
|
||||
|
@ -39,6 +39,12 @@ std::shared_ptr<DisconnectCommand> CommandFactory::CreateDisconnectCommand(const
|
||||
return disconnectCreator_(info, callback);
|
||||
}
|
||||
|
||||
std::shared_ptr<ForceDisconnectCommand> CommandFactory::CreateForceDisconnectCommand(
|
||||
const WifiDirectForceDisconnectInfo &info, const WifiDirectDisconnectCallback &callback)
|
||||
{
|
||||
return std::make_shared<ForceDisconnectCommand>(info, callback);
|
||||
}
|
||||
|
||||
void CommandFactory::Register(const ConnectCreator &creator)
|
||||
{
|
||||
connectCreator_ = creator;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <memory>
|
||||
#include "connect_command.h"
|
||||
#include "disconnect_command.h"
|
||||
#include "force_disconnect_command.h"
|
||||
|
||||
namespace OHOS::SoftBus {
|
||||
class CommandFactory {
|
||||
@ -34,6 +35,8 @@ public:
|
||||
const WifiDirectConnectCallback &callback);
|
||||
std::shared_ptr<DisconnectCommand> CreateDisconnectCommand(const WifiDirectDisconnectInfo &info,
|
||||
const WifiDirectDisconnectCallback &callback);
|
||||
std::shared_ptr<ForceDisconnectCommand> CreateForceDisconnectCommand(const WifiDirectForceDisconnectInfo &info,
|
||||
const WifiDirectDisconnectCallback &callback);
|
||||
void Register(const ConnectCreator &creator);
|
||||
void Register(const DisconnectCreator &creator);
|
||||
|
||||
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "force_disconnect_command.h"
|
||||
#include "conn_log.h"
|
||||
#include "processor_selector_factory.h"
|
||||
#include "channel/auth_negotiate_channel.h"
|
||||
#include "channel/proxy_negotiate_channel.h"
|
||||
#include "channel/dummy_negotiate_channel.h"
|
||||
#include "data/link_manager.h"
|
||||
|
||||
namespace OHOS::SoftBus {
|
||||
ForceDisconnectCommand::ForceDisconnectCommand(
|
||||
const WifiDirectForceDisconnectInfo &info, const WifiDirectDisconnectCallback &callback)
|
||||
: callback_(callback)
|
||||
{
|
||||
info_.info_ = info;
|
||||
remoteDeviceId_ = info.remoteUuid;
|
||||
auto innerLink = LinkManager::GetInstance().GetReuseLink(info.linkType, info.remoteUuid);
|
||||
if (innerLink == nullptr) {
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "not find inner link, prefer input null channel");
|
||||
info_.channel_ = std::make_shared<DummyNegotiateChannel>();
|
||||
return;
|
||||
}
|
||||
|
||||
if (innerLink->GetNegotiateChannel() == nullptr) {
|
||||
if (info.negoChannel.type == NEGO_CHANNEL_AUTH) {
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "prefer input auth channel");
|
||||
info_.channel_ = std::make_shared<AuthNegotiateChannel>(info.negoChannel.handle.authHandle);
|
||||
} else if (info.negoChannel.type == NEGO_CHANNEL_COC) {
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "prefer input proxy channel");
|
||||
info_.channel_ = std::make_shared<CoCProxyNegotiateChannel>(info.negoChannel.handle.channelId);
|
||||
} else {
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "prefer input null channel");
|
||||
info_.channel_ = std::make_shared<DummyNegotiateChannel>();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "prefer inner channel");
|
||||
info_.channel_ = innerLink->GetNegotiateChannel();
|
||||
}
|
||||
|
||||
std::string ForceDisconnectCommand::GetRemoteDeviceId() const
|
||||
{
|
||||
return remoteDeviceId_;
|
||||
}
|
||||
|
||||
std::shared_ptr<WifiDirectProcessor> ForceDisconnectCommand::GetProcessor()
|
||||
{
|
||||
auto selector = ProcessorSelectorFactory::GetInstance().NewSelector();
|
||||
return (*selector)(info_.info_);
|
||||
}
|
||||
|
||||
ForceDisconnectInfo ForceDisconnectCommand::GetDisconnectInfo() const
|
||||
{
|
||||
return info_;
|
||||
}
|
||||
|
||||
std::shared_ptr<NegotiateChannel> ForceDisconnectCommand::GetNegotiateChannel() const
|
||||
{
|
||||
return info_.channel_;
|
||||
}
|
||||
|
||||
void ForceDisconnectCommand::OnSuccess() const
|
||||
{
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "requestId=%{public}u", info_.info_.requestId);
|
||||
callback_.onDisconnectSuccess(info_.info_.requestId);
|
||||
}
|
||||
|
||||
void ForceDisconnectCommand::OnFailure(int32_t reason) const
|
||||
{
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "requestId=%{public}u, reason=%{public}d", info_.info_.requestId, reason);
|
||||
callback_.onDisconnectFailure(info_.info_.requestId, reason);
|
||||
}
|
||||
} // namespace OHOS::SoftBus
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FORCE_DISCONNECT_COMMAND_H
|
||||
#define FORCE_DISCONNECT_COMMAND_H
|
||||
|
||||
#include "wifi_direct_types.h"
|
||||
#include "command/wifi_direct_command.h"
|
||||
#include "channel/negotiate_channel.h"
|
||||
|
||||
namespace OHOS::SoftBus {
|
||||
struct ForceDisconnectInfo {
|
||||
WifiDirectForceDisconnectInfo info_;
|
||||
std::shared_ptr<NegotiateChannel> channel_;
|
||||
};
|
||||
|
||||
class ForceDisconnectCommand : public WifiDirectCommand {
|
||||
public:
|
||||
ForceDisconnectCommand(const WifiDirectForceDisconnectInfo &info, const WifiDirectDisconnectCallback &callback);
|
||||
|
||||
std::string GetRemoteDeviceId() const override;
|
||||
std::shared_ptr<WifiDirectProcessor> GetProcessor() override;
|
||||
CommandType GetType() const override
|
||||
{
|
||||
return CommandType::FORCE_DISCONNECT_COMMAND;
|
||||
}
|
||||
|
||||
ForceDisconnectInfo GetDisconnectInfo() const;
|
||||
std::shared_ptr<NegotiateChannel> GetNegotiateChannel() const;
|
||||
|
||||
void OnSuccess() const;
|
||||
void OnFailure(int32_t reason) const;
|
||||
|
||||
protected:
|
||||
ForceDisconnectInfo info_;
|
||||
WifiDirectDisconnectCallback callback_;
|
||||
mutable std::string remoteDeviceId_;
|
||||
};
|
||||
} // namespace OHOS::SoftBus
|
||||
#endif
|
@ -28,6 +28,7 @@ public:
|
||||
|
||||
virtual std::shared_ptr<WifiDirectProcessor> operator()(const WifiDirectConnectInfo &info) = 0;
|
||||
virtual std::shared_ptr<WifiDirectProcessor> operator()(const WifiDirectDisconnectInfo &info) = 0;
|
||||
virtual std::shared_ptr<WifiDirectProcessor> operator()(const WifiDirectForceDisconnectInfo &info) = 0;
|
||||
virtual std::shared_ptr<WifiDirectProcessor> operator()(NegotiateMessage &msg) = 0;
|
||||
virtual std::shared_ptr<WifiDirectProcessor> operator()(
|
||||
const char *remoteNetworkId, enum WifiDirectLinkType linkType) = 0;
|
||||
|
@ -35,6 +35,11 @@ std::shared_ptr<WifiDirectProcessor> SimpleProcessorSelector::operator()(const W
|
||||
return std::make_shared<P2pV1Processor>(remoteDeviceId);
|
||||
}
|
||||
|
||||
std::shared_ptr<WifiDirectProcessor> SimpleProcessorSelector::operator()(const WifiDirectForceDisconnectInfo &info)
|
||||
{
|
||||
return std::make_shared<P2pV1Processor>(info.remoteUuid);
|
||||
}
|
||||
|
||||
std::shared_ptr<WifiDirectProcessor> SimpleProcessorSelector::operator()(NegotiateMessage &msg)
|
||||
{
|
||||
return std::make_shared<P2pV1Processor>(msg.GetRemoteDeviceId());
|
||||
|
@ -23,6 +23,7 @@ class SimpleProcessorSelector : public ProcessorSelector {
|
||||
public:
|
||||
std::shared_ptr<WifiDirectProcessor> operator()(const WifiDirectConnectInfo &info) override;
|
||||
std::shared_ptr<WifiDirectProcessor> operator()(const WifiDirectDisconnectInfo &info) override;
|
||||
std::shared_ptr<WifiDirectProcessor> operator()(const WifiDirectForceDisconnectInfo &info) override;
|
||||
std::shared_ptr<WifiDirectProcessor> operator()(NegotiateMessage &msg) override;
|
||||
std::shared_ptr<WifiDirectProcessor> operator()(
|
||||
const char *remoteNetworkId, enum WifiDirectLinkType linkType) override;
|
||||
|
@ -26,6 +26,7 @@ enum class CommandType {
|
||||
DISCONNECT_COMMAND,
|
||||
NEGOTIATE_COMMAND,
|
||||
BLE_TRIGGER_COMMAND,
|
||||
FORCE_DISCONNECT_COMMAND,
|
||||
};
|
||||
|
||||
class WifiDirectProcessor;
|
||||
|
@ -106,6 +106,7 @@ static std::map<NegotiateMessageType, std::string> g_messageNameMap = {
|
||||
{ NegotiateMessageType::CMD_CONN_V2_RESP_3, "CMD_CONN_V2_RESP_3" },
|
||||
{ NegotiateMessageType::CMD_DISCONNECT_V2_REQ, "CMD_DISCONNECT_V2_REQ" },
|
||||
{ NegotiateMessageType::CMD_DISCONNECT_V2_RESP, "CMD_DISCONNECT_V2_RESP" },
|
||||
{ NegotiateMessageType::CMD_FORCE_DISCONNECT_REQ, "CMD_FORCE_DISCONNECT_REQ" },
|
||||
{ NegotiateMessageType::CMD_CLIENT_JOIN_FAIL_NOTIFY, "CMD_CLIENT_JOIN_FAIL_NOTIFY" },
|
||||
{ NegotiateMessageType::CMD_TRIGGER_REQ, "CMD_TRIGGER_REQ" },
|
||||
{ NegotiateMessageType::CMD_TRIGGER_RESP, "CMD_TRIGGER_RESP" },
|
||||
@ -133,6 +134,7 @@ static std::map<LegacyCommandType, std::string> g_legacyMessageNameMap = {
|
||||
{ LegacyCommandType::CMD_REUSE_RESP, "CMD_REUSE_RESP" },
|
||||
{ LegacyCommandType::CMD_PC_GET_INTERFACE_INFO_REQ, "CMD_PC_GET_INTERFACE_INFO_REQ" },
|
||||
{ LegacyCommandType::CMD_PC_GET_INTERFACE_INFO_RESP, "CMD_PC_GET_INTERFACE_INFO_RESP" },
|
||||
{ LegacyCommandType::CMD_FORCE_DISCONNECT_V1_REQ, "CMD_FORCE_DISCONNECT_V1_REQ" },
|
||||
};
|
||||
|
||||
NegotiateMessage::NegotiateMessage() { }
|
||||
|
@ -38,6 +38,7 @@ enum class LegacyCommandType {
|
||||
|
||||
CMD_PC_GET_INTERFACE_INFO_REQ = 30,
|
||||
CMD_PC_GET_INTERFACE_INFO_RESP = 31,
|
||||
CMD_FORCE_DISCONNECT_V1_REQ = 32,
|
||||
};
|
||||
|
||||
enum class LegacyContentType {
|
||||
@ -67,6 +68,7 @@ enum class NegotiateMessageType {
|
||||
CMD_DISCONNECT_V2_REQ = 27,
|
||||
CMD_DISCONNECT_V2_RESP = 28,
|
||||
CMD_CLIENT_JOIN_FAIL_NOTIFY = 29,
|
||||
/* 30-49 is for LegacyCommandType*/
|
||||
|
||||
CMD_TRIGGER_REQ = 50,
|
||||
CMD_TRIGGER_RESP = 51,
|
||||
@ -77,6 +79,7 @@ enum class NegotiateMessageType {
|
||||
CMD_AUTH_HAND_SHAKE_RSP = 56,
|
||||
CMD_DETECT_LINK_REQ = 57,
|
||||
CMD_DETECT_LINK_RSP = 58,
|
||||
CMD_FORCE_DISCONNECT_REQ = 59,
|
||||
|
||||
CMD_V3_REQ = 100,
|
||||
CMD_V3_RSP = 101,
|
||||
|
@ -164,6 +164,9 @@ void P2pV1Processor::AvailableState()
|
||||
})
|
||||
.Handle<std::shared_ptr<NegotiateCommand>>([this](std::shared_ptr<NegotiateCommand> &command) {
|
||||
ProcessNegotiateCommandAtAvailableState(command);
|
||||
})
|
||||
.Handle<std::shared_ptr<ForceDisconnectCommand>>([this](std::shared_ptr<ForceDisconnectCommand> &command) {
|
||||
ProcessForceDisconnectCommand(command);
|
||||
});
|
||||
}
|
||||
|
||||
@ -320,6 +323,37 @@ void P2pV1Processor::ProcessDisconnectCommand(std::shared_ptr<DisconnectCommand>
|
||||
Terminate();
|
||||
}
|
||||
|
||||
void P2pV1Processor::ProcessForceDisconnectCommand(std::shared_ptr<ForceDisconnectCommand> &command)
|
||||
{
|
||||
Exclusive(command->GetRemoteDeviceId());
|
||||
canAcceptNegotiateData_ = false;
|
||||
auto info = command->GetDisconnectInfo();
|
||||
auto requestId = info.info_.requestId;
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "force disconnect device, requestId=%{public}d commandId=%{public}d", requestId,
|
||||
command->GetId());
|
||||
|
||||
auto innerLink = LinkManager::GetInstance().GetReuseLink(info.info_.linkType, info.info_.remoteUuid);
|
||||
if (innerLink == nullptr) {
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "link is already not exist");
|
||||
command->OnSuccess();
|
||||
Terminate();
|
||||
}
|
||||
|
||||
auto ret = SendForceDisconnectRequest(*command->GetNegotiateChannel());
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "send force disconnect request, ret=%{public}d", ret);
|
||||
if (ret == SOFTBUS_OK) {
|
||||
CONN_LOGI(
|
||||
CONN_WIFI_DIRECT, "wait for p2p auth to send data, sleep%{public}dms", DISCONNECT_WAIT_POST_REQUEST_MS);
|
||||
SoftBusSleepMs(DISCONNECT_WAIT_POST_REQUEST_MS);
|
||||
}
|
||||
|
||||
LinkManager::GetInstance().RemoveLink(InnerLink::LinkType::P2P, remoteDeviceId_);
|
||||
DestroyGroup();
|
||||
|
||||
command->OnSuccess();
|
||||
Terminate();
|
||||
}
|
||||
|
||||
void P2pV1Processor::ProcessNegotiateCommandAtAvailableState(std::shared_ptr<NegotiateCommand> &command)
|
||||
{
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "commandId=%{public}u", command->GetId());
|
||||
@ -345,6 +379,12 @@ void P2pV1Processor::ProcessNegotiateCommandAtAvailableState(std::shared_ptr<Neg
|
||||
canAcceptNegotiateData_ = false;
|
||||
ret = ProcessDisconnectRequest(command);
|
||||
break;
|
||||
case LegacyCommandType::CMD_FORCE_DISCONNECT_V1_REQ:
|
||||
reply = false;
|
||||
terminate = true;
|
||||
canAcceptNegotiateData_ = false;
|
||||
ret = ProcessForceDisconnectRequest(command);
|
||||
break;
|
||||
default:
|
||||
reply = false;
|
||||
terminate = true;
|
||||
@ -995,6 +1035,20 @@ int P2pV1Processor::SendDisconnectRequest(const NegotiateChannel &channel)
|
||||
return channel.SendMessage(request);
|
||||
}
|
||||
|
||||
int P2pV1Processor::SendForceDisconnectRequest(const NegotiateChannel &channel)
|
||||
{
|
||||
NegotiateMessage request;
|
||||
request.SetLegacyP2pCommandType(LegacyCommandType::CMD_FORCE_DISCONNECT_V1_REQ);
|
||||
auto ret =
|
||||
InterfaceManager::GetInstance().ReadInterface(InterfaceInfo::P2P, [&request](const InterfaceInfo &interface) {
|
||||
request.SetLegacyP2pMac(interface.GetBaseMac());
|
||||
return SOFTBUS_OK;
|
||||
});
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(
|
||||
ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "build request failed, error=%{public}d", ret);
|
||||
return channel.SendMessage(request);
|
||||
}
|
||||
|
||||
int P2pV1Processor::ProcessNoAvailableInterface(std::shared_ptr<NegotiateCommand> &command, LinkInfo::LinkMode myRole)
|
||||
{
|
||||
auto msg = command->GetNegotiateMessage();
|
||||
@ -1159,6 +1213,15 @@ int P2pV1Processor::ProcessDisconnectRequest(std::shared_ptr<NegotiateCommand> &
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int P2pV1Processor::ProcessForceDisconnectRequest(std::shared_ptr<NegotiateCommand> &command)
|
||||
{
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "process force disconnect request, remoteUuid=%{public}s",
|
||||
WifiDirectAnonymizeDeviceId(command->GetRemoteDeviceId()).c_str());
|
||||
LinkManager::GetInstance().RemoveLink(InnerLink::LinkType::P2P, command->GetRemoteDeviceId());
|
||||
|
||||
return DestroyGroup();
|
||||
}
|
||||
|
||||
int P2pV1Processor::ProcessGetInterfaceInfoRequest(std::shared_ptr<NegotiateCommand> &command)
|
||||
{
|
||||
auto msg = command->GetNegotiateMessage();
|
||||
@ -1633,10 +1696,11 @@ int P2pV1Processor::ChooseFrequency(int gcFreq, const std::vector<int> &gcChanne
|
||||
|
||||
int P2pV1Processor::DestroyGroup()
|
||||
{
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "start to destroy group");
|
||||
P2pAdapter::DestroyGroupParam param { IF_NAME_P2P0 };
|
||||
auto result = P2pEntity::GetInstance().DestroyGroup(param);
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(result.errorCode_ == SOFTBUS_OK, result.errorCode_, CONN_WIFI_DIRECT,
|
||||
"copy interface failed, error=%{public}d", result.errorCode_);
|
||||
"destroy group failed, error=%{public}d", result.errorCode_);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "command/connect_command.h"
|
||||
#include "command/disconnect_command.h"
|
||||
#include "command/force_disconnect_command.h"
|
||||
#include "command/negotiate_command.h"
|
||||
#include "data/inner_link.h"
|
||||
#include "entity/p2p_entity.h"
|
||||
@ -61,6 +62,7 @@ private:
|
||||
|
||||
void ProcessConnectCommand(std::shared_ptr<ConnectCommand> &command);
|
||||
void ProcessDisconnectCommand(std::shared_ptr<DisconnectCommand> &command);
|
||||
void ProcessForceDisconnectCommand(std::shared_ptr<ForceDisconnectCommand> &command);
|
||||
|
||||
void ProcessNegotiateCommandAtAvailableState(std::shared_ptr<NegotiateCommand> &command);
|
||||
void ProcessNegotiateCommandAtWaitingReqResponseState(std::shared_ptr<NegotiateCommand> &command);
|
||||
@ -93,6 +95,7 @@ private:
|
||||
int ProcessReuseRequest(std::shared_ptr<NegotiateCommand> &command);
|
||||
int ProcessReuseResponse(std::shared_ptr<NegotiateCommand> &command);
|
||||
int ProcessDisconnectRequest(std::shared_ptr<NegotiateCommand> &command);
|
||||
int ProcessForceDisconnectRequest(std::shared_ptr<NegotiateCommand> &command);
|
||||
|
||||
int ProcessGetInterfaceInfoRequest(std::shared_ptr<NegotiateCommand> &command);
|
||||
|
||||
@ -105,6 +108,7 @@ private:
|
||||
static int SendReuseRequest(const NegotiateChannel &channel);
|
||||
static int SendReuseResponse(const NegotiateChannel &channel, int32_t result);
|
||||
static int SendDisconnectRequest(const NegotiateChannel &channel);
|
||||
static int SendForceDisconnectRequest(const NegotiateChannel &channel);
|
||||
static int SendInterfaceInfoResponse(const NegotiateChannel &channel);
|
||||
static int SendNegotiateResult(const NegotiateChannel &channel, int32_t reason);
|
||||
static int SendHandShakeMessage(const NegotiateChannel &channel);
|
||||
|
@ -151,6 +151,17 @@ static int32_t DisconnectDevice(struct WifiDirectDisconnectInfo *info, struct Wi
|
||||
return OHOS::SoftBus::WifiDirectSchedulerFactory::GetInstance().GetScheduler().DisconnectDevice(*info, *callback);
|
||||
}
|
||||
|
||||
static int32_t ForceDisconnectDevice(
|
||||
struct WifiDirectForceDisconnectInfo *info, struct WifiDirectDisconnectCallback *callback)
|
||||
{
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(info != nullptr, SOFTBUS_INVALID_PARAM, CONN_WIFI_DIRECT, "info is null");
|
||||
CONN_CHECK_AND_RETURN_RET_LOGW(callback != nullptr, SOFTBUS_INVALID_PARAM, CONN_WIFI_DIRECT, "callback is null");
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "requestid=%{public}d linktype=%{public}d remoteUuid=%{public}s", info->requestId,
|
||||
info->linkType, OHOS::SoftBus::WifiDirectAnonymizeDeviceId(info->remoteUuid).c_str());
|
||||
return OHOS::SoftBus::WifiDirectSchedulerFactory::GetInstance().GetScheduler().ForceDisconnectDevice(
|
||||
*info, *callback);
|
||||
}
|
||||
|
||||
static void RegisterStatusListener(struct WifiDirectStatusListener *listener)
|
||||
{
|
||||
g_listeners.push_back(*listener);
|
||||
@ -517,6 +528,7 @@ static struct WifiDirectManager g_manager = {
|
||||
.connectDevice = ConnectDevice,
|
||||
.cancelConnectDevice = CancelConnectDevice,
|
||||
.disconnectDevice = DisconnectDevice,
|
||||
.forceDisconnectDevice = ForceDisconnectDevice,
|
||||
.registerStatusListener = RegisterStatusListener,
|
||||
.prejudgeAvailability = PrejudgeAvailability,
|
||||
.isNoneLinkByType = IsNoneLinkByType,
|
||||
|
@ -44,6 +44,8 @@ struct WifiDirectManager {
|
||||
int32_t (*connectDevice)(struct WifiDirectConnectInfo *info, struct WifiDirectConnectCallback *callback);
|
||||
int32_t (*cancelConnectDevice)(const struct WifiDirectConnectInfo *info);
|
||||
int32_t (*disconnectDevice)(struct WifiDirectDisconnectInfo *info, struct WifiDirectDisconnectCallback *callback);
|
||||
int32_t (*forceDisconnectDevice)(
|
||||
struct WifiDirectForceDisconnectInfo *info, struct WifiDirectDisconnectCallback *callback);
|
||||
void (*registerStatusListener)(struct WifiDirectStatusListener *listener);
|
||||
int32_t (*prejudgeAvailability)(const char *remoteNetworkId, enum WifiDirectLinkType linkType);
|
||||
bool (*isNoneLinkByType)(enum WifiDirectLinkType linkType);
|
||||
|
@ -84,6 +84,26 @@ int WifiDirectScheduler::DisconnectDevice(WifiDirectDisconnectInfo &info, WifiDi
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WifiDirectScheduler::ForceDisconnectDevice(
|
||||
WifiDirectForceDisconnectInfo &info, WifiDirectDisconnectCallback &callback)
|
||||
{
|
||||
auto command = CommandFactory::GetInstance().CreateForceDisconnectCommand(info, callback);
|
||||
CONN_LOGI(CONN_WIFI_DIRECT,
|
||||
"requestId=%{public}d pid=%{public}d networkId=%{public}s remoteUuid=%{public}s linktype=%{public}d",
|
||||
info.requestId, info.pid,
|
||||
WifiDirectAnonymizeDeviceId(WifiDirectUtils::UuidToNetworkId(command->GetRemoteDeviceId())).c_str(),
|
||||
WifiDirectAnonymizeDeviceId(command->GetRemoteDeviceId()).c_str(), info.linkType);
|
||||
std::shared_ptr<WifiDirectExecutor> executor;
|
||||
auto ret = ScheduleActiveCommand(command, executor);
|
||||
CONN_CHECK_AND_RETURN_RET_LOGE(
|
||||
ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "schedule active command failed, ret=%{public}d", ret);
|
||||
if (executor != nullptr) {
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "commandId=%{public}u", command->GetId());
|
||||
executor->SendEvent(command);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool WifiDirectScheduler::ProcessNextCommand(WifiDirectExecutor *executor,
|
||||
std::shared_ptr<WifiDirectProcessor> &processor)
|
||||
{
|
||||
|
@ -41,6 +41,7 @@ public:
|
||||
int ConnectDevice(const std::shared_ptr<ConnectCommand> &command, bool markRetried = false);
|
||||
int CancelConnectDevice(const WifiDirectConnectInfo &info);
|
||||
int DisconnectDevice(WifiDirectDisconnectInfo &info, WifiDirectDisconnectCallback &callback);
|
||||
int ForceDisconnectDevice(WifiDirectForceDisconnectInfo &info, WifiDirectDisconnectCallback &callback);
|
||||
|
||||
template<typename Command>
|
||||
void ProcessNegotiateData(const std::string &remoteDeviceId, Command &command)
|
||||
|
@ -182,6 +182,14 @@ struct WifiDirectDisconnectInfo {
|
||||
struct WifiDirectNegotiateChannel negoChannel;
|
||||
};
|
||||
|
||||
struct WifiDirectForceDisconnectInfo {
|
||||
uint32_t requestId;
|
||||
int32_t pid;
|
||||
char remoteUuid[UUID_BUF_LEN];
|
||||
enum WifiDirectLinkType linkType;
|
||||
struct WifiDirectNegotiateChannel negoChannel;
|
||||
};
|
||||
|
||||
struct WifiDirectConnectCallback {
|
||||
void (*onConnectSuccess)(uint32_t requestId, const struct WifiDirectLink *link);
|
||||
void (*onConnectFailure)(uint32_t requestId, int32_t reason);
|
||||
|
@ -157,6 +157,7 @@ ohos_unittest("WifiDirectManagerCppTest") {
|
||||
"$wifi_direct_cpp_path/command/command_factory.cpp",
|
||||
"$wifi_direct_cpp_path/command/connect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/disconnect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/force_disconnect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/negotiate_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/processor_selector_factory.cpp",
|
||||
"$wifi_direct_cpp_path/command/simple_processor_selector.cpp",
|
||||
|
@ -83,6 +83,7 @@ ohos_unittest("P2pAdapterTest") {
|
||||
"$wifi_direct_cpp_path/command/command_factory.cpp",
|
||||
"$wifi_direct_cpp_path/command/connect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/disconnect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/force_disconnect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/negotiate_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/processor_selector_factory.cpp",
|
||||
"$wifi_direct_cpp_path/command/simple_processor_selector.cpp",
|
||||
|
@ -194,6 +194,7 @@ ohos_unittest("LinkManagerTest") {
|
||||
"$wifi_direct_cpp_path/command/command_factory.cpp",
|
||||
"$wifi_direct_cpp_path/command/connect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/disconnect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/force_disconnect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/negotiate_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/processor_selector_factory.cpp",
|
||||
"$wifi_direct_cpp_path/command/simple_processor_selector.cpp",
|
||||
|
@ -82,6 +82,7 @@ ohos_unittest("P2pEntityTest") {
|
||||
"$wifi_direct_cpp_path/command/command_factory.cpp",
|
||||
"$wifi_direct_cpp_path/command/connect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/disconnect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/force_disconnect_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/negotiate_command.cpp",
|
||||
"$wifi_direct_cpp_path/command/processor_selector_factory.cpp",
|
||||
"$wifi_direct_cpp_path/command/simple_processor_selector.cpp",
|
||||
|
@ -66,6 +66,7 @@ processorv1_ut_sources = [
|
||||
"$wifi_direct_path/command/command_factory.cpp",
|
||||
"$wifi_direct_path/command/connect_command.cpp",
|
||||
"$wifi_direct_path/command/disconnect_command.cpp",
|
||||
"$wifi_direct_path/command/force_disconnect_command.cpp",
|
||||
"$wifi_direct_path/command/negotiate_command.cpp",
|
||||
"$wifi_direct_path/command/processor_selector_factory.cpp",
|
||||
"$wifi_direct_path/command/simple_processor_selector.cpp",
|
||||
|
Loading…
Reference in New Issue
Block a user