From 3afc7bb5d4f2725981486bebbff5276705b48dc3 Mon Sep 17 00:00:00 2001 From: fanxiaoyu Date: Mon, 6 Sep 2021 01:25:14 +0000 Subject: [PATCH 1/4] Description:add dsoftbus kernel driver module Feature or Bugfix:Feature Binary Source: No Signed-off-by: fanxiaoyu --- .../dsoftbus/include/hdf_dsoftbus_driver.h | 25 ++++ model/misc/dsoftbus/include/module_manager.h | 44 ++++++ .../dsoftbus/include/wlan_param_monitor.h | 27 ++++ model/misc/dsoftbus/src/hdf_dsoftbus_driver.c | 74 +++++++++ model/misc/dsoftbus/src/module_manager.c | 84 +++++++++++ model/misc/dsoftbus/src/wlan_param_monitor.c | 141 ++++++++++++++++++ 6 files changed, 395 insertions(+) create mode 100644 model/misc/dsoftbus/include/hdf_dsoftbus_driver.h create mode 100644 model/misc/dsoftbus/include/module_manager.h create mode 100644 model/misc/dsoftbus/include/wlan_param_monitor.h create mode 100644 model/misc/dsoftbus/src/hdf_dsoftbus_driver.c create mode 100644 model/misc/dsoftbus/src/module_manager.c create mode 100644 model/misc/dsoftbus/src/wlan_param_monitor.c diff --git a/model/misc/dsoftbus/include/hdf_dsoftbus_driver.h b/model/misc/dsoftbus/include/hdf_dsoftbus_driver.h new file mode 100644 index 000000000..f3d0c9a98 --- /dev/null +++ b/model/misc/dsoftbus/include/hdf_dsoftbus_driver.h @@ -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 \ No newline at end of file diff --git a/model/misc/dsoftbus/include/module_manager.h b/model/misc/dsoftbus/include/module_manager.h new file mode 100644 index 000000000..bacb5d0ef --- /dev/null +++ b/model/misc/dsoftbus/include/module_manager.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)(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, struct HdfSBuf *reqData, struct HdfSBuf *rspData); + +#ifdef __cplusplus +} +#endif + +#endif // SOFTBUS_MODULE_MANAGER_H \ No newline at end of file diff --git a/model/misc/dsoftbus/include/wlan_param_monitor.h b/model/misc/dsoftbus/include/wlan_param_monitor.h new file mode 100644 index 000000000..5f17a42a4 --- /dev/null +++ b/model/misc/dsoftbus/include/wlan_param_monitor.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(struct HdfSBuf *reqData, struct HdfSBuf *rspData); + +#ifdef __cplusplus +} +#endif + +#endif // SOFTBUS_WLAN_PARAM_MONITOR_H \ No newline at end of file diff --git a/model/misc/dsoftbus/src/hdf_dsoftbus_driver.c b/model/misc/dsoftbus/src/hdf_dsoftbus_driver.c new file mode 100644 index 000000000..1a136079b --- /dev/null +++ b/model/misc/dsoftbus/src/hdf_dsoftbus_driver.c @@ -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" + +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); \ No newline at end of file diff --git a/model/misc/dsoftbus/src/module_manager.c b/model/misc/dsoftbus/src/module_manager.c new file mode 100644 index 000000000..a134dee61 --- /dev/null +++ b/model/misc/dsoftbus/src/module_manager.c @@ -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, 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 = 0; + + 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 = 0; + + 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"); +} \ No newline at end of file diff --git a/model/misc/dsoftbus/src/wlan_param_monitor.c b/model/misc/dsoftbus/src/wlan_param_monitor.c new file mode 100644 index 000000000..46dbb6db1 --- /dev/null +++ b/model/misc/dsoftbus/src/wlan_param_monitor.c @@ -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(struct HdfSBuf *reqData, struct HdfSBuf *rspData) +{ + uint32_t cmd; + const void *data = NULL; + uint32_t dataSize; + + if (reqData == NULL) { + HDF_LOGE("reqData is null"); + return; + } + if (!HdfSbufReadBuffer(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; + } +} \ No newline at end of file -- Gitee From 1982aca045e1b0bbefdf21c942ef50ae1f483cdf Mon Sep 17 00:00:00 2001 From: fanxiaoyu Date: Mon, 6 Sep 2021 02:02:50 +0000 Subject: [PATCH 2/4] Description:clear codex Feature or Bugfix:Feature Binary Source: No Signed-off-by: fanxiaoyu --- model/misc/dsoftbus/include/module_manager.h | 2 +- .../dsoftbus/include/wlan_param_monitor.h | 2 +- model/misc/dsoftbus/src/module_manager.c | 6 ++--- model/misc/dsoftbus/src/wlan_param_monitor.c | 23 +++++++++---------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/model/misc/dsoftbus/include/module_manager.h b/model/misc/dsoftbus/include/module_manager.h index bacb5d0ef..e1ef7dbda 100644 --- a/model/misc/dsoftbus/include/module_manager.h +++ b/model/misc/dsoftbus/include/module_manager.h @@ -35,7 +35,7 @@ typedef struct { int32_t SoftbusModuleManagerInit(struct HdfDeviceObject *device); void SoftbusModuleManagerDeinit(void); -void SoftbusDispatchModuleCommand(int32_t moduleId, struct HdfSBuf *reqData, struct HdfSBuf *rspData); +void SoftbusDispatchModuleCommand(int32_t moduleId, const struct HdfSBuf *reqData, struct HdfSBuf *rspData); #ifdef __cplusplus } diff --git a/model/misc/dsoftbus/include/wlan_param_monitor.h b/model/misc/dsoftbus/include/wlan_param_monitor.h index 5f17a42a4..96eae6b15 100644 --- a/model/misc/dsoftbus/include/wlan_param_monitor.h +++ b/model/misc/dsoftbus/include/wlan_param_monitor.h @@ -18,7 +18,7 @@ extern "C" { int32_t SoftbusWlanParamMonitorInit(struct HdfDeviceObject *device); void SoftbusWlanParamMonitorDeinit(void); -void SoftbusWlanParamMonitorProcess(struct HdfSBuf *reqData, struct HdfSBuf *rspData); +void SoftbusWlanParamMonitorProcess(const struct HdfSBuf *reqData, struct HdfSBuf *rspData); #ifdef __cplusplus } diff --git a/model/misc/dsoftbus/src/module_manager.c b/model/misc/dsoftbus/src/module_manager.c index a134dee61..ea9f741bb 100644 --- a/model/misc/dsoftbus/src/module_manager.c +++ b/model/misc/dsoftbus/src/module_manager.c @@ -25,7 +25,7 @@ static SoftbusDriverModule g_modules[] = { #endif }; -void SoftbusDispatchModuleCommand(int32_t moduleId, struct HdfSBuf *reqData, struct HdfSBuf *rspData) +void SoftbusDispatchModuleCommand(int32_t moduleId, const struct HdfSBuf *reqData, struct HdfSBuf *rspData) { int32_t i; @@ -45,7 +45,7 @@ void SoftbusDispatchModuleCommand(int32_t moduleId, struct HdfSBuf *reqData, str int32_t SoftbusModuleManagerInit(struct HdfDeviceObject *device) { - int32_t i = 0; + int32_t i; for (i = 0; i < HDF_ARRAY_SIZE(g_modules); ++i) { if (g_modules[i].init == NULL) { @@ -72,7 +72,7 @@ int32_t SoftbusModuleManagerInit(struct HdfDeviceObject *device) void SoftbusModuleManagerDeinit(void) { - int32_t i = 0; + int32_t i; for (i = 0; i < HDF_ARRAY_SIZE(g_modules); ++i) { if (g_modules[i].deinit == NULL) { diff --git a/model/misc/dsoftbus/src/wlan_param_monitor.c b/model/misc/dsoftbus/src/wlan_param_monitor.c index 46dbb6db1..35dc7cecb 100644 --- a/model/misc/dsoftbus/src/wlan_param_monitor.c +++ b/model/misc/dsoftbus/src/wlan_param_monitor.c @@ -111,7 +111,7 @@ void SoftbusWlanParamMonitorDeinit(void) } } -void SoftbusWlanParamMonitorProcess(struct HdfSBuf *reqData, struct HdfSBuf *rspData) +void SoftbusWlanParamMonitorProcess(const struct HdfSBuf *reqData, struct HdfSBuf *rspData) { uint32_t cmd; const void *data = NULL; @@ -121,21 +121,20 @@ void SoftbusWlanParamMonitorProcess(struct HdfSBuf *reqData, struct HdfSBuf *rsp HDF_LOGE("reqData is null"); return; } - if (!HdfSbufReadBuffer(reqData, &data, &dataSize)) { + 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; + switch (cmd) { + case CMD_START_MONITOR: + ProcessStartMonitor(); + break; + case CMD_STOP_MONITOR: + ProcessStopMonitor(); + break; + default: + break; } } \ No newline at end of file -- Gitee From 570b6047c6e8330ebcb82f3ade98102b9ab85535 Mon Sep 17 00:00:00 2001 From: fanxiaoyu Date: Mon, 6 Sep 2021 02:23:42 +0000 Subject: [PATCH 3/4] Description:clear codex Feature or Bugfix:Feature Binary Source: No Signed-off-by: fanxiaoyu --- model/misc/dsoftbus/src/hdf_dsoftbus_driver.c | 2 +- model/misc/dsoftbus/src/wlan_param_monitor.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/model/misc/dsoftbus/src/hdf_dsoftbus_driver.c b/model/misc/dsoftbus/src/hdf_dsoftbus_driver.c index 1a136079b..c837ced89 100644 --- a/model/misc/dsoftbus/src/hdf_dsoftbus_driver.c +++ b/model/misc/dsoftbus/src/hdf_dsoftbus_driver.c @@ -13,7 +13,7 @@ #define HDF_LOG_TAG "hdf_dsoftbus" -struct HdfDeviceObject *g_hdfDevObj = NULL; +static struct HdfDeviceObject *g_hdfDevObj = NULL; int32_t HdfSoftbusBroadcastEvent(uint32_t moudleId, const struct HdfSBuf *data) { diff --git a/model/misc/dsoftbus/src/wlan_param_monitor.c b/model/misc/dsoftbus/src/wlan_param_monitor.c index 35dc7cecb..07eeb8309 100644 --- a/model/misc/dsoftbus/src/wlan_param_monitor.c +++ b/model/misc/dsoftbus/src/wlan_param_monitor.c @@ -117,6 +117,7 @@ void SoftbusWlanParamMonitorProcess(const struct HdfSBuf *reqData, struct HdfSBu const void *data = NULL; uint32_t dataSize; + (void)rspData; if (reqData == NULL) { HDF_LOGE("reqData is null"); return; -- Gitee From 9d153746a3753acc0624c636ff6fe203ee5aac70 Mon Sep 17 00:00:00 2001 From: fanxiaoyu Date: Mon, 6 Sep 2021 03:28:54 +0000 Subject: [PATCH 4/4] Description:add dsoftbus kernel driver module Feature or Bugfix:Feature Binary Source: No Signed-off-by: fanxiaoyu --- model/misc/dsoftbus/include/module_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/misc/dsoftbus/include/module_manager.h b/model/misc/dsoftbus/include/module_manager.h index e1ef7dbda..a59ef5fe1 100644 --- a/model/misc/dsoftbus/include/module_manager.h +++ b/model/misc/dsoftbus/include/module_manager.h @@ -24,7 +24,7 @@ typedef enum { typedef int32_t (*SoftbusDriverModuleInit)(struct HdfDeviceObject *device); typedef void (*SoftbusDriverModuleDeinit)(void); -typedef void (*SoftbusDriverModuleProcess)(struct HdfSBuf *reqData, struct HdfSBuf *rspData); +typedef void (*SoftbusDriverModuleProcess)(const struct HdfSBuf *reqData, struct HdfSBuf *rspData); typedef struct { int32_t moduleId; -- Gitee