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