• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "wlan_param_monitor.h"
10 
11 #include "hdf_dsoftbus_driver.h"
12 #include "hdf_log.h"
13 #include "module_manager.h"
14 #include "osal_time.h"
15 
16 #define HDF_LOG_TAG "wlan_param_monitor"
17 
18 #define WLAN_PARAM_REPORT_INTERVAL 1000
19 
20 typedef enum {
21     CMD_REQUEST_PARAM = 0,
22     CMD_MAX_INDEX
23 } Command;
24 
25 typedef enum {
26     EVENT_WLAN_PARAM = 0,
27     EVENT_MAX_INDEX
28 } Event;
29 
30 typedef struct {
31     uint32_t event;
32     uint32_t value;
33 } ReportInfo;
34 
ProcessRequestParam(void)35 static void ProcessRequestParam(void)
36 {
37     ReportInfo info;
38     struct HdfSBuf *data = NULL;
39 
40     info.event = EVENT_WLAN_PARAM;
41     info.value = (uint32_t)OsalGetSysTimeMs();
42     data = HdfSbufObtainDefaultSize();
43     if (data == NULL) {
44         HDF_LOGE("get sbuf fail");
45         return;
46     }
47     if (!HdfSbufWriteBuffer(data, (const void *)&info, sizeof(info))) {
48         HDF_LOGE("sbuf write report value fail");
49         HdfSbufRecycle(data);
50         return;
51     }
52     HdfSoftbusBroadcastEvent(SOFTBUS_MODULE_WLAN_PARAM_MONITOR, data);
53     HdfSbufRecycle(data);
54 }
55 
SoftbusWlanParamMonitorInit(struct HdfDeviceObject * device)56 int32_t SoftbusWlanParamMonitorInit(struct HdfDeviceObject *device)
57 {
58     (void)device;
59     HDF_LOGI("SoftbusWlanParamMonitorInit init");
60     return HDF_SUCCESS;
61 }
62 
SoftbusWlanParamMonitorProcess(const struct HdfSBuf * reqData,struct HdfSBuf * rspData)63 void SoftbusWlanParamMonitorProcess(const struct HdfSBuf *reqData, struct HdfSBuf *rspData)
64 {
65     uint32_t cmd;
66     const void *data = NULL;
67     uint32_t dataSize;
68 
69     (void)rspData;
70     if (reqData == NULL) {
71         HDF_LOGE("reqData is null");
72         return;
73     }
74     if (!HdfSbufReadBuffer((struct HdfSBuf *)reqData, &data, &dataSize)) {
75         HDF_LOGE("read command fail");
76         return;
77     }
78     cmd = *((uint32_t *)data);
79     HDF_LOGI("process command: %d", cmd);
80     if (cmd == CMD_REQUEST_PARAM) {
81         ProcessRequestParam();
82     }
83 }