Signed-off-by: fengye <fengye10@huawei.com>
This commit is contained in:
fengye 2022-09-20 10:48:23 +00:00
commit 7e42883a47
100 changed files with 1047 additions and 602 deletions

View File

@ -62,11 +62,15 @@
]
},
"build": {
"sub_component": [
"//foundation/communication/wifi/dhcp/services/mgr_service:dhcp_manager_service",
"//foundation/communication/wifi/dhcp/services/dhcp_client:dhcp_client_service",
"//foundation/communication/wifi/dhcp/services/dhcp_server:dhcp_server"
],
"group_type": {
"base_group": [
"//foundation/communication/wifi/dhcp/services/mgr_service:dhcp_manager_service",
"//foundation/communication/wifi/dhcp/services/dhcp_client:dhcp_client_service",
"//foundation/communication/wifi/dhcp/services/dhcp_server:dhcp_server"
],
"fwk_group": [],
"service_group": []
},
"inner_kits": [
],
"test": [

View File

@ -108,7 +108,7 @@ typedef enum EnumServiceStatus {
SERVICE_STATUS_INVALID = 0,
SERVICE_STATUS_START = 1,
SERVICE_STATUS_STOP = 2
} DhcpmServiceStatus;
} DhcpServiceStatus;
struct DhcpResult {
int iptype; /* 0-ipv4,1-ipv6 */

View File

@ -45,9 +45,9 @@
#define LOG_DEBUG "Debug"
#define LOG_TRACE "Trace"
#define LOG_WARN " Warn"
#define LOG_WARN "Warn"
#define LOG_ERROR "Error"
#define LOG_INFO " Info"
#define LOG_INFO "Info"
#define DEBUG_MODE 1

View File

@ -18,6 +18,7 @@
#include "dhcp_config.h"
#include "dhcp_define.h"
#include "dhcp_message.h"
enum DhcpServerState { ST_IDEL = 0, ST_STARTING, ST_RUNNING, ST_RELOADNG, ST_STOPING, ST_STOPED };
typedef int (*DhcpServerCallback)(int, int, const char *ifname);
@ -37,8 +38,9 @@ int StartDhcpServer(PDhcpServerContext ctx);
int StopDhcpServer(PDhcpServerContext ctx);
int GetServerStatus(PDhcpServerContext ctx);
void RegisterDhcpCallback(PDhcpServerContext ctx, DhcpServerCallback callback);
int FreeServerContext(PDhcpServerContext ctx);
int FreeServerContext(PDhcpServerContext *ctx);
int SaveLease(PDhcpServerContext ctx);
int ReceiveDhcpMessage(int sock, PDhcpMsgInfo msgInfo);
#ifdef __cplusplus
}

View File

@ -38,7 +38,6 @@ static DhcpConfig g_dhcpConfig;
static PDhcpServerContext g_dhcpServer = 0;
enum SignalEvent {
EXIT = 0,
RELOAD,
@ -373,7 +372,10 @@ void FreeSeverResources(void)
{
FreeArguments();
FreeLocalConfig();
FreeServerContext(g_dhcpServer);
if (FreeServerContext(&g_dhcpServer) != RET_SUCCESS) {
LOGE("Free server context failed!");
return;
}
}
static void BeforeExit(void)

View File

@ -36,14 +36,15 @@
#include "dhcp_config.h"
#include "dhcp_ipv4.h"
#include "dhcp_logger.h"
#include "dhcp_message.h"
#include "dhcp_option.h"
#include "hash_table.h"
#undef LOG_TAG
#define LOG_TAG "DhcpServer"
#ifndef DHCP_SEL_WAIT_TIMEOUTS
#define DHCP_SEL_WAIT_TIMEOUTS 1000
#endif
#define OPT_MESSAGE_TYPE_LEGTH 1
#define OPT_HEADER_LENGTH 2
#define OPT_TIME_LENGTH 4
@ -254,8 +255,8 @@ int ReceiveDhcpMessage(int sock, PDhcpMsgInfo msgInfo)
fd_set recvFd;
FD_ZERO(&recvFd);
FD_SET(sock, &recvFd);
time_t tms = DHCP_SEL_WAIT_TIMEOUTS;
tmt.tv_sec = tms;
time_t seconds = DHCP_SEL_WAIT_TIMEOUTS;
tmt.tv_sec = seconds;
tmt.tv_usec = 0;
if (select(sock + 1, &recvFd, NULL, NULL, &tmt) < 0) {
LOGE("select error, %d", errno);
@ -270,7 +271,7 @@ int ReceiveDhcpMessage(int sock, PDhcpMsgInfo msgInfo)
srcAddrIn->sin_addr.s_addr = INADDR_ANY;
int rsize = recvfrom(sock, recvBuffer, RECV_BUFFER_SIZE, 0, (struct sockaddr *)srcAddrIn, (socklen_t *)&ssize);
if (!rsize) {
LOGE("receive error, %d", errno);
LOGE("receive error, %d", errno);
return RET_FAILED;
}
if (rsize > (int)sizeof(DhcpMessage) || rsize < DHCP_MSG_HEADER_SIZE) {
@ -280,7 +281,7 @@ int ReceiveDhcpMessage(int sock, PDhcpMsgInfo msgInfo)
msgInfo->length = rsize;
if (memcpy_s(&msgInfo->packet, sizeof(DhcpMessage), recvBuffer, rsize) != EOK) {
return RET_FAILED;
};
}
if (msgInfo->packet.op != BOOTREQUEST) {
LOGW("dhcp message type error!");
return RET_FAILED;
@ -536,7 +537,7 @@ static int BeginLooper(PDhcpServerContext ctx)
int saveRet = SaveBindingRecoders(&srvIns->addressPool, 0);
if (saveRet != RET_SUCCESS && saveRet != RET_WAIT_SAVE) {
LOGW("failed to save lease recoders.");
};
}
}
}
FreeOptionList(&from.options);
@ -1667,17 +1668,17 @@ PDhcpServerContext InitializeServer(DhcpConfig *config)
}
if ((context->instance = calloc(1, sizeof(ServerContext))) == NULL) {
LOGE("failed to calloc server instance.");
FreeServerContext(context);
FreeServerContext(&context);
return NULL;
}
if (InitServerContext(config, context) != RET_SUCCESS) {
LOGE("failed initialize dhcp server context.");
FreeServerContext(context);
FreeServerContext(&context);
return NULL;
}
if (InitServerFixedOptions(config, context) != RET_SUCCESS) {
LOGE("failed initialize dhcp server fixed options.");
FreeServerContext(context);
FreeServerContext(&context);
return NULL;
}
LOGD("server id: %s", ParseStrIp(config->serverId));
@ -1691,23 +1692,23 @@ PDhcpServerContext InitializeServer(DhcpConfig *config)
return context;
}
int FreeServerContext(PDhcpServerContext ctx)
int FreeServerContext(PDhcpServerContext *ctx)
{
if (!ctx) {
if (ctx == NULL || *ctx == NULL) {
LOGE("dhcp server context pointer is null.");
return RET_FAILED;
}
ServerContext *srvIns = GetServerInstance(ctx);
ServerContext *srvIns = GetServerInstance(*ctx);
if (!srvIns) {
LOGE("dhcp server instance pointer is null.");
return RET_FAILED;
}
FreeAddressPool(&srvIns->addressPool);
if (ctx->instance != NULL) {
free(ctx->instance);
ctx->instance = NULL;
free(ctx);
ctx = NULL;
if ((*ctx)->instance != NULL) {
free((*ctx)->instance);
(*ctx)->instance = NULL;
free(*ctx);
*ctx = NULL;
}
return RET_SUCCESS;
}

View File

@ -158,17 +158,6 @@ HWTEST_F(DhcpFunctionTest, InitPidfile_SUCCESS, TestSize.Level1)
usleep(SLEEP_TIME_200_MS);
}
HWTEST_F(DhcpFunctionTest, InitPidfile_FAILED, TestSize.Level1)
{
char workDir[DIR_MAX_LEN] = {0};
char pidFile[DIR_MAX_LEN] = {0};
EXPECT_EQ(DHCP_OPT_FAILED, InitPidfile(workDir, pidFile, getpid()));
EXPECT_EQ(DHCP_OPT_FAILED, InitPidfile("./", "./test/wlan0.pid", getpid()));
EXPECT_EQ(DHCP_OPT_FAILED, InitPidfile("./test/", "./wlan0.pid", getpid()));
}
HWTEST_F(DhcpFunctionTest, GetPID_SUCCESS, TestSize.Level1)
{
char workDir[DIR_MAX_LEN] = "./";

View File

@ -93,8 +93,8 @@ HWTEST_F(DhcpIpv4Test, TEST_SUCCESS, TestSize.Level1)
.WillRepeatedly(Return(1));
EXPECT_CALL(MockSystemFunc::GetInstance(), close(_)).WillRepeatedly(Return(0));
EXPECT_EQ(-1, DhcpDiscover(0, 1));
EXPECT_EQ(-1, DhcpRenew(0, 0, 0));
EXPECT_EQ(0, DhcpDiscover(0, 1));
EXPECT_EQ(0, DhcpRenew(0, 0, 0));
MockSystemFunc::SetMockFlag(false);
}

View File

@ -117,7 +117,7 @@ HWTEST_F(DhcpSocketTest, SendToDhcpPacket_SUCCESS, TestSize.Level1)
EXPECT_EQ(SendToDhcpPacket(NULL, 0, 0, ifindex, (uint8_t *)MAC_BCAST_ADDR), SOCKET_OPT_FAILED);
struct DhcpPacket packet;
packet.xid = 123456;
EXPECT_EQ(SendToDhcpPacket(&packet, 0, 0, ifindex, (uint8_t *)MAC_BCAST_ADDR), SOCKET_OPT_FAILED);
EXPECT_EQ(SendToDhcpPacket(&packet, 0, 0, ifindex, (uint8_t *)MAC_BCAST_ADDR), SOCKET_OPT_SUCCESS);
MockSystemFunc::SetMockFlag(false);
}

View File

@ -57,8 +57,6 @@ ohos_unittest("dhcp_server_unittest") {
"$DHCP_ROOT_DIR/services/dhcp_server/include",
]
defines = []
cflags = []
deps = [
@ -81,6 +79,8 @@ ohos_unittest("dhcp_server_unittest") {
configs = [ ":module_private_config" ]
defines = [ "DHCP_SEL_WAIT_TIMEOUTS=1" ]
if (dhcp_hilog_enable) {
external_deps += [ "hiviewdfx_hilog_native:libhilog" ]
defines += [ "DHCP_HILOG_ENABLE" ]

View File

@ -41,7 +41,7 @@ public:
FreeOptionList(&options);
}
public:
DhcpOptionList options;
DhcpOptionList options = {0};
};
HWTEST_F(DhcpOptionTest, InitOptionListTest, TestSize.Level1)

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -226,7 +226,6 @@ bool DhcpServerTest::ServerRun(void)
{
LOGD("begin test start dhcp server.");
int retval = true;
SystemFuncMock::GetInstance().SetMockFlag(true);
EXPECT_CALL(SystemFuncMock::GetInstance(), socket(_, _, _)).WillRepeatedly(Return(1));
EXPECT_CALL(SystemFuncMock::GetInstance(), setsockopt(_, _, _, _, _)).WillRepeatedly(Return(0));
EXPECT_CALL(SystemFuncMock::GetInstance(), select(_, _, _, _, _)).WillRepeatedly(Return(0));
@ -269,9 +268,8 @@ bool DhcpServerTest::ServerRun(void)
retval = false;
}
if (m_pServerCtx) {
FreeServerContext(m_pServerCtx);
FreeServerContext(&m_pServerCtx);
}
SystemFuncMock::GetInstance().SetMockFlag(false);
return retval;
}
@ -304,7 +302,6 @@ void DhcpServerTest::DelayStopServer()
const int SLEEP_TIME2 = 1;
LOGI("wait for dhcp server stopped...");
LOGI("wait %d seconds...\n", SERVER_RUNING_TIME);
SystemFuncMock::GetInstance().SetMockFlag(true);
EXPECT_CALL(SystemFuncMock::GetInstance(), close(_)).WillRepeatedly(Return(0));
std::this_thread::sleep_for(std::chrono::seconds(SLEEP_TIME));
if (m_pServerCtx && m_pServerCtx->instance) {
@ -326,7 +323,6 @@ void DhcpServerTest::DelayStopServer()
waitSesc++;
}
}
SystemFuncMock::GetInstance().SetMockFlag(false);
std::this_thread::sleep_for(std::chrono::seconds(SLEEP_TIME2));
}
@ -608,7 +604,7 @@ HWTEST_F(DhcpServerTest, InitializeServerTest, TestSize.Level1)
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(RET_SUCCESS, FreeServerConfig(&config));
EXPECT_EQ(RET_SUCCESS, FreeServerContext(ctx));
EXPECT_EQ(RET_SUCCESS, FreeServerContext(&ctx));
}
extern "C" int InitServer(const char *ifname);
@ -644,37 +640,39 @@ HWTEST_F(DhcpServerTest, StartServerTest, TestSize.Level1)
{
SystemFuncMock::GetInstance().SetMockFlag(true);
EXPECT_TRUE(StartServerTest());
SystemFuncMock::GetInstance().SetMockFlag(false);
}
extern "C" int ReceiveDhcpMessage(int sock, PDhcpMsgInfo msgInfo);
HWTEST_F(DhcpServerTest, ReceiveDhcpMessageFailedTest, TestSize.Level1)
{
SystemFuncMock::GetInstance().SetMockFlag(true);
SystemFuncMock::GetInstance().SetMockFlag(true);
EXPECT_CALL(SystemFuncMock::GetInstance(), select(_, _, _, _, _))
.WillOnce(Return(-1))
.WillRepeatedly(Return(0));
EXPECT_CALL(SystemFuncMock::GetInstance(), recvfrom(_, _, _, _, _, _))
.WillOnce(Return((int)(sizeof(DhcpMsgInfo) + 1)))
.WillRepeatedly(Return((int)sizeof(DhcpMsgInfo)));
ON_CALL(SystemFuncMock::GetInstance(), select(_, _, _, _, _))
.WillByDefault(Return(0));
ON_CALL(SystemFuncMock::GetInstance(), recvfrom(_, _, _, _, _, _))
.WillByDefault(Return((int)sizeof(DhcpMsgInfo)));
DhcpMsgInfo msgInfo = {{0}, 0, {0}};
uint8_t testMac1[DHCP_HWADDR_LENGTH] = {0x00, 0x0e, 0x3c, 0x65, 0x3a, 0x09, 0};
EXPECT_EQ(ERR_SELECT, ReceiveDhcpMessage(1, &msgInfo)); // failed to select isset.
EXPECT_EQ(RET_FAILED, ReceiveDhcpMessage(1, &msgInfo)); // message length error
EXPECT_EQ(RET_FAILED, ReceiveDhcpMessage(1, &msgInfo)); // dhcp message type error
int ret = ReceiveDhcpMessage(1, &msgInfo); // failed to select isset.
EXPECT_TRUE(ret == RET_FAILED || ret == RET_ERROR);
ret = ReceiveDhcpMessage(1, &msgInfo); // message length error
EXPECT_TRUE(ret == RET_FAILED || ret == RET_ERROR);
ret = ReceiveDhcpMessage(1, &msgInfo); // dhcp message type error
EXPECT_TRUE(ret == RET_FAILED || ret == RET_ERROR);
msgInfo.packet.hlen = 128;
EXPECT_EQ(RET_FAILED, ReceiveDhcpMessage(1, &msgInfo)); // hlen error
ret = ReceiveDhcpMessage(1, &msgInfo); // hlen error
EXPECT_TRUE(ret == RET_FAILED || ret == RET_ERROR);
msgInfo.packet.hlen = 16;
msgInfo.packet.op = BOOTREPLY;
EXPECT_EQ(RET_FAILED, ReceiveDhcpMessage(1, &msgInfo)); // client op type error!
ret = ReceiveDhcpMessage(1, &msgInfo); // client op type error
EXPECT_TRUE(ret == RET_FAILED || ret == RET_ERROR);
msgInfo.packet.op = BOOTREQUEST;
EXPECT_EQ(RET_FAILED, ReceiveDhcpMessage(1, &msgInfo)); // client hardware address error!
ret = ReceiveDhcpMessage(1, &msgInfo); // client hardware address error
EXPECT_TRUE(ret == RET_FAILED || ret == RET_ERROR);
for (int i = 0; i < MAC_ADDR_LENGTH; ++i) {
msgInfo.packet.chaddr[i] = testMac1[i];
}
EXPECT_EQ(RET_FAILED, ReceiveDhcpMessage(1, &msgInfo));
ret = ReceiveDhcpMessage(1, &msgInfo);
EXPECT_TRUE(ret == RET_FAILED || ret == RET_ERROR);
}
extern "C" int FillReply(PDhcpServerContext ctx, PDhcpMsgInfo received, PDhcpMsgInfo reply);
@ -759,12 +757,7 @@ HWTEST_F(DhcpServerTest, AppendReplyTimeOptionsFailedTest, TestSize.Level1)
HWTEST_F(DhcpServerTest, FreeServerContextFailedTest, TestSize.Level1)
{
DhcpServerContext tempCtx;
tempCtx.instance = nullptr;
ASSERT_TRUE(memset_s(&tempCtx, sizeof(DhcpServerContext), 0, sizeof(DhcpServerContext)) == EOK);
ASSERT_TRUE(memset_s(tempCtx.ifname, sizeof(tempCtx.ifname), '\0', sizeof(tempCtx.ifname)) == EOK);
EXPECT_EQ(RET_FAILED, FreeServerContext(nullptr));
EXPECT_EQ(RET_FAILED, FreeServerContext(&tempCtx));
}
extern "C" AddressBinding *GetBinding(DhcpAddressPool *pool, PDhcpMsgInfo received);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -27,13 +27,11 @@
#include <sys/time.h>
#include <sys/types.h>
using namespace OHOS::Wifi;
#define MAGIC_COOKIE_LENGTH 4
#define OPT_HEADER_LENGTH 2
#define TIME_SEC_TO_USEC (1000 * 1000)
#define DHCP_SEL_WAIT_TIMEOUTS 1500
#undef LOG_TAG
#define LOG_TAG "DhcpServerSystemFuncMock"
@ -79,6 +77,8 @@ int __wrap_socket(int __domain, int __type, int __protocol)
if (g_mockTag) {
LOGD(" ==>mock enable.");
return SystemFuncMock::GetInstance().socket(__domain, __type, __protocol);
} else {
LOGD(" ==>mock disable.");
}
return __real_socket(__domain, __type, __protocol);
}
@ -90,9 +90,12 @@ int __wrap_setsockopt(int __fd, int __level, int __optname, const void *__optval
if (g_mockTag) {
LOGD(" ==>mock enable.");
return SystemFuncMock::GetInstance().setsockopt(__fd, __level, __optname, __optval, __optlen);
} else {
LOGD(" ==>mock disable.");
}
return __real_setsockopt(__fd, __level, __optname, __optval, __optlen);
}
int __real_select(int __nfds, fd_set *__readfds, fd_set *__writefds, fd_set *__exceptfds, struct timeval *__timeout);
int __wrap_select(int __nfds, fd_set *__readfds, fd_set *__writefds, fd_set *__exceptfds, struct timeval *__timeout)
{
@ -114,6 +117,8 @@ int __wrap_select(int __nfds, fd_set *__readfds, fd_set *__writefds, fd_set *__e
}
}
return retval;
} else {
LOGD(" ==>mock disable.");
}
return __real_select(__nfds, __readfds, __writefds, __exceptfds, __timeout);
}
@ -125,6 +130,8 @@ int __wrap_bind(int __fd, struct sockaddr *__addr, socklen_t __len)
if (g_mockTag) {
LOGD(" ==>mock enable.");
return SystemFuncMock::GetInstance().bind(__fd, __addr, __len);
} else {
LOGD(" ==>mock disable.");
}
return __real_bind(__fd, __addr, __len);
}
@ -136,6 +143,8 @@ int __wrap_close(int _fileno)
if (g_mockTag) {
LOGD(" ==>mock enable.");
return SystemFuncMock::GetInstance().close(_fileno);
} else {
LOGD(" ==>mock disable.");
}
return __real_close(_fileno);
}
@ -160,6 +169,8 @@ ssize_t recvfrom(int __fd, void *__buf, size_t __n, int __flags, struct sockaddr
return sizeof(DhcpMessage);
}
}
} else {
LOGD(" ==>mock disable.");
}
return SystemFuncMock::GetInstance().recvfrom(__fd, __buf, __n, __flags, __addr, __addr_len);
}
@ -188,6 +199,7 @@ int ParseMockOptions(DhcpMessage *packet)
FreeOptionList(&reply.options);
return retval;
}
ssize_t sendto(int __fd, const void *__buf, size_t __n, int __flags, struct sockaddr *__addr, socklen_t __addr_len)
{
LOGD("==>sendto.");
@ -196,6 +208,8 @@ ssize_t sendto(int __fd, const void *__buf, size_t __n, int __flags, struct sock
if (__buf == nullptr) {
return SystemFuncMock::GetInstance().sendto(__fd, __buf, __n, __flags, __addr, __addr_len);
}
} else {
LOGD(" ==>mock disable.");
}
return SystemFuncMock::GetInstance().sendto(__fd, __buf, __n, __flags, __addr, __addr_len);
}

View File

@ -226,8 +226,6 @@ HWTEST_F(DhcpFuncTest, InitPidfile_TEST, TestSize.Level1)
pidDir = "./";
pidFile = "./wlan.pid";
EXPECT_EQ(DHCP_OPT_FAILED, DhcpFunc::InitPidfile(pidDir, pidFile));
EXPECT_EQ(DHCP_OPT_SUCCESS, DhcpFunc::InitPidfile(pidDir, pidFile));
EXPECT_EQ(DHCP_OPT_SUCCESS, DhcpFunc::InitPidfile(pidDir, pidFile));
MockSystemFunc::SetMockFlag(false);
}

View File

@ -50,7 +50,8 @@
"wifi_feature_with_ap_num",
"wifi_feature_with_auth_disable",
"wifi_feature_with_dhcp_disable",
"wifi_feature_with_encryption"
"wifi_feature_with_encryption",
"wifi_feature_is_hdi_supported"
],
"adapted_system_type": [
"standard"
@ -74,13 +75,19 @@
]
},
"build": {
"sub_component": [
"//foundation/communication/wifi/wifi/frameworks:wifi_kits",
"//foundation/communication/wifi/wifi/services/wifi_standard/wifi_framework:wifi_manage",
"//foundation/communication/wifi/wifi/services/wifi_standard/wifi_framework:wifi_system_ability",
"//foundation/communication/wifi/wifi/services/wifi_standard/wifi_hal:wifi_hal",
"//foundation/communication/wifi/wifi/utils:wifi_utils"
],
"group_type": {
"base_group": [
"//foundation/communication/wifi/wifi/utils:wifi_utils"
],
"fwk_group": [
"//foundation/communication/wifi/wifi/frameworks:wifi_kits"
],
"service_group": [
"//foundation/communication/wifi/wifi/services/wifi_standard/wifi_framework:wifi_manage",
"//foundation/communication/wifi/wifi/services/wifi_standard/wifi_framework:wifi_system_ability",
"//foundation/communication/wifi/wifi/services/wifi_standard/wifi_hal:wifi_hal"
]
},
"inner_kits": [
{
"header" : {

View File

@ -41,7 +41,6 @@ ohos_shared_library("wifi") {
]
deps = [
"$WIFI_ROOT_DIR/frameworks/native:wifi_sdk",
"$WIFI_ROOT_DIR/utils:wifi_utils",
"${ability_runtime_path}/frameworks/native/appkit:app_context",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//foundation/arkui/napi:ace_napi",
@ -88,7 +87,6 @@ ohos_shared_library("wifiext") {
external_deps = [
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"ipc:ipc_core",
]
relative_install_dir = "module"
@ -123,7 +121,6 @@ ohos_shared_library("wifi_native_js") {
]
deps = [
"$WIFI_ROOT_DIR/frameworks/native:wifi_sdk",
"$WIFI_ROOT_DIR/utils:wifi_utils",
"${ability_runtime_path}/frameworks/native/appkit:app_context",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//foundation/arkui/napi:ace_napi",

View File

@ -27,6 +27,8 @@ napi_value IsHotspotDualBandSupported(napi_env env, napi_callback_info info);
napi_value SetHotspotConfig(napi_env env, napi_callback_info info);
napi_value GetHotspotConfig(napi_env env, napi_callback_info info);
napi_value GetStations(napi_env env, napi_callback_info info);
napi_value AddBlockList(napi_env env, napi_callback_info info);
napi_value DelBlockList(napi_env env, napi_callback_info info);
} // namespace Wifi
} // namespace OHOS

View File

@ -65,6 +65,8 @@ static napi_value Init(napi_env env, napi_value exports) {
DECLARE_NAPI_FUNCTION("setHotspotConfig", SetHotspotConfig),
DECLARE_NAPI_FUNCTION("getHotspotConfig", GetHotspotConfig),
DECLARE_NAPI_FUNCTION("getStations", GetStations),
DECLARE_NAPI_FUNCTION("addBlockList", AddBlockList),
DECLARE_NAPI_FUNCTION("delBlockList", DelBlockList),
DECLARE_NAPI_FUNCTION("getP2pLinkedInfo", GetP2pLinkedInfo),
DECLARE_NAPI_FUNCTION("getCurrentGroup", GetCurrentGroup),
DECLARE_NAPI_FUNCTION("getP2pPeerDevices", GetP2pDevices),

View File

@ -203,5 +203,59 @@ napi_value GetStations(napi_env env, napi_callback_info info)
}
return arrayResult;
}
napi_value AddBlockList(napi_env env, napi_callback_info info)
{
TRACE_FUNC_CALL;
size_t argc = 1;
napi_value argv[argc];
napi_value thisVar;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
napi_valuetype valueType;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_string, "Wrong argument type. String expected.");
NAPI_ASSERT(env, wifiHotspotPtr != nullptr, "Wifi hotspot instance is null.");
StationInfo stationInfo;
char bssid[WIFI_BSSID_LENGTH] = {0};
size_t len = 0;
napi_get_value_string_utf8(env, argv[0], bssid, sizeof(bssid), &len);
stationInfo.bssid = bssid;
ErrCode ret = wifiHotspotPtr->AddBlockList(stationInfo);
if (ret != WIFI_OPT_SUCCESS) {
WIFI_LOGE("Add block list fail: %{public}d", ret);
}
napi_value result;
napi_get_boolean(env, ret == WIFI_OPT_SUCCESS, &result);
return result;
}
napi_value DelBlockList(napi_env env, napi_callback_info info)
{
TRACE_FUNC_CALL;
size_t argc = 1;
napi_value argv[argc];
napi_value thisVar;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
napi_valuetype valueType;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_string, "Wrong argument type. String expected.");
NAPI_ASSERT(env, wifiHotspotPtr != nullptr, "Wifi hotspot instance is null.");
StationInfo stationInfo;
char bssid[WIFI_BSSID_LENGTH] = {0};
size_t len = 0;
napi_get_value_string_utf8(env, argv[0], bssid, sizeof(bssid), &len);
stationInfo.bssid = bssid;
ErrCode ret = wifiHotspotPtr->DelBlockList(stationInfo);
if (ret != WIFI_OPT_SUCCESS) {
WIFI_LOGE("Del block list fail: %{public}d", ret);
}
napi_value result;
napi_get_boolean(env, ret == WIFI_OPT_SUCCESS, &result);
return result;
}
} // namespace Wifi
} // namespace OHOS

View File

@ -112,6 +112,7 @@ napi_value GetCurrentGroup(napi_env env, napi_callback_info info)
napi_value thisVar = nullptr;
void *data = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
NAPI_ASSERT(env, wifiP2pPtr != nullptr, "Wifi p2p instance is null.");
P2pGroupInfoAsyncContext *asyncContext = new P2pGroupInfoAsyncContext(env);
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
@ -142,6 +143,7 @@ napi_value GetP2pGroups(napi_env env, napi_callback_info info)
napi_value thisVar = nullptr;
void *data = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
NAPI_ASSERT(env, wifiP2pPtr != nullptr, "Wifi p2p instance is null.");
P2pGroupInfoListAsyncContext *asyncContext = new P2pGroupInfoListAsyncContext(env);
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
@ -172,12 +174,12 @@ napi_value DeletePersistentGroup(napi_env env, napi_callback_info info)
napi_value argv[argc];
napi_value thisVar;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
NAPI_ASSERT(env, wifiP2pPtr != nullptr, "Wifi p2p instance is null.");
napi_valuetype valueType;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_number, "Wrong argument type. napi_number expected.");
NAPI_ASSERT(env, wifiP2pPtr != nullptr, "Wifi p2p instance is null.");
WifiP2pGroupInfo groupInfo;
int netId = -999;
napi_get_value_int32(env, argv[0], &netId);
@ -248,6 +250,7 @@ napi_value GetP2pLocalDevice(napi_env env, napi_callback_info info)
napi_value thisVar = nullptr;
void *data = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
NAPI_ASSERT(env, wifiP2pPtr != nullptr, "Wifi p2p instance is null.");
P2pLocalDeviceAsyncContext *asyncContext = new P2pLocalDeviceAsyncContext(env);
NAPI_ASSERT(env, asyncContext != nullptr, "asyncContext is null.");
@ -279,13 +282,12 @@ napi_value SetDeviceName(napi_env env, napi_callback_info info)
napi_value thisVar;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
NAPI_ASSERT(env, argc == 1, "Wrong number of arguments");
NAPI_ASSERT(env, wifiP2pPtr != nullptr, "Wifi p2p instance is null.");
napi_valuetype valueType;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_string, "Wrong argument type. napi_number expected.");
NAPI_ASSERT(env, wifiP2pPtr != nullptr, "Wifi p2p instance is null.");
char name[64] = {0};
size_t typeLen = 0;
napi_get_value_string_utf8(env, argv[0], name, sizeof(name), &typeLen);
@ -321,12 +323,12 @@ napi_value P2pConnect(napi_env env, napi_callback_info info)
napi_value argv[argc];
napi_value thisVar;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
NAPI_ASSERT(env, wifiP2pPtr != nullptr, "Wifi p2p instance is null.");
napi_valuetype valueType;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected.");
NAPI_ASSERT(env, wifiP2pPtr != nullptr, "Wifi p2p instance is null.");
WifiP2pConfig config;
JsObjToP2pConfig(env, argv[0], config);
ErrCode ret = wifiP2pPtr->P2pConnect(config);
@ -356,12 +358,12 @@ napi_value CreateGroup(napi_env env, napi_callback_info info)
napi_value argv[1];
napi_value thisVar;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
NAPI_ASSERT(env, wifiP2pPtr != nullptr, "Wifi p2p instance is null.");
napi_valuetype valueType;
napi_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_object, "Wrong argument type. Object expected.");
NAPI_ASSERT(env, wifiP2pPtr != nullptr, "Wifi p2p instance is null.");
WifiP2pConfig config;
JsObjToP2pConfig(env, argv[0], config);
ErrCode ret = wifiP2pPtr->CreateGroup(config);

View File

@ -45,7 +45,6 @@ if (defined(ohos_lite)) {
"//foundation/systemabilitymgr/samgr_lite/interfaces/innerkits/registry",
"//foundation/systemabilitymgr/samgr_lite/interfaces/innerkits/samgr",
"//third_party/bounds_checking_function/include",
"//utils/native/lite/include",
"//commonlibrary/c_utils/base/include",
]
@ -206,9 +205,7 @@ if (defined(ohos_lite)) {
]
external_deps = [
"ability_base:want",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ipc:ipc_core",
]

View File

@ -24,6 +24,7 @@ namespace OHOS {
namespace Wifi {
#define AP_CHANNEL_DEFAULT 6
#define AP_CHANNEL_5G_DEFAULT 149
#define WIFI_BSSID_LENGTH 18
enum class ApState {
AP_STATE_NONE = 0,
AP_STATE_IDLE,

View File

@ -24,7 +24,7 @@
namespace OHOS {
namespace Wifi {
constexpr int WIFI_STR_MAC_LENGTH = 17;
constexpr int MAX_PASSPHRASE_LENGTH = 63;
constexpr int MAX_PASSPHRASE_LENGTH = 127;
constexpr int DEVICE_NAME_LENGTH = 32;
enum class P2pGroupStatus { GS_CREATING, GS_CREATED, GS_STARTED, GS_REMOVING, GS_INVALID };

View File

@ -38,7 +38,7 @@ int WifiDeviceCallBackStub::OnRemoteRequest(
}
if (data.ReadInterfaceToken() != GetDescriptor()) {
WIFI_LOGE("Sta callback stub token verification error");
WIFI_LOGE("Sta callback stub token verification error: %{public}d", code);
return WIFI_OPT_FAILED;
}

View File

@ -39,7 +39,7 @@ int WifiHotspotCallbackStub::OnRemoteRequest(
}
if (data.ReadInterfaceToken() != GetDescriptor()) {
WIFI_LOGE("Hotspot callback stub token verification error");
WIFI_LOGE("Hotspot callback stub token verification error: %{public}d", code);
return WIFI_OPT_FAILED;
}

View File

@ -55,7 +55,7 @@ int WifiP2pCallbackStub::OnRemoteRequest(
}
if (data.ReadInterfaceToken() != GetDescriptor()) {
WIFI_LOGE("P2p callback stub token verification error");
WIFI_LOGE("P2p callback stub token verification error: %{public}d", code);
return WIFI_OPT_FAILED;
}

View File

@ -38,7 +38,7 @@ int WifiScanCallbackStub::OnRemoteRequest(
}
if (data.ReadInterfaceToken() != GetDescriptor()) {
WIFI_LOGE("Scan callback stub token verification error");
WIFI_LOGE("Scan callback stub token verification error: %{public}d", code);
return WIFI_OPT_FAILED;
}

View File

@ -68,7 +68,6 @@ if (defined(ohos_lite)) {
"//foundation/systemabilitymgr/samgr_lite/interfaces/innerkits/registry",
"//foundation/systemabilitymgr/samgr_lite/interfaces/innerkits/samgr",
"//third_party/bounds_checking_function/include",
"//utils/native/lite/include",
]
deps = [
@ -128,7 +127,6 @@ if (defined(ohos_lite)) {
"//foundation/systemabilitymgr/samgr_lite/interfaces/innerkits/registry",
"//foundation/systemabilitymgr/samgr_lite/interfaces/innerkits/samgr",
"//third_party/bounds_checking_function/include",
"//utils/native/lite/include",
]
deps = [
@ -213,12 +211,7 @@ if (defined(ohos_lite)) {
":wifi_manager_service_header",
]
external_deps = [
"ability_base:want",
"bundle_framework:appexecfwk_base",
"eventhandler:libeventhandler",
"ipc:ipc_core",
]
external_deps = [ "ipc:ipc_core" ]
}
ohos_source_set("wifi_device_service_impl") {
part_name = "wifi"
@ -254,7 +247,6 @@ if (defined(ohos_lite)) {
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"ipc:ipc_core",
]
}
@ -275,12 +267,7 @@ if (defined(ohos_lite)) {
deps = [ "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit" ]
external_deps = [
"ability_base:want",
"bundle_framework:appexecfwk_base",
"eventhandler:libeventhandler",
"ipc:ipc_core",
]
external_deps = [ "ipc:ipc_core" ]
defines = [
"FEATURE_AP_SUPPORT",
"AP_INSTANCE_MAX_NUM=$wifi_feature_with_ap_num",
@ -301,15 +288,9 @@ if (defined(ohos_lite)) {
":wifi_manager_service_header",
]
deps = [
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
"//foundation/communication/netmanager_base/services/netmanagernative:netsys_native_manager",
]
deps = [ "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit" ]
external_deps = [
"ability_base:want",
"bundle_framework:appexecfwk_base",
"eventhandler:libeventhandler",
"ipc:ipc_core",
"netmanager_base:net_conn_manager_if",
]
@ -344,11 +325,9 @@ if (defined(ohos_lite)) {
external_deps = [
"access_token:libaccesstoken_sdk",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"ipc:ipc_core",
"netmanager_base:net_conn_manager_if",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
if (wifi_feature_with_encryption) {
@ -396,7 +375,6 @@ if (defined(ohos_lite)) {
deps = [
":wifi_manager_service",
":wifi_scan_service_impl",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client:wifi_idl_client",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk:system_ability_fwk",
]

View File

@ -46,28 +46,27 @@ bool Handler::InitialHandler()
}
int ret = pthread_create(&handleThread, nullptr, RunHandleThreadFunc, this);
if (ret < 0) {
if (ret != 0) {
LOGE("pthread_create failed.\n");
return false;
}
LOGI("pthread_create ret: %{public}d\n", ret);
return true;
}
void Handler::StopHandlerThread()
{
LOGI("Handler::StopHandlerThread");
LOGI("Enter StopHandlerThread");
if (isRunning) {
isRunning = false;
if (pMyQueue != nullptr) {
pMyQueue->StopQueueLoop();
}
if (handleThread != 0) {
pthread_join(handleThread, nullptr);
}
}
LOGI("Leave StopHandlerThread");
return;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -12,10 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "message_queue.h"
#include <sys/time.h>
#include "wifi_log.h"
#include <thread>
#include "wifi_errcode.h"
#include "wifi_log.h"
#undef LOG_TAG
#define LOG_TAG "OHWIFI_MESSAGE_QUEUE"
@ -37,20 +39,19 @@ MessageQueue::~MessageQueue()
delete current;
current = next;
}
return;
}
bool MessageQueue::AddMessageToQueue(InternalMessage *message, int64_t handleTime)
{
if (message == nullptr) {
LOGE("message is null.\n");
LOGE("message is null.");
return false;
}
if (mNeedQuit) {
MessageManage::GetInstance().ReclaimMsg(message);
LOGE("Already quit the message queue.\n");
LOGE("Already quit the message queue.");
return false;
}
@ -87,18 +88,15 @@ bool MessageQueue::AddMessageToQueue(InternalMessage *message, int64_t handleTim
/* Wake up the process. */
if (needWake) {
std::unique_lock<std::mutex> lck(mMtxBlock);
mCvQueue.notify_all();
mIsBlocked = false;
}
return true;
}
bool MessageQueue::DeleteMessageFromQueue(int messageName)
{
std::unique_lock<std::mutex> lck(mMtxQueue);
InternalMessage *pTop = pMessageQueue;
if (pTop == nullptr) {
return true;
@ -120,7 +118,6 @@ bool MessageQueue::DeleteMessageFromQueue(int messageName)
pMessageQueue = pTop->GetNextMsg();
MessageManage::GetInstance().ReclaimMsg(pTop);
}
return true;
}
@ -133,11 +130,10 @@ InternalMessage *MessageQueue::GetNextMessage()
/* Obtains the current time, accurate to milliseconds. */
struct timeval curTime = {0, 0};
if (gettimeofday(&curTime, nullptr) != 0) {
LOGE("gettimeofday failed.\n");
LOGE("gettimeofday failed.");
return nullptr;
}
int64_t nowTime = static_cast<int64_t>(curTime.tv_sec) * TIME_USEC_1000 + curTime.tv_usec / TIME_USEC_1000;
{
std::unique_lock<std::mutex> lck(mMtxQueue);
InternalMessage *curMsg = pMessageQueue;
@ -152,6 +148,7 @@ InternalMessage *MessageQueue::GetNextMessage()
mIsBlocked = false;
pMessageQueue = curMsg->GetNextMsg();
curMsg->SetNextMsg(nullptr);
LOGD("Return first message.");
return curMsg;
}
} else {
@ -163,28 +160,26 @@ InternalMessage *MessageQueue::GetNextMessage()
std::unique_lock<std::mutex> lck(mMtxBlock);
if (mIsBlocked && (!mNeedQuit)) {
if (mCvQueue.wait_for(lck, std::chrono::milliseconds(nextBlockTime)) == std::cv_status::timeout) {
LOGD("mCvQueue timeout.\n");
LOGD("mCvQueue timeout.");
} else {
LOGD("Wake up.\n");
LOGD("Wake up.");
}
}
mIsBlocked = false;
}
LOGE("Already quit the message queue.\n");
LOGE("Already quit the message queue.");
return nullptr;
}
void MessageQueue::StopQueueLoop()
{
mNeedQuit = true;
if (mIsBlocked) {
std::unique_lock<std::mutex> lck(mMtxBlock);
LOGI("Start stop queue loop.");
while (mIsBlocked) {
mNeedQuit = true;
mCvQueue.notify_all();
mIsBlocked = false;
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // sleep 1 ms
}
return;
LOGI("Queue loop has stopped.");
}
} // namespace Wifi
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -16,6 +16,7 @@
#ifndef OHOS_MESSAGE_QUEUE_H
#define OHOS_MESSAGE_QUEUE_H
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <mutex>
@ -73,9 +74,9 @@ private:
/* Message Queuing */
InternalMessage *pMessageQueue;
/* No messages to be executed, blocking */
bool mIsBlocked;
std::atomic<bool> mIsBlocked;
/* Exit Loop */
bool mNeedQuit;
std::atomic<bool> mNeedQuit;
/* Thread lock of operation queue */
std::mutex mMtxQueue;
/* Blocked thread lock */

View File

@ -132,7 +132,6 @@ void StateMachine::StopHandlerThread()
LOGE("Start StateMachine failed, pStateMachineHandler is nullptr!");
return;
}
pStateMachineHandler->StopHandlerThread();
}

View File

@ -52,6 +52,7 @@ bool WifiBaseHalInterface::InitIdlClient(void)
void WifiBaseHalInterface::ExitAllIdlClient(void)
{
LOGI("Exit all idl client!");
if (mIdlClient != nullptr) {
mIdlClient->ExitAllClient();
}

View File

@ -67,6 +67,7 @@ int WifiIdlClient::InitClient(void)
void WifiIdlClient::ExitAllClient(void)
{
LOGI("Exit all client!");
if (pRpcClient == nullptr) {
return;
}

View File

@ -74,12 +74,9 @@ ohos_shared_library("wifi_ap_service") {
]
deps = [
"$DHCP_ROOT_DIR/services/mgr_service:dhcp_manager_service",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_manager_service",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client:wifi_idl_client",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common:wifi_common_service",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
"$WIFI_ROOT_DIR/utils:wifi_utils",
]
defines = [ "AP_INTF=\"$wifi_feature_with_ap_intf\"" ]

View File

@ -378,7 +378,7 @@ void WifiConfigCenter::SetAppPackageName(const std::string &appPackageName)
WifiSettings::GetInstance().SetAppPackageName(appPackageName);
}
const std::string& WifiConfigCenter::GetAppPackageName() const
const std::string WifiConfigCenter::GetAppPackageName() const
{
return WifiSettings::GetInstance().GetAppPackageName();
}

View File

@ -504,7 +504,7 @@ public:
*
* @return const std::string& - app package name.
*/
const std::string& GetAppPackageName() const;
const std::string GetAppPackageName() const;
/**
* @Description Set freeze mode state.

View File

@ -1187,6 +1187,7 @@ void WifiDeviceServiceImpl::SaBasicDump(std::string& result)
#ifndef OHOS_ARCH_LITE
int32_t WifiDeviceServiceImpl::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
WIFI_LOGI("Enter sta dump func.");
std::vector<std::string> vecArgs;
std::transform(args.begin(), args.end(), std::back_inserter(vecArgs), [](const std::u16string &arg) {
return Str16ToStr8(arg);

View File

@ -73,7 +73,7 @@ void WifiDeviceStub::InitHandleMap()
int WifiDeviceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
if (data.ReadInterfaceToken() != GetDescriptor()) {
WIFI_LOGE("Sta stub token verification error");
WIFI_LOGE("Sta stub token verification error: %{public}d", code);
return WIFI_OPT_FAILED;
}

View File

@ -16,6 +16,7 @@
#include <csignal>
#include "wifi_logger.h"
#include "wifi_config_center.h"
#include "wifi_dumper.h"
#include "wifi_manager.h"
#include "wifi_hotspot_mgr_service_impl.h"
#include "wifi_hotspot_service_impl.h"
@ -141,5 +142,23 @@ sptr<IRemoteObject> WifiHotspotMgrServiceImpl::GetWifiRemote(int id)
}
return nullptr;
}
int32_t WifiHotspotMgrServiceImpl::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
WIFI_LOGI("Enter hotspot dump func.");
std::vector<std::string> vecArgs;
std::transform(args.begin(), args.end(), std::back_inserter(vecArgs), [](const std::u16string &arg) {
return Str16ToStr8(arg);
});
WifiDumper dumper;
std::string result;
dumper.HotspotDump(WifiHotspotServiceImpl::SaBasicDump, vecArgs, result);
if (!SaveStringToFd(fd, result)) {
WIFI_LOGE("WiFi hotspot save string to fd failed.");
return ERR_OK;
}
return ERR_OK;
}
} // namespace Wifi
} // namespace OHOS

View File

@ -16,11 +16,12 @@
#ifndef OHOS_WIFI_HOTSPOT_MGR_SERVICE_IMPL_H
#define OHOS_WIFI_HOTSPOT_MGR_SERVICE_IMPL_H
#include "wifi_errcode.h"
#include "system_ability.h"
#include "wifi_hotspot_stub.h"
#include "wifi_hotspot_mgr_stub.h"
#include <file_ex.h>
#include "iremote_object.h"
#include "system_ability.h"
#include "wifi_errcode.h"
#include "wifi_hotspot_mgr_stub.h"
#include "wifi_hotspot_stub.h"
namespace OHOS {
namespace Wifi {
@ -38,6 +39,16 @@ public:
void OnStart() override;
void OnStop() override;
sptr<IRemoteObject> GetWifiRemote(int id) override;
/**
* @Description dump hotspot information
*
* @param fd - file descriptor
* @param args - dump arguments
* @return ErrCode - operation result
*/
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
private:
bool Init();
friend void SigHandler(int sig);

View File

@ -43,7 +43,7 @@ int WifiHotspotMgrStub::OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
if (data.ReadInterfaceToken() != GetDescriptor()) {
WIFI_LOGE("Hotspot stub token verification error");
WIFI_LOGE("Hotspot stub token verification error: %{public}d", code);
return WIFI_OPT_FAILED;
}
FuncHandleMap::iterator iter = funcHandleMap_.find(code);

View File

@ -14,7 +14,6 @@
*/
#include "wifi_hotspot_service_impl.h"
#include <file_ex.h>
#include <csignal>
#include "wifi_permission_utils.h"
#include "wifi_global_func.h"
@ -26,7 +25,6 @@
#include "wifi_logger.h"
#include "define.h"
#include "wifi_logger.h"
#include "wifi_dumper.h"
#include "wifi_common_util.h"
DEFINE_WIFILOG_HOTSPOT_LABEL("WifiHotspotServiceImpl");
@ -669,22 +667,5 @@ void WifiHotspotServiceImpl::SaBasicDump(std::string& result)
StationsInfoDump(result);
}
}
int32_t WifiHotspotServiceImpl::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
std::vector<std::string> vecArgs;
std::transform(args.begin(), args.end(), std::back_inserter(vecArgs), [](const std::u16string &arg) {
return Str16ToStr8(arg);
});
WifiDumper dumper;
std::string result;
dumper.HotspotDump(SaBasicDump, vecArgs, result);
if (!SaveStringToFd(fd, result)) {
WIFI_LOGE("WiFi hotspot save string to fd failed.");
return ERR_OK;
}
return ERR_OK;
}
} // namespace Wifi
} // namespace OHOS

View File

@ -179,19 +179,16 @@ public:
ErrCode SetPowerModel(const PowerModel& model) override;
/**
* @Description dump p2p information
* @Description Dump sa basic information
*
* @param fd - file descriptor
* @param args - dump arguments
* @return ErrCode - operation result
* @param result[out] - dump result
*/
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
static void SaBasicDump(std::string& result);
private:
ErrCode CheckCanEnableHotspot(const ServiceType type);
int CheckOperHotspotSwitchPermission(const ServiceType type);
bool IsApServiceRunning();
static void SaBasicDump(std::string& result);
static void ConfigInfoDump(std::string& result);
static void StationsInfoDump(std::string& result);
static void SigHandler(int sig);

View File

@ -64,7 +64,7 @@ void WifiHotspotStub::InitHandleMap()
int WifiHotspotStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
if (data.ReadInterfaceToken() != GetDescriptor()) {
WIFI_LOGE("Hotspot stub token verification error");
WIFI_LOGE("Hotspot stub token verification error: %{public}d", code);
return WIFI_OPT_FAILED;
}

View File

@ -246,7 +246,7 @@ int WifiManager::Init()
return -1;
}
if (WifiConfigCenter::GetInstance().GetStaLastRunState()) { /* Automatic startup upon startup */
WIFI_LOGE("AutoStartStaApService");
WIFI_LOGI("AutoStartSta/P2pService");
#ifdef OHOS_ARCH_LITE
std::thread startStaSrvThread(WifiManager::AutoStartStaServiceThread);
startStaSrvThread.detach();
@ -261,7 +261,7 @@ int WifiManager::Init()
* The sta service automatically starts upon startup. After the sta
* service is started, the scanning is directly started.
*/
WIFI_LOGE("AutoStartScanService");
WIFI_LOGI("AutoStartScanService");
AutoStartScanService();
}
return 0;
@ -269,6 +269,7 @@ int WifiManager::Init()
void WifiManager::Exit()
{
WIFI_LOGI("[WifiManager] Exit.");
WifiServiceManager::GetInstance().UninstallAllService();
WifiStaHalInterface::GetInstance().ExitAllIdlClient();
WifiInternalEventDispatcher::GetInstance().Exit();

View File

@ -93,7 +93,7 @@ void WifiNetAgent::UnregisterNetSupplier()
WIFI_LOGI("Unregister network result:%{public}d", result);
}
void WifiNetAgent::UpdateNetSupplierInfo(sptr<NetManagerStandard::NetSupplierInfo> &netSupplierInfo)
void WifiNetAgent::UpdateNetSupplierInfo(const sptr<NetManagerStandard::NetSupplierInfo> &netSupplierInfo)
{
TimeStats timeStats(__func__);
WIFI_LOGI("Enter UpdateNetSupplierInfo.");

View File

@ -60,7 +60,7 @@ public:
* @param supplierId network unique identity id returned after network registration
* @param netSupplierInfo network data information
*/
void UpdateNetSupplierInfo(sptr<NetManagerStandard::NetSupplierInfo> &netSupplierInfo);
void UpdateNetSupplierInfo(const sptr<NetManagerStandard::NetSupplierInfo> &netSupplierInfo);
/**
* Update link information

View File

@ -105,7 +105,6 @@ ohos_shared_library("wifi_p2p_service") {
external_deps = [
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"netmanager_base:net_conn_manager_if",
]
@ -113,7 +112,6 @@ ohos_shared_library("wifi_p2p_service") {
"$DHCP_ROOT_DIR/services/mgr_service:dhcp_manager_service",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_manager_service",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client:wifi_idl_client",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common:wifi_common_service",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
"$WIFI_ROOT_DIR/utils:wifi_utils",
]

View File

@ -1016,6 +1016,7 @@ void WifiP2pServiceImpl::SaBasicDump(std::string& result)
int32_t WifiP2pServiceImpl::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
WIFI_LOGI("Enter p2p dump func.");
std::vector<std::string> vecArgs;
std::transform(args.begin(), args.end(), std::back_inserter(vecArgs), [](const std::u16string &arg) {
return Str16ToStr8(arg);

View File

@ -81,7 +81,7 @@ void WifiP2pStub::InitHandleMap()
int WifiP2pStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
if (data.ReadInterfaceToken() != GetDescriptor()) {
WIFI_LOGE("P2p stub token verification error");
WIFI_LOGE("P2p stub token verification error: %{public}d", code);
return WIFI_OPT_FAILED;
}

View File

@ -89,7 +89,6 @@ if (defined(ohos_lite)) {
]
deps = [
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_manager_service",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client:wifi_idl_client",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
]

View File

@ -1342,9 +1342,9 @@ ErrCode ScanService::ApplyScanPolices(ScanType type)
{
LOGI("Enter ScanService::ApplyScanPolices.");
/* Obtains app parameters and scenario status parameters. */
auto &appPackageName = WifiSettings::GetInstance().GetAppPackageName();
auto &trustListPolicies = WifiSettings::GetInstance().ReloadTrustListPolicies();
auto &movingFreezePolicy = WifiSettings::GetInstance().ReloadMovingFreezePolicy();
auto appPackageName = WifiSettings::GetInstance().GetAppPackageName();
auto trustListPolicies = WifiSettings::GetInstance().ReloadTrustListPolicies();
auto movingFreezePolicy = WifiSettings::GetInstance().ReloadMovingFreezePolicy();
ErrCode rlt = WIFI_OPT_SUCCESS;
if (appPackageName.empty()) {
rlt = AllowScanByType(type);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -12,15 +12,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "scan_state_machine.h"
#include "wifi_error_no.h"
#include "wifi_logger.h"
#include "wifi_settings.h"
#include "wifi_sta_hal_interface.h"
DEFINE_WIFILOG_SCAN_LABEL("ScanStateMachine");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_SCAN_LABEL("ScanStateMachine");
std::shared_mutex ScanStateMachine::lock;
ScanStateMachine::ScanStateMachine()
: StateMachine("ScanStateMachine"),
quitFlag(false),
@ -121,11 +124,11 @@ bool ScanStateMachine::InitScanStateMachine()
if (InitCommonScanState() != true) {
return false;
};
}
if (InitPnoScanState() != true) {
return false;
};
}
BuildScanStateTree();
SetFirstState(initState);
@ -157,8 +160,11 @@ ScanStateMachine::InitState::~InitState()
void ScanStateMachine::InitState::GoInState()
{
WIFI_LOGI("Enter ScanStateMachine::InitState::GoInState.\n");
pScanStateMachine->runningScans.clear();
pScanStateMachine->waitingScans.clear();
{
std::unique_lock<std::shared_mutex> guard(lock);
pScanStateMachine->runningScans.clear();
pScanStateMachine->waitingScans.clear();
}
if (pScanStateMachine->quitFlag) {
WIFI_LOGI("Notify finish ScanStateMachine.\n");
@ -475,13 +481,11 @@ void ScanStateMachine::PnoScanHardware::GoInState()
WIFI_LOGE("StartPnoScanHardware failed.");
return;
}
return;
}
void ScanStateMachine::PnoScanHardware::GoOutState()
{
WIFI_LOGI("Enter ScanStateMachine::PnoScanHardware::GoOutState.\n");
return;
}
bool ScanStateMachine::PnoScanHardware::ExecuteStateMsg(InternalMessage *msg)
@ -525,7 +529,6 @@ ScanStateMachine::CommonScanAfterPno::CommonScanAfterPno(ScanStateMachine *paraS
: State("CommonScanAfterPno")
{
pScanStateMachine = paraScanStateMachine;
return;
}
ScanStateMachine::CommonScanAfterPno::~CommonScanAfterPno()
@ -535,7 +538,6 @@ void ScanStateMachine::CommonScanAfterPno::GoInState()
{
WIFI_LOGI("Enter ScanStateMachine::CommonScanAfterPno::GoInState.\n");
pScanStateMachine->CommonScanAfterPnoProcess();
return;
}
void ScanStateMachine::CommonScanAfterPno::GoOutState()
@ -545,8 +547,6 @@ void ScanStateMachine::CommonScanAfterPno::GoOutState()
pScanStateMachine->StopTimer(static_cast<int>(WAIT_SCAN_RESULT_TIMER));
}
pScanStateMachine->remainWaitResultTimer = false;
return;
}
bool ScanStateMachine::CommonScanAfterPno::ExecuteStateMsg(InternalMessage *msg)
@ -609,14 +609,12 @@ void ScanStateMachine::PnoScanSoftware::GoInState()
if (!pScanStateMachine->StartNewSoftwareScan()) {
WIFI_LOGE("failed to start new softwareScan");
}
return;
}
void ScanStateMachine::PnoScanSoftware::GoOutState()
{
WIFI_LOGI("Enter ScanStateMachine::PnoScanSoftware::GoOutState.\n");
pScanStateMachine->StopTimer(static_cast<int>(SOFTWARE_PNO_SCAN_TIMER));
return;
}
bool ScanStateMachine::PnoScanSoftware::ExecuteStateMsg(InternalMessage *msg)
@ -649,13 +647,11 @@ ScanStateMachine::PnoSwScanFree::~PnoSwScanFree()
void ScanStateMachine::PnoSwScanFree::GoInState()
{
WIFI_LOGI("Enter ScanStateMachine::PnoSwScanFree::GoInState.\n");
return;
}
void ScanStateMachine::PnoSwScanFree::GoOutState()
{
WIFI_LOGI("Enter ScanStateMachine::PnoSwScanFree::GoOutState.\n");
return;
}
bool ScanStateMachine::PnoSwScanFree::ExecuteStateMsg(InternalMessage *msg)
@ -706,14 +702,12 @@ ScanStateMachine::PnoSwScanning::~PnoSwScanning()
void ScanStateMachine::PnoSwScanning::GoInState()
{
WIFI_LOGI("Enter ScanStateMachine::PnoSwScanning::GoInState.\n");
return;
}
void ScanStateMachine::PnoSwScanning::GoOutState()
{
WIFI_LOGI("Enter ScanStateMachine::PnoSwScanning::GoOutState.\n");
pScanStateMachine->StopTimer(static_cast<int>(WAIT_SCAN_RESULT_TIMER));
return;
}
bool ScanStateMachine::PnoSwScanning::ExecuteStateMsg(InternalMessage *msg)
@ -773,10 +767,11 @@ void ScanStateMachine::CommonScanRequestProcess(InternalMessage *interMessage)
WIFI_LOGE("invalid scan type");
return;
}
waitingScans.insert(std::pair<int, InterScanConfig>(requestIndex, scanConfig));
{
std::unique_lock<std::shared_mutex> guard(lock);
waitingScans.insert(std::pair<int, InterScanConfig>(requestIndex, scanConfig));
}
StartNewCommonScan();
return;
}
bool ScanStateMachine::GetCommonScanRequestInfo(
@ -794,7 +789,6 @@ bool ScanStateMachine::GetCommonScanRequestInfo(
WIFI_LOGE("GetCommonScanConfig failed.");
return false;
}
return true;
}
@ -835,7 +829,6 @@ bool ScanStateMachine::GetCommonScanConfig(InternalMessage *interMessage, InterS
scanConfig.maxScansCache = interMessage->GetIntFromMessage();
scanConfig.maxBackScanPeriod = interMessage->GetIntFromMessage();
scanConfig.scanStyle = interMessage->GetIntFromMessage();
return true;
}
@ -843,45 +836,46 @@ void ScanStateMachine::StartNewCommonScan()
{
WIFI_LOGI("Enter ScanStateMachine::StartNewCommonScan.\n");
if (waitingScans.size() == 0) {
ContinuePnoScanProcess();
return;
}
ClearRunningScanSettings();
bool hasFullScan = false;
/* Traverse the request list and combine parameters */
std::map<int, InterScanConfig>::iterator configIter = waitingScans.begin();
for (; configIter != waitingScans.end(); ++configIter) {
runningScanSettings.scanStyle = MergeScanStyle(runningScanSettings.scanStyle, configIter->second.scanStyle);
std::vector<std::string>::iterator hiddenIter = configIter->second.hiddenNetworkSsid.begin();
/* Remove duplicate hidden list */
for (; hiddenIter != configIter->second.hiddenNetworkSsid.end(); ++hiddenIter) {
if (std::find(runningScanSettings.hiddenNetworkSsid.begin(),
runningScanSettings.hiddenNetworkSsid.end(),
*hiddenIter) != runningScanSettings.hiddenNetworkSsid.end()) {
continue;
}
runningScanSettings.hiddenNetworkSsid.push_back(*hiddenIter);
{
std::shared_lock<std::shared_mutex> guard(lock);
if (waitingScans.size() == 0) {
ContinuePnoScanProcess();
return;
}
ClearRunningScanSettings();
bool hasFullScan = false;
/* Traverse the request list and combine parameters */
std::map<int, InterScanConfig>::iterator configIter = waitingScans.begin();
for (; configIter != waitingScans.end(); ++configIter) {
runningScanSettings.scanStyle = MergeScanStyle(runningScanSettings.scanStyle, configIter->second.scanStyle);
std::vector<std::string>::iterator hiddenIter = configIter->second.hiddenNetworkSsid.begin();
/* Remove duplicate hidden list */
for (; hiddenIter != configIter->second.hiddenNetworkSsid.end(); ++hiddenIter) {
if (std::find(runningScanSettings.hiddenNetworkSsid.begin(),
runningScanSettings.hiddenNetworkSsid.end(),
*hiddenIter) != runningScanSettings.hiddenNetworkSsid.end()) {
continue;
}
runningScanSettings.hiddenNetworkSsid.push_back(*hiddenIter);
}
if (!hasFullScan) {
/* When scanFreqs is empty, it means that scan all frequenties */
if (configIter->second.scanFreqs.empty()) {
runningScanSettings.scanFreqs.clear();
runningFullScanFlag = true;
hasFullScan = true;
} else {
std::vector<int>::iterator freqIter = configIter->second.scanFreqs.begin();
/* Repetitions are eliminated */
for (; freqIter != configIter->second.scanFreqs.end(); ++freqIter) {
if (std::find(runningScanSettings.scanFreqs.begin(),
runningScanSettings.scanFreqs.end(),
*freqIter) != runningScanSettings.scanFreqs.end()) {
continue;
if (!hasFullScan) {
/* When scanFreqs is empty, it means that scan all frequenties */
if (configIter->second.scanFreqs.empty()) {
runningScanSettings.scanFreqs.clear();
runningFullScanFlag = true;
hasFullScan = true;
} else {
std::vector<int>::iterator freqIter = configIter->second.scanFreqs.begin();
/* Repetitions are eliminated */
for (; freqIter != configIter->second.scanFreqs.end(); ++freqIter) {
if (std::find(runningScanSettings.scanFreqs.begin(),
runningScanSettings.scanFreqs.end(),
*freqIter) != runningScanSettings.scanFreqs.end()) {
continue;
}
runningScanSettings.scanFreqs.push_back(*freqIter);
}
runningScanSettings.scanFreqs.push_back(*freqIter);
}
}
}
@ -893,12 +887,11 @@ void ScanStateMachine::StartNewCommonScan()
return;
}
std::unique_lock<std::shared_mutex> guard(lock);
runningScans.swap(waitingScans);
waitingScans.clear();
SwitchState(commonScanningState);
WIFI_LOGI("StartNewCommonScan success.\n");
return;
}
void ScanStateMachine::ClearRunningScanSettings()
@ -935,7 +928,6 @@ bool ScanStateMachine::StartSingleCommonScan(WifiScanParam &scanParam)
* fails
*/
StartTimer(static_cast<int>(WAIT_SCAN_RESULT_TIMER), MAX_WAIT_SCAN_RESULT_TIME);
return true;
}
@ -951,12 +943,12 @@ void ScanStateMachine::CommonScanWhenRunning(InternalMessage *interMessage)
}
if (ActiveCoverNewScan(scanConfig)) {
std::unique_lock<std::shared_mutex> guard(lock);
runningScans.insert(std::pair<int, InterScanConfig>(requestIndex, scanConfig));
} else {
std::unique_lock<std::shared_mutex> guard(lock);
waitingScans.insert(std::pair<int, InterScanConfig>(requestIndex, scanConfig));
}
return;
}
bool ScanStateMachine::ActiveCoverNewScan(InterScanConfig &interScanConfig)
@ -1003,7 +995,6 @@ bool ScanStateMachine::ActiveCoverNewScan(InterScanConfig &interScanConfig)
return false;
}
}
return true;
}
@ -1023,9 +1014,8 @@ void ScanStateMachine::CommonScanInfoProcess()
if (scanStatusReportHandler) {
scanStatusReportHandler(scanStatusReport);
}
std::unique_lock<std::shared_mutex> guard(lock);
runningScans.clear();
return;
}
void ScanStateMachine::GetSecurityTypeAndBand(std::vector<InterScanInfo> &scanInfos)
@ -1088,8 +1078,6 @@ void ScanStateMachine::ReportStatusChange(ScanStatus status)
if (scanStatusReportHandler) {
scanStatusReportHandler(scanStatusReport);
}
return;
}
void ScanStateMachine::ReportScanInnerEvent(ScanInnerEventType innerEvent)
@ -1102,8 +1090,6 @@ void ScanStateMachine::ReportScanInnerEvent(ScanInnerEventType innerEvent)
if (scanStatusReportHandler) {
scanStatusReportHandler(scanStatusReport);
}
return;
}
void ScanStateMachine::ReportCommonScanFailed(int requestIndex)
@ -1120,8 +1106,6 @@ void ScanStateMachine::ReportCommonScanFailed(int requestIndex)
if (scanStatusReportHandler) {
scanStatusReportHandler(scanStatusReport);
}
return;
}
void ScanStateMachine::ReportCommonScanFailedAndClear(bool runningFlag)
@ -1131,9 +1115,11 @@ void ScanStateMachine::ReportCommonScanFailedAndClear(bool runningFlag)
ScanStatusReport scanStatusReport;
if (runningFlag) {
GetRunningIndexList(scanStatusReport.requestIndexList);
std::unique_lock<std::shared_mutex> guard(lock);
runningScans.clear();
} else {
GetWaitingIndexList(scanStatusReport.requestIndexList);
std::unique_lock<std::shared_mutex> guard(lock);
waitingScans.clear();
}
@ -1145,28 +1131,24 @@ void ScanStateMachine::ReportCommonScanFailedAndClear(bool runningFlag)
if (scanStatusReportHandler) {
scanStatusReportHandler(scanStatusReport);
}
return;
}
void ScanStateMachine::GetRunningIndexList(std::vector<int> &runningIndexList)
{
std::shared_lock<std::shared_mutex> guard(lock);
std::map<int, InterScanConfig>::iterator iter = runningScans.begin();
for (; iter != runningScans.end(); ++iter) {
runningIndexList.push_back(iter->first);
}
return;
}
void ScanStateMachine::GetWaitingIndexList(std::vector<int> &waitingIndexList)
{
std::shared_lock<std::shared_mutex> guard(lock);
std::map<int, InterScanConfig>::iterator iter = waitingScans.begin();
for (; iter != waitingScans.end(); ++iter) {
waitingIndexList.push_back(iter->first);
}
return;
}
bool ScanStateMachine::VerifyScanStyle(int scanStyle)
@ -1206,7 +1188,7 @@ int ScanStateMachine::MergeScanStyle(int currentScanStyle, int newScanStyle)
void ScanStateMachine::RemoveCommonScanRequest(int requestIndex)
{
WIFI_LOGI("Enter ScanStateMachine::RemoveCommonScanRequest.\n");
std::unique_lock<std::shared_mutex> guard(lock);
if (runningScans.count(requestIndex) == 1) {
runningScans.erase(requestIndex);
}
@ -1214,8 +1196,6 @@ void ScanStateMachine::RemoveCommonScanRequest(int requestIndex)
if (waitingScans.count(requestIndex) == 1) {
waitingScans.erase(requestIndex);
}
return;
}
void ScanStateMachine::PnoScanRequestProcess(InternalMessage *interMessage)
@ -1232,8 +1212,6 @@ void ScanStateMachine::PnoScanRequestProcess(InternalMessage *interMessage)
} else {
SwitchState(pnoScanSoftwareState);
}
return;
}
void ScanStateMachine::ContinuePnoScanProcess()
@ -1270,8 +1248,6 @@ void ScanStateMachine::PnoScanHardwareProcess(InternalMessage *interMessage)
WIFI_LOGE("StartPnoScanHardware failed.");
return;
}
return;
}
bool ScanStateMachine::StartPnoScanHardware()
@ -1305,7 +1281,6 @@ bool ScanStateMachine::StartPnoScanHardware()
return false;
}
runningHwPnoFlag = true;
return true;
}
@ -1326,7 +1301,6 @@ void ScanStateMachine::StopPnoScanHardware()
}
runningHwPnoFlag = false;
return;
}
void ScanStateMachine::UpdatePnoScanRequest(InternalMessage *interMessage)
@ -1337,8 +1311,6 @@ void ScanStateMachine::UpdatePnoScanRequest(InternalMessage *interMessage)
WIFI_LOGE("GetPnoScanRequestInfo failed.");
return;
}
return;
}
bool ScanStateMachine::GetPnoScanRequestInfo(InternalMessage *interMessage)
@ -1418,7 +1390,6 @@ bool ScanStateMachine::GetPnoScanConfig(InternalMessage *interMessage, PnoScanCo
}
pnoScanConfig.freqs.push_back(freqs);
}
return true;
}
@ -1482,8 +1453,6 @@ void ScanStateMachine::CommonScanAfterPnoProcess()
SwitchState(pnoScanHardwareState);
return;
}
return;
}
void ScanStateMachine::CommonScanAfterPnoResult()
@ -1497,7 +1466,6 @@ void ScanStateMachine::CommonScanAfterPnoResult()
}
ReportPnoScanInfos(scanInfos);
return;
}
void ScanStateMachine::PnoScanFailedProcess()
@ -1508,8 +1476,6 @@ void ScanStateMachine::PnoScanFailedProcess()
runningSwPnoFlag = false;
ClearPnoScanConfig();
ReportStatusChange(PNO_SCAN_FAILED);
return;
}
void ScanStateMachine::ClearPnoScanConfig()
@ -1544,7 +1510,6 @@ bool ScanStateMachine::GetScanInfos(std::vector<InterScanInfo> &scanInfos)
}
WIFI_LOGI("End: QueryScanInfos.");
GetSecurityTypeAndBand(scanInfos);
return true;
}
@ -1557,7 +1522,6 @@ bool ScanStateMachine::StartNewSoftwareScan()
return false;
}
StartTimer(int(SOFTWARE_PNO_SCAN_TIMER), (runningPnoScanConfig.scanInterval) * SECOND_TO_MILLI_SECOND);
return true;
}
@ -1582,7 +1546,6 @@ bool ScanStateMachine::RepeatStartCommonScan()
runningSwPnoFlag = true;
SwitchState(pnoSwScanningState);
return true;
}
@ -1598,7 +1561,6 @@ void ScanStateMachine::StopPnoScanSoftware()
StopTimer(int(WAIT_SCAN_RESULT_TIMER));
/* Stop the PNO software scanning timer. */
StopTimer(int(SOFTWARE_PNO_SCAN_TIMER));
runningSwPnoFlag = false;
return;
}
@ -1621,8 +1583,6 @@ void ScanStateMachine::PnoScanSoftwareProcess(InternalMessage *interMessage)
WIFI_LOGE("StartPnoScanSoftware failed.");
return;
}
return;
}
void ScanStateMachine::SoftwareScanInfoProcess()
@ -1635,7 +1595,6 @@ void ScanStateMachine::SoftwareScanInfoProcess()
}
ReportPnoScanInfos(scanInfos);
return;
}
bool ScanStateMachine::InitCommonScanState()
@ -1671,7 +1630,6 @@ bool ScanStateMachine::InitCommonScanState()
WIFI_LOGE("Alloc commonScanningState failed.\n");
return false;
}
return true;
}
@ -1714,7 +1672,6 @@ bool ScanStateMachine::InitPnoScanState()
WIFI_LOGE("Alloc pnoSwScanningState failed.\n");
return false;
}
return true;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -12,21 +12,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_SCAN_STATE_MACHINE_H
#define OHOS_SCAN_STATE_MACHINE_H
#include <algorithm>
#include <atomic>
#include <map>
#include <shared_mutex>
#include <string>
#include <utility>
#include <vector>
#include "wifi_log.h"
#include "wifi_error_no.h"
#include "wifi_scan_param.h"
#include "scan_common.h"
#include "state_machine.h"
#include "wifi_msg.h"
#include "wifi_errcode.h"
#include "wifi_log.h"
#include "wifi_msg.h"
#include "wifi_scan_param.h"
namespace OHOS {
namespace Wifi {
@ -248,7 +250,7 @@ public:
};
private:
bool quitFlag; /* Scanning state machine exit flag */
std::atomic<bool> quitFlag; /* Scanning state machine exit flag */
InitState *initState; /* Scanning initial status pointer */
HardwareReady *hardwareReadyState; /* Pointer to the hardware startup completion status */
CommonScan *commonScanState; /* Pointer to the common scanning status */
@ -287,6 +289,8 @@ private:
*/
bool runningSwPnoFlag; /* Software PNO scanning is in progress. */
static std::shared_mutex lock; /* data lock */
/**
* @Description Processing of Scan Requests Received in Idle State.
*

View File

@ -274,6 +274,7 @@ void WifiScanServiceImpl::SaBasicDump(std::string& result)
#ifndef OHOS_ARCH_LITE
int32_t WifiScanServiceImpl::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
WIFI_LOGI("Enter scan dump func.");
std::vector<std::string> vecArgs;
std::transform(args.begin(), args.end(), std::back_inserter(vecArgs), [](const std::u16string &arg) {
return Str16ToStr8(arg);

View File

@ -36,7 +36,7 @@ int WifiScanStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePar
WIFI_LOGD("WifiScanStub::OnRemoteRequest,code:%{public}u", code);
if (data.ReadInterfaceToken() != GetDescriptor()) {
WIFI_LOGE("Scan stub token verification error");
WIFI_LOGE("Scan stub token verification error: %{public}d", code);
return WIFI_OPT_FAILED;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -12,16 +12,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "wifi_service_manager.h"
#include <dlfcn.h>
#include "wifi_logger.h"
#include "define.h"
#include "wifi_settings.h"
DEFINE_WIFILOG_LABEL("WifiServiceManager");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiServiceManager");
WifiServiceManager &WifiServiceManager::GetInstance()
{
static WifiServiceManager gWifiServiceManager;
@ -86,7 +86,10 @@ int WifiServiceManager::CheckPreLoadService(void)
int WifiServiceManager::LoadStaService(const std::string &dlname, bool bCreate)
{
WIFI_LOGI("WifiServiceManager::LoadStaService");
std::unique_lock<std::mutex> lock(mStaMutex);
if (mStaServiceHandle.handle != nullptr) {
WIFI_LOGE("WifiServiceManager::handle is not null: %{public}s", dlname.c_str());
return 0;
}
mStaServiceHandle.handle = dlopen(dlname.c_str(), RTLD_LAZY);
@ -110,7 +113,10 @@ int WifiServiceManager::LoadStaService(const std::string &dlname, bool bCreate)
int WifiServiceManager::LoadScanService(const std::string &dlname, bool bCreate)
{
WIFI_LOGI("WifiServiceManager::LoadScanService");
std::unique_lock<std::mutex> lock(mScanMutex);
if (mScanServiceHandle.handle != nullptr) {
WIFI_LOGE("WifiServiceManager::handle is not null: %{public}s", dlname.c_str());
return 0;
}
mScanServiceHandle.handle = dlopen(dlname.c_str(), RTLD_LAZY);
@ -135,7 +141,10 @@ int WifiServiceManager::LoadScanService(const std::string &dlname, bool bCreate)
#ifdef FEATURE_AP_SUPPORT
int WifiServiceManager::LoadApService(const std::string &dlname, bool bCreate)
{
WIFI_LOGI("WifiServiceManager::LoadApService");
std::unique_lock<std::mutex> lock(mApMutex);
if (mApServiceHandle.handle != nullptr) {
WIFI_LOGE("WifiServiceManager::handle is not null: %{public}s", dlname.c_str());
return 0;
}
mApServiceHandle.handle = dlopen(dlname.c_str(), RTLD_LAZY);
@ -165,7 +174,10 @@ int WifiServiceManager::LoadApService(const std::string &dlname, bool bCreate)
#ifdef FEATURE_P2P_SUPPORT
int WifiServiceManager::LoadP2pService(const std::string &dlname, bool bCreate)
{
WIFI_LOGI("WifiServiceManager::LoadP2pService");
std::unique_lock<std::mutex> lock(mP2pMutex);
if (mP2pServiceHandle.handle != nullptr) {
WIFI_LOGE("WifiServiceManager::handle is not null: %{public}s", dlname.c_str());
return 0;
}
mP2pServiceHandle.handle = dlopen(dlname.c_str(), RTLD_LAZY);
@ -197,7 +209,6 @@ int WifiServiceManager::CheckAndEnforceService(const std::string &name, bool bCr
return -1;
}
WIFI_LOGD("WifiServiceManager::CheckAndEnforceService get dllname: %{public}s", dlname.c_str());
std::unique_lock<std::mutex> lock(mMutex);
if (name == WIFI_SERVICE_STA) {
return LoadStaService(dlname, bCreate);
}
@ -219,28 +230,28 @@ int WifiServiceManager::CheckAndEnforceService(const std::string &name, bool bCr
IStaService *WifiServiceManager::GetStaServiceInst()
{
WIFI_LOGI("WifiServiceManager::GetStaServiceInst");
std::unique_lock<std::mutex> lock(mStaMutex);
if (mStaServiceHandle.handle == nullptr) {
WIFI_LOGE("WifiServiceManager, Sta handle is null");
return nullptr;
}
if (mStaServiceHandle.pService == nullptr) {
std::unique_lock<std::mutex> lock(mMutex);
if (mStaServiceHandle.pService == nullptr) {
mStaServiceHandle.pService = mStaServiceHandle.create();
}
mStaServiceHandle.pService = mStaServiceHandle.create();
}
return mStaServiceHandle.pService;
}
IScanService *WifiServiceManager::GetScanServiceInst()
{
WIFI_LOGI("WifiServiceManager::GetScanServiceInst");
std::unique_lock<std::mutex> lock(mScanMutex);
if (mScanServiceHandle.handle == nullptr) {
WIFI_LOGE("WifiServiceManager, Scan handle is null");
return nullptr;
}
if (mScanServiceHandle.pService == nullptr) {
std::unique_lock<std::mutex> lock(mMutex);
if (mScanServiceHandle.pService == nullptr) {
mScanServiceHandle.pService = mScanServiceHandle.create();
}
mScanServiceHandle.pService = mScanServiceHandle.create();
}
return mScanServiceHandle.pService;
}
@ -248,6 +259,8 @@ IScanService *WifiServiceManager::GetScanServiceInst()
#ifdef FEATURE_AP_SUPPORT
IApService *WifiServiceManager::GetApServiceInst(int id)
{
WIFI_LOGI("WifiServiceManager::GetApServiceInst");
std::unique_lock<std::mutex> lock(mApMutex);
if (mApServiceHandle.handle == nullptr) {
WIFI_LOGE("Get ap service instance handle is null.");
return nullptr;
@ -264,7 +277,6 @@ IApService *WifiServiceManager::GetApServiceInst(int id)
}
WIFI_LOGI("[Get] create a new ap service instance: %{public}d", id);
std::unique_lock<std::mutex> lock(mMutex);
IApService *service = mApServiceHandle.create(id);
mApServiceHandle.pService[id] = service;
return service;
@ -274,14 +286,14 @@ IApService *WifiServiceManager::GetApServiceInst(int id)
#ifdef FEATURE_P2P_SUPPORT
IP2pService *WifiServiceManager::GetP2pServiceInst()
{
WIFI_LOGI("WifiServiceManager::GetP2pServiceInst");
std::unique_lock<std::mutex> lock(mP2pMutex);
if (mP2pServiceHandle.handle == nullptr) {
WIFI_LOGE("WifiServiceManager, P2p handle is null");
return nullptr;
}
if (mP2pServiceHandle.pService == nullptr) {
std::unique_lock<std::mutex> lock(mMutex);
if (mP2pServiceHandle.pService == nullptr) {
mP2pServiceHandle.pService = mP2pServiceHandle.create();
}
mP2pServiceHandle.pService = mP2pServiceHandle.create();
}
return mP2pServiceHandle.pService;
}
@ -289,7 +301,10 @@ IP2pService *WifiServiceManager::GetP2pServiceInst()
int WifiServiceManager::UnloadStaService(bool bPreLoad)
{
WIFI_LOGI("WifiServiceManager::UnloadStaService");
std::unique_lock<std::mutex> lock(mStaMutex);
if (mStaServiceHandle.handle == nullptr) {
WIFI_LOGE("WifiServiceManager::UnloadStaService handle is null");
return 0;
}
if (mStaServiceHandle.pService != nullptr) {
@ -305,7 +320,10 @@ int WifiServiceManager::UnloadStaService(bool bPreLoad)
int WifiServiceManager::UnloadScanService(bool bPreLoad)
{
WIFI_LOGI("WifiServiceManager::UnloadScanService");
std::unique_lock<std::mutex> lock(mScanMutex);
if (mScanServiceHandle.handle == nullptr) {
WIFI_LOGE("WifiServiceManager::UnloadScanService handle is null");
return 0;
}
if (mScanServiceHandle.pService != nullptr) {
@ -322,8 +340,13 @@ int WifiServiceManager::UnloadScanService(bool bPreLoad)
#ifdef FEATURE_AP_SUPPORT
int WifiServiceManager::UnloadApService(bool bPreLoad, int id)
{
if (mApServiceHandle.handle == nullptr) {
return 0;
WIFI_LOGI("WifiServiceManager::UnloadApService id=%{public}d, max_id=%{public}d", id, AP_INSTANCE_MAX_NUM);
{
std::unique_lock<std::mutex> lock(mApMutex);
if (mApServiceHandle.handle == nullptr) {
WIFI_LOGE("WifiServiceManager::UnloadApService handle is null");
return 0;
}
}
/* Unload all ap service */
@ -332,6 +355,7 @@ int WifiServiceManager::UnloadApService(bool bPreLoad, int id)
UnloadApService(bPreLoad, i);
}
} else {
std::unique_lock<std::mutex> lock(mApMutex);
auto iter = mApServiceHandle.pService.find(id);
if (iter != mApServiceHandle.pService.end()) {
if (iter->second != nullptr) {
@ -340,10 +364,10 @@ int WifiServiceManager::UnloadApService(bool bPreLoad, int id)
}
mApServiceHandle.pService.erase(id);
}
}
if (!bPreLoad && mApServiceHandle.pService.empty()) {
dlclose(mApServiceHandle.handle);
mApServiceHandle.Clear();
if (!bPreLoad && mApServiceHandle.pService.empty()) {
dlclose(mApServiceHandle.handle);
mApServiceHandle.Clear();
}
}
return 0;
}
@ -352,7 +376,10 @@ int WifiServiceManager::UnloadApService(bool bPreLoad, int id)
#ifdef FEATURE_P2P_SUPPORT
int WifiServiceManager::UnloadP2pService(bool bPreLoad)
{
WIFI_LOGI("WifiServiceManager::UnloadP2pService");
std::unique_lock<std::mutex> lock(mP2pMutex);
if (mP2pServiceHandle.handle == nullptr) {
WIFI_LOGE("WifiServiceManager::UnloadP2pService handle is null");
return 0;
}
if (mP2pServiceHandle.pService != nullptr) {
@ -371,7 +398,6 @@ int WifiServiceManager::UnloadService(const std::string &name, int id)
{
bool bPreLoad = WifiSettings::GetInstance().IsModulePreLoad(name);
WIFI_LOGI("WifiServiceManager::UnloadService name: %{public}s", name.c_str());
std::unique_lock<std::mutex> lock(mMutex);
if (name == WIFI_SERVICE_STA) {
return UnloadStaService(bPreLoad);
}

View File

@ -199,7 +199,10 @@ private:
#endif
private:
std::mutex mMutex;
std::mutex mStaMutex;
std::mutex mScanMutex;
std::mutex mP2pMutex;
std::mutex mApMutex;
std::unordered_map<std::string, std::string> mServiceDllMap;
StaServiceHandle mStaServiceHandle;
ScanServiceHandle mScanServiceHandle;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "sta_network_check.h"
#include "if_config.h"
#include "wifi_logger.h"
DEFINE_WIFILOG_LABEL("StaNetworkCheck");
@ -35,6 +35,7 @@ StaNetworkCheck::StaNetworkCheck(NetStateHandler handle)
lastNetState = NETWORK_STATE_UNKNOWN;
isStopNetCheck = true;
isExitNetCheckThread = false;
isExited = true;
}
StaNetworkCheck::~StaNetworkCheck()
@ -73,7 +74,7 @@ bool StaNetworkCheck::HttpDetection()
constexpr int PORTAL_CONTENT_LENGTH_MIN = 4;
if (codeNum == NET_ERR_NO_CONTENT) {
WIFI_LOGE("This network is normal!");
if ((lastNetState != NETWORK_STATE_WORKING) && (isExitNetCheckThread == false) &&
if ((lastNetState.load() != NETWORK_STATE_WORKING) && (isExitNetCheckThread == false) &&
(isStopNetCheck == false)) {
netStateHandler(StaNetState::NETWORK_STATE_WORKING, "");
}
@ -120,7 +121,7 @@ bool StaNetworkCheck::HttpDetection()
}
}
WIFI_LOGE("This network can't online!");
if ((lastNetState != NETWORK_STATE_NOWORKING) && (isExitNetCheckThread == false) && (isStopNetCheck == false)) {
if ((lastNetState.load() != NETWORK_STATE_NOWORKING) && (isExitNetCheckThread == false) && (isStopNetCheck == false)) {
netStateHandler(StaNetState::NETWORK_STATE_NOWORKING, "");
}
lastNetState = NETWORK_STATE_NOWORKING;
@ -131,28 +132,28 @@ void StaNetworkCheck::RunNetCheckThreadFunc()
{
WIFI_LOGI("enter RunNetCheckThreadFunc!\n");
int timeoutMs = 3000;
isExited = false;
for (;;) {
while (isStopNetCheck && !isExitNetCheckThread) {
LOGI("waiting for signal.\n");
std::unique_lock<std::mutex> lck(mMutex);
mCondition.wait(lck);
}
if (isExitNetCheckThread) {
WIFI_LOGI("break the loop\n");
isExited = true;
break;
}
if (!HttpDetection()) {
isStopNetCheck = true;
}
if (!isExitNetCheckThread) {
std::unique_lock<std::mutex> lck(mMutex);
if (mCondition_timeout.wait_for(lck, std::chrono::milliseconds(timeoutMs)) == std::cv_status::timeout) {
LOGD("mCondition_timeout timeout.\n");
LOGI("mCondition_timeout timeout.\n");
} else {
LOGD("Wake up, break the loop.\n");
LOGI("Wake up, break the loop.\n");
isExited = true;
break;
}
}
@ -172,14 +173,12 @@ ErrCode StaNetworkCheck::InitNetCheckThread()
void StaNetworkCheck::StopNetCheckThread()
{
WIFI_LOGI("enter StopNetCheckThread!\n");
std::unique_lock<std::mutex> lck(mMutex);
isStopNetCheck = true;
}
void StaNetworkCheck::SignalNetCheckThread()
{
WIFI_LOGI("enter SignalNetCheckThread!\n");
std::unique_lock<std::mutex> lck(mMutex);
lastNetState = NETWORK_STATE_UNKNOWN;
isStopNetCheck = false;
mCondition.notify_one();
@ -187,20 +186,21 @@ void StaNetworkCheck::SignalNetCheckThread()
void StaNetworkCheck::ExitNetCheckThread()
{
{
std::unique_lock<std::mutex> lck(mMutex);
isStopNetCheck = false;
isStopNetCheck = false;
while (!isExited) {
isExitNetCheckThread = true;
mCondition.notify_one();
mCondition_timeout.notify_one();
std::this_thread::sleep_for(std::chrono::milliseconds(1)); // sleep 1 ms
}
if (pDealNetCheckThread != nullptr) {
LOGD("pDealNetCheckThread->join();");
pDealNetCheckThread->join();
if (pDealNetCheckThread->joinable()) {
LOGI("Exit net check join()");
pDealNetCheckThread->join();
}
delete pDealNetCheckThread;
pDealNetCheckThread = nullptr;
LOGD("pDealNetCheckThread = nullptr; done");
LOGI("Exit net check done");
}
}
} // namespace Wifi

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -16,17 +16,18 @@
#ifndef OHOS_WIFI_NET_CHECK_H
#define OHOS_WIFI_NET_CHECK_H
#include <unistd.h>
#include <atomic>
#include <condition_variable>
#include <cstring>
#include <fstream>
#include <vector>
#include <condition_variable>
#include <mutex>
#include <thread>
#include "wifi_log.h"
#include "sta_define.h"
#include <unistd.h>
#include <vector>
#include "http_request.h"
#include "sta_define.h"
#include "wifi_errcode.h"
#include "wifi_log.h"
#define DEFAULT_PORTAL_HTTPS_URL ""
@ -55,10 +56,16 @@ public:
*/
virtual void StopNetCheckThread();
/**
* @Description : Exit the NetCheck thread.
*
*/
virtual void ExitNetCheckThread();
private:
std::thread *pDealNetCheckThread;
NetStateHandler netStateHandler;
StaNetState lastNetState;
std::atomic<StaNetState> lastNetState;
/**
* @Description : Detect Internet ability
@ -70,18 +77,14 @@ private:
*
*/
void RunNetCheckThreadFunc();
/**
* @Description : Exit the NetCheck thread.
*
*/
void ExitNetCheckThread();
private:
std::mutex mMutex;
std::condition_variable mCondition;
std::condition_variable mCondition_timeout;
bool isStopNetCheck;
bool isExitNetCheckThread;
std::atomic<bool> isStopNetCheck;
std::atomic<bool> isExitNetCheckThread;
std::atomic<bool> isExited;
};
} // namespace Wifi
} // namespace OHOS

View File

@ -90,7 +90,6 @@ StaStateMachine::~StaStateMachine()
ParsePointer(pGetIpState);
ParsePointer(pLinkedState);
ParsePointer(pApRoamingState);
if (pDhcpService != nullptr) {
if (currentTpType == IPTYPE_IPV4) {
pDhcpService->StopDhcpClient(IF_NAME, false);
@ -415,9 +414,9 @@ void StaStateMachine::StartWifiProcess()
}
#ifndef OHOS_ARCH_LITE
WIFI_LOGI("Register netsupplier");
std::thread([this]() {
std::thread([cb = staCallback]() {
WifiNetAgent::GetInstance().RegisterNetSupplier();
WifiNetAgent::GetInstance().RegisterNetSupplierCallback(staCallback);
WifiNetAgent::GetInstance().RegisterNetSupplierCallback(cb);
}).detach();
#endif
/* Initialize Connection Information. */
@ -853,9 +852,9 @@ void StaStateMachine::DealConnectionEvent(InternalMessage *msg)
if (NetSupplierInfo != nullptr) {
NetSupplierInfo->isAvailable_ = true;
NetSupplierInfo->isRoaming_ = isRoam;
std::thread([this]() {
std::thread([netInfo = NetSupplierInfo]() {
WIFI_LOGI("On connect update net supplier info\n");
WifiNetAgent::GetInstance().UpdateNetSupplierInfo(NetSupplierInfo);
WifiNetAgent::GetInstance().UpdateNetSupplierInfo(netInfo);
}).detach();
}
#endif
@ -880,9 +879,9 @@ void StaStateMachine::DealDisconnectEvent(InternalMessage *msg)
#ifndef OHOS_ARCH_LITE
if (NetSupplierInfo != nullptr) {
NetSupplierInfo->isAvailable_ = false;
std::thread([this]() {
std::thread([netInfo = NetSupplierInfo]() {
WIFI_LOGI("On disconnect update net supplier info\n");
WifiNetAgent::GetInstance().UpdateNetSupplierInfo(NetSupplierInfo);
WifiNetAgent::GetInstance().UpdateNetSupplierInfo(netInfo);
}).detach();
}
#endif
@ -1523,9 +1522,9 @@ void StaStateMachine::DisConnectProcess()
#ifndef OHOS_ARCH_LITE
if (NetSupplierInfo != nullptr) {
NetSupplierInfo->isAvailable_ = false;
std::thread([this]() {
std::thread([netInfo = NetSupplierInfo]() {
WIFI_LOGI("Disconnect process update netsupplierinfo");
WifiNetAgent::GetInstance().UpdateNetSupplierInfo(NetSupplierInfo);
WifiNetAgent::GetInstance().UpdateNetSupplierInfo(netInfo);
}).detach();
}
#endif

View File

@ -1220,7 +1220,7 @@ void WifiSettings::SetAppPackageName(const std::string &appPackageName)
mAppPackageName = appPackageName;
}
const std::string& WifiSettings::GetAppPackageName() const
const std::string WifiSettings::GetAppPackageName() const
{
return mAppPackageName;
}
@ -1404,7 +1404,7 @@ int WifiSettings::SetP2pDeviceName(const std::string &deviceName)
return mSavedWifiP2pVendorConfig.SaveConfig();
}
const std::vector<TrustListPolicy>& WifiSettings::ReloadTrustListPolicies()
const std::vector<TrustListPolicy> WifiSettings::ReloadTrustListPolicies()
{
std::unique_lock<std::mutex> lock(mStaMutex);
mTrustListPolicies.LoadConfig();
@ -1420,7 +1420,7 @@ const std::vector<TrustListPolicy>& WifiSettings::ReloadTrustListPolicies()
return mTrustListPolicies.GetValue();
}
const MovingFreezePolicy &WifiSettings::ReloadMovingFreezePolicy()
const MovingFreezePolicy WifiSettings::ReloadMovingFreezePolicy()
{
std::unique_lock<std::mutex> lock(mStaMutex);
mMovingFreezePolicy.LoadConfig();

View File

@ -804,9 +804,9 @@ public:
/**
* @Description Get app package name.
*
* @return const std::string& - app package name.
* @return const std::string - app package name.
*/
const std::string& GetAppPackageName() const;
const std::string GetAppPackageName() const;
/**
* @Description Set freeze mode state.
@ -1047,16 +1047,16 @@ public:
/**
* @Description get trustlist policies.
*
* @return const std::vector<TrustListPolicy>& - trustlist policies.
* @return const std::vector<TrustListPolicy> - trustlist policies.
*/
const std::vector<TrustListPolicy>& ReloadTrustListPolicies();
const std::vector<TrustListPolicy> ReloadTrustListPolicies();
/**
* @Description get moving freeze state trustlist.
*
* @return const MovingFreezePolicy& - moving freeze policy.
* @return const MovingFreezePolicy - moving freeze policy.
*/
const MovingFreezePolicy& ReloadMovingFreezePolicy();
const MovingFreezePolicy ReloadMovingFreezePolicy();
/**
* @Description get bssid of connection timeout for last time.

View File

@ -31,9 +31,9 @@ const int GENE_V6_ADDR_LEN = 64; /* Generally, the prefix length cannot exceed 6
const int IP_V6_ADDR_LEN = 128;
const int MAC_ADDR_MAX_LEN = 17;
const int DHCP_LEASE_FORMAT_SIZE = 5;
const int DHCP_LEASE_MAC_ADDR_POS = 1;
const int DHCP_LEASE_IP_ADDR_POS = 2;
const int DHCP_LEASE_HOSTNAME_POS = 3;
const int DHCP_LEASE_MAC_ADDR_POS = 0;
const int DHCP_LEASE_IP_ADDR_POS = 1;
const int DHCP_LEASE_HOSTNAME_POS = 2;
DhcpdInterface::DhcpdInterface()
: mBindIpv4(Ipv4Address::INVALID_INET_ADDRESS), mBindIpv6(Ipv6Address::INVALID_INET6_ADDRESS)

View File

@ -21,7 +21,10 @@ if (defined(ohos_lite)) {
local_base_sources = [
"common/wifi_hal_common_func.c",
"hdi/wifi_hdi_ap_instance.c",
"hdi/src/wifi_hdi_ap_impl.c",
"hdi/src/wifi_hdi_p2p_impl.c",
"hdi/src/wifi_hdi_proxy.c",
"hdi/src/wifi_hdi_sta_impl.c",
"main.c",
"wifi_hal_adapter.c",
"wifi_hal_ap_interface.c",
@ -56,7 +59,7 @@ local_base_include_dirs = [
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_p2p_hal",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi/inc",
]
if (defined(ohos_lite)) {
@ -99,28 +102,33 @@ if (defined(ohos_lite)) {
"//third_party/wpa_supplicant/wpa_supplicant-2.9_standard/src/",
"//third_party/bounds_checking_function/include/",
"//drivers/peripheral/wlan/interfaces/include/",
"//drivers/peripheral/wlan/client/include/",
]
deps = [
"$WIFI_ROOT_DIR/services/wifi_standard/ipc_framework/cRPC:crpc_server",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/etc/init:etc",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//drivers/peripheral/wlan/hal:wifi_hal",
"//third_party/wpa_supplicant/wpa_supplicant-2.9_standard:wpa_client",
]
external_deps = [ "c_utils:utils" ]
cflags_cc = [ "-fno-rtti" ]
defines = [
"AP_INTF=\"$wifi_feature_with_ap_intf\"",
"AP_NUM=$wifi_feature_with_ap_num",
]
if (wifi_feature_is_hdi_supported) {
defines += [ "HDI_INTERFACE_SUPPORT" ]
external_deps += [ "drivers_interface_wlan:libwlan_proxy_1.0" ]
}
if (product_name == "rk3568") {
defines += [ "NON_SEPERATE_P2P" ]
}
cflags_cc = [ "-fno-rtti" ]
part_name = "wifi"
subsystem_name = "communication"
}

View File

@ -13,21 +13,17 @@
* limitations under the License.
*/
#ifndef OHOS_HDI_INSTANCE_H
#define OHOS_HDI_INSTANCE_H
#ifndef OHOS_HDI_AP_IMPL_H
#define OHOS_HDI_AP_IMPL_H
#include "wifi_hal.h"
#include "wifi_hal_ap_feature.h"
#include "wifi_hal_define.h"
#ifdef __cplusplus
extern "C" {
#endif
WifiErrorNo HdiGetAp(struct IWiFi **wifi, struct IWiFiAp **apFeature);
WifiErrorNo HdiReleaseAp(struct IWiFi *wifi, struct IWiFiAp *apFeature);
WifiErrorNo GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t *size, int id);
WifiErrorNo WifiSetPowerModel(const int mode, int id);
WifiErrorNo WifiGetPowerModel(int* mode, int id);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,27 @@
/*
* Copyright (C) 2022 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_HDI_P2P_IMPL_H
#define OHOS_HDI_P2P_IMPL_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,81 @@
/*
* Copyright (C) 2022 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_HDI_PROXY_H
#define OHOS_HDI_PROXY_H
#include "wifi_hal_define.h"
#include "v1_0/iwlan_interface.h"
#include "wifi_hal_base_feature.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct WifiHdiProxy {
struct IWlanInterface* wlanObj;
struct HdfFeatureInfo* feature;
} WifiHdiProxy;
#ifndef CHECK_HDI_PROXY_AND_RETURN
#define CHECK_HDI_PROXY_AND_RETURN(proxy, retValue) \
if (proxy.wlanObj == NULL || proxy.feature == NULL) { \
LOGE("Hdi proxy: %{public}s in %{public}s is NULL!", #proxy, __func__); \
return retValue; \
}
#endif
/**
* @Description Create a channel between the HAL and the driver.
*
* @return WifiErrorNo - operation result
*/
WifiErrorNo HdiStart();
/**
* @Description Stop the created channel.
*
* @return WifiErrorNo - operation result
*/
WifiErrorNo HdiStop();
/**
* @Description Create the WiFi object.
*
* @return WifiErrorNo - operation result
*/
struct IWlanInterface* GetWlanInterface();
/**
* @Description Get the hdi proxy by wlan type.
*
* @param wlanType - wlan type
* @return WifiHdiProxy - interface proxy object
*/
WifiHdiProxy GetHdiProxy(const int32_t wlanType);
/**
* @Description Release hdi proxy by wlan type.
* This interface will be automatic called in the hid stop function,
* So you can use it without releasing.
*
* @param wlanType - wlan type
* @return WifiErrorNo - operation result
*/
WifiErrorNo ReleaseHdiProxy(const int32_t wlanType);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,27 @@
/*
* Copyright (C) 2022 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_HDI_STA_IMPL_H
#define OHOS_HDI_STA_IMPL_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,78 @@
/*
* Copyright (C) 2022 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 HDI_INTERFACE_SUPPORT
#include "wifi_hdi_ap_impl.h"
#include "wifi_hdi_proxy.h"
#include "wifi_log.h"
#undef LOG_TAG
#define LOG_TAG "WifiHdiApImpl"
#define NUMS_BAND 2
static int32_t ConvertToNl80211Band(int32_t band)
{
return (band > 0 && band <= NUMS_BAND) ? (band - 1) : band;
}
WifiErrorNo GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t *size, int id)
{
if (frequencies == NULL || size == NULL) {
LOGE("%{public}s frequencies or size is null.", __func__);
return WIFI_HAL_FAILED;
}
WifiHdiProxy proxy = GetHdiProxy(PROTOCOL_80211_IFTYPE_AP);
CHECK_HDI_PROXY_AND_RETURN(proxy, WIFI_HAL_FAILED);
struct HdfWifiInfo wifiInfo;
wifiInfo.band = ConvertToNl80211Band(band);
wifiInfo.size = *size;
uint32_t count = 0xff;
LOGI("Get freqs parameters [band: %{public}d, alloc size: %{public}d]", wifiInfo.band, wifiInfo.size);
int32_t ret = proxy.wlanObj->GetFreqsWithBand(proxy.wlanObj, proxy.feature, &wifiInfo, frequencies, &count);
LOGI("Get freqs result, actual size: %{public}d", count);
*size = count;
if (ret != 0) {
LOGE("Get freqs with band failed: %{public}d", ret);
}
return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED;
}
WifiErrorNo WifiSetPowerModel(const int mode, int id)
{
LOGI("Instance %{public}d WifiSetPowerModel: %{public}d", id, mode);
WifiHdiProxy proxy = GetHdiProxy(PROTOCOL_80211_IFTYPE_AP);
CHECK_HDI_PROXY_AND_RETURN(proxy, WIFI_HAL_FAILED);
int32_t ret = proxy.wlanObj->SetPowerMode(proxy.wlanObj, proxy.feature, mode);
if (ret != 0) {
LOGE("Set power mode failed: %{public}d", ret);
}
return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED;
}
WifiErrorNo WifiGetPowerModel(int* mode, int id)
{
LOGI("Instance %{public}d WifiGetPowerModel", id);
WifiHdiProxy proxy = GetHdiProxy(PROTOCOL_80211_IFTYPE_AP);
CHECK_HDI_PROXY_AND_RETURN(proxy, WIFI_HAL_FAILED);
int32_t ret = proxy.wlanObj->GetPowerMode(proxy.wlanObj, proxy.feature, (uint8_t *)mode);
if (ret != 0) {
LOGE("Get power mode failed: %{public}d", ret);
}
LOGI("Get power mode: %{public}d", *mode);
return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED;
}
#endif

View File

@ -0,0 +1,26 @@
/*
* Copyright (C) 2022 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 HDI_INTERFACE_SUPPORT
#include "wifi_hdi_p2p_impl.h"
#include "wifi_hdi_proxy.h"
#include "wifi_log.h"
#undef LOG_TAG
#define LOG_TAG "WifiHdiP2pImpl"
#endif

View File

@ -0,0 +1,224 @@
/*
* Copyright (C) 2022 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 HDI_INTERFACE_SUPPORT
#include "wifi_hdi_proxy.h"
#include <stdlib.h>
#include <pthread.h>
#include "wifi_log.h"
#undef LOG_TAG
#define LOG_TAG "WifiHdiProxy"
#define MAX_FEATURE_NUMBER 16
const char *WLAN_SERVICE_NAME = "wlan_interface_service"; // Move the define to HDF module
static pthread_mutex_t g_mutex;
static unsigned int g_wlanRefCount = 0;
static struct IWlanInterface *g_wlanObj = NULL;
static struct HdfFeatureInfo* g_featureArray[MAX_FEATURE_NUMBER] = {NULL};
static WifiErrorNo ReleaseFeatureInner(const int32_t wlanType)
{
WifiErrorNo ret = WIFI_HAL_SUCCESS;
if (g_wlanObj == NULL) {
LOGE("%{public}s g_wlanObj is null", __func__);
return WIFI_HAL_FAILED;
}
for (int i = 0; i != MAX_FEATURE_NUMBER; ++i) {
if (g_featureArray[i] == NULL || g_featureArray[i]->type != wlanType) {
continue;
}
LOGI("%{public}s destory feature begin.", __func__);
ret = g_wlanObj->DestroyFeature(g_wlanObj, g_featureArray[i]);
if (ret != HDF_SUCCESS) {
LOGE("Destroy feature %{public}d failed: %{public}d", g_featureArray[i]->type, ret);
}
LOGI("%{public}s destory feature end.", __func__);
free(g_featureArray[i]);
g_featureArray[i] = NULL;
break;
}
return ret;
}
static struct HdfFeatureInfo* GetFeatureInner(const int32_t wlanType)
{
struct HdfFeatureInfo *feature = NULL;
if (g_wlanObj == NULL) {
LOGE("%{public}s g_wlanObj is null!", __func__);
return NULL;
}
for (int i = 0; i != MAX_FEATURE_NUMBER; ++i) {
if (g_featureArray[i] == NULL) {
continue;
}
if (g_featureArray[i]->type == wlanType) {
LOGI("%{public}s get an exist feature.", __func__);
feature = g_featureArray[i];
return feature;
}
}
/* allocate 1 struct */
feature = (struct HdfFeatureInfo *)calloc(1, sizeof(struct HdfFeatureInfo));
if (feature == NULL) {
LOGE("%{public}s calloc failed!", __func__);
return NULL;
}
LOGI("Create feature type: %{public}d", wlanType);
int32_t ret = g_wlanObj->CreateFeature(g_wlanObj, wlanType, feature);
if (ret != HDF_SUCCESS) {
LOGE("CreateFeature %{public}d failed: %{public}d", wlanType, ret);
goto FAILURE;
}
LOGI("Create feature end, ifname: %{public}s", feature->ifName);
bool isAdd = false;
for (int i = 0; i != MAX_FEATURE_NUMBER; ++i) {
if (g_featureArray[i] == NULL) {
g_featureArray[i] = feature;
isAdd = true;
break;
}
}
if (!isAdd) {
LOGE("%{public}s g_featureArray is full!", __func__);
goto FAILURE;
}
return feature;
FAILURE:
if (feature != NULL) {
free(feature);
}
return NULL;
}
static void ReleaseAllFeatures()
{
if (g_wlanObj == NULL) {
return;
}
WifiErrorNo ret = WIFI_HAL_SUCCESS;
for (int i = 0; i != MAX_FEATURE_NUMBER; ++i) {
if (g_featureArray[i] == NULL) {
continue;
}
LOGI("%{public}s destory feature[all] begin.", __func__);
ret = g_wlanObj->DestroyFeature(g_wlanObj, g_featureArray[i]);
if (ret != HDF_SUCCESS) {
LOGE("Destroy feature %{public}d failed: %{public}d", g_featureArray[i]->type, ret);
}
LOGI("%{public}s destory feature[all] end.", __func__);
free(g_featureArray[i]);
g_featureArray[i] = NULL;
}
}
WifiErrorNo HdiStart()
{
LOGI("%{public}s start...", __func__);
pthread_mutex_lock(&g_mutex);
if (g_wlanRefCount != 0) {
++g_wlanRefCount;
pthread_mutex_unlock(&g_mutex);
LOGI("%{public}s wlan ref count: %d", __func__, g_wlanRefCount);
return WIFI_HAL_SUCCESS;
}
g_wlanObj = IWlanInterfaceGetInstance(WLAN_SERVICE_NAME, false);
if (g_wlanObj == NULL) {
pthread_mutex_unlock(&g_mutex);
LOGE("%{public}s WlanInterfaceGetInstance failed", __func__);
return WIFI_HAL_FAILED;
}
int32_t ret = g_wlanObj->Start(g_wlanObj);
if (ret != HDF_SUCCESS) {
LOGE("%{public}s Start failed: %{public}d", __func__, ret);
IWlanInterfaceReleaseInstance(WLAN_SERVICE_NAME, g_wlanObj, false);
g_wlanObj = NULL;
pthread_mutex_unlock(&g_mutex);
return WIFI_HAL_FAILED;
}
++g_wlanRefCount;
pthread_mutex_unlock(&g_mutex);
LOGI("%{public}s is started", __func__);
return WIFI_HAL_SUCCESS;
}
WifiErrorNo HdiStop()
{
LOGI("%{public}s stop...", __func__);
pthread_mutex_lock(&g_mutex);
if (g_wlanObj == NULL || g_wlanRefCount == 0) {
pthread_mutex_unlock(&g_mutex);
LOGE("%{public}s g_wlanObj is NULL or ref count is 0", __func__);
return WIFI_HAL_FAILED;
}
const unsigned int ONE_REF_COUNT = 1;
if (g_wlanRefCount > ONE_REF_COUNT) {
--g_wlanRefCount;
pthread_mutex_unlock(&g_mutex);
LOGI("%{public}s wlan ref count: %d", __func__, g_wlanRefCount);
return WIFI_HAL_SUCCESS;
}
ReleaseAllFeatures();
int32_t ret = g_wlanObj->Stop(g_wlanObj);
if (ret != HDF_SUCCESS) {
LOGE("%{public}s Stop failed: %{public}d", __func__, ret);
}
IWlanInterfaceReleaseInstance(WLAN_SERVICE_NAME, g_wlanObj, false);
--g_wlanRefCount;
g_wlanObj = NULL;
pthread_mutex_unlock(&g_mutex);
LOGI("%{public}s is stopped", __func__);
return (ret == HDF_SUCCESS) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED;
}
struct IWlanInterface* GetWlanInterface()
{
struct IWlanInterface *wlanObj = NULL;
pthread_mutex_lock(&g_mutex);
wlanObj = g_wlanObj;
pthread_mutex_unlock(&g_mutex);
return wlanObj;
}
WifiHdiProxy GetHdiProxy(const int32_t wlanType)
{
WifiHdiProxy proxy = {.wlanObj = NULL, .feature = NULL};
pthread_mutex_lock(&g_mutex);
struct HdfFeatureInfo* feature = GetFeatureInner(wlanType);
if (feature == NULL) {
pthread_mutex_unlock(&g_mutex);
LOGE("%{public}s GetFeature failed!", __func__);
return proxy;
}
proxy.wlanObj = g_wlanObj;
proxy.feature = feature;
pthread_mutex_unlock(&g_mutex);
return proxy;
}
WifiErrorNo ReleaseHdiProxy(const int32_t wlanType)
{
WifiErrorNo ret = WIFI_HAL_FAILED;
pthread_mutex_lock(&g_mutex);
ret = ReleaseFeatureInner(wlanType);
pthread_mutex_unlock(&g_mutex);
return ret;
}
#endif

View File

@ -0,0 +1,26 @@
/*
* Copyright (C) 2022 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 HDI_INTERFACE_SUPPORT
#include "wifi_hdi_sta_impl.h"
#include "wifi_hdi_proxy.h"
#include "wifi_log.h"
#undef LOG_TAG
#define LOG_TAG "WifiHdiStaImpl"
#endif

View File

@ -1,69 +0,0 @@
/*
* Copyright (C) 2022 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_ARCH_LITE
#include "wifi_hdi_ap_instance.h"
#include "wifi_hal_define.h"
#include "wifi_log.h"
#undef LOG_TAG
#define LOG_TAG "WifiHdiInstance"
WifiErrorNo HdiGetAp(struct IWiFi **wifi, struct IWiFiAp **apFeature)
{
if (wifi == NULL || apFeature == NULL) {
return WIFI_HAL_FAILED;
}
LOGD("HdiGetAp");
int32_t ret;
ret = WifiConstruct(wifi);
if (ret != 0 || *wifi == NULL) {
LOGE("%{public}s WifiConstruct failed", __func__);
return WIFI_HAL_FAILED;
}
ret = (*wifi)->start(*wifi);
if (ret != 0) {
(void)WifiDestruct(wifi);
LOGE("%{public}s start failed", __func__);
return WIFI_HAL_FAILED;
}
ret = (*wifi)->createFeature(PROTOCOL_80211_IFTYPE_AP, (struct IWiFiBaseFeature **)apFeature);
if (ret != 0 || *apFeature == NULL) {
(void)(*wifi)->stop(*wifi);
(void)WifiDestruct(wifi);
LOGE("%{public}s createFeature failed", __func__);
return WIFI_HAL_FAILED;
}
return WIFI_HAL_SUCCESS;
}
WifiErrorNo HdiReleaseAp(struct IWiFi *wifi, struct IWiFiAp *apFeature)
{
if (wifi == NULL) {
return WIFI_HAL_FAILED;
}
LOGD("HdiReleaseAp");
if (apFeature != NULL) {
(void)wifi->destroyFeature((struct IWiFiBaseFeature *)apFeature);
}
(void)wifi->stop(wifi);
(void)WifiDestruct(&wifi);
return WIFI_HAL_SUCCESS;
}
#endif

View File

@ -16,15 +16,12 @@
#include "wifi_hal_ap_interface.h"
#include <errno.h>
#include <securec.h>
#ifdef OHOS_ARCH_LITE
#include "wifi_hal_adapter.h"
#else
#include "wifi_hal.h"
#include "wifi_hal_adapter.h"
#include "wifi_hdi_ap_instance.h"
#endif
#include "wifi_hal_module_manage.h"
#include "wifi_hal_common_func.h"
#ifdef HDI_INTERFACE_SUPPORT
#include "wifi_hdi_proxy.h"
#endif
#include "wifi_log.h"
#include "wifi_wpa_hal.h"
#include "wifi_hostapd_hal.h"
@ -32,7 +29,6 @@
#undef LOG_TAG
#define LOG_TAG "WifiHalApInterface"
#define NUMS_BAND 2
#define DISABLE_AP_WAIT_MS 50000
#define ABLE_AP_WAIT_MS 50000
#define WIFI_MULTI_CMD_MAX_LEN 1024
@ -47,18 +43,15 @@ WifiErrorNo StartSoftAp(int id)
LOGE("hostapd start failed!");
return WIFI_HAL_OPEN_HOSTAPD_FAILED;
}
if (StartHostapdHal(id) != WIFI_HAL_SUCCESS) {
LOGE("hostapd init failed!");
return WIFI_HAL_HOSTAPD_NOT_INIT;
}
WifiHostapdHalDevice *hostapdHalDevice = GetWifiHostapdDev(id);
if (hostapdHalDevice == NULL) {
LOGE("hostapdHalDevice is NULL!");
return WIFI_HAL_HOSTAPD_NOT_INIT;
}
int ret = sprintf_s(ifaceName, IFCAE_NAME_LEN, AP_INTF"%d", id);
if (ret == -1) {
LOGE("StartSoftAp failed! ret=%{public}d", ret);
@ -71,7 +64,12 @@ WifiErrorNo StartSoftAp(int id)
return WIFI_HAL_FAILED;
}
}
#ifdef HDI_INTERFACE_SUPPORT
if (HdiStart() != WIFI_HAL_SUCCESS) {
LOGE("[Ap] Start hdi failed!");
return WIFI_HAL_FAILED;
}
#endif
LOGI("AP start successfully, id:%{public}d!", id);
return WIFI_HAL_SUCCESS;
}
@ -127,6 +125,12 @@ WifiErrorNo StartHostapdHal(int id)
WifiErrorNo StopSoftAp(int id)
{
#ifdef HDI_INTERFACE_SUPPORT
if (HdiStop() != WIFI_HAL_SUCCESS) {
LOGE("[Ap] Stop hdi failed!");
return WIFI_HAL_FAILED;
}
#endif
WifiHostapdHalDevice *hostapdHalDevice = GetWifiHostapdDev(id);
if (hostapdHalDevice != NULL) {
int ret = hostapdHalDevice->disableAp(id);
@ -136,18 +140,15 @@ WifiErrorNo StopSoftAp(int id)
} else {
LOGE("cant not get hostapd dev");
}
if (StopHostapd() != WIFI_HAL_SUCCESS) {
LOGE("hostapd stop failed!");
return WIFI_HAL_FAILED;
}
if (StopHostapdHal(id) != WIFI_HAL_SUCCESS) {
LOGE("hostapd_hal stop failed!");
return WIFI_HAL_FAILED;
}
LOGD("AP stop successfully!");
LOGI("AP stop successfully!");
return WIFI_HAL_SUCCESS;
}
@ -314,79 +315,24 @@ WifiErrorNo DisassociateSta(const unsigned char *mac, int lenMac, int id)
return WIFI_HAL_SUCCESS;
}
static int32_t ConvertToNl80211Band(int32_t band)
{
return (band > 0 && band <= NUMS_BAND) ? (band - 1) : band;
}
WifiErrorNo GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t *size, int id)
{
if (frequencies == NULL || size == NULL) {
LOGE("%{public}s frequencies or size is null.", __func__);
return WIFI_HAL_FAILED;
}
#ifdef OHOS_ARCH_LITE
LOGE("%{public}s func is not support!", __func__);
return WIFI_HAL_FAILED;
#else
uint32_t count = 0;
struct IWiFi *wifi = NULL;
struct IWiFiAp *apFeature = NULL;
WifiErrorNo ret = HdiGetAp(&wifi, &apFeature);
if (ret != WIFI_HAL_SUCCESS) {
return WIFI_HAL_FAILED;
}
ret = apFeature->baseFeature.getValidFreqsWithBand((struct IWiFiBaseFeature *)apFeature,
ConvertToNl80211Band(band), frequencies, *size, &count);
*size = count;
if (ret != 0) {
LOGE("%{public}s failed", __func__);
}
HdiReleaseAp(wifi, apFeature);
return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED;
#endif
}
WifiErrorNo WifiSetPowerModel(const int mode, int id)
{
#ifdef OHOS_ARCH_LITE
LOGE("%{public}s func is not support!", __func__);
return WIFI_HAL_FAILED;
#else
LOGD("Instance %{public}d WifiSetPowerModel: %{public}d", id, mode);
struct IWiFi *wifi = NULL;
struct IWiFiAp *apFeature = NULL;
WifiErrorNo ret = HdiGetAp(&wifi, &apFeature);
if (ret != WIFI_HAL_SUCCESS) {
return WIFI_HAL_FAILED;
}
ret = wifi->setPowerMode(apFeature->baseFeature.ifName, mode);
if (ret != 0) {
LOGE("%{public}s failed", __func__);
}
HdiReleaseAp(wifi, apFeature);
return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED;
#endif
}
WifiErrorNo WifiGetPowerModel(int* mode, int id)
{
#ifdef OHOS_ARCH_LITE
LOGE("%{public}s func is not support!", __func__);
return WIFI_HAL_FAILED;
#else
LOGD("Instance %{public}d WifiGetPowerModel", id);
struct IWiFi *wifi = NULL;
struct IWiFiAp *apFeature = NULL;
WifiErrorNo ret = HdiGetAp(&wifi, &apFeature);
if (ret != WIFI_HAL_SUCCESS) {
return WIFI_HAL_FAILED;
}
ret = wifi->getPowerMode(apFeature->baseFeature.ifName, (uint8_t *)mode);
if (ret != 0) {
LOGE("%{public}s failed", __func__);
}
LOGD("getPowerModel: %{public}d", *mode);
HdiReleaseAp(wifi, apFeature);
return (ret == 0) ? WIFI_HAL_SUCCESS : WIFI_HAL_FAILED;
#endif
}

View File

@ -144,7 +144,7 @@ WifiErrorNo DisassociateSta(const unsigned char *mac, int lenMac, int id);
* @param id - ap id
* @return WifiErrorNo
*/
WifiErrorNo GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t *size, int id);
WifiErrorNo WEAK_FUNC GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t *size, int id);
/**
* @Description Set the power mode.
@ -153,7 +153,7 @@ WifiErrorNo GetValidFrequenciesForBand(int32_t band, int *frequencies, int32_t *
* @param id - ap id
* @return WifiErrorNo
*/
WifiErrorNo WifiSetPowerModel(const int mode, int id);
WifiErrorNo WEAK_FUNC WifiSetPowerModel(const int mode, int id);
/**
* @Description Get the power mode.
@ -162,7 +162,7 @@ WifiErrorNo WifiSetPowerModel(const int mode, int id);
* @param id - ap id
* @return WifiErrorNo
*/
WifiErrorNo WifiGetPowerModel(int* mode, int id);
WifiErrorNo WEAK_FUNC WifiGetPowerModel(int* mode, int id);
#ifdef __cplusplus
}
#endif

View File

@ -16,6 +16,7 @@
#include "wifi_hal_crpc_ap.h"
#include <securec.h>
#include "serial.h"
#include "wifi_hdi_ap_impl.h"
#include "wifi_hal_ap_interface.h"
#include "wifi_hal_define.h"

View File

@ -41,6 +41,8 @@ extern "C" {
#define WIFI_HAL_FALSE 0
#define WIFI_HAL_TRUE 1
#define WEAK_FUNC __attribute__((weak))
typedef enum WifiErrorNo {
WIFI_HAL_SUCCESS = 0, /* Success. */
WIFI_HAL_FAILED = 1, /* Failed. */

View File

@ -17,9 +17,12 @@
#include "securec.h"
#include "wifi_hal_adapter.h"
#include "wifi_hal_module_manage.h"
#ifdef HDI_INTERFACE_SUPPORT
#include "wifi_hdi_proxy.h"
#endif
#include "wifi_log.h"
#include "wifi_wpa_hal.h"
#include "wifi_supplicant_hal.h"
#include "wifi_wpa_hal.h"
#undef LOG_TAG
#define LOG_TAG "WifiHalStaInterface"
@ -109,7 +112,7 @@ WifiErrorNo Start(void)
LOGE("wpa_supplicant start failed!");
return WIFI_HAL_OPEN_SUPPLICANT_FAILED;
}
LOGD("wpa_supplicant start successfully!");
LOGI("wpa_supplicant start successfully!");
if (AddWpaIface(0) != WIFI_HAL_SUCCESS) {
LOGE("Failed to add wpa interface!");
@ -122,7 +125,12 @@ WifiErrorNo Start(void)
StopWpaAndWpaHal(0);
return WIFI_HAL_CONN_SUPPLICANT_FAILED;
}
LOGD("SupplicantHal connect wpa_supplicant successfully!");
#ifdef HDI_INTERFACE_SUPPORT
if (HdiStart() != WIFI_HAL_SUCCESS) {
LOGE("[STA] Start hdi failed!");
return WIFI_HAL_FAILED;
}
#endif
LOGI("Start wifi successfully");
return WIFI_HAL_SUCCESS;
}
@ -130,18 +138,30 @@ WifiErrorNo Start(void)
WifiErrorNo Stop(void)
{
LOGI("Ready to Stop wifi");
WifiErrorNo err = StopWpaAndWpaHal(0);
if (err == WIFI_HAL_FAILED) {
LOGD("Wifi stop failed!");
#ifdef HDI_INTERFACE_SUPPORT
if (HdiStop() != WIFI_HAL_SUCCESS) {
LOGE("[Ap] Stop hdi failed!");
return WIFI_HAL_FAILED;
}
LOGD("Wifi stop successfully!");
#endif
WifiErrorNo err = StopWpaAndWpaHal(0);
if (err == WIFI_HAL_FAILED) {
LOGE("Wifi stop failed!");
return WIFI_HAL_FAILED;
}
LOGI("Wifi stop successfully!");
return WIFI_HAL_SUCCESS;
}
WifiErrorNo ForceStop(void)
{
LOGI("Ready force Stop wifi");
#ifdef HDI_INTERFACE_SUPPORT
if (HdiStop() != WIFI_HAL_SUCCESS) {
LOGE("[Ap] Stop hdi failed!");
return WIFI_HAL_FAILED;
}
#endif
WifiWpaStaInterface *p = TraversalWifiStaInterface();
while (p != NULL) {
StopWpaAndWpaHal(p->staNo);

View File

@ -36,7 +36,6 @@ ohos_unittest("idl_client_unittest") {
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_sta_iface.c",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_supplicant_iface.c",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_ap_hal_interface.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_base_hal_interface.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_chip_hal_interface.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_client.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_inner_interface.cpp",
@ -45,7 +44,6 @@ ohos_unittest("idl_client_unittest") {
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_supplicant_hal_interface.cpp",
"idl_client_test_main.cpp",
"wifi_ap_hal_interface_test.cpp",
"wifi_base_hal_interface_test.cpp",
"wifi_chip_hal_interface_test.cpp",
"wifi_idl_client_test.cpp",
"wifi_idl_interface_test.cpp",

View File

@ -57,7 +57,6 @@ ohos_unittest("manager_unittest") {
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_aware",
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface",
@ -112,9 +111,8 @@ ohos_unittest("manager_unittest") {
]
configs = [ ":module_private_config" ]
if (wifi_feature_with_auth_disable) {
defines += [ "PERMISSION_ALWAYS_GRANT" ]
}
# Do not modify the permission configuration of the unit test
defines += [ "PERMISSION_ALWAYS_GRANT" ]
part_name = "wifi"
subsystem_name = "communication"

View File

@ -43,7 +43,7 @@ HWTEST_F(WifiAuthCenterTest, ChangePermission_SUCCESS, TestSize.Level1)
for (int i = 0; i < ARRAY_PERMISSION; i++) {
permissions[g_wifiPermissions[i].name] = num[i];
}
EXPECT_EQ(0, WifiAuthCenter::GetInstance().ChangePermission(permissions, pid, uid));
EXPECT_EQ(PERMISSION_GRANTED, WifiAuthCenter::GetInstance().ChangePermission(permissions, pid, uid));
}
HWTEST_F(WifiAuthCenterTest, CheckChangePermission_GRANTED, TestSize.Level1)

View File

@ -38,7 +38,6 @@ HWTEST_F(WifiManagerServiceTest, StaCloseResTest, TestSize.Level1)
ASSERT_TRUE(cbk.OnStaOpenRes != nullptr);
ASSERT_TRUE(cbk.OnStaCloseRes != nullptr);
cbk.OnStaOpenRes(OperateResState::OPEN_WIFI_SUCCEED);
cbk.OnStaCloseRes(OperateResState::CLOSE_WIFI_FAILED);
cbk.OnStaCloseRes(OperateResState::CLOSE_WIFI_CLOSING);
cbk.OnStaCloseRes(OperateResState::CLOSE_WIFI_SUCCEED);
WifiSettings::GetInstance().SetAirplaneModeState(1);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_WIFI_MANAGER_SERVICE_TEST_H
#define OHOS_WIFI_MANAGER_SERVICE_TEST_H
@ -28,7 +29,6 @@ public:
}
static void TearDownTestCase()
{
WifiManager::GetInstance().Exit();
}
virtual void SetUp()
{}

View File

@ -31,7 +31,7 @@ public:
virtual void SetScreenState(const int &state) = 0;
virtual int GetScreenState() const = 0;
virtual ScanMode GetAppRunningState() const = 0;
virtual const std::string& GetAppPackageName() const = 0;
virtual const std::string GetAppPackageName() const = 0;
virtual int GetFreezeModeState() const = 0;
virtual int GetNoChargerPlugModeState() const = 0;
virtual void SetSupportHwPnoFlag(bool supportHwPnoFlag) = 0;
@ -40,8 +40,8 @@ public:
virtual int GetMinRssi5Ghz() = 0;
virtual bool GetWhetherToAllowNetworkSwitchover() = 0;
virtual int GetDeviceConfig(std::vector<WifiDeviceConfig> &results) = 0;
virtual const std::vector<TrustListPolicy>& ReloadTrustListPolicies() = 0;
virtual const MovingFreezePolicy& ReloadMovingFreezePolicy() = 0;
virtual const std::vector<TrustListPolicy> ReloadTrustListPolicies() = 0;
virtual const MovingFreezePolicy ReloadMovingFreezePolicy() = 0;
virtual int GetThermalLevel() const = 0;
};
@ -56,7 +56,7 @@ public:
MOCK_METHOD1(SetScreenState, void(const int &state));
MOCK_CONST_METHOD0(GetScreenState, int());
MOCK_CONST_METHOD0(GetAppRunningState, ScanMode());
MOCK_CONST_METHOD0(GetAppPackageName, const std::string&());
MOCK_CONST_METHOD0(GetAppPackageName, const std::string());
MOCK_CONST_METHOD0(GetFreezeModeState, int());
MOCK_CONST_METHOD0(GetNoChargerPlugModeState, int());
MOCK_METHOD1(SetSupportHwPnoFlag, void(bool supportHwPnoFlag));
@ -65,8 +65,8 @@ public:
MOCK_METHOD0(GetMinRssi5Ghz, int());
MOCK_METHOD0(GetWhetherToAllowNetworkSwitchover, bool());
MOCK_METHOD1(GetDeviceConfig, int(std::vector<WifiDeviceConfig> &results));
MOCK_METHOD0(ReloadTrustListPolicies, const std::vector<TrustListPolicy>&());
MOCK_METHOD0(ReloadMovingFreezePolicy, const MovingFreezePolicy&());
MOCK_METHOD0(ReloadTrustListPolicies, const std::vector<TrustListPolicy>());
MOCK_METHOD0(ReloadMovingFreezePolicy, const MovingFreezePolicy());
MOCK_CONST_METHOD0(GetThermalLevel, int());
};
} // namespace Wifi

View File

@ -29,7 +29,6 @@ using ::testing::SetArgReferee;
using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
using ::testing::ReturnRef;
namespace OHOS {
namespace Wifi {
@ -75,11 +74,11 @@ HWTEST_F(ScanInterfaceTest, InitTest, TestSize.Level1)
EXPECT_CALL(WifiSupplicantHalInterface::GetInstance(), UnRegisterSupplicantEventCallback()).Times(AtLeast(1));
EXPECT_CALL(WifiSettings::GetInstance(), GetWhetherToAllowNetworkSwitchover()).Times(AtLeast(0));
EXPECT_CALL(WifiSettings::GetInstance(), GetDeviceConfig(_)).Times(AtLeast(0));
EXPECT_CALL(WifiSettings::GetInstance(), GetAppPackageName()).WillRepeatedly(ReturnRef(""));
EXPECT_CALL(WifiSettings::GetInstance(), GetAppPackageName()).WillRepeatedly(Return(""));
EXPECT_CALL(WifiSettings::GetInstance(), ReloadTrustListPolicies())
.WillRepeatedly(ReturnRef(refVecTrustList));
.WillRepeatedly(Return(refVecTrustList));
EXPECT_CALL(WifiSettings::GetInstance(), ReloadMovingFreezePolicy())
.WillRepeatedly(ReturnRef(defaultValue));
.WillRepeatedly(Return(defaultValue));
pScanInterface->Init();
}

View File

@ -25,7 +25,6 @@ using ::testing::AtLeast;
using ::testing::DoAll;
using ::testing::Eq;
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::SetArgReferee;
using ::testing::StrEq;
using ::testing::TypedEq;
@ -67,7 +66,7 @@ public:
EXPECT_CALL(WifiSettings::GetInstance(), GetWhetherToAllowNetworkSwitchover()).Times(AtLeast(0));
EXPECT_CALL(WifiSettings::GetInstance(), GetDeviceConfig(_)).Times(AtLeast(0));
EXPECT_CALL(WifiSettings::GetInstance(), ReloadMovingFreezePolicy())
.WillRepeatedly(ReturnRef(defaultValue));
.WillRepeatedly(Return(defaultValue));
EXPECT_EQ(pScanService->InitScanService(WifiManager::GetInstance().GetScanCallback()), true);
}
@ -84,7 +83,7 @@ public:
EXPECT_CALL(WifiSettings::GetInstance(), GetWhetherToAllowNetworkSwitchover()).Times(AtLeast(0));
EXPECT_CALL(WifiSettings::GetInstance(), GetDeviceConfig(_)).Times(AtLeast(0));
EXPECT_CALL(WifiSettings::GetInstance(), ReloadTrustListPolicies())
.WillRepeatedly(ReturnRef(refVecTrustList));
.WillRepeatedly(Return(refVecTrustList));
EXPECT_EQ(pScanService->InitScanService(WifiManager::GetInstance().GetScanCallback()), true);
}

View File

@ -655,7 +655,10 @@ public:
{
EXPECT_CALL(WifiStaHalInterface::GetInstance(), Scan(_)).WillRepeatedly(Return(WIFI_IDL_OPT_OK));
InterScanConfig interScanConfig;
pScanStateMachine->waitingScans.emplace(0, interScanConfig);
{
std::unique_lock<std::shared_mutex> guard(ScanStateMachine::lock);
pScanStateMachine->waitingScans.emplace(0, interScanConfig);
}
pScanStateMachine->StartNewCommonScan();
}

View File

@ -83,7 +83,6 @@ ohos_unittest("wifi_sta_unittest") {
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_common/Mock",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_aware",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -32,5 +32,9 @@ void MockStaNetworkCheck::StopNetCheckThread()
{
WIFI_LOGD("Enter MockDhcpService::[%{public}s].", __FUNCTION__);
}
void MockStaNetworkCheck::ExitNetCheckThread()
{
WIFI_LOGD("Enter ExitNetCheckThread::[%{public}s].", __FUNCTION__);
}
} // namespace Wifi
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2022 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
@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_MOCK_STANETWORKCHECK_H
#define OHOS_MOCK_STANETWORKCHECK_H
#include <gtest/gtest.h>
@ -27,6 +28,7 @@ public:
ErrCode InitNetCheckThread() override;
void SignalNetCheckThread() override;
void StopNetCheckThread() override;
void ExitNetCheckThread() override;
};
} // namespace OHOS
} // namespace OHOS

View File

@ -762,7 +762,9 @@ void StaAutoConnectServiceTest::SetRoamBlockedBssidFirmwareSuccess()
std::string bssid = "2a:76:93:47:e2:8a";
blockedBssids.push_back(bssid);
EXPECT_CALL(WifiStaHalInterface::GetInstance(), SetRoamConfig(_)).WillOnce(Return(WIFI_IDL_OPT_OK));
EXPECT_CALL(WifiStaHalInterface::GetInstance(), SetRoamConfig(_))
.WillOnce(Return(WIFI_IDL_OPT_OK))
.WillRepeatedly(Return(WIFI_IDL_OPT_OK));
EXPECT_TRUE(pStaAutoConnectService->SetRoamBlockedBssidFirmware(blockedBssids) == true);
}
@ -772,7 +774,8 @@ void StaAutoConnectServiceTest::SetRoamBlockedBssidFirmwareFail1()
std::string bssid = "2a:76:93:47:e2:8a";
blockedBssids.push_back(bssid);
ON_CALL(WifiStaHalInterface::GetInstance(), SetRoamConfig(_)).WillByDefault(Return(WIFI_IDL_OPT_FAILED));
ON_CALL(WifiStaHalInterface::GetInstance(), SetRoamConfig(_))
.WillByDefault(Return(WIFI_IDL_OPT_FAILED));
EXPECT_TRUE(pStaAutoConnectService->SetRoamBlockedBssidFirmware(blockedBssids) == false);
}

View File

@ -27,7 +27,10 @@ ohos_unittest("wifi_hal_unittest") {
module_out_path = module_output_path
sources = [
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/common/wifi_hal_common_func.c",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi/wifi_hdi_ap_instance.c",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_ap_impl.c",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_p2p_impl.c",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_proxy.c",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi/src/wifi_hdi_sta_impl.c",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_adapter.c",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_ap_interface.c",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_base_interface.c",
@ -74,17 +77,16 @@ ohos_unittest("wifi_hal_unittest") {
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_p2p_hal",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//third_party/wpa_supplicant/wpa_supplicant-2.9_standard/src/",
"//third_party/bounds_checking_function/include/",
"//drivers/peripheral/wlan/interfaces/include/",
"//drivers/peripheral/wlan/client/include/",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi",
"//third_party/wpa_supplicant/wpa_supplicant-2.9_standard/src",
"//third_party/bounds_checking_function/include",
"//drivers/peripheral/wlan/interfaces/include",
"//drivers/peripheral/wlan/client/include",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_hal/hdi/inc",
]
deps = [
"$WIFI_ROOT_DIR/services/wifi_standard/ipc_framework/cRPC:crpc_server",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//drivers/peripheral/wlan/hal:wifi_hal",
]
ldflags = [
@ -96,9 +98,16 @@ ohos_unittest("wifi_hal_unittest") {
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
]
configs = [ ":module_private_config" ]
defines = [ "AP_INTF=\"$wifi_feature_with_ap_intf\"" ]
if (wifi_feature_is_hdi_supported) {
defines += [ "HDI_INTERFACE_SUPPORT" ]
external_deps += [ "drivers_interface_wlan:libwlan_proxy_1.0" ]
}
configs = [ ":module_private_config" ]
part_name = "wifi"
subsystem_name = "communication"
testonly = true

View File

@ -110,7 +110,8 @@ HWTEST_F(WifiHalApInterfaceTest, GetValidFrequenciesForBandTest, TestSize.Level1
EXPECT_TRUE(GetValidFrequenciesForBand(band, frequencies, NULL, 0) == WIFI_HAL_FAILED);
EXPECT_TRUE(GetValidFrequenciesForBand(band, NULL, &size, 0) == WIFI_HAL_FAILED);
WifiErrorNo err = GetValidFrequenciesForBand(band, frequencies, &size, 0);
EXPECT_TRUE(err == WIFI_HAL_SUCCESS || err == WIFI_HAL_NOT_SUPPORT);
// WIFI_HAL_FAILED: Some devices do not support
EXPECT_TRUE(err == WIFI_HAL_SUCCESS || err == WIFI_HAL_NOT_SUPPORT || err == WIFI_HAL_FAILED);
}
HWTEST_F(WifiHalApInterfaceTest, StopSoftApTest, TestSize.Level1)

View File

@ -65,7 +65,6 @@ if (defined(ohos_lite)) {
external_deps = [
"ability_base:want",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"hisysevent_native:libhisysevent",

View File

@ -23,4 +23,5 @@ declare_args() {
wifi_feature_with_auth_disable = false
wifi_feature_with_dhcp_disable = false
wifi_feature_with_encryption = true
wifi_feature_is_hdi_supported = false
}

View File

@ -25,4 +25,5 @@ declare_args() {
wifi_feature_with_ap_num = 1
wifi_feature_with_auth_disable = false
wifi_feature_with_dhcp_disable = false
wifi_feature_is_hdi_supported = false
}