• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "../wifi_common_cmd.h"
17 #include "hdf_io_service.h"
18 #include "hdf_sbuf.h"
19 #include "hilog/log.h"
20 #include "securec.h"
21 #include "wifi_driver_client.h"
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
WifiEventNewStaProcess(const char * ifName,uint32_t event,struct HdfSBuf * reqData)29 static void WifiEventNewStaProcess(const char *ifName, uint32_t event, struct HdfSBuf *reqData)
30 {
31     WifiNewStaInfo staInfo;
32     uint32_t len = 0;
33 
34     if (!HdfSbufReadInt32(reqData, &staInfo.reassoc)) {
35         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get reassoc", __FUNCTION__);
36         return;
37     }
38     if (!HdfSbufReadBuffer(reqData, (const void **)(&staInfo.ie), &staInfo.ieLen)) {
39         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get ie", __FUNCTION__);
40         return;
41     }
42     if (!HdfSbufReadBuffer(reqData, (const void **)(&staInfo.macAddr), &len) || (len != ETH_ADDR_LEN)) {
43         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get macAddr", __FUNCTION__);
44         return;
45     }
46     WifiEventReport(ifName, event, &staInfo);
47 }
48 
WifiEventDelStaProcess(const char * ifName,uint32_t event,struct HdfSBuf * reqData)49 static void WifiEventDelStaProcess(const char *ifName, uint32_t event, struct HdfSBuf *reqData)
50 {
51     uint8_t *addr = NULL;
52     uint32_t len = 0;
53 
54     if ((!HdfSbufReadBuffer(reqData, (const void **)(&addr), &len)) || (len != ETH_ADDR_LEN)) {
55         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get macAddr", __FUNCTION__);
56         return;
57     }
58     WifiEventReport(ifName, event, addr);
59 }
60 
WifiEventRxMgmtProcess(const char * ifName,uint32_t event,struct HdfSBuf * reqData)61 static void WifiEventRxMgmtProcess(const char *ifName, uint32_t event, struct HdfSBuf *reqData)
62 {
63     WifiRxMgmt rxMgmt;
64 
65     if (!HdfSbufReadInt32(reqData, &rxMgmt.freq)) {
66         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get freq", __FUNCTION__);
67         return;
68     }
69     if (!HdfSbufReadInt32(reqData, &rxMgmt.sigMbm)) {
70         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get sigMbm", __FUNCTION__);
71         return;
72     }
73     if (!HdfSbufReadBuffer(reqData, (const void **)(&rxMgmt.buf), &rxMgmt.len)) {
74         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get buf", __FUNCTION__);
75         return;
76     }
77     WifiEventReport(ifName, event, &rxMgmt);
78 }
79 
WifiEventTxStatusProcess(const char * ifName,uint32_t event,struct HdfSBuf * reqData)80 static void WifiEventTxStatusProcess(const char *ifName, uint32_t event, struct HdfSBuf *reqData)
81 {
82     WifiTxStatus txStatus;
83 
84     if (!HdfSbufReadUint8(reqData, &txStatus.ack)) {
85         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get ack", __FUNCTION__);
86         return;
87     }
88     if (!HdfSbufReadBuffer(reqData, (const void **)(&txStatus.buf), &txStatus.len)) {
89         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get buf", __FUNCTION__);
90         return;
91     }
92     WifiEventReport(ifName, event, &txStatus);
93 }
94 
WifiEventScanDoneProcess(const char * ifName,uint32_t event,struct HdfSBuf * reqData)95 static void WifiEventScanDoneProcess(const char *ifName, uint32_t event, struct HdfSBuf *reqData)
96 {
97     uint32_t status;
98 
99     if (!HdfSbufReadUint32(reqData, &status)) {
100         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get status", __FUNCTION__);
101         return;
102     }
103     WifiEventReport(ifName, event, &status);
104 }
105 
WifiEventScanResultProcess(const char * ifName,uint32_t event,struct HdfSBuf * reqData)106 static void WifiEventScanResultProcess(const char *ifName, uint32_t event, struct HdfSBuf *reqData)
107 {
108     WifiScanResult scanResult = { 0 };
109     uint32_t len = 0;
110 
111     if (!HdfSbufReadInt16(reqData, &(scanResult.beaconInt))) {
112         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get beaconInt", __FUNCTION__);
113         return;
114     }
115     if (!HdfSbufReadInt16(reqData, &(scanResult.caps))) {
116         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get caps", __FUNCTION__);
117         return;
118     }
119     if (!HdfSbufReadInt32(reqData, &(scanResult.level))) {
120         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get level", __FUNCTION__);
121         return;
122     }
123     if (!HdfSbufReadInt32(reqData, &(scanResult.freq))) {
124         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get freq", __FUNCTION__);
125         return;
126     }
127     if (!HdfSbufReadInt32(reqData, &(scanResult.flags))) {
128         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get flags", __FUNCTION__);
129         return;
130     }
131     if ((!HdfSbufReadBuffer(reqData, (const void **)(&(scanResult.bssid)), &len)) || len != ETH_ADDR_LEN) {
132         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get bssid", __FUNCTION__);
133         return;
134     }
135     if (!HdfSbufReadBuffer(reqData, (const void **)(&(scanResult.ie)), &(scanResult.ieLen))) {
136         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get ie", __FUNCTION__);
137         return;
138     }
139     if (!HdfSbufReadBuffer(reqData, (const void **)(&(scanResult.beaconIe)), &(scanResult.beaconIeLen))) {
140         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get beaconIe", __FUNCTION__);
141         return;
142     }
143     WifiEventReport(ifName, event, &scanResult);
144 }
145 
WifiEventConnectResultProcess(const char * ifName,uint32_t event,struct HdfSBuf * reqData)146 static void WifiEventConnectResultProcess(const char *ifName, uint32_t event, struct HdfSBuf *reqData)
147 {
148     WifiConnectResult result;
149     uint32_t len = 0;
150 
151     if (!HdfSbufReadUint16(reqData, &(result.status))) {
152         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get status", __FUNCTION__);
153         return;
154     }
155     if (!HdfSbufReadUint16(reqData, &(result.freq))) {
156         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get freq", __FUNCTION__);
157         return;
158     }
159     if ((!HdfSbufReadBuffer(reqData, (const void **)(&(result.bssid)), &len)) || len != ETH_ADDR_LEN) {
160         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get bssid", __FUNCTION__);
161         return;
162     }
163     if (!HdfSbufReadBuffer(reqData, (const void **)(&(result.reqIe)), &(result.reqIeLen))) {
164         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get reqIe", __FUNCTION__);
165         return;
166     }
167     if (!HdfSbufReadBuffer(reqData, (const void **)(&(result.respIe)), &(result.respIeLen))) {
168         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get respIe", __FUNCTION__);
169         return;
170     }
171     WifiEventReport(ifName, event, &result);
172 }
173 
WifiEventDisconnectProcess(const char * ifName,uint32_t event,struct HdfSBuf * reqData)174 static void WifiEventDisconnectProcess(const char *ifName, uint32_t event, struct HdfSBuf *reqData)
175 {
176     WifiDisconnect result;
177 
178     if (!HdfSbufReadUint16(reqData, &(result.reason))) {
179         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get reason", __FUNCTION__);
180         return;
181     }
182     if (!HdfSbufReadBuffer(reqData, (const void **)(&(result.ie)), &(result.ieLen))) {
183         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get bssid", __FUNCTION__);
184         return;
185     }
186     WifiEventReport(ifName, event, &result);
187 }
188 
WifiDriverEventEapolRecvProcess(const char * ifName,uint32_t event,struct HdfSBuf * reqData)189 static void WifiDriverEventEapolRecvProcess(const char *ifName, uint32_t event, struct HdfSBuf *reqData)
190 {
191     WifiEventReport(ifName, event, reqData);
192 }
193 
WifiEventResetDriverProcess(const char * ifName,int32_t event,struct HdfSBuf * reqData)194 static void WifiEventResetDriverProcess(const char *ifName, int32_t event, struct HdfSBuf *reqData)
195 {
196     unsigned char chipId;
197     int resetStatus;
198 
199     if (!HdfSbufReadInt32(reqData, &resetStatus)) {
200         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get resetStatus, line: %d", __FUNCTION__, __LINE__);
201         return;
202     }
203     if (!HdfSbufReadUint8(reqData, &chipId)) {
204         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get chipId, line: %d", __FUNCTION__, __LINE__);
205         return;
206     }
207     WifiEventReport(ifName, event, &resetStatus);
208 }
209 
WifiDriverEventRemainOnChannelProcess(const char * ifName,uint32_t event,struct HdfSBuf * reqData)210 static void WifiDriverEventRemainOnChannelProcess(const char *ifName, uint32_t event, struct HdfSBuf *reqData)
211 {
212     WifiOnChannel result = {0};
213     if (!HdfSbufReadUint32(reqData, &(result.freq))) {
214         HILOG_ERROR(LOG_DOMAIN, "%s failed to get frequence.", __FUNCTION__);
215         return;
216     }
217     if (!HdfSbufReadUint32(reqData, &(result.duration))) {
218         HILOG_ERROR(LOG_DOMAIN, "%s failed to get duration.", __FUNCTION__);
219         return;
220     }
221     WifiEventReport(ifName, event, &result);
222 }
223 
WifiDriverEventCancelRemainOnChannelProcess(const char * ifName,uint32_t event,struct HdfSBuf * reqData)224 static void WifiDriverEventCancelRemainOnChannelProcess(const char *ifName, uint32_t event, struct HdfSBuf *reqData)
225 {
226     WifiOnChannel result = {0};
227     if (!HdfSbufReadUint32(reqData, &(result.freq))) {
228         HILOG_ERROR(LOG_DOMAIN, "%s: fail to get freq", __FUNCTION__);
229         return;
230     }
231     WifiEventReport(ifName, event, &result);
232 }
233 
OnWiFiEvents(struct HdfDevEventlistener * listener,struct HdfIoService * service,uint32_t eventId,struct HdfSBuf * data)234 int OnWiFiEvents(struct HdfDevEventlistener *listener,
235     struct HdfIoService *service, uint32_t eventId, struct HdfSBuf *data)
236 {
237     (void)listener;
238     (void)service;
239     (void)data;
240 
241     if (data == NULL) {
242         HILOG_ERROR(LOG_DOMAIN, "%s: params is NULL, line: %d", __FUNCTION__, __LINE__);
243         return RET_CODE_FAILURE;
244     }
245     const char *ifName = HdfSbufReadString(data);
246     if (ifName == NULL) {
247         HILOG_ERROR(LOG_DOMAIN, "%s fail to get ifname", __FUNCTION__);
248         return RET_CODE_FAILURE;
249     }
250     HILOG_INFO(LOG_DOMAIN, "%s: WifiDriverEventProcess event=%d", __FUNCTION__, eventId);
251     switch (eventId) {
252         case WIFI_EVENT_NEW_STA:
253             WifiEventNewStaProcess(ifName, eventId, data);
254             break;
255         case WIFI_EVENT_DEL_STA:
256             WifiEventDelStaProcess(ifName, eventId, data);
257             break;
258         case WIFI_EVENT_RX_MGMT:
259             WifiEventRxMgmtProcess(ifName, eventId, data);
260             break;
261         case WIFI_EVENT_TX_STATUS:
262             WifiEventTxStatusProcess(ifName, eventId, data);
263             break;
264         case WIFI_EVENT_SCAN_DONE:
265             WifiEventScanDoneProcess(ifName, eventId, data);
266             break;
267         case WIFI_EVENT_SCAN_RESULT:
268             WifiEventScanResultProcess(ifName, eventId, data);
269             break;
270         case WIFI_EVENT_CONNECT_RESULT:
271             WifiEventConnectResultProcess(ifName, eventId, data);
272             break;
273         case WIFI_EVENT_DISCONNECT:
274             WifiEventDisconnectProcess(ifName, eventId, data);
275             break;
276         case WIFI_EVENT_EAPOL_RECV:
277             WifiDriverEventEapolRecvProcess(ifName, eventId, data);
278             break;
279         case WIFI_EVENT_RESET_DRIVER:
280             WifiEventResetDriverProcess(ifName, eventId, data);
281             break;
282         case WIFI_EVENT_REMAIN_ON_CHANNEL:
283             WifiDriverEventRemainOnChannelProcess(ifName, eventId, data);
284             break;
285         case WIFI_EVENT_CANCEL_REMAIN_ON_CHANNEL:
286             WifiDriverEventCancelRemainOnChannelProcess(ifName, eventId, data);
287             break;
288         default:
289             break;
290     }
291     return RET_CODE_SUCCESS;
292 }
293 
294 #ifdef __cplusplus
295 #if __cplusplus
296 }
297 #endif
298 #endif
299