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 #include <securec.h>
16 #include <hdf_base.h>
17 #include <hdf_log.h>
18 #include <osal_time.h>
19 #include <osal_mem.h>
20 #include "v1_0/iwlan_callback.h"
21 #include "v1_0/iwlan_interface.h"
22 #include "wlan_common_cmd.h"
23 #include "wlan_extend_cmd.h"
24 #include "wlan_impl.h"
25 #include "v1_0/iwlan_interface.h"
26
27 struct WlanInterfaceService {
28 struct IWlanInterface interface;
29 };
30
WlanInterfaceImplGetInstance(void)31 struct IWlanInterface *WlanInterfaceImplGetInstance(void)
32 {
33 struct WlanInterfaceService *service = (struct WlanInterfaceService *)OsalMemCalloc(
34 sizeof(struct WlanInterfaceService));
35 if (service == NULL) {
36 HDF_LOGE("%{public}s: malloc WlanInterfaceService obj failed!", __func__);
37 return NULL;
38 }
39
40 service->interface.Start = WlanInterfaceStart;
41 service->interface.Stop = WlanInterfaceStop;
42 service->interface.CreateFeature = WlanInterfaceCreateFeature;
43 service->interface.DestroyFeature = WlanInterfaceDestroyFeature;
44 service->interface.GetAssociatedStas = WlanInterfaceGetAssociatedStas;
45 service->interface.GetChipId = WlanInterfaceGetChipId;
46 service->interface.GetDeviceMacAddress = WlanInterfaceGetDeviceMacAddress;
47 service->interface.GetFeatureByIfName = WlanInterfaceGetFeatureByIfName;
48 service->interface.GetFeatureType = WlanInterfaceGetFeatureType;
49 service->interface.GetFreqsWithBand = WlanInterfaceGetFreqsWithBand;
50 service->interface.GetIfNamesByChipId = WlanInterfaceGetIfNamesByChipId;
51 service->interface.GetNetworkIfaceName = WlanInterfaceGetNetworkIfaceName;
52 service->interface.GetSupportCombo = WlanInterfaceGetSupportCombo;
53 service->interface.GetSupportFeature = WlanInterfaceGetSupportFeature;
54 service->interface.RegisterEventCallback = WlanInterfaceRegisterEventCallback;
55 service->interface.UnregisterEventCallback = WlanInterfaceUnregisterEventCallback;
56 service->interface.ResetDriver = WlanInterfaceResetDriver;
57 service->interface.SetCountryCode = WlanInterfaceSetCountryCode;
58 service->interface.SetMacAddress = WlanInterfaceSetMacAddress;
59 service->interface.SetScanningMacAddress = WlanInterfaceSetScanningMacAddress;
60 service->interface.SetTxPower = WlanInterfaceSetTxPower;
61 service->interface.GetNetDevInfo = WlanInterfaceGetNetDevInfo;
62 service->interface.StartScan = WlanInterfaceStartScan;
63 service->interface.GetPowerMode = WlanInterfaceGetPowerMode;
64 service->interface.SetPowerMode = WlanInterfaceSetPowerMode;
65 service->interface.StartChannelMeas = WlanInterfaceStartChannelMeas;
66 service->interface.GetChannelMeasResult = WlanInterfaceGetChannelMeasResult;
67 service->interface.SetProjectionScreenParam = WlanInterfaceSetProjectionScreenParam;
68 service->interface.WifiSendCmdIoctl = WlanInterfaceWifiSendCmdIoctl;
69 service->interface.GetStaInfo = WlanInterfaceGetStaInfo;
70 return &service->interface;
71 }
72
WlanInterfaceServiceInit(void)73 int32_t WlanInterfaceServiceInit(void)
74 {
75 int32_t ret;
76 ret = WlanInterfaceWifiConstruct();
77 if (ret != HDF_SUCCESS) {
78 HDF_LOGE("%{public}s construct wifi interface failed! error code: %{public}d", __func__, ret);
79 return ret;
80 }
81 ret = WlanExtendInterfaceWifiConstruct();
82 if (ret != HDF_SUCCESS) {
83 HDF_LOGE("%{public}s construct wifi extend interface failed! error code: %{public}d", __func__, ret);
84 return ret;
85 }
86 return ret;
87 }
88
WlanInterfaceImplRelease(struct IWlanInterface * instance)89 void WlanInterfaceImplRelease(struct IWlanInterface *instance)
90 {
91 if (instance == NULL) {
92 return;
93 }
94 OsalMemFree(instance);
95 if (WlanInterfaceWifiDestruct() != HDF_SUCCESS) {
96 HDF_LOGE("%{public}s destruct WiFi failed!", __func__);
97 }
98 if (WlanExtendInterfaceWifiDestruct() != HDF_SUCCESS) {
99 HDF_LOGE("%{public}s wifi extend interface destruct failed!", __func__);
100 }
101 }
102