1 /*
2 * Copyright (c) 2023 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 #include "wpa_common_cmd.h"
16 #include "wpa_p2p_cmd.h"
17 #include "hdi_wpa_common.h"
18 #include <securec.h>
19 #include <hdf_base.h>
20 #include <hdf_log.h>
21 #include <osal_time.h>
22 #include <osal_mem.h>
23 #include <arpa/inet.h>
24 #include "utils/common.h"
25 #include "wpa_supplicant_i.h"
26 #include "main.h"
27 #include "wps_supplicant.h"
28 #include "p2p_supplicant.h"
29 #include "ctrl_iface.h"
30 #include "wpa_magiclink.h"
31 #include "wifi_display.h"
32 #include "bssid_ignore.h"
33 #include "config.h"
34 #include "v1_1/iwpa_callback.h"
35 #include "v1_1/iwpa_interface.h"
36 #include "wpa_p2p_hal.h"
37
38 #define HEX_TO_DEC_MOVING 4
39 #define DEC_MAX_SCOPE 10
40 #define MIN_MAC_LEN 6
41
42 struct HdiWpaKeyValue {
43 char key[CMD_SIZE];
44 char value[CMD_SIZE];
45 };
46
GetStrKeyVal(char * src,const char * split,struct HdiWpaKeyValue * out)47 void GetStrKeyVal(char *src, const char *split, struct HdiWpaKeyValue *out)
48 {
49 if (src == NULL || split == NULL || out == NULL) {
50 return;
51 }
52 char *p = strstr(src, split);
53 if (p == NULL) {
54 if (strcpy_s(out->key, sizeof(out->key), src) != EOK) {
55 HDF_LOGE("%{public}s strcpy failed", __func__);
56 }
57 return;
58 }
59 *p = '\0';
60 if (strcpy_s(out->key, sizeof(out->key), src) != EOK) {
61 HDF_LOGE("%{public}s strcpy failed", __func__);
62 }
63 p += strlen(split);
64 if (strcpy_s(out->value, sizeof(out->value), p) != EOK) {
65 HDF_LOGE("%{public}s strcpy failed", __func__);
66 }
67 return;
68 }
69
GetHalNetworkInfos(char * buf,struct HdiP2pNetworkInfo * info)70 void GetHalNetworkInfos(char *buf, struct HdiP2pNetworkInfo *info)
71 {
72 if (buf == NULL || info == NULL) {
73 return;
74 }
75 int len = strlen(buf);
76 int start = 0;
77 int end = 0;
78 int i = 0;
79 const int count = 2;
80 while (end < len) {
81 if (buf[end] != '\t') {
82 ++end;
83 continue;
84 }
85 buf[end] = '\0';
86 if (i == 0) {
87 info->id = atoi(buf);
88 } else if (i == 1) {
89 if (strcpy_s((char *)info->ssid, WIFI_SSID_LENGTH + 1, buf + start) != EOK) {
90 break;
91 }
92 printf_decode((u8 *)info->ssid, WIFI_SSID_LENGTH + 1, (char *)info->ssid);
93 } else if (i == count) {
94 uint8_t tmpBssid[ETH_ADDR_LEN] = {0};
95 hwaddr_aton(buf + start, tmpBssid);
96 if (memcpy_s((char *)info->bssid, ETH_ADDR_LEN, (char *)tmpBssid, ETH_ADDR_LEN) != EOK) {
97 break;
98 }
99 info->bssid[ETH_ADDR_LEN] = '\0';
100 start = end + 1;
101 if (strcpy_s((char *)info->flags, WIFI_NETWORK_FLAGS_LENGTH + 1, buf + start) != EOK) {
102 break;
103 }
104 break;
105 }
106 ++i;
107 end++;
108 start = end;
109 }
110 return;
111 }
112
WpaInterfaceP2pSetSsidPostfixName(struct IWpaInterface * self,const char * ifName,const char * name)113 int32_t WpaInterfaceP2pSetSsidPostfixName(struct IWpaInterface *self, const char *ifName, const char *name)
114 {
115 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
116 (void)self;
117 if (ifName == NULL || name == NULL) {
118 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
119 return HDF_ERR_INVALID_PARAM;
120 }
121 pthread_mutex_lock(GetInterfaceLock());
122 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
123 if (pMainIfc == NULL) {
124 pthread_mutex_unlock(GetInterfaceLock());
125 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
126 return HDF_ERR_INVALID_PARAM;
127 }
128 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdSetSsidPostfixName(pMainIfc, name);
129 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
130 pthread_mutex_unlock(GetInterfaceLock());
131 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
132 return HDF_FAILURE;
133 }
134 pthread_mutex_unlock(GetInterfaceLock());
135 HDF_LOGI("%{public}s success", __func__);
136 return HDF_SUCCESS;
137 }
138
WpaInterfaceP2pSetWpsDeviceType(struct IWpaInterface * self,const char * ifName,const char * type)139 int32_t WpaInterfaceP2pSetWpsDeviceType(struct IWpaInterface *self, const char *ifName, const char *type)
140 {
141 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
142 (void)self;
143 if (ifName == NULL || type == NULL) {
144 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
145 return HDF_ERR_INVALID_PARAM;
146 }
147 pthread_mutex_lock(GetInterfaceLock());
148 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
149 if (pMainIfc == NULL) {
150 pthread_mutex_unlock(GetInterfaceLock());
151 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
152 return HDF_ERR_INVALID_PARAM;
153 }
154 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdSetWpsDeviceType(pMainIfc, type);
155 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
156 pthread_mutex_unlock(GetInterfaceLock());
157 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
158 return HDF_FAILURE;
159 }
160 pthread_mutex_unlock(GetInterfaceLock());
161 HDF_LOGI("%{public}s success", __func__);
162 return HDF_SUCCESS;
163 }
164
WpaInterfaceP2pSetWpsConfigMethods(struct IWpaInterface * self,const char * ifName,const char * methods)165 int32_t WpaInterfaceP2pSetWpsConfigMethods(struct IWpaInterface *self, const char *ifName, const char *methods)
166 {
167 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
168 (void)self;
169 if (ifName == NULL || methods == NULL) {
170 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
171 return HDF_ERR_INVALID_PARAM;
172 }
173 pthread_mutex_lock(GetInterfaceLock());
174 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
175 if (pMainIfc == NULL) {
176 pthread_mutex_unlock(GetInterfaceLock());
177 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
178 return HDF_ERR_INVALID_PARAM;
179 }
180 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdSetWpsConfigMethods(pMainIfc, methods);
181 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
182 pthread_mutex_unlock(GetInterfaceLock());
183 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
184 return HDF_FAILURE;
185 }
186 pthread_mutex_unlock(GetInterfaceLock());
187 HDF_LOGI("%{public}s success", __func__);
188 return HDF_SUCCESS;
189 }
190
WpaInterfaceP2pSetGroupMaxIdle(struct IWpaInterface * self,const char * ifName,int32_t time)191 int32_t WpaInterfaceP2pSetGroupMaxIdle(struct IWpaInterface *self, const char *ifName, int32_t time)
192 {
193 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
194 (void)self;
195 if (ifName == NULL) {
196 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
197 return HDF_ERR_INVALID_PARAM;
198 }
199 pthread_mutex_lock(GetInterfaceLock());
200 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
201 if (pMainIfc == NULL) {
202 pthread_mutex_unlock(GetInterfaceLock());
203 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
204 return HDF_ERR_INVALID_PARAM;
205 }
206 WifiWpaP2pGroupInterface *pGroupIfc = GetWifiWpaP2pGroupInterface(ifName);
207 if (pGroupIfc == NULL) {
208 pthread_mutex_unlock(GetInterfaceLock());
209 HDF_LOGE("%{public}s: pGroupIfc is null", __func__);
210 return HDF_ERR_INVALID_PARAM;
211 }
212 P2pSupplicantErrCode ret = pGroupIfc->wpaP2pCliCmdSetGroupIdle(pGroupIfc, time);
213 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
214 pthread_mutex_unlock(GetInterfaceLock());
215 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
216 return HDF_FAILURE;
217 }
218 pthread_mutex_unlock(GetInterfaceLock());
219 HDF_LOGI("%{public}s success", __func__);
220 return HDF_SUCCESS;
221 }
222
WpaInterfaceP2pSetWfdEnable(struct IWpaInterface * self,const char * ifName,int32_t enable)223 int32_t WpaInterfaceP2pSetWfdEnable(struct IWpaInterface *self, const char *ifName, int32_t enable)
224 {
225 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
226 (void)self;
227 (void)ifName;
228 pthread_mutex_lock(GetInterfaceLock());
229 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
230 if (pMainIfc == NULL) {
231 pthread_mutex_unlock(GetInterfaceLock());
232 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
233 return HDF_ERR_INVALID_PARAM;
234 }
235 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdSetWfdEnable(pMainIfc, enable);
236 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
237 pthread_mutex_unlock(GetInterfaceLock());
238 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
239 return HDF_FAILURE;
240 }
241 pthread_mutex_unlock(GetInterfaceLock());
242 HDF_LOGI("%{public}s success", __func__);
243 return HDF_SUCCESS;
244 }
245
WpaInterfaceP2pSetPersistentReconnect(struct IWpaInterface * self,const char * ifName,int32_t status)246 int32_t WpaInterfaceP2pSetPersistentReconnect(struct IWpaInterface *self, const char *ifName, int32_t status)
247 {
248 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
249 (void)self;
250 (void)ifName;
251 pthread_mutex_lock(GetInterfaceLock());
252 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
253 if (pMainIfc == NULL) {
254 pthread_mutex_unlock(GetInterfaceLock());
255 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
256 return HDF_ERR_INVALID_PARAM;
257 }
258 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdSetPersistentReconnect(pMainIfc, status);
259 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
260 pthread_mutex_unlock(GetInterfaceLock());
261 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
262 return HDF_FAILURE;
263 }
264 pthread_mutex_unlock(GetInterfaceLock());
265 HDF_LOGI("%{public}s success", __func__);
266 return HDF_SUCCESS;
267 }
268
WpaInterfaceP2pSetWpsSecondaryDeviceType(struct IWpaInterface * self,const char * ifName,const char * type)269 int32_t WpaInterfaceP2pSetWpsSecondaryDeviceType(struct IWpaInterface *self, const char *ifName, const char *type)
270 {
271 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
272 (void)self;
273 if (ifName == NULL || type == NULL) {
274 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
275 return HDF_ERR_INVALID_PARAM;
276 }
277 pthread_mutex_lock(GetInterfaceLock());
278 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
279 if (pMainIfc == NULL) {
280 pthread_mutex_unlock(GetInterfaceLock());
281 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
282 return HDF_ERR_INVALID_PARAM;
283 }
284 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdSetWpsSecDeviceType(pMainIfc, type);
285 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
286 pthread_mutex_unlock(GetInterfaceLock());
287 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
288 return HDF_FAILURE;
289 }
290 pthread_mutex_unlock(GetInterfaceLock());
291 HDF_LOGI("%{public}s success", __func__);
292 return HDF_SUCCESS;
293 }
294
WpaInterfaceP2pSetupWpsPbc(struct IWpaInterface * self,const char * ifName,const char * address)295 int32_t WpaInterfaceP2pSetupWpsPbc(struct IWpaInterface *self, const char *ifName, const char *address)
296 {
297 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
298 (void)self;
299 if (ifName == NULL || address == NULL) {
300 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
301 return HDF_ERR_INVALID_PARAM;
302 }
303 pthread_mutex_lock(GetInterfaceLock());
304 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
305 if (pMainIfc == NULL) {
306 pthread_mutex_unlock(GetInterfaceLock());
307 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
308 return HDF_ERR_INVALID_PARAM;
309 }
310 WifiWpaP2pGroupInterface *pGroupIfc = GetWifiWpaP2pGroupInterface(ifName);
311 if (pGroupIfc == NULL) {
312 pthread_mutex_unlock(GetInterfaceLock());
313 HDF_LOGE("%{public}s: pGroupIfc is null", __func__);
314 return HDF_ERR_INVALID_PARAM;
315 }
316 P2pSupplicantErrCode ret = pGroupIfc->wpaP2pCliCmdWpsPbc(pGroupIfc, address);
317 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
318 pthread_mutex_unlock(GetInterfaceLock());
319 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
320 return HDF_FAILURE;
321 }
322 pthread_mutex_unlock(GetInterfaceLock());
323 HDF_LOGI("%{public}s success", __func__);
324 return HDF_SUCCESS;
325 }
326
WpaInterfaceP2pSetupWpsPin(struct IWpaInterface * self,const char * ifName,const char * address,const char * pin,char * result,uint32_t resultLen)327 int32_t WpaInterfaceP2pSetupWpsPin(struct IWpaInterface *self, const char *ifName, const char *address,
328 const char *pin, char *result, uint32_t resultLen)
329 {
330 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
331 (void)self;
332 if (ifName == NULL || address == NULL || pin == NULL || result == NULL || resultLen == 0) {
333 HDF_LOGE("%{public}s groupIfc, address, pin and result have NULL", __func__);
334 return HDF_FAILURE;
335 }
336
337 P2pWpsPinDisplayArgv p2pWpsPinDisplay = {0};
338 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
339 WifiWpaP2pGroupInterface *pGroupIfc = GetWifiWpaP2pGroupInterface(ifName);
340 if (pMainIfc == NULL || pGroupIfc == NULL) {
341 HDF_LOGE("%{public}s: pMainIfc or pGroupIfc is null", __func__);
342 return HDF_ERR_INVALID_PARAM;
343 }
344 P2pSupplicantErrCode ret = pGroupIfc->wpaP2pCliCmdWpsPin(pGroupIfc, &p2pWpsPinDisplay);
345 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
346 HDF_LOGE("WpaP2pCliCmdWpsPin fail, ret = %{public}d", ret);
347 return HDF_FAILURE;
348 }
349 if (strlen(pin) > 0) {
350 p2pWpsPinDisplay.mode = P2P_PIN_KEYPAD;
351 if (strncpy_s(p2pWpsPinDisplay.pinCode, sizeof(p2pWpsPinDisplay.pinCode), pin, strlen(pin)) != EOK) {
352 HDF_LOGE("%{public}s: Failed to init pin code, the input pin code may be invalid!", __func__);
353 return HDF_FAILURE;
354 }
355 } else {
356 p2pWpsPinDisplay.mode = P2P_PIN_DISPLAY;
357 if ((strncpy_s(p2pWpsPinDisplay.bssid, sizeof(p2pWpsPinDisplay.bssid), address, strlen(address)) != EOK) ||
358 (strncpy_s(result, resultLen, p2pWpsPinDisplay.pinCode, strlen(p2pWpsPinDisplay.pinCode)) != EOK)) {
359 HDF_LOGE("%{public}s: Failed to init request message, the input message may be invalid!", __func__);
360 return HDF_FAILURE;
361 }
362 }
363 HDF_LOGI("%{public}s success", __func__);
364 return HDF_SUCCESS;
365 }
366
WpaInterfaceP2pSetPowerSave(struct IWpaInterface * self,const char * ifName,int32_t enable)367 int32_t WpaInterfaceP2pSetPowerSave(struct IWpaInterface *self, const char *ifName, int32_t enable)
368 {
369 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
370 (void)self;
371 if (ifName == NULL) {
372 HDF_LOGE("P2pSetPowerSave, groupIfc is NULL");
373 return HDF_FAILURE;
374 }
375 pthread_mutex_lock(GetInterfaceLock());
376 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
377 if (pMainIfc == NULL) {
378 pthread_mutex_unlock(GetInterfaceLock());
379 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
380 return HDF_ERR_INVALID_PARAM;
381 }
382 WifiWpaP2pGroupInterface *pGroupIfc = GetWifiWpaP2pGroupInterface(ifName);
383 if (pGroupIfc == NULL) {
384 pthread_mutex_unlock(GetInterfaceLock());
385 HDF_LOGE("%{public}s: pGroupIfc is null", __func__);
386 return HDF_ERR_INVALID_PARAM;
387 }
388 P2pSupplicantErrCode ret = pGroupIfc->wpaP2pCliCmdSetPowerSave(pGroupIfc, enable);
389 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
390 pthread_mutex_unlock(GetInterfaceLock());
391 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
392 return HDF_FAILURE;
393 }
394 pthread_mutex_unlock(GetInterfaceLock());
395 HDF_LOGI("%{public}s success", __func__);
396 return HDF_SUCCESS;
397 }
398
WpaInterfaceP2pSetDeviceName(struct IWpaInterface * self,const char * ifName,const char * name)399 int32_t WpaInterfaceP2pSetDeviceName(struct IWpaInterface *self, const char *ifName, const char *name)
400 {
401 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
402 (void)self;
403 if (ifName == NULL || name == NULL) {
404 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
405 return HDF_ERR_INVALID_PARAM;
406 }
407 pthread_mutex_lock(GetInterfaceLock());
408 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
409 if (pMainIfc == NULL) {
410 pthread_mutex_unlock(GetInterfaceLock());
411 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
412 return HDF_ERR_INVALID_PARAM;
413 }
414 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdSetWpsName(pMainIfc, name);
415 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
416 pthread_mutex_unlock(GetInterfaceLock());
417 HDF_LOGE("%{public}s fail, ret = %{public}d", __func__, ret);
418 return HDF_FAILURE;
419 }
420 pthread_mutex_unlock(GetInterfaceLock());
421 HDF_LOGI("%{public}s success", __func__);
422 return HDF_SUCCESS;
423 }
424
WpaInterfaceP2pSetWfdDeviceConfig(struct IWpaInterface * self,const char * ifName,const char * config)425 int32_t WpaInterfaceP2pSetWfdDeviceConfig(struct IWpaInterface *self, const char *ifName, const char *config)
426 {
427 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
428 (void)self;
429 if (ifName == NULL || config == NULL) {
430 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
431 return HDF_ERR_INVALID_PARAM;
432 }
433 pthread_mutex_lock(GetInterfaceLock());
434 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
435 if (pMainIfc == NULL) {
436 pthread_mutex_unlock(GetInterfaceLock());
437 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
438 return HDF_ERR_INVALID_PARAM;
439 }
440 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdSetWfdDeviceInfo(pMainIfc, config);
441 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
442 pthread_mutex_unlock(GetInterfaceLock());
443 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
444 return HDF_FAILURE;
445 }
446 pthread_mutex_unlock(GetInterfaceLock());
447 HDF_LOGI("%{public}s success", __func__);
448 return HDF_SUCCESS;
449 }
450
WpaInterfaceP2pSetRandomMac(struct IWpaInterface * self,const char * ifName,int32_t networkId)451 int32_t WpaInterfaceP2pSetRandomMac(struct IWpaInterface *self, const char *ifName, int32_t networkId)
452 {
453 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
454 (void)self;
455 (void)ifName;
456 pthread_mutex_lock(GetInterfaceLock());
457 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
458 if (pMainIfc == NULL) {
459 pthread_mutex_unlock(GetInterfaceLock());
460 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
461 return HDF_ERR_INVALID_PARAM;
462 }
463 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdSetRandomMac(pMainIfc, networkId);
464 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
465 pthread_mutex_unlock(GetInterfaceLock());
466 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
467 return HDF_FAILURE;
468 }
469 pthread_mutex_unlock(GetInterfaceLock());
470 HDF_LOGI("%{public}s success", __func__);
471 return HDF_SUCCESS;
472 }
473
WpaInterfaceP2pStartFind(struct IWpaInterface * self,const char * ifName,int32_t timeout)474 int32_t WpaInterfaceP2pStartFind(struct IWpaInterface *self, const char *ifName, int32_t timeout)
475 {
476 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
477 (void)self;
478 (void)ifName;
479 pthread_mutex_lock(GetInterfaceLock());
480 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
481 if (pMainIfc == NULL) {
482 pthread_mutex_unlock(GetInterfaceLock());
483 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
484 return HDF_ERR_INVALID_PARAM;
485 }
486 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdP2pFound(pMainIfc, timeout);
487 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
488 pthread_mutex_unlock(GetInterfaceLock());
489 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
490 return HDF_FAILURE;
491 }
492 pthread_mutex_unlock(GetInterfaceLock());
493 HDF_LOGI("%{public}s success", __func__);
494 return HDF_SUCCESS;
495 }
496
WpaInterfaceP2pSetExtListen(struct IWpaInterface * self,const char * ifName,int32_t enable,int32_t period,int32_t interval)497 int32_t WpaInterfaceP2pSetExtListen(struct IWpaInterface *self, const char *ifName, int32_t enable,
498 int32_t period, int32_t interval)
499 {
500 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
501 (void)self;
502 (void)ifName;
503 pthread_mutex_lock(GetInterfaceLock());
504 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
505 if (pMainIfc == NULL) {
506 pthread_mutex_unlock(GetInterfaceLock());
507 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
508 return HDF_ERR_INVALID_PARAM;
509 }
510 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdExtListen(pMainIfc, enable, period, interval);
511 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
512 pthread_mutex_unlock(GetInterfaceLock());
513 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
514 return HDF_FAILURE;
515 }
516 pthread_mutex_unlock(GetInterfaceLock());
517 HDF_LOGI("%{public}s success", __func__);
518 return HDF_SUCCESS;
519 }
520
WpaInterfaceP2pSetListenChannel(struct IWpaInterface * self,const char * ifName,int32_t channel,int32_t regClass)521 int32_t WpaInterfaceP2pSetListenChannel(struct IWpaInterface *self, const char *ifName,
522 int32_t channel, int32_t regClass)
523 {
524 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
525 (void)self;
526 (void)ifName;
527 pthread_mutex_lock(GetInterfaceLock());
528 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
529 if (pMainIfc == NULL) {
530 pthread_mutex_unlock(GetInterfaceLock());
531 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
532 return HDF_ERR_INVALID_PARAM;
533 }
534 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdSetListenChannel(pMainIfc, channel, regClass);
535 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
536 pthread_mutex_unlock(GetInterfaceLock());
537 HDF_LOGE("%{public}s fail, ret = %{public}d", __func__, ret);
538 return HDF_FAILURE;
539 }
540 pthread_mutex_unlock(GetInterfaceLock());
541 HDF_LOGI("%{public}s success", __func__);
542 return HDF_SUCCESS;
543 }
544
WpaInterfaceP2pProvisionDiscovery(struct IWpaInterface * self,const char * ifName,const char * peerBssid,int32_t mode)545 int32_t WpaInterfaceP2pProvisionDiscovery(struct IWpaInterface *self, const char *ifName,
546 const char *peerBssid, int32_t mode)
547 {
548 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
549 (void)self;
550 if (ifName == NULL || peerBssid == NULL) {
551 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
552 return HDF_ERR_INVALID_PARAM;
553 }
554 pthread_mutex_lock(GetInterfaceLock());
555 P2pProvisionDiscoveryArgv p2pProvision;
556 if (memset_s(&p2pProvision, sizeof(p2pProvision), 0, sizeof(p2pProvision)) != EOK ||
557 strncpy_s(p2pProvision.peerbssid, sizeof(p2pProvision.peerbssid), peerBssid, strlen(peerBssid)) != EOK) {
558 pthread_mutex_unlock(GetInterfaceLock());
559 HDF_LOGE("Failed to init request message, the input message may be invalid!");
560 return HDF_FAILURE;
561 }
562 p2pProvision.mode = mode;
563 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
564 if (pMainIfc == NULL) {
565 pthread_mutex_unlock(GetInterfaceLock());
566 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
567 return HDF_ERR_INVALID_PARAM;
568 }
569 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdProvisionDiscovery(pMainIfc, &p2pProvision);
570 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
571 pthread_mutex_unlock(GetInterfaceLock());
572 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
573 return HDF_FAILURE;
574 }
575 pthread_mutex_unlock(GetInterfaceLock());
576 HDF_LOGI("%{public}s success", __func__);
577 return HDF_SUCCESS;
578 }
579
WpaInterfaceP2pAddGroup(struct IWpaInterface * self,const char * ifName,int32_t isPersistent,int32_t networkId,int32_t freq)580 int32_t WpaInterfaceP2pAddGroup(struct IWpaInterface *self, const char *ifName, int32_t isPersistent,
581 int32_t networkId, int32_t freq)
582 {
583 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
584 (void)self;
585 (void)ifName;
586 pthread_mutex_lock(GetInterfaceLock());
587 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
588 if (pMainIfc == NULL) {
589 pthread_mutex_unlock(GetInterfaceLock());
590 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
591 return HDF_ERR_INVALID_PARAM;
592 }
593 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdGroupAdd(pMainIfc, isPersistent, networkId, freq);
594 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
595 pthread_mutex_unlock(GetInterfaceLock());
596 HDF_LOGE("%{public}s fail, ret = %{public}d", __func__, ret);
597 return HDF_FAILURE;
598 }
599 pthread_mutex_unlock(GetInterfaceLock());
600 HDF_LOGI("%{public}s success", __func__);
601 return HDF_SUCCESS;
602 }
603
WpaInterfaceP2pAddService(struct IWpaInterface * self,const char * ifName,const struct HdiP2pServiceInfo * info)604 int32_t WpaInterfaceP2pAddService(struct IWpaInterface *self, const char *ifName,
605 const struct HdiP2pServiceInfo *info)
606 {
607 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
608 (void)self;
609 if (ifName == NULL || info == NULL) {
610 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
611 return HDF_ERR_INVALID_PARAM;
612 }
613 pthread_mutex_lock(GetInterfaceLock());
614 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
615 if (pMainIfc == NULL) {
616 pthread_mutex_unlock(GetInterfaceLock());
617 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
618 return HDF_ERR_INVALID_PARAM;
619 }
620 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdServiceAdd(pMainIfc, info);
621 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
622 pthread_mutex_unlock(GetInterfaceLock());
623 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
624 return HDF_FAILURE;
625 }
626 pthread_mutex_unlock(GetInterfaceLock());
627 HDF_LOGI("%{public}s success", __func__);
628 return HDF_SUCCESS;
629 }
630
WpaInterfaceP2pRemoveService(struct IWpaInterface * self,const char * ifName,const struct HdiP2pServiceInfo * info)631 int32_t WpaInterfaceP2pRemoveService(struct IWpaInterface *self, const char *ifName,
632 const struct HdiP2pServiceInfo *info)
633 {
634 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
635 (void)self;
636 if (ifName == NULL || info == NULL) {
637 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
638 return HDF_ERR_INVALID_PARAM;
639 }
640 pthread_mutex_lock(GetInterfaceLock());
641 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
642 if (pMainIfc == NULL) {
643 pthread_mutex_unlock(GetInterfaceLock());
644 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
645 return HDF_ERR_INVALID_PARAM;
646 }
647 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdServiceDel(pMainIfc, info);
648 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
649 pthread_mutex_unlock(GetInterfaceLock());
650 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
651 return HDF_FAILURE;
652 }
653 pthread_mutex_unlock(GetInterfaceLock());
654 HDF_LOGI("%{public}s success", __func__);
655 return HDF_SUCCESS;
656 }
657
WpaInterfaceP2pStopFind(struct IWpaInterface * self,const char * ifName)658 int32_t WpaInterfaceP2pStopFind(struct IWpaInterface *self, const char *ifName)
659 {
660 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
661 (void)self;
662 (void)ifName;
663 pthread_mutex_lock(GetInterfaceLock());
664 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
665 if (pMainIfc == NULL) {
666 pthread_mutex_unlock(GetInterfaceLock());
667 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
668 return HDF_ERR_INVALID_PARAM;
669 }
670 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdP2pStopFind(pMainIfc);
671 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
672 pthread_mutex_unlock(GetInterfaceLock());
673 HDF_LOGE("%{public}s fail, ret = %{public}d", __func__, ret);
674 return HDF_FAILURE;
675 }
676 pthread_mutex_unlock(GetInterfaceLock());
677 HDF_LOGI("%{public}s success", __func__);
678 return HDF_SUCCESS;
679 }
680
WpaInterfaceP2pFlush(struct IWpaInterface * self,const char * ifName)681 int32_t WpaInterfaceP2pFlush(struct IWpaInterface *self, const char *ifName)
682 {
683 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
684 (void)self;
685 (void)ifName;
686 pthread_mutex_lock(GetInterfaceLock());
687 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
688 if (pMainIfc == NULL) {
689 pthread_mutex_unlock(GetInterfaceLock());
690 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
691 return HDF_ERR_INVALID_PARAM;
692 }
693 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdFlush(pMainIfc);
694 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
695 pthread_mutex_unlock(GetInterfaceLock());
696 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
697 return HDF_FAILURE;
698 }
699 pthread_mutex_unlock(GetInterfaceLock());
700 HDF_LOGI("%{public}s success", __func__);
701 return HDF_SUCCESS;
702 }
703
WpaInterfaceP2pFlushService(struct IWpaInterface * self,const char * ifName)704 int32_t WpaInterfaceP2pFlushService(struct IWpaInterface *self, const char *ifName)
705 {
706 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
707 (void)self;
708 (void)ifName;
709 pthread_mutex_lock(GetInterfaceLock());
710 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
711 if (pMainIfc == NULL) {
712 pthread_mutex_unlock(GetInterfaceLock());
713 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
714 return HDF_ERR_INVALID_PARAM;
715 }
716 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdFlushService(pMainIfc);
717 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
718 pthread_mutex_unlock(GetInterfaceLock());
719 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
720 return HDF_FAILURE;
721 }
722 pthread_mutex_unlock(GetInterfaceLock());
723 HDF_LOGI("%{public}s success", __func__);
724 return HDF_SUCCESS;
725 }
726
WpaInterfaceP2pRemoveNetwork(struct IWpaInterface * self,const char * ifName,int32_t networkId)727 int32_t WpaInterfaceP2pRemoveNetwork(struct IWpaInterface *self, const char *ifName, int32_t networkId)
728 {
729 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
730 (void)self;
731 (void)ifName;
732 pthread_mutex_lock(GetInterfaceLock());
733 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
734 if (pMainIfc == NULL) {
735 pthread_mutex_unlock(GetInterfaceLock());
736 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
737 return HDF_ERR_INVALID_PARAM;
738 }
739 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdRemoveNetwork(pMainIfc, networkId);
740 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
741 pthread_mutex_unlock(GetInterfaceLock());
742 HDF_LOGE("%{public}s fail, ret = %{public}d", __func__, ret);
743 return HDF_FAILURE;
744 }
745 pthread_mutex_unlock(GetInterfaceLock());
746 HDF_LOGI("%{public}s success", __func__);
747 return HDF_SUCCESS;
748 }
749
WpaInterfaceP2pSetGroupConfig(struct IWpaInterface * self,const char * ifName,const int32_t networkId,const char * name,const char * value)750 int32_t WpaInterfaceP2pSetGroupConfig(struct IWpaInterface *self, const char *ifName, const int32_t networkId,
751 const char *name, const char *value)
752 {
753 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
754 char cmd[CMD_SIZE] = {0};
755 char buf[CMD_SIZE] = {0};
756 int32_t ret = 0;
757 (void)self;
758 if (ifName == NULL || name == NULL || value == NULL) {
759 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
760 return HDF_ERR_INVALID_PARAM;
761 }
762 pthread_mutex_lock(GetInterfaceLock());
763 ret = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "IFNAME=%s SET_NETWORK %d %s %s",
764 ifName, networkId, name, value);
765 if (ret < 0) {
766 pthread_mutex_unlock(GetInterfaceLock());
767 HDF_LOGE("%{public}s snprintf_s failed, cmd: %{private}s, count = %{public}d", __func__, cmd, ret);
768 return HDF_FAILURE;
769 }
770 if (WpaCliCmd(cmd, buf, sizeof(buf)) != 0) {
771 pthread_mutex_unlock(GetInterfaceLock());
772 HDF_LOGE("%{public}s command failed!", __func__);
773 return HDF_FAILURE;
774 }
775 pthread_mutex_unlock(GetInterfaceLock());
776 HDF_LOGI("%{public}s success", __func__);
777 return HDF_SUCCESS;
778 }
779
WpaInterfaceP2pInvite(struct IWpaInterface * self,const char * ifName,const char * peerBssid,const char * goBssid)780 int32_t WpaInterfaceP2pInvite(struct IWpaInterface *self, const char *ifName,
781 const char *peerBssid, const char *goBssid)
782 {
783 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
784 (void)self;
785 if (peerBssid == NULL || goBssid == NULL || ifName == NULL) {
786 HDF_LOGE("%{public}s: peerBssid, goBssid and ifname have NULL", __func__);
787 return HDF_FAILURE;
788 }
789 pthread_mutex_lock(GetInterfaceLock());
790 P2pHalInviteArgv p2pHalInvite;
791 if (memset_s(&p2pHalInvite, sizeof(p2pHalInvite), 0, sizeof(p2pHalInvite)) != EOK ||
792 strncpy_s(p2pHalInvite.peerbssid, sizeof(p2pHalInvite.peerbssid), peerBssid, strlen(peerBssid)) != EOK ||
793 strncpy_s(p2pHalInvite.gobssid, sizeof(p2pHalInvite.gobssid), goBssid, strlen(goBssid)) != EOK ||
794 strncpy_s(p2pHalInvite.ifname, sizeof(p2pHalInvite.ifname), ifName, strlen(ifName)) != EOK) {
795 pthread_mutex_unlock(GetInterfaceLock());
796 HDF_LOGE("Failed to init request message, the input message may be invalid!");
797 return HDF_FAILURE;
798 }
799 p2pHalInvite.persistent = 0;
800 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
801 if (pMainIfc == NULL) {
802 pthread_mutex_unlock(GetInterfaceLock());
803 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
804 return HDF_ERR_INVALID_PARAM;
805 }
806 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdInvite(pMainIfc, &p2pHalInvite);
807 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
808 pthread_mutex_unlock(GetInterfaceLock());
809 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
810 return HDF_FAILURE;
811 }
812 pthread_mutex_unlock(GetInterfaceLock());
813 HDF_LOGI("%{public}s success", __func__);
814 return HDF_SUCCESS;
815 }
816
WpaInterfaceP2pReinvoke(struct IWpaInterface * self,const char * ifName,const int32_t networkId,const char * bssid)817 int32_t WpaInterfaceP2pReinvoke(struct IWpaInterface *self, const char *ifName, const int32_t networkId,
818 const char *bssid)
819 {
820 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
821 (void)self;
822 if (ifName == NULL || bssid == NULL) {
823 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
824 return HDF_ERR_INVALID_PARAM;
825 }
826 pthread_mutex_lock(GetInterfaceLock());
827 P2pHalReInviteArgv p2pHalReInvite;
828 if (memset_s(&p2pHalReInvite, sizeof(p2pHalReInvite), 0, sizeof(p2pHalReInvite)) != EOK ||
829 strncpy_s(p2pHalReInvite.peerbssid, sizeof(p2pHalReInvite.peerbssid), bssid, strlen(bssid)) != EOK) {
830 pthread_mutex_unlock(GetInterfaceLock());
831 HDF_LOGE("Failed to init request message, the input message may be invalid!");
832 return HDF_FAILURE;
833 }
834 p2pHalReInvite.networkId = networkId;
835 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
836 if (pMainIfc == NULL) {
837 pthread_mutex_unlock(GetInterfaceLock());
838 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
839 return HDF_ERR_INVALID_PARAM;
840 }
841 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdReInvite(pMainIfc, &p2pHalReInvite);
842 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
843 pthread_mutex_unlock(GetInterfaceLock());
844 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
845 return HDF_FAILURE;
846 }
847 pthread_mutex_unlock(GetInterfaceLock());
848 HDF_LOGI("%{public}s success", __func__);
849 return HDF_SUCCESS;
850 }
851
WpaInterfaceP2pGetDeviceAddress(struct IWpaInterface * self,const char * ifName,char * deviceAddress,uint32_t deviceAddressLen)852 int32_t WpaInterfaceP2pGetDeviceAddress(struct IWpaInterface *self, const char *ifName, char *deviceAddress,
853 uint32_t deviceAddressLen)
854 {
855 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
856 if (ifName == NULL || deviceAddress == NULL) {
857 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
858 return HDF_ERR_INVALID_PARAM;
859 }
860 (void)self;
861 pthread_mutex_lock(GetInterfaceLock());
862 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
863 if (pMainIfc == NULL) {
864 pthread_mutex_unlock(GetInterfaceLock());
865 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
866 return HDF_ERR_INVALID_PARAM;
867 }
868 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdGetDeviceAddress(pMainIfc, deviceAddress, deviceAddressLen);
869 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
870 pthread_mutex_unlock(GetInterfaceLock());
871 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
872 return HDF_FAILURE;
873 }
874 pthread_mutex_unlock(GetInterfaceLock());
875 HDF_LOGI("%{public}s success", __func__);
876 return HDF_SUCCESS;
877 }
878
WpaInterfaceP2pReqServiceDiscovery(struct IWpaInterface * self,const char * ifName,const struct HdiP2pReqService * reqService,char * replyDisc,uint32_t replyDiscLen)879 int32_t WpaInterfaceP2pReqServiceDiscovery(struct IWpaInterface *self, const char *ifName,
880 const struct HdiP2pReqService *reqService, char *replyDisc, uint32_t replyDiscLen)
881 {
882 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
883 if (ifName == NULL || reqService == NULL || replyDisc == NULL) {
884 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
885 return HDF_ERR_INVALID_PARAM;
886 }
887 (void)self;
888 char seq[WIFI_P2P_SERVER_DISCOVERY_SEQUENCE_LENGTH] = {0};
889 pthread_mutex_lock(GetInterfaceLock());
890 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
891 if (pMainIfc == NULL) {
892 pthread_mutex_unlock(GetInterfaceLock());
893 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
894 return HDF_ERR_INVALID_PARAM;
895 }
896 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdServDiscReq(pMainIfc, (char *)reqService->bssid,
897 (char *)reqService->msg, seq, sizeof(seq));
898 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
899 pthread_mutex_unlock(GetInterfaceLock());
900 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
901 return HDF_FAILURE;
902 }
903 if (strncpy_s(replyDisc, replyDiscLen, seq, strlen(seq)) != EOK) {
904 pthread_mutex_unlock(GetInterfaceLock());
905 HDF_LOGE("%{public}s: fail", __func__);
906 return HDF_FAILURE;
907 }
908 pthread_mutex_unlock(GetInterfaceLock());
909 HDF_LOGI("%{public}s success", __func__);
910 return HDF_SUCCESS;
911 }
912
WpaInterfaceP2pCancelServiceDiscovery(struct IWpaInterface * self,const char * ifName,const char * id)913 int32_t WpaInterfaceP2pCancelServiceDiscovery(struct IWpaInterface *self, const char *ifName, const char *id)
914 {
915 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
916 (void)self;
917 if (ifName == NULL || id == NULL) {
918 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
919 return HDF_ERR_INVALID_PARAM;
920 }
921 pthread_mutex_lock(GetInterfaceLock());
922 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
923 if (pMainIfc == NULL) {
924 pthread_mutex_unlock(GetInterfaceLock());
925 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
926 return HDF_ERR_INVALID_PARAM;
927 }
928 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdServDiscCancelReq(pMainIfc, id);
929 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
930 pthread_mutex_unlock(GetInterfaceLock());
931 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
932 return HDF_FAILURE;
933 }
934 pthread_mutex_unlock(GetInterfaceLock());
935 HDF_LOGI("%{public}s success", __func__);
936 return HDF_SUCCESS;
937 }
938
WpaInterfaceP2pRespServerDiscovery(struct IWpaInterface * self,const char * ifName,const struct HdiP2pServDiscReqInfo * info)939 int32_t WpaInterfaceP2pRespServerDiscovery(struct IWpaInterface *self, const char *ifName,
940 const struct HdiP2pServDiscReqInfo *info)
941 {
942 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
943 if (ifName == NULL || info == NULL) {
944 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
945 return HDF_ERR_INVALID_PARAM;
946 }
947 (void)self;
948 pthread_mutex_lock(GetInterfaceLock());
949 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
950 if (pMainIfc == NULL) {
951 pthread_mutex_unlock(GetInterfaceLock());
952 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
953 return HDF_ERR_INVALID_PARAM;
954 }
955 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdRespServerDiscovery(pMainIfc, info);
956 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
957 pthread_mutex_unlock(GetInterfaceLock());
958 HDF_LOGE("WpaP2pCliCmdRespServerDiscovery fail, ret = %{public}d", ret);
959 return HDF_FAILURE;
960 }
961 pthread_mutex_unlock(GetInterfaceLock());
962 HDF_LOGI("%{public}s success", __func__);
963 return HDF_SUCCESS;
964 }
965
WpaInterfaceP2pConnect(struct IWpaInterface * self,const char * ifName,const struct HdiP2pConnectInfo * info,char * replyPin,uint32_t replyPinLen)966 int32_t WpaInterfaceP2pConnect(struct IWpaInterface *self, const char *ifName, const struct HdiP2pConnectInfo *info,
967 char *replyPin, uint32_t replyPinLen)
968 {
969 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
970 if (ifName == NULL || info == NULL || replyPin == NULL) {
971 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
972 return HDF_ERR_INVALID_PARAM;
973 }
974 pthread_mutex_lock(GetInterfaceLock());
975 char *reply;
976 const int replySize = REPLY_SIZE;
977 char cmd[CMD_SIZE] = {0};
978 char join[CMD_SIZE] = {0};
979 char mode[CMD_SIZE] = {0};
980 char pin[CMD_SIZE] = {0};
981 char peerDevAddr[CMD_SIZE] = {0};
982 if (memcpy_s(pin, CMD_SIZE, info->pin, info->pinLen) != EOK) {
983 pthread_mutex_unlock(GetInterfaceLock());
984 HDF_LOGE("%{public}s strcpy failed", __func__);
985 return HDF_FAILURE;
986 }
987
988 if (memcpy_s(peerDevAddr, CMD_SIZE, info->peerDevAddr, info->peerDevAddrLen) != EOK) {
989 pthread_mutex_unlock(GetInterfaceLock());
990 HDF_LOGE("%{public}s strcpy failed", __func__);
991 return HDF_FAILURE;
992 }
993
994 reply = (char *)malloc(replySize);
995 if (reply == NULL) {
996 pthread_mutex_unlock(GetInterfaceLock());
997 HDF_LOGE("%{public}s reply is NULL!", __func__);
998 return HDF_FAILURE;
999 }
1000
1001 int32_t ret = 0;
1002 (void)self;
1003
1004 if (info->mode != 0) {
1005 if (strcpy_s(join, sizeof(join), " join") != EOK) {
1006 HDF_LOGE("%{public}s strcpy failed", __func__);
1007 }
1008 } else {
1009 if (snprintf_s(join, sizeof(join), sizeof(join) - 1, " go_intent=%d", info->goIntent) < 0) {
1010 pthread_mutex_unlock(GetInterfaceLock());
1011 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1012 free(reply);
1013 return HDF_ERR_INVALID_PARAM;
1014 }
1015 }
1016
1017 if (info->provdisc == P2P_WPS_METHOD_DISPLAY) {
1018 if (strcpy_s(mode, sizeof(mode), " display") != EOK) {
1019 HDF_LOGE("%{public}s strcpy failed", __func__);
1020 }
1021 } else if (info->provdisc == P2P_WPS_METHOD_KEYPAD) {
1022 if (strcpy_s(mode, sizeof(mode), " keypad") != EOK) {
1023 HDF_LOGE("%{public}s strcpy failed", __func__);
1024 }
1025 } else if (info->provdisc == P2P_WPS_METHOD_PBC && info->pin != NULL && strlen((char *)info->pin) == 0) {
1026 if (strcpy_s(pin, CMD_SIZE, "pbc") != EOK) {
1027 HDF_LOGE("%{public}s strcpy failed", __func__);
1028 }
1029 } else {
1030 pthread_mutex_unlock(GetInterfaceLock());
1031 HDF_LOGE("%{public}s Mode value is invalid %{public}d!", __func__, info->provdisc);
1032 free(reply);
1033 return HDF_ERR_INVALID_PARAM;
1034 }
1035
1036 if (info->peerDevAddr) {
1037 ret = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "IFNAME=%s P2P_CONNECT %s %s%s persistent=%d %s", ifName,
1038 MacToStr(info->peerDevAddr), pin, mode, info->persistent, join);
1039 }
1040 if (ret < 0) {
1041 pthread_mutex_unlock(GetInterfaceLock());
1042 HDF_LOGE("%{public}s snprintf_s failed, cmd: %{private}s, count = %{public}d", __func__, cmd, ret);
1043 free(reply);
1044 return HDF_FAILURE;
1045 }
1046
1047 if (WpaCliCmd(cmd, reply, REPLY_SIZE) != 0) {
1048 pthread_mutex_unlock(GetInterfaceLock());
1049 HDF_LOGE("P2P_CONNECT command failed!");
1050 free(reply);
1051 return HDF_FAILURE;
1052 }
1053
1054 if (strncmp(reply, "FAIL", strlen("FAIL")) == 0) {
1055 pthread_mutex_unlock(GetInterfaceLock());
1056 HDF_LOGE("%{public}s P2p connect return %{public}s", __func__, reply);
1057 free(reply);
1058 return HDF_FAILURE;
1059 }
1060 if (info->provdisc == P2P_WPS_METHOD_DISPLAY && strcmp((char *)info->pin, "pin") == 0) {
1061 if (strncpy_s(replyPin, replyPinLen, reply, strlen(reply)) != 0) {
1062 pthread_mutex_unlock(GetInterfaceLock());
1063 HDF_LOGE("%{public}s Failed to copy response pin code info!", __func__);
1064 free(reply);
1065 return HDF_FAILURE;
1066 }
1067 }
1068 pthread_mutex_unlock(GetInterfaceLock());
1069 free(reply);
1070 HDF_LOGI("%{public}s success", __func__);
1071 return HDF_SUCCESS;
1072 }
1073
WpaInterfaceP2pHid2dConnect(struct IWpaInterface * self,const char * ifName,const struct HdiHid2dConnectInfo * info)1074 int32_t WpaInterfaceP2pHid2dConnect(struct IWpaInterface *self, const char *ifName,
1075 const struct HdiHid2dConnectInfo *info)
1076 {
1077 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1078 if (ifName == NULL || info == NULL) {
1079 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1080 return HDF_ERR_INVALID_PARAM;
1081 }
1082 pthread_mutex_lock(GetInterfaceLock());
1083 char cmd[CMD_SIZE];
1084 char buf[CMD_SIZE];
1085 (void)self;
1086 int freq = (info->frequency >> 16);
1087 int isLegacyGo = (info->frequency & 0xffff);
1088 if (freq < 0) {
1089 HDF_LOGE("hid2dconnect freq is failed, freq=%{public}d", freq);
1090 freq = 0;
1091 }
1092 HDF_LOGI("hid2dconnect freq=%{public}d, isLegacyGo=%{public}d", freq, isLegacyGo);
1093 if (snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "IFNAME=%s MAGICLINK \"%s\"\n%s\n\"%s\"\n%d\n%d", ifName,
1094 (char *)info->ssid, MacToStr(info->bssid), (char *)info->passphrase, freq, isLegacyGo) < 0) {
1095 pthread_mutex_unlock(GetInterfaceLock());
1096 HDF_LOGE("%{public}s snprintf_s failed, cmd: %{private}s.", __func__, cmd);
1097 return HDF_FAILURE;
1098 }
1099 if (WpaCliCmd(cmd, buf, sizeof(buf)) != 0) {
1100 pthread_mutex_unlock(GetInterfaceLock());
1101 HDF_LOGE("hid2d_connect command failed!");
1102 return HDF_FAILURE;
1103 }
1104 if (strncmp(buf, "FAIL", strlen("FAIL")) == 0) {
1105 pthread_mutex_unlock(GetInterfaceLock());
1106 HDF_LOGE("%{public}s: return %{public}s", __func__, buf);
1107 return HDF_FAILURE;
1108 }
1109 pthread_mutex_unlock(GetInterfaceLock());
1110 HDF_LOGI("%{public}s success", __func__);
1111 return HDF_SUCCESS;
1112 }
1113
WpaInterfaceP2pSetServDiscExternal(struct IWpaInterface * self,const char * ifName,int32_t mode)1114 int32_t WpaInterfaceP2pSetServDiscExternal(struct IWpaInterface *self, const char *ifName, int32_t mode)
1115 {
1116 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1117 (void)self;
1118 (void)ifName;
1119 pthread_mutex_lock(GetInterfaceLock());
1120 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
1121 if (pMainIfc == NULL) {
1122 pthread_mutex_unlock(GetInterfaceLock());
1123 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
1124 return HDF_ERR_INVALID_PARAM;
1125 }
1126 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdSetServDiscExternal(pMainIfc, mode);
1127 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
1128 pthread_mutex_unlock(GetInterfaceLock());
1129 HDF_LOGE("WpaP2pCliCmdSetServDiscExternal fail, ret = %{public}d", ret);
1130 return HDF_FAILURE;
1131 }
1132 pthread_mutex_unlock(GetInterfaceLock());
1133 HDF_LOGI("%{public}s success", __func__);
1134 return HDF_SUCCESS;
1135 }
1136
WpaInterfaceP2pRemoveGroup(struct IWpaInterface * self,const char * ifName,const char * groupName)1137 int32_t WpaInterfaceP2pRemoveGroup(struct IWpaInterface *self, const char *ifName, const char *groupName)
1138 {
1139 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1140 (void)self;
1141 if (ifName == NULL || groupName == NULL) {
1142 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1143 return HDF_ERR_INVALID_PARAM;
1144 }
1145 pthread_mutex_lock(GetInterfaceLock());
1146 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
1147 if (pMainIfc == NULL) {
1148 pthread_mutex_unlock(GetInterfaceLock());
1149 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
1150 return HDF_ERR_INVALID_PARAM;
1151 }
1152 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdP2pRemoveGroup(pMainIfc, groupName);
1153 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
1154 pthread_mutex_unlock(GetInterfaceLock());
1155 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
1156 return HDF_FAILURE;
1157 }
1158 pthread_mutex_unlock(GetInterfaceLock());
1159 HDF_LOGI("%{public}s success", __func__);
1160 return HDF_SUCCESS;
1161 }
1162
WpaInterfaceP2pCancelConnect(struct IWpaInterface * self,const char * ifName)1163 int32_t WpaInterfaceP2pCancelConnect(struct IWpaInterface *self, const char *ifName)
1164 {
1165 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1166 (void)self;
1167 (void)ifName;
1168 pthread_mutex_lock(GetInterfaceLock());
1169 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
1170 if (pMainIfc == NULL) {
1171 pthread_mutex_unlock(GetInterfaceLock());
1172 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
1173 return HDF_ERR_INVALID_PARAM;
1174 }
1175 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdCancelConnect(pMainIfc);
1176 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
1177 pthread_mutex_unlock(GetInterfaceLock());
1178 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
1179 return HDF_FAILURE;
1180 }
1181 pthread_mutex_unlock(GetInterfaceLock());
1182 HDF_LOGI("%{public}s success", __func__);
1183 return HDF_SUCCESS;
1184 }
1185
WpaInterfaceP2pGetGroupConfig(struct IWpaInterface * self,const char * ifName,const int32_t networkId,const char * param,char * value,uint32_t valueLen)1186 int32_t WpaInterfaceP2pGetGroupConfig(struct IWpaInterface *self, const char *ifName, const int32_t networkId,
1187 const char *param, char *value, uint32_t valueLen)
1188 {
1189 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1190 char cmd[CMD_SIZE];
1191
1192 int32_t ret = 0;
1193 (void)self;
1194 if (ifName == NULL || param == NULL || value == NULL) {
1195 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1196 return HDF_ERR_INVALID_PARAM;
1197 }
1198 pthread_mutex_lock(GetInterfaceLock());
1199 ret = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "IFNAME=%s GET_NETWORK %d %s", ifName, networkId, param);
1200 if (ret < 0) {
1201 pthread_mutex_unlock(GetInterfaceLock());
1202 HDF_LOGE("%{public}s snprintf_s failed, cmd: %{private}s, count = %{public}d", __func__, cmd, ret);
1203 return HDF_FAILURE;
1204 }
1205 if (WpaCliCmd(cmd, value, valueLen) != 0) {
1206 pthread_mutex_unlock(GetInterfaceLock());
1207 HDF_LOGE("GET_NETWORK command failed!");
1208 return HDF_FAILURE;
1209 }
1210 pthread_mutex_unlock(GetInterfaceLock());
1211 HDF_LOGI("%{public}s success", __func__);
1212 return HDF_SUCCESS;
1213 }
1214
WpaInterfaceP2pAddNetwork(struct IWpaInterface * self,const char * ifName,int32_t * networkId)1215 int32_t WpaInterfaceP2pAddNetwork(struct IWpaInterface *self, const char *ifName, int32_t *networkId)
1216 {
1217 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1218 if (ifName == NULL || networkId == NULL) {
1219 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1220 return HDF_ERR_INVALID_PARAM;
1221 }
1222 (void)self;
1223 pthread_mutex_lock(GetInterfaceLock());
1224 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
1225 if (pMainIfc == NULL) {
1226 pthread_mutex_unlock(GetInterfaceLock());
1227 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
1228 return HDF_ERR_INVALID_PARAM;
1229 }
1230 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdAddNetwork(pMainIfc, networkId);
1231 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
1232 pthread_mutex_unlock(GetInterfaceLock());
1233 HDF_LOGE("WpaP2pCliCmdAddNetwork fail, ret = %{public}d", ret);
1234 return HDF_FAILURE;
1235 }
1236 pthread_mutex_unlock(GetInterfaceLock());
1237 HDF_LOGI("%{public}s success", __func__);
1238 return HDF_SUCCESS;
1239 }
1240
WpaInterfaceP2pGetPeer(struct IWpaInterface * self,const char * ifName,const char * bssid,struct HdiP2pDeviceInfo * info)1241 int32_t WpaInterfaceP2pGetPeer(struct IWpaInterface *self, const char *ifName, const char *bssid,
1242 struct HdiP2pDeviceInfo *info)
1243 {
1244 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1245 if (ifName == NULL || info == NULL || bssid == NULL) {
1246 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1247 return HDF_ERR_INVALID_PARAM;
1248 }
1249 pthread_mutex_lock(GetInterfaceLock());
1250 char *reply;
1251 const int replySize = REPLY_SIZE;
1252 char cmd[CMD_SIZE];
1253
1254 reply = (char *)malloc(replySize);
1255 if (reply == NULL) {
1256 pthread_mutex_unlock(GetInterfaceLock());
1257 HDF_LOGE("%{public}s reply is NULL!", __func__);
1258 return HDF_FAILURE;
1259 }
1260
1261 int32_t ret = 0;
1262 (void)self;
1263
1264 ret = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "IFNAME=%s P2P_PEER %s", ifName, bssid);
1265 if (ret < 0) {
1266 pthread_mutex_unlock(GetInterfaceLock());
1267 HDF_LOGE("%{public}s snprintf_s failed, cmd: %{private}s, count = %{public}d", __func__, cmd, ret);
1268 free(reply);
1269 return HDF_FAILURE;
1270 }
1271
1272 if (WpaCliCmd(cmd, reply, REPLY_SIZE) != 0) {
1273 pthread_mutex_unlock(GetInterfaceLock());
1274 HDF_LOGE("P2P_PEER command failed!");
1275 free(reply);
1276 return HDF_FAILURE;
1277 }
1278
1279 if (strstr(reply, "\n") == NULL) {
1280 pthread_mutex_unlock(GetInterfaceLock());
1281 HDF_LOGE("%{public}s reply is error", __func__);
1282 free(reply);
1283 return HDF_FAILURE;
1284 }
1285 char *savedPtr = NULL;
1286 char *token = strtok_r(reply, "\n", &savedPtr);
1287 info->srcAddress = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * (ETH_ADDR_LEN + 1));
1288 if (info->srcAddress == NULL) {
1289 pthread_mutex_unlock(GetInterfaceLock());
1290 HDF_LOGE("malloc srcAddress failed!");
1291 free(reply);
1292 HdiP2pDeviceInfoFree(info, false);
1293 return HDF_FAILURE;
1294 }
1295 info->p2pDeviceAddress = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * (ETH_ADDR_LEN + 1));
1296 if (info->p2pDeviceAddress == NULL) {
1297 pthread_mutex_unlock(GetInterfaceLock());
1298 HDF_LOGE("malloc p2pDeviceAddress failed!");
1299 free(reply);
1300 HdiP2pDeviceInfoFree(info, false);
1301 return HDF_FAILURE;
1302 }
1303 info->primaryDeviceType = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * WIFI_P2P_DEVICE_TYPE_LENGTH);
1304 if (info->primaryDeviceType == NULL) {
1305 pthread_mutex_unlock(GetInterfaceLock());
1306 HDF_LOGE("malloc primaryDeviceType failed!");
1307 free(reply);
1308 HdiP2pDeviceInfoFree(info, false);
1309 return HDF_FAILURE;
1310 }
1311 info->deviceName = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * WIFI_P2P_DEVICE_NAME_LENGTH);
1312 if (info->deviceName == NULL) {
1313 pthread_mutex_unlock(GetInterfaceLock());
1314 HDF_LOGE("malloc deviceName failed!");
1315 free(reply);
1316 HdiP2pDeviceInfoFree(info, false);
1317 return HDF_FAILURE;
1318 }
1319 info->wfdDeviceInfo = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * WIFI_P2P_WFD_DEVICE_INFO_LENGTH);
1320 if (info->wfdDeviceInfo == NULL) {
1321 pthread_mutex_unlock(GetInterfaceLock());
1322 HDF_LOGE("malloc wfdDeviceInfo failed!");
1323 free(reply);
1324 HdiP2pDeviceInfoFree(info, false);
1325 return HDF_FAILURE;
1326 }
1327 info->operSsid = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * WIFI_P2P_DEVICE_NAME_LENGTH);
1328 if (info->operSsid == NULL) {
1329 pthread_mutex_unlock(GetInterfaceLock());
1330 HDF_LOGE("malloc operSsid failed!");
1331 free(reply);
1332 HdiP2pDeviceInfoFree(info, false);
1333 return HDF_FAILURE;
1334 }
1335 info->srcAddressLen = ETH_ADDR_LEN + 1;
1336 info->p2pDeviceAddressLen = ETH_ADDR_LEN + 1;
1337 info->primaryDeviceTypeLen = WIFI_P2P_DEVICE_TYPE_LENGTH;
1338 info->deviceNameLen = WIFI_P2P_DEVICE_NAME_LENGTH;
1339 info->wfdDeviceInfoLen = WIFI_P2P_WFD_DEVICE_INFO_LENGTH;
1340 info->operSsidLen = WIFI_P2P_DEVICE_NAME_LENGTH;
1341 uint8_t tmpBssid[ETH_ADDR_LEN] = {0};
1342 hwaddr_aton(token, tmpBssid);
1343 if (memcpy_s((char *)info->p2pDeviceAddress, ETH_ADDR_LEN, (char *)tmpBssid, ETH_ADDR_LEN) != EOK) {
1344 HDF_LOGE("%{public}s memcpy failed", __func__);
1345 }
1346 while (token != NULL) {
1347 struct HdiWpaKeyValue retMsg = {{0}, {0}};
1348 GetStrKeyVal(token, "=", &retMsg);
1349 if (strncmp(retMsg.key, "pri_dev_type", strlen("pri_dev_type")) == 0) {
1350 if (strcpy_s((char *)info->primaryDeviceType, WIFI_P2P_DEVICE_TYPE_LENGTH + 1, retMsg.value) != EOK) {
1351 HDF_LOGE("%{public}s strcpy failed", __func__);
1352 }
1353 } else if (strncmp(retMsg.key, "device_name", strlen("device_name")) == 0) {
1354 if (strcpy_s((char *)info->deviceName, WIFI_P2P_DEVICE_NAME_LENGTH + 1, retMsg.value) != EOK) {
1355 HDF_LOGE("%{public}s strcpy failed", __func__);
1356 }
1357 } else if (strncmp(retMsg.key, "config_methods", strlen("config_methods")) == 0) {
1358 info->configMethods = Hex2Dec(retMsg.value);
1359 } else if (strncmp(retMsg.key, "dev_capab", strlen("dev_capab")) == 0) {
1360 info->deviceCapabilities = Hex2Dec(retMsg.value);
1361 } else if (strncmp(retMsg.key, "group_capab", strlen("group_capab")) == 0) {
1362 info->groupCapabilities = Hex2Dec(retMsg.value);
1363 } else if (strncmp(retMsg.key, "oper_ssid", strlen("oper_ssid")) == 0) {
1364 if (strcpy_s((char *)info->operSsid, WIFI_P2P_DEVICE_NAME_LENGTH + 1, retMsg.value) != EOK) {
1365 HDF_LOGE("%{public}s strcpy failed", __func__);
1366 }
1367 }
1368 token = strtok_r(NULL, "\n", &savedPtr);
1369 }
1370 pthread_mutex_unlock(GetInterfaceLock());
1371 free(reply);
1372 HDF_LOGI("%{public}s success", __func__);
1373 return HDF_SUCCESS;
1374 }
1375
WpaInterfaceP2pGetGroupCapability(struct IWpaInterface * self,const char * ifName,const char * bssid,int32_t * cap)1376 int32_t WpaInterfaceP2pGetGroupCapability(struct IWpaInterface *self, const char *ifName,
1377 const char *bssid, int32_t *cap)
1378 {
1379 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1380 if (ifName == NULL || bssid == NULL || cap == NULL) {
1381 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1382 return HDF_ERR_INVALID_PARAM;
1383 }
1384 pthread_mutex_lock(GetInterfaceLock());
1385 char *reply;
1386 const int replySize = REPLY_SIZE;
1387 char cmd[CMD_SIZE];
1388
1389 reply = (char *)malloc(replySize);
1390 if (reply == NULL) {
1391 pthread_mutex_unlock(GetInterfaceLock());
1392 HDF_LOGE("%{public}s reply is NULL!", __func__);
1393 return HDF_FAILURE;
1394 }
1395
1396 int32_t ret = 0;
1397 (void)self;
1398
1399 ret = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "IFNAME=%s P2P_PEER %s", ifName, bssid);
1400 if (ret < 0) {
1401 pthread_mutex_unlock(GetInterfaceLock());
1402 HDF_LOGE("%{public}s snprintf_s failed, cmd: %{private}s, count = %{public}d", __func__, cmd, ret);
1403 free(reply);
1404 return HDF_FAILURE;
1405 }
1406
1407 if (WpaCliCmd(cmd, reply, REPLY_SIZE) != 0) {
1408 pthread_mutex_unlock(GetInterfaceLock());
1409 HDF_LOGE("P2P_PEER command failed!");
1410 free(reply);
1411 return HDF_FAILURE;
1412 }
1413
1414 if (strstr(reply, "\n") == NULL) {
1415 pthread_mutex_unlock(GetInterfaceLock());
1416 HDF_LOGE("%{public}s reply is error", __func__);
1417 free(reply);
1418 return HDF_FAILURE;
1419 }
1420 char *savedPtr = NULL;
1421 char *token = strtok_r(reply, "\n", &savedPtr);
1422
1423 while (token != NULL) {
1424 struct HdiWpaKeyValue retMsg = {{0}, {0}};
1425 GetStrKeyVal(token, "=", &retMsg);
1426 if (strncmp(retMsg.key, "group_capab", strlen("group_capab")) == 0) {
1427 *cap = Hex2Dec(retMsg.value);
1428 }
1429 token = strtok_r(NULL, "\n", &savedPtr);
1430 }
1431 pthread_mutex_unlock(GetInterfaceLock());
1432 free(reply);
1433 HDF_LOGI("%{public}s success", __func__);
1434 return HDF_SUCCESS;
1435 }
1436
WpaInterfaceP2pListNetworks(struct IWpaInterface * self,const char * ifName,struct HdiP2pNetworkList * infoList)1437 int32_t WpaInterfaceP2pListNetworks(struct IWpaInterface *self, const char *ifName,
1438 struct HdiP2pNetworkList *infoList)
1439 {
1440 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1441 if (ifName == NULL || infoList == NULL) {
1442 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1443 return HDF_ERR_INVALID_PARAM;
1444 }
1445 pthread_mutex_lock(GetInterfaceLock());
1446 char *reply;
1447 const int replySize = P2P_LIST_REPLY_SIZE;
1448 char cmd[CMD_SIZE];
1449 reply = (char *)malloc(replySize);
1450 if (reply == NULL) {
1451 pthread_mutex_unlock(GetInterfaceLock());
1452 HDF_LOGE("%{public}s reply is NULL!", __func__);
1453 return HDF_FAILURE;
1454 }
1455
1456 (void)self;
1457 if (snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "IFNAME=%s LIST_NETWORKS", ifName) < 0) {
1458 pthread_mutex_unlock(GetInterfaceLock());
1459 HDF_LOGE("snprintf err");
1460 free(reply);
1461 return HDF_FAILURE;
1462 }
1463 if (WpaCliCmd(cmd, reply, P2P_LIST_REPLY_SIZE) != 0) {
1464 pthread_mutex_unlock(GetInterfaceLock());
1465 HDF_LOGE("LIST_NETWORKS command failed!");
1466 free(reply);
1467 return HDF_FAILURE;
1468 }
1469
1470 char *token = strstr(reply, "\n");
1471 if (token == NULL) {
1472 pthread_mutex_unlock(GetInterfaceLock());
1473 HDF_LOGE("%{public}s token is NULL!", __func__);
1474 free(reply);
1475 return HDF_FAILURE;
1476 }
1477 char *tmpPos = token + 1;
1478 while ((tmpPos = strstr(tmpPos, "\n")) != NULL) {
1479 infoList->infoNum += 1;
1480 ++tmpPos;
1481 }
1482 if (infoList->infoNum <= 0) {
1483 pthread_mutex_unlock(GetInterfaceLock());
1484 HDF_LOGE("%{public}s infoList->infoNum <= 0", __func__);
1485 free(reply);
1486 return HDF_FAILURE;
1487 }
1488 infoList->infos = (struct HdiP2pNetworkInfo *)OsalMemCalloc(sizeof(struct HdiP2pNetworkInfo) * infoList->infoNum);
1489 if (infoList->infos == NULL) {
1490 pthread_mutex_unlock(GetInterfaceLock());
1491 HDF_LOGE("malloc infos failed!");
1492 free(reply);
1493 return HDF_FAILURE;
1494 }
1495 infoList->infosLen = (uint32_t)infoList->infoNum;
1496 char *tmpBuf = token + 1;
1497 char *savedPtr = NULL;
1498 token = strtok_r(tmpBuf, "\n", &savedPtr);
1499 int index = 0;
1500 while (token != NULL) {
1501 if (index >= infoList->infoNum) {
1502 break;
1503 }
1504 infoList->infos[index].ssid = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * WIFI_SSID_LENGTH);
1505 if (infoList->infos[index].ssid == NULL) {
1506 HDF_LOGE("malloc ssid failed!");
1507 HdiP2pNetworkInfoFree(&(infoList->infos[index]), true);
1508 break;
1509 }
1510 infoList->infos[index].ssidLen = WIFI_SSID_LENGTH;
1511 infoList->infos[index].bssid = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * (ETH_ADDR_LEN + 1));
1512 if (infoList->infos[index].bssid == NULL) {
1513 HDF_LOGE("malloc bssid failed!");
1514 HdiP2pNetworkInfoFree(&(infoList->infos[index]), true);
1515 break;
1516 }
1517 infoList->infos[index].bssidLen = ETH_ADDR_LEN + 1;
1518 infoList->infos[index].flags = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * WIFI_NETWORK_FLAGS_LENGTH);
1519 if (infoList->infos[index].flags == NULL) {
1520 HDF_LOGE("malloc flags failed!");
1521 HdiP2pNetworkInfoFree(&(infoList->infos[index]), true);
1522 break;
1523 }
1524 infoList->infos[index].flagsLen = WIFI_NETWORK_FLAGS_LENGTH;
1525 GetHalNetworkInfos(token, &(infoList->infos[index]));
1526 index++;
1527 token = strtok_r(NULL, "\n", &savedPtr);
1528 }
1529 pthread_mutex_unlock(GetInterfaceLock());
1530 free(reply);
1531 HDF_LOGI("%{public}s success", __func__);
1532 return HDF_SUCCESS;
1533 }
1534
WpaInterfaceP2pSaveConfig(struct IWpaInterface * self,const char * ifName)1535 int32_t WpaInterfaceP2pSaveConfig(struct IWpaInterface *self, const char *ifName)
1536 {
1537 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1538 (void)self;
1539 (void)ifName;
1540 pthread_mutex_lock(GetInterfaceLock());
1541 WifiWpaP2pInterface *pMainIfc = GetWifiWapP2pInterface(ifName);
1542 if (pMainIfc == NULL) {
1543 pthread_mutex_unlock(GetInterfaceLock());
1544 HDF_LOGE("%{public}s: pMainIfc is null", __func__);
1545 return HDF_ERR_INVALID_PARAM;
1546 }
1547 P2pSupplicantErrCode ret = pMainIfc->wpaP2pCliCmdStoreConfig(pMainIfc);
1548 if (ret != P2P_SUP_ERRCODE_SUCCESS) {
1549 pthread_mutex_unlock(GetInterfaceLock());
1550 HDF_LOGE("%{public}s: fail, ret = %{public}d", __func__, ret);
1551 return HDF_FAILURE;
1552 }
1553 pthread_mutex_unlock(GetInterfaceLock());
1554 HDF_LOGI("%{public}s success", __func__);
1555 return HDF_SUCCESS;
1556 }
1557
WpaInterfaceDeliverP2pData(struct IWpaInterface * self,const char * ifName,int32_t cmdType,int32_t dataType,const char * carryData)1558 int32_t WpaInterfaceDeliverP2pData(struct IWpaInterface *self, const char *ifName,
1559 int32_t cmdType, int32_t dataType, const char *carryData)
1560 {
1561 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1562 (void)self;
1563 (void)ifName;
1564 char cmd[CMD_SIZE] = {0};
1565 char buf[CMD_SIZE] = {0};
1566
1567 int32_t ret = 0;
1568 if (ifName == NULL) {
1569 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1570 return HDF_ERR_INVALID_PARAM;
1571 }
1572 pthread_mutex_lock(GetInterfaceLock());
1573 ret = snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1,
1574 "IFNAME=%s P2P_DELIVER_DATA cmdType=%d dataType=%d carryData=%s", ifName, cmdType, dataType, carryData);
1575 if (ret < 0) {
1576 pthread_mutex_unlock(GetInterfaceLock());
1577 HDF_LOGE("%{public}s snprintf_s failed, cmd: %{private}s, count = %{public}d", __func__, cmd, ret);
1578 return HDF_FAILURE;
1579 }
1580 if (WpaCliCmd(cmd, buf, sizeof(buf)) != 0) {
1581 pthread_mutex_unlock(GetInterfaceLock());
1582 HDF_LOGE("%{public}s command failed!", __func__);
1583 return HDF_FAILURE;
1584 }
1585 pthread_mutex_unlock(GetInterfaceLock());
1586 HDF_LOGI("%{public}s success", __func__);
1587 return HDF_SUCCESS;
1588 }
1589
WpaInterfaceVendorExtProcessCmd(struct IWpaInterface * self,const char * ifName,const char * cmd)1590 int32_t WpaInterfaceVendorExtProcessCmd(struct IWpaInterface *self, const char *ifName, const char *cmd)
1591 {
1592 #define NEW_CMD_MAX_LEN 400
1593 HDF_LOGI("Ready to enter hdi %{public}s", __func__);
1594 int32_t ret = 0;
1595 (void)self;
1596 if (cmd == NULL || ifName == NULL) {
1597 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1598 return HDF_ERR_INVALID_PARAM ;
1599 }
1600 pthread_mutex_lock(GetInterfaceLock());
1601 char *reply;
1602 const int replySize = REPLY_SIZE;
1603 reply = (char *)malloc(replySize);
1604 if (reply == NULL) {
1605 pthread_mutex_unlock(GetInterfaceLock());
1606 HDF_LOGE("%{public}s reply is NULL!", __func__);
1607 return HDF_FAILURE;
1608 }
1609
1610 char newCmd[NEW_CMD_MAX_LEN] = {0};
1611 if (snprintf_s(newCmd, sizeof(newCmd), sizeof(newCmd) - 1, "IFNAME=%s %s", ifName, cmd) < 0) {
1612 pthread_mutex_unlock(GetInterfaceLock());
1613 HDF_LOGE("%{public}s: snprintf_s is failed, error code: %{public}d", __func__, ret);
1614 free(reply);
1615 return HDF_FAILURE;
1616 }
1617
1618 if (WpaCliCmd(newCmd, reply, replySize) < 0) {
1619 pthread_mutex_unlock(GetInterfaceLock());
1620 HDF_LOGE("%{public}s WpaCliCmd failed!", __func__);
1621 free(reply);
1622 return HDF_FAILURE;
1623 }
1624
1625 HDF_LOGI("%{public}s reply %{public}s !", __func__, reply);
1626 pthread_mutex_unlock(GetInterfaceLock());
1627 ret = atoi(reply);
1628 free(reply);
1629 return ret;
1630 }
1631
WpaFillP2pDeviceFoundParam(struct P2pDeviceInfoParam * deviceInfoParam,struct HdiP2pDeviceInfoParam * hdiP2pDeviceInfoParam)1632 static int32_t WpaFillP2pDeviceFoundParam(struct P2pDeviceInfoParam *deviceInfoParam,
1633 struct HdiP2pDeviceInfoParam *hdiP2pDeviceInfoParam)
1634 {
1635 int32_t ret = 0;
1636 if (deviceInfoParam == NULL || hdiP2pDeviceInfoParam == NULL) {
1637 HDF_LOGE("%{public}s: deviceInfoParam or hdiP2pDeviceInfo is NULL!", __func__);
1638 return HDF_ERR_INVALID_PARAM;
1639 }
1640 hdiP2pDeviceInfoParam->configMethods = deviceInfoParam->configMethods;
1641 hdiP2pDeviceInfoParam->deviceCapabilities = deviceInfoParam->deviceCapabilities;
1642 hdiP2pDeviceInfoParam->groupCapabilities = deviceInfoParam->groupCapabilities;
1643 hdiP2pDeviceInfoParam->wfdLength = deviceInfoParam->wfdLength;
1644
1645 do {
1646 if (FillData(&hdiP2pDeviceInfoParam->srcAddress, &hdiP2pDeviceInfoParam->srcAddressLen,
1647 deviceInfoParam->srcAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
1648 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1649 ret = HDF_FAILURE;
1650 break;
1651 }
1652 if (FillData(&hdiP2pDeviceInfoParam->p2pDeviceAddress, &hdiP2pDeviceInfoParam->p2pDeviceAddressLen,
1653 deviceInfoParam->p2pDeviceAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
1654 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1655 ret = HDF_FAILURE;
1656 break;
1657 }
1658 if (FillData(&hdiP2pDeviceInfoParam->primaryDeviceType, &hdiP2pDeviceInfoParam->primaryDeviceTypeLen,
1659 deviceInfoParam->primaryDeviceType, WIFI_P2P_DEVICE_TYPE_LENGTH) != HDF_SUCCESS) {
1660 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1661 ret = HDF_FAILURE;
1662 break;
1663 }
1664 if (FillData(&hdiP2pDeviceInfoParam->deviceName, &hdiP2pDeviceInfoParam->deviceNameLen,
1665 deviceInfoParam->deviceName, WIFI_P2P_DEVICE_NAME_LENGTH) != HDF_SUCCESS) {
1666 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1667 ret = HDF_FAILURE;
1668 break;
1669 }
1670 if (deviceInfoParam->wfdLength != 0 &&
1671 FillData(&hdiP2pDeviceInfoParam->wfdDeviceInfo, &hdiP2pDeviceInfoParam->wfdDeviceInfoLen,
1672 deviceInfoParam->wfdDeviceInfo, deviceInfoParam->wfdLength) != HDF_SUCCESS) {
1673 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1674 ret = HDF_FAILURE;
1675 break;
1676 }
1677 if (FillData(&hdiP2pDeviceInfoParam->operSsid, &hdiP2pDeviceInfoParam->operSsidLen,
1678 deviceInfoParam->operSsid, WIFI_P2P_DEVICE_NAME_LENGTH) != HDF_SUCCESS) {
1679 HDF_LOGE("%{public}s: fill reason fail!", __func__);
1680 ret = HDF_FAILURE;
1681 }
1682 } while (0);
1683
1684 if (ret != HDF_SUCCESS) {
1685 if (hdiP2pDeviceInfoParam->srcAddress != NULL) {
1686 OsalMemFree(hdiP2pDeviceInfoParam->srcAddress);
1687 hdiP2pDeviceInfoParam->srcAddress = NULL;
1688 }
1689 if (hdiP2pDeviceInfoParam->p2pDeviceAddress != NULL) {
1690 OsalMemFree(hdiP2pDeviceInfoParam->p2pDeviceAddress);
1691 hdiP2pDeviceInfoParam->p2pDeviceAddress = NULL;
1692 }
1693 if (hdiP2pDeviceInfoParam->primaryDeviceType != NULL) {
1694 OsalMemFree(hdiP2pDeviceInfoParam->primaryDeviceType);
1695 hdiP2pDeviceInfoParam->primaryDeviceType = NULL;
1696 }
1697 if (hdiP2pDeviceInfoParam->deviceName != NULL) {
1698 OsalMemFree(hdiP2pDeviceInfoParam->deviceName);
1699 hdiP2pDeviceInfoParam->deviceName = NULL;
1700 }
1701 if (hdiP2pDeviceInfoParam->wfdDeviceInfo != NULL) {
1702 OsalMemFree(hdiP2pDeviceInfoParam->wfdDeviceInfo);
1703 hdiP2pDeviceInfoParam->wfdDeviceInfo = NULL;
1704 }
1705 if (hdiP2pDeviceInfoParam->operSsid != NULL) {
1706 OsalMemFree(hdiP2pDeviceInfoParam->operSsid);
1707 hdiP2pDeviceInfoParam->operSsid = NULL;
1708 }
1709 }
1710 return ret;
1711 }
1712
WpaFillP2pDeviceLostParam(struct P2pDeviceLostParam * deviceLostParam,struct HdiP2pDeviceLostParam * hdiP2pDeviceLostParam)1713 static int32_t WpaFillP2pDeviceLostParam(struct P2pDeviceLostParam *deviceLostParam,
1714 struct HdiP2pDeviceLostParam *hdiP2pDeviceLostParam)
1715 {
1716 int32_t ret = 0;
1717 if (deviceLostParam == NULL || hdiP2pDeviceLostParam == NULL) {
1718 HDF_LOGE("%{public}s: deviceLostParam or hdiP2pDeviceLostParam is NULL!", __func__);
1719 return HDF_ERR_INVALID_PARAM;
1720 }
1721 hdiP2pDeviceLostParam->networkId = deviceLostParam->networkId;
1722
1723 if (FillData(&hdiP2pDeviceLostParam->p2pDeviceAddress, &hdiP2pDeviceLostParam->p2pDeviceAddressLen,
1724 deviceLostParam->p2pDeviceAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
1725 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1726 ret = HDF_FAILURE;
1727 }
1728 if (ret != HDF_SUCCESS) {
1729 if (hdiP2pDeviceLostParam->p2pDeviceAddress != NULL) {
1730 OsalMemFree(hdiP2pDeviceLostParam->p2pDeviceAddress);
1731 hdiP2pDeviceLostParam->p2pDeviceAddress = NULL;
1732 }
1733 }
1734 return ret;
1735 }
1736
WpaFillP2pGoNegotiationRequestParam(struct P2pGoNegotiationRequestParam * goNegotiationRequestParam,struct HdiP2pGoNegotiationRequestParam * hdiP2pGoNegotiationRequestParam)1737 static int32_t WpaFillP2pGoNegotiationRequestParam(struct P2pGoNegotiationRequestParam *goNegotiationRequestParam,
1738 struct HdiP2pGoNegotiationRequestParam *hdiP2pGoNegotiationRequestParam)
1739 {
1740 int32_t ret = 0;
1741 if (goNegotiationRequestParam == NULL || hdiP2pGoNegotiationRequestParam == NULL) {
1742 HDF_LOGE("%{public}s: goNegotiationRequestParam or hdiP2pGoNegotiationRequestParam is NULL!", __func__);
1743 return HDF_ERR_INVALID_PARAM;
1744 }
1745 hdiP2pGoNegotiationRequestParam->passwordId = goNegotiationRequestParam->passwordId;
1746
1747 if (FillData(&hdiP2pGoNegotiationRequestParam->srcAddress, &hdiP2pGoNegotiationRequestParam->srcAddressLen,
1748 goNegotiationRequestParam->srcAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
1749 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1750 ret = HDF_FAILURE;
1751 }
1752 if (ret != HDF_SUCCESS) {
1753 if (hdiP2pGoNegotiationRequestParam->srcAddress != NULL) {
1754 OsalMemFree(hdiP2pGoNegotiationRequestParam->srcAddress);
1755 hdiP2pGoNegotiationRequestParam->srcAddress = NULL;
1756 }
1757 }
1758 return ret;
1759 }
1760
WpaFillP2pGoNegotiationCompletedParam(struct P2pGoNegotiationCompletedParam * goNegotiationCompletedParam,struct HdiP2pGoNegotiationCompletedParam * hdiP2pGoNegotiationCompletedParam)1761 static int32_t WpaFillP2pGoNegotiationCompletedParam(struct P2pGoNegotiationCompletedParam
1762 *goNegotiationCompletedParam, struct HdiP2pGoNegotiationCompletedParam *hdiP2pGoNegotiationCompletedParam)
1763 {
1764 int32_t ret = 0;
1765 if (goNegotiationCompletedParam == NULL || hdiP2pGoNegotiationCompletedParam == NULL) {
1766 HDF_LOGE("%{public}s: goNegotiationCompletedParam or hdiP2pGoNegotiationCompletedParam is NULL!", __func__);
1767 return HDF_ERR_INVALID_PARAM;
1768 }
1769 hdiP2pGoNegotiationCompletedParam->status = goNegotiationCompletedParam->status;
1770 return ret;
1771 }
1772
WpaFillP2pInvitationReceivedParam(struct P2pInvitationReceivedParam * invitationReceivedParam,struct HdiP2pInvitationReceivedParam * hdiP2pInvitationReceivedParam)1773 static int32_t WpaFillP2pInvitationReceivedParam(struct P2pInvitationReceivedParam *invitationReceivedParam,
1774 struct HdiP2pInvitationReceivedParam *hdiP2pInvitationReceivedParam)
1775 {
1776 int32_t ret = HDF_SUCCESS;
1777 if (invitationReceivedParam == NULL || hdiP2pInvitationReceivedParam == NULL) {
1778 HDF_LOGE("%{public}s: invitationReceivedParam or hdiP2pInvitationReceivedParam is NULL!", __func__);
1779 return HDF_ERR_INVALID_PARAM;
1780 }
1781 hdiP2pInvitationReceivedParam->type = invitationReceivedParam->type;
1782 hdiP2pInvitationReceivedParam->persistentNetworkId = invitationReceivedParam->persistentNetworkId;
1783 hdiP2pInvitationReceivedParam->operatingFrequency = invitationReceivedParam->operatingFrequency;
1784
1785 do {
1786 if (FillData(&hdiP2pInvitationReceivedParam->srcAddress, &hdiP2pInvitationReceivedParam->srcAddressLen,
1787 invitationReceivedParam->srcAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
1788 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1789 ret = HDF_FAILURE;
1790 break;
1791 }
1792 if (FillData(&hdiP2pInvitationReceivedParam->goDeviceAddress,
1793 &hdiP2pInvitationReceivedParam->goDeviceAddressLen,
1794 invitationReceivedParam->goDeviceAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
1795 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1796 ret = HDF_FAILURE;
1797 break;
1798 }
1799 if (FillData(&hdiP2pInvitationReceivedParam->bssid, &hdiP2pInvitationReceivedParam->bssidLen,
1800 invitationReceivedParam->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) {
1801 HDF_LOGE("%{public}s: fill ssid fail!", __func__);
1802 ret = HDF_FAILURE;
1803 }
1804 } while (0);
1805
1806 if (ret != HDF_SUCCESS) {
1807 if (hdiP2pInvitationReceivedParam->srcAddress != NULL) {
1808 OsalMemFree(hdiP2pInvitationReceivedParam->srcAddress);
1809 hdiP2pInvitationReceivedParam->srcAddress = NULL;
1810 }
1811 if (hdiP2pInvitationReceivedParam->goDeviceAddress != NULL) {
1812 OsalMemFree(hdiP2pInvitationReceivedParam->goDeviceAddress);
1813 hdiP2pInvitationReceivedParam->goDeviceAddress = NULL;
1814 }
1815 if (hdiP2pInvitationReceivedParam->bssid != NULL) {
1816 OsalMemFree(hdiP2pInvitationReceivedParam->bssid);
1817 hdiP2pInvitationReceivedParam->bssid = NULL;
1818 }
1819 }
1820 return ret;
1821 }
1822
WpaFillP2pInvitationResultParam(struct P2pInvitationResultParam * invitationResultParam,struct HdiP2pInvitationResultParam * hdiP2pInvitationResultParam)1823 static int32_t WpaFillP2pInvitationResultParam(struct P2pInvitationResultParam *invitationResultParam,
1824 struct HdiP2pInvitationResultParam *hdiP2pInvitationResultParam)
1825 {
1826 int32_t ret = HDF_SUCCESS;
1827 if (invitationResultParam == NULL || hdiP2pInvitationResultParam == NULL) {
1828 HDF_LOGE("%{public}s: invitationResultParam or hdiP2pInvitationResultParam is NULL!", __func__);
1829 return HDF_ERR_INVALID_PARAM;
1830 }
1831 hdiP2pInvitationResultParam->status = invitationResultParam->status;
1832
1833 if (FillData(&hdiP2pInvitationResultParam->bssid, &hdiP2pInvitationResultParam->bssidLen,
1834 invitationResultParam->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) {
1835 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1836 ret = HDF_FAILURE;
1837 }
1838 if (ret != HDF_SUCCESS) {
1839 if (hdiP2pInvitationResultParam->bssid != NULL) {
1840 OsalMemFree(hdiP2pInvitationResultParam->bssid);
1841 hdiP2pInvitationResultParam->bssid = NULL;
1842 }
1843 }
1844 return ret;
1845 }
1846
FillHdiP2pGroupInfoStartedParam(struct P2pGroupStartedParam * groupStartedParam,struct HdiP2pGroupInfoStartedParam * hdiP2pGroupStartedParam)1847 static int32_t FillHdiP2pGroupInfoStartedParam(struct P2pGroupStartedParam *groupStartedParam,
1848 struct HdiP2pGroupInfoStartedParam *hdiP2pGroupStartedParam)
1849 {
1850 int32_t ret = HDF_SUCCESS;
1851 if (groupStartedParam == NULL || hdiP2pGroupStartedParam == NULL) {
1852 HDF_LOGE("%{public}s: groupStartedParam or hdiP2pGroupStartedParam is NULL!", __func__);
1853 return HDF_ERR_INVALID_PARAM;
1854 }
1855 do {
1856 if (FillData(&hdiP2pGroupStartedParam->groupIfName, &hdiP2pGroupStartedParam->groupIfNameLen,
1857 groupStartedParam->groupIfName, WIFI_P2P_GROUP_IFNAME_LENGTH) != HDF_SUCCESS) {
1858 HDF_LOGE("%{public}s: fill groupIfName fail!", __func__);
1859 ret = HDF_FAILURE;
1860 break;
1861 }
1862 if (FillData(&hdiP2pGroupStartedParam->ssid, &hdiP2pGroupStartedParam->ssidLen,
1863 groupStartedParam->ssid, WIFI_SSID_LENGTH) != HDF_SUCCESS) {
1864 HDF_LOGE("%{public}s: fill ssid fail!", __func__);
1865 ret = HDF_FAILURE;
1866 break;
1867 }
1868 if (FillData(&hdiP2pGroupStartedParam->psk, &hdiP2pGroupStartedParam->pskLen,
1869 groupStartedParam->psk, WIFI_P2P_PASSWORD_SIZE) != HDF_SUCCESS) {
1870 HDF_LOGE("%{public}s: fill psk fail!", __func__);
1871 ret = HDF_FAILURE;
1872 break;
1873 }
1874 if (FillData(&hdiP2pGroupStartedParam->passphrase, &hdiP2pGroupStartedParam->passphraseLen,
1875 groupStartedParam->passphrase, WIFI_P2P_PASSWORD_SIZE) != HDF_SUCCESS) {
1876 HDF_LOGE("%{public}s: fill passphrase fail!", __func__);
1877 ret = HDF_FAILURE;
1878 break;
1879 }
1880 if (FillData(&hdiP2pGroupStartedParam->goDeviceAddress, &hdiP2pGroupStartedParam->goDeviceAddressLen,
1881 groupStartedParam->goDeviceAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
1882 HDF_LOGE("%{public}s: fill goDeviceAddress fail!", __func__);
1883 ret = HDF_FAILURE;
1884 }
1885 if (FillData(&hdiP2pGroupStartedParam->goRandomDeviceAddress,
1886 &hdiP2pGroupStartedParam->goRandomDeviceAddressLen,
1887 groupStartedParam->goRandomDeviceAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
1888 HDF_LOGE("%{public}s: fill goRandomDeviceAddress fail!", __func__);
1889 ret = HDF_FAILURE;
1890 }
1891 } while (0);
1892 return ret;
1893 }
1894
WpaFillP2pGroupInfoStartedParam(struct P2pGroupStartedParam * groupStartedParam,struct HdiP2pGroupInfoStartedParam * hdiP2pGroupStartedParam)1895 static int32_t WpaFillP2pGroupInfoStartedParam(struct P2pGroupStartedParam *groupStartedParam,
1896 struct HdiP2pGroupInfoStartedParam *hdiP2pGroupStartedParam)
1897 {
1898 int32_t ret = HDF_SUCCESS;
1899 if (groupStartedParam == NULL || hdiP2pGroupStartedParam == NULL) {
1900 HDF_LOGE("%{public}s: groupStartedParam or hdiP2pGroupStartedParam is NULL!", __func__);
1901 return HDF_ERR_INVALID_PARAM;
1902 }
1903 hdiP2pGroupStartedParam->isGo = groupStartedParam->isGo;
1904 hdiP2pGroupStartedParam->isPersistent = groupStartedParam->isPersistent;
1905 hdiP2pGroupStartedParam->frequency = groupStartedParam->frequency;
1906 ret = FillHdiP2pGroupInfoStartedParam(groupStartedParam, hdiP2pGroupStartedParam);
1907 if (ret != HDF_SUCCESS) {
1908 if (hdiP2pGroupStartedParam->groupIfName != NULL) {
1909 OsalMemFree(hdiP2pGroupStartedParam->groupIfName);
1910 hdiP2pGroupStartedParam->groupIfName = NULL;
1911 }
1912 if (hdiP2pGroupStartedParam->ssid != NULL) {
1913 OsalMemFree(hdiP2pGroupStartedParam->ssid);
1914 hdiP2pGroupStartedParam->ssid = NULL;
1915 }
1916 if (hdiP2pGroupStartedParam->psk != NULL) {
1917 OsalMemFree(hdiP2pGroupStartedParam->psk);
1918 hdiP2pGroupStartedParam->psk = NULL;
1919 }
1920 if (hdiP2pGroupStartedParam->passphrase != NULL) {
1921 OsalMemFree(hdiP2pGroupStartedParam->passphrase);
1922 hdiP2pGroupStartedParam->passphrase = NULL;
1923 }
1924 if (hdiP2pGroupStartedParam->goDeviceAddress != NULL) {
1925 OsalMemFree(hdiP2pGroupStartedParam->goDeviceAddress);
1926 hdiP2pGroupStartedParam->goDeviceAddress = NULL;
1927 }
1928 if (hdiP2pGroupStartedParam->goRandomDeviceAddress != NULL) {
1929 OsalMemFree(hdiP2pGroupStartedParam->goRandomDeviceAddress);
1930 hdiP2pGroupStartedParam->goRandomDeviceAddress = NULL;
1931 }
1932 }
1933 return ret;
1934 }
1935
WpaFillP2pGroupRemovedParam(struct P2pGroupRemovedParam * groupRemovedParam,struct HdiP2pGroupRemovedParam * hdiP2pGroupRemovedParam)1936 static int32_t WpaFillP2pGroupRemovedParam(struct P2pGroupRemovedParam *groupRemovedParam,
1937 struct HdiP2pGroupRemovedParam *hdiP2pGroupRemovedParam)
1938 {
1939 int32_t ret = HDF_SUCCESS;
1940 if (groupRemovedParam == NULL || hdiP2pGroupRemovedParam == NULL) {
1941 HDF_LOGE("%{public}s: groupStartedParam or hdiP2pGroupRemovedParam is NULL!", __func__);
1942 return HDF_ERR_INVALID_PARAM;
1943 }
1944 hdiP2pGroupRemovedParam->isGo = groupRemovedParam->isGo;
1945
1946 if (FillData(&hdiP2pGroupRemovedParam->groupIfName, &hdiP2pGroupRemovedParam->groupIfNameLen,
1947 groupRemovedParam->groupIfName, WIFI_P2P_GROUP_IFNAME_LENGTH) != HDF_SUCCESS) {
1948 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1949 ret = HDF_FAILURE;
1950 }
1951 if (ret != HDF_SUCCESS) {
1952 if (hdiP2pGroupRemovedParam->groupIfName != NULL) {
1953 OsalMemFree(hdiP2pGroupRemovedParam->groupIfName);
1954 hdiP2pGroupRemovedParam->groupIfName = NULL;
1955 }
1956 }
1957 return ret;
1958 }
1959
WpaFillP2pProvisionDiscoveryCompletedParam(struct P2pProvisionDiscoveryCompletedParam * provisionDiscoveryCompletedParam,struct HdiP2pProvisionDiscoveryCompletedParam * hdiP2pProvisionDiscoveryCompletedParam)1960 static int32_t WpaFillP2pProvisionDiscoveryCompletedParam(struct P2pProvisionDiscoveryCompletedParam
1961 *provisionDiscoveryCompletedParam,
1962 struct HdiP2pProvisionDiscoveryCompletedParam *hdiP2pProvisionDiscoveryCompletedParam)
1963 {
1964 int32_t ret = HDF_SUCCESS;
1965 if (provisionDiscoveryCompletedParam == NULL || hdiP2pProvisionDiscoveryCompletedParam == NULL) {
1966 HDF_LOGE("%{public}s: provisionDiscoveryCompletedParam or hdiP2pProvisionDiscoveryCompletedParam is NULL!",
1967 __func__);
1968 return HDF_ERR_INVALID_PARAM;
1969 }
1970 hdiP2pProvisionDiscoveryCompletedParam->isRequest = provisionDiscoveryCompletedParam->isRequest;
1971 hdiP2pProvisionDiscoveryCompletedParam->provDiscStatusCode = provisionDiscoveryCompletedParam->provDiscStatusCode;
1972 hdiP2pProvisionDiscoveryCompletedParam->configMethods = provisionDiscoveryCompletedParam->configMethods;
1973
1974 do {
1975 if (FillData(&hdiP2pProvisionDiscoveryCompletedParam->p2pDeviceAddress,
1976 &hdiP2pProvisionDiscoveryCompletedParam->p2pDeviceAddressLen,
1977 provisionDiscoveryCompletedParam->p2pDeviceAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
1978 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1979 ret = HDF_FAILURE;
1980 break;
1981 }
1982 if (FillData(&hdiP2pProvisionDiscoveryCompletedParam->generatedPin,
1983 &hdiP2pProvisionDiscoveryCompletedParam->generatedPinLen,
1984 provisionDiscoveryCompletedParam->generatedPin, WIFI_PIN_CODE_LENGTH) != HDF_SUCCESS) {
1985 HDF_LOGE("%{public}s: fill ssid fail!", __func__);
1986 ret = HDF_FAILURE;
1987 }
1988 } while (0);
1989
1990 if (ret != HDF_SUCCESS) {
1991 if (hdiP2pProvisionDiscoveryCompletedParam->p2pDeviceAddress != NULL) {
1992 OsalMemFree(hdiP2pProvisionDiscoveryCompletedParam->p2pDeviceAddress);
1993 hdiP2pProvisionDiscoveryCompletedParam->p2pDeviceAddress = NULL;
1994 }
1995 if (hdiP2pProvisionDiscoveryCompletedParam->generatedPin != NULL) {
1996 OsalMemFree(hdiP2pProvisionDiscoveryCompletedParam->generatedPin);
1997 hdiP2pProvisionDiscoveryCompletedParam->generatedPin = NULL;
1998 }
1999 }
2000 return ret;
2001 }
2002
WpaFillP2pServDiscReqParam(struct P2pServDiscReqInfoParam * servDiscReqInfo,struct HdiP2pServDiscReqInfoParam * hdiP2pServDiscReqInfo)2003 static int32_t WpaFillP2pServDiscReqParam(struct P2pServDiscReqInfoParam *servDiscReqInfo,
2004 struct HdiP2pServDiscReqInfoParam *hdiP2pServDiscReqInfo)
2005 {
2006 int32_t ret = HDF_SUCCESS;
2007 if (servDiscReqInfo == NULL || hdiP2pServDiscReqInfo == NULL) {
2008 HDF_LOGE("%{public}s: servDiscReqInfo or hdiP2pServDiscReqInfo is NULL!", __func__);
2009 return HDF_ERR_INVALID_PARAM;
2010 }
2011 hdiP2pServDiscReqInfo->freq = servDiscReqInfo->freq;
2012 hdiP2pServDiscReqInfo->dialogToken = servDiscReqInfo->dialogToken;
2013 hdiP2pServDiscReqInfo->updateIndic = servDiscReqInfo->updateIndic;
2014
2015 do {
2016 if (FillData(&hdiP2pServDiscReqInfo->mac, &hdiP2pServDiscReqInfo->macLen,
2017 servDiscReqInfo->mac, ETH_ADDR_LEN) != HDF_SUCCESS) {
2018 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
2019 ret = HDF_FAILURE;
2020 break;
2021 }
2022 if (FillData(&hdiP2pServDiscReqInfo->tlvs, &hdiP2pServDiscReqInfo->tlvsLen,
2023 servDiscReqInfo->tlvs, WIFI_P2P_TLVS_LENGTH) != HDF_SUCCESS) {
2024 HDF_LOGE("%{public}s: fill ssid fail!", __func__);
2025 ret = HDF_FAILURE;
2026 }
2027 } while (0);
2028
2029 if (ret != HDF_SUCCESS) {
2030 if (hdiP2pServDiscReqInfo->mac != NULL) {
2031 OsalMemFree(hdiP2pServDiscReqInfo->mac);
2032 hdiP2pServDiscReqInfo->mac = NULL;
2033 }
2034 if (hdiP2pServDiscReqInfo->tlvs != NULL) {
2035 OsalMemFree(hdiP2pServDiscReqInfo->tlvs);
2036 hdiP2pServDiscReqInfo->tlvs = NULL;
2037 }
2038 }
2039 return ret;
2040 }
2041
WpaFillP2pServDiscRespParam(struct P2pServDiscRespParam * servDiscRespParam,struct HdiP2pServDiscRespParam * hdiP2pServDiscRespParam)2042 static int32_t WpaFillP2pServDiscRespParam(struct P2pServDiscRespParam *servDiscRespParam,
2043 struct HdiP2pServDiscRespParam *hdiP2pServDiscRespParam)
2044 {
2045 int32_t ret = HDF_SUCCESS;
2046 if (servDiscRespParam == NULL || hdiP2pServDiscRespParam == NULL) {
2047 HDF_LOGE("%{public}s: servDiscRespParam or hdiP2pServDiscRespParam is NULL!", __func__);
2048 return HDF_ERR_INVALID_PARAM;
2049 }
2050 hdiP2pServDiscRespParam->updateIndicator = servDiscRespParam->updateIndicator;
2051
2052 do {
2053 if (FillData(&hdiP2pServDiscRespParam->srcAddress, &hdiP2pServDiscRespParam->srcAddressLen,
2054 servDiscRespParam->srcAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
2055 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
2056 ret = HDF_FAILURE;
2057 break;
2058 }
2059 if (FillData(&hdiP2pServDiscRespParam->tlvs, &hdiP2pServDiscRespParam->tlvsLen,
2060 servDiscRespParam->tlvs, WIFI_P2P_TLVS_LENGTH) != HDF_SUCCESS) {
2061 HDF_LOGE("%{public}s: fill ssid fail!", __func__);
2062 ret = HDF_FAILURE;
2063 }
2064 } while (0);
2065
2066 if (ret != HDF_SUCCESS) {
2067 if (hdiP2pServDiscRespParam->srcAddress != NULL) {
2068 OsalMemFree(hdiP2pServDiscRespParam->srcAddress);
2069 hdiP2pServDiscRespParam->srcAddress = NULL;
2070 }
2071 if (hdiP2pServDiscRespParam->tlvs != NULL) {
2072 OsalMemFree(hdiP2pServDiscRespParam->tlvs);
2073 hdiP2pServDiscRespParam->tlvs = NULL;
2074 }
2075 }
2076 return ret;
2077 }
2078
WpaFillP2pStaConnectStateParam(struct P2pStaConnectStateParam * staConnectStateParam,struct HdiP2pStaConnectStateParam * hdiP2pStaConnectStateParam)2079 static int32_t WpaFillP2pStaConnectStateParam(struct P2pStaConnectStateParam *staConnectStateParam,
2080 struct HdiP2pStaConnectStateParam *hdiP2pStaConnectStateParam)
2081 {
2082 int32_t ret = HDF_SUCCESS;
2083 if (staConnectStateParam == NULL || hdiP2pStaConnectStateParam == NULL) {
2084 HDF_LOGE("%{public}s: staConnectStateParam or hdiP2pStaConnectStateParam is NULL!", __func__);
2085 return HDF_ERR_INVALID_PARAM;
2086 }
2087 hdiP2pStaConnectStateParam->state = staConnectStateParam->state;
2088 do {
2089 if (FillData(&hdiP2pStaConnectStateParam->srcAddress, &hdiP2pStaConnectStateParam->srcAddressLen,
2090 staConnectStateParam->srcAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
2091 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
2092 ret = HDF_FAILURE;
2093 break;
2094 }
2095 if (FillData(&hdiP2pStaConnectStateParam->p2pDeviceAddress, &hdiP2pStaConnectStateParam->p2pDeviceAddressLen,
2096 staConnectStateParam->p2pDeviceAddress, ETH_ADDR_LEN) != HDF_SUCCESS) {
2097 HDF_LOGE("%{public}s: fill ssid fail!", __func__);
2098 ret = HDF_FAILURE;
2099 }
2100 } while (0);
2101
2102 if (ret != HDF_SUCCESS) {
2103 if (hdiP2pStaConnectStateParam->srcAddress != NULL) {
2104 OsalMemFree(hdiP2pStaConnectStateParam->srcAddress);
2105 hdiP2pStaConnectStateParam->srcAddress = NULL;
2106 }
2107 if (hdiP2pStaConnectStateParam->p2pDeviceAddress != NULL) {
2108 OsalMemFree(hdiP2pStaConnectStateParam->p2pDeviceAddress);
2109 hdiP2pStaConnectStateParam->p2pDeviceAddress = NULL;
2110 }
2111 }
2112 return ret;
2113 }
2114
WpaFillP2pIfaceCreatedParam(struct P2pIfaceCreatedParam * ifaceCreatedParam,struct HdiP2pIfaceCreatedParam * hdiP2pIfaceCreatedParam)2115 static int32_t WpaFillP2pIfaceCreatedParam(struct P2pIfaceCreatedParam *ifaceCreatedParam,
2116 struct HdiP2pIfaceCreatedParam *hdiP2pIfaceCreatedParam)
2117 {
2118 int32_t ret = HDF_SUCCESS;
2119 if (ifaceCreatedParam == NULL || hdiP2pIfaceCreatedParam == NULL) {
2120 HDF_LOGE("%{public}s: ifaceCreatedParam or hdiP2pIfaceCreatedParam is NULL!", __func__);
2121 return HDF_ERR_INVALID_PARAM;
2122 }
2123 hdiP2pIfaceCreatedParam->isGo = ifaceCreatedParam->isGo;
2124 return ret;
2125 }
2126
ProcessEventP2pDeviceFound(struct HdfWpaRemoteNode * node,struct P2pDeviceInfoParam * deviceInfoParam,const char * ifName)2127 int32_t ProcessEventP2pDeviceFound(struct HdfWpaRemoteNode *node,
2128 struct P2pDeviceInfoParam *deviceInfoParam, const char *ifName)
2129 {
2130 struct HdiP2pDeviceInfoParam hdiP2pDeviceInfo = {0};
2131 int32_t ret = HDF_FAILURE;
2132 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventDeviceFound == NULL) {
2133 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2134 return HDF_ERR_INVALID_PARAM;
2135 }
2136 if (WpaFillP2pDeviceFoundParam(deviceInfoParam, &hdiP2pDeviceInfo) != HDF_SUCCESS) {
2137 HDF_LOGE("%{public}s: hdiP2pDeviceInfo is NULL or deviceInfoParam fialed!", __func__);
2138 } else {
2139 ret = node->callbackObj->OnEventDeviceFound(node->callbackObj, &hdiP2pDeviceInfo, ifName);
2140 }
2141 HdiP2pDeviceInfoParamFree(&hdiP2pDeviceInfo, false);
2142 return ret;
2143 }
2144
ProcessEventP2pDeviceLost(struct HdfWpaRemoteNode * node,struct P2pDeviceLostParam * deviceLostParam,const char * ifName)2145 int32_t ProcessEventP2pDeviceLost(struct HdfWpaRemoteNode *node,
2146 struct P2pDeviceLostParam *deviceLostParam, const char *ifName)
2147 {
2148 struct HdiP2pDeviceLostParam hdiP2pDeviceLostParam = {0};
2149 int32_t ret = HDF_FAILURE;
2150 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventDeviceLost == NULL) {
2151 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2152 return HDF_ERR_INVALID_PARAM;
2153 }
2154 if (WpaFillP2pDeviceLostParam(deviceLostParam, &hdiP2pDeviceLostParam) != HDF_SUCCESS) {
2155 HDF_LOGE("%{public}s: hdiP2pDeviceLostParam is NULL or deviceLostParam fialed!", __func__);
2156 } else {
2157 ret = node->callbackObj->OnEventDeviceLost(node->callbackObj, &hdiP2pDeviceLostParam, ifName);
2158 }
2159 HdiP2pDeviceLostParamFree(&hdiP2pDeviceLostParam, false);
2160 return ret;
2161 }
2162
ProcessEventP2pGoNegotiationRequest(struct HdfWpaRemoteNode * node,struct P2pGoNegotiationRequestParam * goNegotiationRequestParam,const char * ifName)2163 int32_t ProcessEventP2pGoNegotiationRequest(struct HdfWpaRemoteNode *node,
2164 struct P2pGoNegotiationRequestParam *goNegotiationRequestParam, const char *ifName)
2165 {
2166 struct HdiP2pGoNegotiationRequestParam hdiP2pGoNegotiationRequestParam = {0};
2167 int32_t ret = HDF_FAILURE;
2168 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventGoNegotiationRequest == NULL) {
2169 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2170 return HDF_ERR_INVALID_PARAM;
2171 }
2172 if (WpaFillP2pGoNegotiationRequestParam(goNegotiationRequestParam,
2173 &hdiP2pGoNegotiationRequestParam) != HDF_SUCCESS) {
2174 HDF_LOGE("%{public}s: hdiP2pGoNegotiationRequestParam is NULL or goNegotiationRequestParam fialed!", __func__);
2175 } else {
2176 ret = node->callbackObj->OnEventGoNegotiationRequest(node->callbackObj,
2177 &hdiP2pGoNegotiationRequestParam, ifName);
2178 }
2179 HdiP2pGoNegotiationRequestParamFree(&hdiP2pGoNegotiationRequestParam, false);
2180 return ret;
2181 }
2182
ProcessEventP2pGoNegotiationCompleted(struct HdfWpaRemoteNode * node,struct P2pGoNegotiationCompletedParam * goNegotiationCompletedParam,const char * ifName)2183 int32_t ProcessEventP2pGoNegotiationCompleted(struct HdfWpaRemoteNode *node, struct P2pGoNegotiationCompletedParam
2184 *goNegotiationCompletedParam, const char *ifName)
2185 {
2186 struct HdiP2pGoNegotiationCompletedParam hdiP2pGoNegotiationCompletedParam = {0};
2187 int32_t ret = HDF_FAILURE;
2188 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventGoNegotiationCompleted == NULL) {
2189 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2190 return HDF_ERR_INVALID_PARAM;
2191 }
2192 if (WpaFillP2pGoNegotiationCompletedParam(goNegotiationCompletedParam,
2193 &hdiP2pGoNegotiationCompletedParam) != HDF_SUCCESS) {
2194 HDF_LOGE("%{public}s: hdiP2pGoNegotiationCompletedParam is NULL or goNegotiationCompletedParam fialed!",
2195 __func__);
2196 } else {
2197 ret = node->callbackObj->OnEventGoNegotiationCompleted(node->callbackObj,
2198 &hdiP2pGoNegotiationCompletedParam, ifName);
2199 }
2200 HdiP2pGoNegotiationCompletedParamFree(&hdiP2pGoNegotiationCompletedParam, false);
2201 return ret;
2202 }
2203
ProcessEventP2pInvitationReceived(struct HdfWpaRemoteNode * node,struct P2pInvitationReceivedParam * invitationReceivedParam,const char * ifName)2204 int32_t ProcessEventP2pInvitationReceived(struct HdfWpaRemoteNode *node,
2205 struct P2pInvitationReceivedParam *invitationReceivedParam, const char *ifName)
2206 {
2207 struct HdiP2pInvitationReceivedParam hdiP2pInvitationReceivedParam = {0};
2208 int32_t ret = HDF_FAILURE;
2209 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventInvitationReceived == NULL) {
2210 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2211 return HDF_ERR_INVALID_PARAM;
2212 }
2213 if (WpaFillP2pInvitationReceivedParam(invitationReceivedParam, &hdiP2pInvitationReceivedParam) != HDF_SUCCESS) {
2214 HDF_LOGE("%{public}s: hdiP2pInvitationReceivedParam is NULL or invitationReceivedParam fialed!", __func__);
2215 return ret;
2216 } else {
2217 ret = node->callbackObj->OnEventInvitationReceived(node->callbackObj, &hdiP2pInvitationReceivedParam, ifName);
2218 }
2219 HdiP2pInvitationReceivedParamFree(&hdiP2pInvitationReceivedParam, false);
2220 return ret;
2221 }
2222
ProcessEventP2pInvitationResult(struct HdfWpaRemoteNode * node,struct P2pInvitationResultParam * invitationResultParam,const char * ifName)2223 int32_t ProcessEventP2pInvitationResult(struct HdfWpaRemoteNode *node,
2224 struct P2pInvitationResultParam *invitationResultParam, const char *ifName)
2225 {
2226 struct HdiP2pInvitationResultParam hdiP2pInvitationResultParam = {0};
2227 int32_t ret = HDF_FAILURE;
2228 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventInvitationResult == NULL) {
2229 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2230 return HDF_ERR_INVALID_PARAM;
2231 }
2232 if (WpaFillP2pInvitationResultParam(invitationResultParam, &hdiP2pInvitationResultParam) != HDF_SUCCESS) {
2233 HDF_LOGE("%{public}s: hdiP2pInvitationResultParam is NULL or invitationResultParam fialed!", __func__);
2234 return ret;
2235 } else {
2236 ret = node->callbackObj->OnEventInvitationResult(node->callbackObj, &hdiP2pInvitationResultParam, ifName);
2237 }
2238 HdiP2pInvitationResultParamFree(&hdiP2pInvitationResultParam, false);
2239 return ret;
2240 }
2241
ProcessEventP2pGroupFormationSuccess(struct HdfWpaRemoteNode * node,const char * ifName)2242 int32_t ProcessEventP2pGroupFormationSuccess(struct HdfWpaRemoteNode *node,
2243 const char *ifName)
2244 {
2245 int32_t ret = HDF_FAILURE;
2246 if (node == NULL || node->callbackObj == NULL) {
2247 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2248 return HDF_ERR_INVALID_PARAM;
2249 }
2250 ret = node->callbackObj->OnEventGroupFormationSuccess(node->callbackObj, ifName);
2251 return ret;
2252 }
2253
ProcessEventP2pGroupFormationFailure(struct HdfWpaRemoteNode * node,char * reason,const char * ifName)2254 int32_t ProcessEventP2pGroupFormationFailure(struct HdfWpaRemoteNode *node, char *reason,
2255 const char *ifName)
2256 {
2257 char *hdiReason = NULL;
2258 int32_t ret = HDF_FAILURE;
2259 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventGroupFormationFailure == NULL ||
2260 reason == NULL) {
2261 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2262 return HDF_ERR_INVALID_PARAM;
2263 }
2264 hdiReason = (char *)OsalMemCalloc(WIFI_REASON_LENGTH);
2265 if ((hdiReason == NULL) || (strncpy_s(hdiReason, WIFI_REASON_LENGTH, reason, strlen(reason)) != HDF_SUCCESS)) {
2266 HDF_LOGE("%{public}s: hdiReason is NULL or reason fialed!", __func__);
2267 } else {
2268 ret = node->callbackObj->OnEventGroupFormationFailure(node->callbackObj, hdiReason, ifName);
2269 }
2270 OsalMemFree(hdiReason);
2271 hdiReason = NULL;
2272 return ret;
2273 }
2274
ProcessEventP2pGroupStarted(struct HdfWpaRemoteNode * node,struct P2pGroupStartedParam * groupStartedParam,const char * ifName)2275 int32_t ProcessEventP2pGroupStarted(struct HdfWpaRemoteNode *node,
2276 struct P2pGroupStartedParam *groupStartedParam, const char *ifName)
2277 {
2278 struct HdiP2pGroupInfoStartedParam hdiP2pGroupInfoStartedParam = {0};
2279 int32_t ret = HDF_FAILURE;
2280 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventGroupInfoStarted == NULL) {
2281 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2282 return HDF_ERR_INVALID_PARAM;
2283 }
2284 if (WpaFillP2pGroupInfoStartedParam(groupStartedParam, &hdiP2pGroupInfoStartedParam) != HDF_SUCCESS) {
2285 HDF_LOGE("%{public}s: hdiP2pGroupStartedParam is NULL or groupStartedParam fialed!", __func__);
2286 } else {
2287 ret = node->callbackObj->OnEventGroupInfoStarted(node->callbackObj, &hdiP2pGroupInfoStartedParam, ifName);
2288 }
2289 HdiP2pGroupInfoStartedParamFree(&hdiP2pGroupInfoStartedParam, false);
2290 return ret;
2291 }
2292
ProcessEventP2pGroupRemoved(struct HdfWpaRemoteNode * node,struct P2pGroupRemovedParam * groupRemovedParam,const char * ifName)2293 int32_t ProcessEventP2pGroupRemoved(struct HdfWpaRemoteNode *node,
2294 struct P2pGroupRemovedParam *groupRemovedParam, const char *ifName)
2295 {
2296 struct HdiP2pGroupRemovedParam hdiP2pGroupRemovedParam = {0};
2297 int32_t ret = HDF_FAILURE;
2298 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventGroupRemoved == NULL) {
2299 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2300 return HDF_ERR_INVALID_PARAM;
2301 }
2302 if (WpaFillP2pGroupRemovedParam(groupRemovedParam, &hdiP2pGroupRemovedParam) != HDF_SUCCESS) {
2303 HDF_LOGE("%{public}s: hdiP2pGroupRemovedParam is NULL or groupRemovedParam fialed!", __func__);
2304 } else {
2305 ret = node->callbackObj->OnEventGroupRemoved(node->callbackObj, &hdiP2pGroupRemovedParam, ifName);
2306 }
2307 HdiP2pGroupRemovedParamFree(&hdiP2pGroupRemovedParam, false);
2308 return ret;
2309 }
2310
ProcessEventP2pProvisionDiscoveryCompleted(struct HdfWpaRemoteNode * node,struct P2pProvisionDiscoveryCompletedParam * provisionDiscoveryCompletedParam,const char * ifName)2311 int32_t ProcessEventP2pProvisionDiscoveryCompleted(struct HdfWpaRemoteNode *node,
2312 struct P2pProvisionDiscoveryCompletedParam *provisionDiscoveryCompletedParam, const char *ifName)
2313 {
2314 struct HdiP2pProvisionDiscoveryCompletedParam hdiP2pProvisionDiscoveryCompletedParam = {0};
2315 int32_t ret = HDF_FAILURE;
2316 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventProvisionDiscoveryCompleted == NULL) {
2317 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2318 return HDF_ERR_INVALID_PARAM;
2319 }
2320 if (WpaFillP2pProvisionDiscoveryCompletedParam(provisionDiscoveryCompletedParam,
2321 &hdiP2pProvisionDiscoveryCompletedParam) != HDF_SUCCESS) {
2322 HDF_LOGE("%{public}s: Param is NULL or provisionDiscoveryCompletedParam fialed!", __func__);
2323 } else {
2324 ret = node->callbackObj->OnEventProvisionDiscoveryCompleted(node->callbackObj,
2325 &hdiP2pProvisionDiscoveryCompletedParam, ifName);
2326 }
2327 HdiP2pProvisionDiscoveryCompletedParamFree(&hdiP2pProvisionDiscoveryCompletedParam, false);
2328 return ret;
2329 }
2330
ProcessEventP2pFindStopped(struct HdfWpaRemoteNode * node,const char * ifName)2331 int32_t ProcessEventP2pFindStopped(struct HdfWpaRemoteNode *node,
2332 const char *ifName)
2333 {
2334 int32_t ret = HDF_FAILURE;
2335 if (node == NULL || node->callbackObj == NULL) {
2336 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2337 return HDF_ERR_INVALID_PARAM;
2338 }
2339 ret = node->callbackObj->OnEventFindStopped(node->callbackObj, ifName);
2340 return ret;
2341 }
2342
ProcessEventP2pServDiscReq(struct HdfWpaRemoteNode * node,struct P2pServDiscReqInfoParam * servDiscReqInfo,const char * ifName)2343 int32_t ProcessEventP2pServDiscReq(struct HdfWpaRemoteNode *node,
2344 struct P2pServDiscReqInfoParam *servDiscReqInfo, const char *ifName)
2345 {
2346 struct HdiP2pServDiscReqInfoParam hdiP2pServDiscReqInfo = {0};
2347 int32_t ret = HDF_FAILURE;
2348 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventServDiscReq == NULL) {
2349 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2350 return HDF_ERR_INVALID_PARAM;
2351 }
2352 if (WpaFillP2pServDiscReqParam(servDiscReqInfo, &hdiP2pServDiscReqInfo) != HDF_SUCCESS) {
2353 HDF_LOGE("%{public}s: hdiP2pServDiscReqInfo is NULL or servDiscReqInfo fialed!", __func__);
2354 } else {
2355 ret = node->callbackObj->OnEventServDiscReq(node->callbackObj, &hdiP2pServDiscReqInfo, ifName);
2356 }
2357 HdiP2pServDiscReqInfoParamFree(&hdiP2pServDiscReqInfo, false);
2358 return ret;
2359 }
2360
ProcessEventP2pServDiscResp(struct HdfWpaRemoteNode * node,struct P2pServDiscRespParam * servDiscRespParam,const char * ifName)2361 int32_t ProcessEventP2pServDiscResp(struct HdfWpaRemoteNode *node,
2362 struct P2pServDiscRespParam *servDiscRespParam, const char *ifName)
2363 {
2364 struct HdiP2pServDiscRespParam hdiP2pServDiscRespParam = {0};
2365 int32_t ret = HDF_FAILURE;
2366 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventServDiscResp == NULL) {
2367 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2368 return HDF_ERR_INVALID_PARAM;
2369 }
2370 if (WpaFillP2pServDiscRespParam(servDiscRespParam, &hdiP2pServDiscRespParam) != HDF_SUCCESS) {
2371 HDF_LOGE("%{public}s: hdiP2pServDiscRespParam is NULL or servDiscRespParam fialed!", __func__);
2372 } else {
2373 ret = node->callbackObj->OnEventServDiscResp(node->callbackObj, &hdiP2pServDiscRespParam, ifName);
2374 }
2375 HdiP2pServDiscRespParamFree(&hdiP2pServDiscRespParam, false);
2376 return ret;
2377 }
2378
ProcessEventP2pStaConnectState(struct HdfWpaRemoteNode * node,struct P2pStaConnectStateParam * staConnectStateParam,const char * ifName)2379 int32_t ProcessEventP2pStaConnectState(struct HdfWpaRemoteNode *node,
2380 struct P2pStaConnectStateParam *staConnectStateParam, const char *ifName)
2381 {
2382 struct HdiP2pStaConnectStateParam hdiP2pStaConnectStateParam = {0};
2383 int32_t ret = HDF_FAILURE;
2384 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventStaConnectState == NULL) {
2385 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2386 return HDF_ERR_INVALID_PARAM;
2387 }
2388 if (WpaFillP2pStaConnectStateParam(staConnectStateParam, &hdiP2pStaConnectStateParam) != HDF_SUCCESS) {
2389 HDF_LOGE("%{public}s: hdiP2pStaConnectStateParam is NULL or staConnectStateParam fialed!", __func__);
2390 } else {
2391 ret = node->callbackObj->OnEventStaConnectState(node->callbackObj, &hdiP2pStaConnectStateParam, ifName);
2392 }
2393 HdiP2pStaConnectStateParamFree(&hdiP2pStaConnectStateParam, false);
2394 return ret;
2395 }
2396
ProcessEventP2pIfaceCreated(struct HdfWpaRemoteNode * node,struct P2pIfaceCreatedParam * ifaceCreatedParam,const char * ifName)2397 int32_t ProcessEventP2pIfaceCreated(struct HdfWpaRemoteNode *node, struct P2pIfaceCreatedParam *ifaceCreatedParam,
2398 const char *ifName)
2399 {
2400 struct HdiP2pIfaceCreatedParam hdiP2pIfaceCreatedParam = {0};
2401 int32_t ret = HDF_FAILURE;
2402 if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventIfaceCreated == NULL) {
2403 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
2404 return HDF_ERR_INVALID_PARAM;
2405 }
2406 if (WpaFillP2pIfaceCreatedParam(ifaceCreatedParam, &hdiP2pIfaceCreatedParam) != HDF_SUCCESS) {
2407 HDF_LOGE("%{public}s: hdiP2pIfaceCreatedParam is NULL or ifaceCreatedParam fialed!", __func__);
2408 } else {
2409 ret = node->callbackObj->OnEventIfaceCreated(node->callbackObj, &hdiP2pIfaceCreatedParam, ifName);
2410 }
2411 HdiP2pIfaceCreatedParamFree(&hdiP2pIfaceCreatedParam, false);
2412 return ret;
2413 }
2414