wifi rpt - use p2p as hotspot when wifi chip not support coexist of ap and sta

Signed-off-by: gusihan <igusihan@qq.com>
This commit is contained in:
gusihan 2024-09-13 21:48:37 +08:00
parent 121d0319c3
commit 31bafac57e
69 changed files with 2400 additions and 501 deletions

View File

@ -471,6 +471,8 @@ if (defined(ohos_lite)) {
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/rpt_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/rpt_manager_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp",
@ -615,6 +617,10 @@ if (defined(ohos_lite)) {
defines += [ "FEATURE_P2P_SUPPORT" ]
}
if (wifi_feature_with_rpt) {
defines += [ "FEATURE_RPT_SUPPORT" ]
}
if (wifi_feature_with_ap_extension) {
defines += [ "FEATURE_AP_EXTENSION" ]
}

View File

@ -110,6 +110,11 @@ ohos_shared_library("wifi_ap_service") {
defines += [ "SUPPORT_LOCAL_RANDOM_MAC" ]
}
if (wifi_feature_with_hdi_chip_supported) {
defines += [ "HDI_CHIP_INTERFACE_SUPPORT" ]
external_deps += [ "drivers_interface_wlan:libchip_proxy_1.0" ]
}
if (defined(global_parts_info) &&
defined(global_parts_info.powermgr_battery_manager)) {
external_deps += [ "battery_manager:batterysrv_client" ]

View File

@ -32,22 +32,50 @@ ApStationsManager::ApStationsManager(int id) : m_id(id)
ApStationsManager::~ApStationsManager()
{}
#ifdef HDI_CHIP_INTERFACE_SUPPORT
static WifiErrorNo SetMacFilter(std::string mac, int mid)
{
std::vector<StationInfo> blockList;
WifiSettings::GetInstance().GetBlockList(blockList, mid);
std::vector<std::string> blockMacs;
for (auto& sta : blockList) {
if (mac != sta.bssid) {
blockMacs.push_back(sta.bssid);
}
}
std::string ifname = WifiConfigCenter::GetInstance().GetApIfaceName();
WIFI_LOGI("SetMacFilter size:%{public}d", static_cast<int>(blockMacs.size()));
return WifiApHalInterface::GetInstance().SetSoftApBlockList(ifname, blockMacs);
}
#endif
bool ApStationsManager::AddBlockList(const StationInfo &staInfo) const
{
#ifdef HDI_CHIP_INTERFACE_SUPPORT
WifiApHalInterface::GetInstance().DisAssociateSta(WifiConfigCenter::GetInstance().GetApIfaceName(), staInfo.bssid);
return SetMacFilter("", m_id);
#else
if (WifiApHalInterface::GetInstance().AddBlockByMac(staInfo.bssid, m_id) != WifiErrorNo::WIFI_HAL_OPT_OK) {
WIFI_LOGE("Instance is %{public}d failed to add block.", m_id);
return false;
}
return true;
#endif
}
bool ApStationsManager::DelBlockList(const StationInfo &staInfo) const
{
#ifdef HDI_CHIP_INTERFACE_SUPPORT
return SetMacFilter(staInfo.bssid, m_id);
#else
if (WifiApHalInterface::GetInstance().DelBlockByMac(staInfo.bssid, m_id) != WifiErrorNo::WIFI_HAL_OPT_OK) {
WIFI_LOGE("Instance is %{public}d failed to del block.", m_id);
return false;
}
return true;
#endif
}
bool ApStationsManager::AddAssociationStation(const StationInfo &staInfo) const
@ -70,6 +98,9 @@ bool ApStationsManager::DelAssociationStation(const StationInfo &staInfo) const
bool ApStationsManager::EnableAllBlockList() const
{
#ifdef HDI_CHIP_INTERFACE_SUPPORT
return SetMacFilter("", m_id);
#else
std::vector<StationInfo> results;
if (WifiSettings::GetInstance().GetBlockList(results, m_id)) {
WIFI_LOGE("Instance is %{public}d failed to get blocklist.", m_id);
@ -85,6 +116,7 @@ bool ApStationsManager::EnableAllBlockList() const
}
}
return ret;
#endif
}
void ApStationsManager::StationLeave(const std::string &mac) const

View File

@ -54,8 +54,7 @@ ErrCode WifiHotspotServiceImpl::IsHotspotActive(bool &bActive)
WIFI_LOGE("IsHotspotActive:VerifyGetWifiInfoPermission PERMISSION_DENIED!");
return WIFI_OPT_PERMISSION_DENIED;
}
bActive = IsApServiceRunning();
bActive = IsApServiceRunning() || IsRptRunning();
return WIFI_OPT_SUCCESS;
}
@ -257,18 +256,21 @@ ErrCode WifiHotspotServiceImpl::GetStationList(std::vector<StationInfo> &result)
WIFI_LOGE("GetStationList:VerifyManageWifiHotspotPermission PERMISSION_DENIED!");
return WIFI_OPT_PERMISSION_DENIED;
}
if (!IsApServiceRunning()) {
ErrCode errCode;
if (IsApServiceRunning()) {
IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
if (pService == nullptr) {
WIFI_LOGE("Instance %{public}d get hotspot service is null!", m_id);
return WIFI_OPT_AP_NOT_OPENED;
}
errCode = pService->GetStationList(result);
} else if (IsRptRunning()) {
auto rptManager = WifiManager::GetInstance().GetRptInterface(m_id);
errCode = (rptManager != nullptr) ? rptManager->GetStationList(result) : WIFI_OPT_FAILED;
} else {
WIFI_LOGE("Instance %{public}d hotspot service is not running!", m_id);
return WIFI_OPT_AP_NOT_OPENED;
}
IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
if (pService == nullptr) {
WIFI_LOGE("Instance %{public}d get hotspot service is null!", m_id);
return WIFI_OPT_AP_NOT_OPENED;
}
ErrCode errCode = pService->GetStationList(result);
#ifdef SUPPORT_RANDOM_MAC_ADDR
if (WifiPermissionUtils::VerifyGetWifiPeersMacPermission() == PERMISSION_DENIED) {
WIFI_LOGI("%{public}s: GET_WIFI_PEERS_MAC PERMISSION_DENIED", __func__);
@ -425,6 +427,34 @@ ErrCode WifiHotspotServiceImpl::DisableHotspot(const ServiceType type)
return WifiManager::GetInstance().GetWifiTogglerManager()->SoftapToggled(0, m_id);
}
static ErrCode AddApBlockList(int m_id, StationInfo& updateInfo)
{
IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
if (pService == nullptr) {
WIFI_LOGE("Instance %{public}d get hotspot service is null!", m_id);
return WIFI_OPT_AP_NOT_OPENED;
}
if (pService->AddBlockList(updateInfo) != WIFI_OPT_SUCCESS) {
WIFI_LOGE("AddBlockList: request add hotspot blocklist failed!");
return WIFI_OPT_FAILED;
}
if (pService->DisconnetStation(updateInfo) != WIFI_OPT_SUCCESS) {
WIFI_LOGE("AddBlockList: request disconnet station failed!");
return WIFI_OPT_FAILED;
}
return WIFI_OPT_SUCCESS;
}
static ErrCode AddRptBlockList(int m_id, StationInfo &info)
{
auto rptManager = WifiManager::GetInstance().GetRptInterface(m_id);
if (rptManager == nullptr) {
return WIFI_OPT_FAILED;
}
rptManager->AddBlock(info.bssid);
return WIFI_OPT_SUCCESS;
}
ErrCode WifiHotspotServiceImpl::AddBlockList(const StationInfo &info)
{
WIFI_LOGI("current ap service is %{public}d %{public}s"
@ -444,7 +474,9 @@ ErrCode WifiHotspotServiceImpl::AddBlockList(const StationInfo &info)
if (CheckMacIsValid(info.bssid)) {
return WIFI_OPT_INVALID_PARAM;
}
if (!IsApServiceRunning()) {
bool isApServiceRunning = IsApServiceRunning();
bool isRptRunning = IsRptRunning();
if (!isApServiceRunning && !isRptRunning) {
WIFI_LOGE("ApService is not running!");
return WIFI_OPT_AP_NOT_OPENED;
}
@ -456,18 +488,11 @@ ErrCode WifiHotspotServiceImpl::AddBlockList(const StationInfo &info)
WIFI_LOGE("Add block list failed!");
return WIFI_OPT_FAILED;
}
IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(m_id);
if (pService == nullptr) {
WIFI_LOGE("Instance %{public}d get hotspot service is null!", m_id);
return WIFI_OPT_AP_NOT_OPENED;
}
if (pService->AddBlockList(updateInfo) != WIFI_OPT_SUCCESS) {
WIFI_LOGE("AddBlockList: request add hotspot blocklist failed!");
return WIFI_OPT_FAILED;
}
if (pService->DisconnetStation(updateInfo) != WIFI_OPT_SUCCESS) {
WIFI_LOGE("AddBlockList: request disconnet station failed!");
return WIFI_OPT_FAILED;
if (isApServiceRunning) {
return AddApBlockList(m_id, updateInfo);
} else if (isRptRunning) {
return AddRptBlockList(m_id, updateInfo);
}
return WIFI_OPT_SUCCESS;
}
@ -507,6 +532,12 @@ ErrCode WifiHotspotServiceImpl::DelBlockList(const StationInfo &info)
WIFI_LOGE("request del hotspot blocklist failed!");
return WIFI_OPT_FAILED;
}
} else if (IsRptRunning()) {
auto rptManager = WifiManager::GetInstance().GetRptInterface(m_id);
if (rptManager == nullptr) {
return WIFI_OPT_FAILED;
}
rptManager->DelBlock(info.bssid);
}
if (WifiSettings::GetInstance().ManageBlockList(info, MODE_DEL, m_id) < 0) {
@ -608,6 +639,13 @@ bool WifiHotspotServiceImpl::IsApServiceRunning()
return true;
}
bool WifiHotspotServiceImpl::IsRptRunning()
{
WIFI_LOGI("current rpt is %{public}d %{public}s", m_id, __func__);
auto rptManager = WifiManager::GetInstance().GetRptInterface(m_id);
return rptManager != nullptr && rptManager->IsRptRunning();
}
ErrCode WifiHotspotServiceImpl::RegisterCallBack(const sptr<IWifiHotspotCallback> &callback,
const std::vector<std::string> &event)
{
@ -925,7 +963,12 @@ ErrCode WifiHotspotServiceImpl::GetApIfaceName(std::string& ifaceName)
WIFI_LOGE("GetBlockLists:VerifyGetWifiInfoPermission PERMISSION_DENIED!");
return WIFI_OPT_PERMISSION_DENIED;
}
ifaceName = WifiConfigCenter::GetInstance().GetApIfaceName();
if (IsApServiceRunning()) {
ifaceName = WifiConfigCenter::GetInstance().GetApIfaceName();
} else if (IsRptRunning()) {
auto rptManager = WifiManager::GetInstance().GetRptInterface(m_id);
ifaceName = (rptManager != nullptr) ? rptManager->GetRptIfaceName() : "";
}
return ErrCode::WIFI_OPT_SUCCESS;
}
} // namespace Wifi

View File

@ -276,6 +276,7 @@ private:
ErrCode CheckCanEnableHotspot(const ServiceType type);
int CheckOperHotspotSwitchPermission(const ServiceType type);
bool IsApServiceRunning();
bool IsRptRunning();
static void ConfigInfoDump(std::string& result);
static void StationsInfoDump(std::string& result);

View File

@ -69,7 +69,7 @@ ErrCode ConcreteClientModeManager::InitConcreteManager()
return WIFI_OPT_SUCCESS;
}
ConcreteMangerMachine *ConcreteClientModeManager::GetConcreteMachine()
ConcreteMangerMachine *ConcreteClientModeManager::GetMachine()
{
return pConcreteMangerMachine;
}

View File

@ -31,7 +31,7 @@ public:
explicit ConcreteClientModeManager(ConcreteManagerRole role, int id);
~ConcreteClientModeManager();
ErrCode InitConcreteManager();
ConcreteMangerMachine *GetConcreteMachine();
ConcreteMangerMachine *GetMachine();
int mid;
private:

View File

@ -55,7 +55,7 @@ ErrCode MultiStaManager::RegisterCallback(const MultiStaModeCallback &callbacks)
return WIFI_OPT_SUCCESS;
}
MultiStaStateMachine *MultiStaManager::GetMultiStaMachine()
MultiStaStateMachine *MultiStaManager::GetMachine()
{
return pMultiStaStateMachine;
}

View File

@ -37,7 +37,7 @@ public:
ErrCode InitMultiStaManager();
void SetRole(Role role);
Role GetRole();
MultiStaStateMachine *GetMultiStaMachine();
MultiStaStateMachine *GetMachine();
int mid;
private:

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2024-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 OHOS_RPT_INTERFACE_H
#define OHOS_RPT_INTERFACE_H
#include <string>
#include "wifi_errcode.h"
#include "wifi_ap_msg.h"
#include "wifi_p2p_msg.h"
namespace OHOS::Wifi {
class RptInterface {
public:
RptInterface() {};
virtual ~RptInterface() {};
virtual bool IsRptRunning() = 0;
virtual ErrCode GetStationList(std::vector<StationInfo> &result) = 0;
virtual std::string GetRptIfaceName() = 0;
virtual void AddBlock(const std::string &mac) = 0;
virtual void DelBlock(const std::string &mac) = 0;
virtual void OnP2pActionResult(P2pActionCallback action, ErrCode code) = 0;
virtual void OnP2pConnectionChanged(P2pConnectedState p2pConnState) = 0;
virtual void OnStationJoin(std::string mac) = 0;
virtual void OnStationLeave(std::string mac) = 0;
};
} // namespace OHOS::Wifi
#endif

View File

@ -0,0 +1,160 @@
/*
* Copyright (C) 2024-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.
*/
#ifdef FEATURE_RPT_SUPPORT
#include "rpt_manager.h"
#include "wifi_logger.h"
#include "wifi_service_manager.h"
#include "wifi_manager.h"
#include "wifi_config_center.h"
DEFINE_WIFILOG_LABEL("RptManager");
namespace OHOS::Wifi {
RptManager::RptManager(RptManager::Role role, int id) : mid(id), curRole(role), pRptManagerMachine(nullptr)
{}
RptManager::~RptManager()
{
WIFI_LOGI("Exit.");
if (pRptManagerMachine != nullptr) {
pRptManagerMachine = nullptr;
}
}
ErrCode RptManager::InitRptManager()
{
pRptManagerMachine = std::make_shared<RptManagerMachine>();
if (pRptManagerMachine == nullptr) {
WIFI_LOGE("Alloc pRptManagerMachine failed.\n");
return WIFI_OPT_FAILED;
}
if (pRptManagerMachine->InitRptManagerMachine() != WIFI_OPT_SUCCESS) {
WIFI_LOGE("InitRptManagerMachine failed.\n");
return WIFI_OPT_FAILED;
}
pRptManagerMachine->RegisterCallback(mcb);
pRptManagerMachine->SendMessage(RPT_CMD_START, static_cast<int>(curRole), mid);
return WIFI_OPT_SUCCESS;
}
ErrCode RptManager::RegisterCallback(const RptModeCallback &callbacks)
{
mcb = callbacks;
return WIFI_OPT_SUCCESS;
}
std::shared_ptr<RptManagerMachine> RptManager::GetMachine()
{
return pRptManagerMachine;
}
void RptManager::SetRole(Role role)
{
curRole = role;
}
RptManager::Role RptManager::GetRole()
{
return curRole;
}
bool RptManager::IsRptRunning()
{
return pRptManagerMachine != nullptr && pRptManagerMachine->GetCurStateName() == "StartedState";
}
void RptManager::OnP2pConnectionChanged(P2pConnectedState p2pConnState)
{
if (p2pConnState == P2pConnectedState::P2P_CONNECTED) {
auto msg = pRptManagerMachine->CreateMessage(RPT_CMD_ON_GROUP_CREATED);
pRptManagerMachine->SendMessage(msg);
}
}
void RptManager::OnP2pActionResult(P2pActionCallback action, ErrCode code)
{
if (action == P2pActionCallback::RemoveGroup && code == ErrCode::WIFI_OPT_SUCCESS) {
auto msg = pRptManagerMachine->CreateMessage(RPT_CMD_ON_GROUP_REMOVED);
pRptManagerMachine->SendMessage(msg);
}
}
void RptManager::OnP2pClosed()
{
auto msg = pRptManagerMachine->CreateMessage(RPT_CMD_ON_P2P_CLOSE);
pRptManagerMachine->SendMessage(msg);
}
void RptManager::OnStationJoin(std::string mac)
{
auto msg = pRptManagerMachine->CreateMessage(RPT_CMD_ON_STATION_JOIN);
msg->AddStringMessageBody(mac);
pRptManagerMachine->SendMessage(msg);
}
void RptManager::OnStationLeave(std::string mac)
{
auto msg = pRptManagerMachine->CreateMessage(RPT_CMD_ON_STATION_LEAVE);
msg->AddStringMessageBody(mac);
pRptManagerMachine->SendMessage(msg);
}
void RptManager::AddBlock(const std::string &mac)
{
auto msg = pRptManagerMachine->CreateMessage(RPT_CMD_ADD_BLOCK);
msg->AddStringMessageBody(mac);
pRptManagerMachine->SendMessage(msg);
}
void RptManager::DelBlock(const std::string &mac)
{
auto msg = pRptManagerMachine->CreateMessage(RPT_CMD_DEL_BLOCK);
msg->AddStringMessageBody(mac);
pRptManagerMachine->SendMessage(msg);
}
ErrCode RptManager::GetStationList(std::vector<StationInfo> &result)
{
#ifndef FEATURE_P2P_SUPPORT
return WIFI_OPT_P2P_NOT_OPENED;
#else
IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst();
if (pService == nullptr) {
WIFI_LOGE("Get P2P service failed!");
return WIFI_OPT_P2P_NOT_OPENED;
}
return pService->GetRptStationsList(result);
#endif
}
std::string RptManager::GetRptIfaceName()
{
#ifndef FEATURE_P2P_SUPPORT
return "";
#else
IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst();
if (pService == nullptr) {
WIFI_LOGE("Get P2P service failed!");
return "";
}
WifiP2pGroupInfo group;
pService->GetCurrentGroup(group);
return group.GetInterface();
#endif
}
} // namespace OHOS::Wifi
#endif

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2024-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 OHOS_RPT_MANAGER_H
#define OHOS_RPT_MANAGER_H
#ifdef FEATURE_RPT_SUPPORT
#include <functional>
#include <string>
#include "wifi_errcode.h"
#include "rpt_manager_state_machine.h"
#include "rpt_interface.h"
namespace OHOS::Wifi {
class RptManager : public RptInterface {
public:
enum class Role {
ROLE_UNKNOW = -1,
ROLE_RPT = 0,
ROLE_HAS_REMOVED = 1,
};
ErrCode RegisterCallback(const RptModeCallback &callbacks);
explicit RptManager(RptManager::Role role, int id);
~RptManager() override;
ErrCode InitRptManager();
void SetRole(Role role);
Role GetRole();
std::shared_ptr<RptManagerMachine> GetMachine();
int mid;
bool IsRptRunning() override;
ErrCode GetStationList(std::vector<StationInfo> &result) override;
std::string GetRptIfaceName() override;
void AddBlock(const std::string &mac) override;
void DelBlock(const std::string &mac) override;
void OnP2pActionResult(P2pActionCallback action, ErrCode code) override;
void OnP2pConnectionChanged(P2pConnectedState p2pConnState) override;
void OnStationJoin(std::string mac) override;
void OnStationLeave(std::string mac) override;
void OnP2pClosed();
private:
RptManager::Role curRole;
RptModeCallback mcb;
std::shared_ptr<RptManagerMachine> pRptManagerMachine;
};
} // namespace OHOS::Wifi
#endif
#endif

View File

@ -0,0 +1,584 @@
/*
* Copyright (C) 2024-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.
*/
#ifdef FEATURE_RPT_SUPPORT
#include "rpt_manager_state_machine.h"
#include "wifi_manager.h"
#include "wifi_service_manager.h"
#include "wifi_config_center.h"
#include "wifi_chip_hal_interface.h"
#include "wifi_settings.h"
#include "wifi_common_event_helper.h"
#include "wifi_internal_event_dispatcher.h"
#include "wifi_p2p_msg.h"
#include "ip2p_service.h"
#include "wifi_p2p_hal_interface.h"
#define TIME_DELAY (1000)
#define MAX_RETRY_COUNT (3)
namespace OHOS::Wifi {
DEFINE_WIFILOG_LABEL("RptManagerMachine");
int RptManagerMachine::mid{0};
RptManagerMachine::RptManagerMachine() : StateMachine("RptManagerMachine"), pDefaultState(nullptr),
pIdleState(nullptr), pStartingState(nullptr), pP2pConflictState(nullptr), pStartedState(nullptr),
pStoppingState(nullptr), pStoppedState(nullptr)
{}
RptManagerMachine::~RptManagerMachine()
{
WIFI_LOGE("RptManagerMachine::~RptManagerMachine");
StopHandlerThread();
ParsePointer(pDefaultState);
ParsePointer(pIdleState);
ParsePointer(pStartingState);
ParsePointer(pP2pConflictState);
ParsePointer(pStartedState);
ParsePointer(pStoppingState);
ParsePointer(pStoppedState);
}
/* --------------------------Initialization functions--------------------------*/
ErrCode RptManagerMachine::InitRptManagerMachine()
{
WIFI_LOGE("Enter RptManagerMachine::InitRptManagerMachine.\n");
if (!InitialStateMachine("RptManagerMachine")) {
WIFI_LOGE("Initial StateMachine failed.\n");
return WIFI_OPT_FAILED;
}
if (InitRptManagerStates() == WIFI_OPT_FAILED) {
return WIFI_OPT_FAILED;
}
BuildStateTree();
SetFirstState(pIdleState);
StartStateMachine();
return WIFI_OPT_SUCCESS;
}
void RptManagerMachine::BuildStateTree()
{
StatePlus(pDefaultState, nullptr);
StatePlus(pIdleState, pDefaultState);
StatePlus(pStartingState, pDefaultState);
StatePlus(pP2pConflictState, pDefaultState);
StatePlus(pStartedState, pDefaultState);
StatePlus(pStoppingState, pDefaultState);
StatePlus(pStoppedState, pDefaultState);
}
ErrCode RptManagerMachine::InitRptManagerStates()
{
WIFI_LOGE("Enter InitConcreteMangerStates\n");
pDefaultState = new (std::nothrow) DefaultState(this);
pIdleState = new (std::nothrow) IdleState(this);
pStartingState = new (std::nothrow) StartingState(this);
pP2pConflictState = new (std::nothrow) P2pConflictState(this);
pStartedState = new (std::nothrow) StartedState(this);
pStoppingState = new (std::nothrow) StoppingState(this);
pStoppedState = new (std::nothrow) StoppedState(this);
int tmpErrNumber = 0;
tmpErrNumber += JudgmentEmpty(pDefaultState);
tmpErrNumber += JudgmentEmpty(pIdleState);
tmpErrNumber += JudgmentEmpty(pStartingState);
tmpErrNumber += JudgmentEmpty(pP2pConflictState);
tmpErrNumber += JudgmentEmpty(pStartedState);
tmpErrNumber += JudgmentEmpty(pStoppingState);
tmpErrNumber += JudgmentEmpty(pStoppedState);
if (tmpErrNumber != 0) {
WIFI_LOGE("InitRptManagerStates some one state is null\n");
return WIFI_OPT_FAILED;
}
return WIFI_OPT_SUCCESS;
}
ErrCode RptManagerMachine::RegisterCallback(const RptModeCallback &callbacks)
{
mcb = callbacks;
return WIFI_OPT_SUCCESS;
}
/* ---------------- DefaultState ---------------- */
RptManagerMachine::DefaultState::DefaultState(RptManagerMachine *rptManagerMachine)
: State("DefaultState"), pRptManagerMachine(rptManagerMachine)
{}
RptManagerMachine::DefaultState::~DefaultState()
{}
void RptManagerMachine::DefaultState::GoInState()
{
WIFI_LOGE("DefaultState GoInState function.\n");
}
void RptManagerMachine::DefaultState::GoOutState()
{
WIFI_LOGE("DefaultState GoOutState function.\n");
}
bool RptManagerMachine::DefaultState::ExecuteStateMsg(InternalMessagePtr msg)
{
if (msg == nullptr || pRptManagerMachine == nullptr) {
return false;
}
WIFI_LOGE("DefaultState-msgCode=%{public}d is received.\n", msg->GetMessageName());
return true;
}
/* ---------------- IdleState ---------------- */
RptManagerMachine::IdleState::IdleState(RptManagerMachine *rptManagerMachine)
: State("IdleState"), pRptManagerMachine(rptManagerMachine)
{}
RptManagerMachine::IdleState::~IdleState()
{}
void RptManagerMachine::IdleState::GoInState()
{
WIFI_LOGE("IdleState GoInState function.\n");
}
void RptManagerMachine::IdleState::GoOutState()
{
WIFI_LOGE("IdleState GoOutState function.\n");
}
bool RptManagerMachine::IdleState::ExecuteStateMsg(InternalMessagePtr msg)
{
if (msg == nullptr || pRptManagerMachine == nullptr) {
return false;
}
WIFI_LOGE("IdleState-msgCode=%{public}d is received.\n", msg->GetMessageName());
switch (msg->GetMessageName()) {
case RPT_CMD_START:
pRptManagerMachine->pStartingState->retryCount = 0;
pRptManagerMachine->pP2pConflictState->retryCount = 0;
pRptManagerMachine->SwitchState(pRptManagerMachine->pStartingState);
break;
case RPT_CMD_STOP:
case RPT_CMD_ON_P2P_CLOSE:
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
break;
default:
break;
}
return true;
}
/* ---------------- StartingState ---------------- */
RptManagerMachine::StartingState::StartingState(RptManagerMachine *rptManagerMachine)
: State("StartingState"), pRptManagerMachine(rptManagerMachine)
{}
RptManagerMachine::StartingState::~StartingState()
{}
void RptManagerMachine::StartingState::GoInState()
{
WIFI_LOGE("StartingState GoInState function.\n");
StartRpt();
}
void RptManagerMachine::StartingState::GoOutState()
{
WIFI_LOGE("StartingState GoOutState function.\n");
}
bool RptManagerMachine::StartingState::ExecuteStateMsg(InternalMessagePtr msg)
{
if (msg == nullptr || pRptManagerMachine == nullptr) {
return false;
}
WIFI_LOGE("StartingState-msgCode=%{public}d is received.\n", msg->GetMessageName());
switch (msg->GetMessageName()) {
case RPT_CMD_ON_GROUP_CREATED:
pRptManagerMachine->SwitchState(pRptManagerMachine->pStartedState);
break;
case RPT_CMD_ON_P2P_CLOSE:
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
break;
case RPT_CMD_STOP:
pRptManagerMachine->MessageExecutedLater(RPT_CMD_STOP, TIME_DELAY);
break;
case RPT_CMD_ON_CREATE_RPT_GROUP_TIMEOUT:
if (retryCount < MAX_RETRY_COUNT) {
StartRpt();
} else {
pRptManagerMachine->mcb.onStartFailure(mid);
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
}
break;
default:
break;
}
return true;
}
void RptManagerMachine::StartingState::StartRpt()
{
#ifdef FEATURE_P2P_SUPPORT
if (WifiConfigCenter::GetInstance().GetP2pMidState() != WifiOprMidState::RUNNING) {
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
return;
}
IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst();
if (pService == nullptr) {
WIFI_LOGE("Get P2P service failed!");
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
return;
}
int p2pConnectedStatus;
pService->GetP2pConnectedStatus(p2pConnectedStatus);
if (p2pConnectedStatus != static_cast<int>(P2pConnectedState::P2P_DISCONNECTED)) {
WIFI_LOGE("P2p is already connected, remove current group and retry");
pRptManagerMachine->SwitchState(pRptManagerMachine->pP2pConflictState);
return;
}
retryCount++;
auto config = pRptManagerMachine->CreateRptConfig();
pService->CreateRptGroup(config);
pRptManagerMachine->MessageExecutedLater(RPT_CMD_ON_CREATE_RPT_GROUP_TIMEOUT, TIME_DELAY);
#endif
}
/* ---------------- P2pConflictState ---------------- */
RptManagerMachine::P2pConflictState::P2pConflictState(RptManagerMachine *rptManagerMachine)
: State("P2pConflictState"), pRptManagerMachine(rptManagerMachine)
{}
RptManagerMachine::P2pConflictState::~P2pConflictState()
{}
void RptManagerMachine::P2pConflictState::GoInState()
{
WIFI_LOGE("P2pConflictState GoInState function.\n");
RemoveP2pConflictGroup();
}
void RptManagerMachine::P2pConflictState::GoOutState()
{
WIFI_LOGE("P2pConflictState GoOutState function.\n");
}
bool RptManagerMachine::P2pConflictState::ExecuteStateMsg(InternalMessagePtr msg)
{
if (msg == nullptr || pRptManagerMachine == nullptr) {
return false;
}
WIFI_LOGE("P2pConflictState-msgCode=%{public}d is received.\n", msg->GetMessageName());
switch (msg->GetMessageName()) {
case RPT_CMD_ON_GROUP_REMOVED:
pRptManagerMachine->SwitchState(pRptManagerMachine->pStartingState);
break;
case RPT_CMD_ON_REMOVE_CONFLICT_GROUP_TIMEOUT:
if (retryCount < MAX_RETRY_COUNT) {
RemoveP2pConflictGroup();
} else {
pRptManagerMachine->mcb.onStartFailure(mid);
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
}
break;
case RPT_CMD_ON_P2P_CLOSE:
case RPT_CMD_STOP:
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
break;
default:
break;
}
return true;
}
void RptManagerMachine::P2pConflictState::RemoveP2pConflictGroup()
{
#ifdef FEATURE_P2P_SUPPORT
IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst();
if (pService == nullptr) {
WIFI_LOGE("Get P2P service failed!");
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
return;
}
int p2pConnectedStatus;
pService->GetP2pConnectedStatus(p2pConnectedStatus);
if (p2pConnectedStatus == static_cast<int>(P2pConnectedState::P2P_DISCONNECTED)) {
pRptManagerMachine->SwitchState(pRptManagerMachine->pStartingState);
return;
}
retryCount++;
pService->RemoveGroup();
pRptManagerMachine->MessageExecutedLater(RPT_CMD_ON_REMOVE_CONFLICT_GROUP_TIMEOUT, TIME_DELAY);
#endif
}
/* ---------------- StartedState ---------------- */
RptManagerMachine::StartedState::StartedState(RptManagerMachine *rptManagerMachine)
: State("StartedState"), pRptManagerMachine(rptManagerMachine)
{}
RptManagerMachine::StartedState::~StartedState()
{}
void RptManagerMachine::StartedState::GoInState()
{
WIFI_LOGE("StartedState GoInState function.\n");
pRptManagerMachine->BroadcastApState(static_cast<int>(ApState::AP_STATE_STARTED));
pRptManagerMachine->InitBlockList();
}
void RptManagerMachine::StartedState::GoOutState()
{
WIFI_LOGE("StartedState GoOutState function.\n");
pRptManagerMachine->BroadcastApState(static_cast<int>(ApState::AP_STATE_CLOSED));
}
bool RptManagerMachine::StartedState::ExecuteStateMsg(InternalMessagePtr msg)
{
if (msg == nullptr || pRptManagerMachine == nullptr) {
return false;
}
WIFI_LOGE("StartedState-msgCode=%{public}d is received.\n", msg->GetMessageName());
switch (msg->GetMessageName()) {
case RPT_CMD_STOP:
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppingState);
break;
case RPT_CMD_ON_GROUP_REMOVED:
pRptManagerMachine->mcb.onStartFailure(mid);
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
break;
case RPT_CMD_ON_P2P_CLOSE:
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
break;
case RPT_CMD_ON_STATION_JOIN: {
auto mac = msg->GetStringFromMessage();
pRptManagerMachine->BroadcastStationJoin(mac);
}
break;
case RPT_CMD_ON_STATION_LEAVE: {
auto mac = msg->GetStringFromMessage();
pRptManagerMachine->BroadcastStationLeave(mac);
}
break;
case RPT_CMD_ADD_BLOCK: {
auto mac = msg->GetStringFromMessage();
pRptManagerMachine->AddBlockList(mac);
}
break;
case RPT_CMD_DEL_BLOCK: {
auto mac = msg->GetStringFromMessage();
pRptManagerMachine->DelBlockList(mac);
}
break;
default:
break;
}
return true;
}
/* ---------------- StoppingState ---------------- */
RptManagerMachine::StoppingState::StoppingState(RptManagerMachine *rptManagerMachine)
: State("StoppingState"), pRptManagerMachine(rptManagerMachine)
{}
RptManagerMachine::StoppingState::~StoppingState()
{}
void RptManagerMachine::StoppingState::GoInState()
{
WIFI_LOGE("StoppingState GoInState function.\n");
StopRpt();
}
void RptManagerMachine::StoppingState::GoOutState()
{
WIFI_LOGE("StoppingState GoOutState function.\n");
}
bool RptManagerMachine::StoppingState::ExecuteStateMsg(InternalMessagePtr msg)
{
if (msg == nullptr || pRptManagerMachine == nullptr) {
return false;
}
WIFI_LOGE("StoppingState-msgCode=%{public}d is received.\n", msg->GetMessageName());
switch (msg->GetMessageName()) {
case RPT_CMD_ON_P2P_CLOSE:
case RPT_CMD_ON_GROUP_REMOVED:
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
break;
default:
break;
}
return true;
}
void RptManagerMachine::StoppingState::StopRpt()
{
#ifdef FEATURE_P2P_SUPPORT
if (WifiConfigCenter::GetInstance().GetP2pMidState() != WifiOprMidState::RUNNING) {
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
return;
}
IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst();
if (pService == nullptr) {
WIFI_LOGE("Get P2P service failed!");
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
return;
}
WifiP2pGroupInfo group;
if (pService->GetCurrentGroup(group) != ErrCode::WIFI_OPT_SUCCESS) {
WIFI_LOGE("group not exist when stop rpt");
pRptManagerMachine->SwitchState(pRptManagerMachine->pStoppedState);
return;
}
pService->DeleteGroup(group);
#endif
}
/* ---------------- StoppedState ---------------- */
RptManagerMachine::StoppedState::StoppedState(RptManagerMachine *rptManagerMachine)
: State("StoppedState"), pRptManagerMachine(rptManagerMachine)
{}
RptManagerMachine::StoppedState::~StoppedState()
{}
void RptManagerMachine::StoppedState::GoInState()
{
WIFI_LOGE("StoppedState GoInState function.\n");
pRptManagerMachine->mcb.onStopped(mid);
}
void RptManagerMachine::StoppedState::GoOutState()
{
WIFI_LOGE("StoppedState GoOutState function.\n");
}
bool RptManagerMachine::StoppedState::ExecuteStateMsg(InternalMessagePtr msg)
{
if (msg == nullptr || pRptManagerMachine == nullptr) {
return false;
}
WIFI_LOGE("StoppedState-msgCode=%{public}d is received.\n", msg->GetMessageName());
return true;
}
/* ---------------- RptManagerMachine ---------------- */
WifiP2pConfig RptManagerMachine::CreateRptConfig()
{
WifiP2pConfig p2pConfig;
HotspotConfig hotspotConfig;
WifiSettings::GetInstance().GetHotspotConfig(hotspotConfig, mid);
p2pConfig.SetGroupName(hotspotConfig.GetSsid());
p2pConfig.SetPassphrase(hotspotConfig.GetPreSharedKey());
p2pConfig.SetGoBand(hotspotConfig.GetBand() == BandType::BAND_2GHZ ? GroupOwnerBand::GO_BAND_2GHZ :
hotspotConfig.GetBand() == BandType::BAND_5GHZ ? GroupOwnerBand::GO_BAND_5GHZ :
GroupOwnerBand::GO_BAND_AUTO);
return p2pConfig;
}
void RptManagerMachine::BroadcastApState(int apState)
{
WIFI_LOGI("RptManagerMachine NotifyApState, state %{public}d", apState);
WifiEventCallbackMsg cbMsg;
cbMsg.msgCode = WIFI_CBK_MSG_HOTSPOT_STATE_CHANGE;
cbMsg.msgData = apState;
cbMsg.id = mid;
WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
std::string msg = std::string("OnHotspotStateChanged") + std::string("id = ") + std::to_string(mid);
WifiCommonEventHelper::PublishHotspotStateChangedEvent(apState, msg);
}
void RptManagerMachine::BroadcastStationJoin(std::string mac)
{
StationInfo info;
info.bssid = mac;
WifiEventCallbackMsg cbMsg;
cbMsg.msgCode = WIFI_CBK_MSG_HOTSPOT_STATE_JOIN;
cbMsg.staInfo = info;
cbMsg.id = mid;
WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
std::string msg = std::string("ApStaJoined") + std::string("id = ") + std::to_string(mid);
WifiCommonEventHelper::PublishApStaJoinEvent(0, msg);
}
void RptManagerMachine::BroadcastStationLeave(std::string mac)
{
StationInfo info;
info.bssid = mac;
WifiEventCallbackMsg cbMsg;
cbMsg.msgCode = WIFI_CBK_MSG_HOTSPOT_STATE_LEAVE;
cbMsg.staInfo = info;
cbMsg.id = mid;
WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
std::string msg = std::string("ApStaLeaved") + std::string("id = ") + std::to_string(mid);
WifiCommonEventHelper::PublishApStaLeaveEvent(0, msg);
}
std::string GetRptIfaceName()
{
#ifdef FEATURE_P2P_SUPPORT
IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst();
if (pService == nullptr) {
WIFI_LOGE("Get P2P service failed!");
return "";
}
WifiP2pGroupInfo group;
pService->GetCurrentGroup(group);
return group.GetInterface();
#else
return "";
#endif
}
void RptManagerMachine::SetMacFilter(std::string mac)
{
std::vector<StationInfo> blockList;
WifiSettings::GetInstance().GetBlockList(blockList, mid);
std::vector<std::string> blockMacs;
for (auto& sta : blockList) {
if (mac != sta.bssid) {
blockMacs.push_back(sta.bssid);
}
}
std::string p2pIfname = WifiConfigCenter::GetInstance().GetP2pIfaceName();
std::string p2pInterfaceName = GetRptIfaceName();
WIFI_LOGI("SetMacFilter size:%{public}d", static_cast<int>(blockMacs.size()));
WifiP2PHalInterface::GetInstance().SetRptBlockList(p2pIfname, p2pInterfaceName, blockMacs);
}
void DisAssSta(std::string mac)
{
std::string p2pIfname = WifiConfigCenter::GetInstance().GetP2pIfaceName();
std::string p2pInterfaceName = GetRptIfaceName();
WifiP2PHalInterface::GetInstance().DisAssociateSta(p2pIfname, p2pInterfaceName, mac);
}
void RptManagerMachine::InitBlockList()
{
SetMacFilter("");
}
void RptManagerMachine::AddBlockList(std::string mac)
{
DisAssSta(mac);
SetMacFilter("");
}
void RptManagerMachine::DelBlockList(std::string mac)
{
SetMacFilter(mac);
}
} // namespace OHOS::Wifi
#endif

View File

@ -0,0 +1,166 @@
/*
* Copyright (C) 2024-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 RPT_MANAGER_STATE_MACHINE_H
#define RPT_MANAGER_STATE_MACHINE_H
#ifdef FEATURE_RPT_SUPPORT
#include "state.h"
#include "state_machine.h"
#include "wifi_logger.h"
#include "wifi_errcode.h"
#include <string>
#include "wifi_ap_msg.h"
#include "wifi_internal_msg.h"
#include "wifi_controller_define.h"
#include "ip2p_service_callbacks.h"
namespace OHOS::Wifi {
class RptManagerMachine : public StateMachine {
public:
RptManagerMachine();
~RptManagerMachine();
class DefaultState : public State {
public:
explicit DefaultState(RptManagerMachine *rptManagerMachine);
~DefaultState() override;
void GoInState() override;
void GoOutState() override;
bool ExecuteStateMsg(InternalMessagePtr msg) override;
private:
RptManagerMachine *pRptManagerMachine;
};
class IdleState : public State {
public:
explicit IdleState(RptManagerMachine *rptManagerMachine);
~IdleState() override;
void GoInState() override;
void GoOutState() override;
bool ExecuteStateMsg(InternalMessagePtr msg) override;
private:
RptManagerMachine *pRptManagerMachine;
};
class StartingState : public State {
public:
explicit StartingState(RptManagerMachine *rptManagerMachine);
~StartingState() override;
void GoInState() override;
void GoOutState() override;
bool ExecuteStateMsg(InternalMessagePtr msg) override;
int retryCount;
private:
void StartRpt();
RptManagerMachine *pRptManagerMachine;
};
class P2pConflictState : public State {
public:
explicit P2pConflictState(RptManagerMachine *rptManagerMachine);
~P2pConflictState() override;
void GoInState() override;
void GoOutState() override;
bool ExecuteStateMsg(InternalMessagePtr msg) override;
int retryCount;
private:
void RemoveP2pConflictGroup();
RptManagerMachine *pRptManagerMachine;
};
class StartedState : public State {
public:
explicit StartedState(RptManagerMachine *rptManagerMachine);
~StartedState() override;
void GoInState() override;
void GoOutState() override;
bool ExecuteStateMsg(InternalMessagePtr msg) override;
private:
RptManagerMachine *pRptManagerMachine;
};
class StoppingState : public State {
public:
explicit StoppingState(RptManagerMachine *rptManagerMachine);
~StoppingState() override;
void GoInState() override;
void GoOutState() override;
bool ExecuteStateMsg(InternalMessagePtr msg) override;
private:
void StopRpt();
RptManagerMachine *pRptManagerMachine;
};
class StoppedState : public State {
public:
explicit StoppedState(RptManagerMachine *rptManagerMachine);
~StoppedState() override;
void GoInState() override;
void GoOutState() override;
bool ExecuteStateMsg(InternalMessagePtr msg) override;
private:
RptManagerMachine *pRptManagerMachine;
};
public:
ErrCode InitRptManagerMachine();
ErrCode RegisterCallback(const RptModeCallback &callbacks);
private:
template <typename T>
inline void ParsePointer(T *&pointer)
{
if (pointer != nullptr) {
delete pointer;
pointer = nullptr;
}
}
template <typename T>
inline ErrCode JudgmentEmpty(T *&pointer)
{
if (pointer == nullptr) {
return WIFI_OPT_FAILED;
}
return WIFI_OPT_SUCCESS;
}
void BuildStateTree();
ErrCode InitRptManagerStates();
WifiP2pConfig CreateRptConfig();
void SetMacFilter(std::string mac);
void InitBlockList();
void AddBlockList(std::string mac);
void DelBlockList(std::string mac);
void BroadcastStationJoin(std::string mac);
void BroadcastStationLeave(std::string mac);
void BroadcastApState(int apState);
DefaultState *pDefaultState;
IdleState *pIdleState;
StartingState *pStartingState;
P2pConflictState *pP2pConflictState;
StartedState *pStartedState;
StoppingState *pStoppingState;
StoppedState *pStoppedState;
RptModeCallback mcb;
static int mid;
};
} // namespace OHOS::Wifi
#endif
#endif

View File

@ -54,7 +54,7 @@ ErrCode SoftApManager::RegisterCallback(const SoftApModeCallback &callbacks)
return WIFI_OPT_SUCCESS;
}
SoftapManagerMachine *SoftApManager::GetSoftapMachine()
SoftapManagerMachine *SoftApManager::GetMachine()
{
return pSoftapManagerMachine;
}

View File

@ -37,7 +37,7 @@ public:
ErrCode InitSoftapManager();
void SetRole(Role role);
Role GetRole();
SoftapManagerMachine *GetSoftapMachine();
SoftapManagerMachine *GetMachine();
int mid;
private:

View File

@ -39,6 +39,9 @@ namespace Wifi {
#define CMD_STA_REMOVED 0x14
#define CMD_CONCRETECLIENT_REMOVED 0x15
#define CMD_AP_REMOVED 0x16
#define CMD_RPT_STOPPED 0x17
#define CMD_RPT_START_FAILURE 0x18
#define CMD_P2P_STOPPED 0x19
#define CONCRETE_CMD_START 0x101
#define CONCRETE_CMD_SWITCH_TO_CONNECT_MODE 0x102
@ -59,6 +62,19 @@ namespace Wifi {
#define MULTI_STA_CMD_STOPPED 0x304
#define CMD_MULTI_STA_STOPPED 0x305
#define RPT_CMD_START 0x401
#define RPT_CMD_STOP 0x402
#define RPT_CMD_ON_P2P_CLOSE 0x403
#define RPT_CMD_ON_GROUP_CREATED 0x404
#define RPT_CMD_ON_GROUP_REMOVED 0x405
#define RPT_CMD_ON_CREATE_RPT_GROUP_TIMEOUT 0x406
#define RPT_CMD_ON_REMOVE_RPT_GROUP_TIMEOUT 0x407
#define RPT_CMD_ON_REMOVE_CONFLICT_GROUP_TIMEOUT 0x408
#define RPT_CMD_ADD_BLOCK 0x409
#define RPT_CMD_DEL_BLOCK 0x40A
#define RPT_CMD_ON_STATION_JOIN 0x40B
#define RPT_CMD_ON_STATION_LEAVE 0x40C
#define STOP_WIFI_WAIT_TIME 100
struct ConcreteModeCallback {
@ -77,6 +93,11 @@ struct MultiStaModeCallback {
std::function<void(int)> onStartFailure;
};
struct RptModeCallback {
std::function<void(int)> onStopped;
std::function<void(int)> onStartFailure;
};
enum class ConcreteManagerRole {
ROLE_UNKNOW = -1,
ROLE_CLIENT_SCAN_ONLY = 0,

View File

@ -0,0 +1,122 @@
/*
* Copyright (C) 2024-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 OHOS_WIFI_CONTROLLER_MANAGERS_TEMPLATE_H
#define OHOS_WIFI_CONTROLLER_MANAGERS_TEMPLATE_H
#include <memory>
namespace OHOS::Wifi {
template <class T>
class ManagerControl {
public:
bool HasAnyManager()
{
std::unique_lock<std::mutex> lock(mutex_);
return !managers.empty();
}
bool IdExist(int id)
{
return GetManager(id) != nullptr;
}
std::shared_ptr<T> GetFirstManager()
{
std::unique_lock<std::mutex> lock(mutex_);
if (managers.empty()) {
return nullptr;
}
return managers.front();
}
std::shared_ptr<T> GetManager(int id)
{
std::unique_lock<std::mutex> lock(mutex_);
if (managers.empty()) {
return nullptr;
}
for (auto iter = managers.begin(); iter != managers.end(); ++iter) {
if ((*iter)->mid == id) {
return *iter;
}
}
return nullptr;
}
void StopManager(int id)
{
SendMessage(stopCmdId, id);
}
void StopAllManagers()
{
SendMessageToAll(stopCmdId);
}
void SendMessage(int cmd, int id)
{
std::unique_lock<std::mutex> lock(mutex_);
if (managers.empty()) {
return;
}
for (auto iter = managers.begin(); iter != managers.end(); ++iter) {
if ((*iter)->mid == id) {
if (auto machine = (*iter)->GetMachine(); machine != nullptr) {
machine->SendMessage(cmd);
}
return;
}
}
}
void SendMessageToAll(int cmd)
{
std::unique_lock<std::mutex> lock(mutex_);
if (managers.empty()) {
return;
}
for (auto iter = managers.begin(); iter != managers.end(); ++iter) {
if (auto machine = (*iter)->GetMachine(); machine != nullptr) {
machine->SendMessage(cmd);
}
}
}
void AddManager(std::shared_ptr<T> manager)
{
std::unique_lock<std::mutex> lock(mutex_);
managers.push_back(manager);
}
void RemoveManager(int id)
{
std::unique_lock<std::mutex> lock(mutex_);
if (managers.empty()) {
return;
}
for (auto iter = managers.begin(); iter != managers.end(); ++iter) {
if ((*iter)->mid == id) {
managers.erase(iter);
break;
}
}
}
public:
int stopCmdId;
std::vector<std::shared_ptr<T>> managers {};
mutable std::mutex mutex_;
};
}
#endif

View File

@ -20,6 +20,7 @@
#include "wifi_msg.h"
#include "wifi_system_timer.h"
#include "wifi_hisysevent.h"
#include "wifi_global_func.h"
#ifdef HAS_BATTERY_MANAGER_PART
#include "battery_srv_client.h"
#endif
@ -29,7 +30,6 @@
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiControllerMachine");
int WifiControllerMachine::mWifiStartFailCount{0};
@ -123,8 +123,7 @@ bool WifiControllerMachine::DisableState::ExecuteStateMsg(InternalMessagePtr msg
case CMD_SOFTAP_TOGGLED:
if (msg->GetParam1()) {
int id = msg->GetParam2();
pWifiControllerMachine->MakeSoftapManager(SoftApManager::Role::ROLE_SOFTAP, id);
pWifiControllerMachine->StartTimer(CMD_AP_START_TIME, SOFT_AP_TIME_OUT);
pWifiControllerMachine->MakeHotspotManager(id, true);
pWifiControllerMachine->SwitchState(pWifiControllerMachine->pEnableState);
}
break;
@ -192,7 +191,45 @@ bool WifiControllerMachine::EnableState::ExecuteStateMsg(InternalMessagePtr msg)
pWifiControllerMachine->StopTimer(CMD_OPEN_WIFI_RETRY);
HandleWifiToggleChangeInEnabledState(msg);
break;
case CMD_STA_START_FAILURE:
msg->GetParam1() == INSTID_WLAN0 ? HandleStaStartFailure(INSTID_WLAN0) :
pWifiControllerMachine->multiStaManagers.RemoveManager(INSTID_WLAN1);
break;
case CMD_CONCRETE_STOPPED:
pWifiControllerMachine->HandleConcreteStop(INSTID_WLAN0);
break;
case CMD_MULTI_STA_STOPPED:
pWifiControllerMachine->multiStaManagers.RemoveManager(INSTID_WLAN1);
break;
case CMD_AIRPLANE_TOGGLED:
if (msg->GetParam1()) {
pWifiControllerMachine->HandleAirplaneOpen();
} else {
pWifiControllerMachine->HandleAirplaneClose();
}
break;
case CMD_OPEN_WIFI_RETRY:
pWifiControllerMachine->SendMessage(CMD_WIFI_TOGGLED, 1, 0);
break;
case CMD_STA_REMOVED:
INSTID_WLAN0 == msg->GetParam2() ? HandleStaRemoved(msg) : HandleWifi2Removed(msg);
break;
case CMD_CONCRETECLIENT_REMOVED:
HandleConcreteClientRemoved(msg);
break;
default:
#ifdef FEATURE_AP_SUPPORT
HandleApMsg(msg);
#endif
break;
}
return true;
}
#ifdef FEATURE_AP_SUPPORT
void WifiControllerMachine::EnableState::HandleApMsg(InternalMessagePtr msg)
{
switch (msg->GetMessageName()) {
case CMD_SOFTAP_TOGGLED:
HandleSoftapToggleChangeInEnabledState(msg);
break;
@ -213,43 +250,25 @@ bool WifiControllerMachine::EnableState::ExecuteStateMsg(InternalMessagePtr msg)
case CMD_AP_STOP_TIME:
WriteSoftApOpenAndCloseFailedEvent(static_cast<int>(SoftApperateType::CLOSE_SOFT_AP_FAILED), "TIME_OUT");
break;
#endif
case CMD_STA_START_FAILURE:
msg->GetParam1() == INSTID_WLAN0 ?
HandleStaStartFailure(INSTID_WLAN0) : pWifiControllerMachine->RemoveMultiStaManager(INSTID_WLAN1);
break;
case CMD_CONCRETE_STOPPED:
pWifiControllerMachine->HandleConcreteStop(INSTID_WLAN0);
break;
case CMD_MULTI_STA_STOPPED:
pWifiControllerMachine->RemoveMultiStaManager(INSTID_WLAN1);
break;
case CMD_AIRPLANE_TOGGLED:
if (msg->GetParam1()) {
pWifiControllerMachine->HandleAirplaneOpen();
} else {
pWifiControllerMachine->HandleAirplaneClose();
}
break;
case CMD_OPEN_WIFI_RETRY:
pWifiControllerMachine->SendMessage(CMD_WIFI_TOGGLED, 1, 0);
break;
case CMD_STA_REMOVED:
INSTID_WLAN0 == msg->GetParam2() ? HandleStaRemoved(msg) : HandleWifi2Removed(msg);
break;
case CMD_CONCRETECLIENT_REMOVED:
HandleConcreteClientRemoved(msg);
break;
case CMD_AP_REMOVED:
#ifdef FEATURE_AP_SUPPORT
HandleApRemoved(msg);
#endif
break;
#ifdef FEATURE_RPT_SUPPORT
case CMD_RPT_STOPPED:
pWifiControllerMachine->HandleRptStop(msg->GetParam1());
break;
case CMD_P2P_STOPPED:
HandleP2pStop(msg);
break;
case CMD_RPT_START_FAILURE:
HandleRptStartFail(msg);
break;
#endif
default:
break;
}
return true;
}
#endif
WifiControllerMachine::DefaultState::DefaultState(WifiControllerMachine *wifiControllerMachine)
: State("DefaultState"), pWifiControllerMachine(wifiControllerMachine)
@ -282,11 +301,14 @@ void WifiControllerMachine::HandleAirplaneOpen()
WIFI_LOGI("airplane open set softap false");
#ifdef FEATURE_AP_SUPPORT
WifiConfigCenter::GetInstance().SetSoftapToggledState(false);
StopAllSoftapManagers();
softApManagers.StopAllManagers();
#ifdef FEATURE_RPT_SUPPORT
rptManagers.StopAllManagers();
#endif
#endif
if (!WifiSettings::GetInstance().GetWifiFlagOnAirplaneMode() || !ShouldEnableWifi(INSTID_WLAN0)) {
StopAllMultiStaManagers();
StopAllConcreteManagers();
multiStaManagers.StopAllManagers();
concreteManagers.StopAllManagers();
}
}
@ -301,7 +323,7 @@ void WifiControllerMachine::HandleAirplaneClose()
}
#ifdef FEATURE_AP_SUPPORT
#ifndef HDI_CHIP_INTERFACE_SUPPORT
if (!WifiConfigCenter::GetInstance().GetCoexSupport() && HasAnySoftApManager()) {
if (!WifiConfigCenter::GetInstance().GetCoexSupport() && softApManagers.HasAnyManager()) {
WIFI_LOGE("HandleAirplaneClose, has softap in runing return.");
return;
}
@ -312,7 +334,7 @@ void WifiControllerMachine::HandleAirplaneClose()
WIFI_LOGE("Get unknow wifi role in HandleAirplaneClose.");
return;
}
if (!HasAnyConcreteManager()) {
if (!concreteManagers.HasAnyManager()) {
MakeConcreteManager(role, 0);
SwitchState(pEnableState);
} else {
@ -320,147 +342,48 @@ void WifiControllerMachine::HandleAirplaneClose()
}
}
#ifdef FEATURE_AP_SUPPORT
bool WifiControllerMachine::SoftApIdExist(int id)
{
if (!HasAnySoftApManager()) {
return false;
}
std::unique_lock<std::mutex> lock(softapManagerMutex);
for (auto iter = softapManagers.begin(); iter != softapManagers.end(); ++iter) {
if ((*iter)->mid == id) {
WIFI_LOGI("Softap id %{public}d exist.", id);
return true;
}
}
return false;
}
SoftApManager *WifiControllerMachine::GetSoftApManager(int id)
{
if (!HasAnySoftApManager()) {
return nullptr;
}
std::unique_lock<std::mutex> lock(softapManagerMutex);
for (auto iter = softapManagers.begin(); iter != softapManagers.end(); ++iter) {
if ((*iter)->mid == id) {
WIFI_LOGI("Get softap manager id %{public}d.", id);
return *iter;
}
}
return nullptr;
}
#endif
bool WifiControllerMachine::ConcreteIdExist(int id)
{
if (!HasAnyConcreteManager()) {
return false;
}
std::unique_lock<std::mutex> lock(concreteManagerMutex);
for (auto iter = concreteManagers.begin(); iter != concreteManagers.end(); ++iter) {
if ((*iter)->mid == id) {
WIFI_LOGI("concreteManagers is match");
return true;
}
}
return false;
}
bool WifiControllerMachine::IsWifi2IdExist(int id)
{
if (!HasAnyMultiStaManager()) {
return false;
}
std::unique_lock<std::mutex> lock(multiStaManagerMutex);
for (auto iter = multiStaManagers.begin(); iter != multiStaManagers.end(); ++iter) {
if ((*iter)->mid == id) {
WIFI_LOGI("multiStaManagers is match");
return true;
}
}
return false;
}
bool WifiControllerMachine::HasAnyConcreteManager()
{
std::unique_lock<std::mutex> lock(concreteManagerMutex);
if (concreteManagers.empty()) {
WIFI_LOGE("Enter HasAnyConcreteManager is empty");
return false;
}
return true;
}
bool WifiControllerMachine::HasAnyMultiStaManager()
{
std::unique_lock<std::mutex> lock(multiStaManagerMutex);
if (multiStaManagers.empty()) {
WIFI_LOGE("Enter HasAnyMultiStaManager is empty");
return false;
}
return true;
}
#ifdef FEATURE_AP_SUPPORT
bool WifiControllerMachine::HasAnySoftApManager()
{
std::unique_lock<std::mutex> lock(softapManagerMutex);
if (softapManagers.empty()) {
WIFI_LOGI("Softap managers is empty");
return false;
}
WIFI_LOGI("Has softap manager");
return true;
}
#endif
bool WifiControllerMachine::HasAnyManager()
{
if (!HasAnyConcreteManager() && !HasAnyMultiStaManager()
return (concreteManagers.HasAnyManager() || multiStaManagers.HasAnyManager()
#ifdef FEATURE_AP_SUPPORT
&& !HasAnySoftApManager()
|| softApManagers.HasAnyManager()
#ifdef FEATURE_RPT_SUPPORT
|| rptManagers.HasAnyManager()
#endif
) {
return false;
}
return true;
#endif
);
}
void WifiControllerMachine::MakeConcreteManager(ConcreteManagerRole role, int id)
{
WIFI_LOGE("Enter MakeConcreteManager");
ConcreteClientModeManager *clientmode = new (std::nothrow) ConcreteClientModeManager(role, id);
auto clientmode = std::make_shared<ConcreteClientModeManager>(role, id);
clientmode->RegisterCallback(WifiManager::GetInstance().GetWifiTogglerManager()->GetConcreteCallback());
clientmode->InitConcreteManager();
std::unique_lock<std::mutex> lock(concreteManagerMutex);
concreteManagers.push_back(clientmode);
concreteManagers.AddManager(clientmode);
}
void WifiControllerMachine::MakeMultiStaManager(MultiStaManager::Role role, int instId)
{
WIFI_LOGI("Enter MakeMultiStaManager");
MultiStaManager *multiStaMode = new (std::nothrow) MultiStaManager(role, instId);
auto multiStaMode = std::make_shared<MultiStaManager>(role, instId);
if (multiStaMode == nullptr) {
WIFI_LOGE("new multiStaMode failed");
return;
}
multiStaMode->RegisterCallback(WifiManager::GetInstance().GetWifiTogglerManager()->GetMultiStaCallback());
multiStaMode->InitMultiStaManager();
std::unique_lock<std::mutex> lock(multiStaManagerMutex);
multiStaManagers.push_back(multiStaMode);
multiStaManagers.AddManager(multiStaMode);
}
#ifdef FEATURE_AP_SUPPORT
void WifiControllerMachine::MakeSoftapManager(SoftApManager::Role role, int id)
{
WIFI_LOGE("Enter MakeSoftapManager");
SoftApManager *softapmode = new (std::nothrow) SoftApManager(role, id);
auto softapmode = std::make_shared<SoftApManager>(role, id);
softapmode->RegisterCallback(WifiManager::GetInstance().GetWifiTogglerManager()->GetSoftApCallback());
softapmode->InitSoftapManager();
std::unique_lock<std::mutex> lock(softapManagerMutex);
softapManagers.push_back(softapmode);
softApManagers.AddManager(softapmode);
}
bool WifiControllerMachine::ShouldEnableSoftap()
@ -469,6 +392,103 @@ bool WifiControllerMachine::ShouldEnableSoftap()
WIFI_LOGI("Softap toggled state is %{public}d", toggledState);
return toggledState;
}
#ifdef FEATURE_RPT_SUPPORT
std::shared_ptr<RptManager> WifiControllerMachine::GetRptManager(int id)
{
return id == ANY_ID ? rptManagers.GetFirstManager() : rptManagers.GetManager(id);
}
void WifiControllerMachine::MakeRptManager(RptManager::Role role, int id)
{
WIFI_LOGE("Enter MakeRptManager");
auto rptmode = std::make_shared<RptManager>(role, id);
rptmode->RegisterCallback(WifiManager::GetInstance().GetWifiTogglerManager()->GetRptCallback());
rptmode->InitRptManager();
rptManagers.AddManager(rptmode);
}
bool WifiControllerMachine::ShouldUseRpt(int id)
{
#ifndef FEATURE_P2P_SUPPORT
return false;
#else
const int bufferLen = 32;
char buffer[bufferLen] = {0};
GetParamValue("const.wifi.support_rpt", "false", buffer, bufferLen);
std::string supportRpt = buffer;
if (supportRpt == "false") {
WIFI_LOGI("ShouldUseRpt not support rpt");
return false;
}
GetParamValue("const.wifi.support_sapcoexist", "false", buffer, bufferLen);
std::string supportSapcoexist = buffer;
if (supportSapcoexist == "true") {
WIFI_LOGI("ShouldUseRpt support coexist, not use rpt");
return false;
}
if (WifiConfigCenter::GetInstance().GetWifiMidState(id) != WifiOprMidState::RUNNING) {
WIFI_LOGI("ShouldUseRpt wifi is off");
return false;
}
if (rptManagers.HasAnyManager()) {
WIFI_LOGI("ShouldUseRpt rpt is running");
return false;
}
WifiLinkedInfo linkedInfo;
WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo);
if (linkedInfo.connState != ConnState::CONNECTED) {
WIFI_LOGI("ShouldUseRpt wifi is not connected");
return false;
}
if (WifiConfigCenter::GetInstance().GetP2pMidState() != WifiOprMidState::RUNNING) {
WIFI_LOGI("ShouldUseRpt p2p is not on");
return false;
}
return true;
#endif
}
#endif
WifiControllerMachine::HotspotMode WifiControllerMachine::CalculateHotspotMode(int id)
{
if (hotspotMode != HotspotMode::NONE) {
return hotspotMode;
}
#ifdef FEATURE_RPT_SUPPORT
if (softApManagers.HasAnyManager()) {
return HotspotMode::SOFTAP;
} else if (rptManagers.HasAnyManager()) {
return HotspotMode::RPT;
} else if (ShouldUseRpt(id)) {
return HotspotMode::RPT;
}
#endif
return HotspotMode::SOFTAP;
}
void WifiControllerMachine::MakeHotspotManager(int id, bool startTimer)
{
hotspotMode = CalculateHotspotMode(id);
if (hotspotMode == HotspotMode::SOFTAP && !softApManagers.IdExist(id)) {
MakeSoftapManager(SoftApManager::Role::ROLE_SOFTAP, id);
if (startTimer) {
StartTimer(CMD_AP_START_TIME, SOFT_AP_TIME_OUT);
}
return;
}
#ifdef FEATURE_RPT_SUPPORT
if (hotspotMode == HotspotMode::RPT && !rptManagers.IdExist(id)) {
MakeRptManager(RptManager::Role::ROLE_RPT, id);
return;
}
#endif
}
#endif
bool WifiControllerMachine::ShouldDisableWifi(InternalMessagePtr msg)
@ -476,7 +496,7 @@ bool WifiControllerMachine::ShouldDisableWifi(InternalMessagePtr msg)
auto currState = WifiConfigCenter::GetInstance().GetWifiDetailState(msg->GetParam2());
if (WifiConfigCenter::GetInstance().GetWifiToggledEnable() == WIFI_STATE_SEMI_ENABLED &&
(currState == WifiDetailState::STATE_ACTIVATED || currState == WifiDetailState::STATE_ACTIVATING) &&
msg->GetMessageName() == CMD_WIFI_TOGGLED && ConcreteIdExist(msg->GetParam2())) {
msg->GetMessageName() == CMD_WIFI_TOGGLED && concreteManagers.IdExist(msg->GetParam2())) {
WIFI_LOGI("Should disable wifi");
return true;
}
@ -547,213 +567,67 @@ bool WifiControllerMachine::IsScanOnlyEnable()
return false;
}
void WifiControllerMachine::StopAllConcreteManagers()
{
WIFI_LOGI("Enter StopAllConcreteManagers.");
if (!HasAnyConcreteManager()) {
return;
}
std::unique_lock<std::mutex> lock(concreteManagerMutex);
for (auto iter = concreteManagers.begin(); iter != concreteManagers.end(); ++iter) {
WIFI_LOGD("Enter StopAllConcreteManagers. mid = %{public}d", (*iter)->mid);
(*iter)->GetConcreteMachine()->SendMessage(CONCRETE_CMD_STOP);
}
}
void WifiControllerMachine::StopConcreteManager(int id)
{
if (!HasAnyConcreteManager()) {
return;
}
std::unique_lock<std::mutex> lock(concreteManagerMutex);
for (auto iter = concreteManagers.begin(); iter != concreteManagers.end(); ++iter) {
if ((*iter)->mid == id) {
(*iter)->GetConcreteMachine()->SendMessage(CONCRETE_CMD_STOP);
return;
}
}
return;
}
void WifiControllerMachine::StopMultiStaManager(int id)
{
WIFI_LOGI("Enter StopMultiStaManager, id = %{public}d", id);
if (!HasAnyMultiStaManager()) {
return;
}
std::unique_lock<std::mutex> lock(multiStaManagerMutex);
for (auto iter = multiStaManagers.begin(); iter != multiStaManagers.end(); ++iter) {
if ((*iter)->mid == id) {
(*iter)->GetMultiStaMachine()->SendMessage(MULTI_STA_CMD_STOP);
return;
}
}
}
void WifiControllerMachine::StopAllMultiStaManagers()
{
WIFI_LOGI("Enter StopAllMultiStaManagers");
if (!HasAnyMultiStaManager()) {
return;
}
std::unique_lock<std::mutex> lock(multiStaManagerMutex);
for (auto iter = multiStaManagers.begin(); iter != multiStaManagers.end(); ++iter) {
(*iter)->GetMultiStaMachine()->SendMessage(MULTI_STA_CMD_STOP);
}
}
#ifdef FEATURE_AP_SUPPORT
void WifiControllerMachine::StopSoftapManager(int id)
{
if (!HasAnySoftApManager()) {
return;
}
std::unique_lock<std::mutex> lock(softapManagerMutex);
for (auto iter = softapManagers.begin(); iter != softapManagers.end(); ++iter) {
if ((*iter)->mid == id) {
(*iter)->GetSoftapMachine()->SendMessage(SOFTAP_CMD_STOP);
return;
}
}
}
void WifiControllerMachine::StopAllSoftapManagers()
{
if (!HasAnySoftApManager()) {
WIFI_LOGE("Not found AnySoftApManager.");
return;
}
std::unique_lock<std::mutex> lock(softapManagerMutex);
for (auto iter = softapManagers.begin(); iter != softapManagers.end(); ++iter) {
(*iter)->GetSoftapMachine()->SendMessage(SOFTAP_CMD_STOP);
}
}
#endif
void WifiControllerMachine::RemoveConcreteManager(int id)
{
ConcreteClientModeManager *concreteManager = nullptr;
if (!HasAnyConcreteManager()) {
return;
}
{
std::unique_lock<std::mutex> lock(concreteManagerMutex);
for (auto iter = concreteManagers.begin(); iter != concreteManagers.end(); ++iter) {
if ((*iter)->mid == id) {
concreteManager = *iter;
concreteManagers.erase(iter);
break;
}
}
}
if (concreteManager != nullptr) {
delete concreteManager;
}
}
void WifiControllerMachine::RemoveMultiStaManager(int id)
{
MultiStaManager *multiStaMgr = nullptr;
if (!HasAnyMultiStaManager()) {
return;
}
{
std::unique_lock<std::mutex> lock(multiStaManagerMutex);
for (auto iter = multiStaManagers.begin(); iter != multiStaManagers.end(); ++iter) {
if ((*iter)->mid == id) {
multiStaMgr = *iter;
multiStaManagers.erase(iter);
break;
}
}
}
if (multiStaMgr != nullptr) {
delete multiStaMgr;
multiStaMgr = nullptr;
}
}
#ifdef FEATURE_AP_SUPPORT
void WifiControllerMachine::RmoveSoftapManager(int id)
{
SoftApManager *softapManager = nullptr;
if (!HasAnySoftApManager()) {
return;
}
std::unique_lock<std::mutex> lock(softapManagerMutex);
for (auto iter = softapManagers.begin(); iter != softapManagers.end(); ++iter) {
if ((*iter)->mid == id) {
softapManager = *iter;
softapManagers.erase(iter);
break;
}
}
if (softapManager != nullptr) {
delete softapManager;
}
}
#endif
void WifiControllerMachine::HandleStaClose(int id)
{
std::unique_lock<std::mutex> lock(concreteManagerMutex);
if (concreteManagers.empty()) {
return;
}
for (auto iter = concreteManagers.begin(); iter != concreteManagers.end(); ++iter) {
if ((*iter)->mid == id) {
(*iter)->GetConcreteMachine()->SendMessage(CONCRETE_CMD_STA_STOP);
break;
}
}
concreteManagers.SendMessage(CONCRETE_CMD_STA_STOP, id);
}
void WifiControllerMachine::HandleWifi2Close(int id)
{
std::unique_lock<std::mutex> lock(multiStaManagerMutex);
if (multiStaManagers.empty()) {
return;
}
for (auto iter = multiStaManagers.begin(); iter != multiStaManagers.end(); ++iter) {
if ((*iter)->mid == id) {
(*iter)->GetMultiStaMachine()->SendMessage(MULTI_STA_CMD_STOPPED);
break;
}
}
multiStaManagers.SendMessage(MULTI_STA_CMD_STOPPED, id);
}
void WifiControllerMachine::SwitchRole(ConcreteManagerRole role)
{
std::unique_lock<std::mutex> lock(concreteManagerMutex);
for (auto iter = concreteManagers.begin(); iter != concreteManagers.end(); ++iter) {
std::unique_lock<std::mutex> lock(concreteManagers.mutex_);
for (auto iter = concreteManagers.managers.begin(); iter != concreteManagers.managers.end(); ++iter) {
(*iter)->SetRole(role);
}
}
void WifiControllerMachine::EnableState::HandleWifiToggleChangeForRpt(int id, int isOpen)
{
#ifdef FEATURE_RPT_SUPPORT
if (isOpen == 0 && pWifiControllerMachine->hotspotMode == HotspotMode::RPT) {
WifiConfigCenter::GetInstance().SetSoftapToggledState(false);
pWifiControllerMachine->SendMessage(CMD_SOFTAP_TOGGLED, 0, id);
}
#endif
}
bool WifiControllerMachine::EnableState::HandleWifiToggleChangeForWlan1(int id, int isOpen)
{
if (id == INSTID_WLAN1 && isOpen == 0) {
WIFI_LOGI("Toggle disable wlan1.");
pWifiControllerMachine->multiStaManagers.StopManager(INSTID_WLAN1);
return true;
}
if (id == INSTID_WLAN1 && isOpen == 1 &&
WifiConfigCenter::GetInstance().GetPersistWifiState(INSTID_WLAN0) == WIFI_STATE_ENABLED) {
pWifiControllerMachine->MakeMultiStaManager(MultiStaManager::Role::ROLE_STA_WIFI_2, id);
return true;
}
return false;
}
void WifiControllerMachine::EnableState::HandleWifiToggleChangeInEnabledState(InternalMessagePtr msg)
{
if (msg->GetParam2() == INSTID_WLAN1 && msg->GetParam1() == 0) {
WIFI_LOGI("Toggle disable wlan1.");
pWifiControllerMachine->StopMultiStaManager(INSTID_WLAN1);
return;
}
if (msg->GetParam2() == INSTID_WLAN1 && WifiConfigCenter::GetInstance().GetPersistWifiState(INSTID_WLAN0)
== WIFI_STATE_ENABLED && msg->GetParam1() == 1) {
pWifiControllerMachine->MakeMultiStaManager(MultiStaManager::Role::ROLE_STA_WIFI_2, msg->GetParam2());
int id = msg->GetParam2();
int isOpen = msg->GetParam1();
HandleWifiToggleChangeForRpt(id, isOpen);
if (HandleWifiToggleChangeForWlan1(id, isOpen)) {
return;
}
ConcreteManagerRole presentRole;
if (pWifiControllerMachine->ShouldDisableWifi(msg)) {
pWifiControllerMachine->StopAllMultiStaManagers();
pWifiControllerMachine->StopAllConcreteManagers();
pWifiControllerMachine->multiStaManagers.StopAllManagers();
pWifiControllerMachine->concreteManagers.StopAllManagers();
return;
}
if (pWifiControllerMachine->ConcreteIdExist(msg->GetParam2())) {
ConcreteManagerRole presentRole;
if (pWifiControllerMachine->concreteManagers.IdExist(id)) {
if (WifiConfigCenter::GetInstance().GetWifiStopState()) {
return;
}
@ -763,7 +637,7 @@ void WifiControllerMachine::EnableState::HandleWifiToggleChangeInEnabledState(In
return;
}
if (presentRole != ConcreteManagerRole::ROLE_CLIENT_STA) {
pWifiControllerMachine->StopMultiStaManager(INSTID_WLAN1);
pWifiControllerMachine->multiStaManagers.StopManager(INSTID_WLAN1);
}
pWifiControllerMachine->SwitchRole(presentRole);
return;
@ -772,8 +646,8 @@ void WifiControllerMachine::EnableState::HandleWifiToggleChangeInEnabledState(In
#ifdef FEATURE_AP_SUPPORT
#ifndef HDI_CHIP_INTERFACE_SUPPORT
if (!WifiConfigCenter::GetInstance().GetCoexSupport() &&
pWifiControllerMachine->HasAnySoftApManager()) {
pWifiControllerMachine->StopAllSoftapManagers();
pWifiControllerMachine->softApManagers.HasAnyManager()) {
pWifiControllerMachine->softApManagers.StopAllManagers();
return;
}
#endif
@ -783,48 +657,65 @@ void WifiControllerMachine::EnableState::HandleWifiToggleChangeInEnabledState(In
WIFI_LOGE("Get unknow wifi role in EnableState.");
return;
}
pWifiControllerMachine->MakeConcreteManager(presentRole, msg->GetParam2());
pWifiControllerMachine->MakeConcreteManager(presentRole, id);
return;
}
#ifdef FEATURE_AP_SUPPORT
void WifiControllerMachine::EnableState::HandleSoftapToggleChangeInEnabledState(InternalMessagePtr msg)
{
int open = msg->GetParam1();
int id = msg->GetParam2();
WIFI_LOGI("handleSoftapToggleChangeInEnabledState");
if (msg->GetParam1() == 1) {
WIFI_LOGE("handleSoftapToggleChangeInEnabledState");
if (open == 1) {
HandleSoftapOpen(id);
} else {
HandleSoftapClose(id);
}
}
void WifiControllerMachine::EnableState::HandleSoftapOpen(int id)
{
#ifndef HDI_CHIP_INTERFACE_SUPPORT
if (!WifiConfigCenter::GetInstance().GetCoexSupport() &&
pWifiControllerMachine->HasAnyConcreteManager()) {
pWifiControllerMachine->StopAllMultiStaManagers();
pWifiControllerMachine->StopAllConcreteManagers();
pWifiControllerMachine->concreteManagers.HasAnyManager()) {
pWifiControllerMachine->multiStaManagers.StopAllManagers();
pWifiControllerMachine->concreteManagers.StopAllManagers();
pWifiControllerMachine->mApidStopWifi = id;
return;
}
#endif
if (!pWifiControllerMachine->SoftApIdExist(id)) {
pWifiControllerMachine->MakeSoftapManager(SoftApManager::Role::ROLE_SOFTAP, id);
return;
}
}
pWifiControllerMachine->MakeHotspotManager(id);
}
void WifiControllerMachine::EnableState::HandleSoftapClose(int id)
{
#ifndef HDI_CHIP_INTERFACE_SUPPORT
if (!WifiConfigCenter::GetInstance().GetCoexSupport() &&
pWifiControllerMachine->ShouldEnableWifi(INSTID_WLAN0) &&
!WifiConfigCenter::GetInstance().GetWifiStopState() &&
pWifiControllerMachine->HasAnyConcreteManager()) {
pWifiControllerMachine->concreteManagers.HasAnyManager()) {
ConcreteManagerRole role = pWifiControllerMachine->GetWifiRole();
if (role != ConcreteManagerRole::ROLE_UNKNOW) {
pWifiControllerMachine->SwitchRole(role);
}
}
#endif
#ifdef FEATURE_RPT_SUPPORT
if (pWifiControllerMachine->hotspotMode == HotspotMode::RPT) {
if (pWifiControllerMachine->rptManagers.IdExist(id)) {
pWifiControllerMachine->rptManagers.StopManager(id);
}
return;
}
#endif
WifiOprMidState apState = WifiConfigCenter::GetInstance().GetApMidState(id);
if (apState == WifiOprMidState::CLOSING || apState == WifiOprMidState::OPENING) {
WIFI_LOGI("Current ap state is %{public}d, return", apState);
return;
}
if (pWifiControllerMachine->SoftApIdExist(id)) {
pWifiControllerMachine->StopSoftapManager(id);
if (pWifiControllerMachine->softApManagers.IdExist(id)) {
pWifiControllerMachine->softApManagers.StopManager(id);
pWifiControllerMachine->StartTimer(CMD_AP_STOP_TIME, SOFT_AP_TIME_OUT);
return;
}
@ -834,7 +725,7 @@ void WifiControllerMachine::EnableState::HandleSoftapToggleChangeInEnabledState(
void WifiControllerMachine::EnableState::HandleStaStartFailure(int id)
{
WIFI_LOGE("HandleStaStartFailure");
pWifiControllerMachine->RemoveConcreteManager(id);
pWifiControllerMachine->concreteManagers.RemoveManager(id);
mWifiStartFailCount++;
if (pWifiControllerMachine->ShouldEnableWifi(id) && mWifiStartFailCount < WIFI_OPEN_RETRY_MAX_COUNT) {
pWifiControllerMachine->StartTimer(CMD_OPEN_WIFI_RETRY, WIFI_OPEN_RETRY_TIMEOUT);
@ -843,28 +734,22 @@ void WifiControllerMachine::EnableState::HandleStaStartFailure(int id)
void WifiControllerMachine::EnableState::HandleStaRemoved(InternalMessagePtr msg)
{
{
std::unique_lock<std::mutex> lock(pWifiControllerMachine->concreteManagerMutex);
for (auto iter = pWifiControllerMachine->concreteManagers.begin();
iter != pWifiControllerMachine->concreteManagers.end(); ++iter) {
if ((*iter)->mid == msg->GetParam2() && msg->GetParam1() >= 0) {
(*iter)->GetConcreteMachine()->SendMessage(CONCRETE_CMD_STA_REMOVED);
}
}
if (msg->GetParam1() >= 0) {
pWifiControllerMachine->concreteManagers.SendMessage(CONCRETE_CMD_STA_REMOVED, msg->GetParam2());
}
pWifiControllerMachine->StopAllMultiStaManagers();
pWifiControllerMachine->StopConcreteManager(msg->GetParam2());
pWifiControllerMachine->multiStaManagers.StopAllManagers();
pWifiControllerMachine->concreteManagers.StopManager(msg->GetParam2());
}
void WifiControllerMachine::EnableState::HandleWifi2Removed(InternalMessagePtr msg)
{
pWifiControllerMachine->StopMultiStaManager(msg->GetParam2());
pWifiControllerMachine->multiStaManagers.StopManager(msg->GetParam2());
}
void WifiControllerMachine::EnableState::HandleConcreteClientRemoved(InternalMessagePtr msg)
{
int id = msg->GetParam1();
pWifiControllerMachine->RemoveConcreteManager(id);
pWifiControllerMachine->concreteManagers.RemoveManager(id);
if (!(pWifiControllerMachine->HasAnyManager())) {
pWifiControllerMachine->SwitchState(pWifiControllerMachine->pDisableState);
}
@ -886,35 +771,26 @@ void WifiControllerMachine::HandleStaStart(int id)
{
mWifiStartFailCount = 0;
this->StopTimer(CMD_OPEN_WIFI_RETRY);
std::unique_lock<std::mutex> lock(concreteManagerMutex);
for (auto iter = concreteManagers.begin(); iter != concreteManagers.end(); ++iter) {
(*iter)->GetConcreteMachine()->SendMessage(CONCRETE_CMD_STA_START);
}
concreteManagers.SendMessageToAll(CONCRETE_CMD_STA_START);
}
void WifiControllerMachine::HandleWifi2Start(int id)
{
std::unique_lock<std::mutex> lock(multiStaManagerMutex);
for (auto iter = multiStaManagers.begin(); iter != multiStaManagers.end(); ++iter) {
(*iter)->GetMultiStaMachine()->SendMessage(MULTI_STA_CMD_STARTED);
}
multiStaManagers.SendMessageToAll(MULTI_STA_CMD_STARTED);
}
void WifiControllerMachine::HandleStaSemiActive(int id)
{
mWifiStartFailCount = 0;
this->StopTimer(CMD_OPEN_WIFI_RETRY);
std::unique_lock<std::mutex> lock(concreteManagerMutex);
for (auto iter = concreteManagers.begin(); iter != concreteManagers.end(); ++iter) {
(*iter)->GetConcreteMachine()->SendMessage(CONCRETE_CMD_STA_SEMI_ACTIVE);
}
concreteManagers.SendMessageToAll(CONCRETE_CMD_STA_SEMI_ACTIVE);
}
#ifdef FEATURE_AP_SUPPORT
void WifiControllerMachine::EnableState::HandleApStart(int id)
{
if (!pWifiControllerMachine->ShouldEnableSoftap()) {
pWifiControllerMachine->StopSoftapManager(id);
pWifiControllerMachine->softApManagers.StopManager(id);
return;
}
pWifiControllerMachine->StartSoftapCloseTimer();
@ -922,8 +798,8 @@ void WifiControllerMachine::EnableState::HandleApStart(int id)
void WifiControllerMachine::EnableState::HandleApRemoved(InternalMessagePtr msg)
{
pWifiControllerMachine->StopSoftapManager(msg->GetParam2());
SoftApManager *softap = pWifiControllerMachine->GetSoftApManager(msg->GetParam2());
pWifiControllerMachine->softApManagers.StopManager(msg->GetParam2());
auto softap = pWifiControllerMachine->softApManagers.GetManager(msg->GetParam2());
if (softap != nullptr) {
softap->SetRole(SoftApManager::Role::ROLE_HAS_REMOVED);
}
@ -935,19 +811,34 @@ void WifiControllerMachine::EnableState::HandleApStop(InternalMessagePtr msg)
pWifiControllerMachine->StopSoftapCloseTimer();
pWifiControllerMachine->HandleSoftapStop(msg->GetParam1());
}
#ifdef FEATURE_RPT_SUPPORT
void WifiControllerMachine::EnableState::HandleP2pStop(InternalMessagePtr msg)
{
auto rpt = pWifiControllerMachine->rptManagers.GetManager(msg->GetParam1());
if (rpt != nullptr) {
rpt->OnP2pClosed();
}
}
void WifiControllerMachine::EnableState::HandleRptStartFail(InternalMessagePtr msg)
{
WIFI_LOGE("rpt start fail, set softap toggled false");
WifiConfigCenter::GetInstance().SetSoftapToggledState(false);
}
#endif
#endif
void WifiControllerMachine::HandleConcreteStop(int id)
{
WIFI_LOGD("WifiControllerMachine HandleConcreteStop id = %{public}d", id);
RemoveConcreteManager(id);
concreteManagers.RemoveManager(id);
#ifndef HDI_CHIP_INTERFACE_SUPPORT
if (!WifiConfigCenter::GetInstance().GetCoexSupport()) {
#ifdef FEATURE_AP_SUPPORT
int airplanstate = WifiConfigCenter::GetInstance().GetAirplaneModeState();
if (ShouldEnableSoftap() && airplanstate != MODE_STATE_OPEN &&
!SoftApIdExist(mApidStopWifi)) {
MakeSoftapManager(SoftApManager::Role::ROLE_SOFTAP, mApidStopWifi);
if (ShouldEnableSoftap() && airplanstate != MODE_STATE_OPEN) {
MakeHotspotManager(id);
return;
}
#endif
@ -974,21 +865,29 @@ void WifiControllerMachine::HandleConcreteStop(int id)
}
#ifdef FEATURE_AP_SUPPORT
void WifiControllerMachine::HandleSoftapStop(int id)
template <class T>
void WifiControllerMachine::HandleHotspotStop(int id, HotspotMode THotspotMode, ManagerControl<T> &TManagers)
{
ConcreteManagerRole role;
SoftApManager *softap = GetSoftApManager(id);
if (softap != nullptr && softap->GetRole() == SoftApManager::Role::ROLE_HAS_REMOVED) {
RmoveSoftapManager(id);
auto softap = TManagers.GetManager(id);
if (softap != nullptr && softap->GetRole() == T::Role::ROLE_HAS_REMOVED) {
TManagers.RemoveManager(id);
softap = nullptr;
if (!TManagers.HasAnyManager() && hotspotMode == THotspotMode) {
hotspotMode = HotspotMode::NONE;
}
if (!HasAnyManager()) {
SwitchState(pDisableState);
}
return;
}
RmoveSoftapManager(id);
if (ShouldEnableSoftap() && !SoftApIdExist(0)) {
MakeSoftapManager(SoftApManager::Role::ROLE_SOFTAP, 0);
TManagers.RemoveManager(id);
softap = nullptr;
if (!TManagers.HasAnyManager() && hotspotMode == THotspotMode) {
hotspotMode = HotspotMode::NONE;
}
if (ShouldEnableSoftap()) {
MakeHotspotManager(id);
return;
}
if (HasAnyManager()) {
@ -1006,6 +905,18 @@ void WifiControllerMachine::HandleSoftapStop(int id)
}
}
void WifiControllerMachine::HandleSoftapStop(int id)
{
HandleHotspotStop(id, HotspotMode::SOFTAP, softApManagers);
}
#ifdef FEATURE_RPT_SUPPORT
void WifiControllerMachine::HandleRptStop(int id)
{
HandleHotspotStop(id, HotspotMode::RPT, rptManagers);
}
#endif
static void AlarmStopSoftap()
{
WifiManager::GetInstance().GetWifiTogglerManager()->SoftapToggled(0, 0);
@ -1051,11 +962,14 @@ void WifiControllerMachine::ShutdownWifi(bool shutDownAp)
if (shutDownAp) {
#ifdef FEATURE_AP_SUPPORT
WifiConfigCenter::GetInstance().SetSoftapToggledState(false);
StopAllSoftapManagers();
softApManagers.StopAllManagers();
#ifdef FEATURE_RPT_SUPPORT
rptManagers.StopAllManagers();
#endif
#endif
}
StopAllConcreteManagers();
StopAllConcreteManagers();
multiStaManagers.StopAllManagers();
concreteManagers.StopAllManagers();
}
} // namespace Wifi
} // namespace OHOS

View File

@ -22,10 +22,14 @@
#include "state_machine.h"
#include "wifi_logger.h"
#include "wifi_errcode.h"
#include "wifi_controller_managers_template.h"
#include "concrete_clientmode_manager.h"
#include "multi_sta_manager.h"
#ifdef FEATURE_AP_SUPPORT
#include "softap_manager.h"
#ifdef FEATURE_RPT_SUPPORT
#include "rpt_manager.h"
#endif
#endif
namespace OHOS {
@ -59,14 +63,23 @@ public:
void HandleWifi2Removed(InternalMessagePtr msg);
void HandleAPServiceStartFail(int id);
void HandleConcreteClientRemoved(InternalMessagePtr msg);
private:
void HandleApStart(int id);
void HandleWifiToggleChangeForRpt(int id, int isOpen);
bool HandleWifiToggleChangeForWlan1(int id, int isOpen);
void HandleWifiToggleChangeInEnabledState(InternalMessagePtr msg);
#ifdef FEATURE_AP_SUPPORT
void HandleSoftapToggleChangeInEnabledState(InternalMessagePtr msg);
void HandleSoftapOpen(int id);
void HandleSoftapClose(int id);
void HandleApRemoved(InternalMessagePtr msg);
void HandleApStop(InternalMessagePtr msg);
void HandleApMsg(InternalMessagePtr msg);
#ifdef FEATURE_RPT_SUPPORT
void HandleRptStartFail(InternalMessagePtr msg);
void HandleP2pStop(InternalMessagePtr msg);
#endif
#endif
WifiControllerMachine *pWifiControllerMachine;
};
@ -83,11 +96,16 @@ public:
WifiControllerMachine *pWifiControllerMachine;
};
#ifdef FEATURE_AP_SUPPORT
enum class HotspotMode {
NONE = 0,
SOFTAP,
RPT
};
#endif
public:
ErrCode InitWifiControllerMachine();
void RemoveConcreteManager(int id);
void RemoveMultiStaManager(int id);
void HandleStaClose(int id);
void HandleWifi2Close(int id);
void HandleStaStart(int id);
@ -96,13 +114,16 @@ public:
void HandleConcreteStop(int id);
void ClearWifiStartFailCount();
#ifdef FEATURE_AP_SUPPORT
void RmoveSoftapManager(int id);
template <class T> void HandleHotspotStop(int id, HotspotMode THotspotMode, ManagerControl<T> &TManagers);
void HandleSoftapStop(int id);
void StartSoftapCloseTimer();
void StopSoftapCloseTimer();
#ifdef FEATURE_RPT_SUPPORT
void HandleRptStop(int id);
std::shared_ptr<RptManager> GetRptManager(int id);
#endif
#endif
void ShutdownWifi(bool shutDownAp = true);
private:
template <typename T>
inline void ParsePointer(T *&pointer)
@ -124,29 +145,22 @@ private:
void BuildStateTree();
ErrCode InitWifiStates();
bool HasAnyConcreteManager();
bool HasAnyMultiStaManager();
bool HasAnyManager();
bool ConcreteIdExist(int id);
bool IsWifi2IdExist(int id);
void MakeConcreteManager(ConcreteManagerRole role, int id);
void MakeMultiStaManager(MultiStaManager::Role role, int instId);
#ifdef FEATURE_AP_SUPPORT
bool HasAnySoftApManager();
bool SoftApIdExist(int id);
void MakeHotspotManager(int id, bool startTimer = false);
void MakeSoftapManager(SoftApManager::Role role, int id);
HotspotMode CalculateHotspotMode(int id);
bool ShouldEnableSoftap();
void StopAllSoftapManagers();
void StopSoftapManager(int id);
SoftApManager *GetSoftApManager(int id);
#ifdef FEATURE_RPT_SUPPORT
bool ShouldUseRpt(int id);
void MakeRptManager(RptManager::Role role, int id);
#endif
#endif
bool ShouldDisableWifi(InternalMessagePtr msg);
bool ShouldEnableWifi(int id = 0);
ConcreteManagerRole GetWifiRole();
void StopAllConcreteManagers();
void StopConcreteManager(int id);
void StopAllMultiStaManagers();
void StopMultiStaManager(int id);
void SwitchRole(ConcreteManagerRole role);
void HandleAirplaneOpen();
void HandleAirplaneClose();
@ -160,16 +174,17 @@ private:
EnableState *pEnableState;
DisableState *pDisableState;
DefaultState *pDefaultState;
std::vector<ConcreteClientModeManager *> concreteManagers;
mutable std::mutex concreteManagerMutex;
ManagerControl<ConcreteClientModeManager> concreteManagers{CONCRETE_CMD_STOP};
static int mWifiStartFailCount;
#ifdef FEATURE_AP_SUPPORT
std::vector<SoftApManager *> softapManagers;
mutable std::mutex softapManagerMutex;
uint64_t stopSoftapTimerId_ {0};
#ifdef FEATURE_RPT_SUPPORT
ManagerControl<RptManager> rptManagers{RPT_CMD_STOP};
#endif
mutable std::mutex multiStaManagerMutex;
std::vector<MultiStaManager *> multiStaManagers;
ManagerControl<SoftApManager> softApManagers{SOFTAP_CMD_STOP};
uint64_t stopSoftapTimerId_{0};
HotspotMode hotspotMode {HotspotMode::NONE};
#endif
ManagerControl<MultiStaManager> multiStaManagers{MULTI_STA_CMD_STOP};
};
} // namespace Wifi
} // namespace OHOS

View File

@ -324,6 +324,22 @@ std::unique_ptr<WifiTogglerManager>& WifiManager::GetWifiTogglerManager()
return wifiTogglerManager;
}
std::shared_ptr<RptInterface> WifiManager::GetRptInterface(int id)
{
#if defined(FEATURE_RPT_SUPPORT) && defined(FEATURE_AP_SUPPORT) && defined(FEATURE_P2P_SUPPORT)
if (wifiTogglerManager == nullptr) {
return nullptr;
}
auto& wifiControllerMachine = wifiTogglerManager->GetControllerMachine();
if (wifiControllerMachine == nullptr) {
return nullptr;
}
return wifiControllerMachine->GetRptManager(id);
#else
return nullptr;
#endif
}
#ifdef FEATURE_AP_SUPPORT
std::unique_ptr<WifiHotspotManager>& WifiManager::GetWifiHotspotManager()
{

View File

@ -36,6 +36,9 @@
#include "wifi_app_state_aware.h"
#include "wifi_multi_vap_manager.h"
#endif
#include "rpt_interface.h"
#define ANY_ID (-1)
namespace OHOS {
namespace Wifi {
@ -116,6 +119,7 @@ public:
std::unique_ptr<WifiStaManager>& GetWifiStaManager();
std::unique_ptr<WifiScanManager>& GetWifiScanManager();
std::unique_ptr<WifiTogglerManager>& GetWifiTogglerManager();
std::shared_ptr<RptInterface> GetRptInterface(int id = ANY_ID);
#ifdef FEATURE_AP_SUPPORT
std::unique_ptr<WifiHotspotManager>& GetWifiHotspotManager();
#endif

View File

@ -777,6 +777,27 @@ WifiErrorNo HdiP2pRemoveNetwork(int networkId)
return WIFI_HAL_OPT_OK;
}
WifiErrorNo HdiP2pSetSingleConfig(int networkId, const char *key, const char *value)
{
LOGI("HdiP2pSetSingleConfig enter");
struct IWpaInterface *wpaObj = GetWpaInterface();
if (wpaObj == NULL) {
LOGE("HdiP2pSetSingleConfig: wpaObj is NULL");
return WIFI_HAL_OPT_FAILED;
}
char cfgValue[WIFI_P2P_GROUP_CONFIG_VALUE_LENGTH];
if (sprintf_s(cfgValue, sizeof(cfgValue), "%s", value) < 0) {
return WIFI_HAL_OPT_FAILED;
}
int32_t result = wpaObj->P2pSetGroupConfig(wpaObj, GetHdiP2pIfaceName(), networkId, key, cfgValue);
if (result != HDF_SUCCESS) {
LOGE("HdiP2pSetSingleConfig failed result:%{public}d", result);
return WIFI_HAL_OPT_FAILED;
}
LOGI("HdiP2pSetSingleConfig success.");
return WIFI_HAL_OPT_OK;
}
WifiErrorNo HdiP2pSetGroupConfig(int networkId, P2pGroupConfig *pConfig, int size)
{
LOGI("HdiP2pSetGroupConfig enter size=%{public}d", size);

View File

@ -78,6 +78,8 @@ WifiErrorNo HdiP2pFlushService();
WifiErrorNo HdiP2pRemoveNetwork(int networkId);
WifiErrorNo HdiP2pSetSingleConfig(int networkId, const char *key, const char *value);
WifiErrorNo HdiP2pSetGroupConfig(int networkId, P2pGroupConfig *pConfig, int size);
WifiErrorNo HdiP2pInvite(const char *peerBssid, const char *goBssid, const char *ifname);

View File

@ -1368,6 +1368,13 @@ WifiErrorNo WifiHdiWpaClient::ReqP2pGetSupportFrequencies(int band, std::vector<
return WIFI_HAL_OPT_FAILED;
}
WifiErrorNo WifiHdiWpaClient::ReqP2pSetSingleConfig(int networkId,
const std::string &key, const std::string &value) const
{
LOGI("WifiHdiWpaClient::%{public}s enter, key=%{public}s", __func__, key.c_str());
return HdiP2pSetSingleConfig(networkId, key.c_str(), value.c_str());
}
WifiErrorNo WifiHdiWpaClient::ReqP2pSetGroupConfig(int networkId, const HalP2pGroupConfig &config) const
{
P2pGroupConfig conf[GROUP_CONFIG_END_POS];

View File

@ -756,6 +756,16 @@ public:
*/
WifiErrorNo ReqP2pGetSupportFrequencies(int band, std::vector<int> &frequencies) const;
/**
* @Description Setting one config of the P2P group.
*
* @param networkId
* @param key
* @param value
* @return WifiErrorNo
*/
WifiErrorNo ReqP2pSetSingleConfig(int networkId, const std::string &key, const std::string &value) const;
/**
* @Description Setting the P2P group config.
*

View File

@ -747,6 +747,68 @@ bool HalDeviceManager::SetApMacAddress(const std::string &ifaceName, const std::
return true;
}
bool HalDeviceManager::SendCmdToDriver(const std::string &ifaceName, const std::string &interfaceName,
int cmd, const std::string &param)
{
if (!CheckReloadChipHdiService()) {
return false;
}
std::lock_guard<std::mutex> lock(mMutex);
LOGI("SendCmdToDriver, ifaceName:%{public}s, cmd:%{public}d", ifaceName.c_str(), cmd);
sptr<IChipIface> iface = nullptr;
if (auto iter = mIWifiP2pIfaces.find(ifaceName); iter != mIWifiP2pIfaces.end()) {
iface = iter->second;
} else if (auto iter = mIWifiApIfaces.find(ifaceName); iter != mIWifiApIfaces.end()) {
iface = iter->second;
} else {
LOGE("SendCmdToDriver, not find iface info");
return false;
}
CHECK_NULL_AND_RETURN(iface, false);
std::vector<int8_t> paramBuf;
for (auto c : param) {
int8_t cc = c;
paramBuf.push_back(cc);
}
int32_t ret = iface->SendCmdToDriver(interfaceName, cmd, paramBuf);
if (ret != HDF_SUCCESS) {
LOGE("SendCmdToDriver, call SendCmdToDriver failed! ret:%{public}d", ret);
}
LOGI("SendCmdToDriver success");
return true;
}
std::string HalDeviceManager::MakeMacFilterString(const std::vector<std::string> &blockList)
{
if (blockList.empty()) {
return "MAC_MODE=0,MAC_CNT=0";
}
int macCount = static_cast<int>(blockList.size());
std::string macs = "MAC_MODE=1,MAC_CNT=" + std::to_string(macCount);
for (auto mac : blockList) {
mac.erase(std::remove(mac.begin(), mac.end(), ':'), mac.end());
macs.append(",MAC=").append(mac);
}
return macs;
}
bool HalDeviceManager::SetBlockList(const std::string &ifaceName, const std::string &interfaceName,
const std::vector<std::string> &blockList)
{
const int setMacFilterCmd = 100;
std::string macFilterStr = MakeMacFilterString(blockList);
return SendCmdToDriver(ifaceName, interfaceName, setMacFilterCmd, macFilterStr);
}
bool HalDeviceManager::DisAssociateSta(const std::string &ifaceName, const std::string &interfaceName,
std::string mac)
{
const int disAssociateStaCmd = 101;
mac.erase(std::remove(mac.begin(), mac.end(), ':'), mac.end());
return SendCmdToDriver(ifaceName, interfaceName, disAssociateStaCmd, mac);
}
void HalDeviceManager::ResetHalDeviceManagerInfo(bool isRemoteDied)
{
std::lock_guard<std::mutex> lock(mMutex);

View File

@ -394,6 +394,25 @@ public:
*/
bool SetApMacAddress(const std::string &ifaceName, const std::string &mac);
/**
* @Description set block list
* @param ifaceName ifaceName
* @param interfaceName interfaceName
* @param blockList mac address of block devices
* @return bool
*/
bool SetBlockList(const std::string &ifaceName, const std::string &interfaceName,
const std::vector<std::string> &blockList);
/**
* @Description disassociate with target device
* @param ifaceName ifaceName
* @param interfaceName interfaceName
* @param mac mac address of target device
* @return bool
*/
bool DisAssociateSta(const std::string &ifaceName, const std::string &interfaceName, std::string mac);
private:
bool CheckReloadChipHdiService();
bool CheckChipHdiStarted();
@ -427,6 +446,9 @@ private:
IfaceType createIfaceType);
bool GetChip(const std::string &removeIfaceName, IfaceType removeIfaceType, sptr<IConcreteChip> &chip);
bool RemoveIface(sptr<IChipIface> &iface, bool isCallback, IfaceType createIfaceType);
bool SendCmdToDriver(const std::string &ifaceName, const std::string &interfaceName,
int cmd, const std::string &param);
std::string MakeMacFilterString(const std::vector<std::string> &blockList);
static void ClearStaInfo();
static void ClearApInfo();
static void ResetHalDeviceManagerInfo(bool isRemoteDied);

View File

@ -103,6 +103,31 @@ WifiErrorNo WifiApHalInterface::GetStationList(std::vector<std::string> &result,
#endif
}
WifiErrorNo WifiApHalInterface::SetSoftApBlockList(const std::string &ifaceName,
const std::vector<std::string> &blockList)
{
#ifdef HDI_CHIP_INTERFACE_SUPPORT
if (!DelayedSingleton<HalDeviceManager>::GetInstance()->SetBlockList(ifaceName, ifaceName, blockList)) {
return WIFI_HAL_OPT_FAILED;
}
return WIFI_HAL_OPT_OK;
#else
return WIFI_HAL_OPT_FAILED;
#endif
}
WifiErrorNo WifiApHalInterface::DisAssociateSta(const std::string &ifaceName, const std::string &mac)
{
#ifdef HDI_CHIP_INTERFACE_SUPPORT
if (!DelayedSingleton<HalDeviceManager>::GetInstance()->DisAssociateSta(ifaceName, ifaceName, mac)) {
return WIFI_HAL_OPT_FAILED;
}
return WIFI_HAL_OPT_OK;
#else
return WIFI_HAL_OPT_FAILED;
#endif
}
WifiErrorNo WifiApHalInterface::AddBlockByMac(const std::string &mac, int id)
{
#ifdef HDI_WPA_INTERFACE_SUPPORT

View File

@ -71,6 +71,22 @@ public:
*/
WifiErrorNo GetStationList(std::vector<std::string> &result, int id = 0);
/**
* @Description set block list of ap
* @param ifaceName ifaceName
* @param blockList mac address of block devices
* @return WifiErrorNo
*/
WifiErrorNo SetSoftApBlockList(const std::string &ifaceName, const std::vector<std::string> &blockList);
/**
* @Description disassociate with target device
* @param ifaceName ifaceName
* @param mac mac address of target device
* @return WifiErrorNo
*/
WifiErrorNo DisAssociateSta(const std::string &ifaceName, const std::string &mac);
/**
* @Description To set the blocklist filtering in AP mode to prohibit
* the MAC address connection.

View File

@ -15,6 +15,7 @@
#include "wifi_p2p_hal_interface.h"
#include "wifi_log.h"
#include "hal_device_manage.h"
#include <mutex>
#undef LOG_TAG
@ -547,6 +548,17 @@ WifiErrorNo WifiP2PHalInterface::P2pGetSupportFrequenciesByBand(int band, std::v
#endif
}
WifiErrorNo WifiP2PHalInterface::P2pSetSingleConfig(int networkId,
const std::string &key, const std::string &value) const
{
#ifdef HDI_WPA_INTERFACE_SUPPORT
CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
return mHdiWpaClient->ReqP2pSetSingleConfig(networkId, key, value);
#else
return WIFI_HAL_OPT_FAILED;
#endif
}
WifiErrorNo WifiP2PHalInterface::P2pSetGroupConfig(int networkId, const HalP2pGroupConfig &config) const
{
#ifdef HDI_WPA_INTERFACE_SUPPORT
@ -606,5 +618,31 @@ WifiErrorNo WifiP2PHalInterface::DeliverP2pData(int32_t cmdType, int32_t dataTyp
return WIFI_HAL_OPT_FAILED;
#endif
}
WifiErrorNo WifiP2PHalInterface::SetRptBlockList(const std::string &ifaceName, const std::string &interfaceName,
const std::vector<std::string> &blockList)
{
#ifdef HDI_CHIP_INTERFACE_SUPPORT
if (!DelayedSingleton<HalDeviceManager>::GetInstance()->SetBlockList(ifaceName, interfaceName, blockList)) {
return WIFI_HAL_OPT_FAILED;
}
return WIFI_HAL_OPT_OK;
#else
return WIFI_HAL_OPT_FAILED;
#endif
}
WifiErrorNo WifiP2PHalInterface::DisAssociateSta(const std::string &ifaceName, const std::string &interfaceName,
const std::string &mac)
{
#ifdef HDI_CHIP_INTERFACE_SUPPORT
if (!DelayedSingleton<HalDeviceManager>::GetInstance()->DisAssociateSta(ifaceName, interfaceName, mac)) {
return WIFI_HAL_OPT_FAILED;
}
return WIFI_HAL_OPT_OK;
#else
return WIFI_HAL_OPT_FAILED;
#endif
}
} // namespace Wifi
} // namespace OHOS

View File

@ -412,6 +412,16 @@ public:
*/
WifiErrorNo P2pGetSupportFrequenciesByBand(int band, std::vector<int> &frequencies) const;
/**
* @Description Setting the P2P single config.
*
* @param networkId
* @param key
* @param value
* @return WifiErrorNo
*/
WifiErrorNo P2pSetSingleConfig(int networkId, const std::string &key, const std::string &value) const;
/**
* @Description Setting the P2P group config.
*
@ -462,6 +472,26 @@ public:
*/
WifiErrorNo DeliverP2pData(int32_t cmdType, int32_t dataType, const std::string& carryData) const;
/**
* @Description set block list of rpt
* @param ifaceName ifaceName
* @param interfaceName interfaceName
* @param blockList mac address of block devices
* @return WifiErrorNo
*/
WifiErrorNo SetRptBlockList(const std::string &ifaceName, const std::string &interfaceName,
const std::vector<std::string> &blockList);
/**
* @Description disassociate with target device
* @param ifaceName ifaceName
* @param interfaceName interfaceName
* @param mac mac address of target device
* @return WifiErrorNo
*/
WifiErrorNo DisAssociateSta(const std::string &ifaceName, const std::string &interfaceName,
const std::string &mac);
private:
P2pHalCallback mP2pCallback;
};

View File

@ -262,6 +262,7 @@ bool GroupFormedState::ProcessDisconnectEvt(const InternalMessagePtr msg) const
p2pStateMachine.BroadcastP2pPeersChanged();
p2pStateMachine.BroadcastP2pConnectionChanged();
p2pStateMachine.BroadcastP2pGcLeaveGroup(device);
p2pStateMachine.BroadcastP2pPeerJoinOrLeave(false, device.GetDeviceAddress());
deviceManager.RemoveDevice(device);
if (groupManager.IsCurrGroupClientEmpty() && !groupManager.GetCurrentGroup().IsExplicitGroup()) {
WIFI_LOGE("Clients empty, remove p2p group.");
@ -298,6 +299,7 @@ bool GroupFormedState::ProcessConnectEvt(const InternalMessagePtr msg) const
p2pStateMachine.curClientList.emplace_back(device.GetDeviceAddress());
p2pStateMachine.BroadcastP2pPeersChanged();
p2pStateMachine.BroadcastP2pConnectionChanged();
p2pStateMachine.BroadcastP2pPeerJoinOrLeave(true, device.GetDeviceAddress());
return EXECUTED;
}

View File

@ -20,6 +20,7 @@
#include "wifi_msg.h"
#include "ip2p_service_callbacks.h"
#include "wifi_hid2d_msg.h"
#include "wifi_ap_msg.h"
namespace OHOS {
namespace Wifi {
@ -325,6 +326,20 @@ public:
* @return ErrCode - operate result
*/
virtual ErrCode SetGcIpAddress(const IpAddrInfo& ipInfo) = 0;
/**
* @Description create rpt group
*
* @return ErrCode - operate result
*/
virtual ErrCode CreateRptGroup(const WifiP2pConfig &config) = 0;
/**
* @Description get station list of rpt
*
* @return ErrCode - operate result
*/
virtual ErrCode GetRptStationsList(std::vector<StationInfo> &result) = 0;
};
} // namespace Wifi
} // namespace OHOS

View File

@ -30,6 +30,7 @@ struct IP2pServiceCallbacks {
std::function<void(P2pState)> OnP2pStateChangedEvent;
/* Report the latest devices discovery information. */
std::function<void(const std::vector<WifiP2pDevice> &)> OnP2pPeersChangedEvent;
std::function<void(bool, const std::string &)> OnP2pPeerJoinOrLeaveEvent;
/* Report the latest services discovery information. */
std::function<void(const std::vector<WifiP2pServiceInfo> &)> OnP2pServicesChangedEvent;
/* The event of connection status change. */

View File

@ -102,6 +102,7 @@ enum class P2P_STATE_MACHINE_CMD {
CMD_FORM_GROUP,
CMD_REMOVE_GROUP,
CMD_DELETE_GROUP,
CMD_FORM_RPT_GROUP,
CMD_CONNECT,
CMD_DISCONNECT,
CMD_SET_DEVICE_NAME, /* set device name */

View File

@ -57,6 +57,8 @@ void P2pGroupOperatingState::Init()
{
mProcessFunMap.insert(std::make_pair(P2P_STATE_MACHINE_CMD::CMD_FORM_GROUP,
[this](const InternalMessagePtr msg) { return this->ProcessCmdCreateGroup(msg); }));
mProcessFunMap.insert(std::make_pair(P2P_STATE_MACHINE_CMD::CMD_FORM_RPT_GROUP,
[this](const InternalMessagePtr msg) { return this->ProcessCmdCreateRptGroup(msg); }));
mProcessFunMap.insert(std::make_pair(P2P_STATE_MACHINE_CMD::P2P_EVENT_GROUP_STARTED,
[this](const InternalMessagePtr msg) { return this->ProcessGroupStartedEvt(msg); }));
mProcessFunMap.insert(std::make_pair(P2P_STATE_MACHINE_CMD::CREATE_GROUP_TIMED_OUT,
@ -73,6 +75,45 @@ void P2pGroupOperatingState::Init()
[this](const InternalMessagePtr msg) { return this->ProcessCmdHid2dCreateGroup(msg); }));
}
bool P2pGroupOperatingState::ProcessCmdCreateRptGroup(const InternalMessagePtr msg) const
{
WifiErrorNo ret = WIFI_HAL_OPT_FAILED;
WifiP2pConfigInternal config;
if (!msg->GetMessageObj(config)) {
WIFI_LOGE("failed to get config.");
return false;
}
WifiLinkedInfo linkedInfo;
WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo);
if (linkedInfo.connState == CONNECTED && !config.GetPassphrase().empty() && !config.GetGroupName().empty() &&
config.GetPassphrase().length() >= MIN_PSK_LEN && config.GetPassphrase().length() <= MAX_PSK_LEN) {
bool sameFreq = (linkedInfo.band == static_cast<int>(BandType::BAND_5GHZ) &&
config.GetGoBand() == GroupOwnerBand::GO_BAND_5GHZ) ||
(linkedInfo.band == static_cast<int>(BandType::BAND_2GHZ) &&
config.GetGoBand() == GroupOwnerBand::GO_BAND_2GHZ);
int freq = sameFreq ? linkedInfo.frequency : p2pStateMachine.GetAvailableFreqByBand(config.GetGoBand());
WIFI_LOGI("Create rpt group.");
WifiConfigCenter::GetInstance().SetExplicitGroup(true);
if (p2pStateMachine.DealCreateRptGroupWithConfig(config, freq)) {
ret = WIFI_HAL_OPT_OK;
}
} else {
WIFI_LOGE("Invalid parameter.");
}
if (WifiErrorNo::WIFI_HAL_OPT_FAILED == ret) {
WIFI_LOGE("p2p configure to CreateGroup failed.");
p2pStateMachine.BroadcastActionResult(P2pActionCallback::CreateGroup, WIFI_OPT_FAILED);
p2pStateMachine.SwitchState(&p2pStateMachine.p2pIdleState);
} else {
const int cgTimedOut = 5000;
WIFI_LOGI("p2p configure to CreateGroup successful.");
p2pStateMachine.MessageExecutedLater(
static_cast<int>(P2P_STATE_MACHINE_CMD::CREATE_GROUP_TIMED_OUT), cgTimedOut);
p2pStateMachine.BroadcastActionResult(P2pActionCallback::CreateGroup, WIFI_OPT_SUCCESS);
}
return EXECUTED;
}
bool P2pGroupOperatingState::ProcessCmdCreateGroup(const InternalMessagePtr msg) const
{
WifiErrorNo ret = WIFI_HAL_OPT_FAILED;

View File

@ -79,6 +79,13 @@ private:
*/
virtual bool ProcessCmdCreateGroup(const InternalMessagePtr msg) const;
/**
* @Description Process the create group of rpt command received by the state machine
* @param msg - Message body sent by the state machine
* @return - bool true:handle false:not handle
*/
virtual bool ProcessCmdCreateRptGroup(const InternalMessagePtr msg) const;
/**
* @Description Process the group started message received by the state machine
* @param msg - Message body sent by the state machine

View File

@ -69,6 +69,8 @@ void P2pIdleState::Init()
[this](InternalMessagePtr msg) { return this->ProcessProvDiscShowPinEvt(msg); }));
mProcessFunMap.insert(std::make_pair(P2P_STATE_MACHINE_CMD::CMD_FORM_GROUP,
[this](InternalMessagePtr msg) { return this->ProcessCmdCreateGroup(msg); }));
mProcessFunMap.insert(std::make_pair(P2P_STATE_MACHINE_CMD::CMD_FORM_RPT_GROUP,
[this](InternalMessagePtr msg) { return this->ProcessCmdCreateGroup(msg); }));
mProcessFunMap.insert(std::make_pair(P2P_STATE_MACHINE_CMD::CMD_REMOVE_GROUP,
[this](InternalMessagePtr msg) { return this->ProcessCmdRemoveGroup(msg); }));
mProcessFunMap.insert(std::make_pair(P2P_STATE_MACHINE_CMD::CMD_DELETE_GROUP,

View File

@ -132,6 +132,16 @@ ErrCode P2pInterface::DeleteGroup(const WifiP2pGroupInfo &group)
return p2pService.DeleteGroup(group);
}
ErrCode P2pInterface::CreateRptGroup(const WifiP2pConfig &config)
{
return p2pService.CreateRptGroup(config);
}
ErrCode P2pInterface::GetRptStationsList(std::vector<StationInfo> &result)
{
return p2pService.GetRptStationsList(result);
}
ErrCode P2pInterface::P2pConnect(const WifiP2pConfig &config)
{
return p2pService.P2pConnect(config);

View File

@ -338,6 +338,20 @@ public:
* @return ErrCode - operate result
*/
virtual ErrCode SetGcIpAddress(const IpAddrInfo& ipInfo) override;
/**
* @Description create p2p group of rpt
*
* @return ErrCode - operate result
*/
virtual ErrCode CreateRptGroup(const WifiP2pConfig &config) override;
/**
* @Description get station list of rpt
*
* @return ErrCode - operate result
*/
virtual ErrCode GetRptStationsList(std::vector<StationInfo> &result) override;
private:
WifiP2pGroupManager groupManager; /* group manager */
WifiP2pDeviceManager deviceMgr; /* device manager */

View File

@ -431,6 +431,16 @@ void P2pStateMachine::BroadcastP2pStatusChanged(P2pState state) const
}
}
void P2pStateMachine::BroadcastP2pPeerJoinOrLeave(bool isJoin, const std::string &mac) const
{
std::unique_lock<std::mutex> lock(cbMapMutex);
for (const auto &callBackItem : p2pServiceCallbacks) {
if (callBackItem.second.OnP2pPeerJoinOrLeaveEvent != nullptr) {
callBackItem.second.OnP2pPeerJoinOrLeaveEvent(isJoin, mac);
}
}
}
void P2pStateMachine::BroadcastP2pPeersChanged() const
{
std::vector<WifiP2pDevice> peers;
@ -1085,11 +1095,7 @@ bool P2pStateMachine::SetGroupConfig(const WifiP2pConfigInternal &config, bool n
group.SetNetworkId(config.GetNetId());
groupManager.AddOrUpdateGroup(group);
ret = WifiP2PHalInterface::GetInstance().P2pSetGroupConfig(config.GetNetId(), wpaConfig);
if (ret == WifiErrorNo::WIFI_HAL_OPT_FAILED) {
return false;
} else {
return true;
}
return ret != WIFI_HAL_OPT_FAILED;
}
bool P2pStateMachine::DealCreateNewGroupWithConfig(const WifiP2pConfigInternal &config, int freq) const
@ -1125,7 +1131,32 @@ bool P2pStateMachine::DealCreateNewGroupWithConfig(const WifiP2pConfigInternal &
UpdateGroupManager();
UpdatePersistentGroups();
return (ret == WIFI_HAL_OPT_FAILED) ? false : true;
return ret != WIFI_HAL_OPT_FAILED;
}
bool P2pStateMachine::DealCreateRptGroupWithConfig(const WifiP2pConfigInternal &config, int freq) const
{
int createdNetId = -1;
WifiErrorNo ret = WifiP2PHalInterface::GetInstance().P2pAddNetwork(createdNetId);
if (ret == WIFI_HAL_OPT_OK) {
WifiP2PHalInterface::GetInstance().P2pSetSingleConfig(createdNetId, "rptid", std::to_string(createdNetId));
WifiP2pConfigInternal cfgBuf = config;
cfgBuf.SetNetId(createdNetId);
if (!SetGroupConfig(cfgBuf, true)) {
WIFI_LOGW("Some configuration settings failed!");
}
ret = WifiP2PHalInterface::GetInstance().GroupAdd(true, createdNetId, freq);
}
if (ret == WIFI_HAL_OPT_FAILED) {
WifiP2PHalInterface::GetInstance().RemoveNetwork(createdNetId);
WifiP2pGroupInfo removedInfo;
removedInfo.SetNetworkId(createdNetId);
groupManager.RemoveGroup(removedInfo);
}
UpdateGroupManager();
UpdatePersistentGroups();
return ret != WIFI_HAL_OPT_FAILED;
}
bool P2pStateMachine::IsInterfaceReuse() const
@ -1255,5 +1286,16 @@ void P2pStateMachine::DoP2pArp(std::string serverIp, std::string clientIp)
arpChecker.Start(ifName, macAddress, clientIp, serverIp);
arpChecker.DoArpCheck(ARP_TIMEOUT, true);
}
bool P2pStateMachine::GetConnectedStationInfo(std::map<std::string, StationInfo> &result)
{
#ifdef WIFI_DHCP_DISABLED
return true;
#endif
WIFI_LOGE("rpt GetConnectedStationInfo");
std::string ifaceName = groupManager.GetCurrentGroup().GetInterface();
return m_DhcpdInterface.GetConnectedStationInfo(ifaceName, result);
}
} // namespace Wifi
} // namespace OHOS

View File

@ -128,6 +128,12 @@ public:
*/
void SetIsNeedDhcp(DHCPTYPE dhcpType);
/**
* @Description - get connected stations
* @param result - result
*/
bool GetConnectedStationInfo(std::map<std::string, StationInfo> &result);
private:
/**
* @Description Handle event of CMD_DEVICE_DISCOVERS
@ -267,6 +273,15 @@ private:
* @return false - creation failed
*/
virtual bool DealCreateNewGroupWithConfig(const WifiP2pConfigInternal &config, int freq) const;
/**
* @Description Processing function of using configuration to create a group.
*
* @param config - p2p group's configuration
* @param freq - the frequency when starting a group
* @return true - created successfully
* @return false - creation failed
*/
virtual bool DealCreateRptGroupWithConfig(const WifiP2pConfigInternal &config, int freq) const;
/**
* @Description Update persistent group's info to wpa.
*
@ -299,6 +314,12 @@ private:
* @param state - current state
*/
virtual void BroadcastP2pStatusChanged(P2pState state) const;
/**
* @Description - Broadcast peer change event.
* @param isJoin - is join or leave
* @param mac - mac address
*/
virtual void BroadcastP2pPeerJoinOrLeave(bool isJoin, const std::string &mac) const;
/**
* @Description - Peers update detected by broadcast.
*/

View File

@ -24,6 +24,7 @@
#include "wifi_config_center.h"
#include "wifi_country_code_manager.h"
#include "wifi_p2p_hal_interface.h"
#include "ap_define.h"
DEFINE_WIFILOG_P2P_LABEL("WifiP2pService");
@ -125,6 +126,56 @@ ErrCode WifiP2pService::StopP2pListen()
return ErrCode::WIFI_OPT_SUCCESS;
}
ErrCode WifiP2pService::CreateRptGroup(const WifiP2pConfig &config)
{
WifiConfigCenter::GetInstance().SaveP2pCreatorUid(IPCSkeleton::GetCallingUid());
WIFI_LOGI("CreateGroup name: %{private}s, address:%{private}s, addressType:%{public}d",
config.GetGroupName().c_str(), config.GetDeviceAddress().c_str(), config.GetDeviceAddressType());
WifiP2pConfigInternal configInternal(config);
WpsInfo wps;
wps.SetWpsMethod(WpsMethod::WPS_METHOD_PBC);
configInternal.SetWpsInfo(wps);
const std::any info = configInternal;
p2pStateMachine.SendMessage(static_cast<int>(P2P_STATE_MACHINE_CMD::CMD_FORM_RPT_GROUP), info);
return ErrCode::WIFI_OPT_SUCCESS;
}
ErrCode WifiP2pService::GetRptStationsList(std::vector<StationInfo> &result)
{
auto devices = groupManager.GetCurrentGroup().GetClientDevices();
if (devices.empty()) {
WIFI_LOGI("GetRptStationsList is empty");
return ErrCode::WIFI_OPT_SUCCESS;
}
WIFI_LOGI("GetRptStationsList size:%{public}d", static_cast<int>(devices.size()));
for (const auto &dev : devices) {
StationInfo info;
info.bssid = dev.GetRandomDeviceAddress();
info.bssidType = dev.GetDeviceAddressType();
info.deviceName = dev.GetDeviceName();
info.ipAddr = GETTING_INFO;
result.push_back(info);
}
// get dhcp lease info, return full connected station info
std::map<std::string, StationInfo> tmp;
if (!p2pStateMachine.GetConnectedStationInfo(tmp)) {
WIFI_LOGW("Get connected station info failed!");
return ErrCode::WIFI_OPT_FAILED;
}
for (auto iter = result.begin(); iter != result.end(); ++iter) {
auto itMap = tmp.find(iter->bssid);
if (itMap == tmp.end()) {
continue;
}
iter->deviceName = itMap->second.deviceName;
iter->ipAddr = itMap->second.ipAddr;
}
return ErrCode::WIFI_OPT_SUCCESS;
}
ErrCode WifiP2pService::CreateGroup(const WifiP2pConfig &config)
{
int callingUid = IPCSkeleton::GetCallingUid();

View File

@ -309,6 +309,21 @@ public:
* @return ErrCode - operate result
*/
virtual ErrCode SetGcIpAddress(const IpAddrInfo& ipInfo) override;
/**
* @Description create rpt group
*
* @return ErrCode - operate result
*/
virtual ErrCode CreateRptGroup(const WifiP2pConfig &config) override;
/**
* @Description get rpt station list
*
* @return ErrCode - operate result
*/
virtual ErrCode GetRptStationsList(std::vector<StationInfo> &result) override;
private:
/**
* @Description - P2P state machine deregistration event callback.

View File

@ -86,7 +86,7 @@ void WifiHotspotManager::CloseApService(int id)
WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_AP, id);
WifiConfigCenter::GetInstance().SetApMidState(WifiOprMidState::CLOSED, id);
WifiConfigCenter::GetInstance().SetHotspotState(static_cast<int>(ApState::AP_STATE_CLOSED), id);
auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine();
auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine();
ins->SendMessage(CMD_AP_STOPPED, id);
WifiEventCallbackMsg cbMsg;
cbMsg.msgCode = WIFI_CBK_MSG_HOTSPOT_STATE_CHANGE;
@ -132,7 +132,7 @@ void WifiHotspotManager::DealApStateChanged(ApState state, int id)
}
if (state == ApState::AP_STATE_STARTED) {
WifiConfigCenter::GetInstance().SetApMidState(WifiOprMidState::OPENING, WifiOprMidState::RUNNING, id);
auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine();
auto &ins = WifiManager::GetInstance().GetWifiTogglerManager()->GetControllerMachine();
ins->SendMessage(CMD_AP_START, id);
}

View File

@ -191,6 +191,13 @@ void WifiP2pManager::CloseP2pService(void)
cbMsg.msgCode = WIFI_CBK_MSG_P2P_STATE_CHANGE;
cbMsg.msgData = static_cast<int>(P2pState::P2P_STATE_CLOSED);
WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
if (auto &togglerManager = WifiManager::GetInstance().GetWifiTogglerManager(); togglerManager != nullptr) {
if (auto &ctrlMachine = togglerManager->GetControllerMachine(); ctrlMachine != nullptr) {
ctrlMachine->SendMessage(CMD_P2P_STOPPED, 0);
}
}
#ifdef HDI_CHIP_INTERFACE_SUPPORT
if (!ifaceName.empty()) {
DelayedSingleton<HalDeviceManager>::GetInstance()->RemoveP2pIface(ifaceName);
@ -221,6 +228,9 @@ void WifiP2pManager::InitP2pCallback(void)
mP2pCallback.OnP2pPeersChangedEvent = [this](const std::vector<WifiP2pDevice> &vPeers) {
this->DealP2pPeersChanged(vPeers);
};
mP2pCallback.OnP2pPeerJoinOrLeaveEvent = [this] (bool isJoin, const std::string &mac) {
this->DealP2pPeerJoinOrLeave(isJoin, mac);
};
mP2pCallback.OnP2pServicesChangedEvent = [this](const std::vector<WifiP2pServiceInfo> &vServices) {
this->DealP2pServiceChanged(vServices);
};
@ -275,6 +285,14 @@ void WifiP2pManager::DealP2pStateChanged(P2pState state)
return;
}
void WifiP2pManager::DealP2pPeerJoinOrLeave(bool isJoin, const std::string &mac)
{
auto rptManager = WifiManager::GetInstance().GetRptInterface();
if (rptManager != nullptr) {
isJoin ? rptManager->OnStationJoin(mac) : rptManager->OnStationLeave(mac);
}
}
void WifiP2pManager::DealP2pPeersChanged(const std::vector<WifiP2pDevice> &vPeers)
{
WifiEventCallbackMsg cbMsg;
@ -325,6 +343,11 @@ void WifiP2pManager::DealP2pConnectionChanged(const WifiP2pLinkedInfo &info)
if (info.GetConnectState() == P2pConnectedState::P2P_CONNECTED) {
WriteP2pKpiCountHiSysEvent(static_cast<int>(P2P_CHR_EVENT::CONN_SUC_CNT));
}
auto rptManager = WifiManager::GetInstance().GetRptInterface();
if (rptManager != nullptr) {
rptManager->OnP2pConnectionChanged(info.GetConnectState());
}
return;
}
@ -364,6 +387,11 @@ void WifiP2pManager::DealP2pActionResult(P2pActionCallback action, ErrCode code)
cbMsg.p2pAction = action;
cbMsg.msgData = static_cast<int>(code);
WifiInternalEventDispatcher::GetInstance().AddBroadCastMsg(cbMsg);
auto rptManager = WifiManager::GetInstance().GetRptInterface();
if (rptManager != nullptr) {
rptManager->OnP2pActionResult(action, code);
}
return;
}

View File

@ -40,6 +40,7 @@ public:
private:
void InitP2pCallback(void);
void DealP2pStateChanged(P2pState bState);
void DealP2pPeerJoinOrLeave(bool isJoin, const std::string &mac);
void DealP2pPeersChanged(const std::vector<WifiP2pDevice> &vPeers);
void DealP2pServiceChanged(const std::vector<WifiP2pServiceInfo> &vServices);
void DealP2pConnectionChanged(const WifiP2pLinkedInfo &info);

View File

@ -50,6 +50,7 @@ WifiTogglerManager::WifiTogglerManager()
InitConcreteCallback();
InitSoftapCallback();
InitMultiStacallback();
InitRptCallback();
pWifiControllerMachine = std::make_unique<WifiControllerMachine>();
if (pWifiControllerMachine) {
pWifiControllerMachine->InitWifiControllerMachine();
@ -71,6 +72,11 @@ MultiStaModeCallback& WifiTogglerManager::GetMultiStaCallback()
return mMultiStaModeCb;
}
RptModeCallback& WifiTogglerManager::GetRptCallback()
{
return mRptModeCb;
}
ErrCode WifiTogglerManager::WifiToggled(int isOpen, int id)
{
pWifiControllerMachine->ClearWifiStartFailCount();
@ -145,6 +151,13 @@ void WifiTogglerManager::InitMultiStacallback()
mMultiStaModeCb.onStopped = std::bind(&WifiTogglerManager::DealMultiStaStop, this, _1);
}
void WifiTogglerManager::InitRptCallback()
{
using namespace std::placeholders;
mRptModeCb.onStartFailure = std::bind(&WifiTogglerManager::DealRptStartFailure, this, _1);
mRptModeCb.onStopped = std::bind(&WifiTogglerManager::DealRptStop, this, _1);
}
void WifiTogglerManager::DealConcreateStop(int id)
{
if (pWifiControllerMachine) {
@ -173,6 +186,20 @@ void WifiTogglerManager::DealSoftapStartFailure(int id)
}
}
void WifiTogglerManager::DealRptStop(int id)
{
if (pWifiControllerMachine) {
pWifiControllerMachine->SendMessage(CMD_RPT_STOPPED, id);
}
}
void WifiTogglerManager::DealRptStartFailure(int id)
{
if (pWifiControllerMachine) {
pWifiControllerMachine->SendMessage(CMD_RPT_START_FAILURE);
}
}
void WifiTogglerManager::DealClientRemoved(int id)
{
if (pWifiControllerMachine) {

View File

@ -33,6 +33,7 @@ public:
ConcreteModeCallback& GetConcreteCallback(void);
MultiStaModeCallback &GetMultiStaCallback();
SoftApModeCallback& GetSoftApCallback(void);
RptModeCallback& GetRptCallback(void);
ErrCode WifiToggled(int isOpen, int id = 0);
ErrCode SoftapToggled(int isOpen, int id = 0);
ErrCode ScanOnlyToggled(int isOpen);
@ -50,10 +51,13 @@ private:
void InitConcreteCallback(void);
void InitSoftapCallback(void);
void InitMultiStacallback();
void InitRptCallback(void);
void DealConcreateStop(int id = 0);
void DealConcreateStartFailure(int id = 0);
void DealSoftapStop(int id = 0);
void DealSoftapStartFailure(int id = 0);
void DealRptStop(int id = 0);
void DealRptStartFailure(int id = 0);
void DealClientRemoved(int id = 0);
void DealMultiStaStartFailure(int id);
void DealMultiStaStop(int id);
@ -64,6 +68,7 @@ private:
ConcreteModeCallback mConcreteModeCb;
SoftApModeCallback mSoftApModeCb;
MultiStaModeCallback mMultiStaModeCb;
RptModeCallback mRptModeCb;
std::unique_ptr<WifiControllerMachine> pWifiControllerMachine = nullptr;
};

View File

@ -713,6 +713,26 @@ HWTEST_F(WifiHalDeviceManagerTest, OnRssiReportCallbackTest_01, TestSize.Level1)
EXPECT_EQ(result, 0);
}
HWTEST_F(WifiHalDeviceManagerTest, MakeMacFilterStringTest_01, TestSize.Level1)
{
std::vector<std::string> blockList{};
std::string result = DelayedSingleton<HalDeviceManager>::GetInstance()->MakeMacFilterString(blockList);
EXPECT_EQ(result, "MAC_MODE=0,MAC_CNT=0");
}
HWTEST_F(WifiHalDeviceManagerTest, MakeMacFilterStringTest_02, TestSize.Level1)
{
std::vector<std::string> blockList{"AA:BB"};
std::string result = DelayedSingleton<HalDeviceManager>::GetInstance()->MakeMacFilterString(blockList);
EXPECT_EQ(result, "MAC_MODE=1,MAC_CNT=1,MAC=AABB");
}
HWTEST_F(WifiHalDeviceManagerTest, MakeMacFilterStringTest_03, TestSize.Level1)
{
std::vector<std::string> blockList{"AA:BB", "CCDD"};
std::string result = DelayedSingleton<HalDeviceManager>::GetInstance()->MakeMacFilterString(blockList);
EXPECT_EQ(result, "MAC_MODE=1,MAC_CNT=2,MAC=AABB,MAC=CCDD");
}
} // namespace Wifi
} // namespace OHOS
#endif

View File

@ -59,6 +59,8 @@ ohos_unittest("manager_unittest") {
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/rpt_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/rpt_manager_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp",
@ -250,6 +252,10 @@ ohos_unittest("manager_unittest") {
defines += [ "FEATURE_P2P_SUPPORT" ]
}
if (wifi_feature_with_rpt) {
defines += [ "FEATURE_RPT_SUPPORT" ]
}
if (defined(global_parts_info) &&
defined(global_parts_info.telephony_core_service)) {
external_deps += [ "core_service:tel_core_service_api" ]

View File

@ -51,7 +51,9 @@ public:
wifiManager.wifiScanManager = std::make_unique<WifiScanManager>();
wifiManager.wifiTogglerManager = std::make_unique<WifiTogglerManager>();
wifiManager.wifiHotspotManager = std::make_unique<WifiHotspotManager>();
#ifdef FEATURE_P2P_SUPPORT
wifiManager.wifiP2pManager = std::make_unique<WifiP2pManager>();
#endif
wifiManager.wifiEventSubscriberManager = std::make_unique<WifiEventSubscriberManager>();
wifiManager.wifiMultiVapManager = std::make_unique<WifiMultiVapManager>();
}
@ -61,7 +63,9 @@ public:
wifiManager.wifiScanManager = nullptr;
wifiManager.wifiTogglerManager = nullptr;
wifiManager.wifiHotspotManager = nullptr;
#ifdef FEATURE_P2P_SUPPORT
wifiManager.wifiP2pManager = nullptr;
#endif
wifiManager.wifiEventSubscriberManager = nullptr;
wifiManager.wifiMultiVapManager = nullptr;
}
@ -204,6 +208,7 @@ HWTEST_F(WifiManagerTest, DealApGetStaLeaveTest, TestSize.Level1)
wifiManager.wifiHotspotManager->DealApGetStaLeave(info);
}
#ifdef FEATURE_P2P_SUPPORT
HWTEST_F(WifiManagerTest, AutoStartP2pService_001, TestSize.Level1)
{
WIFI_LOGI("AutoStartP2pService_001 enter!");
@ -336,6 +341,7 @@ HWTEST_F(WifiManagerTest, IfaceDestoryCallbackTest, TestSize.Level1)
std::string destoryIfaceName = "test";
wifiManager.wifiP2pManager->IfaceDestoryCallback(destoryIfaceName, 1);
}
#endif
HWTEST_F(WifiManagerTest, GetSupportedFeaturesTest, TestSize.Level1)
{

View File

@ -421,6 +421,16 @@ ErrCode WifiMockP2pService::RegisterP2pServiceCallbacks(const IP2pServiceCallbac
return WIFI_OPT_SUCCESS;
}
ErrCode WifiMockP2pService::CreateRptGroup(const WifiP2pConfig &config)
{
return WIFI_OPT_SUCCESS;
}
ErrCode WifiMockP2pService::GetRptStationsList(std::vector<StationInfo> &result)
{
return WIFI_OPT_SUCCESS;
}
extern "C" IP2pService *Create(void)
{
return new (std::nothrow) WifiMockP2pService();

View File

@ -51,6 +51,8 @@ public:
ErrCode QueryP2pGroups(std::vector<WifiP2pGroupInfo> &groups);
ErrCode QueryP2pServices(std::vector<WifiP2pServiceInfo> &services);
ErrCode RegisterP2pServiceCallbacks(const IP2pServiceCallbacks &callbacks);
ErrCode CreateRptGroup(const WifiP2pConfig &config);
ErrCode GetRptStationsList(std::vector<StationInfo> &result);
public:
IP2pServiceCallbacks mCallback;

View File

@ -73,6 +73,7 @@ HWTEST_F(WifiServiceManagerTest, GetApServiceInstTest, TestSize.Level1)
EXPECT_TRUE(WifiServiceManager::GetInstance().GetApServiceInst() == nullptr);
}
#ifdef FEATURE_P2P_SUPPORT
HWTEST_F(WifiServiceManagerTest, GetP2pServiceInstTest, TestSize.Level1)
{
WIFI_LOGE("GetP2pServiceInstTest enter!");
@ -83,6 +84,7 @@ HWTEST_F(WifiServiceManagerTest, GetP2pServiceInstTest, TestSize.Level1)
WifiServiceManager::GetInstance().CheckAndEnforceService("P2pService", false);
EXPECT_TRUE(WifiServiceManager::GetInstance().GetP2pServiceInst() == nullptr);
}
#endif
HWTEST_F(WifiServiceManagerTest, UnloadServiceTest, TestSize.Level1)
{

View File

@ -30,6 +30,8 @@ ohos_unittest("wifi_controller_unittest") {
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/concrete_manager_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/multi_sta_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/rpt_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/rpt_manager_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/softap_manager_state_machine.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller/wifi_controller_state_machine.cpp",
@ -150,6 +152,11 @@ ohos_unittest("wifi_controller_unittest") {
if (wifi_feature_wifi_pro_ctrl) {
defines += [ "FEATURE_WIFI_PRO_SUPPORT" ]
}
if (wifi_feature_with_rpt) {
defines += [ "FEATURE_RPT_SUPPORT" ]
}
part_name = "wifi"
subsystem_name = "communication"
}

View File

@ -0,0 +1,59 @@
/*
* 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 "mock_rpt_manager_state_machine.h"
#include "wifi_logger.h"
DEFINE_WIFILOG_LABEL("MockRptManagerStateMachine");
namespace OHOS {
namespace Wifi {
void MockRptManagerStateMachine::SendMessage(int msgName)
{
WIFI_LOGD("MockRptManagerStateMachine::SendMessage, msgName is %{public}d.", msgName);
}
void MockRptManagerStateMachine::SendMessage(int msgName, int param1)
{
WIFI_LOGD("SendMessage, msgName is %{public}d, param1 is %{public}d.", msgName, param1);
}
void MockRptManagerStateMachine::SendMessage(int msgName, int param1, int param2)
{
WIFI_LOGD("SendMessage, msgName is %{public}d, param1 is %{public}d, param2 is %{public}d.",
msgName, param1, param2);
}
void MockRptManagerStateMachine::SendMessage(InternalMessagePtr msg)
{
if (msg == nullptr) {
return;
}
WIFI_LOGD("MockRptManagerStateMachine::SendMessage, msg is %{public}d.", msg->GetMessageName());
}
void MockRptManagerStateMachine::SendMessage(int msgName, const std::any &messageObj)
{
(void)messageObj;
WIFI_LOGD("MockRptManagerStateMachine::SendMessage, msgName is %{public}d.", msgName);
}
void MockRptManagerStateMachine::SendMessage(int msgName, int param1, int param2, const std::any &messageObj)
{
(void)messageObj;
WIFI_LOGD("SendMessage, msgName is %{public}d, param1 is %{public}d, param2 is %{public}d.",
msgName, param1, param2);
}
} // namespace Wifi
} // namespace OHOS

View File

@ -0,0 +1,36 @@
/*
* 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 OHOS_MOCK_RPTSTATEMACHINE_H
#define OHOS_MOCK_RPTSTATEMACHINE_H
#include <gmock/gmock.h>
#include "rpt_manager_state_machine.h"
namespace OHOS {
namespace Wifi {
class MockRptManagerStateMachine : public RptManagerMachine {
public:
MockRptManagerStateMachine() {}
~MockRptManagerStateMachine() {}
void SendMessage(int msgName);
void SendMessage(int msgName, int param1);
void SendMessage(int msgName, int param1, int param2);
void SendMessage(InternalMessagePtr msg);
void SendMessage(int msgName, const std::any &messageObj);
void SendMessage(int msgName, int param1, int param2, const std::any &messageObj);
};
} // namespace OHOS
} // namespace Wifi
#endif

View File

@ -44,14 +44,14 @@ public:
mCb.onStopped = DealConcreteStop;
mCb.onRemoved = DealClientRemoved;
pConcreteModeManager->mcb = mCb;
pConcreteModeManager->GetConcreteMachine()->SendMessage(CONCRETE_CMD_START,
pConcreteModeManager->GetMachine()->SendMessage(CONCRETE_CMD_START,
static_cast<int>(ConcreteManagerRole::ROLE_CLIENT_STA), 0);
}
virtual void TearDown()
{
if (pConcreteModeManager != nullptr) {
pConcreteModeManager->GetConcreteMachine()->SendMessage(CONCRETE_CMD_STOP);
pConcreteModeManager->GetMachine()->SendMessage(CONCRETE_CMD_STOP);
pConcreteModeManager.reset();
}
}

View File

@ -43,14 +43,14 @@ public:
mCb.onStartFailure = DealSoftapStartFailure;
mCb.onStopped = DealSoftapStop;
pSoftApManager->mcb = mCb;
pSoftApManager->GetSoftapMachine()->SendMessage(SOFTAP_CMD_START,
pSoftApManager->GetMachine()->SendMessage(SOFTAP_CMD_START,
static_cast<int>(SoftApManager::Role::ROLE_UNKNOW), 0);
}
virtual void TearDown()
{
if (pSoftApManager != nullptr) {
pSoftApManager->GetSoftapMachine()->SendMessage(SOFTAP_CMD_STOP);
pSoftApManager->GetMachine()->SendMessage(SOFTAP_CMD_STOP);
pSoftApManager.reset();
}
}

View File

@ -145,7 +145,7 @@ public:
void RemoveConcreteManagerTest()
{
pWifiControllerMachine->RemoveConcreteManager(0);
pWifiControllerMachine->concreteManagers.RemoveManager(0);
}
void HandleStaCloseTest()
@ -175,7 +175,7 @@ public:
void RmoveSoftapManagerTest()
{
pWifiControllerMachine->RmoveSoftapManager(0);
pWifiControllerMachine->softApManagers.RemoveManager(0);
}
void HandleSoftapStopTest()
@ -198,17 +198,16 @@ public:
EXPECT_TRUE(pWifiControllerMachine->pEnableState->ExecuteStateMsg(msg));
WifiConfigCenter::GetInstance().SetApMidState(WifiOprMidState::CLOSING, 0);
EXPECT_TRUE(pWifiControllerMachine->pEnableState->ExecuteStateMsg(msg));
SoftApManager *softapmode = new (std::nothrow) SoftApManager(SoftApManager::Role::ROLE_SOFTAP, 0);
auto softapmode = std::make_shared<SoftApManager>(SoftApManager::Role::ROLE_SOFTAP, 0);
softapmode->pSoftapManagerMachine = new MockSoftapManagerStateMachine();
pWifiControllerMachine->softapManagers.push_back(softapmode);
pWifiControllerMachine->softApManagers.AddManager(softapmode);
WifiConfigCenter::GetInstance().SetApMidState(WifiOprMidState::RUNNING, 0);
EXPECT_TRUE(pWifiControllerMachine->pEnableState->ExecuteStateMsg(msg));
msg->SetParam1(1);
EXPECT_TRUE(pWifiControllerMachine->pEnableState->ExecuteStateMsg(msg));
ConcreteClientModeManager *clientmode =
new (std::nothrow) ConcreteClientModeManager(ConcreteManagerRole::ROLE_CLIENT_STA, 0);
auto clientmode = std::make_shared<ConcreteClientModeManager>(ConcreteManagerRole::ROLE_CLIENT_STA, 0);
clientmode->pConcreteMangerMachine = new MockConcreteMangerMachine();
pWifiControllerMachine->concreteManagers.push_back(clientmode);
pWifiControllerMachine->concreteManagers.AddManager(clientmode);
EXPECT_TRUE(pWifiControllerMachine->pEnableState->ExecuteStateMsg(msg));
}
@ -235,17 +234,16 @@ public:
EXPECT_TRUE(pWifiControllerMachine->pEnableState->ExecuteStateMsg(msg));
msg->SetMessageName(CMD_AP_START_FAILURE);
EXPECT_TRUE(pWifiControllerMachine->pEnableState->ExecuteStateMsg(msg));
SoftApManager *softapmode = new (std::nothrow) SoftApManager(SoftApManager::Role::ROLE_HAS_REMOVED, 0);
auto softapmode = std::make_shared<SoftApManager>(SoftApManager::Role::ROLE_HAS_REMOVED, 0);
softapmode->pSoftapManagerMachine = new MockSoftapManagerStateMachine();
pWifiControllerMachine->softapManagers.push_back(softapmode);
pWifiControllerMachine->softApManagers.AddManager(softapmode);
EXPECT_TRUE(pWifiControllerMachine->pEnableState->ExecuteStateMsg(msg));
SoftApManager *softapmodeBack = new (std::nothrow) SoftApManager(SoftApManager::Role::ROLE_HAS_REMOVED, 0);
auto softapmodeBack = std::make_shared<SoftApManager>(SoftApManager::Role::ROLE_HAS_REMOVED, 0);
softapmodeBack->pSoftapManagerMachine = new MockSoftapManagerStateMachine();
pWifiControllerMachine->softapManagers.push_back(softapmodeBack);
ConcreteClientModeManager *clientmode =
new (std::nothrow) ConcreteClientModeManager(ConcreteManagerRole::ROLE_CLIENT_STA, 0);
pWifiControllerMachine->softApManagers.AddManager(softapmodeBack);
auto clientmode = std::make_shared<ConcreteClientModeManager>(ConcreteManagerRole::ROLE_CLIENT_STA, 0);
clientmode->pConcreteMangerMachine = new MockConcreteMangerMachine();
pWifiControllerMachine->concreteManagers.push_back(clientmode);
pWifiControllerMachine->concreteManagers.AddManager(clientmode);
EXPECT_TRUE(pWifiControllerMachine->pEnableState->ExecuteStateMsg(msg));
}
@ -281,35 +279,34 @@ public:
void SoftApIdExistTest()
{
SoftApManager *softapmode = new (std::nothrow) SoftApManager(SoftApManager::Role::ROLE_SOFTAP, 0);
auto softapmode = std::make_shared<SoftApManager>(SoftApManager::Role::ROLE_SOFTAP, 0);
softapmode->pSoftapManagerMachine = new MockSoftapManagerStateMachine();
pWifiControllerMachine->softapManagers.push_back(softapmode);
EXPECT_TRUE(pWifiControllerMachine->SoftApIdExist(0));
EXPECT_FALSE(pWifiControllerMachine->SoftApIdExist(1));
EXPECT_TRUE(pWifiControllerMachine->HasAnySoftApManager());
pWifiControllerMachine->StopSoftapManager(0);
pWifiControllerMachine->StopSoftapManager(1);
pWifiControllerMachine->StopAllSoftapManagers();
pWifiControllerMachine->GetSoftApManager(0);
pWifiControllerMachine->GetSoftApManager(1);
pWifiControllerMachine->RmoveSoftapManager(1);
pWifiControllerMachine->RmoveSoftapManager(0);
pWifiControllerMachine->softApManagers.AddManager(softapmode);
EXPECT_TRUE(pWifiControllerMachine->softApManagers.IdExist(0));
EXPECT_FALSE(pWifiControllerMachine->softApManagers.IdExist(1));
EXPECT_TRUE(pWifiControllerMachine->softApManagers.HasAnyManager());
pWifiControllerMachine->softApManagers.StopManager(0);
pWifiControllerMachine->softApManagers.StopManager(1);
pWifiControllerMachine->softApManagers.StopAllManagers();
pWifiControllerMachine->softApManagers.GetManager(0);
pWifiControllerMachine->softApManagers.GetManager(1);
pWifiControllerMachine->softApManagers.RemoveManager(1);
pWifiControllerMachine->softApManagers.RemoveManager(0);
}
void ConcreteIdExistTest()
{
int instId = 0;
ConcreteClientModeManager *clientmode =
new (std::nothrow) ConcreteClientModeManager(ConcreteManagerRole::ROLE_CLIENT_STA, 0);
auto clientmode = std::make_shared<ConcreteClientModeManager>(ConcreteManagerRole::ROLE_CLIENT_STA, 0);
clientmode->pConcreteMangerMachine = new MockConcreteMangerMachine();
pWifiControllerMachine->concreteManagers.push_back(clientmode);
EXPECT_TRUE(pWifiControllerMachine->ConcreteIdExist(0));
EXPECT_FALSE(pWifiControllerMachine->ConcreteIdExist(1));
EXPECT_TRUE(pWifiControllerMachine->HasAnyConcreteManager());
pWifiControllerMachine->concreteManagers.AddManager(clientmode);
EXPECT_TRUE(pWifiControllerMachine->concreteManagers.IdExist(0));
EXPECT_FALSE(pWifiControllerMachine->concreteManagers.IdExist(1));
EXPECT_TRUE(pWifiControllerMachine->concreteManagers.HasAnyManager());
EXPECT_TRUE(pWifiControllerMachine->HasAnyManager());
pWifiControllerMachine->StopAllConcreteManagers();
pWifiControllerMachine->StopConcreteManager(0);
pWifiControllerMachine->StopConcreteManager(1);
pWifiControllerMachine->concreteManagers.StopAllManagers();
pWifiControllerMachine->concreteManagers.StopManager(0);
pWifiControllerMachine->concreteManagers.StopManager(1);
pWifiControllerMachine->HandleStaStart(0);
pWifiControllerMachine->HandleStaSemiActive(0);
pWifiControllerMachine->HandleStaClose(0);
@ -323,8 +320,8 @@ public:
WifiConfigCenter::GetInstance().SetWifiToggledState(WIFI_STATE_SEMI_ENABLED, instId);
WifiConfigCenter::GetInstance().SetWifiDetailState(WifiDetailState::STATE_ACTIVATED, 0);
EXPECT_TRUE(pWifiControllerMachine->ShouldDisableWifi(msg));
pWifiControllerMachine->RemoveConcreteManager(1);
pWifiControllerMachine->RemoveConcreteManager(0);
pWifiControllerMachine->concreteManagers.RemoveManager(1);
pWifiControllerMachine->concreteManagers.RemoveManager(0);
pWifiControllerMachine->ShutdownWifi();
}

View File

@ -222,5 +222,16 @@ ErrCode P2pInterface::DisableRandomMac(int setmode)
{
return WIFI_OPT_SUCCESS;
}
ErrCode P2pInterface::CreateRptGroup(const WifiP2pConfig &config)
{
return WIFI_OPT_SUCCESS;
}
ErrCode P2pInterface::GetRptStationsList(std::vector<StationInfo> &result)
{
return WIFI_OPT_SUCCESS;
}
} // namespace Wifi
} // namespace OHOS

View File

@ -65,6 +65,8 @@ public:
virtual ErrCode MonitorCfgChange(void) override;
virtual ErrCode DiscoverPeers(int32_t channelid) override;
virtual ErrCode DisableRandomMac(int setmode) override;
virtual ErrCode CreateRptGroup(const WifiP2pConfig &config) override;
virtual ErrCode GetRptStationsList(std::vector<StationInfo> &result) override;
};
} // namespace Wifi
} // namespace OHOS

View File

@ -76,6 +76,11 @@ public:
virtual WifiErrorNo GetP2pPeer(const std::string &deviceAddress, WifiP2pDevice &device) const = 0;
virtual WifiErrorNo P2pGetSupportFrequenciesByBand(int band, std::vector<int> &frequencies) const = 0;
virtual WifiErrorNo P2pSetGroupConfig(int networkId, const HalP2pGroupConfig &config) const = 0;
virtual WifiErrorNo P2pSetSingleConfig(int networkId, const std::string &key, const std::string &value) const = 0;
virtual WifiErrorNo SetRptBlockList(const std::string &ifaceName, const std::string &interfaceName,
const std::vector<std::string> &blockList) = 0;
virtual WifiErrorNo DisAssociateSta(const std::string &ifaceName, const std::string &interfaceName,
const std::string &mac) = 0;
virtual WifiErrorNo P2pGetGroupConfig(int networkId, HalP2pGroupConfig &config) const = 0;
virtual WifiErrorNo P2pAddNetwork(int &networkId) const = 0;
virtual WifiErrorNo SetPersistentReconnect(int mode) const = 0;
@ -141,6 +146,12 @@ public:
MOCK_METHOD1(SetP2pSecondaryDeviceType, WifiErrorNo(const std::string &type));
MOCK_CONST_METHOD1(Hid2dConnect, WifiErrorNo(const Hid2dConnectConfig &config));
MOCK_CONST_METHOD0(GetP2pCallbackInst, const P2pHalCallback &());
MOCK_CONST_METHOD3(P2pSetSingleConfig, WifiErrorNo(int networkId,
const std::string &key, const std::string &value));
MOCK_METHOD3(SetRptBlockList, WifiErrorNo(const std::string &ifaceName, const std::string &interfaceName,
const std::vector<std::string> &blockList));
MOCK_METHOD3(DisAssociateSta, WifiErrorNo(const std::string &ifaceName, const std::string &interfaceName,
const std::string &mac));
};
} // namespace Wifi
} // namespace OHOS

View File

@ -53,10 +53,12 @@ std::unique_ptr<WifiScanManager>& WifiManager::GetWifiScanManager()
return wifiScanManager;
}
#ifdef FEATURE_P2P_SUPPORT
std::unique_ptr<WifiP2pManager>& WifiManager::GetWifiP2pManager()
{
return wifiP2pManager;
}
#endif
std::unique_ptr<WifiTogglerManager>& WifiManager::GetWifiTogglerManager()
{
@ -67,7 +69,12 @@ std::unique_ptr<WifiHotspotManager>& WifiManager::GetWifiHotspotManager()
{
return wifiHotspotManager;
}
std::shared_ptr<RptInterface> WifiManager::GetRptInterface(int id)
{
return nullptr;
}
std::unique_ptr<WifiEventSubscriberManager>& WifiManager::GetWifiEventSubscriberManager()
{
return wifiEventSubscriberManager;
@ -85,7 +92,9 @@ int WifiManager::Init()
wifiMultiVapManager = std::make_unique<WifiMultiVapManager>();
wifiStaManager = std::make_unique<WifiStaManager>();
wifiScanManager = std::make_unique<WifiScanManager>();
#ifdef FEATURE_P2P_SUPPORT
wifiP2pManager = std::make_unique<WifiP2pManager>();
#endif
wifiTogglerManager = std::make_unique<WifiTogglerManager>();
wifiHotspotManager = std::make_unique<WifiHotspotManager>();
return 0;
@ -105,9 +114,11 @@ void WifiManager::Exit()
if (wifiScanManager) {
wifiScanManager.reset();
}
#ifdef FEATURE_P2P_SUPPORT
if (wifiP2pManager) {
wifiP2pManager.reset();
}
#endif
if (wifiTogglerManager) {
wifiTogglerManager.reset();
}

View File

@ -24,7 +24,12 @@
#include "wifi_event_subscriber_manager.h"
#include "wifi_app_state_aware.h"
#include "wifi_multi_vap_manager.h"
#ifdef FEATURE_P2P_SUPPORT
#include "wifi_p2p_manager.h"
#endif
#include "rpt_interface.h"
#define ANY_ID (-1)
namespace OHOS {
namespace Wifi {
@ -69,9 +74,12 @@ public:
std::unique_ptr<WifiScanManager>& GetWifiScanManager();
std::unique_ptr<WifiTogglerManager>& GetWifiTogglerManager();
std::unique_ptr<WifiHotspotManager>& GetWifiHotspotManager();
std::shared_ptr<RptInterface> GetRptInterface(int id = ANY_ID);
std::unique_ptr<WifiEventSubscriberManager>& GetWifiEventSubscriberManager();
std::unique_ptr<WifiMultiVapManager>& GetWifiMultiVapManager();
#ifdef FEATURE_P2P_SUPPORT
std::unique_ptr<WifiP2pManager>& GetWifiP2pManager();
#endif
int Init();
void Exit();
private:
@ -85,7 +93,9 @@ private:
std::unique_ptr<WifiHotspotManager> wifiHotspotManager = nullptr;
std::unique_ptr<WifiEventSubscriberManager> wifiEventSubscriberManager = nullptr;
std::unique_ptr<WifiMultiVapManager> wifiMultiVapManager = nullptr;
#ifdef FEATURE_P2P_SUPPORT
std::unique_ptr<WifiP2pManager> wifiP2pManager = nullptr;
#endif
};
} // namespace Wifi
} // namespace OHOS

View File

@ -110,6 +110,7 @@ local_base_include_dirs = [
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_country_code",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/network_black_list",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/hid2d",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",

View File

@ -20,6 +20,7 @@ CONFIG_CTRL_IFACE = "unix"
declare_args() {
wifi_feature_with_p2p = true
wifi_feature_with_rpt = true
wifi_feature_with_ap_intf = "wlan"
wifi_feature_with_ap_num = 1
wifi_feature_with_sta_num = 2