• 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 
16 #ifdef HDI_WPA_INTERFACE_SUPPORT
17 #include "wifi_hdi_wpa_p2p_impl.h"
18 #include "wifi_hdi_util.h"
19 #include "wifi_log.h"
20 #include "stub_collector.h"
21 #include "wifi_native_define.h"
22 
23 #undef LOG_TAG
24 #define LOG_TAG "WifiHdiWpaP2pImpl"
25 #define REPLY_BUF_LENGTH (1024)
26 #define BUFF_SIZE 256
27 #define P2P_RANDOM_MAC_FLAG "p2p_device_random_mac_addr=1\n"
28 #define PERSISENT_MAC_LEN 55
29 #define PERSISENT_MAC_STRING "p2p_device_persistent_mac_addr"
30 #define P2P_SUPPLICANT_PATH CONFIG_ROOR_DIR"/wpa_supplicant/p2p_supplicant.conf"
31 
32 typedef struct HdiP2pWpaNetworkField {
33     P2pGroupConfigType field;
34     char fieldName[32];
35     int flag; /* 0 need add "" 1 no need */
36 } HdiP2pWpaNetworkField;
37 
38 static const HdiP2pWpaNetworkField g_hdiP2pWpaNetworkFields[] = {
39     {GROUP_CONFIG_SSID, "ssid", 0},
40     {GROUP_CONFIG_BSSID, "bssid", 1},
41     {GROUP_CONFIG_PSK, "psk", 1},
42     {GROUP_CONFIG_PROTO, "proto", 1},
43     {GROUP_CONFIG_KEY_MGMT, "key_mgmt", 1},
44     {GROUP_CONFIG_PAIRWISE, "pairwise", 1},
45     {GROUP_CONFIG_AUTH_ALG, "auth_alg", 1},
46     {GROUP_CONFIG_MODE, "mode", 1},
47     {GROUP_CONFIG_DISABLED, "disabled", 1},
48     {GROUP_CONFIG_CLIENTLIST, "p2p_client_list", 1}
49 };
50 
51 static struct IWpaCallback *g_hdiWpaP2pCallbackObj = NULL;
52 
ReleaseP2pCallback(void)53 void ReleaseP2pCallback(void)
54 {
55     StubCollectorRemoveObject(IWPACALLBACK_INTERFACE_DESC, g_hdiWpaP2pCallbackObj);
56     free(g_hdiWpaP2pCallbackObj);
57     g_hdiWpaP2pCallbackObj = NULL;
58 }
59 
RegisterP2pEventCallback()60 static WifiErrorNo RegisterP2pEventCallback()
61 {
62     LOGI("RegisterP2pEventCallback enter");
63     pthread_mutex_lock(GetWpaObjMutex());
64     if (g_hdiWpaP2pCallbackObj == NULL) {
65         pthread_mutex_unlock(GetWpaObjMutex());
66         LOGE("RegisterP2pEventCallback: g_hdiWpaP2pCallbackObj is NULL");
67         return WIFI_HAL_OPT_FAILED;
68     }
69 
70     struct IWpaInterface *wpaObj = GetWpaInterface();
71     if (wpaObj == NULL) {
72         pthread_mutex_unlock(GetWpaObjMutex());
73         LOGE("RegisterP2pEventCallback: wpaObj is NULL");
74         return WIFI_HAL_OPT_FAILED;
75     }
76 
77     int32_t result = wpaObj->RegisterWpaEventCallback(wpaObj, g_hdiWpaP2pCallbackObj, GetHdiP2pIfaceName());
78     if (result != HDF_SUCCESS) {
79         pthread_mutex_unlock(GetWpaObjMutex());
80         LOGE("RegisterP2pEventCallback: RegisterEventCallback failed result:%{public}d", result);
81         return WIFI_HAL_OPT_FAILED;
82     }
83 
84     pthread_mutex_unlock(GetWpaObjMutex());
85     LOGI("RegisterP2pEventCallback success.");
86     return WIFI_HAL_OPT_OK;
87 }
88 
AddP2pRandomMacFlag()89 static WifiErrorNo AddP2pRandomMacFlag()
90 {
91     char str[BUFF_SIZE] = { 0 };
92     int indicate = 0;
93     FILE *fp = fopen(P2P_WPA_CONFIG_FILE, "a+");
94     if (fp == NULL) {
95         LOGE("%{public}s: failed to open the file", __func__);
96         return WIFI_HAL_OPT_FAILED;
97     }
98     while (fgets(str, BUFF_SIZE, fp)) {
99         if (strstr(str, P2P_RANDOM_MAC_FLAG) != NULL) {
100             indicate = 1;
101             break;
102         }
103         if (memset_s(str, sizeof(str), 0x0, sizeof(str)) != EOK) {
104             LOGE("%{public}s: memset_s is failed", __func__);
105             fclose(fp);
106             return WIFI_HAL_OPT_FAILED;
107         }
108     }
109     if (indicate == 0) {
110         int ret = fputs(P2P_RANDOM_MAC_FLAG, fp);
111         if (ret < 0) {
112             LOGE("%{public}s: failed to update the file", __func__);
113             fclose(fp);
114             return WIFI_HAL_OPT_FAILED;
115         } else {
116             LOGD("%{public}s: success to update the file, ret:%{public}d", __func__, ret);
117         }
118     }
119     fclose(fp);
120     return WIFI_HAL_OPT_OK;
121 }
122 
HdiWpaP2pStart(const char * ifaceName,const bool hasPersisentGroup)123 WifiErrorNo HdiWpaP2pStart(const char *ifaceName, const bool hasPersisentGroup)
124 {
125     LOGI("HdiWpaP2pStart enter");
126     if (SetHdiP2pIfaceName(ifaceName) != WIFI_HAL_OPT_OK) {
127         LOGE("HdiWpaP2pStart: set p2p iface name failed!");
128         return WIFI_HAL_OPT_FAILED;
129     }
130     if (access(CONFIG_ROOR_DIR"/wpa_supplicant/p2p_supplicant.conf", F_OK) == -1) {
131         if (CopyConfigFile("p2p_supplicant.conf") != WIFI_HAL_OPT_OK) {
132             LOGE("HdiWpaP2pStart: CopyConfigFile failed!");
133             return WIFI_HAL_OPT_FAILED;
134         }
135     }
136     if (HdiWpaStart() != WIFI_HAL_OPT_OK) {
137         LOGE("HdiWpaP2pStart: HdiWpaStart failed!");
138         return WIFI_HAL_OPT_FAILED;
139     }
140 
141     if (RegisterP2pEventCallback() != WIFI_HAL_OPT_OK) {
142         LOGE("HdiWpaP2pStart: RegisterEventCallback failed!");
143         return WIFI_HAL_OPT_FAILED;
144     }
145 
146     if (HdiAddWpaIface(GetHdiP2pIfaceName(), CONFIG_ROOR_DIR"/wpa_supplicant/p2p_supplicant.conf") != WIFI_HAL_OPT_OK) {
147         LOGE("HdiWpaP2pStart: HdiAddWpaIface failed!");
148         return WIFI_HAL_OPT_FAILED;
149     }
150 
151     LOGI("HdiWpaP2pStart success");
152     return WIFI_HAL_OPT_OK;
153 }
154 
HdiWpaP2pStop()155 WifiErrorNo HdiWpaP2pStop()
156 {
157     LOGI("HdiWpaP2pStop enter");
158     if (IsHdiWpaStopped() == WIFI_HAL_OPT_OK) {
159         LOGE("HdiWpaP2pStop: HdiWpa already stopped, HdiWpaP2pStop success");
160         return WIFI_HAL_OPT_OK;
161     }
162 
163     if (HdiRemoveWpaIface(GetHdiP2pIfaceName()) != WIFI_HAL_OPT_OK) {
164         LOGE("HdiWpaP2pStop: HdiRemoveWpaIface failed!");
165         return WIFI_HAL_OPT_FAILED;
166     }
167 
168     LOGI("HdiWpaP2pStop success");
169     return WIFI_HAL_OPT_OK;
170 }
171 
InitHdiWpaP2pCallbackObj(struct IWpaCallback * callback)172 static void InitHdiWpaP2pCallbackObj(struct IWpaCallback *callback)
173 {
174     g_hdiWpaP2pCallbackObj->OnEventDeviceFound = callback->OnEventDeviceFound;
175     g_hdiWpaP2pCallbackObj->OnEventDeviceLost = callback->OnEventDeviceLost;
176     g_hdiWpaP2pCallbackObj->OnEventGoNegotiationRequest = callback->OnEventGoNegotiationRequest;
177     g_hdiWpaP2pCallbackObj->OnEventGoNegotiationCompleted = callback->OnEventGoNegotiationCompleted;
178     g_hdiWpaP2pCallbackObj->OnEventInvitationReceived = callback->OnEventInvitationReceived;
179     g_hdiWpaP2pCallbackObj->OnEventInvitationResult = callback->OnEventInvitationResult;
180     g_hdiWpaP2pCallbackObj->OnEventGroupFormationSuccess = callback->OnEventGroupFormationSuccess;
181     g_hdiWpaP2pCallbackObj->OnEventGroupFormationFailure = callback->OnEventGroupFormationFailure;
182     g_hdiWpaP2pCallbackObj->OnEventGroupStarted = callback->OnEventGroupStarted;
183     g_hdiWpaP2pCallbackObj->OnEventGroupInfoStarted = callback->OnEventGroupInfoStarted;
184     g_hdiWpaP2pCallbackObj->OnEventGroupRemoved = callback->OnEventGroupRemoved;
185     g_hdiWpaP2pCallbackObj->OnEventProvisionDiscoveryCompleted = callback->OnEventProvisionDiscoveryCompleted;
186     g_hdiWpaP2pCallbackObj->OnEventFindStopped = callback->OnEventFindStopped;
187     g_hdiWpaP2pCallbackObj->OnEventServDiscReq = callback->OnEventServDiscReq;
188     g_hdiWpaP2pCallbackObj->OnEventServDiscResp = callback->OnEventServDiscResp;
189     g_hdiWpaP2pCallbackObj->OnEventStaConnectState = callback->OnEventStaConnectState;
190     g_hdiWpaP2pCallbackObj->OnEventIfaceCreated = callback->OnEventIfaceCreated;
191 }
192 
RegisterHdiWpaP2pEventCallback(struct IWpaCallback * callback)193 WifiErrorNo RegisterHdiWpaP2pEventCallback(struct IWpaCallback *callback)
194 {
195     LOGI("RegisterHdiWpaP2pEventCallback enter");
196     pthread_mutex_lock(GetWpaObjMutex());
197     if (callback == NULL || callback->OnEventDeviceFound == NULL) {
198         pthread_mutex_unlock(GetWpaObjMutex());
199         LOGE("RegisterHdiWpaP2pEventCallback: invalid parameter!");
200         return WIFI_HAL_OPT_INVALID_PARAM;
201     }
202 
203     if (g_hdiWpaP2pCallbackObj != NULL) {
204         pthread_mutex_unlock(GetWpaObjMutex());
205         LOGI("RegisterHdiWpaP2pEventCallback: already register!");
206         return WIFI_HAL_OPT_OK;
207     }
208 
209     g_hdiWpaP2pCallbackObj = (struct IWpaCallback *)malloc(sizeof(struct IWpaCallback));
210     if (g_hdiWpaP2pCallbackObj == NULL) {
211         pthread_mutex_unlock(GetWpaObjMutex());
212         LOGE("RegisterHdiWpaP2pEventCallback: IWpaCallback malloc failed!");
213         return WIFI_HAL_OPT_FAILED;
214     }
215     if (memset_s(g_hdiWpaP2pCallbackObj, sizeof(struct IWpaCallback),
216         0, sizeof(struct IWpaCallback)) != EOK) {
217         pthread_mutex_unlock(GetWpaObjMutex());
218         return WIFI_HAL_OPT_FAILED;
219     }
220     InitHdiWpaP2pCallbackObj(callback);
221     pthread_mutex_unlock(GetWpaObjMutex());
222     LOGI("RegisterHdiWpaP2pEventCallback success.");
223     return WIFI_HAL_OPT_OK;
224 }
225 
HdiP2pSetSsidPostfixName(const char * name)226 WifiErrorNo HdiP2pSetSsidPostfixName(const char *name)
227 {
228     LOGI("HdiP2pSetSsidPostfixName enter, name:%{private}s", name);
229     pthread_mutex_lock(GetWpaObjMutex());
230     struct IWpaInterface *wpaObj = GetWpaInterface();
231     if (wpaObj == NULL) {
232         LOGE("HdiP2pSetSsidPostfixName: wpaObj is NULL");
233         pthread_mutex_unlock(GetWpaObjMutex());
234         return WIFI_HAL_OPT_FAILED;
235     }
236 
237     int32_t result = wpaObj->P2pSetSsidPostfixName(wpaObj, GetHdiP2pIfaceName(), name);
238     if (result != HDF_SUCCESS) {
239         LOGE("HdiP2pSetSsidPostfixName: P2pSetSsidPostfixName failed result:%{public}d", result);
240         pthread_mutex_unlock(GetWpaObjMutex());
241         return WIFI_HAL_OPT_FAILED;
242     }
243     pthread_mutex_unlock(GetWpaObjMutex());
244     LOGI("HdiP2pSetSsidPostfixName success.");
245     return WIFI_HAL_OPT_OK;
246 }
247 
HdiP2pSetWpsDeviceType(const char * type)248 WifiErrorNo HdiP2pSetWpsDeviceType(const char *type)
249 {
250     LOGI("HdiP2pSetWpsDeviceType enter");
251     pthread_mutex_lock(GetWpaObjMutex());
252     struct IWpaInterface *wpaObj = GetWpaInterface();
253     if (wpaObj == NULL) {
254         LOGE("HdiP2pSetWpsDeviceType: wpaObj is NULL");
255         pthread_mutex_unlock(GetWpaObjMutex());
256         return WIFI_HAL_OPT_FAILED;
257     }
258 
259     int32_t result = wpaObj->P2pSetWpsDeviceType(wpaObj, GetHdiP2pIfaceName(), type);
260     if (result != HDF_SUCCESS) {
261         LOGE("HdiP2pSetWpsDeviceType: P2pSetWpsDeviceType failed result:%{public}d", result);
262         pthread_mutex_unlock(GetWpaObjMutex());
263         return WIFI_HAL_OPT_FAILED;
264     }
265     pthread_mutex_unlock(GetWpaObjMutex());
266     LOGI("HdiP2pSetWpsDeviceType success.");
267     return WIFI_HAL_OPT_OK;
268 }
269 
HdiP2pSetWpsConfigMethods(const char * methods)270 WifiErrorNo HdiP2pSetWpsConfigMethods(const char *methods)
271 {
272     LOGI("HdiP2pSetWpsConfigMethods enter");
273     pthread_mutex_lock(GetWpaObjMutex());
274     struct IWpaInterface *wpaObj = GetWpaInterface();
275     if (wpaObj == NULL) {
276         LOGE("HdiP2pSetWpsConfigMethods: wpaObj is NULL");
277         pthread_mutex_unlock(GetWpaObjMutex());
278         return WIFI_HAL_OPT_FAILED;
279     }
280 
281     int32_t result = wpaObj->P2pSetWpsConfigMethods(wpaObj, GetHdiP2pIfaceName(), methods);
282     if (result != HDF_SUCCESS) {
283         LOGE("HdiP2pSetWpsConfigMethods: P2pSetWpsConfigMethods failed result:%{public}d", result);
284         pthread_mutex_unlock(GetWpaObjMutex());
285         return WIFI_HAL_OPT_FAILED;
286     }
287     pthread_mutex_unlock(GetWpaObjMutex());
288     LOGI("HdiP2pSetWpsConfigMethods success.");
289     return WIFI_HAL_OPT_OK;
290 }
291 
HdiP2pSetGroupMaxIdle(const char * groupIfc,int time)292 WifiErrorNo HdiP2pSetGroupMaxIdle(const char *groupIfc, int time)
293 {
294     LOGI("HdiP2pSetGroupMaxIdle enter");
295     pthread_mutex_lock(GetWpaObjMutex());
296     struct IWpaInterface *wpaObj = GetWpaInterface();
297     if (wpaObj == NULL) {
298         LOGE("HdiP2pSetGroupMaxIdle: wpaObj is NULL");
299         pthread_mutex_unlock(GetWpaObjMutex());
300         return WIFI_HAL_OPT_FAILED;
301     }
302 
303     int32_t result = wpaObj->P2pSetGroupMaxIdle(wpaObj, groupIfc, time);
304     if (result != HDF_SUCCESS) {
305         LOGE("HdiP2pSetGroupMaxIdle: P2pSetGroupMaxIdle failed result:%{public}d", result);
306         pthread_mutex_unlock(GetWpaObjMutex());
307         return WIFI_HAL_OPT_FAILED;
308     }
309     pthread_mutex_unlock(GetWpaObjMutex());
310     LOGI("HdiP2pSetGroupMaxIdle success.");
311     return WIFI_HAL_OPT_OK;
312 }
313 
HdiP2pSetWfdEnable(int enable)314 WifiErrorNo HdiP2pSetWfdEnable(int enable)
315 {
316     LOGI("HdiP2pSetWfdEnable enter");
317     pthread_mutex_lock(GetWpaObjMutex());
318     struct IWpaInterface *wpaObj = GetWpaInterface();
319     if (wpaObj == NULL) {
320         LOGE("HdiP2pSetWfdEnable: wpaObj is NULL");
321         pthread_mutex_unlock(GetWpaObjMutex());
322         return WIFI_HAL_OPT_FAILED;
323     }
324 
325     int32_t result = wpaObj->P2pSetWfdEnable(wpaObj, GetHdiP2pIfaceName(), enable);
326     if (result != HDF_SUCCESS) {
327         LOGE("HdiP2pSetWfdEnable: P2pSetWfdEnable failed result:%{public}d", result);
328         pthread_mutex_unlock(GetWpaObjMutex());
329         return WIFI_HAL_OPT_FAILED;
330     }
331     pthread_mutex_unlock(GetWpaObjMutex());
332     LOGI("HdiP2pSetWfdEnable success.");
333     return WIFI_HAL_OPT_OK;
334 }
335 
HdiP2pSetPersistentReconnect(int status)336 WifiErrorNo HdiP2pSetPersistentReconnect(int status)
337 {
338     LOGI("HdiP2pSetPersistentReconnect enter");
339     pthread_mutex_lock(GetWpaObjMutex());
340     struct IWpaInterface *wpaObj = GetWpaInterface();
341     if (wpaObj == NULL) {
342         LOGE("HdiP2pSetPersistentReconnect: wpaObj is NULL");
343         pthread_mutex_unlock(GetWpaObjMutex());
344         return WIFI_HAL_OPT_FAILED;
345     }
346 
347     int32_t result = wpaObj->P2pSetPersistentReconnect(wpaObj, GetHdiP2pIfaceName(), status);
348     if (result != HDF_SUCCESS) {
349         LOGE("HdiP2pSetPersistentReconnect: P2pSetPersistentReconnect failed result:%{public}d", result);
350         pthread_mutex_unlock(GetWpaObjMutex());
351         return WIFI_HAL_OPT_FAILED;
352     }
353     pthread_mutex_unlock(GetWpaObjMutex());
354     LOGI("HdiP2pSetPersistentReconnect success.");
355     return WIFI_HAL_OPT_OK;
356 }
357 
HdiP2pSetWpsSecondaryDeviceType(const char * type)358 WifiErrorNo HdiP2pSetWpsSecondaryDeviceType(const char *type)
359 {
360     LOGI("HdiP2pSetWpsSecondaryDeviceType enter");
361     pthread_mutex_lock(GetWpaObjMutex());
362     struct IWpaInterface *wpaObj = GetWpaInterface();
363     if (wpaObj == NULL) {
364         LOGE("HdiP2pSetWpsSecondaryDeviceType: wpaObj is NULL");
365         pthread_mutex_unlock(GetWpaObjMutex());
366         return WIFI_HAL_OPT_FAILED;
367     }
368 
369     int32_t result = wpaObj->P2pSetWpsSecondaryDeviceType(wpaObj, GetHdiP2pIfaceName(), type);
370     if (result != HDF_SUCCESS) {
371         LOGE("HdiP2pSetWpsSecondaryDeviceType: P2pSetWpsSecondaryDeviceType failed result:%{public}d", result);
372         pthread_mutex_unlock(GetWpaObjMutex());
373         return WIFI_HAL_OPT_FAILED;
374     }
375     pthread_mutex_unlock(GetWpaObjMutex());
376     LOGI("HdiP2pSetWpsSecondaryDeviceType success.");
377     return WIFI_HAL_OPT_OK;
378 }
379 
HdiP2pSetupWpsPbc(const char * groupIfc,const char * address)380 WifiErrorNo HdiP2pSetupWpsPbc(const char *groupIfc, const char *address)
381 {
382     char anonymizeAddr[MAC_STRING_SIZE + 1] = {0};
383     if (ConvertMacArr2String((const unsigned char *)address, MAC_UINT_SIZE,
384                              anonymizeAddr, sizeof(anonymizeAddr)) != 0) {
385         LOGE("HdiP2pSetupWpsPbc: failed to convert address!");
386     }
387     LOGI("HdiP2pSetupWpsPbc enter groupIfc=%{public}s anonymizeAddr=%{public}s", groupIfc, anonymizeAddr);
388     pthread_mutex_lock(GetWpaObjMutex());
389     struct IWpaInterface *wpaObj = GetWpaInterface();
390     if (wpaObj == NULL) {
391         LOGE("HdiP2pSetupWpsPbc: wpaObj is NULL");
392         pthread_mutex_unlock(GetWpaObjMutex());
393         return WIFI_HAL_OPT_FAILED;
394     }
395 
396     int32_t result = wpaObj->P2pSetupWpsPbc(wpaObj, groupIfc, address);
397     if (result != HDF_SUCCESS) {
398         LOGE("HdiP2pSetupWpsPbc: P2pSetupWpsPbc failed result:%{public}d", result);
399         pthread_mutex_unlock(GetWpaObjMutex());
400         return WIFI_HAL_OPT_FAILED;
401     }
402     pthread_mutex_unlock(GetWpaObjMutex());
403     LOGI("HdiP2pSetupWpsPbc success.");
404     return WIFI_HAL_OPT_OK;
405 }
406 
HdiP2pSetupWpsPin(const char * groupIfc,const char * address,const char * pin,char * result)407 WifiErrorNo HdiP2pSetupWpsPin(const char *groupIfc, const char *address, const char *pin, char *result)
408 {
409     LOGI("HdiP2pSetupWpsPin enter");
410     pthread_mutex_lock(GetWpaObjMutex());
411     struct IWpaInterface *wpaObj = GetWpaInterface();
412     if (wpaObj == NULL) {
413         LOGE("HdiP2pSetupWpsPin: wpaObj is NULL");
414         pthread_mutex_unlock(GetWpaObjMutex());
415         return WIFI_HAL_OPT_FAILED;
416     }
417 
418     int32_t res = wpaObj->P2pSetupWpsPin(wpaObj, groupIfc, address, pin, result, REPLY_BUF_LENGTH);
419     if (res != HDF_SUCCESS) {
420         LOGE("HdiP2pSetupWpsPin: P2pSetupWpsPin failed res:%{public}s", result);
421         pthread_mutex_unlock(GetWpaObjMutex());
422         return WIFI_HAL_OPT_FAILED;
423     }
424     pthread_mutex_unlock(GetWpaObjMutex());
425     LOGI("HdiP2pSetupWpsPin success.");
426     return WIFI_HAL_OPT_OK;
427 }
428 
HdiP2pSetPowerSave(const char * groupIfc,int enable)429 WifiErrorNo HdiP2pSetPowerSave(const char *groupIfc, int enable)
430 {
431     LOGI("HdiP2pSetPowerSave enter");
432     pthread_mutex_lock(GetWpaObjMutex());
433     struct IWpaInterface *wpaObj = GetWpaInterface();
434     if (wpaObj == NULL) {
435         LOGE("HdiP2pSetPowerSave: wpaObj is NULL");
436         pthread_mutex_unlock(GetWpaObjMutex());
437         return WIFI_HAL_OPT_FAILED;
438     }
439 
440     int32_t result = wpaObj->P2pSetPowerSave(wpaObj, groupIfc, enable);
441     if (result != HDF_SUCCESS) {
442         LOGE("HdiP2pSetPowerSave: P2pSetPowerSave failed result:%{public}d", result);
443         pthread_mutex_unlock(GetWpaObjMutex());
444         return WIFI_HAL_OPT_FAILED;
445     }
446     pthread_mutex_unlock(GetWpaObjMutex());
447     LOGI("HdiP2pSetPowerSave success.");
448     return WIFI_HAL_OPT_OK;
449 }
450 
HdiP2pSetDeviceName(const char * name)451 WifiErrorNo HdiP2pSetDeviceName(const char *name)
452 {
453     LOGI("HdiP2pSetDeviceName enter");
454     pthread_mutex_lock(GetWpaObjMutex());
455     struct IWpaInterface *wpaObj = GetWpaInterface();
456     if (wpaObj == NULL) {
457         LOGE("HdiP2pSetDeviceName: wpaObj is NULL");
458         pthread_mutex_unlock(GetWpaObjMutex());
459         return WIFI_HAL_OPT_FAILED;
460     }
461 
462     int32_t result = wpaObj->P2pSetDeviceName(wpaObj, GetHdiP2pIfaceName(), name);
463     if (result != HDF_SUCCESS) {
464         LOGE("HdiP2pSetDeviceName: P2pSetDeviceName failed result:%{public}d", result);
465         pthread_mutex_unlock(GetWpaObjMutex());
466         return WIFI_HAL_OPT_FAILED;
467     }
468     pthread_mutex_unlock(GetWpaObjMutex());
469     LOGI("HdiP2pSetDeviceName success.");
470     return WIFI_HAL_OPT_OK;
471 }
472 
HdiP2pSetWfdDeviceConfig(const char * config)473 WifiErrorNo HdiP2pSetWfdDeviceConfig(const char *config)
474 {
475     LOGI("HdiP2pSetWfdDeviceConfig enter");
476     pthread_mutex_lock(GetWpaObjMutex());
477     struct IWpaInterface *wpaObj = GetWpaInterface();
478     if (wpaObj == NULL) {
479         LOGE("HdiP2pSetWfdDeviceConfig: wpaObj is NULL");
480         pthread_mutex_unlock(GetWpaObjMutex());
481         return WIFI_HAL_OPT_FAILED;
482     }
483 
484     int32_t result = wpaObj->P2pSetWfdDeviceConfig(wpaObj, GetHdiP2pIfaceName(), config);
485     if (result != HDF_SUCCESS) {
486         LOGE("HdiP2pSetWfdDeviceConfig: P2pSetWfdDeviceConfig failed result:%{public}d", result);
487         pthread_mutex_unlock(GetWpaObjMutex());
488         return WIFI_HAL_OPT_FAILED;
489     }
490     pthread_mutex_unlock(GetWpaObjMutex());
491     LOGI("HdiP2pSetWfdDeviceConfig success.");
492     return WIFI_HAL_OPT_OK;
493 }
494 
HdiP2pSetRandomMac(int enable)495 WifiErrorNo HdiP2pSetRandomMac(int enable)
496 {
497     LOGI("HdiP2pSetRandomMac enter");
498     pthread_mutex_lock(GetWpaObjMutex());
499     struct IWpaInterface *wpaObj = GetWpaInterface();
500     if (wpaObj == NULL) {
501         LOGE("HdiP2pSetRandomMac: wpaObj is NULL");
502         pthread_mutex_unlock(GetWpaObjMutex());
503         return WIFI_HAL_OPT_FAILED;
504     }
505 
506     int32_t result = wpaObj->P2pSetRandomMac(wpaObj, GetHdiP2pIfaceName(), enable);
507     if (result != HDF_SUCCESS) {
508         LOGE("HdiP2pSetRandomMac: P2pSetRandomMac failed result:%{public}d", result);
509         pthread_mutex_unlock(GetWpaObjMutex());
510         return WIFI_HAL_OPT_FAILED;
511     }
512     if (AddP2pRandomMacFlag() != WIFI_HAL_OPT_OK) {
513         LOGW("%{public}s: failed to write %{public}s", __func__, P2P_RANDOM_MAC_FLAG);
514     }
515     pthread_mutex_unlock(GetWpaObjMutex());
516     LOGI("HdiP2pSetRandomMac success.");
517     return WIFI_HAL_OPT_OK;
518 }
519 
HdiP2pStartFind(int timeout)520 WifiErrorNo HdiP2pStartFind(int timeout)
521 {
522     LOGI("HdiP2pStartFind enter");
523     pthread_mutex_lock(GetWpaObjMutex());
524     struct IWpaInterface *wpaObj = GetWpaInterface();
525     if (wpaObj == NULL) {
526         LOGE("HdiP2pStartFind: wpaObj is NULL");
527         pthread_mutex_unlock(GetWpaObjMutex());
528         return WIFI_HAL_OPT_FAILED;
529     }
530 
531     int32_t result = wpaObj->P2pStartFind(wpaObj, GetHdiP2pIfaceName(), timeout);
532     if (result != HDF_SUCCESS) {
533         LOGE("HdiP2pStartFind: P2pStartFind failed result:%{public}d", result);
534         pthread_mutex_unlock(GetWpaObjMutex());
535         return WIFI_HAL_OPT_FAILED;
536     }
537     pthread_mutex_unlock(GetWpaObjMutex());
538     LOGI("HdiP2pStartFind success.");
539     return WIFI_HAL_OPT_OK;
540 }
541 
HdiP2pSetExtListen(int enable,int period,int interval)542 WifiErrorNo HdiP2pSetExtListen(int enable, int period, int interval)
543 {
544     LOGI("HdiP2pSetExtListen enter");
545     pthread_mutex_lock(GetWpaObjMutex());
546     struct IWpaInterface *wpaObj = GetWpaInterface();
547     if (wpaObj == NULL) {
548         LOGE("HdiP2pSetExtListen: wpaObj is NULL");
549         pthread_mutex_unlock(GetWpaObjMutex());
550         return WIFI_HAL_OPT_FAILED;
551     }
552 
553     int32_t result = wpaObj->P2pSetExtListen(wpaObj, GetHdiP2pIfaceName(), enable, period, interval);
554     if (result != HDF_SUCCESS) {
555         LOGE("HdiP2pSetExtListen: P2pSetExtListen failed result:%{public}d", result);
556         pthread_mutex_unlock(GetWpaObjMutex());
557         return WIFI_HAL_OPT_FAILED;
558     }
559     pthread_mutex_unlock(GetWpaObjMutex());
560     LOGI("HdiP2pSetExtListen success.");
561     return WIFI_HAL_OPT_OK;
562 }
563 
HdiP2pSetListenChannel(int channel,int regClass)564 WifiErrorNo HdiP2pSetListenChannel(int channel, int regClass)
565 {
566     LOGI("HdiP2pSetListenChannel enter");
567     pthread_mutex_lock(GetWpaObjMutex());
568     struct IWpaInterface *wpaObj = GetWpaInterface();
569     if (wpaObj == NULL) {
570         LOGE("HdiP2pSetListenChannel: wpaObj is NULL");
571         pthread_mutex_unlock(GetWpaObjMutex());
572         return WIFI_HAL_OPT_FAILED;
573     }
574 
575     int32_t result = wpaObj->P2pSetListenChannel(wpaObj, GetHdiP2pIfaceName(), channel, regClass);
576     if (result != HDF_SUCCESS) {
577         LOGE("HdiP2pSetListenChannel: P2pSetListenChannel failed result:%{public}d", result);
578         pthread_mutex_unlock(GetWpaObjMutex());
579         return WIFI_HAL_OPT_FAILED;
580     }
581     pthread_mutex_unlock(GetWpaObjMutex());
582     LOGI("HdiP2pSetListenChannel success.");
583     return WIFI_HAL_OPT_OK;
584 }
585 
HdiP2pProvisionDiscovery(const char * peerBssid,int mode)586 WifiErrorNo HdiP2pProvisionDiscovery(const char *peerBssid, int mode)
587 {
588     LOGI("HdiP2pProvisionDiscovery enter");
589     pthread_mutex_lock(GetWpaObjMutex());
590     struct IWpaInterface *wpaObj = GetWpaInterface();
591     if (wpaObj == NULL) {
592         LOGE("HdiP2pProvisionDiscovery: wpaObj is NULL");
593         pthread_mutex_unlock(GetWpaObjMutex());
594         return WIFI_HAL_OPT_FAILED;
595     }
596 
597     int32_t result = wpaObj->P2pProvisionDiscovery(wpaObj, GetHdiP2pIfaceName(), peerBssid, mode);
598     if (result != HDF_SUCCESS) {
599         LOGE("HdiP2pProvisionDiscovery: P2pProvisionDiscovery failed result:%{public}d", result);
600         pthread_mutex_unlock(GetWpaObjMutex());
601         return WIFI_HAL_OPT_FAILED;
602     }
603     pthread_mutex_unlock(GetWpaObjMutex());
604     LOGI("HdiP2pProvisionDiscovery success.");
605     return WIFI_HAL_OPT_OK;
606 }
607 
HdiP2pAddGroup(int isPersistent,int networkId,int freq)608 WifiErrorNo HdiP2pAddGroup(int isPersistent, int networkId, int freq)
609 {
610     LOGI("HdiP2pAddGroup enter isPersistent=%{public}d", isPersistent);
611     pthread_mutex_lock(GetWpaObjMutex());
612     struct IWpaInterface *wpaObj = GetWpaInterface();
613     if (wpaObj == NULL) {
614         LOGE("HdiP2pAddGroup: wpaObj is NULL");
615         pthread_mutex_unlock(GetWpaObjMutex());
616         return WIFI_HAL_OPT_FAILED;
617     }
618 
619     int32_t result = wpaObj->P2pAddGroup(wpaObj, GetHdiP2pIfaceName(), isPersistent, networkId, freq);
620     if (result != HDF_SUCCESS) {
621         LOGE("HdiP2pAddGroup: P2pAddGroup failed result:%{public}d", result);
622         pthread_mutex_unlock(GetWpaObjMutex());
623         return WIFI_HAL_OPT_FAILED;
624     }
625     pthread_mutex_unlock(GetWpaObjMutex());
626     LOGI("HdiP2pAddGroup success.");
627     return WIFI_HAL_OPT_OK;
628 }
629 
HdiP2pAddService(struct HdiP2pServiceInfo * info)630 WifiErrorNo HdiP2pAddService(struct HdiP2pServiceInfo *info)
631 {
632     LOGI("HdiP2pAddService enter");
633     pthread_mutex_lock(GetWpaObjMutex());
634     struct IWpaInterface *wpaObj = GetWpaInterface();
635     if (wpaObj == NULL) {
636         LOGE("HdiP2pAddService: wpaObj is NULL");
637         pthread_mutex_unlock(GetWpaObjMutex());
638         return WIFI_HAL_OPT_FAILED;
639     }
640 
641     int32_t result = wpaObj->P2pAddService(wpaObj, GetHdiP2pIfaceName(), info);
642     if (result != HDF_SUCCESS) {
643         LOGE("HdiP2pAddService: P2pAddService failed result:%{public}d", result);
644         pthread_mutex_unlock(GetWpaObjMutex());
645         return WIFI_HAL_OPT_FAILED;
646     }
647     pthread_mutex_unlock(GetWpaObjMutex());
648     LOGI("HdiP2pAddService success.");
649     return WIFI_HAL_OPT_OK;
650 }
651 
HdiP2pRemoveService(struct HdiP2pServiceInfo * info)652 WifiErrorNo HdiP2pRemoveService(struct HdiP2pServiceInfo *info)
653 {
654     LOGI("HdiP2pRemoveService enter");
655     pthread_mutex_lock(GetWpaObjMutex());
656     struct IWpaInterface *wpaObj = GetWpaInterface();
657     if (wpaObj == NULL) {
658         LOGE("HdiP2pRemoveService: wpaObj is NULL");
659         pthread_mutex_unlock(GetWpaObjMutex());
660         return WIFI_HAL_OPT_FAILED;
661     }
662 
663     int32_t result = wpaObj->P2pRemoveService(wpaObj, GetHdiP2pIfaceName(), info);
664     if (result != HDF_SUCCESS) {
665         LOGE("HdiP2pRemoveService: P2pRemoveService failed result:%{public}d", result);
666         pthread_mutex_unlock(GetWpaObjMutex());
667         return WIFI_HAL_OPT_FAILED;
668     }
669     pthread_mutex_unlock(GetWpaObjMutex());
670     LOGI("HdiP2pRemoveService success.");
671     return WIFI_HAL_OPT_OK;
672 }
673 
HdiP2pStopFind()674 WifiErrorNo HdiP2pStopFind()
675 {
676     LOGI("HdiP2pStopFind enter");
677     pthread_mutex_lock(GetWpaObjMutex());
678     struct IWpaInterface *wpaObj = GetWpaInterface();
679     if (wpaObj == NULL) {
680         LOGE("HdiP2pStopFind: wpaObj is NULL");
681         pthread_mutex_unlock(GetWpaObjMutex());
682         return WIFI_HAL_OPT_FAILED;
683     }
684 
685     int32_t result = wpaObj->P2pStopFind(wpaObj, GetHdiP2pIfaceName());
686     if (result != HDF_SUCCESS) {
687         LOGE("HdiP2pStopFind: P2pStopFind failed result:%{public}d", result);
688         pthread_mutex_unlock(GetWpaObjMutex());
689         return WIFI_HAL_OPT_FAILED;
690     }
691     pthread_mutex_unlock(GetWpaObjMutex());
692     LOGI("HdiP2pStopFind success.");
693     return WIFI_HAL_OPT_OK;
694 }
695 
HdiP2pFlush()696 WifiErrorNo HdiP2pFlush()
697 {
698     LOGI("HdiP2pFlush enter");
699     pthread_mutex_lock(GetWpaObjMutex());
700     struct IWpaInterface *wpaObj = GetWpaInterface();
701     if (wpaObj == NULL) {
702         LOGE("HdiP2pFlush: wpaObj is NULL");
703         pthread_mutex_unlock(GetWpaObjMutex());
704         return WIFI_HAL_OPT_FAILED;
705     }
706 
707     int32_t result = wpaObj->P2pFlush(wpaObj, GetHdiP2pIfaceName());
708     if (result != HDF_SUCCESS) {
709         LOGE("HdiP2pFlush: P2pFlush failed result:%{public}d", result);
710         pthread_mutex_unlock(GetWpaObjMutex());
711         return WIFI_HAL_OPT_FAILED;
712     }
713     pthread_mutex_unlock(GetWpaObjMutex());
714     LOGI("HdiP2pFlush success.");
715     return WIFI_HAL_OPT_OK;
716 }
717 
HdiP2pFlushService()718 WifiErrorNo HdiP2pFlushService()
719 {
720     LOGI("HdiP2pFlushService enter");
721     pthread_mutex_lock(GetWpaObjMutex());
722     struct IWpaInterface *wpaObj = GetWpaInterface();
723     if (wpaObj == NULL) {
724         LOGE("HdiP2pFlushService: wpaObj is NULL");
725         pthread_mutex_unlock(GetWpaObjMutex());
726         return WIFI_HAL_OPT_FAILED;
727     }
728 
729     int32_t result = wpaObj->P2pFlushService(wpaObj, GetHdiP2pIfaceName());
730     if (result != HDF_SUCCESS) {
731         LOGE("HdiP2pFlushService: P2pFlushService failed result:%{public}d", result);
732         pthread_mutex_unlock(GetWpaObjMutex());
733         return WIFI_HAL_OPT_FAILED;
734     }
735     pthread_mutex_unlock(GetWpaObjMutex());
736     LOGI("HdiP2pFlushService success.");
737     return WIFI_HAL_OPT_OK;
738 }
739 
HdiP2pRemoveNetwork(int networkId)740 WifiErrorNo HdiP2pRemoveNetwork(int networkId)
741 {
742     LOGI("HdiP2pRemoveNetwork enter");
743     pthread_mutex_lock(GetWpaObjMutex());
744     struct IWpaInterface *wpaObj = GetWpaInterface();
745     if (wpaObj == NULL) {
746         LOGE("HdiP2pRemoveNetwork: wpaObj is NULL");
747         pthread_mutex_unlock(GetWpaObjMutex());
748         return WIFI_HAL_OPT_FAILED;
749     }
750 
751     int32_t result = wpaObj->P2pRemoveNetwork(wpaObj, GetHdiP2pIfaceName(), networkId);
752     if (result != HDF_SUCCESS) {
753         LOGE("HdiP2pRemoveNetwork: P2pRemoveNetwork failed result:%{public}d", result);
754         pthread_mutex_unlock(GetWpaObjMutex());
755         return WIFI_HAL_OPT_FAILED;
756     }
757     pthread_mutex_unlock(GetWpaObjMutex());
758     LOGI("HdiP2pRemoveNetwork success.");
759     return WIFI_HAL_OPT_OK;
760 }
761 
HdiP2pSetSingleConfig(int networkId,const char * key,const char * value)762 WifiErrorNo HdiP2pSetSingleConfig(int networkId, const char *key, const char *value)
763 {
764     LOGI("HdiP2pSetSingleConfig enter");
765     struct IWpaInterface *wpaObj = GetWpaInterface();
766     if (wpaObj == NULL) {
767         LOGE("HdiP2pSetSingleConfig: wpaObj is NULL");
768         return WIFI_HAL_OPT_FAILED;
769     }
770     char cfgValue[WIFI_P2P_GROUP_CONFIG_VALUE_LENGTH];
771     if (sprintf_s(cfgValue, sizeof(cfgValue), "%s", value) < 0) {
772         return WIFI_HAL_OPT_FAILED;
773     }
774     int32_t result = wpaObj->P2pSetGroupConfig(wpaObj, GetHdiP2pIfaceName(), networkId, key, cfgValue);
775     if (result != HDF_SUCCESS) {
776         LOGE("HdiP2pSetSingleConfig failed result:%{public}d", result);
777         return WIFI_HAL_OPT_FAILED;
778     }
779     LOGI("HdiP2pSetSingleConfig success.");
780     return WIFI_HAL_OPT_OK;
781 }
782 
HdiP2pSetGroupConfig(int networkId,P2pGroupConfig * pConfig,int size)783 WifiErrorNo HdiP2pSetGroupConfig(int networkId, P2pGroupConfig *pConfig, int size)
784 {
785     LOGI("HdiP2pSetGroupConfig enter size=%{public}d", size);
786     pthread_mutex_lock(GetWpaObjMutex());
787     struct IWpaInterface *wpaObj = GetWpaInterface();
788     if (wpaObj == NULL) {
789         LOGE("HdiP2pSetGroupConfig: wpaObj is NULL");
790         pthread_mutex_unlock(GetWpaObjMutex());
791         return WIFI_HAL_OPT_FAILED;
792     }
793 
794     for (int i = 0; i < size; ++i) {
795         int32_t result = wpaObj->P2pSetGroupConfig(wpaObj, GetHdiP2pIfaceName(), networkId,
796             g_hdiP2pWpaNetworkFields[pConfig[i].cfgParam].fieldName, pConfig[i].cfgValue);
797         if (result != HDF_SUCCESS) {
798             LOGE("HdiP2pSetGroupConfig: %{public}s failed result:%{public}d",
799                 g_hdiP2pWpaNetworkFields[pConfig[i].cfgParam].fieldName, result);
800             pthread_mutex_unlock(GetWpaObjMutex());
801             return WIFI_HAL_OPT_FAILED;
802         }
803     }
804     pthread_mutex_unlock(GetWpaObjMutex());
805     LOGI("HdiP2pSetGroupConfig success.");
806     return WIFI_HAL_OPT_OK;
807 }
808 
HdiP2pInvite(const char * peerBssid,const char * goBssid,const char * ifname)809 WifiErrorNo HdiP2pInvite(const char *peerBssid, const char *goBssid, const char *ifname)
810 {
811     LOGI("HdiP2pInvite enter");
812     pthread_mutex_lock(GetWpaObjMutex());
813     struct IWpaInterface *wpaObj = GetWpaInterface();
814     if (wpaObj == NULL) {
815         LOGE("HdiP2pInvite: wpaObj is NULL");
816         pthread_mutex_unlock(GetWpaObjMutex());
817         return WIFI_HAL_OPT_FAILED;
818     }
819 
820     int32_t result = wpaObj->P2pInvite(wpaObj, ifname, peerBssid, goBssid);
821     if (result != HDF_SUCCESS) {
822         LOGE("HdiP2pInvite: P2pInvite failed result:%{public}d", result);
823         pthread_mutex_unlock(GetWpaObjMutex());
824         return WIFI_HAL_OPT_FAILED;
825     }
826     pthread_mutex_unlock(GetWpaObjMutex());
827     LOGI("HdiP2pInvite success.");
828     return WIFI_HAL_OPT_OK;
829 }
830 
HdiP2pReinvoke(int networkId,const char * bssid)831 WifiErrorNo HdiP2pReinvoke(int networkId, const char *bssid)
832 {
833     LOGI("HdiP2pReinvoke enter");
834     pthread_mutex_lock(GetWpaObjMutex());
835     struct IWpaInterface *wpaObj = GetWpaInterface();
836     if (wpaObj == NULL) {
837         LOGE("HdiP2pReinvoke: wpaObj is NULL");
838         pthread_mutex_unlock(GetWpaObjMutex());
839         return WIFI_HAL_OPT_FAILED;
840     }
841 
842     int32_t result = wpaObj->P2pReinvoke(wpaObj, GetHdiP2pIfaceName(), networkId, bssid);
843     if (result != HDF_SUCCESS) {
844         LOGE("HdiP2pReinvoke: P2pReinvoke failed result:%{public}d", result);
845         pthread_mutex_unlock(GetWpaObjMutex());
846         return WIFI_HAL_OPT_FAILED;
847     }
848     pthread_mutex_unlock(GetWpaObjMutex());
849     LOGI("HdiP2pReinvoke success.");
850     return WIFI_HAL_OPT_OK;
851 }
852 
HdiP2pGetDeviceAddress(char * deviceAddress,int size)853 WifiErrorNo HdiP2pGetDeviceAddress(char *deviceAddress, int size)
854 {
855     LOGI("HdiP2pGetDeviceAddress enter");
856     pthread_mutex_lock(GetWpaObjMutex());
857     struct IWpaInterface *wpaObj = GetWpaInterface();
858     if (wpaObj == NULL) {
859         LOGE("HdiP2pGetDeviceAddress: wpaObj is NULL");
860         pthread_mutex_unlock(GetWpaObjMutex());
861         return WIFI_HAL_OPT_FAILED;
862     }
863 
864     int32_t result = wpaObj->P2pGetDeviceAddress(wpaObj, GetHdiP2pIfaceName(), deviceAddress, size);
865     if (result != HDF_SUCCESS) {
866         LOGE("HdiP2pGetDeviceAddress: P2pGetDeviceAddress failed result:%{public}d", result);
867         pthread_mutex_unlock(GetWpaObjMutex());
868         return WIFI_HAL_OPT_FAILED;
869     }
870     pthread_mutex_unlock(GetWpaObjMutex());
871     LOGI("HdiP2pGetDeviceAddress success.");
872     return WIFI_HAL_OPT_OK;
873 }
874 
HdiP2pReqServiceDiscovery(struct HdiP2pReqService * reqService,char * replyDisc,int size)875 WifiErrorNo HdiP2pReqServiceDiscovery(struct HdiP2pReqService *reqService, char *replyDisc, int size)
876 {
877     LOGI("HdiP2pReqServiceDiscovery enter");
878     pthread_mutex_lock(GetWpaObjMutex());
879     struct IWpaInterface *wpaObj = GetWpaInterface();
880     if (wpaObj == NULL) {
881         LOGE("HdiP2pReqServiceDiscovery: wpaObj is NULL");
882         pthread_mutex_unlock(GetWpaObjMutex());
883         return WIFI_HAL_OPT_FAILED;
884     }
885 
886     int32_t result = wpaObj->P2pReqServiceDiscovery(wpaObj, GetHdiP2pIfaceName(), reqService,
887         replyDisc, size);
888     if (result != HDF_SUCCESS) {
889         LOGE("HdiP2pReqServiceDiscovery: P2pReqServiceDiscovery failed result:%{public}d", result);
890         pthread_mutex_unlock(GetWpaObjMutex());
891         return WIFI_HAL_OPT_FAILED;
892     }
893     pthread_mutex_unlock(GetWpaObjMutex());
894     LOGI("HdiP2pReqServiceDiscovery success.");
895     return WIFI_HAL_OPT_OK;
896 }
897 
HdiP2pCancelServiceDiscovery(const char * id)898 WifiErrorNo HdiP2pCancelServiceDiscovery(const char *id)
899 {
900     LOGI("HdiP2pCancelServiceDiscovery enter");
901     pthread_mutex_lock(GetWpaObjMutex());
902     struct IWpaInterface *wpaObj = GetWpaInterface();
903     if (wpaObj == NULL) {
904         LOGE("HdiP2pCancelServiceDiscovery: wpaObj is NULL");
905         pthread_mutex_unlock(GetWpaObjMutex());
906         return WIFI_HAL_OPT_FAILED;
907     }
908 
909     int32_t result = wpaObj->P2pCancelServiceDiscovery(wpaObj, GetHdiP2pIfaceName(), id);
910     if (result != HDF_SUCCESS) {
911         LOGE("HdiP2pCancelServiceDiscovery: P2pCancelServiceDiscovery failed result:%{public}d", result);
912         pthread_mutex_unlock(GetWpaObjMutex());
913         return WIFI_HAL_OPT_FAILED;
914     }
915     pthread_mutex_unlock(GetWpaObjMutex());
916     LOGI("HdiP2pCancelServiceDiscovery success.");
917     return WIFI_HAL_OPT_OK;
918 }
919 
HdiP2pRespServerDiscovery(struct HdiP2pServDiscReqInfo * info)920 WifiErrorNo HdiP2pRespServerDiscovery(struct HdiP2pServDiscReqInfo *info)
921 {
922     LOGI("HdiP2pRespServerDiscovery enter");
923     pthread_mutex_lock(GetWpaObjMutex());
924     struct IWpaInterface *wpaObj = GetWpaInterface();
925     if (wpaObj == NULL) {
926         LOGE("HdiP2pRespServerDiscovery: wpaObj is NULL");
927         pthread_mutex_unlock(GetWpaObjMutex());
928         return WIFI_HAL_OPT_FAILED;
929     }
930 
931     int32_t result = wpaObj->P2pRespServerDiscovery(wpaObj, GetHdiP2pIfaceName(), info);
932     if (result != HDF_SUCCESS) {
933         LOGE("HdiP2pRespServerDiscovery: P2pRespServerDiscovery failed result:%{public}d", result);
934         pthread_mutex_unlock(GetWpaObjMutex());
935         return WIFI_HAL_OPT_FAILED;
936     }
937     pthread_mutex_unlock(GetWpaObjMutex());
938     LOGI("HdiP2pRespServerDiscovery success.");
939     return WIFI_HAL_OPT_OK;
940 }
941 #define HDI_POS_TEN 10
hex2num(char c)942 static int hex2num(char c)
943 {
944     if (c >= '0' && c <= '9') {
945         return c - '0';
946     }
947     if (c >= 'a' && c <= 'f') {
948         return c - 'a' + HDI_POS_TEN;
949     }
950     if (c >= 'A' && c <= 'F') {
951         return c - 'A' + HDI_POS_TEN;
952     }
953     return -1;
954 }
955 
hex2byte(const char * hex)956 static int hex2byte(const char *hex)
957 {
958     int a = hex2num(*hex++);
959     if (a < 0) {
960         return -1;
961     }
962     int b = hex2num(*hex++);
963     if (b < 0) {
964         return -1;
965     }
966     return (int)(((unsigned int)a << HDI_POS_FOURTH) | (unsigned int)b);
967 }
968 
hwaddr_parse(char * txt,uint8_t * addr)969 static char* hwaddr_parse(char *txt, uint8_t *addr)
970 {
971     size_t i;
972 
973     for (i = 0; i < ETH_ALEN; i++) {
974         int a;
975 
976         a = hex2byte(txt);
977         if (a < 0)
978             return NULL;
979         txt += HDI_MAC_SUB_LEN;
980         addr[i] = a;
981         if (i < ETH_ALEN - 1 && (*txt++ != ':'))
982             return NULL;
983     }
984     return txt;
985 }
986 
hwaddr_aton(char * txt,uint8_t * addr)987 static int hwaddr_aton(char *txt, uint8_t *addr)
988 {
989     return hwaddr_parse(txt, addr) ? 0 : -1;
990 }
991 
HdiP2pConnect(P2pConnectInfo * info,char * replyPin,int size)992 WifiErrorNo HdiP2pConnect(P2pConnectInfo *info, char *replyPin, int size)
993 {
994     LOGI("HdiP2pConnect enter");
995     pthread_mutex_lock(GetWpaObjMutex());
996     struct IWpaInterface *wpaObj = GetWpaInterface();
997     if (wpaObj == NULL) {
998         LOGE("HdiP2pConnect: wpaObj is NULL");
999         pthread_mutex_unlock(GetWpaObjMutex());
1000         return WIFI_HAL_OPT_FAILED;
1001     }
1002     struct HdiP2pConnectInfo wpsParam = {0};
1003     wpsParam.persistent = info->persistent;
1004     wpsParam.mode = info->mode;
1005     wpsParam.goIntent = info->goIntent;
1006     wpsParam.provdisc = info->provdisc;
1007     uint8_t addr[ETH_ALEN];
1008     hwaddr_aton(info->peerDevAddr, addr);
1009     wpsParam.peerDevAddr = addr;
1010     wpsParam.peerDevAddrLen = ETH_ALEN;
1011     wpsParam.pin = (uint8_t *)info->pin;
1012     wpsParam.pinLen = HDI_PIN_LEN;
1013 
1014     int32_t result = wpaObj->P2pConnect(wpaObj, GetHdiP2pIfaceName(), &wpsParam, replyPin, size - 1);
1015     if (result != HDF_SUCCESS) {
1016         LOGE("HdiP2pConnect: P2pConnect failed result:%{public}d", result);
1017         pthread_mutex_unlock(GetWpaObjMutex());
1018         return WIFI_HAL_OPT_FAILED;
1019     }
1020     pthread_mutex_unlock(GetWpaObjMutex());
1021     LOGI("HdiP2pConnect success.");
1022     return WIFI_HAL_OPT_OK;
1023 }
1024 
HdiP2pHid2dConnect(struct Hid2dConnectInfo * info)1025 WifiErrorNo HdiP2pHid2dConnect(struct Hid2dConnectInfo *info)
1026 {
1027     LOGI("HdiP2pHid2dConnect enter");
1028     pthread_mutex_lock(GetWpaObjMutex());
1029     struct IWpaInterface *wpaObj = GetWpaInterface();
1030     if (wpaObj == NULL) {
1031         LOGE("HdiP2pHid2dConnect: wpaObj is NULL");
1032         pthread_mutex_unlock(GetWpaObjMutex());
1033         return WIFI_HAL_OPT_FAILED;
1034     }
1035     struct HdiHid2dConnectInfo wpsParam = {0};
1036     uint8_t addr[ETH_ALEN];
1037     hwaddr_aton(info->bssid, addr);
1038     wpsParam.ssid = (uint8_t *)info->ssid;
1039     wpsParam.ssidLen = strlen(info->ssid) + 1;
1040     wpsParam.bssid = addr;
1041     wpsParam.bssidLen = ETH_ALEN;
1042     wpsParam.passphrase = (uint8_t *)info->passphrase;
1043     wpsParam.passphraseLen = strlen(info->passphrase) + 1;
1044     wpsParam.frequency = (int)(((unsigned int)(info->frequency) << HDI_POS_OT) | (unsigned int)(info->isLegacyGo));
1045     int32_t result = wpaObj->P2pHid2dConnect(wpaObj, GetHdiP2pIfaceName(), &wpsParam);
1046     if (result != HDF_SUCCESS) {
1047         LOGE("HdiP2pHid2dConnect: P2pHid2dConnect failed result:%{public}d", result);
1048         pthread_mutex_unlock(GetWpaObjMutex());
1049         return WIFI_HAL_OPT_FAILED;
1050     }
1051     pthread_mutex_unlock(GetWpaObjMutex());
1052     LOGI("HdiP2pHid2dConnect success.");
1053     return WIFI_HAL_OPT_OK;
1054 }
1055 
HdiP2pSetServDiscExternal(int mode)1056 WifiErrorNo HdiP2pSetServDiscExternal(int mode)
1057 {
1058     LOGI("HdiP2pSetServDiscExternal enter");
1059     pthread_mutex_lock(GetWpaObjMutex());
1060     struct IWpaInterface *wpaObj = GetWpaInterface();
1061     if (wpaObj == NULL) {
1062         LOGE("HdiP2pSetServDiscExternal: wpaObj is NULL");
1063         pthread_mutex_unlock(GetWpaObjMutex());
1064         return WIFI_HAL_OPT_FAILED;
1065     }
1066 
1067     int32_t result = wpaObj->P2pSetServDiscExternal(wpaObj, GetHdiP2pIfaceName(), mode);
1068     if (result != HDF_SUCCESS) {
1069         LOGE("HdiP2pSetServDiscExternal: P2pSetServDiscExternal failed result:%{public}d", result);
1070         pthread_mutex_unlock(GetWpaObjMutex());
1071         return WIFI_HAL_OPT_FAILED;
1072     }
1073     pthread_mutex_unlock(GetWpaObjMutex());
1074     LOGI("HdiP2pSetServDiscExternal success.");
1075     return WIFI_HAL_OPT_OK;
1076 }
1077 
HdiP2pRemoveGroup(const char * groupName)1078 WifiErrorNo HdiP2pRemoveGroup(const char *groupName)
1079 {
1080     LOGI("HdiP2pRemoveGroup enter groupName=%{public}s", groupName);
1081     pthread_mutex_lock(GetWpaObjMutex());
1082     struct IWpaInterface *wpaObj = GetWpaInterface();
1083     if (wpaObj == NULL) {
1084         LOGE("HdiP2pRemoveGroup: wpaObj is NULL");
1085         pthread_mutex_unlock(GetWpaObjMutex());
1086         return WIFI_HAL_OPT_FAILED;
1087     }
1088 
1089     int32_t result = wpaObj->P2pRemoveGroup(wpaObj, GetHdiP2pIfaceName(), groupName);
1090     if (result != HDF_SUCCESS) {
1091         LOGE("HdiP2pRemoveGroup: P2pRemoveGroup failed result:%{public}d", result);
1092         pthread_mutex_unlock(GetWpaObjMutex());
1093         return WIFI_HAL_OPT_FAILED;
1094     }
1095     pthread_mutex_unlock(GetWpaObjMutex());
1096     LOGI("HdiP2pRemoveGroup success.");
1097     return WIFI_HAL_OPT_OK;
1098 }
1099 
HdiP2pCancelConnect()1100 WifiErrorNo HdiP2pCancelConnect()
1101 {
1102     LOGI("HdiP2pCancelConnect enter");
1103     pthread_mutex_lock(GetWpaObjMutex());
1104     struct IWpaInterface *wpaObj = GetWpaInterface();
1105     if (wpaObj == NULL) {
1106         LOGE("HdiP2pCancelConnect: wpaObj is NULL");
1107         pthread_mutex_unlock(GetWpaObjMutex());
1108         return WIFI_HAL_OPT_FAILED;
1109     }
1110 
1111     int32_t result = wpaObj->P2pCancelConnect(wpaObj, GetHdiP2pIfaceName());
1112     if (result != HDF_SUCCESS) {
1113         LOGE("HdiP2pCancelConnect: P2pCancelConnect failed result:%{public}d", result);
1114         pthread_mutex_unlock(GetWpaObjMutex());
1115         return WIFI_HAL_OPT_FAILED;
1116     }
1117     pthread_mutex_unlock(GetWpaObjMutex());
1118     LOGI("HdiP2pCancelConnect success.");
1119     return WIFI_HAL_OPT_OK;
1120 }
1121 
HdiP2pGetGroupConfig(int networkId,char * param,char * value)1122 WifiErrorNo HdiP2pGetGroupConfig(int networkId, char *param, char *value)
1123 {
1124     LOGI("HdiP2pGetGroupConfig enter");
1125     pthread_mutex_lock(GetWpaObjMutex());
1126     struct IWpaInterface *wpaObj = GetWpaInterface();
1127     if (wpaObj == NULL) {
1128         LOGE("HdiP2pGetGroupConfig: wpaObj is NULL");
1129         pthread_mutex_unlock(GetWpaObjMutex());
1130         return WIFI_HAL_OPT_FAILED;
1131     }
1132 
1133     int32_t result = wpaObj->P2pGetGroupConfig(wpaObj, GetHdiP2pIfaceName(), networkId,
1134         param, value, WIFI_P2P_GROUP_CONFIG_VALUE_LENGTH);
1135     if (result != HDF_SUCCESS) {
1136         LOGE("HdiP2pGetGroupConfig: P2pGetGroupConfig failed result:%{public}d", result);
1137         pthread_mutex_unlock(GetWpaObjMutex());
1138         return WIFI_HAL_OPT_FAILED;
1139     }
1140     pthread_mutex_unlock(GetWpaObjMutex());
1141     LOGI("HdiP2pGetGroupConfig success.");
1142     return WIFI_HAL_OPT_OK;
1143 }
1144 
HdiP2pAddNetwork(int * networkId)1145 WifiErrorNo HdiP2pAddNetwork(int *networkId)
1146 {
1147     LOGI("HdiP2pAddNetwork enter");
1148     pthread_mutex_lock(GetWpaObjMutex());
1149     struct IWpaInterface *wpaObj = GetWpaInterface();
1150     if (wpaObj == NULL) {
1151         LOGE("HdiP2pAddNetwork: wpaObj is NULL");
1152         pthread_mutex_unlock(GetWpaObjMutex());
1153         return WIFI_HAL_OPT_FAILED;
1154     }
1155 
1156     int32_t result = wpaObj->P2pAddNetwork(wpaObj, GetHdiP2pIfaceName(), networkId);
1157     if (result != HDF_SUCCESS) {
1158         LOGE("HdiP2pAddNetwork: P2pAddNetwork failed result:%{public}d", result);
1159         pthread_mutex_unlock(GetWpaObjMutex());
1160         return WIFI_HAL_OPT_FAILED;
1161     }
1162     pthread_mutex_unlock(GetWpaObjMutex());
1163     LOGI("HdiP2pAddNetwork success networkId=%{public}d.", *networkId);
1164     return WIFI_HAL_OPT_OK;
1165 }
1166 
HdiP2pGetPeer(const char * bssid,struct HdiP2pDeviceInfo * info)1167 WifiErrorNo HdiP2pGetPeer(const char *bssid, struct HdiP2pDeviceInfo *info)
1168 {
1169     LOGI("HdiP2pGetPeer enter");
1170     pthread_mutex_lock(GetWpaObjMutex());
1171     struct IWpaInterface *wpaObj = GetWpaInterface();
1172     if (wpaObj == NULL) {
1173         LOGE("HdiP2pGetPeer: wpaObj is NULL");
1174         pthread_mutex_unlock(GetWpaObjMutex());
1175         return WIFI_HAL_OPT_FAILED;
1176     }
1177 
1178     int32_t result = wpaObj->P2pGetPeer(wpaObj, GetHdiP2pIfaceName(), bssid, info);
1179     if (result != HDF_SUCCESS) {
1180         LOGE("HdiP2pGetPeer: P2pGetPeer failed result:%{public}d", result);
1181         pthread_mutex_unlock(GetWpaObjMutex());
1182         return WIFI_HAL_OPT_FAILED;
1183     }
1184     pthread_mutex_unlock(GetWpaObjMutex());
1185     LOGI("HdiP2pGetPeer success.");
1186     return WIFI_HAL_OPT_OK;
1187 }
1188 
HdiP2pGetGroupCapability(const char * bssid,int cap)1189 WifiErrorNo HdiP2pGetGroupCapability(const char *bssid, int cap)
1190 {
1191     LOGI("HdiP2pGetGroupCapability enter");
1192     pthread_mutex_lock(GetWpaObjMutex());
1193     struct IWpaInterface *wpaObj = GetWpaInterface();
1194     if (wpaObj == NULL) {
1195         LOGE("HdiP2pGetGroupCapability: wpaObj is NULL");
1196         pthread_mutex_unlock(GetWpaObjMutex());
1197         return WIFI_HAL_OPT_FAILED;
1198     }
1199 
1200     int32_t result = wpaObj->P2pGetGroupCapability(wpaObj, GetHdiP2pIfaceName(), bssid, &cap);
1201     if (result != HDF_SUCCESS) {
1202         LOGE("HdiP2pGetGroupCapability: P2pGetGroupCapability failed result:%{public}d", result);
1203         pthread_mutex_unlock(GetWpaObjMutex());
1204         return WIFI_HAL_OPT_FAILED;
1205     }
1206     pthread_mutex_unlock(GetWpaObjMutex());
1207     LOGI("HdiP2pGetGroupCapability success.");
1208     return WIFI_HAL_OPT_OK;
1209 }
1210 
HdiP2pListNetworks(struct HdiP2pNetworkList * infoList)1211 WifiErrorNo HdiP2pListNetworks(struct HdiP2pNetworkList *infoList)
1212 {
1213     LOGI("HdiP2pListNetworks enter");
1214     pthread_mutex_lock(GetWpaObjMutex());
1215     struct IWpaInterface *wpaObj = GetWpaInterface();
1216     if (wpaObj == NULL) {
1217         LOGE("HdiP2pListNetworks: wpaObj is NULL");
1218         pthread_mutex_unlock(GetWpaObjMutex());
1219         return WIFI_HAL_OPT_FAILED;
1220     }
1221 
1222     int32_t result = wpaObj->P2pListNetworks(wpaObj, GetHdiP2pIfaceName(), infoList);
1223     if (result != HDF_SUCCESS) {
1224         LOGE("HdiP2pListNetworks: P2pListNetworks failed result:%{public}d", result);
1225         pthread_mutex_unlock(GetWpaObjMutex());
1226         return WIFI_HAL_OPT_FAILED;
1227     }
1228     pthread_mutex_unlock(GetWpaObjMutex());
1229     LOGI("HdiP2pListNetworks success.");
1230     return WIFI_HAL_OPT_OK;
1231 }
1232 
HdiP2pSaveConfig()1233 WifiErrorNo HdiP2pSaveConfig()
1234 {
1235     LOGI("HdiP2pSaveConfig enter");
1236     pthread_mutex_lock(GetWpaObjMutex());
1237     struct IWpaInterface *wpaObj = GetWpaInterface();
1238     if (wpaObj == NULL) {
1239         LOGE("HdiP2pSaveConfig: wpaObj is NULL");
1240         pthread_mutex_unlock(GetWpaObjMutex());
1241         return WIFI_HAL_OPT_FAILED;
1242     }
1243 
1244     int32_t result = wpaObj->P2pSaveConfig(wpaObj, GetHdiP2pIfaceName());
1245     if (result != HDF_SUCCESS) {
1246         LOGE("HdiP2pSaveConfig: P2pSaveConfig failed result:%{public}d", result);
1247         pthread_mutex_unlock(GetWpaObjMutex());
1248         return WIFI_HAL_OPT_FAILED;
1249     }
1250     pthread_mutex_unlock(GetWpaObjMutex());
1251     LOGI("HdiP2pSaveConfig success.");
1252     return WIFI_HAL_OPT_OK;
1253 }
1254 
HdiDeliverP2pData(int32_t cmdType,int32_t dataType,const char * carryData)1255 WifiErrorNo HdiDeliverP2pData(int32_t cmdType, int32_t dataType, const char *carryData)
1256 {
1257     LOGI("HdiDeliverP2pData enter");
1258     pthread_mutex_lock(GetWpaObjMutex());
1259     struct IWpaInterface *wpaObj = GetWpaInterface();
1260     if (wpaObj == NULL) {
1261         LOGE("HdiDeliverP2pData: wpaObj is NULL");
1262         pthread_mutex_unlock(GetWpaObjMutex());
1263         return WIFI_HAL_OPT_FAILED;
1264     }
1265 
1266     int32_t result = wpaObj->DeliverP2pData(wpaObj, "p2p0", cmdType, dataType, carryData);
1267     if (result != HDF_SUCCESS) {
1268         LOGE("HdiDeliverP2pData: send failed result:%{public}d", result);
1269         pthread_mutex_unlock(GetWpaObjMutex());
1270         return WIFI_HAL_OPT_FAILED;
1271     }
1272     pthread_mutex_unlock(GetWpaObjMutex());
1273     LOGI("HdiDeliverP2pData success.");
1274     return WIFI_HAL_OPT_OK;
1275 }
1276 
HdiP2pRemoveGroupClient(const char * deviceMac,const char * ifName)1277 WifiErrorNo HdiP2pRemoveGroupClient(const char *deviceMac, const char *ifName)
1278 {
1279     LOGI("HdiP2pRemoveGroupClient enter");
1280     pthread_mutex_lock(GetWpaObjMutex());
1281     struct IWpaInterface *wpaObj = GetWpaInterface();
1282     if (wpaObj == NULL) {
1283         LOGE("HdiP2pRemoveGroupClient: wpaObj is NULL");
1284         pthread_mutex_unlock(GetWpaObjMutex());
1285         return WIFI_HAL_OPT_FAILED;
1286     }
1287 
1288     int32_t result = wpaObj->DeliverP2pData(wpaObj, ifName, P2P_REMOVE_GROUP_CLIENT, 0, deviceMac);
1289     if (result != HDF_SUCCESS) {
1290         LOGE("HdiP2pRemoveGroupClient: send failed result:%{public}d", result);
1291         pthread_mutex_unlock(GetWpaObjMutex());
1292         return WIFI_HAL_OPT_FAILED;
1293     }
1294     pthread_mutex_unlock(GetWpaObjMutex());
1295     LOGI("HdiP2pRemoveGroupClient success.");
1296     return WIFI_HAL_OPT_OK;
1297 }
1298 
HdiP2pReject(const char * bssid)1299 WifiErrorNo HdiP2pReject(const char *bssid)
1300 {
1301     LOGI("HdiP2pReject enter");
1302     pthread_mutex_lock(GetWpaObjMutex());
1303     struct IWpaInterface *wpaObj = GetWpaInterface();
1304     if (wpaObj == NULL) {
1305         LOGE("HdiP2pReject: wpaObj is NULL");
1306         pthread_mutex_unlock(GetWpaObjMutex());
1307         return WIFI_HAL_OPT_FAILED;
1308     }
1309 
1310     int32_t result = wpaObj->DeliverP2pData(wpaObj, GetHdiP2pIfaceName(), P2P_REJECT, 0, bssid);
1311     if (result != HDF_SUCCESS) {
1312         LOGE("HdiP2pReject: send failed result:%{public}d", result);
1313         pthread_mutex_unlock(GetWpaObjMutex());
1314         return WIFI_HAL_OPT_FAILED;
1315     }
1316     pthread_mutex_unlock(GetWpaObjMutex());
1317     LOGI("HdiP2pReject success.");
1318     return WIFI_HAL_OPT_OK;
1319 }
1320 
HdiSetMiracastSinkConfig(const char * config)1321 WifiErrorNo HdiSetMiracastSinkConfig(const char *config)
1322 {
1323     LOGI("HdiSetMiracastSinkConfig enter");
1324     pthread_mutex_lock(GetWpaObjMutex());
1325     struct IWpaInterface *wpaObj = GetWpaInterface();
1326     if (wpaObj == NULL) {
1327         LOGE("HdiSetMiracastSinkConfig: wpaObj is NULL");
1328         pthread_mutex_unlock(GetWpaObjMutex());
1329         return WIFI_HAL_OPT_FAILED;
1330     }
1331 
1332     int32_t result = wpaObj->DeliverP2pData(wpaObj, GetHdiP2pIfaceName(), P2P_SET_MIRACAST_SINK_CONFIG, 0, config);
1333     if (result != HDF_SUCCESS) {
1334         LOGE("HdiSetMiracastSinkConfig: send failed result:%{public}d", result);
1335         pthread_mutex_unlock(GetWpaObjMutex());
1336         return WIFI_HAL_OPT_FAILED;
1337     }
1338     pthread_mutex_unlock(GetWpaObjMutex());
1339     LOGI("HdiSetMiracastSinkConfig success.");
1340     return WIFI_HAL_OPT_OK;
1341 }
1342 
HdiP2pTempGroupAdd(int freq)1343 WifiErrorNo HdiP2pTempGroupAdd(int freq)
1344 {
1345     char cmd[BUFF_SIZE] = {0};
1346     LOGI("HdiP2pTempGroupAdd enter");
1347     pthread_mutex_lock(GetWpaObjMutex());
1348     struct IWpaInterface *wpaObj = GetWpaInterface();
1349     if (wpaObj == NULL) {
1350         LOGE("HdiP2pTempGroupAdd: wpaObj is NULL");
1351         pthread_mutex_unlock(GetWpaObjMutex());
1352         return WIFI_HAL_OPT_FAILED;
1353     }
1354     if (snprintf_s(cmd, sizeof(cmd),sizeof(cmd) - 1, "%d", freq) < 0) {
1355         LOGE("HdiP2pTempGroupAdd snprintf_s failed");
1356         return WIFI_HAL_OPT_FAILED;
1357     }
1358     int32_t result = wpaObj->DeliverP2pData(wpaObj, GetHdiP2pIfaceName(), P2P_CREATE_TEMP_GROUP, 0, cmd);
1359     if (result != HDF_SUCCESS) {
1360         LOGE("HdiP2pTempGroupAdd: send failed result:%{public}d", result);
1361         pthread_mutex_unlock(GetWpaObjMutex());
1362         return WIFI_HAL_OPT_FAILED;
1363     }
1364     pthread_mutex_unlock(GetWpaObjMutex());
1365     LOGI("HdiP2pTempGroupAdd success.");
1366     return WIFI_HAL_OPT_OK;
1367 }
1368 #endif