• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifdef HDI_WPA_INTERFACE_SUPPORT
17 #include "wifi_hdi_wpa_callback.h"
18 #include "wifi_sta_hal_interface.h"
19 #include "wifi_supplicant_hal_interface.h"
20 #include "wifi_hdi_util.h"
21 #include "wifi_ap_hal_interface.h"
22 #include "wifi_p2p_hal_interface.h"
23 #include "wifi_hdi_common.h"
24 #include "wifi_common_util.h"
25 #include "wifi_native_define.h"
26 #include "wifi_msg.h"
27 #include "wifi_config_center.h"
28 #include "wifi_log.h"
29 #include "wifi_hisysevent.h"
30 #ifdef UT_TEST
31 #define static
32 #endif
33 
34 constexpr int WIFI_HDI_STR_MAC_LENGTH = 17;
35 constexpr int WIFI_HDI_REASON_LENGTH = 32;
36 constexpr int WIFI_SSID_MAX_LENGTH = 32;
37 constexpr int WIFI_DEVICE_INFO_MAX_LENGTH = 128;
38 constexpr int PD_STATUS_CODE_SHOW_PIN = 0;
39 constexpr int PD_STATUS_CODE_ENTER_PIN = 1;
40 constexpr int PD_STATUS_CODE_PBC_REQ = 2;
41 constexpr int PD_STATUS_CODE_PBC_RSP = 3;
42 constexpr int PD_STATUS_CODE_FAIL = 4;
43 constexpr int WEP_WRONG_PASSWORD_STATUS_CODE = 5202;
44 int g_currentWpaStatus = static_cast<int>(OHOS::Wifi::SupplicantState::UNKNOWN);
45 #undef LOG_TAG
46 #define LOG_TAG "WifiHdiWpaCallback"
47 
OnEventDisconnected(struct IWpaCallback * self,const struct HdiWpaDisconnectParam * disconectParam,const char * ifName)48 int32_t OnEventDisconnected(struct IWpaCallback *self,
49     const struct HdiWpaDisconnectParam *disconectParam, const char* ifName)
50 {
51     if (ifName == nullptr) {
52         LOGE("OnEventDisconnected: invalid ifName!");
53         return 1;
54     }
55     LOGI("OnEventDisconnected: callback enter! ifName = %{public}s", ifName);
56     if (disconectParam == NULL || disconectParam->bssidLen <= 0) {
57         LOGE("OnEventDisconnected: invalid parameter!");
58         return 1;
59     }
60     uint32_t bssidLen = disconectParam->bssidLen;
61     char szBssid[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
62     if (ConvertMacArr2String(disconectParam->bssid, bssidLen, szBssid, sizeof(szBssid)) != 0) {
63         LOGE("%{public}s: failed to convert mac!", __func__);
64         return 1;
65     }
66     int reasonCode = disconectParam->reasonCode;
67     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName);
68     if (cbk.onReportDisConnectReason) {
69         cbk.onReportDisConnectReason(reasonCode, std::string(szBssid));
70     }
71     bool isPsk = false;
72     std::vector<OHOS::Wifi::WifiScanInfo> scanResults;
73     OHOS::Wifi::WifiConfigCenter::GetInstance().GetWifiScanConfig()->GetScanInfoList(scanResults);
74     for (OHOS::Wifi::WifiScanInfo &item : scanResults) {
75         if (strcasecmp(item.bssid.c_str(), szBssid) == 0 &&
76             (item.capabilities.find("PSK") != std::string::npos ||
77             item.capabilities.find("WAPI-PSK") != std::string::npos)) {
78                 isPsk = true;
79                 break;
80         }
81     }
82     int locallyGenerated = disconectParam->locallyGenerated;
83     if (cbk.onWpaSsidWrongKey && isPsk &&
84         g_currentWpaStatus == static_cast<int>(OHOS::Wifi::SupplicantState::FOUR_WAY_HANDSHAKE) &&
85         (reasonCode != Wifi80211ReasonCode::WLAN_REASON_IE_IN_4WAY_DIFFERS || !locallyGenerated)) {
86         LOGI("OnEventDisconnected, wrong password");
87         std::string bssid = std::string(szBssid);
88         cbk.onWpaSsidWrongKey(bssid);
89         OHOS::Wifi::WriteAuthFailHiSysEvent("WRONG_PSWD", reasonCode);
90     }
91     if (cbk.onConnectChanged) {
92         cbk.onConnectChanged(HAL_WPA_CB_DISCONNECTED, reasonCode, std::string(szBssid), locallyGenerated);
93     }
94     LOGI("%{public}s callback out, bssid:%{public}s ifName = %{public}s",
95         __func__,
96         OHOS::Wifi::MacAnonymize(szBssid).c_str(),
97         ifName);
98     return 0;
99 }
100 
OnEventConnected(struct IWpaCallback * self,const struct HdiWpaConnectParam * connectParam,const char * ifName)101 int32_t OnEventConnected(struct IWpaCallback *self,
102     const struct HdiWpaConnectParam *connectParam, const char* ifName)
103 {
104     if (ifName == nullptr) {
105         LOGE("OnEventConnected: invalid ifName!");
106         return 1;
107     }
108     LOGI("OnEventConnected: callback enter! ifName = %{public}s", ifName);
109     if (connectParam == NULL || connectParam->bssidLen <= 0) {
110         LOGE("OnEventConnected: invalid parameter!");
111         return 1;
112     }
113     uint32_t bssidLen = connectParam->bssidLen;
114     char szBssid[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
115     if (ConvertMacArr2String(connectParam->bssid, bssidLen, szBssid, sizeof(szBssid)) != 0) {
116         LOGE("%{public}s: failed to convert mac!", __func__);
117         return 1;
118     }
119     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName);
120     if (cbk.onConnectChanged) {
121         cbk.onConnectChanged(HAL_WPA_CB_CONNECTED, connectParam->networkId, szBssid, 0);
122     }
123     LOGI("%{public}s callback out ,bssid = %{public}s", __func__, OHOS::Wifi::MacAnonymize(szBssid).c_str());
124     return 0;
125 }
126 
OnEventBssidChanged(struct IWpaCallback * self,const struct HdiWpaBssidChangedParam * bssidChangedParam,const char * ifName)127 int32_t OnEventBssidChanged(struct IWpaCallback *self,
128     const struct HdiWpaBssidChangedParam *bssidChangedParam, const char* ifName)
129 {
130     if (ifName == nullptr) {
131         LOGE("OnEventBssidChanged: invalid ifName!");
132         return 1;
133     }
134     LOGI("OnEventBssidChanged: callback enter! ifName = %{public}s", ifName);
135     if (bssidChangedParam == nullptr || bssidChangedParam->reason == nullptr) {
136         LOGE("OnEventBssidChanged: invalid parameter!");
137         return 1;
138     }
139 
140     std::string reason = "";
141     if (bssidChangedParam->reasonLen > 0 && bssidChangedParam->reasonLen < WIFI_HDI_REASON_LENGTH) {
142         reason = std::string(bssidChangedParam->reason, bssidChangedParam->reason + bssidChangedParam->reasonLen);
143     } else {
144         LOGE("OnEventBssidChanged: invalid reasonLen:%{public}u", bssidChangedParam->reasonLen);
145     }
146     char szBssid[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
147     if (ConvertMacArr2String(bssidChangedParam->bssid, bssidChangedParam->bssidLen, szBssid, sizeof(szBssid)) != 0) {
148         LOGE("OnEventBssidChanged: failed to convert mac!");
149         return 1;
150     }
151 
152     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName);
153     if (cbk.onBssidChanged) {
154         cbk.onBssidChanged(reason, szBssid);
155     }
156     LOGI("%{public}s callback out, bssid:%{public}s reason:%{public}s reasonLen:%{public}u",
157         __func__, OHOS::Wifi::MacAnonymize(szBssid).c_str(), reason.c_str(), bssidChangedParam->reasonLen);
158     return 0;
159 }
160 
OnEventStateChanged(struct IWpaCallback * self,const struct HdiWpaStateChangedParam * statechangedParam,const char * ifName)161 int32_t OnEventStateChanged(struct IWpaCallback *self,
162     const struct HdiWpaStateChangedParam *statechangedParam, const char* ifName)
163 {
164     if (ifName == nullptr) {
165         LOGE("OnEventStateChanged: invalid ifName!");
166         return 1;
167     }
168     LOGD("OnEventStateChanged: callback enter! ifName = %{public}s", ifName);
169     if (statechangedParam == NULL) {
170         LOGE("OnEventStateChanged: invalid parameter!");
171         return 1;
172     }
173 
174     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName);
175     g_currentWpaStatus = statechangedParam->status;
176     std::string ssid;
177     if (statechangedParam->ssid != NULL && statechangedParam->ssidLen > 0 &&
178         statechangedParam->ssidLen <= WIFI_SSID_MAX_LENGTH) {
179         ssid = std::string(statechangedParam->ssid, statechangedParam->ssid + statechangedParam->ssidLen);
180     }
181     if (cbk.onWpaStateChanged) {
182         cbk.onWpaStateChanged(g_currentWpaStatus, ssid);
183     }
184     LOGI("OnEventStateChanged:callback out status = %{public}d, ifName = %{public}s", g_currentWpaStatus, ifName);
185     return 0;
186 }
187 
OnEventTempDisabled(struct IWpaCallback * self,const struct HdiWpaTempDisabledParam * tempDisabledParam,const char * ifName)188 int32_t OnEventTempDisabled(struct IWpaCallback *self,
189     const struct HdiWpaTempDisabledParam *tempDisabledParam, const char *ifName)
190 {
191     if (ifName == nullptr) {
192         LOGE("OnEventTempDisabled: invalid ifName!");
193         return 1;
194     }
195     LOGI("OnEventTempDisabled: callback enter! ifName = %{public}s", ifName);
196 
197     if (tempDisabledParam == NULL) {
198         LOGE("OnEventTempDisabled tempDisabledParam is NULL");
199         return 1;
200     }
201     std::string ssid = "";
202     if (tempDisabledParam->ssid != NULL && tempDisabledParam->ssidLen > 0 &&
203         tempDisabledParam->ssidLen <= WIFI_SSID_MAX_LENGTH) {
204         ssid = std::string(tempDisabledParam->ssid, tempDisabledParam->ssid + tempDisabledParam->ssidLen);
205     }
206     std::string reason = "";
207     if (tempDisabledParam->reason != NULL && tempDisabledParam->reasonLen > 0) {
208         reason = std::string(tempDisabledParam->reason, tempDisabledParam->reason + tempDisabledParam->reasonLen);
209     }
210     LOGI("OnEventTempDisabled ssid:%{public}s reason:%{public}s, ifName = %{public}s",
211         OHOS::Wifi::SsidAnonymize(ssid).c_str(),
212         reason.c_str(),
213         ifName);
214     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName);
215     if (cbk.onWpaSsidWrongKey && reason == "AUTH_FAILED") {
216         cbk.onWpaSsidWrongKey("");
217     }
218     return 0;
219 }
220 
OnEventAssociateReject(struct IWpaCallback * self,const struct HdiWpaAssociateRejectParam * associateRejectParam,const char * ifName)221 int32_t OnEventAssociateReject(struct IWpaCallback *self,
222     const struct HdiWpaAssociateRejectParam *associateRejectParam, const char *ifName)
223 {
224     if (ifName == nullptr) {
225         LOGE("OnEventAssociateReject: invalid ifName!");
226         return 1;
227     }
228     LOGI("OnEventAssociateReject: callback enter! ifName = %{public}s", ifName);
229     if (associateRejectParam == NULL) {
230         LOGE("OnEventAssociateReject: invalid parameter!");
231         return 1;
232     }
233     char bssid[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
234     ConvertMacArr2String(associateRejectParam->bssid, associateRejectParam->bssidLen, bssid, sizeof(bssid));
235     int statusCode = associateRejectParam->statusCode;
236 
237     /* Special handling for WPA3-Personal networks. If the password is
238        incorrect, the AP will send association rejection, with status code 1
239        (unspecified failure). In SAE networks, the password authentication
240        is not related to the 4-way handshake. In this case, we will send an
241        authentication failure event up. */
242     bool isWrongPwd = false;
243     std::string failReason = "";
244     std::vector<OHOS::Wifi::WifiScanInfo> scanResults;
245     OHOS::Wifi::WifiConfigCenter::GetInstance().GetWifiScanConfig()->GetScanInfoList(scanResults);
246     for (OHOS::Wifi::WifiScanInfo &item : scanResults) {
247         if (strcasecmp(item.bssid.c_str(), bssid) == 0) {
248             if (statusCode == Wifi80211StatusCode::WLAN_STATUS_UNSPECIFIED_FAILURE &&
249                 (item.capabilities.find("SAE") != std::string::npos)) {
250                 isWrongPwd = true;
251                 failReason = "WPA3_WRONG_PSWD";
252                 break;
253             } else if (statusCode == WEP_WRONG_PASSWORD_STATUS_CODE &&
254                 item.capabilities.find("WEP") != std::string::npos) {
255                 isWrongPwd = true;
256                 failReason = "WEP_WRONG_PSWD";
257                 break;
258             }
259         }
260     }
261     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName);
262     if (isWrongPwd && cbk.onWpaSsidWrongKey) {
263         LOGI("onWpaConnectionRejectCallBack, wrong password");
264         std::string bssidString = std::string(bssid);
265         cbk.onWpaSsidWrongKey(bssidString);
266         OHOS::Wifi::WriteAuthFailHiSysEvent(failReason, statusCode);
267         return 0;
268     }
269     if ((statusCode == Wifi80211StatusCode::WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA ||
270         statusCode == Wifi80211StatusCode::WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY ||
271         statusCode == Wifi80211StatusCode::WLAN_STATUS_DENIED_INSUFFICIENT_BANDWIDTH) &&
272         cbk.onWpaConnectionFull) {
273         LOGI("onWpaConnectionRejectCallBack, connect full");
274         cbk.onWpaConnectionFull(statusCode);
275         OHOS::Wifi::WriteAssocFailHiSysEvent("CONNECT_FULL", statusCode);
276         return 0;
277     }
278     if (cbk.onWpaConnectionReject) {
279         LOGI("onWpaConnectionRejectCallBack");
280         OHOS::Wifi::AssocRejectInfo assocRejectInfo;
281         assocRejectInfo.bssid = std::string(bssid);
282         assocRejectInfo.statusCode = statusCode;
283         assocRejectInfo.timeOut = associateRejectParam->timeOut;
284         cbk.onWpaConnectionReject(assocRejectInfo);
285         OHOS::Wifi::WriteAssocFailHiSysEvent("CONNECT_REJECT", statusCode);
286     }
287     return 0;
288 }
289 
OnEventStaNotify(struct IWpaCallback * self,const char * notifyParam,const char * ifName)290 int32_t OnEventStaNotify(struct IWpaCallback *self, const char* notifyParam, const char *ifName)
291 {
292     if (ifName == nullptr) {
293         LOGE("OnEventStaNotify: invalid ifName!");
294         return 1;
295     }
296     LOGI("OnEventStaNotify: callback enter! ifName = %{public}s", ifName);
297     if (notifyParam == NULL) {
298         LOGE("OnEventStaNotify: invalid parameter!");
299         return 1;
300     }
301 
302     if (strcmp(ifName, "wlan0") == 0 || strcmp(ifName, "wlan1") == 0) {
303         const OHOS::Wifi::WifiEventCallback &cbk =
304             OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName);
305         if (cbk.onEventStaNotify) {
306             cbk.onEventStaNotify(notifyParam);
307         }
308     } else if (strncmp(ifName, "p2p", strlen("p2p")) == 0) {
309         const OHOS::Wifi::P2pHalCallback &p2pCbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
310         if (p2pCbk.onEventStaNotify) {
311             p2pCbk.onEventStaNotify(notifyParam);
312         }
313     }
314     return 0;
315 }
316 
OnEventWpsOverlap(struct IWpaCallback * self,const char * ifName)317 int32_t OnEventWpsOverlap(struct IWpaCallback *self, const char *ifName)
318 {
319     if (ifName == nullptr) {
320         LOGE("OnEventWpsOverlap: invalid ifName!");
321         return 1;
322     }
323     LOGI("OnEventWpsOverlap: callback enter! ifName = %{public}s", ifName);
324     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName);
325     if (cbk.onWpsOverlap) {
326         cbk.onWpsOverlap(1);
327     }
328     return 0;
329 }
330 
OnEventWpsTimeout(struct IWpaCallback * self,const char * ifName)331 int32_t OnEventWpsTimeout(struct IWpaCallback *self, const char *ifName)
332 {
333     if (ifName == nullptr) {
334         LOGE("OnEventWpsOverlap: invalid ifName!");
335         return 1;
336     }
337     LOGI("OnEventWpsTimeout: callback enter! ifName = %{public}s", ifName);
338     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName);
339     if (cbk.onWpsTimeOut) {
340         cbk.onWpsTimeOut(1);
341     }
342     return 0;
343 }
344 
OnEventAuthTimeout(struct IWpaCallback * self,const char * ifName)345 int32_t OnEventAuthTimeout(struct IWpaCallback *self, const char *ifName)
346 {
347     if (ifName == nullptr) {
348         LOGE("OnEventWpsOverlap: invalid ifName!");
349         return 1;
350     }
351     LOGI("OnEventAuthTimeout: callback enter! ifName = %{public}s", ifName);
352     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName);
353     if (g_currentWpaStatus == static_cast<int>(OHOS::Wifi::SupplicantState::FOUR_WAY_HANDSHAKE) &&
354         cbk.onWpaSsidWrongKey) {
355         LOGI("OnEventAuthTimeout, wrong password");
356         cbk.onWpaSsidWrongKey("");
357         OHOS::Wifi::WriteAuthFailHiSysEvent("WRONG_PSWD");
358         return 0;
359     }
360     if (cbk.onWpaAuthTimeout) {
361         cbk.onWpaAuthTimeout();
362         OHOS::Wifi::WriteAuthFailHiSysEvent("AUTH_TIMEOUT");
363     }
364     return 0;
365 }
366 
OnEventAuthReject(struct IWpaCallback * self,const struct HdiWpaAuthRejectParam * authRejectParam,const char * ifName)367 int32_t OnEventAuthReject(struct IWpaCallback *self,
368     const struct HdiWpaAuthRejectParam *authRejectParam, const char *ifName)
369 {
370     if (ifName == nullptr) {
371         LOGE("OnEventAuthReject: invalid ifName!");
372         return 1;
373     }
374     LOGI("OnEventAuthReject: callback enter! ifName = %{public}s", ifName);
375     if (authRejectParam == NULL) {
376         LOGE("OnEventAuthReject:param invalid");
377         return 1;
378     }
379     char bssid[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
380     ConvertMacArr2String(authRejectParam->bssid, authRejectParam->bssidLen, bssid, sizeof(bssid));
381     int statusCode = authRejectParam->statusCode;
382     int authType = authRejectParam->authType;
383 
384     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(ifName);
385     if (cbk.onWpaSsidWrongKey && statusCode == Wifi80211StatusCode::WLAN_STATUS_CHALLENGE_FAIL &&
386         authType == Wifi80211AuthType::WLAN_AUTH_SAE) {
387         LOGI("OnEventAuthReject, wrong password");
388         cbk.onWpaSsidWrongKey(std::string(bssid));
389         OHOS::Wifi::WriteAuthFailHiSysEvent("WRONG_PSWD");
390         return 0;
391     }
392     return 0;
393 }
394 
OnEventScanResult(struct IWpaCallback * self,const struct HdiWpaRecvScanResultParam * recvScanResultParam,const char * ifName)395 int32_t OnEventScanResult(struct IWpaCallback *self,
396     const struct HdiWpaRecvScanResultParam *recvScanResultParam, const char* ifName)
397 {
398     LOGI("OnEventScanResult: callback enter!");
399     if (recvScanResultParam == NULL) {
400         LOGE("OnEventScanResult: invalid parameter!");
401         return 1;
402     }
403 
404     const OHOS::Wifi::SupplicantEventCallback &cbk =
405         OHOS::Wifi::WifiSupplicantHalInterface::GetInstance().GetCallbackInst();
406     if (cbk.onScanNotify) {
407         cbk.onScanNotify(HAL_SINGLE_SCAN_OVER_OK);
408     }
409     return 0;
410 }
411 
onEventStaJoin(struct IHostapdCallback * self,const struct HdiApCbParm * apCbParm,const char * ifName)412 int32_t onEventStaJoin(struct IHostapdCallback *self, const struct HdiApCbParm *apCbParm, const char* ifName)
413 {
414     LOGI("onEvenStaJoin: callback enter!");
415     if (apCbParm == nullptr || apCbParm->content == NULL) {
416         LOGE("onEvenStaJoin: invalid parameter!");
417         return 1;
418     }
419     HalCallbackEvent event;
420     uint8_t len = 0;
421     char tmpBuf[WIFI_BSSID_LENGTH] = {0};
422     if (strncmp(apCbParm->content, "AP-STA-CONNECTED", strlen("AP-STA-CONNECTED")) == 0) {
423         event = HAL_CBK_CMD_STA_JOIN;
424         len = strlen("AP-STA-CONNECTED");
425     } else if (strncmp(apCbParm->content, "AP-STA-DISCONNECTED", strlen("AP-STA-DISCONNECTED")) == 0) {
426         event = HAL_CBK_CMD_STA_LEAVE;
427         len = strlen("AP-STA-DISCONNECTED");
428     } else {
429         LOGE("onEvenStaJoin: unknown content!");
430         return 1;
431     }
432 
433     if (sizeof(tmpBuf) < WIFI_HDI_STR_MAC_LENGTH) {
434         LOGE("onEvenStaJoin: tmpBuf len invalid!");
435     }
436 
437     if (memcpy_s(tmpBuf, sizeof(tmpBuf), apCbParm->content + len + 1, WIFI_HDI_STR_MAC_LENGTH) != 0) {
438         LOGE("onEvenStaJoin: strcpy_s failed!");
439     }
440 
441     const OHOS::Wifi::IWifiApMonitorEventCallback &cbk =
442             OHOS::Wifi::WifiApHalInterface::GetInstance().GetApCallbackInst(apCbParm->id);
443     if (cbk.onStaJoinOrLeave) {
444         OHOS::Wifi::WifiHalApConnectionNofify cbInfo;
445         cbInfo.type = static_cast<int>(event);
446         cbInfo.mac = tmpBuf;
447         cbk.onStaJoinOrLeave(cbInfo);
448     }
449     return 0;
450 }
451 
onEventApState(struct IHostapdCallback * self,const struct HdiApCbParm * apCbParm,const char * ifName)452 int32_t onEventApState(struct IHostapdCallback *self, const struct HdiApCbParm *apCbParm, const char* ifName)
453 {
454     LOGI("onEvenApState: callback enter!");
455     if (apCbParm == nullptr || apCbParm->content == NULL) {
456         LOGE("onEvenApState: invalid parameter!");
457         return 1;
458     }
459     HalCallbackEvent event;
460     if (strncmp(apCbParm->content, "AP-ENABLED", strlen("AP-ENABLED")) == 0) {
461         event = HAL_CBK_CMD_AP_ENABLE;
462     } else if (strncmp(apCbParm->content, "AP-DISABLED", strlen("AP-DISABLED")) == 0) {
463         event = HAL_CBK_CMD_AP_DISABLE;
464         if (GetExecDisable() == EXEC_DISABLE) {
465             SetExecDisable(0);
466             return 0;
467         }
468     } else if (strncmp(apCbParm->content, "CTRL-EVENT-TERMINATING", strlen("CTRL-EVENT-TERMINATING")) == 0) {
469         event = HAL_CBK_CMD_AP_DISABLE;
470     } else if (strncmp(apCbParm->content, "AP-STA-POSSIBLE-PSK-MISMATCH ",
471         strlen("AP-STA-POSSIBLE-PSK-MISMATCH ")) == 0) {
472         event = HAL_CBK_CMD_AP_STA_PSK_MISMATCH_EVENT;
473     } else if (strncmp(apCbParm->content, "AP-CSA-FINISHED ", strlen("AP-CSA-FINISHED ")) == 0) {
474         const OHOS::Wifi::IWifiApMonitorEventCallback &cbk =
475             OHOS::Wifi::WifiApHalInterface::GetInstance().GetApCallbackInst(apCbParm->id);
476         const std::string str(apCbParm->content);
477         if (cbk.onEventHostApdNotify) {
478             cbk.onEventHostApdNotify(str);
479         }
480         return 0;
481     } else {
482         return 1;
483     }
484 
485     const OHOS::Wifi::IWifiApMonitorEventCallback &cbk =
486             OHOS::Wifi::WifiApHalInterface::GetInstance().GetApCallbackInst(apCbParm->id);
487     if (cbk.onApEnableOrDisable) {
488         cbk.onApEnableOrDisable(static_cast<int>(event));
489     }
490     return 0;
491 }
492 
OnEventP2pStateChanged(int status)493 int32_t OnEventP2pStateChanged(int status)
494 {
495     LOGI("OnEventP2pStateChanged %{public}d", status);
496     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
497     if (cbk.onConnectSupplicant) {
498         cbk.onConnectSupplicant(status);
499     }
500     return 0;
501 }
502 
OnEventDeviceFound(struct IWpaCallback * self,const struct HdiP2pDeviceInfoParam * deviceInfoParam,const char * ifName)503 int32_t OnEventDeviceFound(struct IWpaCallback *self,
504     const struct HdiP2pDeviceInfoParam *deviceInfoParam, const char* ifName)
505 {
506     LOGI("OnEventDeviceFound");
507     if (deviceInfoParam == nullptr) {
508         return 1;
509     }
510     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
511     if (cbk.onDeviceFound) {
512         OHOS::Wifi::HalP2pDeviceFound cbInfo;
513         uint32_t srcAddressLen = deviceInfoParam->srcAddressLen;
514         char srcAddress[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
515         ConvertMacArr2String(deviceInfoParam->srcAddress, srcAddressLen, srcAddress, sizeof(srcAddress));
516         cbInfo.srcAddress = srcAddress;
517 
518         uint32_t p2pDeviceAddressLen = deviceInfoParam->p2pDeviceAddressLen;
519         char p2pDeviceAddress[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
520         ConvertMacArr2String(deviceInfoParam->p2pDeviceAddress, p2pDeviceAddressLen,
521             p2pDeviceAddress, sizeof(p2pDeviceAddress));
522         cbInfo.p2pDeviceAddress = p2pDeviceAddress;
523 
524         cbInfo.primaryDeviceType = (char *)(deviceInfoParam->primaryDeviceType);
525         cbInfo.deviceName = (char *)(deviceInfoParam->deviceName);
526         cbInfo.configMethods = deviceInfoParam->configMethods;
527         cbInfo.deviceCapabilities = deviceInfoParam->deviceCapabilities;
528         cbInfo.groupCapabilities = deviceInfoParam->groupCapabilities;
529         if (deviceInfoParam && deviceInfoParam->wfdDeviceInfo && deviceInfoParam->wfdLength > 0 &&
530             deviceInfoParam->wfdLength <= WIFI_DEVICE_INFO_MAX_LENGTH) {
531             cbInfo.wfdDeviceInfo.insert(cbInfo.wfdDeviceInfo.begin(),
532                 deviceInfoParam->wfdDeviceInfo,
533                 deviceInfoParam->wfdDeviceInfo + deviceInfoParam->wfdLength);
534         }
535         cbk.onDeviceFound(cbInfo);
536         LOGI("OnEventDeviceFound p2pDeviceAddress=%{private}s deviceName=%{private}s",
537             p2pDeviceAddress, deviceInfoParam->deviceName);
538     }
539     return 0;
540 }
541 
OnEventDeviceLost(struct IWpaCallback * self,const struct HdiP2pDeviceLostParam * deviceLostParam,const char * ifName)542 int32_t OnEventDeviceLost(struct IWpaCallback *self,
543     const struct HdiP2pDeviceLostParam *deviceLostParam, const char* ifName)
544 {
545     LOGI("OnEventDeviceLost");
546     if (deviceLostParam == nullptr) {
547         return 1;
548     }
549     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
550     if (cbk.onDeviceLost) {
551         uint32_t p2pDeviceAddressLen = deviceLostParam->p2pDeviceAddressLen;
552         char p2pDeviceAddress[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
553         ConvertMacArr2String(deviceLostParam->p2pDeviceAddress, p2pDeviceAddressLen,
554             p2pDeviceAddress, sizeof(p2pDeviceAddress));
555         cbk.onDeviceLost(p2pDeviceAddress);
556         LOGI("OnEventDeviceLost p2pDeviceAddress=%{private}s", p2pDeviceAddress);
557     }
558     return 0;
559 }
560 
OnEventGoNegotiationRequest(struct IWpaCallback * self,const struct HdiP2pGoNegotiationRequestParam * goNegotiationRequestParam,const char * ifName)561 int32_t OnEventGoNegotiationRequest(struct IWpaCallback *self,
562     const struct HdiP2pGoNegotiationRequestParam *goNegotiationRequestParam, const char* ifName)
563 {
564     LOGI("OnEventGoNegotiationRequest");
565     if (goNegotiationRequestParam == nullptr) {
566         return 1;
567     }
568     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
569     if (cbk.onGoNegotiationRequest) {
570         char address[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
571         ConvertMacArr2String(goNegotiationRequestParam->srcAddress,
572             goNegotiationRequestParam->srcAddressLen, address, sizeof(address));
573 
574         cbk.onGoNegotiationRequest(address, goNegotiationRequestParam->passwordId);
575     }
576     return 0;
577 }
578 
OnEventGoNegotiationCompleted(struct IWpaCallback * self,const struct HdiP2pGoNegotiationCompletedParam * goNegotiationCompletedParam,const char * ifName)579 int32_t OnEventGoNegotiationCompleted(struct IWpaCallback *self,
580     const struct HdiP2pGoNegotiationCompletedParam *goNegotiationCompletedParam, const char* ifName)
581 {
582     if (goNegotiationCompletedParam == nullptr) {
583         LOGI("goNegotiationCompletedParam is null");
584         return 1;
585     }
586     int status = goNegotiationCompletedParam->status;
587     LOGI("OnEventGoNegotiationCompleted, status is %{public}d", status);
588     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
589     if (status == 0) {
590         if (cbk.onGoNegotiationSuccess) {
591             cbk.onGoNegotiationSuccess();
592         }
593     } else {
594         if (cbk.onGoNegotiationFailure) {
595             cbk.onGoNegotiationFailure(status);
596         }
597     }
598     return 0;
599 }
600 
OnEventInvitationReceived(struct IWpaCallback * self,const struct HdiP2pInvitationReceivedParam * invitationReceivedParam,const char * ifName)601 int32_t OnEventInvitationReceived(struct IWpaCallback *self,
602     const struct HdiP2pInvitationReceivedParam *invitationReceivedParam, const char *ifName)
603 {
604     LOGI("OnEventInvitationReceived");
605     if (invitationReceivedParam == nullptr) {
606         return 1;
607     }
608     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
609     if (cbk.onInvitationReceived) {
610         OHOS::Wifi::HalP2pInvitationInfo cbInfo;
611         cbInfo.type = invitationReceivedParam->type;
612         cbInfo.persistentNetworkId = invitationReceivedParam->persistentNetworkId;
613         cbInfo.operatingFrequency = invitationReceivedParam->operatingFrequency;
614 
615         char address[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
616         ConvertMacArr2String(invitationReceivedParam->srcAddress,
617             invitationReceivedParam->srcAddressLen, address, sizeof(address));
618         cbInfo.srcAddress = address;
619 
620         char address1[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
621         ConvertMacArr2String(invitationReceivedParam->goDeviceAddress,
622             invitationReceivedParam->goDeviceAddressLen, address1, sizeof(address1));
623         cbInfo.goDeviceAddress = address1;
624 
625         char address2[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
626         ConvertMacArr2String(invitationReceivedParam->bssid,
627             invitationReceivedParam->bssidLen, address2, sizeof(address2));
628         cbInfo.bssid = address2;
629 
630         cbk.onInvitationReceived(cbInfo);
631     }
632     return 0;
633 }
634 
OnEventInvitationResult(struct IWpaCallback * self,const struct HdiP2pInvitationResultParam * invitationResultParam,const char * ifName)635 int32_t OnEventInvitationResult(struct IWpaCallback *self,
636     const struct HdiP2pInvitationResultParam *invitationResultParam, const char *ifName)
637 {
638     LOGI("OnEventInvitationResult");
639     if (invitationResultParam == nullptr) {
640         return 1;
641     }
642     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
643     if (cbk.onInvitationResult) {
644         char address[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
645         ConvertMacArr2String(invitationResultParam->bssid,
646             invitationResultParam->bssidLen, address, sizeof(address));
647         cbk.onInvitationResult(address, invitationResultParam->status);
648     }
649     return 0;
650 }
651 
OnEventGroupFormationSuccess(struct IWpaCallback * self,const char * ifName)652 int32_t OnEventGroupFormationSuccess(struct IWpaCallback *self, const char *ifName)
653 {
654     LOGI("OnEventGroupFormationSuccess");
655     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
656     if (cbk.onGroupFormationSuccess) {
657         cbk.onGroupFormationSuccess();
658     }
659     return 0;
660 }
661 
OnEventGroupFormationFailure(struct IWpaCallback * self,const char * reason,const char * ifName)662 int32_t OnEventGroupFormationFailure(struct IWpaCallback *self, const char *reason, const char *ifName)
663 {
664     LOGI("OnEventGroupFormationFailure");
665     if (reason == nullptr) {
666         return 1;
667     }
668     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
669     if (cbk.onGroupFormationFailure) {
670         cbk.onGroupFormationFailure(reason);
671     }
672     return 0;
673 }
674 
OnEventGroupStarted(struct IWpaCallback * self,const struct HdiP2pGroupStartedParam * groupStartedParam,const char * ifName)675 int32_t OnEventGroupStarted(struct IWpaCallback *self,
676     const struct HdiP2pGroupStartedParam *groupStartedParam, const char* ifName)
677 {
678     LOGI("OnEventGroupStarted");
679     if (groupStartedParam == nullptr) {
680         return 1;
681     }
682     char tempSsid[WIFI_SSID_LENGTH] = {0};
683     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
684     if (cbk.onGroupStarted) {
685         OHOS::Wifi::HalP2pGroupInfo cbInfo;
686         cbInfo.isGo = groupStartedParam->isGo;
687         cbInfo.isPersistent = groupStartedParam->isPersistent;
688         cbInfo.frequency = groupStartedParam->frequency;
689         cbInfo.groupName = (char *)(groupStartedParam->groupIfName);
690         StrSafeCopy(tempSsid, sizeof(tempSsid), (char *)groupStartedParam->ssid);
691         PrintfDecode((u8 *)tempSsid, sizeof(tempSsid), tempSsid);
692         cbInfo.ssid = (char *)(tempSsid);
693         cbInfo.psk = (char *)(groupStartedParam->psk);
694         cbInfo.passphrase = (char *)(groupStartedParam->passphrase);
695         LOGI("OnEventGroupStarted groupName=%{public}s ssid=%{private}s len=%{public}zu",
696             cbInfo.groupName.c_str(), OHOS::Wifi::SsidAnonymize(cbInfo.ssid).c_str(), cbInfo.ssid.size());
697 
698         char address[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
699         ConvertMacArr2String(groupStartedParam->goDeviceAddress,
700             groupStartedParam->goDeviceAddressLen, address, sizeof(address));
701         cbInfo.goDeviceAddress = address;
702 
703         cbk.onGroupStarted(cbInfo);
704     }
705     return 0;
706 }
707 
OnEventGroupInfoStarted(struct IWpaCallback * self,const struct HdiP2pGroupInfoStartedParam * groupStartedParam,const char * ifName)708 int32_t OnEventGroupInfoStarted(struct IWpaCallback *self,
709     const struct HdiP2pGroupInfoStartedParam *groupStartedParam, const char* ifName)
710 {
711     LOGI("OnEventGroupInfoStarted");
712     if (groupStartedParam == nullptr) {
713         return 1;
714     }
715     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
716     char tempSsid[WIFI_SSID_LENGTH] = {0};
717     if (cbk.onGroupStarted) {
718         OHOS::Wifi::HalP2pGroupInfo cbInfo;
719         cbInfo.isGo = groupStartedParam->isGo;
720         cbInfo.isPersistent = groupStartedParam->isPersistent;
721         cbInfo.frequency = groupStartedParam->frequency;
722         cbInfo.groupName = (char *)(groupStartedParam->groupIfName);
723         StrSafeCopy(tempSsid, sizeof(tempSsid), (char *)groupStartedParam->ssid);
724         PrintfDecode((u8 *)tempSsid, sizeof(tempSsid), tempSsid);
725         cbInfo.ssid = (char *)(tempSsid);
726         cbInfo.psk = (char *)(groupStartedParam->psk);
727         cbInfo.passphrase = (char *)(groupStartedParam->passphrase);
728         char address[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
729         char address1[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
730         ConvertMacArr2String(groupStartedParam->goDeviceAddress,
731             groupStartedParam->goDeviceAddressLen, address, sizeof(address));
732         ConvertMacArr2String(groupStartedParam->goRandomDeviceAddress,
733             groupStartedParam->goRandomDeviceAddressLen, address1, sizeof(address1));
734         LOGI("OnEventGroupInfoStarted address=%{private}s len %{public}d address1=%{private}s ",
735             address, groupStartedParam->goRandomDeviceAddressLen, address1);
736         cbInfo.goDeviceAddress = address;
737         cbInfo.goRandomAddress = address1;
738         cbk.onGroupStarted(cbInfo);
739     }
740     return 0;
741 }
742 
OnEventGroupRemoved(struct IWpaCallback * self,const struct HdiP2pGroupRemovedParam * groupRemovedParam,const char * ifName)743 int32_t OnEventGroupRemoved(struct IWpaCallback *self,
744     const struct HdiP2pGroupRemovedParam *groupRemovedParam, const char* ifName)
745 {
746     LOGI("OnEventGroupRemoved");
747     if (groupRemovedParam == nullptr) {
748         return 1;
749     }
750     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
751     if (cbk.onGroupRemoved) {
752         cbk.onGroupRemoved((char *)(groupRemovedParam->groupIfName), (groupRemovedParam->isGo == 1));
753     }
754     return 0;
755 }
756 
OnEventProvisionDiscoveryCompleted(struct IWpaCallback * self,const struct HdiP2pProvisionDiscoveryCompletedParam * provisionDiscoveryCompletedParam,const char * ifName)757 int32_t OnEventProvisionDiscoveryCompleted(struct IWpaCallback *self,
758     const struct HdiP2pProvisionDiscoveryCompletedParam *provisionDiscoveryCompletedParam, const char* ifName)
759 {
760     LOGI("OnEventProvisionDiscoveryCompleted enter");
761     if (provisionDiscoveryCompletedParam == nullptr) {
762         return 1;
763     }
764     LOGI("OnEventProvisionDiscoveryCompleted provDiscStatusCode=%{public}d",
765         provisionDiscoveryCompletedParam->provDiscStatusCode);
766     uint32_t addressLen = provisionDiscoveryCompletedParam->p2pDeviceAddressLen;
767     char address[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
768     ConvertMacArr2String(provisionDiscoveryCompletedParam->p2pDeviceAddress,
769         addressLen, address, sizeof(address));
770 
771     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
772     if (provisionDiscoveryCompletedParam->provDiscStatusCode == PD_STATUS_CODE_SHOW_PIN) {
773         if (cbk.onProvisionDiscoveryShowPin) {
774             cbk.onProvisionDiscoveryShowPin(address,
775                 (char *)(provisionDiscoveryCompletedParam->generatedPin));
776         }
777     } else if (provisionDiscoveryCompletedParam->provDiscStatusCode == PD_STATUS_CODE_ENTER_PIN) {
778         if (cbk.onProvisionDiscoveryEnterPin) {
779             cbk.onProvisionDiscoveryEnterPin(address);
780         }
781     } else if (provisionDiscoveryCompletedParam->provDiscStatusCode == PD_STATUS_CODE_PBC_REQ) {
782         if (cbk.onProvisionDiscoveryPbcRequest) {
783             cbk.onProvisionDiscoveryPbcRequest(address);
784         }
785     } else if (provisionDiscoveryCompletedParam->provDiscStatusCode == PD_STATUS_CODE_PBC_RSP) {
786         if (cbk.onProvisionDiscoveryPbcResponse) {
787         cbk.onProvisionDiscoveryPbcResponse(address);
788     }
789     } else if (provisionDiscoveryCompletedParam->provDiscStatusCode == PD_STATUS_CODE_FAIL) {
790         if (cbk.onProvisionDiscoveryFailure) {
791             cbk.onProvisionDiscoveryFailure();
792         }
793     }
794     return 0;
795 }
796 
OnEventFindStopped(struct IWpaCallback * self,const char * ifName)797 int32_t OnEventFindStopped(struct IWpaCallback *self, const char* ifName)
798 {
799     LOGI("OnEventFindStopped");
800     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
801     if (cbk.onFindStopped) {
802         cbk.onFindStopped();
803     }
804     return 0;
805 }
806 
OnEventServDiscReq(struct IWpaCallback * self,const struct HdiP2pServDiscReqInfoParam * servDiscReqInfoParam,const char * ifName)807 int32_t OnEventServDiscReq(struct IWpaCallback *self,
808     const struct HdiP2pServDiscReqInfoParam *servDiscReqInfoParam, const char* ifName)
809 {
810     LOGI("OnEventServDiscReq");
811     if (servDiscReqInfoParam == nullptr) {
812         return 1;
813     }
814     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
815     if (cbk.onP2pServDiscReq) {
816         OHOS::Wifi::HalP2pServDiscReqInfo cbInfo;
817         cbInfo.freq = servDiscReqInfoParam->freq;
818         cbInfo.dialogToken = servDiscReqInfoParam->dialogToken;
819         cbInfo.updateIndic = servDiscReqInfoParam->updateIndic;
820 
821         char address[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
822         ConvertMacArr2String(servDiscReqInfoParam->mac, servDiscReqInfoParam->macLen,
823             address, sizeof(address));
824         cbInfo.mac = address;
825 
826         if (servDiscReqInfoParam->tlvsLen > 0 && servDiscReqInfoParam->tlvs != nullptr) {
827             OHOS::Wifi::Char2Vec(servDiscReqInfoParam->tlvs, servDiscReqInfoParam->tlvsLen, cbInfo.tlvList);
828         }
829         cbk.onP2pServDiscReq(cbInfo);
830     }
831     return 0;
832 }
833 
OnEventServDiscResp(struct IWpaCallback * self,const struct HdiP2pServDiscRespParam * servDiscRespParam,const char * ifName)834 int32_t OnEventServDiscResp(struct IWpaCallback *self,
835     const struct HdiP2pServDiscRespParam *servDiscRespParam, const char* ifName)
836 {
837     LOGI("OnEventServDiscResp");
838     if (servDiscRespParam == nullptr) {
839         return 1;
840     }
841     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
842     if (cbk.onServiceDiscoveryResponse) {
843         std::vector<unsigned char> tlvList;
844         if (servDiscRespParam->tlvs != nullptr) {
845             OHOS::Wifi::Char2Vec(servDiscRespParam->tlvs, servDiscRespParam->tlvsLen, tlvList);
846         }
847         char address[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
848         ConvertMacArr2String(servDiscRespParam->srcAddress, servDiscRespParam->srcAddressLen,
849             address, sizeof(address));
850         cbk.onServiceDiscoveryResponse(address, servDiscRespParam->updateIndicator, tlvList);
851     }
852     return 0;
853 }
854 
OnEventStaConnectState(struct IWpaCallback * self,const struct HdiP2pStaConnectStateParam * staConnectStateParam,const char * ifName)855 int32_t OnEventStaConnectState(struct IWpaCallback *self,
856     const struct HdiP2pStaConnectStateParam *staConnectStateParam, const char* ifName)
857 {
858     LOGI("OnEventStaConnectState");
859     if (staConnectStateParam == nullptr) {
860         return 1;
861     }
862     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
863     char srcAddress[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
864     char address[WIFI_HDI_STR_MAC_LENGTH + 1] = {0};
865     ConvertMacArr2String(staConnectStateParam->p2pDeviceAddress,
866         staConnectStateParam->p2pDeviceAddressLen, address, sizeof(address));
867     ConvertMacArr2String(staConnectStateParam->srcAddress,
868         staConnectStateParam->srcAddressLen, srcAddress, sizeof(srcAddress));
869     if (staConnectStateParam->state == 1) {
870         if (cbk.onStaAuthorized) {
871             cbk.onStaAuthorized(address, srcAddress);
872         }
873     } else {
874         if (cbk.onStaDeauthorized) {
875             cbk.onStaDeauthorized(address);
876         }
877     }
878     return 0;
879 }
880 
OnEventIfaceCreated(struct IWpaCallback * self,const struct HdiP2pIfaceCreatedParam * ifaceCreatedParam,const char * ifName)881 int32_t OnEventIfaceCreated(struct IWpaCallback *self,
882     const struct HdiP2pIfaceCreatedParam *ifaceCreatedParam, const char* ifName)
883 {
884     LOGI("OnEventIfaceCreated");
885     if (ifaceCreatedParam == nullptr) {
886         return 1;
887     }
888     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
889     if (cbk.onP2pIfaceCreated) {
890         cbk.onP2pIfaceCreated(ifName, ifaceCreatedParam->isGo);
891     }
892     return 0;
893 }
894 
OnNativeProcessDeath(int status)895 void OnNativeProcessDeath(int status)
896 {
897     LOGI("OnNativeProcessDeath status=%{public}d", status);
898     const std::function<void(int)> &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetDeathCallbackInst();
899     if (cbk) {
900         cbk(status);
901     }
902 }
903 #endif
904