mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-27 10:50:41 +00:00
commit
da0d9b82f6
@ -1,22 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_event_monitor_impl.h"
|
||||
|
||||
#include "softbus_errcode.h"
|
||||
int32_t LnnInitDriverMonitorImpl(void)
|
||||
{
|
||||
return SOFTBUS_OK;
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_event_monitor_impl.h"
|
||||
|
||||
#include "softbus_errcode.h"
|
||||
int32_t LnnInitDriverMonitorImpl(void)
|
||||
{
|
||||
return SOFTBUS_OK;
|
||||
}
|
@ -1,29 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_driver_request.h"
|
||||
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
int32_t LnnSendCmdToDriver(int32_t moduleId, const uint8_t *cmd, uint32_t cmdLen,
|
||||
uint8_t *reply, uint32_t replyLen)
|
||||
{
|
||||
(void)moduleId;
|
||||
(void)cmd;
|
||||
(void)cmdLen;
|
||||
(void)reply;
|
||||
(void)replyLen;
|
||||
return SOFTBUS_OK;
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_driver_request.h"
|
||||
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
int32_t LnnSendCmdToDriver(int32_t moduleId, const uint8_t *cmd, uint32_t cmdLen,
|
||||
uint8_t *reply, uint32_t replyLen)
|
||||
{
|
||||
(void)moduleId;
|
||||
(void)cmd;
|
||||
(void)cmdLen;
|
||||
(void)reply;
|
||||
(void)replyLen;
|
||||
return SOFTBUS_OK;
|
||||
}
|
@ -1,139 +1,139 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_event_monitor_impl.h"
|
||||
|
||||
#include <hdf_io_service.h>
|
||||
#include <hdf_sbuf.h>
|
||||
#include <securec.h>
|
||||
|
||||
#include "lnn_async_callback_utils.h"
|
||||
#include "lnn_driver_request.h"
|
||||
#include "lnn_network_manager.h"
|
||||
#include "message_handler.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
|
||||
#define DRIVER_SERVICE_NAME "hdf_dsoftbus"
|
||||
|
||||
#define NETIF_NAME_LENGTH 16
|
||||
|
||||
#define BIND_HDF_DELAY 1000
|
||||
#define MAX_BIND_HDF_RETRY_COUNT 10
|
||||
|
||||
typedef struct {
|
||||
struct HdfIoService *softbusService;
|
||||
struct HdfDevEventlistener eventListener;
|
||||
} HdfDriverEventCtrl;
|
||||
|
||||
typedef struct {
|
||||
uint32_t event;
|
||||
char ifName[NETIF_NAME_LENGTH];
|
||||
union ExtInfo {
|
||||
int32_t status;
|
||||
} extInfo;
|
||||
} LwipMonitorReportInfo;
|
||||
|
||||
static HdfDriverEventCtrl g_driverCtrl;
|
||||
|
||||
static void ProcessLwipEvent(struct HdfSBuf *data)
|
||||
{
|
||||
LnnNetIfType type = LNN_NETIF_TYPE_ETH;
|
||||
uint32_t eventDataSize = 0;
|
||||
uint8_t *eventData = NULL;
|
||||
|
||||
if (!HdfSbufReadBuffer(data, (const void **)&eventData, &eventDataSize)) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "read data from sbuff failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (eventData == NULL || eventDataSize != sizeof(LwipMonitorReportInfo)) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "receive lwip monitor not correct size: %d<->%d", eventDataSize,
|
||||
sizeof(LwipMonitorReportInfo));
|
||||
return;
|
||||
}
|
||||
const LwipMonitorReportInfo *info = (const LwipMonitorReportInfo *)eventData;
|
||||
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "receive lwip monitor event(%d) for %s", info->event, info->ifName);
|
||||
if (LnnGetNetIfTypeByName(info->ifName, &type) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ProcessLwipEvent LnnGetNetIfTypeByName error");
|
||||
return;
|
||||
}
|
||||
if (type == LNN_NETIF_TYPE_ETH || type == LNN_NETIF_TYPE_WLAN) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "network addr changed, type:%d", type);
|
||||
LnnNotifyAddressChangedEvent(info->ifName);
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessWlanEvent(struct HdfSBuf *data)
|
||||
{
|
||||
LnnNotifyWlanStateChangeEvent(SOFTBUS_WIFI_UNKNOWN);
|
||||
}
|
||||
|
||||
static int32_t OnReceiveDriverEvent(
|
||||
struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t moduleId, struct HdfSBuf *data)
|
||||
{
|
||||
(void)listener;
|
||||
(void)service;
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "receive hdf moudle(%d) event", moduleId);
|
||||
if (moduleId >= LNN_DRIVER_MODULE_MAX_INDEX) {
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
switch (moduleId) {
|
||||
case LNN_DRIVER_MODULE_WLAN_PARAM:
|
||||
ProcessWlanEvent(data);
|
||||
break;
|
||||
case LNN_DRIVER_MODULE_LWIP_MONITOR:
|
||||
ProcessLwipEvent(data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void DelayInitFunction(void *para)
|
||||
{
|
||||
int32_t rc;
|
||||
static int32_t retry = 0;
|
||||
|
||||
(void)para;
|
||||
if (retry >= MAX_BIND_HDF_RETRY_COUNT) {
|
||||
return;
|
||||
}
|
||||
g_driverCtrl.softbusService = HdfIoServiceBind(DRIVER_SERVICE_NAME);
|
||||
if (g_driverCtrl.softbusService == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get hdf dsoftbus service fail(%d)", retry);
|
||||
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), DelayInitFunction, NULL, BIND_HDF_DELAY);
|
||||
++retry;
|
||||
return;
|
||||
}
|
||||
rc = HdfDeviceRegisterEventListener(g_driverCtrl.softbusService, &g_driverCtrl.eventListener);
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "init hdf driver monitor(%d) result: %d", retry, rc);
|
||||
if (rc != SOFTBUS_OK) {
|
||||
HdfIoServiceRecycle(g_driverCtrl.softbusService);
|
||||
g_driverCtrl.softbusService = NULL;
|
||||
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), DelayInitFunction, NULL, BIND_HDF_DELAY);
|
||||
}
|
||||
++retry;
|
||||
}
|
||||
|
||||
int32_t LnnInitDriverMonitorImpl(void)
|
||||
{
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "hdf driver monitor init enter");
|
||||
g_driverCtrl.eventListener.onReceive = OnReceiveDriverEvent;
|
||||
return LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), DelayInitFunction, NULL, BIND_HDF_DELAY);
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_event_monitor_impl.h"
|
||||
|
||||
#include <hdf_io_service.h>
|
||||
#include <hdf_sbuf.h>
|
||||
#include <securec.h>
|
||||
|
||||
#include "lnn_async_callback_utils.h"
|
||||
#include "lnn_driver_request.h"
|
||||
#include "lnn_network_manager.h"
|
||||
#include "message_handler.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
|
||||
#define DRIVER_SERVICE_NAME "hdf_dsoftbus"
|
||||
|
||||
#define NETIF_NAME_LENGTH 16
|
||||
|
||||
#define BIND_HDF_DELAY 1000
|
||||
#define MAX_BIND_HDF_RETRY_COUNT 10
|
||||
|
||||
typedef struct {
|
||||
struct HdfIoService *softbusService;
|
||||
struct HdfDevEventlistener eventListener;
|
||||
} HdfDriverEventCtrl;
|
||||
|
||||
typedef struct {
|
||||
uint32_t event;
|
||||
char ifName[NETIF_NAME_LENGTH];
|
||||
union ExtInfo {
|
||||
int32_t status;
|
||||
} extInfo;
|
||||
} LwipMonitorReportInfo;
|
||||
|
||||
static HdfDriverEventCtrl g_driverCtrl;
|
||||
|
||||
static void ProcessLwipEvent(struct HdfSBuf *data)
|
||||
{
|
||||
LnnNetIfType type = LNN_NETIF_TYPE_ETH;
|
||||
uint32_t eventDataSize = 0;
|
||||
uint8_t *eventData = NULL;
|
||||
|
||||
if (!HdfSbufReadBuffer(data, (const void **)&eventData, &eventDataSize)) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "read data from sbuff failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (eventData == NULL || eventDataSize != sizeof(LwipMonitorReportInfo)) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "receive lwip monitor not correct size: %d<->%d", eventDataSize,
|
||||
sizeof(LwipMonitorReportInfo));
|
||||
return;
|
||||
}
|
||||
const LwipMonitorReportInfo *info = (const LwipMonitorReportInfo *)eventData;
|
||||
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "receive lwip monitor event(%d) for %s", info->event, info->ifName);
|
||||
if (LnnGetNetIfTypeByName(info->ifName, &type) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ProcessLwipEvent LnnGetNetIfTypeByName error");
|
||||
return;
|
||||
}
|
||||
if (type == LNN_NETIF_TYPE_ETH || type == LNN_NETIF_TYPE_WLAN) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "network addr changed, type:%d", type);
|
||||
LnnNotifyAddressChangedEvent(info->ifName);
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessWlanEvent(struct HdfSBuf *data)
|
||||
{
|
||||
LnnNotifyWlanStateChangeEvent(SOFTBUS_WIFI_UNKNOWN);
|
||||
}
|
||||
|
||||
static int32_t OnReceiveDriverEvent(
|
||||
struct HdfDevEventlistener *listener, struct HdfIoService *service, uint32_t moduleId, struct HdfSBuf *data)
|
||||
{
|
||||
(void)listener;
|
||||
(void)service;
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "receive hdf moudle(%d) event", moduleId);
|
||||
if (moduleId >= LNN_DRIVER_MODULE_MAX_INDEX) {
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
switch (moduleId) {
|
||||
case LNN_DRIVER_MODULE_WLAN_PARAM:
|
||||
ProcessWlanEvent(data);
|
||||
break;
|
||||
case LNN_DRIVER_MODULE_LWIP_MONITOR:
|
||||
ProcessLwipEvent(data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void DelayInitFunction(void *para)
|
||||
{
|
||||
int32_t rc;
|
||||
static int32_t retry = 0;
|
||||
|
||||
(void)para;
|
||||
if (retry >= MAX_BIND_HDF_RETRY_COUNT) {
|
||||
return;
|
||||
}
|
||||
g_driverCtrl.softbusService = HdfIoServiceBind(DRIVER_SERVICE_NAME);
|
||||
if (g_driverCtrl.softbusService == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get hdf dsoftbus service fail(%d)", retry);
|
||||
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), DelayInitFunction, NULL, BIND_HDF_DELAY);
|
||||
++retry;
|
||||
return;
|
||||
}
|
||||
rc = HdfDeviceRegisterEventListener(g_driverCtrl.softbusService, &g_driverCtrl.eventListener);
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "init hdf driver monitor(%d) result: %d", retry, rc);
|
||||
if (rc != SOFTBUS_OK) {
|
||||
HdfIoServiceRecycle(g_driverCtrl.softbusService);
|
||||
g_driverCtrl.softbusService = NULL;
|
||||
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), DelayInitFunction, NULL, BIND_HDF_DELAY);
|
||||
}
|
||||
++retry;
|
||||
}
|
||||
|
||||
int32_t LnnInitDriverMonitorImpl(void)
|
||||
{
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "hdf driver monitor init enter");
|
||||
g_driverCtrl.eventListener.onReceive = OnReceiveDriverEvent;
|
||||
return LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), DelayInitFunction, NULL, BIND_HDF_DELAY);
|
||||
}
|
@ -1,100 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_driver_request.h"
|
||||
|
||||
#include <hdf_io_service.h>
|
||||
#include <hdf_sbuf.h>
|
||||
#include <securec.h>
|
||||
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
|
||||
#define DRIVER_SERVICE_NAME "hdf_dsoftbus"
|
||||
|
||||
static int32_t ParseReply(struct HdfSBuf *rspData, uint8_t *reply, uint32_t replyLen)
|
||||
{
|
||||
uint8_t *data = NULL;
|
||||
uint32_t dataSize;
|
||||
|
||||
if (reply == NULL) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (!HdfSbufReadBuffer(rspData, (const void **)&data, &dataSize)) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "read cmd reply fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (dataSize > replyLen) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "no enough space save reply");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (memcpy_s(reply, replyLen, data, dataSize) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy reply fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t LnnSendCmdToDriver(int32_t moduleId, const uint8_t *cmd, uint32_t cmdLen,
|
||||
uint8_t *reply, uint32_t replyLen)
|
||||
{
|
||||
int32_t rc = SOFTBUS_ERR;
|
||||
struct HdfIoService *softbusService = NULL;
|
||||
struct HdfSBuf *reqData = NULL;
|
||||
struct HdfSBuf *rspData = NULL;
|
||||
|
||||
if (cmd == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid cmd for module %d", moduleId);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
softbusService = HdfIoServiceBind(DRIVER_SERVICE_NAME);
|
||||
if (softbusService == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "bind hdf softbus fail for module %d", moduleId);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (softbusService->dispatcher == NULL ||
|
||||
softbusService->dispatcher->Dispatch == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "bind hdf softbus fail for module %d", moduleId);
|
||||
HdfIoServiceRecycle(softbusService);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
reqData = HdfSbufObtainDefaultSize();
|
||||
rspData = HdfSbufObtainDefaultSize();
|
||||
do {
|
||||
if (reqData == NULL || rspData == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "obtain sbuf fail for module %d", moduleId);
|
||||
break;
|
||||
}
|
||||
if (!HdfSbufWriteBuffer(reqData, cmd, cmdLen)) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "write sbuf fail for module %d", moduleId);
|
||||
break;
|
||||
}
|
||||
rc = softbusService->dispatcher->Dispatch(&softbusService->object, moduleId, reqData, rspData);
|
||||
if (rc != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "send command fail for module %d", moduleId);
|
||||
}
|
||||
} while (false);
|
||||
if (rc == SOFTBUS_OK) {
|
||||
rc = ParseReply(rspData, reply, replyLen);
|
||||
}
|
||||
if (reqData != NULL) {
|
||||
HdfSbufRecycle(reqData);
|
||||
}
|
||||
if (rspData != NULL) {
|
||||
HdfSbufRecycle(rspData);
|
||||
}
|
||||
HdfIoServiceRecycle(softbusService);
|
||||
return rc;
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_driver_request.h"
|
||||
|
||||
#include <hdf_io_service.h>
|
||||
#include <hdf_sbuf.h>
|
||||
#include <securec.h>
|
||||
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
|
||||
#define DRIVER_SERVICE_NAME "hdf_dsoftbus"
|
||||
|
||||
static int32_t ParseReply(struct HdfSBuf *rspData, uint8_t *reply, uint32_t replyLen)
|
||||
{
|
||||
uint8_t *data = NULL;
|
||||
uint32_t dataSize;
|
||||
|
||||
if (reply == NULL) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (!HdfSbufReadBuffer(rspData, (const void **)&data, &dataSize)) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "read cmd reply fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (dataSize > replyLen) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "no enough space save reply");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (memcpy_s(reply, replyLen, data, dataSize) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy reply fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t LnnSendCmdToDriver(int32_t moduleId, const uint8_t *cmd, uint32_t cmdLen,
|
||||
uint8_t *reply, uint32_t replyLen)
|
||||
{
|
||||
int32_t rc = SOFTBUS_ERR;
|
||||
struct HdfIoService *softbusService = NULL;
|
||||
struct HdfSBuf *reqData = NULL;
|
||||
struct HdfSBuf *rspData = NULL;
|
||||
|
||||
if (cmd == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid cmd for module %d", moduleId);
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
softbusService = HdfIoServiceBind(DRIVER_SERVICE_NAME);
|
||||
if (softbusService == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "bind hdf softbus fail for module %d", moduleId);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (softbusService->dispatcher == NULL ||
|
||||
softbusService->dispatcher->Dispatch == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "bind hdf softbus fail for module %d", moduleId);
|
||||
HdfIoServiceRecycle(softbusService);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
reqData = HdfSbufObtainDefaultSize();
|
||||
rspData = HdfSbufObtainDefaultSize();
|
||||
do {
|
||||
if (reqData == NULL || rspData == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "obtain sbuf fail for module %d", moduleId);
|
||||
break;
|
||||
}
|
||||
if (!HdfSbufWriteBuffer(reqData, cmd, cmdLen)) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "write sbuf fail for module %d", moduleId);
|
||||
break;
|
||||
}
|
||||
rc = softbusService->dispatcher->Dispatch(&softbusService->object, moduleId, reqData, rspData);
|
||||
if (rc != 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "send command fail for module %d", moduleId);
|
||||
}
|
||||
} while (false);
|
||||
if (rc == SOFTBUS_OK) {
|
||||
rc = ParseReply(rspData, reply, replyLen);
|
||||
}
|
||||
if (reqData != NULL) {
|
||||
HdfSbufRecycle(reqData);
|
||||
}
|
||||
if (rspData != NULL) {
|
||||
HdfSbufRecycle(rspData);
|
||||
}
|
||||
HdfIoServiceRecycle(softbusService);
|
||||
return rc;
|
||||
}
|
@ -1,41 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 LNN_DRIVER_REQUEST_H
|
||||
#define LNN_DRIVER_REQUEST_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
LNN_DRIVER_MODULE_WLAN_PARAM = 0,
|
||||
LNN_DRIVER_MODULE_LWIP_MONITOR,
|
||||
LNN_DRIVER_MODULE_MAX_INDEX,
|
||||
} LnnDriverModuleId;
|
||||
|
||||
int32_t LnnSendCmdToDriver(int32_t moduleId, const uint8_t *cmd, uint32_t cmdLen,
|
||||
uint8_t *reply, uint32_t replyLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
/*
|
||||
* Copyright (c) 2021 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 LNN_DRIVER_REQUEST_H
|
||||
#define LNN_DRIVER_REQUEST_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
LNN_DRIVER_MODULE_WLAN_PARAM = 0,
|
||||
LNN_DRIVER_MODULE_LWIP_MONITOR,
|
||||
LNN_DRIVER_MODULE_MAX_INDEX,
|
||||
} LnnDriverModuleId;
|
||||
|
||||
int32_t LnnSendCmdToDriver(int32_t moduleId, const uint8_t *cmd, uint32_t cmdLen,
|
||||
uint8_t *reply, uint32_t replyLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* LNN_DRIVER_REQUEST_H */
|
@ -1,48 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 LNN_EVENT_MONITOR_IMPL_H
|
||||
#define LNN_EVENT_MONITOR_IMPL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "bus_center_event.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int32_t (*LnnInitEventMonitorImpl)(void);
|
||||
typedef void (*LnnDeinitEventMonitorImpl)(void);
|
||||
|
||||
int32_t LnnInitNetlinkMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitProductMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitLwipMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitWifiServiceMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitDriverMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitCommonEventMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitBtStateMonitorImpl(void);
|
||||
|
||||
void LnnDeinitBtStateMonitorImpl(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* LNN_EVENT_MONITOR_IMPL_H */
|
||||
/*
|
||||
* Copyright (c) 2021 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 LNN_EVENT_MONITOR_IMPL_H
|
||||
#define LNN_EVENT_MONITOR_IMPL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "bus_center_event.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int32_t (*LnnInitEventMonitorImpl)(void);
|
||||
typedef void (*LnnDeinitEventMonitorImpl)(void);
|
||||
|
||||
int32_t LnnInitNetlinkMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitProductMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitLwipMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitWifiServiceMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitDriverMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitCommonEventMonitorImpl(void);
|
||||
|
||||
int32_t LnnInitBtStateMonitorImpl(void);
|
||||
|
||||
void LnnDeinitBtStateMonitorImpl(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* LNN_EVENT_MONITOR_IMPL_H */
|
||||
|
@ -1,35 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 LNN_LINKWATCH_H
|
||||
#define LNN_LINKWATCH_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool LnnIsLinkReady(const char *iface);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
/*
|
||||
* Copyright (c) 2021 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 LNN_LINKWATCH_H
|
||||
#define LNN_LINKWATCH_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool LnnIsLinkReady(const char *iface);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* LNN_LINKWATCH_H */
|
@ -1,183 +1,183 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_event_monitor_impl.h"
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include "bus_center_event.h"
|
||||
#include "common_event_data.h"
|
||||
#include "common_event_manager.h"
|
||||
#include "common_event_subscriber.h"
|
||||
#include "common_event_support.h"
|
||||
#include "lnn_async_callback_utils.h"
|
||||
#include "want.h"
|
||||
#include "wifi_msg.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
#include "wifi_event.h"
|
||||
#include "wifi_ap_msg.h"
|
||||
|
||||
static const int32_t DELAY_LEN = 1000;
|
||||
static const int32_t RETRY_MAX = 20;
|
||||
|
||||
namespace OHOS {
|
||||
namespace EventFwk {
|
||||
class WifiServiceMonitor : public CommonEventSubscriber {
|
||||
public:
|
||||
explicit WifiServiceMonitor(const CommonEventSubscribeInfo &subscriberInfo);
|
||||
virtual ~WifiServiceMonitor(){}
|
||||
virtual void OnReceiveEvent(const CommonEventData &data);
|
||||
};
|
||||
|
||||
WifiServiceMonitor::WifiServiceMonitor(const CommonEventSubscribeInfo &subscriberInfo)
|
||||
:CommonEventSubscriber(subscriberInfo)
|
||||
{
|
||||
}
|
||||
|
||||
void WifiServiceMonitor::OnReceiveEvent(const CommonEventData &data)
|
||||
{
|
||||
int code = data.GetCode();
|
||||
std::string action = data.GetWant().GetAction();
|
||||
SoftBusWifiState state = SOFTBUS_WIFI_UNKNOWN;
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "notify wifiservice event %s, code(%d)", action.c_str(), code);
|
||||
|
||||
if (action == CommonEventSupport::COMMON_EVENT_WIFI_CONN_STATE) {
|
||||
switch (code) {
|
||||
case int(OHOS::Wifi::ConnState::CONNECTED):
|
||||
state = SOFTBUS_WIFI_CONNECTED;
|
||||
break;
|
||||
case int(OHOS::Wifi::ConnState::DISCONNECTED):
|
||||
state = SOFTBUS_WIFI_DISCONNECTED;
|
||||
break;
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (action == CommonEventSupport::COMMON_EVENT_WIFI_POWER_STATE) {
|
||||
switch (code) {
|
||||
case int(OHOS::Wifi::WifiState::DISABLED):
|
||||
state = SOFTBUS_WIFI_DISABLED;
|
||||
break;
|
||||
case int(OHOS::Wifi::WifiState::ENABLED):
|
||||
state = SOFTBUS_WIFI_ENABLED;
|
||||
break;
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (action == CommonEventSupport::COMMON_EVENT_WIFI_HOTSPOT_STATE) {
|
||||
switch (code) {
|
||||
case int(OHOS::Wifi::ApState::AP_STATE_STARTED):
|
||||
state = SOFTBUS_AP_ENABLED;
|
||||
break;
|
||||
case int(OHOS::Wifi::ApState::AP_STATE_CLOSED):
|
||||
state = SOFTBUS_AP_DISABLED;
|
||||
break;
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state != SOFTBUS_WIFI_UNKNOWN) {
|
||||
LnnNotifyWlanStateChangeEvent(state);
|
||||
}
|
||||
}
|
||||
|
||||
class SubscribeEvent {
|
||||
public:
|
||||
int32_t SubscribeWifiConnStateEvent();
|
||||
int32_t SubscribeWifiPowerStateEvent();
|
||||
int32_t SubscribeAPConnStateEvent();
|
||||
};
|
||||
|
||||
int32_t SubscribeEvent::SubscribeAPConnStateEvent()
|
||||
{
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_HOTSPOT_STATE);
|
||||
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
std::shared_ptr<WifiServiceMonitor> subscriberPtr = std::make_shared<WifiServiceMonitor>(subscriberInfo);
|
||||
if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SubscribeEvent::SubscribeWifiConnStateEvent()
|
||||
{
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_CONN_STATE);
|
||||
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
std::shared_ptr<WifiServiceMonitor> subscriberPtr = std::make_shared<WifiServiceMonitor>(subscriberInfo);
|
||||
if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SubscribeEvent::SubscribeWifiPowerStateEvent()
|
||||
{
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_POWER_STATE);
|
||||
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
std::shared_ptr<WifiServiceMonitor> subscriberPtr = std::make_shared<WifiServiceMonitor>(subscriberInfo);
|
||||
if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
} // namespace EventFwk
|
||||
} // namespace OHOS
|
||||
|
||||
static void LnnSubscribeWifiService(void *para)
|
||||
{
|
||||
(void)para;
|
||||
static int32_t retry = 0;
|
||||
if (retry > RETRY_MAX) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "try subscribe wifiservice event max times");
|
||||
return;
|
||||
}
|
||||
OHOS::EventFwk::SubscribeEvent *subscriberPtr = new OHOS::EventFwk::SubscribeEvent();
|
||||
if (subscriberPtr == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "SubscribeEvent init fail");
|
||||
return;
|
||||
}
|
||||
if (subscriberPtr->SubscribeWifiConnStateEvent() == SOFTBUS_OK &&
|
||||
subscriberPtr->SubscribeWifiPowerStateEvent() == SOFTBUS_OK &&
|
||||
subscriberPtr->SubscribeAPConnStateEvent() == SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "subscribe wifiservice conn and power state success");
|
||||
} else {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "subscribe wifiservice event fail");
|
||||
retry++;
|
||||
SoftBusLooper *looper = GetLooper(LOOP_TYPE_DEFAULT);
|
||||
if (LnnAsyncCallbackDelayHelper(looper, LnnSubscribeWifiService, NULL, DELAY_LEN) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init wifiservice LnnAsyncCallbackDelayHelper fail");
|
||||
}
|
||||
}
|
||||
delete subscriberPtr;
|
||||
}
|
||||
|
||||
int32_t LnnInitWifiServiceMonitorImpl(void)
|
||||
{
|
||||
SoftBusLooper *looper = GetLooper(LOOP_TYPE_DEFAULT);
|
||||
int32_t ret = LnnAsyncCallbackDelayHelper(looper, LnnSubscribeWifiService, NULL, DELAY_LEN);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init wifiservice LnnAsyncCallbackDelayHelper fail");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_event_monitor_impl.h"
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include "bus_center_event.h"
|
||||
#include "common_event_data.h"
|
||||
#include "common_event_manager.h"
|
||||
#include "common_event_subscriber.h"
|
||||
#include "common_event_support.h"
|
||||
#include "lnn_async_callback_utils.h"
|
||||
#include "want.h"
|
||||
#include "wifi_msg.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
#include "wifi_event.h"
|
||||
#include "wifi_ap_msg.h"
|
||||
|
||||
static const int32_t DELAY_LEN = 1000;
|
||||
static const int32_t RETRY_MAX = 20;
|
||||
|
||||
namespace OHOS {
|
||||
namespace EventFwk {
|
||||
class WifiServiceMonitor : public CommonEventSubscriber {
|
||||
public:
|
||||
explicit WifiServiceMonitor(const CommonEventSubscribeInfo &subscriberInfo);
|
||||
virtual ~WifiServiceMonitor(){}
|
||||
virtual void OnReceiveEvent(const CommonEventData &data);
|
||||
};
|
||||
|
||||
WifiServiceMonitor::WifiServiceMonitor(const CommonEventSubscribeInfo &subscriberInfo)
|
||||
:CommonEventSubscriber(subscriberInfo)
|
||||
{
|
||||
}
|
||||
|
||||
void WifiServiceMonitor::OnReceiveEvent(const CommonEventData &data)
|
||||
{
|
||||
int code = data.GetCode();
|
||||
std::string action = data.GetWant().GetAction();
|
||||
SoftBusWifiState state = SOFTBUS_WIFI_UNKNOWN;
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "notify wifiservice event %s, code(%d)", action.c_str(), code);
|
||||
|
||||
if (action == CommonEventSupport::COMMON_EVENT_WIFI_CONN_STATE) {
|
||||
switch (code) {
|
||||
case int(OHOS::Wifi::ConnState::CONNECTED):
|
||||
state = SOFTBUS_WIFI_CONNECTED;
|
||||
break;
|
||||
case int(OHOS::Wifi::ConnState::DISCONNECTED):
|
||||
state = SOFTBUS_WIFI_DISCONNECTED;
|
||||
break;
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (action == CommonEventSupport::COMMON_EVENT_WIFI_POWER_STATE) {
|
||||
switch (code) {
|
||||
case int(OHOS::Wifi::WifiState::DISABLED):
|
||||
state = SOFTBUS_WIFI_DISABLED;
|
||||
break;
|
||||
case int(OHOS::Wifi::WifiState::ENABLED):
|
||||
state = SOFTBUS_WIFI_ENABLED;
|
||||
break;
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (action == CommonEventSupport::COMMON_EVENT_WIFI_HOTSPOT_STATE) {
|
||||
switch (code) {
|
||||
case int(OHOS::Wifi::ApState::AP_STATE_STARTED):
|
||||
state = SOFTBUS_AP_ENABLED;
|
||||
break;
|
||||
case int(OHOS::Wifi::ApState::AP_STATE_CLOSED):
|
||||
state = SOFTBUS_AP_DISABLED;
|
||||
break;
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state != SOFTBUS_WIFI_UNKNOWN) {
|
||||
LnnNotifyWlanStateChangeEvent(state);
|
||||
}
|
||||
}
|
||||
|
||||
class SubscribeEvent {
|
||||
public:
|
||||
int32_t SubscribeWifiConnStateEvent();
|
||||
int32_t SubscribeWifiPowerStateEvent();
|
||||
int32_t SubscribeAPConnStateEvent();
|
||||
};
|
||||
|
||||
int32_t SubscribeEvent::SubscribeAPConnStateEvent()
|
||||
{
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_HOTSPOT_STATE);
|
||||
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
std::shared_ptr<WifiServiceMonitor> subscriberPtr = std::make_shared<WifiServiceMonitor>(subscriberInfo);
|
||||
if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SubscribeEvent::SubscribeWifiConnStateEvent()
|
||||
{
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_CONN_STATE);
|
||||
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
std::shared_ptr<WifiServiceMonitor> subscriberPtr = std::make_shared<WifiServiceMonitor>(subscriberInfo);
|
||||
if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SubscribeEvent::SubscribeWifiPowerStateEvent()
|
||||
{
|
||||
MatchingSkills matchingSkills;
|
||||
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_WIFI_POWER_STATE);
|
||||
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
std::shared_ptr<WifiServiceMonitor> subscriberPtr = std::make_shared<WifiServiceMonitor>(subscriberInfo);
|
||||
if (!CommonEventManager::SubscribeCommonEvent(subscriberPtr)) {
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
} // namespace EventFwk
|
||||
} // namespace OHOS
|
||||
|
||||
static void LnnSubscribeWifiService(void *para)
|
||||
{
|
||||
(void)para;
|
||||
static int32_t retry = 0;
|
||||
if (retry > RETRY_MAX) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "try subscribe wifiservice event max times");
|
||||
return;
|
||||
}
|
||||
OHOS::EventFwk::SubscribeEvent *subscriberPtr = new OHOS::EventFwk::SubscribeEvent();
|
||||
if (subscriberPtr == nullptr) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "SubscribeEvent init fail");
|
||||
return;
|
||||
}
|
||||
if (subscriberPtr->SubscribeWifiConnStateEvent() == SOFTBUS_OK &&
|
||||
subscriberPtr->SubscribeWifiPowerStateEvent() == SOFTBUS_OK &&
|
||||
subscriberPtr->SubscribeAPConnStateEvent() == SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "subscribe wifiservice conn and power state success");
|
||||
} else {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "subscribe wifiservice event fail");
|
||||
retry++;
|
||||
SoftBusLooper *looper = GetLooper(LOOP_TYPE_DEFAULT);
|
||||
if (LnnAsyncCallbackDelayHelper(looper, LnnSubscribeWifiService, NULL, DELAY_LEN) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init wifiservice LnnAsyncCallbackDelayHelper fail");
|
||||
}
|
||||
}
|
||||
delete subscriberPtr;
|
||||
}
|
||||
|
||||
int32_t LnnInitWifiServiceMonitorImpl(void)
|
||||
{
|
||||
SoftBusLooper *looper = GetLooper(LOOP_TYPE_DEFAULT);
|
||||
int32_t ret = LnnAsyncCallbackDelayHelper(looper, LnnSubscribeWifiService, NULL, DELAY_LEN);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init wifiservice LnnAsyncCallbackDelayHelper fail");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_event_monitor_impl.h"
|
||||
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
int32_t LnnInitWifiServiceMonitorImpl(void)
|
||||
{
|
||||
return SOFTBUS_OK;
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_event_monitor_impl.h"
|
||||
|
||||
#include "softbus_errcode.h"
|
||||
|
||||
int32_t LnnInitWifiServiceMonitorImpl(void)
|
||||
{
|
||||
return SOFTBUS_OK;
|
||||
}
|
@ -1,42 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "softbus_adapter_log.h"
|
||||
|
||||
void SoftBusOutPrint(const char *buf, SoftBusLogLevel level)
|
||||
{
|
||||
#ifdef SOFTBUS_PRINTF
|
||||
(void)level;
|
||||
printf("%s\n", buf);
|
||||
return;
|
||||
#else
|
||||
switch (level) {
|
||||
case SOFTBUS_LOG_DBG:
|
||||
HILOG_DEBUG(SOFTBUS_HILOG_ID, "%{public}s", buf);
|
||||
break;
|
||||
case SOFTBUS_LOG_INFO:
|
||||
HILOG_INFO(SOFTBUS_HILOG_ID, "%{public}s", buf);
|
||||
break;
|
||||
case SOFTBUS_LOG_WARN:
|
||||
HILOG_WARN(SOFTBUS_HILOG_ID, "%{public}s", buf);
|
||||
break;
|
||||
case SOFTBUS_LOG_ERROR:
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "%{public}s", buf);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "softbus_adapter_log.h"
|
||||
|
||||
void SoftBusOutPrint(const char *buf, SoftBusLogLevel level)
|
||||
{
|
||||
#ifdef SOFTBUS_PRINTF
|
||||
(void)level;
|
||||
printf("%s\n", buf);
|
||||
return;
|
||||
#else
|
||||
switch (level) {
|
||||
case SOFTBUS_LOG_DBG:
|
||||
HILOG_DEBUG(SOFTBUS_HILOG_ID, "%{public}s", buf);
|
||||
break;
|
||||
case SOFTBUS_LOG_INFO:
|
||||
HILOG_INFO(SOFTBUS_HILOG_ID, "%{public}s", buf);
|
||||
break;
|
||||
case SOFTBUS_LOG_WARN:
|
||||
HILOG_WARN(SOFTBUS_HILOG_ID, "%{public}s", buf);
|
||||
break;
|
||||
case SOFTBUS_LOG_ERROR:
|
||||
HILOG_ERROR(SOFTBUS_HILOG_ID, "%{public}s", buf);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1,375 +1,375 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "softbus_wifi_api_adapter.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "securec.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
#include "wifi_device.h"
|
||||
#include "wifi_hid2d.h"
|
||||
#include "wifi_p2p.h"
|
||||
|
||||
static int32_t ConvertSoftBusWifiConfFromWifiDev(const WifiDeviceConfig *sourceWifiConf, SoftBusWifiDevConf *wifiConf)
|
||||
{
|
||||
if (strcpy_s(wifiConf->ssid, sizeof(wifiConf->ssid), sourceWifiConf->ssid) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "str copy ssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (memcpy_s(wifiConf->bssid, sizeof(wifiConf->bssid), sourceWifiConf->bssid,
|
||||
sizeof(sourceWifiConf->bssid)) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "mem copy bssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (strcpy_s(wifiConf->preSharedKey, sizeof(wifiConf->preSharedKey),
|
||||
sourceWifiConf->preSharedKey) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "str copy ssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
wifiConf->securityType = sourceWifiConf->securityType;
|
||||
wifiConf->isHiddenSsid = sourceWifiConf->isHiddenSsid;
|
||||
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t ConvertWifiDevConfFromSoftBusWifiConf(const SoftBusWifiDevConf *result, WifiDeviceConfig *wifiConf)
|
||||
{
|
||||
if (strcpy_s(wifiConf->ssid, sizeof(wifiConf->ssid), result->ssid) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "str copy ssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (memcpy_s(wifiConf->bssid, sizeof(wifiConf->bssid),
|
||||
result->bssid, sizeof(result->bssid)) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "mem copy bssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (strcpy_s(wifiConf->preSharedKey, sizeof(wifiConf->preSharedKey),
|
||||
result->preSharedKey) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "str copy ssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
wifiConf->securityType = result->securityType;
|
||||
wifiConf->isHiddenSsid = result->isHiddenSsid;
|
||||
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf *configList, uint32_t *num)
|
||||
{
|
||||
WifiDeviceConfig *result = NULL;
|
||||
uint32_t wifiConfigSize;
|
||||
int32_t retVal;
|
||||
uint32_t i;
|
||||
|
||||
if (configList == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "para configList is NULL");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
result = SoftBusMalloc(sizeof(WifiDeviceConfig) * WIFI_MAX_CONFIG_SIZE);
|
||||
if (result == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc wifi device config fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
(void)memset_s(result, sizeof(WifiDeviceConfig) * WIFI_MAX_CONFIG_SIZE, 0,
|
||||
sizeof(WifiDeviceConfig) * WIFI_MAX_CONFIG_SIZE);
|
||||
retVal = GetDeviceConfigs(result, &wifiConfigSize);
|
||||
if (retVal != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc wifi device config fail");
|
||||
SoftBusFree(result);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (wifiConfigSize > WIFI_MAX_CONFIG_SIZE) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "wifi device config size is invalid.");
|
||||
SoftBusFree(result);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
for (i = 0; i < wifiConfigSize; i++) {
|
||||
if (ConvertSoftBusWifiConfFromWifiDev(result, configList) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "convert wifi config failed.");
|
||||
SoftBusFree(result);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
result++;
|
||||
configList++;
|
||||
}
|
||||
*num = wifiConfigSize;
|
||||
SoftBusFree(result);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusConnectToDevice(const SoftBusWifiDevConf *wifiConfig)
|
||||
{
|
||||
WifiDeviceConfig wifiDevConfig;
|
||||
|
||||
if (wifiConfig == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "para wifiConfig is NULL");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
(void)memset_s(&wifiDevConfig, sizeof(WifiDeviceConfig), 0, sizeof(WifiDeviceConfig));
|
||||
if (ConvertWifiDevConfFromSoftBusWifiConf(wifiConfig, &wifiDevConfig) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "convert wifi config failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (ConnectToDevice(&wifiDevConfig) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "connect to wifi failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusDisconnectDevice(void)
|
||||
{
|
||||
return Disconnect();
|
||||
}
|
||||
|
||||
static ISoftBusScanResult *g_scanResultCb[MAX_CALLBACK_NUM] = {NULL};
|
||||
static bool g_registerFlag = true;
|
||||
|
||||
int32_t SoftBusStartWifiScan(void)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
ret = Scan();
|
||||
if (ret != WIFI_SUCCESS) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "softbus start wifi scan failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void SoftBusWifiScanStateChanged(int state, int size)
|
||||
{
|
||||
for (int i = 0; i < MAX_CALLBACK_NUM; i++) {
|
||||
if (g_scanResultCb[i] != NULL) {
|
||||
g_scanResultCb[i]->onSoftBusWifiScanResult(state, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static WifiEvent g_event = {
|
||||
.OnWifiConnectionChanged = NULL,
|
||||
.OnWifiScanStateChanged = SoftBusWifiScanStateChanged,
|
||||
.OnHotspotStateChanged = NULL,
|
||||
.OnHotspotStaJoin = NULL,
|
||||
.OnHotspotStaLeave = NULL,
|
||||
};
|
||||
|
||||
static int32_t FindFreeCallbackIndex(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_CALLBACK_NUM; i++) {
|
||||
if (g_scanResultCb[i] == NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int32_t SoftBusRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
int index = FindFreeCallbackIndex();
|
||||
if (index == MAX_CALLBACK_NUM) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "register callback index invalid.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_scanResultCb[index] = cb;
|
||||
|
||||
if (g_registerFlag) {
|
||||
ret = RegisterWifiEvent(&g_event);
|
||||
if (ret == WIFI_SUCCESS) {
|
||||
g_registerFlag = false;
|
||||
} else {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "softbus register wifi event failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t ConvertSoftBusWifiScanInfoFromWifi(WifiScanInfo *info, SoftBusWifiScanInfo *result, uint32_t *size)
|
||||
{
|
||||
if (info == NULL || result == NULL || size == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid para");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
for (uint32_t i = 0; i < (*size); i++) {
|
||||
if (strcpy_s(result->ssid, WIFI_MAX_SSID_LEN, info->ssid) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "strcpy ssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (memcpy_s(result->bssid, WIFI_MAC_LEN, info->bssid, sizeof(info->bssid)) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy bssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
result->securityType = (int32_t)(info->securityType);
|
||||
result->rssi = (int32_t)(info->rssi);
|
||||
result->band = (int32_t)(info->band);
|
||||
result->frequency = (int32_t)(info->frequency);
|
||||
result->channelWidth = (int32_t)(info->channelWidth);
|
||||
result->centerFrequency0 =(int32_t)(info->centerFrequency0);
|
||||
result->centerFrequency1 = (int32_t)(info->centerFrequency1);
|
||||
result->timestamp = info->timestamp;
|
||||
++result;
|
||||
++info;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetWifiScanList(SoftBusWifiScanInfo **result, uint32_t *size)
|
||||
{
|
||||
if (size == NULL || result == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "para size or result is NULL.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
WifiScanInfo *info = (WifiScanInfo *)SoftBusMalloc(sizeof(WifiScanInfo) * WIFI_MAX_SCAN_HOTSPOT_LIMIT);
|
||||
if (info == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc wifi scan information failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
(void)memset_s(info, sizeof(WifiScanInfo)*WIFI_MAX_SCAN_HOTSPOT_LIMIT, 0,
|
||||
sizeof(WifiScanInfo)*WIFI_MAX_SCAN_HOTSPOT_LIMIT);
|
||||
*size = WIFI_MAX_SCAN_HOTSPOT_LIMIT;
|
||||
int32_t ret = GetScanInfoList(info, (unsigned int *)size);
|
||||
if (ret != WIFI_SUCCESS || size == 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "softbus get wifi scan list failed.");
|
||||
SoftBusFree(info);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
*result = (SoftBusWifiScanInfo *)SoftBusMalloc(sizeof(SoftBusWifiScanInfo) * (*size));
|
||||
if (*result == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc softbus wifi scan information failed.");
|
||||
SoftBusFree(info);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
(void)memset_s(*result, sizeof(SoftBusWifiScanInfo)* (*size), 0, sizeof(SoftBusWifiScanInfo)* (*size));
|
||||
if (ConvertSoftBusWifiScanInfoFromWifi(info, *result, size) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ConvertSoftBusWifiScaninfoFromWifi failed.");
|
||||
SoftBusFree(*result);
|
||||
*result = NULL;
|
||||
SoftBusFree(info);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
SoftBusFree(info);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static bool IsScanResultCbEmpty(void)
|
||||
{
|
||||
for (int i = 0; i < MAX_CALLBACK_NUM; i++) {
|
||||
if (g_scanResultCb[i] != NULL) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t SoftBusUnRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
for (int i = 0; i < MAX_CALLBACK_NUM; i++) {
|
||||
if (g_scanResultCb[i] == cb) {
|
||||
g_scanResultCb[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsScanResultCbEmpty()) {
|
||||
ret = UnRegisterWifiEvent(&g_event);
|
||||
if (ret == WIFI_SUCCESS) {
|
||||
g_registerFlag = true;
|
||||
} else {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "softBus unRegister wifi event failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetChannelListFor5G(int32_t *channelList, int32_t num)
|
||||
{
|
||||
if (channelList == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "para channelList is NULL.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
int32_t ret = Hid2dGetChannelListFor5G(channelList, num);
|
||||
if (ret != WIFI_SUCCESS) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get channel 5G list failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
SoftBusBand SoftBusGetLinkBand(void)
|
||||
{
|
||||
WifiLinkedInfo result;
|
||||
GetLinkedInfo(&result);
|
||||
if (GetLinkedInfo(&result) != WIFI_SUCCESS) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get SoftBusGetLinkBand failed.");
|
||||
return BAND_UNKNOWN;
|
||||
}
|
||||
if (result.band == BAND_24G) {
|
||||
return BAND_24G;
|
||||
} else if (result.band == BAND_5G) {
|
||||
return BAND_5G;
|
||||
} else {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get SoftBusGetLinkBand success.");
|
||||
return BAND_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t SoftBusGetLinkedInfo(SoftBusWifiLinkedInfo *info)
|
||||
{
|
||||
WifiLinkedInfo result;
|
||||
if (GetLinkedInfo(&result) != WIFI_SUCCESS) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get SoftBusGetLinkedInfo failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
info->frequency = result.frequency;
|
||||
info->band = result.band;
|
||||
info->connState = SOFTBUS_API_WIFI_DISCONNECTED;
|
||||
if (result.connState == WIFI_CONNECTED) {
|
||||
info->connState = SOFTBUS_API_WIFI_CONNECTED;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetCurrentGroup(SoftBusWifiP2pGroupInfo *groupInfo)
|
||||
{
|
||||
WifiP2pGroupInfo result;
|
||||
if (GetCurrentGroup(&result) != WIFI_SUCCESS) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get SoftBusGetCurrentGroup failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (memcpy_s(groupInfo, sizeof(SoftBusWifiP2pGroupInfo), &result, sizeof(WifiP2pGroupInfo)) != EOK) {
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "softbus_wifi_api_adapter.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "securec.h"
|
||||
#include "softbus_adapter_mem.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
#include "wifi_device.h"
|
||||
#include "wifi_hid2d.h"
|
||||
#include "wifi_p2p.h"
|
||||
|
||||
static int32_t ConvertSoftBusWifiConfFromWifiDev(const WifiDeviceConfig *sourceWifiConf, SoftBusWifiDevConf *wifiConf)
|
||||
{
|
||||
if (strcpy_s(wifiConf->ssid, sizeof(wifiConf->ssid), sourceWifiConf->ssid) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "str copy ssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (memcpy_s(wifiConf->bssid, sizeof(wifiConf->bssid), sourceWifiConf->bssid,
|
||||
sizeof(sourceWifiConf->bssid)) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "mem copy bssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (strcpy_s(wifiConf->preSharedKey, sizeof(wifiConf->preSharedKey),
|
||||
sourceWifiConf->preSharedKey) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "str copy ssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
wifiConf->securityType = sourceWifiConf->securityType;
|
||||
wifiConf->isHiddenSsid = sourceWifiConf->isHiddenSsid;
|
||||
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t ConvertWifiDevConfFromSoftBusWifiConf(const SoftBusWifiDevConf *result, WifiDeviceConfig *wifiConf)
|
||||
{
|
||||
if (strcpy_s(wifiConf->ssid, sizeof(wifiConf->ssid), result->ssid) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "str copy ssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (memcpy_s(wifiConf->bssid, sizeof(wifiConf->bssid),
|
||||
result->bssid, sizeof(result->bssid)) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "mem copy bssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (strcpy_s(wifiConf->preSharedKey, sizeof(wifiConf->preSharedKey),
|
||||
result->preSharedKey) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "str copy ssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
wifiConf->securityType = result->securityType;
|
||||
wifiConf->isHiddenSsid = result->isHiddenSsid;
|
||||
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf *configList, uint32_t *num)
|
||||
{
|
||||
WifiDeviceConfig *result = NULL;
|
||||
uint32_t wifiConfigSize;
|
||||
int32_t retVal;
|
||||
uint32_t i;
|
||||
|
||||
if (configList == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "para configList is NULL");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
result = SoftBusMalloc(sizeof(WifiDeviceConfig) * WIFI_MAX_CONFIG_SIZE);
|
||||
if (result == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc wifi device config fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
(void)memset_s(result, sizeof(WifiDeviceConfig) * WIFI_MAX_CONFIG_SIZE, 0,
|
||||
sizeof(WifiDeviceConfig) * WIFI_MAX_CONFIG_SIZE);
|
||||
retVal = GetDeviceConfigs(result, &wifiConfigSize);
|
||||
if (retVal != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc wifi device config fail");
|
||||
SoftBusFree(result);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (wifiConfigSize > WIFI_MAX_CONFIG_SIZE) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "wifi device config size is invalid.");
|
||||
SoftBusFree(result);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
for (i = 0; i < wifiConfigSize; i++) {
|
||||
if (ConvertSoftBusWifiConfFromWifiDev(result, configList) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "convert wifi config failed.");
|
||||
SoftBusFree(result);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
result++;
|
||||
configList++;
|
||||
}
|
||||
*num = wifiConfigSize;
|
||||
SoftBusFree(result);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusConnectToDevice(const SoftBusWifiDevConf *wifiConfig)
|
||||
{
|
||||
WifiDeviceConfig wifiDevConfig;
|
||||
|
||||
if (wifiConfig == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "para wifiConfig is NULL");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
(void)memset_s(&wifiDevConfig, sizeof(WifiDeviceConfig), 0, sizeof(WifiDeviceConfig));
|
||||
if (ConvertWifiDevConfFromSoftBusWifiConf(wifiConfig, &wifiDevConfig) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "convert wifi config failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if (ConnectToDevice(&wifiDevConfig) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "connect to wifi failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusDisconnectDevice(void)
|
||||
{
|
||||
return Disconnect();
|
||||
}
|
||||
|
||||
static ISoftBusScanResult *g_scanResultCb[MAX_CALLBACK_NUM] = {NULL};
|
||||
static bool g_registerFlag = true;
|
||||
|
||||
int32_t SoftBusStartWifiScan(void)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
ret = Scan();
|
||||
if (ret != WIFI_SUCCESS) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "softbus start wifi scan failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void SoftBusWifiScanStateChanged(int state, int size)
|
||||
{
|
||||
for (int i = 0; i < MAX_CALLBACK_NUM; i++) {
|
||||
if (g_scanResultCb[i] != NULL) {
|
||||
g_scanResultCb[i]->onSoftBusWifiScanResult(state, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static WifiEvent g_event = {
|
||||
.OnWifiConnectionChanged = NULL,
|
||||
.OnWifiScanStateChanged = SoftBusWifiScanStateChanged,
|
||||
.OnHotspotStateChanged = NULL,
|
||||
.OnHotspotStaJoin = NULL,
|
||||
.OnHotspotStaLeave = NULL,
|
||||
};
|
||||
|
||||
static int32_t FindFreeCallbackIndex(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_CALLBACK_NUM; i++) {
|
||||
if (g_scanResultCb[i] == NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int32_t SoftBusRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
int index = FindFreeCallbackIndex();
|
||||
if (index == MAX_CALLBACK_NUM) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "register callback index invalid.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
g_scanResultCb[index] = cb;
|
||||
|
||||
if (g_registerFlag) {
|
||||
ret = RegisterWifiEvent(&g_event);
|
||||
if (ret == WIFI_SUCCESS) {
|
||||
g_registerFlag = false;
|
||||
} else {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "softbus register wifi event failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t ConvertSoftBusWifiScanInfoFromWifi(WifiScanInfo *info, SoftBusWifiScanInfo *result, uint32_t *size)
|
||||
{
|
||||
if (info == NULL || result == NULL || size == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid para");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
for (uint32_t i = 0; i < (*size); i++) {
|
||||
if (strcpy_s(result->ssid, WIFI_MAX_SSID_LEN, info->ssid) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "strcpy ssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (memcpy_s(result->bssid, WIFI_MAC_LEN, info->bssid, sizeof(info->bssid)) != EOK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy bssid fail");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
result->securityType = (int32_t)(info->securityType);
|
||||
result->rssi = (int32_t)(info->rssi);
|
||||
result->band = (int32_t)(info->band);
|
||||
result->frequency = (int32_t)(info->frequency);
|
||||
result->channelWidth = (int32_t)(info->channelWidth);
|
||||
result->centerFrequency0 =(int32_t)(info->centerFrequency0);
|
||||
result->centerFrequency1 = (int32_t)(info->centerFrequency1);
|
||||
result->timestamp = info->timestamp;
|
||||
++result;
|
||||
++info;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetWifiScanList(SoftBusWifiScanInfo **result, uint32_t *size)
|
||||
{
|
||||
if (size == NULL || result == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "para size or result is NULL.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
WifiScanInfo *info = (WifiScanInfo *)SoftBusMalloc(sizeof(WifiScanInfo) * WIFI_MAX_SCAN_HOTSPOT_LIMIT);
|
||||
if (info == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc wifi scan information failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
(void)memset_s(info, sizeof(WifiScanInfo)*WIFI_MAX_SCAN_HOTSPOT_LIMIT, 0,
|
||||
sizeof(WifiScanInfo)*WIFI_MAX_SCAN_HOTSPOT_LIMIT);
|
||||
*size = WIFI_MAX_SCAN_HOTSPOT_LIMIT;
|
||||
int32_t ret = GetScanInfoList(info, (unsigned int *)size);
|
||||
if (ret != WIFI_SUCCESS || size == 0) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "softbus get wifi scan list failed.");
|
||||
SoftBusFree(info);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
*result = (SoftBusWifiScanInfo *)SoftBusMalloc(sizeof(SoftBusWifiScanInfo) * (*size));
|
||||
if (*result == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc softbus wifi scan information failed.");
|
||||
SoftBusFree(info);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
(void)memset_s(*result, sizeof(SoftBusWifiScanInfo)* (*size), 0, sizeof(SoftBusWifiScanInfo)* (*size));
|
||||
if (ConvertSoftBusWifiScanInfoFromWifi(info, *result, size) != SOFTBUS_OK) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ConvertSoftBusWifiScaninfoFromWifi failed.");
|
||||
SoftBusFree(*result);
|
||||
*result = NULL;
|
||||
SoftBusFree(info);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
SoftBusFree(info);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static bool IsScanResultCbEmpty(void)
|
||||
{
|
||||
for (int i = 0; i < MAX_CALLBACK_NUM; i++) {
|
||||
if (g_scanResultCb[i] != NULL) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t SoftBusUnRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
for (int i = 0; i < MAX_CALLBACK_NUM; i++) {
|
||||
if (g_scanResultCb[i] == cb) {
|
||||
g_scanResultCb[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsScanResultCbEmpty()) {
|
||||
ret = UnRegisterWifiEvent(&g_event);
|
||||
if (ret == WIFI_SUCCESS) {
|
||||
g_registerFlag = true;
|
||||
} else {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "softBus unRegister wifi event failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetChannelListFor5G(int32_t *channelList, int32_t num)
|
||||
{
|
||||
if (channelList == NULL) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "para channelList is NULL.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
int32_t ret = Hid2dGetChannelListFor5G(channelList, num);
|
||||
if (ret != WIFI_SUCCESS) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get channel 5G list failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
SoftBusBand SoftBusGetLinkBand(void)
|
||||
{
|
||||
WifiLinkedInfo result;
|
||||
GetLinkedInfo(&result);
|
||||
if (GetLinkedInfo(&result) != WIFI_SUCCESS) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get SoftBusGetLinkBand failed.");
|
||||
return BAND_UNKNOWN;
|
||||
}
|
||||
if (result.band == BAND_24G) {
|
||||
return BAND_24G;
|
||||
} else if (result.band == BAND_5G) {
|
||||
return BAND_5G;
|
||||
} else {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get SoftBusGetLinkBand success.");
|
||||
return BAND_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t SoftBusGetLinkedInfo(SoftBusWifiLinkedInfo *info)
|
||||
{
|
||||
WifiLinkedInfo result;
|
||||
if (GetLinkedInfo(&result) != WIFI_SUCCESS) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get SoftBusGetLinkedInfo failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
info->frequency = result.frequency;
|
||||
info->band = result.band;
|
||||
info->connState = SOFTBUS_API_WIFI_DISCONNECTED;
|
||||
if (result.connState == WIFI_CONNECTED) {
|
||||
info->connState = SOFTBUS_API_WIFI_CONNECTED;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetCurrentGroup(SoftBusWifiP2pGroupInfo *groupInfo)
|
||||
{
|
||||
WifiP2pGroupInfo result;
|
||||
if (GetCurrentGroup(&result) != WIFI_SUCCESS) {
|
||||
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get SoftBusGetCurrentGroup failed.");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (memcpy_s(groupInfo, sizeof(SoftBusWifiP2pGroupInfo), &result, sizeof(WifiP2pGroupInfo)) != EOK) {
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
@ -1,85 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "securec.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_wifi_api_adapter.h"
|
||||
|
||||
int32_t SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf *configList, uint32_t *num)
|
||||
{
|
||||
(void)configList;
|
||||
(void)num;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusConnectToDevice(const SoftBusWifiDevConf *wifiConfig)
|
||||
{
|
||||
(void)wifiConfig;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusDisconnectDevice(void)
|
||||
{
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusStartWifiScan(void)
|
||||
{
|
||||
return SOFTBUS_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
int32_t SoftBusRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
{
|
||||
(void)cb;
|
||||
return SOFTBUS_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetWifiScanList(SoftBusWifiScanInfo **result, uint32_t *size)
|
||||
{
|
||||
(void)result;
|
||||
(void)size;
|
||||
return SOFTBUS_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
int32_t SoftBusUnRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
{
|
||||
(void)cb;
|
||||
return SOFTBUS_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetChannelListFor5G(int32_t *channelList, int32_t num)
|
||||
{
|
||||
(void)channelList;
|
||||
(void)num;
|
||||
return SOFTBUS_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
SoftBusBand SoftBusGetLinkBand(void)
|
||||
{
|
||||
return BAND_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetLinkedInfo(SoftBusWifiLinkedInfo *info)
|
||||
{
|
||||
(void)info;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetCurrentGroup(SoftBusWifiP2pGroupInfo *groupInfo)
|
||||
{
|
||||
(void)groupInfo;
|
||||
return SOFTBUS_OK;
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "securec.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_wifi_api_adapter.h"
|
||||
|
||||
int32_t SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf *configList, uint32_t *num)
|
||||
{
|
||||
(void)configList;
|
||||
(void)num;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusConnectToDevice(const SoftBusWifiDevConf *wifiConfig)
|
||||
{
|
||||
(void)wifiConfig;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusDisconnectDevice(void)
|
||||
{
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusStartWifiScan(void)
|
||||
{
|
||||
return SOFTBUS_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
int32_t SoftBusRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
{
|
||||
(void)cb;
|
||||
return SOFTBUS_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetWifiScanList(SoftBusWifiScanInfo **result, uint32_t *size)
|
||||
{
|
||||
(void)result;
|
||||
(void)size;
|
||||
return SOFTBUS_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
int32_t SoftBusUnRegisterWifiEvent(ISoftBusScanResult *cb)
|
||||
{
|
||||
(void)cb;
|
||||
return SOFTBUS_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetChannelListFor5G(int32_t *channelList, int32_t num)
|
||||
{
|
||||
(void)channelList;
|
||||
(void)num;
|
||||
return SOFTBUS_NOT_IMPLEMENT;
|
||||
}
|
||||
|
||||
SoftBusBand SoftBusGetLinkBand(void)
|
||||
{
|
||||
return BAND_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetLinkedInfo(SoftBusWifiLinkedInfo *info)
|
||||
{
|
||||
(void)info;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t SoftBusGetCurrentGroup(SoftBusWifiP2pGroupInfo *groupInfo)
|
||||
{
|
||||
(void)groupInfo;
|
||||
return SOFTBUS_OK;
|
||||
}
|
Loading…
Reference in New Issue
Block a user