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_hal.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 "ctrl_iface.h"
27  #include "main.h"
28  #include "wps_supplicant.h"
29  #include "bssid_ignore.h"
30  #include "wpa_supplicant/config.h"
31  #include "common/defs.h"
32  #include "v1_1/iwpa_callback.h"
33  #include "v1_1/iwpa_interface.h"
34  #include <unistd.h>
35  #include <stdlib.h>
36  #include <dlfcn.h>
37  #include <string.h>
38  #include "hdi_wpa_common.h"
39  
40  #define BUF_SIZE 512
41  
42  const int QUOTATION_MARKS_FLAG_YES = 0;
43  const int QUOTATION_MARKS_FLAG_NO = 1;
44  const int MAX_NETWORKS_NUM = 100;
45  pthread_mutex_t g_interfaceLock = PTHREAD_MUTEX_INITIALIZER;
46  
47  static WpaSsidField g_wpaSsidFields[] = {
48      {DEVICE_CONFIG_SSID, "ssid", QUOTATION_MARKS_FLAG_YES},
49      {DEVICE_CONFIG_PSK, "psk", QUOTATION_MARKS_FLAG_YES},
50      {DEVICE_CONFIG_KEYMGMT, "key_mgmt", QUOTATION_MARKS_FLAG_NO},
51      {DEVICE_CONFIG_PRIORITY, "priority", QUOTATION_MARKS_FLAG_NO},
52      {DEVICE_CONFIG_SCAN_SSID, "scan_ssid", QUOTATION_MARKS_FLAG_NO},
53      {DEVICE_CONFIG_EAP, "eap", QUOTATION_MARKS_FLAG_NO},
54      {DEVICE_CONFIG_IDENTITY, "identity", QUOTATION_MARKS_FLAG_YES},
55      {DEVICE_CONFIG_PASSWORD, "password", QUOTATION_MARKS_FLAG_YES},
56      {DEVICE_CONFIG_BSSID, "bssid", QUOTATION_MARKS_FLAG_NO},
57      {DEVICE_CONFIG_AUTH_ALGORITHMS, "auth_alg", QUOTATION_MARKS_FLAG_NO},
58      {DEVICE_CONFIG_WEP_KEY_IDX, "wep_tx_keyidx", QUOTATION_MARKS_FLAG_NO},
59      {DEVICE_CONFIG_WEP_KEY_0, "wep_key0", QUOTATION_MARKS_FLAG_NO},
60      {DEVICE_CONFIG_WEP_KEY_1, "wep_key1", QUOTATION_MARKS_FLAG_NO},
61      {DEVICE_CONFIG_WEP_KEY_2, "wep_key2", QUOTATION_MARKS_FLAG_NO},
62      {DEVICE_CONFIG_WEP_KEY_3, "wep_key3", QUOTATION_MARKS_FLAG_NO},
63      {DEVICE_CONFIG_EAP_CLIENT_CERT, "client_cert", QUOTATION_MARKS_FLAG_YES},
64      {DEVICE_CONFIG_EAP_PRIVATE_KEY, "private_key", QUOTATION_MARKS_FLAG_YES},
65      {DEVICE_CONFIG_EAP_PHASE2METHOD, "phase2", QUOTATION_MARKS_FLAG_YES},
66      {DEVICE_CONFIG_IEEE80211W, "ieee80211w", QUOTATION_MARKS_FLAG_NO},
67      {DEVICE_CONFIG_ALLOW_PROTOCOLS, "proto", QUOTATION_MARKS_FLAG_NO},
68      {DEVICE_CONFIG_GROUP_CIPHERS, "group", QUOTATION_MARKS_FLAG_NO},
69      {DEVICE_CONFIG_PAIRWISE_CIPHERS, "pairwise", QUOTATION_MARKS_FLAG_NO},
70      {DEVICE_CONFIG_SAE_PASSWD, "sae_password", QUOTATION_MARKS_FLAG_YES},
71      {DEVICE_CONFIG_WAPI_CA_CERT, "wapi_ca_cert", QUOTATION_MARKS_FLAG_YES},
72      {DEVICE_CONFIG_WAPI_USER_CERT, "wapi_user_sel_cert", QUOTATION_MARKS_FLAG_YES},
73      {DEVICE_CONFIG_WAPI_PSK_KEY_TYPE, "psk_key_type", QUOTATION_MARKS_FLAG_NO},
74      {DEVICE_CONFIG_WAPI_PSK, "wapi_psk", QUOTATION_MARKS_FLAG_YES},
75  };
76  
CalcQuotationMarksFlag(int pos,const char value[WIFI_NETWORK_CONFIG_VALUE_LENGTH])77  int CalcQuotationMarksFlag(int pos, const char value[WIFI_NETWORK_CONFIG_VALUE_LENGTH])
78  {
79      int flag = g_wpaSsidFields[pos].flag;
80      const int hexPskMaxLen = 64;
81      int len = strlen(value);
82      /* if the psk length is 64, it's hex format and don't need quotation marks */
83      if (pos == DEVICE_CONFIG_PSK && len >= hexPskMaxLen) {
84          flag = QUOTATION_MARKS_FLAG_NO;
85      }
86      if (pos == DEVICE_CONFIG_WEP_KEY_0 ||
87          pos == DEVICE_CONFIG_WEP_KEY_1 ||
88          pos == DEVICE_CONFIG_WEP_KEY_2 ||
89          pos == DEVICE_CONFIG_WEP_KEY_3) {
90          const int wepKeyLen1 = 5;
91          const int wepKeyLen2 = 13;
92          const int wepKeyLen3 = 16;
93          /* For wep key, ASCII format need quotation marks, hex format is not required */
94          if (len == wepKeyLen1 || len == wepKeyLen2 || len == wepKeyLen3) {
95              flag = QUOTATION_MARKS_FLAG_YES;
96          }
97      }
98      return flag;
99  }
100  
GetInterfaceLock()101  pthread_mutex_t *GetInterfaceLock()
102  {
103      return &g_interfaceLock;
104  }
105  
WpaInterfaceAddNetwork(struct IWpaInterface * self,const char * ifName,int32_t * networkId)106  int32_t WpaInterfaceAddNetwork(struct IWpaInterface *self, const char *ifName, int32_t *networkId)
107  {
108      (void)self;
109      HDF_LOGI("enter %{public}s", __func__);
110      if (ifName == NULL || networkId == NULL) {
111          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
112          return HDF_ERR_INVALID_PARAM;
113      }
114      pthread_mutex_lock(&g_interfaceLock);
115      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
116      if (pStaIfc == NULL) {
117          pthread_mutex_unlock(&g_interfaceLock);
118          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
119          return HDF_FAILURE;
120      }
121      int ret = pStaIfc->wpaCliCmdAddNetworks(pStaIfc);
122      if (ret < 0) {
123          pthread_mutex_unlock(&g_interfaceLock);
124          HDF_LOGE("%{public}s: WpaInterfaceAddNetwork fail! ret = %{public}d", __func__, ret);
125          return HDF_FAILURE;
126      }
127      *networkId = ret;
128      pthread_mutex_unlock(&g_interfaceLock);
129      HDF_LOGI("%{public}s: add network success networkId = %{public}d", __func__, *networkId);
130      return HDF_SUCCESS;
131  }
132  
WpaInterfaceRemoveNetwork(struct IWpaInterface * self,const char * ifName,int32_t networkId)133  int32_t WpaInterfaceRemoveNetwork(struct IWpaInterface *self, const char *ifName, int32_t networkId)
134  {
135      (void)self;
136      HDF_LOGI("enter %{public}s networkId = %{public}d", __func__, networkId);
137      if (ifName == NULL) {
138          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
139          return HDF_ERR_INVALID_PARAM;
140      }
141      pthread_mutex_lock(&g_interfaceLock);
142      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
143      if (pStaIfc == NULL) {
144          pthread_mutex_unlock(&g_interfaceLock);
145          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
146          return HDF_FAILURE;
147      }
148      int ret = pStaIfc->wpaCliCmdRemoveNetwork(pStaIfc, networkId);
149      if (ret < 0) {
150          pthread_mutex_unlock(&g_interfaceLock);
151          HDF_LOGE("%{public}s: WpaInterfaceRemoveNetwork fail! ret = %{public}d", __func__, ret);
152          return HDF_FAILURE;
153      }
154      pthread_mutex_unlock(&g_interfaceLock);
155      HDF_LOGI("%{public}s: remove network success ret = %{public}d", __func__, ret);
156      return HDF_SUCCESS;
157  }
158  
WpaInterfaceDisableNetwork(struct IWpaInterface * self,const char * ifName,const int32_t networkId)159  int32_t WpaInterfaceDisableNetwork(struct IWpaInterface *self, const char *ifName, const int32_t networkId)
160  {
161      (void)self;
162      HDF_LOGI("enter %{public}s networkId = %{public}d", __func__, networkId);
163      if (ifName == NULL) {
164          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
165          return HDF_ERR_INVALID_PARAM;
166      }
167      pthread_mutex_lock(&g_interfaceLock);
168      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
169      if (pStaIfc == NULL) {
170          pthread_mutex_unlock(&g_interfaceLock);
171          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
172          return HDF_FAILURE;
173      }
174      int ret = pStaIfc->wpaCliCmdDisableNetwork(pStaIfc, networkId);
175      if (ret < 0) {
176          pthread_mutex_unlock(&g_interfaceLock);
177          HDF_LOGE("%{public}s: WpaInterfaceDisableNetwork fail! ret = %{public}d", __func__, ret);
178          return HDF_FAILURE;
179      }
180      pthread_mutex_unlock(&g_interfaceLock);
181      HDF_LOGI("%{public}s: WpaInterfaceDisableNetwork success ret = %{public}d", __func__, ret);
182      return HDF_SUCCESS;
183  }
184  
WpaInterfaceSetNetwork(struct IWpaInterface * self,const char * ifName,const int32_t networkId,const char * name,const char * value)185  int32_t WpaInterfaceSetNetwork(struct IWpaInterface *self, const char *ifName,
186      const int32_t networkId, const char *name, const char *value)
187  {
188      (void)self;
189      if (ifName == NULL || name == NULL || value == NULL) {
190          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
191          return HDF_ERR_INVALID_PARAM;
192      }
193      HDF_LOGI("enter %{public}s networkId = %{public}d name = %{private}s value = %{private}s", __func__, networkId,
194          name, value);
195      pthread_mutex_lock(&g_interfaceLock);
196      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
197      if (pStaIfc == NULL) {
198          pthread_mutex_unlock(&g_interfaceLock);
199          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
200          return HDF_FAILURE;
201      }
202      struct WpaSetNetworkArgv conf = {0};
203      conf.id = networkId;
204      int pos = -1;
205      for (int i = 0; i < (int)(sizeof(g_wpaSsidFields) / sizeof(g_wpaSsidFields[0])); ++i) {
206          if (strcmp(g_wpaSsidFields[i].fieldName, name) == 0) {
207              pos = i;
208              conf.param = g_wpaSsidFields[i].field;
209              break;
210          }
211      }
212      if (pos < 0) {
213          pthread_mutex_unlock(&g_interfaceLock);
214          HDF_LOGE("%{public}s SetNetwork: unsupported name  %{public}s", __func__, name);
215          return HDF_FAILURE;
216      }
217      if (strncpy_s(conf.value, sizeof(conf.value), value, strlen(value)) != 0) {
218          pthread_mutex_unlock(&g_interfaceLock);
219          HDF_LOGE("%{public}s strncpy_s conf.value fail", __func__);
220          return HDF_FAILURE;
221      }
222      int ret = pStaIfc->wpaCliCmdSetNetwork(pStaIfc, &conf);
223      if (ret < 0) {
224          pthread_mutex_unlock(&g_interfaceLock);
225          HDF_LOGE("%{public}s: wpaCliCmdSetNetwork fail! ret = %{public}d", __func__, ret);
226          return HDF_FAILURE;
227      }
228      pthread_mutex_unlock(&g_interfaceLock);
229      HDF_LOGI("%{public}s: wpaCliCmdSetNetwork sucess ret = %{public}d", __func__, ret);
230      return HDF_SUCCESS;
231  }
232  
WpaFillWpaListNetworkParam(struct WifiNetworkInfo * wifiWpaNetworkInfo,struct HdiWifiWpaNetworkInfo * hdiWifiWpaNetworkInfo)233  static int32_t WpaFillWpaListNetworkParam(struct WifiNetworkInfo  *wifiWpaNetworkInfo,
234      struct HdiWifiWpaNetworkInfo *hdiWifiWpaNetworkInfo)
235  {
236      int32_t ret = HDF_SUCCESS;
237  
238      if (wifiWpaNetworkInfo == NULL || hdiWifiWpaNetworkInfo == NULL) {
239          HDF_LOGE("%{public}s: wifiWpaNetworkInfo or hdiWifiWpaNetworkInfo is NULL!", __func__);
240          return HDF_ERR_INVALID_PARAM;
241      }
242      do {
243          uint8_t tmpBssid[ETH_ADDR_LEN] = {0};
244          hwaddr_aton(wifiWpaNetworkInfo->bssid, tmpBssid);
245          if (FillData(&hdiWifiWpaNetworkInfo->bssid, &hdiWifiWpaNetworkInfo->bssidLen,
246              tmpBssid, ETH_ADDR_LEN) != HDF_SUCCESS) {
247              HDF_LOGE("%{public}s: fill bssid fail!", __func__);
248              ret = HDF_FAILURE;
249              break;
250          }
251          if (FillData(&hdiWifiWpaNetworkInfo->ssid, &hdiWifiWpaNetworkInfo->ssidLen,
252              (uint8_t *)wifiWpaNetworkInfo->ssid, strlen(wifiWpaNetworkInfo->ssid)) != HDF_SUCCESS) {
253              HDF_LOGE("%{public}s: fill ssid fail!", __func__);
254              ret = HDF_FAILURE;
255          }
256          if (FillData(&hdiWifiWpaNetworkInfo->flags, &hdiWifiWpaNetworkInfo->flagsLen,
257              (uint8_t *)wifiWpaNetworkInfo->flags, strlen(wifiWpaNetworkInfo->flags)) != HDF_SUCCESS) {
258              HDF_LOGE("%{public}s: fill flags fail!", __func__);
259              ret = HDF_FAILURE;
260          }
261      } while (0);
262      if (ret != HDF_SUCCESS) {
263          if (hdiWifiWpaNetworkInfo->bssid != NULL) {
264              OsalMemFree(hdiWifiWpaNetworkInfo->bssid);
265              hdiWifiWpaNetworkInfo->bssid = NULL;
266          }
267          if (hdiWifiWpaNetworkInfo->ssid != NULL) {
268              OsalMemFree(hdiWifiWpaNetworkInfo->ssid);
269              hdiWifiWpaNetworkInfo->ssid = NULL;
270          }
271          if (hdiWifiWpaNetworkInfo->flags != NULL) {
272              OsalMemFree(hdiWifiWpaNetworkInfo->flags);
273              hdiWifiWpaNetworkInfo->flags = NULL;
274          }
275      }
276      return ret;
277  }
278  
279  //need to check
WpaInterfaceListNetworks(struct IWpaInterface * self,const char * ifName,struct HdiWifiWpaNetworkInfo * networkInfo,uint32_t * networkInfoLen)280  int32_t WpaInterfaceListNetworks(struct IWpaInterface *self, const char *ifName,
281      struct HdiWifiWpaNetworkInfo *networkInfo, uint32_t *networkInfoLen)
282  {
283      (void)self;
284      HDF_LOGI("enter %{public}s ", __func__);
285      if (ifName == NULL || networkInfo == NULL || networkInfoLen == NULL) {
286          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
287          return HDF_ERR_INVALID_PARAM;
288      }
289      pthread_mutex_lock(&g_interfaceLock);
290      int size = MAX_NETWORKS_NUM;
291      WifiNetworkInfo *infos = (WifiNetworkInfo *)calloc(size, sizeof(WifiNetworkInfo));
292      if (infos == NULL) {
293          pthread_mutex_unlock(&g_interfaceLock);
294          HDF_LOGE("%{public}s: info = NULL", __func__);
295          return HDF_FAILURE;
296      }
297      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
298      if (pStaIfc == NULL) {
299          pthread_mutex_unlock(&g_interfaceLock);
300          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
301          free(infos);
302          return HDF_FAILURE;
303      }
304      int ret = pStaIfc->wpaCliCmdListNetworks(pStaIfc, infos, &size);
305      if (ret < 0) {
306          pthread_mutex_unlock(&g_interfaceLock);
307          HDF_LOGE("%{public}s: wpaCliCmdListNetworks fail! ret = %{public}d", __func__, ret);
308          free(infos);
309          return HDF_FAILURE;
310      }
311      WifiNetworkInfo *infosTmp = infos;
312      HDF_LOGI("%{public}s: wpaCliCmdListNetworks success size = %{public}d", __func__, size);
313      for (int i = 0; i < ((size > MAX_NETWORKS_NUM) ? MAX_NETWORKS_NUM : size); i++) {
314          WpaFillWpaListNetworkParam(infos, networkInfo);
315          infos++;
316          networkInfo++;
317      }
318      *networkInfoLen = size;
319      free(infosTmp);
320      pthread_mutex_unlock(&g_interfaceLock);
321      return HDF_SUCCESS;
322  }
323  
WpaInterfaceSelectNetwork(struct IWpaInterface * self,const char * ifName,const int32_t networkId)324  int32_t WpaInterfaceSelectNetwork(struct IWpaInterface *self, const char *ifName,
325      const int32_t networkId)
326  {
327      (void)self;
328      HDF_LOGI("enter %{public}s networkId = %{public}d", __func__, networkId);
329      if (ifName == NULL) {
330          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
331          return HDF_ERR_INVALID_PARAM;
332      }
333      pthread_mutex_lock(&g_interfaceLock);
334      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
335      if (pStaIfc == NULL) {
336          pthread_mutex_unlock(&g_interfaceLock);
337          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
338          return HDF_FAILURE;
339      }
340      int ret = pStaIfc->wpaCliCmdSelectNetwork(pStaIfc, networkId);
341      if (ret < 0) {
342          pthread_mutex_unlock(&g_interfaceLock);
343          HDF_LOGE("%{public}s: wpaCliCmdSelectNetwork fail! ret = %{public}d", __func__, ret);
344          return HDF_FAILURE;
345      }
346      pthread_mutex_unlock(&g_interfaceLock);
347      HDF_LOGI("%{public}s: wpaCliCmdSelectNetwork success ret = %{public}d", __func__, ret);
348      return HDF_SUCCESS;
349  }
350  
WpaInterfaceEnableNetwork(struct IWpaInterface * self,const char * ifName,const int32_t networkId)351  int32_t WpaInterfaceEnableNetwork(struct IWpaInterface *self, const char *ifName, const int32_t networkId)
352  {
353      (void)self;
354      HDF_LOGI("enter %{public}s networkId = %{public}d", __func__, networkId);
355      if (ifName == NULL) {
356          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
357          return HDF_ERR_INVALID_PARAM;
358      }
359      pthread_mutex_lock(&g_interfaceLock);
360      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
361      if (pStaIfc == NULL) {
362          pthread_mutex_unlock(&g_interfaceLock);
363          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
364          return HDF_FAILURE;
365      }
366      int ret = pStaIfc->wpaCliCmdEnableNetwork(pStaIfc, networkId);
367      if (ret < 0) {
368          pthread_mutex_unlock(&g_interfaceLock);
369          HDF_LOGE("%{public}s: wpaCliCmdEnableNetwork fail! ret = %{public}d", __func__, ret);
370          return HDF_FAILURE;
371      }
372      pthread_mutex_unlock(&g_interfaceLock);
373      HDF_LOGI("%{public}s: wpaCliCmdEnableNetwork success ret = %{public}d", __func__, ret);
374      return HDF_SUCCESS;
375  }
376  
WpaInterfaceReconnect(struct IWpaInterface * self,const char * ifName)377  int32_t WpaInterfaceReconnect(struct IWpaInterface *self, const char *ifName)
378  {
379      (void)self;
380      HDF_LOGI("enter %{public}s ", __func__);
381      if (ifName == NULL) {
382          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
383          return HDF_ERR_INVALID_PARAM;
384      }
385      pthread_mutex_lock(&g_interfaceLock);
386      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
387      if (pStaIfc == NULL) {
388          pthread_mutex_unlock(&g_interfaceLock);
389          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
390          return HDF_FAILURE;
391      }
392      int ret = pStaIfc->wpaCliCmdReconnect(pStaIfc);
393      if (ret < 0) {
394          pthread_mutex_unlock(&g_interfaceLock);
395          HDF_LOGE("%{public}s: wpaCliCmdReconnect fail! ret = %{public}d", __func__, ret);
396          return HDF_FAILURE;
397      }
398      pthread_mutex_unlock(&g_interfaceLock);
399      HDF_LOGI("%{public}s: wpaCliCmdReconnect success ret = %{public}d", __func__, ret);
400      return HDF_SUCCESS;
401  }
402  
WpaInterfaceDisconnect(struct IWpaInterface * self,const char * ifName)403  int32_t WpaInterfaceDisconnect(struct IWpaInterface *self, const char *ifName)
404  {
405      (void)self;
406      HDF_LOGI("enter %{public}s ", __func__);
407      if (ifName == NULL) {
408          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
409          return HDF_ERR_INVALID_PARAM;
410      }
411      pthread_mutex_lock(&g_interfaceLock);
412      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
413      if (pStaIfc == NULL) {
414          pthread_mutex_unlock(&g_interfaceLock);
415          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
416          return HDF_FAILURE;
417      }
418      int ret = pStaIfc->wpaCliCmdDisconnect(pStaIfc);
419      if (ret < 0) {
420          pthread_mutex_unlock(&g_interfaceLock);
421          HDF_LOGE("%{public}s: wpaCliCmdDisconnect fail! ret = %{public}d", __func__, ret);
422          return HDF_FAILURE;
423      }
424      pthread_mutex_unlock(&g_interfaceLock);
425      HDF_LOGI("%{public}s: wpaCliCmdDisconnect success ret = %{public}d", __func__, ret);
426      return HDF_SUCCESS;
427  }
428  
WpaInterfaceSetPowerSave(struct IWpaInterface * self,const char * ifName,const int32_t enable)429  int32_t WpaInterfaceSetPowerSave(struct IWpaInterface *self, const char *ifName, const int32_t enable)
430  {
431      (void)self;
432      HDF_LOGI("enter %{public}s enable = %{public}d", __func__, enable);
433      if (ifName == NULL) {
434          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
435          return HDF_ERR_INVALID_PARAM;
436      }
437      pthread_mutex_lock(&g_interfaceLock);
438      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
439      if (pStaIfc == NULL) {
440          pthread_mutex_unlock(&g_interfaceLock);
441          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
442          return HDF_FAILURE;
443      }
444      int ret = pStaIfc->wpaCliCmdPowerSave(pStaIfc, enable);
445      if (ret < 0) {
446          pthread_mutex_unlock(&g_interfaceLock);
447          HDF_LOGE("%{public}s: wpaCliCmdPowerSave fail! ret = %{public}d", __func__, ret);
448          return HDF_FAILURE;
449      }
450      pthread_mutex_unlock(&g_interfaceLock);
451      HDF_LOGI("%{public}s: wpaCliCmdPowerSave success ret = %{public}d", __func__, ret);
452      return HDF_SUCCESS;
453  }
454  
WpaInterfaceAutoConnect(struct IWpaInterface * self,const char * ifName,const int32_t enable)455  int32_t WpaInterfaceAutoConnect(struct IWpaInterface *self, const char *ifName, const int32_t enable)
456  {
457      (void)self;
458      HDF_LOGI("enter %{public}s enable = %{public}d", __func__, enable);
459      if (ifName == NULL) {
460          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
461          return HDF_ERR_INVALID_PARAM;
462      }
463      pthread_mutex_lock(&g_interfaceLock);
464      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
465      if (pStaIfc == NULL) {
466          pthread_mutex_unlock(&g_interfaceLock);
467          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
468          return HDF_FAILURE;
469      }
470      int ret = pStaIfc->wpaCliCmdSetAutoConnect(pStaIfc, enable);
471      if (ret < 0) {
472          pthread_mutex_unlock(&g_interfaceLock);
473          HDF_LOGE("%{public}s: wpaCliCmdSetAutoConnect fail! ret=%{public}d", __func__, ret);
474          return HDF_FAILURE;
475      }
476      pthread_mutex_unlock(&g_interfaceLock);
477      HDF_LOGI("%{public}s: wpaCliCmdSetAutoConnect success ret = %{public}d", __func__, ret);
478      return HDF_SUCCESS;
479  }
480  
GetWpaCmdStatus(uint8_t ** dst,uint32_t * dstLen,char * src)481  static void GetWpaCmdStatus(uint8_t** dst, uint32_t* dstLen, char* src)
482  {
483      if (strcmp(src, "") != 0) {
484          *dst = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * (strlen(src) + 1));
485          if (*dst == NULL) {
486              HDF_LOGE("%{public}s OsalMemCalloc is NULL", __func__);
487              *dstLen = 0;
488              return;
489          }
490          *dstLen = strlen(src);
491          if (strcpy_s((char*)(*dst), strlen(src) + 1, src) != EOK) {
492              HDF_LOGE("%{public}s strcpy failed", __func__);
493              return;
494          }
495      }
496      return;
497  }
498  
WpaProcessWifiStatus(struct WpaHalCmdStatus * halStatus,struct HdiWpaCmdStatus * status)499  static void WpaProcessWifiStatus(struct WpaHalCmdStatus *halStatus, struct HdiWpaCmdStatus *status)
500  {
501      if (halStatus == NULL) {
502          HDF_LOGE("%{public}s halStatus is NULL", __func__);
503          return;
504      }
505      status->id = halStatus->id;
506      status->freq = halStatus->freq;
507      GetWpaCmdStatus(&(status->keyMgmt), &(status->keyMgmtLen), halStatus->keyMgmt);
508      GetWpaCmdStatus(&(status->ssid), &(status->ssidLen), halStatus->ssid);
509      if (strcmp(halStatus->address, "") != 0) {
510          HDF_LOGI("%{public}s key include address value=%{private}s", __func__, halStatus->address);
511          uint8_t tmpAddress[ETH_ADDR_LEN + 1] = {0};
512          hwaddr_aton(halStatus->address, tmpAddress);
513          status->address = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * (ETH_ADDR_LEN + 1));
514          if (status->address == NULL) {
515              HDF_LOGE("%{public}s status->address is NULL", __func__);
516              status->addressLen = 0;
517              return;
518          }
519          status->addressLen = ETH_ADDR_LEN + 1 ;
520          if (memcpy_s((char *)status->address, ETH_ADDR_LEN + 1, (char*)tmpAddress, ETH_ADDR_LEN + 1) != EOK) {
521              HDF_LOGE("%{public}s strcpy memcpy", __func__);
522          }
523      }
524      if (strcmp(halStatus->bssid, "") != 0) {
525          HDF_LOGI("%{public}s key include bssid value=%{private}s", __func__, halStatus->bssid);
526          uint8_t tmpBssid[ETH_ADDR_LEN + 1] = {0};
527          hwaddr_aton(halStatus->bssid, tmpBssid);
528          status->bssid = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * (ETH_ADDR_LEN + 1));
529          if (status->bssid == NULL) {
530              HDF_LOGE("%{public}s status->bssid is NULL", __func__);
531              status->bssidLen = 0;
532              return;
533          }
534          status->bssidLen = ETH_ADDR_LEN + 1 ;
535          if (strcpy_s((char *)status->bssid, ETH_ADDR_LEN + 1, (char*)tmpBssid) != EOK) {
536              HDF_LOGE("%{public}s strcpy failed", __func__);
537          }
538      }
539  }
540  
WpaInterfaceWifiStatus(struct IWpaInterface * self,const char * ifName,struct HdiWpaCmdStatus * status)541  int32_t WpaInterfaceWifiStatus(struct IWpaInterface *self, const char *ifName, struct HdiWpaCmdStatus *status)
542  {
543      HDF_LOGI("enter %{public}s", __func__);
544      if (ifName == NULL || status == NULL) {
545          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
546          return HDF_ERR_INVALID_PARAM;
547      }
548      pthread_mutex_lock(&g_interfaceLock);
549      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
550      if (pStaIfc == NULL) {
551          pthread_mutex_unlock(&g_interfaceLock);
552          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
553          return HDF_FAILURE;
554      }
555      struct WpaHalCmdStatus halStatus;
556      if (memset_s(&halStatus, sizeof(halStatus), 0, sizeof(halStatus)) != EOK) {
557          pthread_mutex_unlock(&g_interfaceLock);
558          return HDF_FAILURE;
559      }
560      int ret = pStaIfc->wpaCliCmdStatus(pStaIfc, ifName, &halStatus);
561      if (ret < 0) {
562          pthread_mutex_unlock(&g_interfaceLock);
563          HDF_LOGE("%{public}s: wpaCliCmdStatus fail! ret=%{public}d", __func__, ret);
564          return HDF_FAILURE;
565      }
566      status->bssidLen = 0;
567      status->ssidLen = 0;
568      status->keyMgmtLen = 0;
569      status->addressLen = 0;
570      WpaProcessWifiStatus(&halStatus, status);
571      if (status->addressLen == 0) {
572          HDF_LOGE("%{public}s key not include address", __func__);
573      }
574      if (status->bssidLen == 0) {
575          HDF_LOGE("%{public}s key not include bssid", __func__);
576      }
577      pthread_mutex_unlock(&g_interfaceLock);
578      HDF_LOGI("%{public}s: WpaInterfaceWifiStatus success ", __func__);
579      return HDF_SUCCESS;
580  }
581  
WpaInterfaceSaveConfig(struct IWpaInterface * self,const char * ifName)582  int32_t WpaInterfaceSaveConfig(struct IWpaInterface *self, const char *ifName)
583  {
584      (void)self;
585      HDF_LOGI("enter %{public}s ", __func__);
586      if (ifName == NULL) {
587          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
588          return HDF_ERR_INVALID_PARAM;
589      }
590      pthread_mutex_lock(&g_interfaceLock);
591      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
592      if (pStaIfc == NULL) {
593          pthread_mutex_unlock(&g_interfaceLock);
594          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
595          return HDF_FAILURE;
596      }
597      int ret = pStaIfc->wpaCliCmdSaveConfig(pStaIfc);
598      if (ret < 0) {
599          pthread_mutex_unlock(&g_interfaceLock);
600          HDF_LOGE("%{public}s: wpaCliCmdSaveConfig fail! ret = %{public}d", __func__, ret);
601          return HDF_FAILURE;
602      }
603      pthread_mutex_unlock(&g_interfaceLock);
604      HDF_LOGI("%{public}s: wpaCliCmdSaveConfig success ret = %{public}d", __func__, ret);
605      return HDF_SUCCESS;
606  }
607  
WpaInterfaceWpsPbcMode(struct IWpaInterface * self,const char * ifName,const struct HdiWifiWpsParam * wpaParam)608  int32_t WpaInterfaceWpsPbcMode(struct IWpaInterface *self, const char *ifName, const struct HdiWifiWpsParam *wpaParam)
609  {
610      HDF_LOGI("enter %{public}s ", __func__);
611      (void)self;
612      if (ifName == NULL || wpaParam == NULL || wpaParam->bssid == NULL) {
613          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
614          return HDF_ERR_INVALID_PARAM;
615      }
616      pthread_mutex_lock(&g_interfaceLock);
617      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
618      if (pStaIfc == NULL) {
619          pthread_mutex_unlock(&g_interfaceLock);
620          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
621          return HDF_FAILURE;
622      }
623      int ret;
624      if (wpaParam->anyFlag < 0 && wpaParam->multiAp <= 0 && wpaParam->bssidLen == 0) {
625          ret = pStaIfc->wpaCliCmdWpsPbc(pStaIfc, NULL);
626      } else {
627          struct WpaWpsPbcArgv config = {0};
628          config.anyFlag = wpaParam->anyFlag;
629          config.multiAp = wpaParam->multiAp;
630          if (wpaParam->bssidLen > 0) {
631              if (strncpy_s(config.bssid, sizeof(config.bssid), (const char *)wpaParam->bssid,
632                  wpaParam->bssidLen) != 0) {
633                  pthread_mutex_unlock(&g_interfaceLock);
634                  HDF_LOGE("%{public}s: strncpy_s bssid fail", __func__);
635                  return HDF_FAILURE;
636              }
637          }
638          ret = pStaIfc->wpaCliCmdWpsPbc(pStaIfc, &config);
639      }
640      if (ret < 0) {
641          pthread_mutex_unlock(&g_interfaceLock);
642          HDF_LOGE("%{public}s: wpaCliCmdWpsPbc fail! ret = %{public}d", __func__, ret);
643          return HDF_FAILURE;
644      } else if (ret == WIFI_HAL_PBC_OVERLAP) {
645          pthread_mutex_unlock(&g_interfaceLock);
646          HDF_LOGE("%{public}s: wpaCliCmdWpsPbc fail PBC_OVERLAP ret = %{public}d", __func__, ret);
647          return HDF_FAILURE;
648      }
649      pthread_mutex_unlock(&g_interfaceLock);
650      HDF_LOGI("%{public}s: wpaCliCmdWpsPbc success ret = %{public}d", __func__, ret);
651      return HDF_SUCCESS;
652  }
653  
WpaInterfaceWpsPinMode(struct IWpaInterface * self,const char * ifName,const struct HdiWifiWpsParam * wpaParam,int * pinCode)654  int32_t WpaInterfaceWpsPinMode(struct IWpaInterface *self, const char *ifName,
655      const struct HdiWifiWpsParam *wpaParam, int *pinCode)
656  {
657      HDF_LOGI("enter %{public}s ", __func__);
658      (void)self;
659      if (ifName == NULL || wpaParam == NULL || wpaParam->bssid == NULL
660          || wpaParam->pinCode == NULL || pinCode == NULL) {
661          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
662          return HDF_ERR_INVALID_PARAM;
663      }
664      pthread_mutex_lock(&g_interfaceLock);
665      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
666      if (pStaIfc == NULL) {
667          pthread_mutex_unlock(&g_interfaceLock);
668          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
669          return HDF_FAILURE;
670      }
671      struct WpaWpsPinArgv config = {{0}, {0}};
672      if (strncpy_s(config.bssid, sizeof(config.bssid), MacToStr(wpaParam->bssid),
673          strlen(MacToStr(wpaParam->bssid))) != 0) {
674          pthread_mutex_unlock(&g_interfaceLock);
675          HDF_LOGE("%{public}s: strncpy_s bssid fail", __func__);
676          return HDF_FAILURE;
677      }
678      int ret = pStaIfc->wpaCliCmdWpsPin(pStaIfc, &config, pinCode);
679      if (ret < 0) {
680          pthread_mutex_unlock(&g_interfaceLock);
681          HDF_LOGE("%{public}s: wpaCliCmdWpsPin fail! ret = %{public}d", __func__, ret);
682          return HDF_FAILURE;
683      }
684      pthread_mutex_unlock(&g_interfaceLock);
685      HDF_LOGI("%{public}s: wpaCliCmdWpsPin success ret = %{public}d", __func__, ret);
686      return HDF_SUCCESS;
687  }
688  
WpaInterfaceWpsCancel(struct IWpaInterface * self,const char * ifName)689  int32_t WpaInterfaceWpsCancel(struct IWpaInterface *self, const char *ifName)
690  {
691      HDF_LOGI("enter %{public}s ", __func__);
692      (void)self;
693      if (ifName == NULL) {
694          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
695          return HDF_ERR_INVALID_PARAM;
696      }
697      pthread_mutex_lock(&g_interfaceLock);
698      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
699      if (pStaIfc == NULL) {
700          pthread_mutex_unlock(&g_interfaceLock);
701          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
702          return HDF_FAILURE;
703      }
704  
705      int ret = pStaIfc->wpaCliCmdWpsCancel(pStaIfc);
706      if (ret < 0) {
707          pthread_mutex_unlock(&g_interfaceLock);
708          HDF_LOGE("%{public}s: wpaCliCmdWpsCancel fail! ret = %{public}d", __func__, ret);
709          return HDF_FAILURE;
710      }
711      pthread_mutex_unlock(&g_interfaceLock);
712      HDF_LOGI("%{public}s: wpaCliCmdWpsCancel success ret = %{public}d", __func__, ret);
713      return HDF_SUCCESS;
714  }
715  
716  //need to deal countryCodeLen
WpaInterfaceGetCountryCode(struct IWpaInterface * self,const char * ifName,char * countryCode,uint32_t countryCodeLen)717  int32_t WpaInterfaceGetCountryCode(struct IWpaInterface *self, const char *ifName,
718      char *countryCode, uint32_t countryCodeLen)
719  {
720      HDF_LOGI("enter %{public}s: ", __func__);
721      (void)self;
722      if (ifName == NULL || countryCode == NULL) {
723          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
724          return HDF_ERR_INVALID_PARAM;
725      }
726      pthread_mutex_lock(&g_interfaceLock);
727      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
728      if (pStaIfc == NULL) {
729          pthread_mutex_unlock(&g_interfaceLock);
730          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
731          return HDF_FAILURE;
732      }
733      int ret = pStaIfc->wpaCliCmdGetCountryCode(pStaIfc, countryCode, countryCodeLen);
734      if (ret < 0) {
735          pthread_mutex_unlock(&g_interfaceLock);
736          HDF_LOGE("%{public}s: wpaCliCmdGetCountryCode fail! ret = %{public}d", __func__, ret);
737          return HDF_FAILURE;
738      }
739      pthread_mutex_unlock(&g_interfaceLock);
740      HDF_LOGI("%{public}s: wpaCliCmdGetCountryCode success ret = %{public}d", __func__, ret);
741      return HDF_SUCCESS;
742  }
743  
744  //need to deal valueLen
WpaInterfaceGetNetwork(struct IWpaInterface * self,const char * ifName,const int32_t networkId,const char * param,char * value,uint32_t valueLen)745  int32_t WpaInterfaceGetNetwork(struct IWpaInterface *self, const char *ifName,
746      const int32_t networkId, const char *param, char *value, uint32_t valueLen)
747  {
748      HDF_LOGI("enter %{public}s ", __func__);
749      (void)self;
750      if (ifName == NULL || param == NULL || value == NULL || valueLen == 0) {
751          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
752          return HDF_ERR_INVALID_PARAM;
753      }
754      pthread_mutex_lock(&g_interfaceLock);
755      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
756      if (pStaIfc == NULL) {
757          pthread_mutex_unlock(&g_interfaceLock);
758          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
759          return HDF_FAILURE;
760      }
761      struct WpaGetNetworkArgv getNetwork = {0};
762      getNetwork.id = networkId;
763      if (strncpy_s(getNetwork.param, sizeof(getNetwork.param), param, strlen(param)) != 0) {
764          pthread_mutex_unlock(&g_interfaceLock);
765          HDF_LOGE("%{public}s: strncpy_s param fail", __func__);
766          return HDF_FAILURE;
767      }
768      int ret = pStaIfc->wpaCliCmdGetNetwork(pStaIfc, &getNetwork, value, valueLen);
769      if (ret < 0) {
770          pthread_mutex_unlock(&g_interfaceLock);
771          HDF_LOGE("%{public}s: wpaCliCmdGetNetwork fail! ret = %{public}d", __func__, ret);
772          return HDF_FAILURE;
773      }
774      pthread_mutex_unlock(&g_interfaceLock);
775      HDF_LOGI("%{public}s: wpaCliCmdGetNetwork success ret = %{public}d", __func__, ret);
776      return HDF_SUCCESS;
777  }
778  
WpaInterfaceBlocklistClear(struct IWpaInterface * self,const char * ifName)779  int32_t WpaInterfaceBlocklistClear(struct IWpaInterface *self, const char *ifName)
780  {
781      HDF_LOGI("enter %{public}s ", __func__);
782      (void)self;
783      if (ifName == NULL) {
784          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
785          return HDF_ERR_INVALID_PARAM;
786      }
787      pthread_mutex_lock(&g_interfaceLock);
788      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
789      if (pStaIfc == NULL) {
790          pthread_mutex_unlock(&g_interfaceLock);
791          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
792          return HDF_FAILURE;
793      }
794      int ret = pStaIfc->wpaCliCmdWpaBlockListClear(pStaIfc);
795      if (ret < 0) {
796          pthread_mutex_unlock(&g_interfaceLock);
797          HDF_LOGE("%{public}s: wpaCliCmdWpaBlockListClear fail! ret = %{public}d", __func__, ret);
798          return HDF_FAILURE;
799      }
800      pthread_mutex_unlock(&g_interfaceLock);
801      HDF_LOGI("%{public}s: wpaCliCmdWpaBlockListClear success ret = %{public}d", __func__, ret);
802      return HDF_SUCCESS;
803  }
804  
WpaInterfaceSetSuspendMode(struct IWpaInterface * self,const char * ifName,const int32_t mode)805  int32_t WpaInterfaceSetSuspendMode(struct IWpaInterface *self, const char *ifName, const int32_t mode)
806  {
807      HDF_LOGI("enter %{public}s: mode = %{public}d", __func__, mode);
808      (void)self;
809      if (ifName == NULL) {
810          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
811          return HDF_ERR_INVALID_PARAM;
812      }
813      pthread_mutex_lock(&g_interfaceLock);
814      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
815      if (pStaIfc == NULL) {
816          pthread_mutex_unlock(&g_interfaceLock);
817          HDF_LOGE("%{public}s pStaIfc = NULL", __func__);
818          return HDF_FAILURE;
819      }
820      int ret = pStaIfc->wpaCliCmdWpaSetSuspendMode(pStaIfc, mode);
821      if (ret != 0) {
822          pthread_mutex_unlock(&g_interfaceLock);
823          HDF_LOGE("%{public}s: wpaCliCmdWpaSetSuspendMode failed!, ret = %{public}d", __func__, ret);
824          return HDF_FAILURE;
825      }
826      pthread_mutex_unlock(&g_interfaceLock);
827      HDF_LOGI("%{public}s: wpaCliCmdWpaSetSuspendMode success, ret = %{public}d", __func__, ret);
828      return HDF_SUCCESS;
829  }
830  
WpaInterfaceGetConnectionCapabilities(struct IWpaInterface * self,const char * ifName,struct ConnectionCapabilities * connectionCap)831  int32_t WpaInterfaceGetConnectionCapabilities(struct IWpaInterface *self, const char *ifName,
832      struct ConnectionCapabilities *connectionCap)
833  {
834      HDF_LOGI("enter %{public}s: ", __func__);
835      (void)self;
836      if (ifName == NULL || connectionCap == NULL) {
837          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
838          return HDF_ERR_INVALID_PARAM;
839      }
840      pthread_mutex_lock(&g_interfaceLock);
841      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
842      if (pStaIfc == NULL) {
843          pthread_mutex_unlock(&g_interfaceLock);
844          HDF_LOGE("%{public}s pStaIfc = NULL", __func__);
845          return HDF_FAILURE;
846      }
847      int ret = pStaIfc->wpaCliCmdGetConnectionCapabilities(pStaIfc, connectionCap);
848      if (ret != 0) {
849          pthread_mutex_unlock(&g_interfaceLock);
850          HDF_LOGE("%{public}s: wpaCliCmdGetConnectionCapabilities failed!, ret = %{public}d", __func__, ret);
851          return HDF_FAILURE;
852      }
853      pthread_mutex_unlock(&g_interfaceLock);
854      HDF_LOGI("%{public}s: wpaCliCmdGetConnectionCapabilities success, ret = %{public}d", __func__, ret);
855      return HDF_SUCCESS;
856  }
857  
WpaInterfaceGetScanSsid(struct IWpaInterface * self,const char * ifName,int32_t * enable)858  int32_t WpaInterfaceGetScanSsid(struct IWpaInterface *self, const char *ifName, int32_t *enable)
859  {
860      HDF_LOGI("enter %{public}s ", __func__);
861      (void)self;
862      if (ifName == NULL || enable == NULL) {
863          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
864          return HDF_ERR_INVALID_PARAM;
865      }
866      pthread_mutex_lock(&g_interfaceLock);
867      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
868      if (pStaIfc == NULL) {
869          pthread_mutex_unlock(&g_interfaceLock);
870          HDF_LOGE("%{public}s pStaIfc = NULL", __func__);
871          return HDF_FAILURE;
872      }
873      int scanSsid = 0;
874      int ret = pStaIfc->wpaCliCmdGetScanSsid(pStaIfc, &scanSsid);
875      if (ret != 0) {
876          pthread_mutex_unlock(&g_interfaceLock);
877          HDF_LOGE("%{public}s: wpaCliCmdGetScanSsid failed!, ret = %{public}d", __func__, ret);
878          return HDF_FAILURE;
879      }
880      *enable = (scanSsid == 1);
881      pthread_mutex_unlock(&g_interfaceLock);
882      HDF_LOGI("%{public}s: wpaCliCmdGetScanSsid success, scanSsid = %{public}d ", __func__, scanSsid);
883      return HDF_SUCCESS;
884  }
885  
WpaInterfaceGetPskPassphrase(struct IWpaInterface * self,const char * ifName,char * psk,uint32_t pskLen)886  int32_t WpaInterfaceGetPskPassphrase(struct IWpaInterface *self, const char *ifName,
887      char *psk, uint32_t pskLen)
888  {
889      HDF_LOGI("enter %{public}s ", __func__);
890      (void)self;
891      if (ifName == NULL || psk == NULL || pskLen == 0) {
892          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
893          return HDF_ERR_INVALID_PARAM;
894      }
895      pthread_mutex_lock(&g_interfaceLock);
896      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
897      if (pStaIfc == NULL) {
898          pthread_mutex_unlock(&g_interfaceLock);
899          HDF_LOGE("%{public}s pStaIfc = NULL", __func__);
900          return HDF_FAILURE;
901      }
902      int ret = pStaIfc->wpaCliCmdGetPskPassphrase(pStaIfc, psk, pskLen);
903      if (ret < 0) {
904          pthread_mutex_unlock(&g_interfaceLock);
905          HDF_LOGE("%{public}s: wpaCliCmdGetPskPassphrase failed!,ret = %{public}d", __func__, ret);
906          return HDF_FAILURE;
907      }
908      pthread_mutex_unlock(&g_interfaceLock);
909      HDF_LOGI("%{public}s: wpaCliCmdGetPskPassphrase success!,ret = %{public}d", __func__, ret);
910      return HDF_SUCCESS;
911  }
912  
WpaInterfaceGetPsk(struct IWpaInterface * self,const char * ifName,uint8_t * psk,uint32_t * pskLen)913  int32_t WpaInterfaceGetPsk(struct IWpaInterface *self, const char *ifName, uint8_t *psk, uint32_t *pskLen)
914  {
915      HDF_LOGI("enter %{public}s ", __func__);
916      (void)self;
917      if (ifName == NULL || psk == NULL || pskLen == NULL) {
918          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
919          return HDF_ERR_INVALID_PARAM;
920      }
921      pthread_mutex_lock(&g_interfaceLock);
922      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
923      if (pStaIfc == NULL) {
924          pthread_mutex_unlock(&g_interfaceLock);
925          HDF_LOGE("%{public}s pStaIfc = NULL", __func__);
926          return HDF_FAILURE;
927      }
928      int ret = pStaIfc->wpaCliCmdGetPsk(pStaIfc, psk, pskLen);
929      if (ret < 0) {
930          pthread_mutex_unlock(&g_interfaceLock);
931          HDF_LOGE("%{public}s: wpaCliCmdGetPsk failed!,ret = %{public}d", __func__, ret);
932          return HDF_FAILURE;
933      }
934      pthread_mutex_unlock(&g_interfaceLock);
935      HDF_LOGI("%{public}s: wpaCliCmdGetPsk success!,ret = %{public}d", __func__, ret);
936      return HDF_SUCCESS;
937  }
938  
WpaInterfaceGetWepKey(struct IWpaInterface * self,const char * ifName,int keyIdx,uint8_t * wepKey,uint32_t * wepKeyLen)939  int32_t WpaInterfaceGetWepKey(struct IWpaInterface *self, const char *ifName, int keyIdx,
940      uint8_t *wepKey, uint32_t *wepKeyLen)
941  {
942      HDF_LOGI("enter %{public}s keyIdx = %{public}d", __func__, keyIdx);
943      (void)self;
944      if (ifName == NULL || wepKey == NULL || wepKeyLen == NULL) {
945          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
946          return HDF_ERR_INVALID_PARAM;
947      }
948      pthread_mutex_lock(&g_interfaceLock);
949      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
950      if (pStaIfc == NULL) {
951          pthread_mutex_unlock(&g_interfaceLock);
952          HDF_LOGE("%{public}s pStaIfc = NULL", __func__);
953          return HDF_FAILURE;
954      }
955      int ret = pStaIfc->wpaCliCmdWepKey(pStaIfc, keyIdx, wepKey, wepKeyLen);
956      if (ret < 0) {
957          pthread_mutex_unlock(&g_interfaceLock);
958          HDF_LOGE("%{public}s: wpaCliCmdWepKey failed!,ret = %{public}d", __func__, ret);
959          return HDF_FAILURE;
960      }
961      pthread_mutex_unlock(&g_interfaceLock);
962      HDF_LOGI("%{public}s: wpaCliCmdWepKey success!,ret = %{public}d", __func__, ret);
963      return HDF_SUCCESS;
964  }
965  
WpaInterfaceGetWepTxKeyIdx(struct IWpaInterface * self,const char * ifName,int * keyIdx)966  int32_t WpaInterfaceGetWepTxKeyIdx(struct IWpaInterface *self, const char *ifName, int *keyIdx)
967  {
968      HDF_LOGI("enter %{public}s ", __func__);
969      (void)self;
970      if (ifName == NULL || keyIdx == NULL) {
971          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
972          return HDF_ERR_INVALID_PARAM;
973      }
974      pthread_mutex_lock(&g_interfaceLock);
975      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
976      if (pStaIfc == NULL) {
977          pthread_mutex_unlock(&g_interfaceLock);
978          HDF_LOGE("%{public}s pStaIfc = NULL", __func__);
979          return HDF_FAILURE;
980      }
981      int ret = pStaIfc->wpaCliCmdWepKeyTxKeyIdx(pStaIfc, keyIdx);
982      if (ret < 0) {
983          pthread_mutex_unlock(&g_interfaceLock);
984          HDF_LOGE("%{public}s: wpaCliCmdWepKeyTxKeyIdx failed!,ret = %{public}d", __func__, ret);
985          return HDF_FAILURE;
986      }
987      pthread_mutex_unlock(&g_interfaceLock);
988      HDF_LOGI("%{public}s: wpaCliCmdWepKeyTxKeyIdx success!,*keyIdx = %{public}d", __func__, *keyIdx);
989      return HDF_SUCCESS;
990  }
991  
WpaInterfaceGetRequirePmf(struct IWpaInterface * self,const char * ifName,int * enable)992  int32_t WpaInterfaceGetRequirePmf(struct IWpaInterface *self, const char *ifName, int *enable)
993  {
994      HDF_LOGI("enter %{public}s ", __func__);
995      (void)self;
996      if (ifName == NULL || enable == NULL) {
997          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
998          return HDF_ERR_INVALID_PARAM;
999      }
1000      pthread_mutex_lock(&g_interfaceLock);
1001      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
1002      if (pStaIfc == NULL) {
1003          pthread_mutex_unlock(&g_interfaceLock);
1004          HDF_LOGE("%{public}s pStaIfc = NULL", __func__);
1005          return HDF_FAILURE;
1006      }
1007      int ret = pStaIfc->wpaCliCmdGetRequirePmf(pStaIfc, enable);
1008      if (ret != 0) {
1009          pthread_mutex_unlock(&g_interfaceLock);
1010          HDF_LOGE("%{public}s: wpaCliCmdGetRequirePmf failed!, ret=%{public}d", __func__, ret);
1011          return HDF_FAILURE;
1012      }
1013      pthread_mutex_unlock(&g_interfaceLock);
1014      HDF_LOGI("%{public}s: wpaCliCmdGetRequirePmf success, ret=%{public}d  enable=%{public}d ", __func__, ret, *enable);
1015      return HDF_SUCCESS;
1016  }
1017  
WpaInterfaceSetCountryCode(struct IWpaInterface * self,const char * ifName,const char * countryCode)1018  int32_t WpaInterfaceSetCountryCode(struct IWpaInterface *self, const char *ifName, const char *countryCode)
1019  {
1020      HDF_LOGI("enter %{public}s ", __func__);
1021      (void)self;
1022      if (ifName == NULL || countryCode == NULL) {
1023          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1024          return HDF_ERR_INVALID_PARAM;
1025      }
1026      pthread_mutex_lock(&g_interfaceLock);
1027      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
1028      if (pStaIfc == NULL) {
1029          pthread_mutex_unlock(&g_interfaceLock);
1030          HDF_LOGE("%{public}s pStaIfc = NULL", __func__);
1031          return HDF_FAILURE;
1032      }
1033      int ret = pStaIfc->wpaCliCmdSetCountryCode(pStaIfc, countryCode);
1034      if (ret < 0) {
1035          pthread_mutex_unlock(&g_interfaceLock);
1036          HDF_LOGE("%{public}s: wpaCliCmdSetCountryCode failed!, ret = %{public}d", __func__, ret);
1037          return HDF_FAILURE;
1038      }
1039      pthread_mutex_unlock(&g_interfaceLock);
1040      HDF_LOGI("%{public}s: wpaCliCmdSetCountryCode success, ret = %{public}d", __func__, ret);
1041      return HDF_SUCCESS;
1042  }
1043  
OnRemoteServiceDied(struct HdfDeathRecipient * deathRecipient,struct HdfRemoteService * remote)1044  static void OnRemoteServiceDied(struct HdfDeathRecipient *deathRecipient, struct HdfRemoteService *remote)
1045  {
1046      HDF_LOGI("enter %{public}s ", __func__);
1047      WifiWpaInterface *pWpaInterface = GetWifiWpaGlobalInterface();
1048      if (pWpaInterface == NULL) {
1049          HDF_LOGE("%{public}s: Get wpa global interface failed!", __func__);
1050          return;
1051      }
1052      int ret = pWpaInterface->wpaCliTerminate();
1053      if (ret != 0) {
1054          HDF_LOGE("%{public}s: wpaCliTerminate failed!", __func__);
1055      } else {
1056          HDF_LOGI("%{public}s: wpaCliTerminate suc!", __func__);
1057      }
1058      ReleaseWpaGlobalInterface();
1059      HDF_LOGI("%{public}s: call ReleaseWpaGlobalInterface finish", __func__);
1060      ReleaseWifiStaInterface(0);
1061      HDF_LOGI("%{public}s: call ReleaseWifiStaInterface finish", __func__);
1062  }
1063  
1064  static struct RemoteServiceDeathRecipient g_deathRecipient = {
1065      .recipient = {
1066          .OnRemoteDied = OnRemoteServiceDied,
1067      }
1068  };
1069  
AddDeathRecipientForService(struct IWpaCallback * cbFunc)1070  static void AddDeathRecipientForService(struct IWpaCallback *cbFunc)
1071  {
1072      HDF_LOGI("enter %{public}s ", __func__);
1073      if (cbFunc == NULL) {
1074          HDF_LOGE("invalid parameter");
1075          return;
1076      }
1077      struct HdfRemoteService *remote = cbFunc->AsObject(cbFunc);
1078      if (remote == NULL) {
1079          HDF_LOGE("remote is NULL");
1080          return;
1081      }
1082      HdfRemoteServiceAddDeathRecipient(remote, &g_deathRecipient.recipient);
1083  }
1084  
HdfWpaAddRemoteObj(struct IWpaCallback * self,const char * ifName)1085  static int32_t HdfWpaAddRemoteObj(struct IWpaCallback *self, const char *ifName)
1086  {
1087      struct HdfWpaRemoteNode *pos = NULL;
1088      struct DListHead *head = &HdfWpaStubDriver()->remoteListHead;
1089  
1090      if (self == NULL) {
1091          HDF_LOGE("%{public}s:self == NULL", __func__);
1092          return HDF_ERR_INVALID_PARAM;
1093      }
1094      if (!DListIsEmpty(head)) {
1095          DLIST_FOR_EACH_ENTRY(pos, head, struct HdfWpaRemoteNode, node) {
1096              if (pos->service == self->AsObject(self)) {
1097                  HDF_LOGE("%{public}s: pos->service == self", __func__);
1098                  return HDF_FAILURE;
1099              }
1100          }
1101      }
1102      struct HdfWpaRemoteNode *newRemoteNode = (struct HdfWpaRemoteNode *)OsalMemCalloc(sizeof(struct HdfWpaRemoteNode));
1103      if (newRemoteNode == NULL) {
1104          HDF_LOGE("%{public}s:newRemoteNode is NULL", __func__);
1105          return HDF_FAILURE;
1106      }
1107      newRemoteNode->callbackObj = self;
1108      newRemoteNode->service = self->AsObject(self);
1109      DListInsertTail(&newRemoteNode->node, head);
1110      if (strncmp(ifName, "wlan0", strlen("wlan0")) == 0) {
1111          AddDeathRecipientForService(self);
1112      }
1113      return HDF_SUCCESS;
1114  }
1115  
WpaFillWpaDisconnectParam(struct WpaDisconnectParam * disconnectParam,struct HdiWpaDisconnectParam * hdiWpaDisconnectParam)1116  static int32_t WpaFillWpaDisconnectParam(struct WpaDisconnectParam *disconnectParam,
1117      struct HdiWpaDisconnectParam *hdiWpaDisconnectParam)
1118  {
1119      int32_t ret = HDF_SUCCESS;
1120  
1121      if (disconnectParam == NULL || hdiWpaDisconnectParam == NULL) {
1122          HDF_LOGE("%{public}s: disconnectParam or hdiWpaDisconnectParam is NULL!", __func__);
1123          return HDF_ERR_INVALID_PARAM;
1124      }
1125      hdiWpaDisconnectParam->locallyGenerated = disconnectParam->locallyGenerated;
1126      hdiWpaDisconnectParam->reasonCode = disconnectParam->reasonCode;
1127      if (FillData(&hdiWpaDisconnectParam->bssid, &hdiWpaDisconnectParam->bssidLen,
1128          disconnectParam->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) {
1129              HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1130              ret = HDF_FAILURE;
1131      }
1132      if (ret != HDF_SUCCESS) {
1133          if (hdiWpaDisconnectParam->bssid != NULL) {
1134              OsalMemFree(hdiWpaDisconnectParam->bssid);
1135              hdiWpaDisconnectParam->bssid = NULL;
1136          }
1137      }
1138      return ret;
1139  }
1140  
WpaFillWpaConnectParam(struct WpaConnectParam * connectParam,struct HdiWpaConnectParam * hdiWpaConnectParam)1141  static int32_t WpaFillWpaConnectParam(struct WpaConnectParam *connectParam,
1142      struct HdiWpaConnectParam *hdiWpaConnectParam)
1143  {
1144      int32_t ret = HDF_SUCCESS;
1145  
1146      if (connectParam == NULL || hdiWpaConnectParam == NULL) {
1147          HDF_LOGE("%{public}s: connectParam or hdiWpaConnectParam is NULL!", __func__);
1148          return HDF_ERR_INVALID_PARAM;
1149      }
1150      hdiWpaConnectParam->networkId = connectParam->networkId;
1151      if (FillData(&hdiWpaConnectParam->bssid, &hdiWpaConnectParam->bssidLen,
1152          connectParam->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) {
1153              HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1154              ret = HDF_FAILURE;
1155      }
1156      if (ret != HDF_SUCCESS) {
1157          if (hdiWpaConnectParam->bssid != NULL) {
1158              OsalMemFree(hdiWpaConnectParam->bssid);
1159              hdiWpaConnectParam->bssid = NULL;
1160          }
1161      }
1162      return ret;
1163  }
1164  
WpaFillWpaBssidChangedParam(struct WpaBssidChangedParam * bssidChangedParam,struct HdiWpaBssidChangedParam * hdiWpaBssidChangedParam)1165  static int32_t WpaFillWpaBssidChangedParam(struct WpaBssidChangedParam *bssidChangedParam,
1166      struct HdiWpaBssidChangedParam *hdiWpaBssidChangedParam)
1167  {
1168      int32_t ret = HDF_SUCCESS;
1169  
1170      if (bssidChangedParam == NULL || hdiWpaBssidChangedParam == NULL) {
1171          HDF_LOGE("%{public}s: bssidChangedParam or hdiWpaBssidChangedParam is NULL!", __func__);
1172          return HDF_ERR_INVALID_PARAM;
1173      }
1174      do {
1175          if (FillData(&hdiWpaBssidChangedParam->bssid, &hdiWpaBssidChangedParam->bssidLen,
1176              bssidChangedParam->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) {
1177              HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1178              ret = HDF_FAILURE;
1179              break;
1180          }
1181          if (FillData(&hdiWpaBssidChangedParam->reason, &hdiWpaBssidChangedParam->reasonLen,
1182              bssidChangedParam->reason, strlen((char*) bssidChangedParam->reason)) != HDF_SUCCESS) {
1183              HDF_LOGE("%{public}s: fill reason fail!", __func__);
1184              ret = HDF_FAILURE;
1185          }
1186      } while (0);
1187      if (ret != HDF_SUCCESS) {
1188          if (hdiWpaBssidChangedParam->bssid != NULL) {
1189              OsalMemFree(hdiWpaBssidChangedParam->bssid);
1190              hdiWpaBssidChangedParam->bssid = NULL;
1191          }
1192          if (hdiWpaBssidChangedParam->reason != NULL) {
1193              OsalMemFree(hdiWpaBssidChangedParam->reason);
1194              hdiWpaBssidChangedParam->reason = NULL;
1195          }
1196      }
1197      return ret;
1198  }
1199  
WpaFillWpaStateChangedParam(struct WpaStateChangedParam * stateChangedParam,struct HdiWpaStateChangedParam * hdiWpaStateChangedParam)1200  static int32_t WpaFillWpaStateChangedParam(struct WpaStateChangedParam *stateChangedParam,
1201      struct HdiWpaStateChangedParam *hdiWpaStateChangedParam)
1202  {
1203      int32_t ret = HDF_SUCCESS;
1204  
1205      if (stateChangedParam == NULL || hdiWpaStateChangedParam == NULL) {
1206          HDF_LOGE("%{public}s: stateChangedParam or hdiWpaStateChangedParam is NULL!", __func__);
1207          return HDF_ERR_INVALID_PARAM;
1208      }
1209      hdiWpaStateChangedParam->networkId = stateChangedParam->networkId;
1210      HDF_LOGD("%{public}s: hdiWpaStateChangedParam->networkId =%d", __func__, hdiWpaStateChangedParam->networkId);
1211      hdiWpaStateChangedParam->status = stateChangedParam->status;
1212      HDF_LOGD("%{public}s: hdiWpaStateChangedParam->status =%d", __func__, hdiWpaStateChangedParam->status);
1213      do {
1214          HDF_LOGD("%{public}s: stateChangedParam->bssid[0] = %x", __func__, stateChangedParam->bssid[0]);
1215          HDF_LOGD("%{public}s: stateChangedParam->bssid[5] = %x", __func__,
1216              stateChangedParam->bssid[WIFI_BSSID_LEN - 1]);
1217          if (FillData(&hdiWpaStateChangedParam->bssid, &hdiWpaStateChangedParam->bssidLen,
1218              stateChangedParam->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) {
1219              HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1220              ret = HDF_FAILURE;
1221              break;
1222          }
1223          HDF_LOGD("%{public}s: stateChangedParam->ssid[0] = %x", __func__, stateChangedParam->ssid[0]);
1224          HDF_LOGD("%{public}s: stateChangedParam->ssid[WIFI_SSID_LENGTH-1] = %x", __func__,
1225              stateChangedParam->ssid[WIFI_SSID_LENGTH - 1]);
1226          if (memcmp(stateChangedParam->ssid, "\0", 1) == 0) {
1227              hdiWpaStateChangedParam->ssidLen = 0;
1228              HDF_LOGE("%{public}s: hdiWpaStateChangedParam->ssidLen =%d", __func__, hdiWpaStateChangedParam->ssidLen);
1229          } else {
1230              if (FillData(&hdiWpaStateChangedParam->ssid, &hdiWpaStateChangedParam->ssidLen,
1231              stateChangedParam->ssid, strlen((char*)stateChangedParam->ssid)) != HDF_SUCCESS) {
1232              HDF_LOGE("%{public}s: fill ssid fail!", __func__);
1233              ret = HDF_FAILURE;
1234              }
1235          }
1236      } while (0);
1237      if (ret != HDF_SUCCESS) {
1238          if (hdiWpaStateChangedParam->bssid != NULL) {
1239              OsalMemFree(hdiWpaStateChangedParam->bssid);
1240              hdiWpaStateChangedParam->bssid = NULL;
1241          }
1242          if (hdiWpaStateChangedParam->ssid != NULL) {
1243              OsalMemFree(hdiWpaStateChangedParam->ssid);
1244              hdiWpaStateChangedParam->ssid = NULL;
1245          }
1246      }
1247      return ret;
1248  }
1249  
WpaFillWpaTempDisabledParam(struct WpaTempDisabledParam * tempDisabledParam,struct HdiWpaTempDisabledParam * hdiWpaTempDisabledParam)1250  static int32_t WpaFillWpaTempDisabledParam(struct WpaTempDisabledParam *tempDisabledParam,
1251      struct HdiWpaTempDisabledParam *hdiWpaTempDisabledParam)
1252  {
1253      int32_t ret = HDF_SUCCESS;
1254  
1255      if (tempDisabledParam == NULL || hdiWpaTempDisabledParam == NULL) {
1256          HDF_LOGE("%{public}s: tempDisabledParam or hdiWpaTempDisabledParam is NULL!", __func__);
1257          return HDF_ERR_INVALID_PARAM;
1258      }
1259      hdiWpaTempDisabledParam->networkId = tempDisabledParam->networkId;
1260      hdiWpaTempDisabledParam->authFailures = tempDisabledParam->authFailures;
1261      hdiWpaTempDisabledParam->duration = tempDisabledParam->duration;
1262      do {
1263          if (FillData(&hdiWpaTempDisabledParam->reason, &hdiWpaTempDisabledParam->reasonLen,
1264              tempDisabledParam->reason, strlen((char*)tempDisabledParam->reason)) != HDF_SUCCESS) {
1265              HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1266              ret = HDF_FAILURE;
1267              break;
1268          }
1269          if (FillData(&hdiWpaTempDisabledParam->ssid, &hdiWpaTempDisabledParam->ssidLen,
1270              tempDisabledParam->ssid, strlen((char*)tempDisabledParam->ssid)) != HDF_SUCCESS) {
1271              HDF_LOGE("%{public}s: fill ssid fail!", __func__);
1272              ret = HDF_FAILURE;
1273          }
1274      } while (0);
1275      if (ret != HDF_SUCCESS) {
1276          if (hdiWpaTempDisabledParam->reason != NULL) {
1277              OsalMemFree(hdiWpaTempDisabledParam->reason);
1278              hdiWpaTempDisabledParam->reason = NULL;
1279          }
1280          if (hdiWpaTempDisabledParam->ssid != NULL) {
1281              OsalMemFree(hdiWpaTempDisabledParam->ssid);
1282              hdiWpaTempDisabledParam->ssid = NULL;
1283          }
1284      }
1285      return ret;
1286  }
1287  
WpaFillWpaAssociateRejectParam(struct WpaAssociateRejectParam * associateRejectParam,struct HdiWpaAssociateRejectParam * hdiWpaAssociateRejectParam)1288  static int32_t WpaFillWpaAssociateRejectParam(struct WpaAssociateRejectParam *associateRejectParam,
1289      struct HdiWpaAssociateRejectParam *hdiWpaAssociateRejectParam)
1290  {
1291      int32_t ret = HDF_SUCCESS;
1292  
1293      if (associateRejectParam == NULL || hdiWpaAssociateRejectParam == NULL) {
1294          HDF_LOGE("%{public}s: associateRejectParam or hdiWpaAssociateRejectParam is NULL!", __func__);
1295          return HDF_ERR_INVALID_PARAM;
1296      }
1297      hdiWpaAssociateRejectParam->statusCode = associateRejectParam->statusCode;
1298      hdiWpaAssociateRejectParam->timeOut = associateRejectParam->timeOut;
1299      if (FillData(&hdiWpaAssociateRejectParam->bssid, &hdiWpaAssociateRejectParam->bssidLen,
1300          associateRejectParam->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) {
1301              HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1302              ret = HDF_FAILURE;
1303      }
1304      if (ret != HDF_SUCCESS) {
1305          if (hdiWpaAssociateRejectParam->bssid != NULL) {
1306              OsalMemFree(hdiWpaAssociateRejectParam->bssid);
1307              hdiWpaAssociateRejectParam->bssid = NULL;
1308          }
1309      }
1310      return ret;
1311  }
1312  
WpaFillWpaRecvScanResultParam(struct WpaRecvScanResultParam * recvScanResultParam,struct HdiWpaRecvScanResultParam * hdiWpaRecvScanResultParam)1313  static int32_t WpaFillWpaRecvScanResultParam(struct WpaRecvScanResultParam *recvScanResultParam,
1314      struct HdiWpaRecvScanResultParam *hdiWpaRecvScanResultParam)
1315  {
1316      int32_t ret = HDF_SUCCESS;
1317  
1318      if (recvScanResultParam == NULL || hdiWpaRecvScanResultParam == NULL) {
1319          HDF_LOGE("%{public}s: recvScanResultParam or hdiWpaRecvScanResultParam is NULL!", __func__);
1320          return HDF_ERR_INVALID_PARAM;
1321      }
1322      hdiWpaRecvScanResultParam->scanId = recvScanResultParam->scanId;
1323      return ret;
1324  }
1325  
WpaFillWpaAuthRejectParam(struct WpaAuthRejectParam * authRejectParam,struct HdiWpaAuthRejectParam * hdiWpaAuthRejectParam)1326  static int32_t WpaFillWpaAuthRejectParam(struct WpaAuthRejectParam *authRejectParam,
1327      struct HdiWpaAuthRejectParam *hdiWpaAuthRejectParam)
1328  {
1329      int32_t ret = HDF_SUCCESS;
1330  
1331      if (authRejectParam == NULL || hdiWpaAuthRejectParam == NULL) {
1332          HDF_LOGE("%{public}s: authRejectParam or hdiWpaAuthRejectParam is NULL!", __func__);
1333          return HDF_ERR_INVALID_PARAM;
1334      }
1335      hdiWpaAuthRejectParam->statusCode = authRejectParam->statusCode;
1336      hdiWpaAuthRejectParam->authType = authRejectParam->authType;
1337      hdiWpaAuthRejectParam->authTransaction = authRejectParam->authTransaction;
1338      if (FillData(&hdiWpaAuthRejectParam->bssid, &hdiWpaAuthRejectParam->bssidLen,
1339          authRejectParam->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) {
1340              HDF_LOGE("%{public}s: fill bssid fail!", __func__);
1341              ret = HDF_FAILURE;
1342      }
1343      if (ret != HDF_SUCCESS) {
1344          if (hdiWpaAuthRejectParam->bssid != NULL) {
1345              OsalMemFree(hdiWpaAuthRejectParam->bssid);
1346              hdiWpaAuthRejectParam->bssid = NULL;
1347          }
1348      }
1349      return ret;
1350  }
1351  
ProcessEventWpaDisconnect(struct HdfWpaRemoteNode * node,struct WpaDisconnectParam * disconnectParam,const char * ifName)1352  static int32_t ProcessEventWpaDisconnect(struct HdfWpaRemoteNode *node,
1353      struct WpaDisconnectParam *disconnectParam, const char *ifName)
1354  {
1355      struct HdiWpaDisconnectParam *hdiWpaDisconnectParam = NULL;
1356      int32_t ret = HDF_FAILURE;
1357  
1358      if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventDisconnected == NULL) {
1359          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1360          return HDF_ERR_INVALID_PARAM;
1361      }
1362      hdiWpaDisconnectParam = (struct HdiWpaDisconnectParam *)OsalMemCalloc(sizeof(struct HdiWpaDisconnectParam));
1363      if ((hdiWpaDisconnectParam == NULL) || (WpaFillWpaDisconnectParam(disconnectParam,
1364          hdiWpaDisconnectParam) != HDF_SUCCESS)) {
1365          HDF_LOGE("%{public}s: hdiWpaDisconnectParam is NULL or disconnectParam fialed!", __func__);
1366      } else {
1367          ret = node->callbackObj->OnEventDisconnected(node->callbackObj, hdiWpaDisconnectParam, ifName);
1368      }
1369      HdiWpaDisconnectParamFree(hdiWpaDisconnectParam, true);
1370      return ret;
1371  }
1372  
ProcessEventWpaConnect(struct HdfWpaRemoteNode * node,struct WpaConnectParam * connectParam,const char * ifName)1373  static int32_t ProcessEventWpaConnect(struct HdfWpaRemoteNode *node,
1374      struct WpaConnectParam *connectParam, const char *ifName)
1375  {
1376      struct HdiWpaConnectParam *hdiWpaConnectParam = NULL;
1377      int32_t ret = HDF_FAILURE;
1378  
1379      if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventConnected == NULL) {
1380          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1381          return HDF_ERR_INVALID_PARAM;
1382      }
1383      hdiWpaConnectParam = (struct HdiWpaConnectParam *)OsalMemCalloc(sizeof(struct HdiWpaConnectParam));
1384      if ((hdiWpaConnectParam == NULL) || (WpaFillWpaConnectParam(connectParam, hdiWpaConnectParam) != HDF_SUCCESS)) {
1385          HDF_LOGE("%{public}s: HdiWpaConnectParam is NULL or connectParam fialed!", __func__);
1386      } else {
1387          ret = node->callbackObj->OnEventConnected(node->callbackObj, hdiWpaConnectParam, ifName);
1388      }
1389      HdiWpaConnectParamFree(hdiWpaConnectParam, true);
1390      return ret;
1391  }
1392  
ProcessEventWpaBssidChange(struct HdfWpaRemoteNode * node,struct WpaBssidChangedParam * bssidChangeParam,const char * ifName)1393  static int32_t ProcessEventWpaBssidChange(struct HdfWpaRemoteNode *node,
1394      struct WpaBssidChangedParam *bssidChangeParam, const char *ifName)
1395  {
1396      struct HdiWpaBssidChangedParam *hdiWpaBssidChangedParam = NULL;
1397      int32_t ret = HDF_FAILURE;
1398      if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventBssidChanged == NULL) {
1399          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1400          return HDF_ERR_INVALID_PARAM;
1401      }
1402      hdiWpaBssidChangedParam = (struct HdiWpaBssidChangedParam *)OsalMemCalloc(sizeof(struct HdiWpaBssidChangedParam));
1403      if ((hdiWpaBssidChangedParam == NULL) || (WpaFillWpaBssidChangedParam(bssidChangeParam,
1404          hdiWpaBssidChangedParam) != HDF_SUCCESS)) {
1405          HDF_LOGE("%{public}s: hdiWpaBssidChangedParam is NULL or bssidChangeParam fialed!", __func__);
1406      } else {
1407          ret = node->callbackObj->OnEventBssidChanged(node->callbackObj, hdiWpaBssidChangedParam, ifName);
1408      }
1409      HdiWpaBssidChangedParamFree(hdiWpaBssidChangedParam, true);
1410      return ret;
1411  }
1412  
ProcessEventWpaStateChange(struct HdfWpaRemoteNode * node,struct WpaStateChangedParam * stateChangeParam,const char * ifName)1413  static int32_t ProcessEventWpaStateChange(struct HdfWpaRemoteNode *node,
1414      struct WpaStateChangedParam *stateChangeParam, const char *ifName)
1415  {
1416      struct HdiWpaStateChangedParam *hdiWpaStateChangedParam = NULL;
1417      int32_t ret = HDF_FAILURE;
1418  
1419      if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventStateChanged == NULL) {
1420          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1421          return HDF_ERR_INVALID_PARAM;
1422      }
1423      hdiWpaStateChangedParam = (struct HdiWpaStateChangedParam *)OsalMemCalloc(sizeof(struct HdiWpaStateChangedParam));
1424      if ((hdiWpaStateChangedParam == NULL) || (WpaFillWpaStateChangedParam(stateChangeParam,
1425          hdiWpaStateChangedParam) != HDF_SUCCESS)) {
1426          HDF_LOGE("%{public}s: hdiWpaStateChangedParam is NULL or stateChangeParam fialed!", __func__);
1427      } else {
1428          ret = node->callbackObj->OnEventStateChanged(node->callbackObj, hdiWpaStateChangedParam, ifName);
1429      }
1430      HdiWpaStateChangedParamFree(hdiWpaStateChangedParam, true);
1431      return ret;
1432  }
1433  
ProcessEventWpaTempDisable(struct HdfWpaRemoteNode * node,struct WpaTempDisabledParam * tempDisabledParam,const char * ifName)1434  static int32_t ProcessEventWpaTempDisable(struct HdfWpaRemoteNode *node,
1435      struct WpaTempDisabledParam *tempDisabledParam, const char *ifName)
1436  {
1437      struct HdiWpaTempDisabledParam *hdiWpaTempDisabledParam = NULL;
1438      int32_t ret = HDF_FAILURE;
1439  
1440      if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventTempDisabled == NULL) {
1441          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1442          return HDF_ERR_INVALID_PARAM;
1443      }
1444      hdiWpaTempDisabledParam = (struct HdiWpaTempDisabledParam *)OsalMemCalloc(sizeof(struct HdiWpaTempDisabledParam));
1445      if ((hdiWpaTempDisabledParam == NULL) || (WpaFillWpaTempDisabledParam(tempDisabledParam,
1446          hdiWpaTempDisabledParam) != HDF_SUCCESS)) {
1447          HDF_LOGE("%{public}s: hdiWpaTempDisabledParam is NULL or tempDisabledParam fialed!", __func__);
1448      } else {
1449          ret = node->callbackObj->OnEventTempDisabled(node->callbackObj, hdiWpaTempDisabledParam, ifName);
1450      }
1451      HdiWpaTempDisabledParamFree(hdiWpaTempDisabledParam, true);
1452      return ret;
1453  }
1454  
ProcessEventWpaAssociateReject(struct HdfWpaRemoteNode * node,struct WpaAssociateRejectParam * associateRejectParam,const char * ifName)1455  static int32_t ProcessEventWpaAssociateReject(struct HdfWpaRemoteNode *node,
1456      struct WpaAssociateRejectParam *associateRejectParam, const char *ifName)
1457  {
1458      struct HdiWpaAssociateRejectParam *hdiWpaAssociateRejectParam = NULL;
1459      int32_t ret = HDF_FAILURE;
1460  
1461      if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventAssociateReject == NULL) {
1462          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1463          return HDF_ERR_INVALID_PARAM;
1464      }
1465      hdiWpaAssociateRejectParam = (struct HdiWpaAssociateRejectParam *)
1466          OsalMemCalloc(sizeof(struct HdiWpaAssociateRejectParam));
1467      if ((hdiWpaAssociateRejectParam == NULL) || (WpaFillWpaAssociateRejectParam(associateRejectParam,
1468          hdiWpaAssociateRejectParam) != HDF_SUCCESS)) {
1469          HDF_LOGE("%{public}s: hdiWpaAssociateRejectParam is NULL or associateRejectParam fialed!", __func__);
1470      } else {
1471          ret = node->callbackObj->OnEventAssociateReject(node->callbackObj, hdiWpaAssociateRejectParam, ifName);
1472      }
1473      HdiWpaAssociateRejectParamFree(hdiWpaAssociateRejectParam, true);
1474      return ret;
1475  }
1476  
ProcessEventWpaWpsOverlap(struct HdfWpaRemoteNode * node,const char * ifName)1477  static int32_t ProcessEventWpaWpsOverlap(struct HdfWpaRemoteNode *node,
1478       const char *ifName)
1479  {
1480      int32_t ret = HDF_FAILURE;
1481  
1482      if (node == NULL || node->callbackObj == NULL) {
1483          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1484          return HDF_ERR_INVALID_PARAM;
1485      }
1486      ret = node->callbackObj->OnEventWpsOverlap(node->callbackObj, ifName);
1487      return ret;
1488  }
1489  
ProcessEventWpaWpsTimeout(struct HdfWpaRemoteNode * node,const char * ifName)1490  static int32_t ProcessEventWpaWpsTimeout(struct HdfWpaRemoteNode *node,
1491       const char *ifName)
1492  {
1493      int32_t ret = HDF_FAILURE;
1494  
1495      if (node == NULL || node->callbackObj == NULL) {
1496          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1497          return HDF_ERR_INVALID_PARAM;
1498      }
1499      ret = node->callbackObj->OnEventWpsTimeout(node->callbackObj, ifName);
1500      return ret;
1501  }
1502  
ProcessEventWpaAuthTimeout(struct HdfWpaRemoteNode * node,const char * ifName)1503  static int32_t ProcessEventWpaAuthTimeout(struct HdfWpaRemoteNode *node, const char *ifName)
1504  {
1505      int32_t ret = HDF_FAILURE;
1506      if (node == NULL || node->callbackObj == NULL) {
1507          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1508          return HDF_ERR_INVALID_PARAM;
1509      }
1510      ret = node->callbackObj->OnEventAuthTimeout(node->callbackObj, ifName);
1511      return ret;
1512  }
1513  
ProcessEventWpaRecvScanResult(struct HdfWpaRemoteNode * node,struct WpaRecvScanResultParam * recvScanResultParam,const char * ifName)1514  static int32_t ProcessEventWpaRecvScanResult(struct HdfWpaRemoteNode *node,
1515      struct WpaRecvScanResultParam *recvScanResultParam, const char *ifName)
1516  {
1517      struct HdiWpaRecvScanResultParam *hdiRecvScanResultParam = NULL;
1518      int32_t ret = HDF_FAILURE;
1519  
1520      if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventScanResult == NULL) {
1521          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1522          return HDF_ERR_INVALID_PARAM;
1523      }
1524      hdiRecvScanResultParam  = (struct HdiWpaRecvScanResultParam *)
1525          OsalMemCalloc(sizeof(struct HdiWpaRecvScanResultParam));
1526      if ((hdiRecvScanResultParam == NULL) || (WpaFillWpaRecvScanResultParam(recvScanResultParam,
1527          hdiRecvScanResultParam) != HDF_SUCCESS)) {
1528          HDF_LOGE("%{public}s: hdiWpaAssociateRejectParam is NULL or associateRejectParam fialed!", __func__);
1529      } else {
1530          ret = node->callbackObj->OnEventScanResult(node->callbackObj, hdiRecvScanResultParam, ifName);
1531      }
1532      HdiWpaRecvScanResultParamFree(hdiRecvScanResultParam, true);
1533      return ret;
1534  }
1535  
ProcessEventWpaAuthReject(struct HdfWpaRemoteNode * node,struct WpaAuthRejectParam * authRejectParam,const char * ifName)1536  static int32_t ProcessEventWpaAuthReject(
1537      struct HdfWpaRemoteNode *node, struct WpaAuthRejectParam *authRejectParam, const char *ifName)
1538  {
1539      struct HdiWpaAuthRejectParam *hdiWpaAuthRejectParam = NULL;
1540      int32_t ret = HDF_FAILURE;
1541  
1542      if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventAuthReject == NULL) {
1543          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1544          return HDF_ERR_INVALID_PARAM;
1545      }
1546      hdiWpaAuthRejectParam =
1547          (struct HdiWpaAuthRejectParam *)OsalMemCalloc(sizeof(struct HdiWpaAuthRejectParam));
1548      if ((hdiWpaAuthRejectParam == NULL) ||
1549          (WpaFillWpaAuthRejectParam(authRejectParam, hdiWpaAuthRejectParam) != HDF_SUCCESS)) {
1550          HDF_LOGE("%{public}s: hdiWpaAuthRejectParam is NULL or authRejectParam fialed!", __func__);
1551      } else {
1552          ret = node->callbackObj->OnEventAuthReject(node->callbackObj, hdiWpaAuthRejectParam, ifName);
1553      }
1554      HdiWpaAuthRejectParamFree(hdiWpaAuthRejectParam, true);
1555      return ret;
1556  }
1557  
ProcessEventStaNotify(struct HdfWpaRemoteNode * node,char * notifyParam,const char * ifName)1558  int32_t ProcessEventStaNotify(struct HdfWpaRemoteNode *node, char *notifyParam, const char *ifName)
1559  {
1560      int32_t ret = HDF_FAILURE;
1561      if (notifyParam == NULL || ifName == NULL) {
1562          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1563          return HDF_FAILURE;
1564      }
1565      char *notifyStr = (char*)malloc(BUF_SIZE);
1566      if (notifyStr == NULL) {
1567          HDF_LOGE("%{public}s notifyStr malloc failed", __func__);
1568          return HDF_FAILURE;
1569      }
1570      if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventStaNotify == NULL) {
1571          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1572          free(notifyStr);
1573          return HDF_ERR_INVALID_PARAM;
1574      }
1575      if (memset_s(notifyStr, BUF_SIZE, 0, BUF_SIZE) != EOK) {
1576          HDF_LOGE("%{public}s memset failed", __func__);
1577          free(notifyStr);
1578          return HDF_FAILURE;
1579      }
1580      if (strcpy_s(notifyStr, BUF_SIZE, notifyParam) != EOK) {
1581          HDF_LOGE("%{public}s strcpy failed", __func__);
1582          free(notifyStr);
1583          return HDF_FAILURE;
1584      }
1585      ret = node->callbackObj->OnEventStaNotify(node->callbackObj, notifyStr, ifName);
1586      free(notifyStr);
1587      return ret;
1588  }
1589  
WpaFillWpaVendorExtInfo(struct WpaVendorExtInfo * wpaVendorExtInfo,struct WpaVendorInfo * wpaVendorInfo)1590  static int32_t WpaFillWpaVendorExtInfo(struct WpaVendorExtInfo *wpaVendorExtInfo,
1591                                         struct WpaVendorInfo *wpaVendorInfo)
1592  {
1593      if (wpaVendorExtInfo == NULL || wpaVendorInfo == NULL) {
1594          HDF_LOGE("%{public}s: wpaVendorExtInfo or wpaVendorInfo is NULL!", __func__);
1595          return HDF_ERR_INVALID_PARAM;
1596      }
1597      wpaVendorInfo->data = NULL;
1598      wpaVendorInfo->type = wpaVendorExtInfo->type;
1599      wpaVendorInfo->freq = wpaVendorExtInfo->freq;
1600      wpaVendorInfo->width = wpaVendorExtInfo->width;
1601      wpaVendorInfo->id = wpaVendorExtInfo->id;
1602      wpaVendorInfo->status = wpaVendorExtInfo->status;
1603      wpaVendorInfo->reason = wpaVendorExtInfo->reason;
1604      if (FillData(&wpaVendorInfo->ssid, &wpaVendorInfo->ssidLen,
1605                   wpaVendorExtInfo->ssid, strlen((char *)wpaVendorExtInfo->ssid)) != EOK) {
1606          HDF_LOGE("%{public}s: memcpy_s ssid fail !", __func__);
1607          return HDF_FAILURE;
1608      }
1609  
1610      if (FillData(&wpaVendorInfo->psk, &wpaVendorInfo->pskLen,
1611                   wpaVendorExtInfo->psk, strlen((char *)wpaVendorExtInfo->psk)) != EOK) {
1612          HDF_LOGE("%{public}s: memcpy_s psk fail !", __func__);
1613          return HDF_FAILURE;
1614      }
1615  
1616      if (FillData(&wpaVendorInfo->devAddr, &wpaVendorInfo->devAddrLen,
1617                   wpaVendorExtInfo->devAddr, ETH_ADDR_LEN) != EOK) {
1618          HDF_LOGE("%{public}s: memcpy_s devAddr fail !", __func__);
1619          return HDF_FAILURE;
1620      }
1621  
1622      if (FillData(&wpaVendorInfo->data, &wpaVendorInfo->dataLen,
1623                   wpaVendorExtInfo->data, strlen((char *)wpaVendorExtInfo->data)) != EOK) {
1624          HDF_LOGE("%{public}s: memcpy_s data fail !", __func__);
1625          return HDF_FAILURE;
1626      }
1627  
1628      HDF_LOGI("wpaVendorInfo type %{public}d, freq %{public}d, reason %{public}d, "
1629               "id %{public}d status %{public}d!",
1630               wpaVendorInfo->type, wpaVendorInfo->freq, wpaVendorInfo->reason,
1631               wpaVendorInfo->id, wpaVendorInfo->status);
1632      return HDF_SUCCESS;
1633  }
1634  
ProcessEventWpaVendorExt(struct HdfWpaRemoteNode * node,struct WpaVendorExtInfo * wpaVendorExtInfo,const char * ifName)1635  static int32_t ProcessEventWpaVendorExt(struct HdfWpaRemoteNode *node,
1636      struct WpaVendorExtInfo *wpaVendorExtInfo, const char *ifName)
1637  {
1638      HDF_LOGI("%{public}s: ifName => %{public}s ; ", __func__, ifName);
1639      struct WpaVendorInfo wpaVendorInfo;
1640      int32_t ret = HDF_FAILURE;
1641      if (wpaVendorExtInfo == NULL) {
1642          HDF_LOGE("%{public}s: wpaVendorExtInfo is NULL !", __func__);
1643          return HDF_ERR_INVALID_PARAM;
1644      }
1645  
1646      if (node == NULL || node->callbackObj == NULL || node->callbackObj->OnEventVendorCb == NULL) {
1647          HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
1648          return HDF_ERR_INVALID_PARAM;
1649      }
1650  
1651      if (WpaFillWpaVendorExtInfo(wpaVendorExtInfo, &wpaVendorInfo) != HDF_SUCCESS) {
1652          ret = HDF_FAILURE;
1653          HDF_LOGE("%{public}s: wpaVendorInfo is NULL or associateRejectParam fialed!", __func__);
1654      } else {
1655          ret = node->callbackObj->OnEventVendorCb(node->callbackObj, &wpaVendorInfo, ifName);
1656      }
1657      HDF_LOGI("%{public}s: res %{public}d!", __func__, ret);
1658      return ret;
1659  }
HdfStaDealEvent(uint32_t event,struct HdfWpaRemoteNode * pos,void * data,const char * ifName)1660  static int32_t HdfStaDealEvent(uint32_t event, struct HdfWpaRemoteNode *pos, void *data, const char *ifName)
1661  {
1662      int32_t ret = HDF_FAILURE;
1663      switch (event) {
1664          case WPA_EVENT_DISCONNECT:
1665              ret = ProcessEventWpaDisconnect(pos, (struct WpaDisconnectParam *)data, ifName);
1666              break;
1667          case WPA_EVENT_CONNECT:
1668              ret = ProcessEventWpaConnect(pos, (struct WpaConnectParam *)data, ifName);
1669              break;
1670          case WPA_EVENT_BSSID_CHANGE:
1671              ret = ProcessEventWpaBssidChange(pos, (struct WpaBssidChangedParam *)data, ifName);
1672              break;
1673          case WPA_EVENT_STATE_CHANGED:
1674              ret = ProcessEventWpaStateChange(pos, (struct WpaStateChangedParam *)data, ifName);
1675              break;
1676          case WPA_EVENT_TEMP_DISABLE:
1677              ret = ProcessEventWpaTempDisable(pos, (struct WpaTempDisabledParam *)data, ifName);
1678              break;
1679          case WPA_EVENT_ASSOCIATE_REJECT:
1680              ret = ProcessEventWpaAssociateReject(pos, (struct WpaAssociateRejectParam *)data, ifName);
1681              break;
1682          case WPA_EVENT_WPS_OVERLAP:
1683              ret = ProcessEventWpaWpsOverlap(pos, ifName);
1684              break;
1685          case WPA_EVENT_WPS_TIMEMOUT:
1686              ret = ProcessEventWpaWpsTimeout(pos, ifName);
1687              break;
1688          case WPA_EVENT_AUTH_TIMEOUT:
1689              ProcessEventWpaAuthTimeout(pos, ifName);
1690              break;
1691          case WPA_EVENT_RECV_SCAN_RESULT:
1692              ret = ProcessEventWpaRecvScanResult(pos, (struct WpaRecvScanResultParam *)data, ifName);
1693              break;
1694          case WPA_EVENT_STA_AUTH_REJECT:
1695              ret = ProcessEventWpaAuthReject(pos, (struct WpaAuthRejectParam *)data, ifName);
1696              break;
1697          case WPA_EVENT_STA_NOTIFY:
1698              ret = ProcessEventStaNotify(pos, (char *)data, ifName);
1699              break;
1700          default:
1701              HDF_LOGE("%{public}s: unknown eventId:%{public}d", __func__, event);
1702              break;
1703      }
1704      return ret;
1705  }
1706  
HdfP2pDealEvent(uint32_t event,struct HdfWpaRemoteNode * pos,void * data,const char * ifName)1707  static int32_t HdfP2pDealEvent(uint32_t event, struct HdfWpaRemoteNode *pos, void *data, const char *ifName)
1708  {
1709      int32_t ret = HDF_FAILURE;
1710      switch (event) {
1711          case WPA_EVENT_DEVICE_FOUND:
1712              ret = ProcessEventP2pDeviceFound(pos, (struct P2pDeviceInfoParam *)data, ifName);
1713              break;
1714          case WPA_EVENT_DEVICE_LOST:
1715              ret = ProcessEventP2pDeviceLost(pos, (struct P2pDeviceLostParam *)data, ifName);
1716              break;
1717          case WPA_EVENT_GO_NEGOTIATION_REQUEST:
1718              ret = ProcessEventP2pGoNegotiationRequest(pos, (struct P2pGoNegotiationRequestParam *)data, ifName);
1719              break;
1720          case WPA_EVENT_GO_NEGOTIATION_COMPLETED:
1721              ret = ProcessEventP2pGoNegotiationCompleted(pos, (struct P2pGoNegotiationCompletedParam *)data, ifName);
1722              break;
1723          case WPA_EVENT_INVITATION_RECEIVED:
1724              ret = ProcessEventP2pInvitationReceived(pos, (struct P2pInvitationReceivedParam *)data, ifName);
1725              break;
1726          case WPA_EVENT_INVITATION_RESULT:
1727              ret = ProcessEventP2pInvitationResult(pos, (struct P2pInvitationResultParam *)data, ifName);
1728              break;
1729          case WPA_EVENT_GROUP_FORMATION_SUCCESS:
1730              ret = ProcessEventP2pGroupFormationSuccess(pos, ifName);
1731              break;
1732          case WPA_EVENT_GROUP_FORMATION_FAILURE:
1733              ret = ProcessEventP2pGroupFormationFailure(pos, (char *)data, ifName);
1734              break;
1735          case WPA_EVENT_GROUP_START:
1736              ret = ProcessEventP2pGroupStarted(pos, (struct P2pGroupStartedParam *)data, ifName);
1737              break;
1738          case WPA_EVENT_GROUP_REMOVED:
1739              ret = ProcessEventP2pGroupRemoved(pos, (struct P2pGroupRemovedParam *)data, ifName);
1740              break;
1741          case WPA_EVENT_PROVISION_DISCOVERY_COMPLETED:
1742              ret = ProcessEventP2pProvisionDiscoveryCompleted(pos, (struct P2pProvisionDiscoveryCompletedParam *)data,
1743                  ifName);
1744              break;
1745          case WPA_EVENT_FIND_STOPPED:
1746              ret = ProcessEventP2pFindStopped(pos, ifName);
1747              break;
1748          case WPA_EVENT_SERV_DISC_REQ:
1749              ret = ProcessEventP2pServDiscReq(pos, (struct P2pServDiscReqInfoParam *)data, ifName);
1750              break;
1751          case WPA_EVENT_SERV_DISC_RESP:
1752              ret = ProcessEventP2pServDiscResp(pos, (struct P2pServDiscRespParam *)data, ifName);
1753              break;
1754          case WPA_EVENT_STA_CONNECT_STATE:
1755              ret = ProcessEventP2pStaConnectState(pos, (struct P2pStaConnectStateParam *)data, ifName);
1756              break;
1757          case WPA_EVENT_IFACE_CREATED:
1758              ret = ProcessEventP2pIfaceCreated(pos, (struct P2pIfaceCreatedParam *)data, ifName);
1759              break;
1760          case WPA_EVENT_STA_NOTIFY:
1761              ret = ProcessEventStaNotify(pos, (char *)data, ifName);
1762              break;
1763          default:
1764              HDF_LOGE("%{public}s: unknown eventId:%{public}d", __func__, event);
1765              break;
1766      }
1767      return ret;
1768  }
1769  
HdfVendorExtDealEvent(uint32_t event,struct HdfWpaRemoteNode * pos,void * data,const char * ifName)1770  static int32_t HdfVendorExtDealEvent(uint32_t event, struct HdfWpaRemoteNode *pos, void *data, const char *ifName)
1771  {
1772      int32_t ret = HDF_FAILURE;
1773      switch (event) {
1774          case WPA_EVENT_VENDOR_EXT:
1775              ret = ProcessEventWpaVendorExt(pos, (struct WpaVendorExtInfo *)data, ifName);
1776              break;
1777          default:
1778              HDF_LOGE("%{public}s: unknown eventId:%{public}d", __func__, event);
1779              break;
1780      }
1781      return ret;
1782  }
1783  
1784  
HdfWpaCallbackFun(uint32_t event,void * data,const char * ifName)1785  static int32_t HdfWpaCallbackFun(uint32_t event, void *data, const char *ifName)
1786  {
1787      struct HdfWpaRemoteNode *pos = NULL;
1788      struct DListHead *head = NULL;
1789      int32_t ret = HDF_FAILURE;
1790  
1791      (void)OsalMutexLock(&HdfWpaStubDriver()->mutex);
1792      head = &HdfWpaStubDriver()->remoteListHead;
1793      HDF_LOGD("%s: enter HdfWpaCallbackFun event =%u", __FUNCTION__, event);
1794      if (ifName == NULL) {
1795          HDF_LOGE("%{public}s: data or ifName is NULL!", __func__);
1796          (void)OsalMutexUnlock(&HdfWpaStubDriver()->mutex);
1797          return HDF_ERR_INVALID_PARAM;
1798      }
1799      DLIST_FOR_EACH_ENTRY(pos, head, struct HdfWpaRemoteNode, node) {
1800          if (pos == NULL) {
1801              HDF_LOGE("%{public}s: pos is NULL", __func__);
1802              break;
1803          }
1804          if (pos->callbackObj == NULL) {
1805              HDF_LOGW("%{public}s: pos->callbackObj NULL", __func__);
1806              continue;
1807          }
1808          if (pos->service == NULL) {
1809              HDF_LOGW("%{public}s: pos->service NULL", __func__);
1810              continue;
1811          }
1812          if (strncmp(ifName, "wlan", strlen("wlan")) == 0 || strncmp(ifName, "common", strlen("common")) == 0) {
1813              ret = HdfStaDealEvent(event, pos, data, ifName);
1814          } else if (strncmp(ifName, "chba", strlen("chba")) == 0 ||
1815              strncmp(ifName, "p2p-chba", strlen("p2p-chba")) == 0) {
1816              ret = HdfVendorExtDealEvent(event, pos, data, ifName);
1817          } else if (strncmp(ifName, "p2p", strlen("p2p")) == 0) {
1818              ret = HdfP2pDealEvent(event, pos, data, ifName);
1819          } else {
1820              HDF_LOGE("%{public}s: ifName is error %{public}s", __func__, ifName);
1821          }
1822          if (ret != HDF_SUCCESS) {
1823              HDF_LOGE("%{public}s: dispatch code fialed, error code: %{public}d", __func__, ret);
1824          }
1825      }
1826      (void)OsalMutexUnlock(&HdfWpaStubDriver()->mutex);
1827      return ret;
1828  }
1829  
WpaInterfaceRegisterEventCallback(struct IWpaInterface * self,struct IWpaCallback * cbFunc,const char * ifName)1830  int32_t WpaInterfaceRegisterEventCallback(struct IWpaInterface *self, struct IWpaCallback *cbFunc,
1831      const char *ifName)
1832  {
1833      int32_t ret = HDF_FAILURE;
1834  
1835      (void)self;
1836      pthread_mutex_lock(&g_interfaceLock);
1837      if (cbFunc == NULL || ifName == NULL) {
1838          pthread_mutex_unlock(&g_interfaceLock);
1839          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1840          return HDF_ERR_INVALID_PARAM;
1841      }
1842      int nameLen = strlen(ifName);
1843      if (IsSockRemoved(ifName, nameLen) == 0) {
1844          pthread_mutex_unlock(&g_interfaceLock);
1845          HDF_LOGE("invalid opt");
1846          return HDF_FAILURE;
1847      }
1848      (void)OsalMutexLock(&HdfWpaStubDriver()->mutex);
1849      do {
1850          HDF_LOGE("%{public}s: call HdfWpaAddRemoteObj", __func__);
1851          ret = HdfWpaAddRemoteObj(cbFunc, ifName);
1852          if (ret != HDF_SUCCESS) {
1853              HDF_LOGE("%{public}s: HdfSensorAddRemoteObj false", __func__);
1854              break;
1855          }
1856          ret = WpaRegisterEventCallback(HdfWpaCallbackFun, WIFI_WPA_TO_HAL_CLIENT, ifName);
1857          if (ret != HDF_SUCCESS) {
1858              HDF_LOGE("%{public}s: Register failed!, error code: %{public}d", __func__, ret);
1859              HdfWpaDelRemoteObj(cbFunc);
1860              break;
1861          }
1862      } while (0);
1863      (void)OsalMutexUnlock(&HdfWpaStubDriver()->mutex);
1864      pthread_mutex_unlock(&g_interfaceLock);
1865      return ret;
1866  }
1867  
WpaInterfaceUnregisterEventCallback(struct IWpaInterface * self,struct IWpaCallback * cbFunc,const char * ifName)1868  int32_t WpaInterfaceUnregisterEventCallback(struct IWpaInterface *self, struct IWpaCallback *cbFunc,
1869      const char *ifName)
1870  {
1871      (void)self;
1872      pthread_mutex_lock(&g_interfaceLock);
1873      if (cbFunc == NULL || ifName == NULL) {
1874          pthread_mutex_unlock(&g_interfaceLock);
1875          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1876          return HDF_ERR_INVALID_PARAM;
1877      }
1878      int nameLen = strlen(ifName);
1879      if (IsSockRemoved(ifName, nameLen) == 0) {
1880          pthread_mutex_unlock(&g_interfaceLock);
1881          HDF_LOGE("invalid opt");
1882          return HDF_FAILURE;
1883      }
1884      (void)OsalMutexLock(&HdfWpaStubDriver()->mutex);
1885      if (DListIsEmpty(&HdfWpaStubDriver()->remoteListHead)) {
1886          int32_t ret = WpaUnregisterEventCallback(HdfWpaCallbackFun, WIFI_WPA_TO_HAL_CLIENT, ifName);
1887          if (ret != HDF_SUCCESS) {
1888              HDF_LOGE("%{public}s: Unregister failed!, error code: %{public}d", __func__, ret);
1889          }
1890      }
1891      HdfWpaDelRemoteObj(cbFunc);
1892      (void)OsalMutexUnlock(&HdfWpaStubDriver()->mutex);
1893      pthread_mutex_unlock(&g_interfaceLock);
1894      return HDF_SUCCESS;
1895  }
1896  
WpaInterfaceReassociate(struct IWpaInterface * self,const char * ifName)1897  int32_t WpaInterfaceReassociate(struct IWpaInterface *self, const char *ifName)
1898  {
1899      (void)self;
1900      HDF_LOGI("enter %{public}s ", __func__);
1901      pthread_mutex_lock(&g_interfaceLock);
1902      if (ifName == NULL) {
1903          pthread_mutex_unlock(&g_interfaceLock);
1904          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1905          return HDF_ERR_INVALID_PARAM;
1906      }
1907      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
1908      if (pStaIfc == NULL) {
1909          pthread_mutex_unlock(&g_interfaceLock);
1910          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
1911          return HDF_FAILURE;
1912      }
1913      int ret = pStaIfc->wpaCliCmdReassociate(pStaIfc);
1914      if (ret < 0) {
1915          pthread_mutex_unlock(&g_interfaceLock);
1916          HDF_LOGE("%{public}s: wpaCliCmdReassociate fail! ret = %{public}d", __func__, ret);
1917          return HDF_FAILURE;
1918      }
1919      pthread_mutex_unlock(&g_interfaceLock);
1920      HDF_LOGI("%{public}s: wpaCliCmdReassociate success ret = %{public}d", __func__, ret);
1921      return HDF_SUCCESS;
1922  }
1923  
WpaInterfaceStaShellCmd(struct IWpaInterface * self,const char * ifName,const char * cmd)1924  int32_t WpaInterfaceStaShellCmd(struct IWpaInterface *self, const char *ifName, const char *cmd)
1925  {
1926      (void)self;
1927      HDF_LOGI("enter %{public}s", __func__);
1928      pthread_mutex_lock(&g_interfaceLock);
1929      if (ifName == NULL || cmd == NULL) {
1930          pthread_mutex_unlock(&g_interfaceLock);
1931          HDF_LOGE("%{public}s: input parameter invalid!", __func__);
1932          return HDF_ERR_INVALID_PARAM;
1933      }
1934      WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(ifName);
1935      if (pStaIfc == NULL) {
1936          pthread_mutex_unlock(&g_interfaceLock);
1937          HDF_LOGE("%{public}s: pStaIfc = NULL", __func__);
1938          return HDF_FAILURE;
1939      }
1940      int ret = pStaIfc->wpaCliCmdStaShellCmd(pStaIfc, cmd);
1941      if (ret < 0) {
1942          pthread_mutex_unlock(&g_interfaceLock);
1943          HDF_LOGE("%{public}s: fail ret = %{public}d", __func__, ret);
1944          return HDF_FAILURE;
1945      }
1946      pthread_mutex_unlock(&g_interfaceLock);
1947      HDF_LOGI("%{public}s: success", __func__);
1948      return HDF_SUCCESS;
1949  }
1950  
ClearHdfWpaRemoteObj(void)1951  void ClearHdfWpaRemoteObj(void)
1952  {
1953      struct HdfWpaRemoteNode *pos = NULL;
1954      struct HdfWpaRemoteNode *tmp = NULL;
1955  
1956      (void)OsalMutexLock(&HdfWpaStubDriver()->mutex);
1957      struct DListHead *head = &HdfWpaStubDriver()->remoteListHead;
1958      DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, head, struct HdfWpaRemoteNode, node) {
1959          DListRemove(&(pos->node));
1960          IWpaCallbackRelease(pos->callbackObj);
1961          OsalMemFree(pos);
1962          pos = NULL;
1963      }
1964      (void)OsalMutexUnlock(&HdfWpaStubDriver()->mutex);
1965  }
1966