mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-08-27 20:49:55 -04:00
!228 Add dsoftbus kernel driver module
Merge pull request !228 from steve/master
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef HDF_DSOFTBUS_DRIVER_H
|
||||
#define HDF_DSOFTBUS_DRIVER_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_sbuf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t HdfSoftbusBroadcastEvent(uint32_t moudleId, const struct HdfSBuf *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HDF_DSOFTBUS_DRIVER_H
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef SOFTBUS_MODULE_MANAGER_H
|
||||
#define SOFTBUS_MODULE_MANAGER_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_sbuf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_MODULE_WLAN_PARAM_MONITOR = 0,
|
||||
SOFTBUS_MODULE_MAX_INDEX,
|
||||
} SoftbusDriverModuleId;
|
||||
|
||||
typedef int32_t (*SoftbusDriverModuleInit)(struct HdfDeviceObject *device);
|
||||
typedef void (*SoftbusDriverModuleDeinit)(void);
|
||||
typedef void (*SoftbusDriverModuleProcess)(const struct HdfSBuf *reqData, struct HdfSBuf *rspData);
|
||||
|
||||
typedef struct {
|
||||
int32_t moduleId;
|
||||
SoftbusDriverModuleInit init;
|
||||
SoftbusDriverModuleDeinit deinit;
|
||||
SoftbusDriverModuleProcess process;
|
||||
} SoftbusDriverModule;
|
||||
|
||||
int32_t SoftbusModuleManagerInit(struct HdfDeviceObject *device);
|
||||
void SoftbusModuleManagerDeinit(void);
|
||||
void SoftbusDispatchModuleCommand(int32_t moduleId, const struct HdfSBuf *reqData, struct HdfSBuf *rspData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SOFTBUS_MODULE_MANAGER_H
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef SOFTBUS_WLAN_PARAM_MONITOR_H
|
||||
#define SOFTBUS_WLAN_PARAM_MONITOR_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t SoftbusWlanParamMonitorInit(struct HdfDeviceObject *device);
|
||||
void SoftbusWlanParamMonitorDeinit(void);
|
||||
void SoftbusWlanParamMonitorProcess(const struct HdfSBuf *reqData, struct HdfSBuf *rspData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SOFTBUS_WLAN_PARAM_MONITOR_H
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_log.h"
|
||||
#include "module_manager.h"
|
||||
|
||||
#define HDF_LOG_TAG "hdf_dsoftbus"
|
||||
|
||||
static struct HdfDeviceObject *g_hdfDevObj = NULL;
|
||||
|
||||
int32_t HdfSoftbusBroadcastEvent(uint32_t moudleId, const struct HdfSBuf *data)
|
||||
{
|
||||
if (g_hdfDevObj == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HdfDeviceSendEvent(g_hdfDevObj, moudleId, data);
|
||||
}
|
||||
|
||||
static int32_t DispatchCommand(struct HdfDeviceIoClient *client, int moduleId,
|
||||
struct HdfSBuf *reqData, struct HdfSBuf *rspData)
|
||||
{
|
||||
(void)client;
|
||||
SoftbusDispatchModuleCommand(moduleId, reqData, rspData);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t HdfSoftbusDriverBind(struct HdfDeviceObject *dev)
|
||||
{
|
||||
static struct IDeviceIoService softbusService = {
|
||||
.object.objectId = 1,
|
||||
.Dispatch = DispatchCommand,
|
||||
};
|
||||
|
||||
if (dev == NULL) {
|
||||
HDF_LOGE("hdf device object is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
dev->service = &softbusService;
|
||||
HDF_LOGE("softbus driver bind success");
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t HdfSoftbusDriverInit(struct HdfDeviceObject *device)
|
||||
{
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("device object is null");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
g_hdfDevObj = device;
|
||||
return SoftbusModuleManagerInit(device);
|
||||
}
|
||||
|
||||
static void HdfSoftbusDriverRelease(struct HdfDeviceObject *object)
|
||||
{
|
||||
(void)object;
|
||||
HDF_LOGE("softbus driver release success");
|
||||
}
|
||||
|
||||
static struct HdfDriverEntry g_hdfSoftbusEntry = {
|
||||
.moduleVersion = 1,
|
||||
.Bind = HdfSoftbusDriverBind,
|
||||
.Init = HdfSoftbusDriverInit,
|
||||
.Release = HdfSoftbusDriverRelease,
|
||||
.moduleName = "HDF_DSOFTBUS"
|
||||
};
|
||||
|
||||
HDF_INIT(g_hdfSoftbusEntry);
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "module_manager.h"
|
||||
|
||||
#include "hdf_log.h"
|
||||
#ifdef ENABLE_WLAN_PARAM_MONITOR
|
||||
#include "wlan_param_monitor.h"
|
||||
#endif
|
||||
|
||||
#define HDF_LOG_TAG "hdf_dsoftbus"
|
||||
|
||||
static SoftbusDriverModule g_modules[] = {
|
||||
#ifdef ENABLE_WLAN_PARAM_MONITOR
|
||||
{
|
||||
.init = SoftbusWlanParamMonitorInit,
|
||||
.deinit = SoftbusWlanParamMonitorDeinit,
|
||||
.process = SoftbusWlanParamMonitorProcess,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
void SoftbusDispatchModuleCommand(int32_t moduleId, const struct HdfSBuf *reqData, struct HdfSBuf *rspData)
|
||||
{
|
||||
int32_t i;
|
||||
|
||||
for (i = 0; i < HDF_ARRAY_SIZE(g_modules); ++i) {
|
||||
if (g_modules[i].moduleId != moduleId) {
|
||||
continue;
|
||||
}
|
||||
if (g_modules[i].process == NULL) {
|
||||
HDF_LOGE("module(%d) no process function", moduleId);
|
||||
break;
|
||||
}
|
||||
g_modules[i].process(reqData, rspData);
|
||||
return;
|
||||
}
|
||||
HDF_LOGE("no moduleId: %d registered", moduleId);
|
||||
}
|
||||
|
||||
int32_t SoftbusModuleManagerInit(struct HdfDeviceObject *device)
|
||||
{
|
||||
int32_t i;
|
||||
|
||||
for (i = 0; i < HDF_ARRAY_SIZE(g_modules); ++i) {
|
||||
if (g_modules[i].init == NULL) {
|
||||
HDF_LOGE("module(%d) is no init function", g_modules[i].moduleId);
|
||||
break;
|
||||
}
|
||||
if (g_modules[i].init(device) != HDF_SUCCESS) {
|
||||
HDF_LOGE("init module(%d) fail", g_modules[i].moduleId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i < HDF_ARRAY_SIZE(g_modules)) {
|
||||
for (i = i - 1; i >= 0; --i) {
|
||||
if (g_modules[i].deinit == NULL) {
|
||||
continue;
|
||||
}
|
||||
g_modules[i].deinit();
|
||||
}
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HDF_LOGE("init softbus module manager success");
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void SoftbusModuleManagerDeinit(void)
|
||||
{
|
||||
int32_t i;
|
||||
|
||||
for (i = 0; i < HDF_ARRAY_SIZE(g_modules); ++i) {
|
||||
if (g_modules[i].deinit == NULL) {
|
||||
continue;
|
||||
}
|
||||
g_modules[i].deinit();
|
||||
}
|
||||
HDF_LOGE("deinit softbus module manager");
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "wlan_param_monitor.h"
|
||||
|
||||
#include "hdf_dsoftbus_driver.h"
|
||||
#include "hdf_log.h"
|
||||
#include "module_manager.h"
|
||||
#include "osal_time.h"
|
||||
#include "osal_timer.h"
|
||||
|
||||
#define HDF_LOG_TAG "wlan_param_monitor"
|
||||
|
||||
#define WLAN_PARAM_REPORT_INTERVAL 1000
|
||||
|
||||
typedef enum {
|
||||
CMD_START_MONITOR = 0,
|
||||
CMD_STOP_MONITOR,
|
||||
CMD_MAX_INDEX
|
||||
} Command;
|
||||
|
||||
typedef enum {
|
||||
EVENT_WLAN_PARAM = 0,
|
||||
EVENT_MAX_INDEX
|
||||
} Event;
|
||||
|
||||
typedef struct {
|
||||
OSAL_DECLARE_TIMER(timer);
|
||||
bool isTimerStart;
|
||||
} WlanParamMonitorCtrl;
|
||||
|
||||
typedef struct {
|
||||
uint32_t event;
|
||||
uint32_t value;
|
||||
} ReportInfo;
|
||||
|
||||
static WlanParamMonitorCtrl g_wlanParamMonitorCtrl = {
|
||||
.isTimerStart = false,
|
||||
};
|
||||
|
||||
static void WlanParamReportTimer(uintptr_t arg)
|
||||
{
|
||||
ReportInfo info;
|
||||
struct HdfSBuf *data = NULL;
|
||||
|
||||
(void)arg;
|
||||
info.event = EVENT_WLAN_PARAM;
|
||||
info.value = (uint32_t)OsalGetSysTimeMs();
|
||||
data = HdfSBufObtainDefaultSize();
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("get sbuf fail");
|
||||
return;
|
||||
}
|
||||
if (!HdfSbufWriteBuffer(data, (const void *)&info, sizeof(info))) {
|
||||
HDF_LOGE("sbuf write report value fail");
|
||||
HdfSBufRecycle(data);
|
||||
return;
|
||||
}
|
||||
HdfSoftbusBroadcastEvent(SOFTBUS_MODULE_WLAN_PARAM_MONITOR, data);
|
||||
HdfSBufRecycle(data);
|
||||
}
|
||||
|
||||
static void ProcessStartMonitor(void)
|
||||
{
|
||||
if (g_wlanParamMonitorCtrl.isTimerStart) {
|
||||
HDF_LOGE("wlan param monitor timer is already started");
|
||||
return;
|
||||
}
|
||||
if (OsalTimerCreate(&g_wlanParamMonitorCtrl.timer, WLAN_PARAM_REPORT_INTERVAL,
|
||||
WlanParamReportTimer, 0) != HDF_SUCCESS) {
|
||||
HDF_LOGE("create wlan param monitor timer fail");
|
||||
return;
|
||||
}
|
||||
if (OsalTimerStartLoop(&g_wlanParamMonitorCtrl.timer) != HDF_SUCCESS) {
|
||||
OsalTimerDelete(&g_wlanParamMonitorCtrl.timer);
|
||||
HDF_LOGE("start wlan param monitor timer fail");
|
||||
return;
|
||||
}
|
||||
g_wlanParamMonitorCtrl.isTimerStart = true;
|
||||
}
|
||||
|
||||
static void ProcessStopMonitor(void)
|
||||
{
|
||||
if (!g_wlanParamMonitorCtrl.isTimerStart) {
|
||||
HDF_LOGE("wlan param monitor timer is not started");
|
||||
return;
|
||||
}
|
||||
if (OsalTimerDelete(&g_wlanParamMonitorCtrl.timer) != HDF_SUCCESS) {
|
||||
HDF_LOGE("delete wlan param monitor timer fail");
|
||||
} else {
|
||||
g_wlanParamMonitorCtrl.isTimerStart = false;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t SoftbusWlanParamMonitorInit(struct HdfDeviceObject *device)
|
||||
{
|
||||
(void)device;
|
||||
HDF_LOGI("SoftbusWlanParamMonitorInit init");
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void SoftbusWlanParamMonitorDeinit(void)
|
||||
{
|
||||
if (g_wlanParamMonitorCtrl.isTimerStart) {
|
||||
ProcessStartMonitor();
|
||||
}
|
||||
}
|
||||
|
||||
void SoftbusWlanParamMonitorProcess(const struct HdfSBuf *reqData, struct HdfSBuf *rspData)
|
||||
{
|
||||
uint32_t cmd;
|
||||
const void *data = NULL;
|
||||
uint32_t dataSize;
|
||||
|
||||
(void)rspData;
|
||||
if (reqData == NULL) {
|
||||
HDF_LOGE("reqData is null");
|
||||
return;
|
||||
}
|
||||
if (!HdfSbufReadBuffer((struct HdfSBuf *)reqData, &data, &dataSize)) {
|
||||
HDF_LOGE("read command fail");
|
||||
return;
|
||||
}
|
||||
cmd = *((uint32_t *)data);
|
||||
HDF_LOGI("process command: %d", cmd);
|
||||
switch (cmd) {
|
||||
case CMD_START_MONITOR:
|
||||
ProcessStartMonitor();
|
||||
break;
|
||||
case CMD_STOP_MONITOR:
|
||||
ProcessStopMonitor();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user