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