1 /*
2 * Copyright (c) 2022 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 <stdlib.h>
17
18 #include "hdf_log.h"
19 #include "sbuf_common_adapter.h"
20 #include "securec.h"
21
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27
WifiEapolPacketSend(const char * ifName,const uint8_t * srcAddr,const uint8_t * dstAddr,uint8_t * buf,uint32_t length)28 int32_t WifiEapolPacketSend(const char *ifName, const uint8_t *srcAddr,
29 const uint8_t *dstAddr, uint8_t *buf, uint32_t length)
30 {
31 (void)srcAddr;
32 (void)dstAddr;
33 int32_t ret;
34 struct HdfSBuf *data = NULL;
35
36 if (ifName == NULL || buf == NULL) {
37 HDF_LOGE("%s: Input param is null", __FUNCTION__);
38 return RET_CODE_INVALID_PARAM;
39 }
40 data = HdfSbufObtainDefaultSize();
41 if (data == NULL) {
42 HDF_LOGE("%s: Init HdfSBuf failed", __FUNCTION__);
43 return RET_CODE_FAILURE;
44 }
45 bool isSerializeFailed = false;
46 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
47 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, buf, length);
48 if (isSerializeFailed) {
49 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
50 ret = RET_CODE_FAILURE;
51 } else {
52 ret = SendCmdSync(WIFI_WPA_CMD_SEND_EAPOL, data, NULL);
53 }
54 HdfSbufRecycle(data);
55 return ret;
56 }
57
58 #define DEFAULT_EAPOL_PACKAGE_SIZE 800
59
WifiEapolPacketReceive(const char * ifName,WifiRxEapol * rxEapol)60 int32_t WifiEapolPacketReceive(const char *ifName, WifiRxEapol *rxEapol)
61 {
62 int32_t ret;
63 WifiRxEapol eapol = {0};
64 struct HdfSBuf *data = NULL;
65 struct HdfSBuf *respData = NULL;
66
67 if (ifName == NULL || rxEapol == NULL) {
68 HDF_LOGE("%s: Input param is null", __FUNCTION__);
69 return RET_CODE_INVALID_PARAM;
70 }
71 data = HdfSbufObtainDefaultSize();
72 respData = HdfSbufObtain(DEFAULT_EAPOL_PACKAGE_SIZE);
73 do {
74 if (data == NULL || respData == NULL) {
75 HDF_LOGE("%s: Init HdfSBuf failed", __FUNCTION__);
76 ret = RET_CODE_FAILURE;
77 break;
78 }
79 if (!HdfSbufWriteString(data, ifName)) {
80 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
81 ret = RET_CODE_FAILURE;
82 break;
83 }
84 ret = SendCmdSync(WIFI_WPA_CMD_RECEIVE_EAPOL, data, respData);
85 if (ret != HDF_SUCCESS) {
86 HDF_LOGE("%s: WifiEapolPacketReceive failed ret = %d", __FUNCTION__, ret);
87 break;
88 }
89 if (!HdfSbufReadBuffer(respData, (const void **)(&(eapol.buf)), &(eapol.len))) {
90 ret = RET_CODE_FAILURE;
91 HDF_LOGE("%s: WifiEapolPacketReceive HdfSbufReadBuffer failed", __FUNCTION__);
92 break;
93 }
94 rxEapol->buf = NULL;
95 rxEapol->len = 0;
96 if (eapol.len != 0) {
97 rxEapol->buf = malloc(eapol.len);
98 if (rxEapol->buf == NULL) {
99 HDF_LOGE("%s: rxEapol->buf is null", __FUNCTION__);
100 ret = RET_CODE_FAILURE;
101 break;
102 }
103 if (memcpy_s(rxEapol->buf, eapol.len, eapol.buf, eapol.len) != EOK) {
104 HDF_LOGE("%s: memcpy failed", __FUNCTION__);
105 }
106 rxEapol->len = eapol.len;
107 }
108 } while (0);
109 HdfSbufRecycle(respData);
110 HdfSbufRecycle(data);
111 return ret;
112 }
113
WifiEapolEnable(const char * ifName)114 int32_t WifiEapolEnable(const char *ifName)
115 {
116 int32_t ret;
117 struct HdfSBuf *data = NULL;
118
119 if (ifName == NULL) {
120 HDF_LOGE("%s: Input param is null", __FUNCTION__);
121 return RET_CODE_INVALID_PARAM;
122 }
123 data = HdfSbufObtainDefaultSize();
124 if (data == NULL) {
125 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail", __FUNCTION__);
126 return RET_CODE_FAILURE;
127 }
128 if (HdfSbufWriteString(data, ifName)) {
129 ret = SendCmdSync(WIFI_WPA_CMD_ENALBE_EAPOL, data, NULL);
130 } else {
131 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
132 ret = RET_CODE_FAILURE;
133 }
134 HdfSbufRecycle(data);
135
136 return ret;
137 }
138
WifiEapolDisable(const char * ifName)139 int32_t WifiEapolDisable(const char *ifName)
140 {
141 int32_t ret;
142 struct HdfSBuf *data = NULL;
143
144 if (ifName == NULL) {
145 return RET_CODE_INVALID_PARAM;
146 }
147 data = HdfSbufObtainDefaultSize();
148 if (data == NULL) {
149 return RET_CODE_FAILURE;
150 }
151 if (HdfSbufWriteString(data, ifName)) {
152 ret = SendCmdSync(WIFI_WPA_CMD_DISABLE_EAPOL, data, NULL);
153 } else {
154 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
155 ret = RET_CODE_FAILURE;
156 }
157 HdfSbufRecycle(data);
158 return ret;
159 }
160
WifiCmdSetAp(const char * ifName,WifiApSetting * apsettings)161 int32_t WifiCmdSetAp(const char *ifName, WifiApSetting *apsettings)
162 {
163 int32_t ret;
164 struct HdfSBuf *data = NULL;
165
166 if (ifName == NULL || apsettings == NULL) {
167 HDF_LOGE("%s: Input param is null", __FUNCTION__);
168 return RET_CODE_INVALID_PARAM;
169 }
170 data = HdfSbufObtainDefaultSize();
171 if (data == NULL) {
172 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail", __FUNCTION__);
173 return RET_CODE_FAILURE;
174 }
175 bool isSerializeFailed = false;
176 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
177 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, apsettings->freqParams.mode);
178 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, apsettings->freqParams.freq);
179 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, apsettings->freqParams.channel);
180 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, apsettings->freqParams.htEnabled);
181 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, apsettings->freqParams.secChannelOffset);
182 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, apsettings->freqParams.vhtEnabled);
183 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, apsettings->freqParams.centerFreq1);
184 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, apsettings->freqParams.centerFreq2);
185 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, apsettings->freqParams.bandwidth);
186 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, apsettings->freqParams.band);
187
188 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, apsettings->beaconInterval);
189 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, apsettings->dtimPeriod);
190 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, apsettings->hiddenSsid);
191 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, apsettings->authType);
192 isSerializeFailed =
193 isSerializeFailed || !HdfSbufWriteBuffer(data, apsettings->beaconData.head, apsettings->beaconData.headLen);
194 isSerializeFailed =
195 isSerializeFailed || !HdfSbufWriteBuffer(data, apsettings->beaconData.tail, apsettings->beaconData.tailLen);
196 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, apsettings->ssid, apsettings->ssidLen);
197 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, apsettings->meshSsid, apsettings->meshSsidLen);
198 if (isSerializeFailed) {
199 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
200 ret = RET_CODE_FAILURE;
201 } else {
202 ret = SendCmdSync(WIFI_WPA_CMD_SET_AP, data, NULL);
203 }
204 HdfSbufRecycle(data);
205 return ret;
206 }
207
WifiCmdChangeBeacon(const char * ifName,WifiApSetting * apsettings)208 int32_t WifiCmdChangeBeacon(const char *ifName, WifiApSetting *apsettings)
209 {
210 int32_t ret;
211 struct HdfSBuf *data = NULL;
212
213 if (ifName == NULL || apsettings == NULL) {
214 HDF_LOGE("%s: Input param is null", __FUNCTION__);
215 return RET_CODE_INVALID_PARAM;
216 }
217 data = HdfSbufObtainDefaultSize();
218 if (data == NULL) {
219 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail", __FUNCTION__);
220 return RET_CODE_FAILURE;
221 }
222 bool isSerializeFailed = false;
223 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
224 isSerializeFailed =
225 isSerializeFailed || !HdfSbufWriteBuffer(data, apsettings->beaconData.head, apsettings->beaconData.headLen);
226 isSerializeFailed =
227 isSerializeFailed || !HdfSbufWriteBuffer(data, apsettings->beaconData.tail, apsettings->beaconData.tailLen);
228 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, apsettings->ssid, apsettings->ssidLen);
229 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, apsettings->meshSsid, apsettings->meshSsidLen);
230 if (isSerializeFailed) {
231 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
232 ret = RET_CODE_FAILURE;
233 } else {
234 ret = SendCmdSync(WIFI_WPA_CMD_CHANGE_BEACON, data, NULL);
235 }
236 HdfSbufRecycle(data);
237 return ret;
238 }
239
WifiCmdSendMlme(const char * ifName,WifiMlmeData * mlme)240 int32_t WifiCmdSendMlme(const char *ifName, WifiMlmeData *mlme)
241 {
242 int32_t ret;
243 struct HdfSBuf *data = NULL;
244
245 if (ifName == NULL || mlme == NULL) {
246 return RET_CODE_INVALID_PARAM;
247 }
248 data = HdfSbufObtainDefaultSize();
249 if (data == NULL) {
250 return RET_CODE_FAILURE;
251 }
252 bool isSerializeFailed = false;
253 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
254 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, mlme, sizeof(WifiMlmeData));
255 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, mlme->data, mlme->dataLen);
256 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, mlme->cookie, sizeof(*mlme->cookie));
257 if (isSerializeFailed) {
258 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
259 ret = RET_CODE_FAILURE;
260 } else {
261 ret = SendCmdSync(WIFI_WPA_CMD_SEND_MLME, data, NULL);
262 }
263 HdfSbufRecycle(data);
264 return ret;
265 }
266
WifiCmdOperKey(const char * ifName,uint32_t cmd,WifiKeyExt * keyExt)267 static int32_t WifiCmdOperKey(const char *ifName, uint32_t cmd, WifiKeyExt *keyExt)
268 {
269 int32_t ret;
270 struct HdfSBuf *data = NULL;
271
272 if (ifName == NULL || keyExt == NULL) {
273 HDF_LOGE("%s: Input param is null", __FUNCTION__);
274 return RET_CODE_INVALID_PARAM;
275 }
276 data = HdfSbufObtainDefaultSize();
277 if (data == NULL) {
278 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail", __FUNCTION__);
279 return RET_CODE_FAILURE;
280 }
281 bool isSerializeFailed = false;
282 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
283 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, keyExt->type);
284 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint32(data, keyExt->keyIdx);
285 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint32(data, keyExt->cipher);
286 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, keyExt->def);
287 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, keyExt->defMgmt);
288 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, keyExt->defaultTypes);
289 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, keyExt->resv);
290 if (keyExt->addr == NULL) {
291 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, keyExt->addr, 0);
292 } else {
293 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, keyExt->addr, ETH_ADDR_LEN);
294 }
295 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, keyExt->key, keyExt->keyLen);
296 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, keyExt->seq, keyExt->seqLen);
297 if (isSerializeFailed) {
298 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
299 ret = RET_CODE_FAILURE;
300 } else {
301 ret = SendCmdSync(cmd, data, NULL);
302 }
303 HdfSbufRecycle(data);
304 return ret;
305 }
306
WifiCmdDelKey(const char * ifName,WifiKeyExt * keyExt)307 int32_t WifiCmdDelKey(const char *ifName, WifiKeyExt *keyExt)
308 {
309 return WifiCmdOperKey(ifName, WIFI_WPA_CMD_DEL_KEY, keyExt);
310 }
311
WifiCmdNewKey(const char * ifName,WifiKeyExt * keyExt)312 int32_t WifiCmdNewKey(const char *ifName, WifiKeyExt *keyExt)
313 {
314 return WifiCmdOperKey(ifName, WIFI_WPA_CMD_NEW_KEY, keyExt);
315 }
316
WifiCmdSetKey(const char * ifName,WifiKeyExt * keyExt)317 int32_t WifiCmdSetKey(const char *ifName, WifiKeyExt *keyExt)
318 {
319 return WifiCmdOperKey(ifName, WIFI_WPA_CMD_SET_KEY, keyExt);
320 }
321
WifiCmdSetMode(const char * ifName,WifiSetMode * setMode)322 int32_t WifiCmdSetMode(const char *ifName, WifiSetMode *setMode)
323 {
324 int32_t ret;
325 struct HdfSBuf *data = NULL;
326
327 if (ifName == NULL || setMode == NULL) {
328 HDF_LOGE("%s: Input param is null", __FUNCTION__);
329 return RET_CODE_INVALID_PARAM;
330 }
331 data = HdfSbufObtainDefaultSize();
332 if (data == NULL) {
333 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail", __FUNCTION__);
334 return RET_CODE_FAILURE;
335 }
336 bool isSerializeFailed = false;
337 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
338 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, setMode, sizeof(*setMode));
339 if (isSerializeFailed) {
340 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
341 ret = RET_CODE_FAILURE;
342 } else {
343 ret = SendCmdSync(WIFI_WPA_CMD_SET_MODE, data, NULL);
344 }
345 HdfSbufRecycle(data);
346 HDF_LOGD("%s: WifiCmdSetMode finished! ret=%d", __FUNCTION__, ret);
347 return ret;
348 }
349
WifiCmdGetOwnMac(const char * ifName,char * buf,uint32_t len)350 int32_t WifiCmdGetOwnMac(const char *ifName, char *buf, uint32_t len)
351 {
352 int32_t ret;
353 struct HdfSBuf *data = NULL;
354 struct HdfSBuf *reply = NULL;
355
356 if (ifName == NULL || buf == NULL) {
357 HDF_LOGE("%s: Input param is null", __FUNCTION__);
358 return RET_CODE_INVALID_PARAM;
359 }
360 data = HdfSbufObtainDefaultSize();
361 reply = HdfSbufObtainDefaultSize();
362 do {
363 if (data == NULL || reply == NULL) {
364 HDF_LOGE("%s: At least one param is null", __FUNCTION__);
365 ret = RET_CODE_FAILURE;
366 break;
367 }
368 if (HdfSbufWriteString(data, ifName)) {
369 ret = SendCmdSync(WIFI_WPA_CMD_GET_ADDR, data, reply);
370 } else {
371 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
372 ret = RET_CODE_FAILURE;
373 }
374 if (ret != RET_CODE_SUCCESS) {
375 ret = RET_CODE_FAILURE;
376 break;
377 }
378 uint32_t replayDataSize = 0;
379 const uint8_t *replayData = 0;
380 if (!HdfSbufReadBuffer(reply, (const void **)(&replayData), &replayDataSize) ||
381 replayDataSize != ETH_ADDR_LEN) {
382 HDF_LOGE("%s: fail or data size mismatch", __FUNCTION__);
383 ret = RET_CODE_FAILURE;
384 break;
385 }
386 if (memcpy_s(buf, len, replayData, replayDataSize) != EOK) {
387 HDF_LOGE("%s: memcpy failed", __FUNCTION__);
388 ret = RET_CODE_FAILURE;
389 }
390 } while (0);
391 HdfSbufRecycle(reply);
392 HdfSbufRecycle(data);
393 return ret;
394 }
395
WifiCmdGetHwFeature(const char * ifName,WifiHwFeatureData * hwFeatureData)396 int32_t WifiCmdGetHwFeature(const char *ifName, WifiHwFeatureData *hwFeatureData)
397 {
398 int32_t ret;
399 struct HdfSBuf *data = NULL;
400 struct HdfSBuf *reply = NULL;
401
402 if (ifName == NULL || hwFeatureData == NULL) {
403 HDF_LOGE("%s: Input param is null", __FUNCTION__);
404 return RET_CODE_INVALID_PARAM;
405 }
406 data = HdfSbufObtainDefaultSize();
407 reply = HdfSbufObtain(sizeof(WifiHwFeatureData) + sizeof(uint64_t));
408 do {
409 if (data == NULL || reply == NULL) {
410 HDF_LOGE("%s: At least one param is null", __FUNCTION__);
411 ret = RET_CODE_FAILURE;
412 break;
413 }
414 if (HdfSbufWriteString(data, ifName)) {
415 ret = SendCmdSync(WIFI_WPA_CMD_GET_HW_FEATURE, data, reply);
416 } else {
417 HDF_LOGE("%s: HdfSbufWriteString failed", __FUNCTION__);
418 ret = RET_CODE_FAILURE;
419 }
420 if (ret != RET_CODE_SUCCESS) {
421 ret = RET_CODE_FAILURE;
422 break;
423 }
424 const WifiHwFeatureData *respFeaturenData = NULL;
425 uint32_t dataSize = 0;
426 if (!HdfSbufReadBuffer(reply, (const void **)(&respFeaturenData), &dataSize) ||
427 dataSize != sizeof(WifiHwFeatureData)) {
428 HDF_LOGE("%s: HdfSbufReadBuffer failed or unexpect dataSize", __FUNCTION__);
429 ret = RET_CODE_FAILURE;
430 break;
431 }
432 if (memcpy_s(hwFeatureData, sizeof(WifiHwFeatureData), respFeaturenData, dataSize) != EOK) {
433 HDF_LOGE("%s: memcpy failed", __FUNCTION__);
434 ret = RET_CODE_FAILURE;
435 }
436 } while (0);
437 HdfSbufRecycle(reply);
438 HdfSbufRecycle(data);
439 return ret;
440 }
441
WifiCmdDisconnet(const char * ifName,int32_t reasonCode)442 int32_t WifiCmdDisconnet(const char *ifName, int32_t reasonCode)
443 {
444 int32_t ret;
445 struct HdfSBuf *data = NULL;
446
447 if (ifName == NULL) {
448 HDF_LOGE("%s: Input param is null", __FUNCTION__);
449 return RET_CODE_INVALID_PARAM;
450 }
451 data = HdfSbufObtainDefaultSize();
452 if (data == NULL) {
453 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail", __FUNCTION__);
454 return RET_CODE_FAILURE;
455 }
456 bool isSerializeFailed = false;
457 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
458 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint16(data, reasonCode);
459 if (isSerializeFailed) {
460 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
461 ret = RET_CODE_FAILURE;
462 } else {
463 ret = SendCmdSync(WIFI_WPA_CMD_DISCONNECT, data, NULL);
464 }
465 HdfSbufRecycle(data);
466 return ret;
467 }
468
WifiCmdAssoc(const char * ifName,WifiAssociateParams * assocParams)469 int32_t WifiCmdAssoc(const char *ifName, WifiAssociateParams *assocParams)
470 {
471 int32_t ret;
472 struct HdfSBuf *data = NULL;
473
474 if (ifName == NULL || assocParams == NULL) {
475 HDF_LOGE("%s: Input param is null!", __FUNCTION__);
476 return RET_CODE_INVALID_PARAM;
477 }
478 data = HdfSbufObtainDefaultSize();
479 if (data == NULL) {
480 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail!", __FUNCTION__);
481 return RET_CODE_FAILURE;
482 }
483 bool isSerializeFailed = false;
484 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
485 if (assocParams->bssid == NULL) {
486 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, assocParams->bssid, 0);
487 } else {
488 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, assocParams->bssid, ETH_ADDR_LEN);
489 }
490 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, assocParams->ssid, assocParams->ssidLen);
491 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, assocParams->ie, assocParams->ieLen);
492 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, assocParams->key, assocParams->keyLen);
493 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, assocParams->authType);
494 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, assocParams->privacy);
495 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, assocParams->keyIdx);
496 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, assocParams->mfp);
497 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint32(data, assocParams->freq);
498 isSerializeFailed =
499 isSerializeFailed || !HdfSbufWriteBuffer(data, assocParams->crypto, sizeof(assocParams->crypto[0]));
500 if (isSerializeFailed) {
501 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
502 ret = RET_CODE_FAILURE;
503 } else {
504 ret = SendCmdSync(WIFI_WPA_CMD_ASSOC, data, NULL);
505 }
506 HdfSbufRecycle(data);
507 return ret;
508 }
509
WifiCmdSetNetdev(const char * ifName,WifiSetNewDev * info)510 int32_t WifiCmdSetNetdev(const char *ifName, WifiSetNewDev *info)
511 {
512 int32_t ret;
513 struct HdfSBuf *data = NULL;
514
515 if (ifName == NULL || info == NULL) {
516 HDF_LOGE("%s: Input param is null!", __FUNCTION__);
517 return RET_CODE_INVALID_PARAM;
518 }
519 data = HdfSbufObtainDefaultSize();
520 if (data == NULL) {
521 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail!", __FUNCTION__);
522 return RET_CODE_FAILURE;
523 }
524 bool isSerializeFailed = false;
525 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
526 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, info, sizeof(WifiSetNewDev));
527 if (isSerializeFailed) {
528 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
529 ret = RET_CODE_FAILURE;
530 } else {
531 ret = SendCmdSync(WIFI_WPA_CMD_SET_NETDEV, data, NULL);
532 }
533 HdfSbufRecycle(data);
534 return ret;
535 }
536
WifiCmdStaRemove(const char * ifName,const uint8_t * addr,uint32_t addrLen)537 int32_t WifiCmdStaRemove(const char *ifName, const uint8_t *addr, uint32_t addrLen)
538 {
539 int32_t ret;
540 struct HdfSBuf *data = NULL;
541
542 if (ifName == NULL || addr == NULL) {
543 return RET_CODE_INVALID_PARAM;
544 }
545 data = HdfSbufObtainDefaultSize();
546 if (data == NULL) {
547 return RET_CODE_FAILURE;
548 }
549 bool isSerializeFailed = false;
550 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
551 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, addr, addrLen);
552 if (isSerializeFailed) {
553 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
554 ret = RET_CODE_FAILURE;
555 } else {
556 ret = SendCmdSync(WIFI_WPA_CMD_STA_REMOVE, data, NULL);
557 }
558 HdfSbufRecycle(data);
559 return ret;
560 }
561
WifiCmdSendAction(const char * ifName,WifiActionData * actionData)562 int32_t WifiCmdSendAction(const char *ifName, WifiActionData *actionData)
563 {
564 int32_t ret;
565 struct HdfSBuf *data = NULL;
566
567 if (ifName == NULL || actionData == NULL) {
568 HDF_LOGE("%s: input parameter invalid!", __FUNCTION__);
569 return RET_CODE_INVALID_PARAM;
570 }
571 data = HdfSbufObtainDefaultSize();
572 if (data == NULL) {
573 HDF_LOGE("%s: Init HdfSBuf failed", __FUNCTION__);
574 return RET_CODE_FAILURE;
575 }
576 bool isSerializeFailed = false;
577 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
578
579 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, actionData->bssid, ETH_ADDR_LEN);
580 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, actionData->dst, ETH_ADDR_LEN);
581 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, actionData->src, ETH_ADDR_LEN);
582 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, actionData->data, actionData->dataLen);
583 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint32(data, actionData->freq);
584 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint32(data, actionData->wait);
585 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, actionData->noCck);
586 if (isSerializeFailed) {
587 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
588 ret = RET_CODE_FAILURE;
589 } else {
590 ret = SendCmdSync(WIFI_WPA_CMD_SEND_ACTION, data, NULL);
591 }
592 HdfSbufRecycle(data);
593 return ret;
594 }
595
WifiCmdSetClient(uint32_t clientNum)596 int32_t WifiCmdSetClient(uint32_t clientNum)
597 {
598 int32_t ret;
599 struct HdfSBuf *data = NULL;
600
601 data = HdfSbufObtainDefaultSize();
602 if (data == NULL) {
603 HDF_LOGE("%s: Init HdfSBuf failed", __FUNCTION__);
604 return RET_CODE_FAILURE;
605 }
606 if (!HdfSbufWriteUint32(data, clientNum)) {
607 HDF_LOGE("%s: sbuf write failed!", __FUNCTION__);
608 ret = RET_CODE_FAILURE;
609 } else {
610 ret = SendCmdSync(WIFI_CLIENT_CMD_SET_CLIENT, data, NULL);
611 }
612 HdfSbufRecycle(data);
613 return ret;
614 }
615
WifiCmdProbeReqReport(const char * ifName,const int32_t * report)616 int32_t WifiCmdProbeReqReport(const char *ifName, const int32_t *report)
617 {
618 if (ifName == NULL || report == NULL) {
619 HDF_LOGE("%s: input parameter invalid!", __FUNCTION__);
620 return RET_CODE_INVALID_PARAM;
621 }
622 struct HdfSBuf *data = HdfSbufObtainDefaultSize();
623 if (data == NULL) {
624 HDF_LOGE("%s: Init HdfSBuf failed", __FUNCTION__);
625 return RET_CODE_FAILURE;
626 }
627 bool isSerializeFailed = false;
628 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
629 isSerializeFailed = isSerializeFailed || !HdfSbufWriteInt32(data, *report);
630 int32_t ret;
631 if (isSerializeFailed) {
632 HDF_LOGE("Serialize failed.");
633 ret = RET_CODE_FAILURE;
634 } else {
635 ret = SendCmdSync(WIFI_WPA_CMD_PROBE_REQ_REPORT, data, NULL);
636 }
637 HdfSbufRecycle(data);
638 return ret;
639 }
640
WifiCmdRemainOnChannel(const char * ifName,const WifiOnChannel * onChannel)641 int32_t WifiCmdRemainOnChannel(const char *ifName, const WifiOnChannel *onChannel)
642 {
643 if (ifName == NULL || onChannel == NULL) {
644 HDF_LOGE("%s: input parameter invalid!", __FUNCTION__);
645 return RET_CODE_INVALID_PARAM;
646 }
647 struct HdfSBuf *data = HdfSbufObtainDefaultSize();
648 if (data == NULL) {
649 HDF_LOGE("%s: Init HdfSBuf failed", __FUNCTION__);
650 return RET_CODE_FAILURE;
651 }
652 bool isSerializeFailed = false;
653 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
654 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint32(data, onChannel->freq);
655 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint32(data, onChannel->duration);
656 int32_t ret;
657 if (isSerializeFailed) {
658 HDF_LOGE("Serialize failed.");
659 ret = RET_CODE_FAILURE;
660 } else {
661 ret = SendCmdSync(WIFI_WPA_CMD_REMAIN_ON_CHANNEL, data, NULL);
662 HdfSbufRecycle(data);
663 return ret;
664 }
665 HdfSbufRecycle(data);
666 return ret;
667 }
668
WifiCmdCancelRemainOnChannel(const char * ifName)669 int32_t WifiCmdCancelRemainOnChannel(const char *ifName)
670 {
671 if (ifName == NULL) {
672 HDF_LOGE("%s: input parameter invalid!", __FUNCTION__);
673 return RET_CODE_INVALID_PARAM;
674 }
675 struct HdfSBuf *data = HdfSbufObtainDefaultSize();
676 if (data == NULL) {
677 HDF_LOGE("%s: Init HdfSBuf failed", __FUNCTION__);
678 return RET_CODE_FAILURE;
679 }
680 bool isSerializeFailed = false;
681 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
682 int32_t ret;
683 if (isSerializeFailed) {
684 HDF_LOGE("Serialize failed.");
685 ret = RET_CODE_FAILURE;
686 } else {
687 ret = SendCmdSync(WIFI_WPA_CMD_CANCEL_REMAIN_ON_CHANNEL, data, NULL);
688 HdfSbufRecycle(data);
689 return ret;
690 }
691 HdfSbufRecycle(data);
692 return ret;
693 }
694
WifiCmdAddIf(const char * ifName,const WifiIfAdd * ifAdd)695 int32_t WifiCmdAddIf(const char *ifName, const WifiIfAdd *ifAdd)
696 {
697 if (ifName == NULL || ifAdd == NULL) {
698 HDF_LOGE("%s: input parameter invalid!", __FUNCTION__);
699 return RET_CODE_INVALID_PARAM;
700 }
701 struct HdfSBuf *data = HdfSbufObtainDefaultSize();
702 if (data == NULL) {
703 HDF_LOGE("%s: Init HdfSBuf failed", __FUNCTION__);
704 return RET_CODE_FAILURE;
705 }
706 bool isSerializeFailed = false;
707 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
708 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, ifAdd, sizeof(WifiIfAdd));
709 int32_t ret;
710 if (isSerializeFailed) {
711 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
712 ret = RET_CODE_FAILURE;
713 } else {
714 ret = SendCmdSync(WIFI_WPA_CMD_ADD_IF, data, NULL);
715 }
716 HdfSbufRecycle(data);
717 return ret;
718 }
719
WifiCmdRemoveIf(const char * ifName,const WifiIfRemove * ifRemove)720 int32_t WifiCmdRemoveIf(const char *ifName, const WifiIfRemove *ifRemove)
721 {
722 if (ifName == NULL || ifRemove == NULL) {
723 HDF_LOGE("%s: input parameter invalid!", __FUNCTION__);
724 return RET_CODE_INVALID_PARAM;
725 }
726 struct HdfSBuf *data = HdfSbufObtainDefaultSize();
727 if (data == NULL) {
728 HDF_LOGE("%s: Init HdfSBuf failed", __FUNCTION__);
729 return RET_CODE_FAILURE;
730 }
731 bool isSerializeFailed = false;
732 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
733 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, ifRemove, sizeof(WifiIfRemove));
734 int32_t ret;
735 if (isSerializeFailed) {
736 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
737 ret = RET_CODE_FAILURE;
738 } else {
739 ret = SendCmdSync(WIFI_WPA_CMD_REMOVE_IF, data, NULL);
740 }
741 HdfSbufRecycle(data);
742 return ret;
743 }
744
WifiCmdSetApWpsP2pIe(const char * ifName,const WifiAppIe * appIe)745 int32_t WifiCmdSetApWpsP2pIe(const char *ifName, const WifiAppIe *appIe)
746 {
747 if (ifName == NULL || appIe == NULL) {
748 HDF_LOGE("%s: input parameter invalid!", __FUNCTION__);
749 return RET_CODE_INVALID_PARAM;
750 }
751 struct HdfSBuf *data = HdfSbufObtainDefaultSize();
752 if (data == NULL) {
753 HDF_LOGE("%s: Init HdfSBuf failed", __FUNCTION__);
754 return RET_CODE_FAILURE;
755 }
756 bool isSerializeFailed = false;
757 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
758 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint32(data, appIe->ieLen);
759 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, appIe->appIeType);
760 if (appIe->ie == NULL) {
761 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, appIe->ie, 0);
762 } else {
763 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, appIe->ie, appIe->ieLen);
764 }
765 int32_t ret;
766 if (isSerializeFailed) {
767 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
768 ret = RET_CODE_FAILURE;
769 } else {
770 ret = SendCmdSync(WIFI_WPA_CMD_SET_AP_WPS_P2P_IE, data, NULL);
771 }
772 HdfSbufRecycle(data);
773 return ret;
774 }
775
WifiCmdGetDrvFlags(const char * ifName,WifiGetDrvFlags * params)776 int32_t WifiCmdGetDrvFlags(const char *ifName, WifiGetDrvFlags *params)
777 {
778 int32_t ret;
779
780 if (ifName == NULL || params == NULL) {
781 HDF_LOGE("%s: input parameter invalid!", __FUNCTION__);
782 return RET_CODE_INVALID_PARAM;
783 }
784 struct HdfSBuf *data = HdfSbufObtainDefaultSize();
785 struct HdfSBuf *reply = HdfSbufObtainDefaultSize();
786 do {
787 if (data == NULL || reply == NULL) {
788 HDF_LOGE("%s: Init HdfSBuf failed", __FUNCTION__);
789 ret = RET_CODE_FAILURE;
790 break;
791 }
792
793 if (!HdfSbufWriteString(data, ifName)) {
794 HDF_LOGE("%s: HdfSbufWriteString failed!", __FUNCTION__);
795 ret = RET_CODE_FAILURE;
796 break;
797 }
798 ret = SendCmdSync(WIFI_WPA_CMD_GET_DRIVER_FLAGS, data, reply);
799 if (ret != RET_CODE_SUCCESS) {
800 ret = RET_CODE_FAILURE;
801 break;
802 }
803 if (!HdfSbufReadUint64(reply, &(params->drvFlags))) {
804 ret = RET_CODE_FAILURE;
805 break;
806 }
807 } while (0);
808 HdfSbufRecycle(reply);
809 HdfSbufRecycle(data);
810 return ret;
811 }
812
813 #ifdef __cplusplus
814 #if __cplusplus
815 }
816 #endif
817 #endif
818