• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "wifi_idl_inner_interface.h"
16 #include "wifi_chip_hal_interface.h"
17 #include "wifi_ap_hal_interface.h"
18 #include "wifi_sta_hal_interface.h"
19 #include "wifi_supplicant_hal_interface.h"
20 #include "wifi_p2p_hal_interface.h"
21 #include "wifi_global_func.h"
22 
GetChipRpcClient(void)23 RpcClient *GetChipRpcClient(void)
24 {
25     return OHOS::Wifi::WifiChipHalInterface::GetInstance().mIdlClient->pRpcClient;
26 }
27 
GetApRpcClient(void)28 RpcClient *GetApRpcClient(void)
29 {
30     return OHOS::Wifi::WifiApHalInterface::GetInstance().mIdlClient->pRpcClient;
31 }
32 
OnApStaJoinOrLeave(const CStationInfo * info,int id)33 void OnApStaJoinOrLeave(const CStationInfo *info, int id)
34 {
35     if (info == nullptr) {
36         return;
37     }
38     const OHOS::Wifi::IWifiApMonitorEventCallback &cbk =
39         OHOS::Wifi::WifiApHalInterface::GetInstance().GetApCallbackInst(id);
40     if (cbk.onStaJoinOrLeave) {
41         OHOS::Wifi::WifiApConnectionNofify cbInfo;
42         cbInfo.type = info->type;
43         cbInfo.mac = info->mac;
44         cbk.onStaJoinOrLeave(cbInfo);
45     }
46 }
47 
OnApEnableOrDisable(int status,int id)48 void OnApEnableOrDisable(int status, int id)
49 {
50     const OHOS::Wifi::IWifiApMonitorEventCallback &cbk =
51         OHOS::Wifi::WifiApHalInterface::GetInstance().GetApCallbackInst(id);
52     if (cbk.onApEnableOrDisable) {
53         cbk.onApEnableOrDisable(status);
54     }
55 }
56 
GetStaRpcClient(void)57 RpcClient *GetStaRpcClient(void)
58 {
59     return OHOS::Wifi::WifiStaHalInterface::GetInstance().mIdlClient->pRpcClient;
60 }
61 
OnConnectChanged(int status,int networkId,const char * mac)62 void OnConnectChanged(int status, int networkId, const char *mac)
63 {
64     if (mac == nullptr) {
65         return;
66     }
67     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst();
68     if (cbk.onConnectChanged) {
69         cbk.onConnectChanged(status, networkId, mac);
70     }
71 }
72 
OnBssidChanged(const char * reason,const char * bssid)73 void OnBssidChanged(const char *reason, const char *bssid)
74 {
75     if (reason == nullptr || bssid == nullptr) {
76         return;
77     }
78     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst();
79     if (cbk.onBssidChanged) {
80         cbk.onBssidChanged(reason, bssid);
81     }
82 }
83 
OnWpaStateChanged(int status)84 void OnWpaStateChanged(int status)
85 {
86     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst();
87     if (cbk.onWpaStateChanged) {
88         cbk.onWpaStateChanged(status);
89     }
90 }
91 
OnWpaSsidWrongKey(int status)92 void OnWpaSsidWrongKey(int status)
93 {
94     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst();
95     if (cbk.onWpaSsidWrongKey) {
96         cbk.onWpaSsidWrongKey(status);
97     }
98 }
99 
OnWpaConnectionFull(int status)100 void OnWpaConnectionFull(int status)
101 {
102     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst();
103     if (cbk.onWpaConnectionFull) {
104         cbk.onWpaConnectionFull(status);
105     }
106 }
107 
OnWpaConnectionReject(int status)108 void OnWpaConnectionReject(int status)
109 {
110     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst();
111     if (cbk.onWpaConnectionReject) {
112         cbk.onWpaConnectionReject(status);
113     }
114 }
115 
OnWpsOverlap(int status)116 void OnWpsOverlap(int status)
117 {
118     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst();
119     if (cbk.onWpsOverlap) {
120         cbk.onWpsOverlap(status);
121     }
122 }
123 
OnWpsTimeOut(int status)124 void OnWpsTimeOut(int status)
125 {
126     const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst();
127     if (cbk.onWpsTimeOut) {
128         cbk.onWpsTimeOut(status);
129     }
130 }
131 
GetSupplicantRpcClient(void)132 RpcClient *GetSupplicantRpcClient(void)
133 {
134     return OHOS::Wifi::WifiSupplicantHalInterface::GetInstance().mIdlClient->pRpcClient;
135 }
136 
OnScanNotify(int status)137 void OnScanNotify(int status)
138 {
139     const OHOS::Wifi::SupplicantEventCallback &cbk =
140         OHOS::Wifi::WifiSupplicantHalInterface::GetInstance().GetCallbackInst();
141     if (cbk.onScanNotify) {
142         cbk.onScanNotify(status);
143     }
144 }
145 
GetP2pRpcClient(void)146 RpcClient *GetP2pRpcClient(void)
147 {
148     return OHOS::Wifi::WifiP2PHalInterface::GetInstance().mIdlClient->pRpcClient;
149 }
150 
OnP2pConnectSupplicant(int state)151 void OnP2pConnectSupplicant(int state)
152 {
153     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
154     if (cbk.onConnectSupplicant) {
155         cbk.onConnectSupplicant(state);
156     }
157 }
158 
OnP2pDeviceFound(const P2pDeviceInfo * info)159 void OnP2pDeviceFound(const P2pDeviceInfo *info)
160 {
161     if (info == nullptr) {
162         return;
163     }
164     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
165     if (cbk.onDeviceFound) {
166         OHOS::Wifi::IdlP2pDeviceFound cbInfo;
167         cbInfo.srcAddress = info->srcAddress;
168         cbInfo.p2pDeviceAddress = info->p2pDeviceAddress;
169         cbInfo.primaryDeviceType = info->primaryDeviceType;
170         cbInfo.deviceName = info->deviceName;
171         cbInfo.configMethods = info->configMethods;
172         cbInfo.deviceCapabilities = info->deviceCapabilities;
173         cbInfo.groupCapabilities = info->groupCapabilities;
174         const int wfdLength = 14; /* wfd info type: 0x000000000000 */
175         const int wfdStartPos = 2; /* skip 0x */
176         if (info->wfdLength >= wfdLength && strlen(info->wfdDeviceInfo) >= wfdLength) {
177             OHOS::Wifi::HexStringToVec(info->wfdDeviceInfo + wfdStartPos, cbInfo.wfdDeviceInfo);
178         }
179         cbk.onDeviceFound(cbInfo);
180     }
181 }
182 
OnP2pDeviceLost(const char * p2pDeviceAddress)183 void OnP2pDeviceLost(const char *p2pDeviceAddress)
184 {
185     if (p2pDeviceAddress == nullptr) {
186         return;
187     }
188     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
189     if (cbk.onDeviceLost) {
190         cbk.onDeviceLost(p2pDeviceAddress);
191     }
192 }
193 
OnP2pGoNegotiationRequest(const char * srcAddress,short passwordId)194 void OnP2pGoNegotiationRequest(const char *srcAddress, short passwordId)
195 {
196     if (srcAddress == nullptr) {
197         return;
198     }
199     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
200     if (cbk.onGoNegotiationRequest) {
201         cbk.onGoNegotiationRequest(srcAddress, passwordId);
202     }
203 }
204 
OnP2pGoNegotiationSuccess(void)205 void OnP2pGoNegotiationSuccess(void)
206 {
207     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
208     if (cbk.onGoNegotiationSuccess) {
209         cbk.onGoNegotiationSuccess();
210     }
211 }
212 
OnP2pGoNegotiationFailure(int status)213 void OnP2pGoNegotiationFailure(int status)
214 {
215     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
216     if (cbk.onGoNegotiationFailure) {
217         cbk.onGoNegotiationFailure(status);
218     }
219 }
220 
OnP2pInvitationResult(const char * bssid,int status)221 void OnP2pInvitationResult(const char *bssid, int status)
222 {
223     if (bssid == nullptr) {
224         return;
225     }
226     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
227     if (cbk.onInvitationResult) {
228         cbk.onInvitationResult(bssid, status);
229     }
230 }
231 
OnP2pInvitationReceived(const P2pInvitationInfo * info)232 void OnP2pInvitationReceived(const P2pInvitationInfo *info)
233 {
234     if (info == nullptr) {
235         return;
236     }
237     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
238     if (cbk.onInvitationReceived) {
239         OHOS::Wifi::IdlP2pInvitationInfo cbInfo;
240         cbInfo.type = info->type;
241         cbInfo.persistentNetworkId = info->persistentNetworkId;
242         cbInfo.operatingFrequency = info->operatingFrequency;
243         cbInfo.srcAddress = info->srcAddress;
244         cbInfo.goDeviceAddress = info->goDeviceAddress;
245         cbInfo.bssid = info->bssid;
246         cbk.onInvitationReceived(cbInfo);
247     }
248 }
249 
OnP2pGroupFormationSuccess(void)250 void OnP2pGroupFormationSuccess(void)
251 {
252     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
253     if (cbk.onGroupFormationSuccess) {
254         cbk.onGroupFormationSuccess();
255     }
256 }
257 
OnP2pGroupFormationFailure(const char * failureReason)258 void OnP2pGroupFormationFailure(const char *failureReason)
259 {
260     if (failureReason == nullptr) {
261         return;
262     }
263     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
264     if (cbk.onGroupFormationFailure) {
265         cbk.onGroupFormationFailure(failureReason);
266     }
267 }
268 
OnP2pGroupStarted(const P2pGroupInfo * group)269 void OnP2pGroupStarted(const P2pGroupInfo *group)
270 {
271     if (group == nullptr) {
272         return;
273     }
274     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
275     if (cbk.onGroupStarted) {
276         OHOS::Wifi::IdlP2pGroupInfo cbInfo;
277         cbInfo.isGo = group->isGo;
278         cbInfo.isPersistent = group->isPersistent;
279         cbInfo.frequency = group->frequency;
280         cbInfo.groupName = group->groupName;
281         cbInfo.ssid = group->ssid;
282         cbInfo.psk = group->psk;
283         cbInfo.passphrase = group->passphrase;
284         cbInfo.goDeviceAddress = group->goDeviceAddress;
285         cbk.onGroupStarted(cbInfo);
286     }
287 }
288 
OnP2pGroupRemoved(const char * groupIfName,int isGo)289 void OnP2pGroupRemoved(const char *groupIfName, int isGo)
290 {
291     if (groupIfName == nullptr) {
292         return;
293     }
294     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
295     if (cbk.onGroupRemoved) {
296         cbk.onGroupRemoved(groupIfName, (isGo == 1));
297     }
298 }
299 
OnP2pProvisionDiscoveryPbcRequest(const char * p2pDeviceAddress)300 void OnP2pProvisionDiscoveryPbcRequest(const char *p2pDeviceAddress)
301 {
302     if (p2pDeviceAddress == nullptr) {
303         return;
304     }
305     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
306     if (cbk.onProvisionDiscoveryPbcRequest) {
307         cbk.onProvisionDiscoveryPbcRequest(p2pDeviceAddress);
308     }
309 }
310 
OnP2pProvisionDiscoveryPbcResponse(const char * p2pDeviceAddress)311 void OnP2pProvisionDiscoveryPbcResponse(const char *p2pDeviceAddress)
312 {
313     if (p2pDeviceAddress == nullptr) {
314         return;
315     }
316     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
317     if (cbk.onProvisionDiscoveryPbcResponse) {
318         cbk.onProvisionDiscoveryPbcResponse(p2pDeviceAddress);
319     }
320 }
321 
OnP2pProvisionDiscoveryEnterPin(const char * p2pDeviceAddress)322 void OnP2pProvisionDiscoveryEnterPin(const char *p2pDeviceAddress)
323 {
324     if (p2pDeviceAddress == nullptr) {
325         return;
326     }
327     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
328     if (cbk.onProvisionDiscoveryEnterPin) {
329         cbk.onProvisionDiscoveryEnterPin(p2pDeviceAddress);
330     }
331 }
332 
OnP2pProvisionDiscoveryShowPin(const char * p2pDeviceAddress,const char * generatedPin)333 void OnP2pProvisionDiscoveryShowPin(const char *p2pDeviceAddress, const char *generatedPin)
334 {
335     if (p2pDeviceAddress == nullptr || generatedPin == nullptr) {
336         return;
337     }
338     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
339     if (cbk.onProvisionDiscoveryShowPin) {
340         cbk.onProvisionDiscoveryShowPin(p2pDeviceAddress, generatedPin);
341     }
342 }
343 
OnP2pProvisionDiscoveryFailure(void)344 void OnP2pProvisionDiscoveryFailure(void)
345 {
346     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
347     if (cbk.onProvisionDiscoveryFailure) {
348         cbk.onProvisionDiscoveryFailure();
349     }
350 }
351 
OnP2pFindStopped(void)352 void OnP2pFindStopped(void)
353 {
354     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
355     if (cbk.onFindStopped) {
356         cbk.onFindStopped();
357     }
358 }
359 
OnP2pServiceDiscoveryResponse(const char * srcAddress,short updateIndicator,const unsigned char * tlvs,size_t tlvsLength)360 void OnP2pServiceDiscoveryResponse(
361     const char *srcAddress, short updateIndicator, const unsigned char *tlvs, size_t tlvsLength)
362 {
363     if (srcAddress == nullptr) {
364         return;
365     }
366     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
367     if (cbk.onServiceDiscoveryResponse) {
368         std::vector<unsigned char> tlvList;
369         if (tlvs != nullptr) {
370             OHOS::Wifi::Char2Vec(tlvs, tlvsLength, tlvList);
371         }
372         cbk.onServiceDiscoveryResponse(srcAddress, updateIndicator, tlvList);
373     }
374 }
375 
OnP2pStaDeauthorized(const char * p2pDeviceAddress)376 void OnP2pStaDeauthorized(const char *p2pDeviceAddress)
377 {
378     if (p2pDeviceAddress == nullptr) {
379         return;
380     }
381     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
382     if (cbk.onStaDeauthorized) {
383         cbk.onStaDeauthorized(p2pDeviceAddress);
384     }
385 }
386 
OnP2pStaAuthorized(const char * p2pDeviceAddress)387 void OnP2pStaAuthorized(const char *p2pDeviceAddress)
388 {
389     if (p2pDeviceAddress == nullptr) {
390         return;
391     }
392     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
393     if (cbk.onStaAuthorized) {
394         cbk.onStaAuthorized(p2pDeviceAddress);
395     }
396 }
397 
OnP2pConnectSupplicantFailed(void)398 void OnP2pConnectSupplicantFailed(void)
399 {
400     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
401     if (cbk.connectSupplicantFailed) {
402         cbk.connectSupplicantFailed();
403     }
404 }
405 
OnP2pServDiscReq(const P2pServDiscReqInfo * info)406 void OnP2pServDiscReq(const P2pServDiscReqInfo *info)
407 {
408     if (info == nullptr) {
409         return;
410     }
411     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
412     if (cbk.onP2pServDiscReq) {
413         OHOS::Wifi::IdlP2pServDiscReqInfo cbInfo;
414         cbInfo.freq = info->freq;
415         cbInfo.dialogToken = info->dialogToken;
416         cbInfo.updateIndic = info->updateIndic;
417         cbInfo.mac = info->mac;
418         if (info->tlvsLength > 0 && info->tlvs != nullptr) {
419             OHOS::Wifi::Char2Vec(info->tlvs, info->tlvsLength, cbInfo.tlvList);
420         }
421         cbk.onP2pServDiscReq(cbInfo);
422     }
423 }
424 
OnP2pIfaceCreated(const char * ifName,int isGo)425 void OnP2pIfaceCreated(const char *ifName, int isGo)
426 {
427     if (ifName == nullptr) {
428         return;
429     }
430     const OHOS::Wifi::P2pHalCallback &cbk = OHOS::Wifi::WifiP2PHalInterface::GetInstance().GetP2pCallbackInst();
431     if (cbk.onP2pIfaceCreated) {
432         cbk.onP2pIfaceCreated(ifName, isGo);
433     }
434 }
435