• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "wlan_callback_impl.h"
17 #include <securec.h>
18 #include <hdf_base.h>
19 #include <hdf_log.h>
20 #include <osal_mem.h>
21 
WlanCallbackResetDriver(struct IWlanCallback * self,uint32_t event,int32_t code,const char * ifName)22 static int32_t WlanCallbackResetDriver(struct IWlanCallback *self, uint32_t event, int32_t code, const char *ifName)
23 {
24     (void)self;
25     HDF_LOGE("WlanCallbackResetDriver: receive resetStatus=%{public}d", code);
26     return HDF_SUCCESS;
27 }
28 
WlanCallbackScanResult(struct IWlanCallback * self,uint32_t event,const struct HdfWifiScanResult * scanResult,const char * ifName)29 static int32_t WlanCallbackScanResult(struct IWlanCallback *self, uint32_t event,
30     const struct HdfWifiScanResult *scanResult, const char *ifName)
31 {
32     (void)self;
33     if (scanResult == NULL || ifName == NULL) {
34         HDF_LOGE("%{public}s: input parameter invalid!", __func__);
35         return HDF_ERR_INVALID_PARAM;
36     }
37     HDF_LOGE("HdiProcessScanResult: flags=%{public}d, caps=%{public}d, freq=%{public}d, beaconInt=%{public}d",
38         scanResult->flags, scanResult->caps, scanResult->freq, scanResult->beaconInt);
39     HDF_LOGE("HdiProcessScanResult: qual=%{public}d, beaconIeLen=%{public}d, level=%{public}d", scanResult->qual,
40         scanResult->beaconIeLen, scanResult->level);
41     HDF_LOGE("HdiProcessScanResult: age=%{public}d, ieLen=%{public}d", scanResult->age, scanResult->ieLen);
42     return HDF_SUCCESS;
43 }
44 
WlanCallbackNetlinkMessage(struct IWlanCallback * self,const uint8_t * msg,uint32_t msgLen)45 static int32_t WlanCallbackNetlinkMessage(struct IWlanCallback *self, const uint8_t *msg, uint32_t msgLen)
46 {
47     uint32_t i;
48     (void)self;
49     if (msg == NULL) {
50         HDF_LOGE("%{public}s: input parameter invalid!", __func__);
51         return HDF_ERR_INVALID_PARAM;
52     }
53 
54     HDF_LOGI("%{public}s: receive message from netlink", __func__);
55     for (i = 0; i < msgLen; i++) {
56         HDF_LOGI("%02x", msg[i]);
57     }
58     return HDF_SUCCESS;
59 }
60 
WlanCallbackServiceGet(void)61 struct IWlanCallback *WlanCallbackServiceGet(void)
62 {
63     struct WlanCallbackService *service =
64         (struct WlanCallbackService *)OsalMemCalloc(sizeof(struct WlanCallbackService));
65     if (service == NULL) {
66         HDF_LOGE("%{public}s: malloc WlanCallbackService obj failed!", __func__);
67         return NULL;
68     }
69 
70     service->interface.ResetDriverResult = WlanCallbackResetDriver;
71     service->interface.ScanResult = WlanCallbackScanResult;
72     service->interface.WifiNetlinkMessage = WlanCallbackNetlinkMessage;
73     return &service->interface;
74 }
75 
WlanCallbackServiceRelease(struct IWlanCallback * instance)76 void WlanCallbackServiceRelease(struct IWlanCallback *instance)
77 {
78     struct WlanCallbackService *service = (struct WlanCallbackService *)instance;
79     if (service == NULL) {
80         return;
81     }
82 
83     OsalMemFree(service);
84 }
85