1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci#include <securec.h>
16094332d3Sopenharmony_ci#include <hdf_base.h>
17094332d3Sopenharmony_ci#include <hdf_log.h>
18094332d3Sopenharmony_ci#include <osal_time.h>
19094332d3Sopenharmony_ci#include <osal_mem.h>
20094332d3Sopenharmony_ci#include "v1_3/iwlan_callback.h"
21094332d3Sopenharmony_ci#include "v1_3/iwlan_interface.h"
22094332d3Sopenharmony_ci#include "wlan_common_cmd.h"
23094332d3Sopenharmony_ci#include "wlan_extend_cmd.h"
24094332d3Sopenharmony_ci#include "wlan_impl.h"
25094332d3Sopenharmony_ci
26094332d3Sopenharmony_cistruct WlanInterfaceService {
27094332d3Sopenharmony_ci    struct IWlanInterface interface;
28094332d3Sopenharmony_ci};
29094332d3Sopenharmony_ci
30094332d3Sopenharmony_cistruct IWlanInterface *WlanInterfaceImplGetInstance(void)
31094332d3Sopenharmony_ci{
32094332d3Sopenharmony_ci    struct WlanInterfaceService *service = (struct WlanInterfaceService *)OsalMemCalloc(
33094332d3Sopenharmony_ci        sizeof(struct WlanInterfaceService));
34094332d3Sopenharmony_ci    if (service == NULL) {
35094332d3Sopenharmony_ci        HDF_LOGE("%{public}s: malloc WlanInterfaceService obj failed!", __func__);
36094332d3Sopenharmony_ci        return NULL;
37094332d3Sopenharmony_ci    }
38094332d3Sopenharmony_ci
39094332d3Sopenharmony_ci    service->interface.Start = WlanInterfaceStart;
40094332d3Sopenharmony_ci    service->interface.Stop = WlanInterfaceStop;
41094332d3Sopenharmony_ci    service->interface.CreateFeature = WlanInterfaceCreateFeature;
42094332d3Sopenharmony_ci    service->interface.DestroyFeature = WlanInterfaceDestroyFeature;
43094332d3Sopenharmony_ci    service->interface.GetAssociatedStas = WlanInterfaceGetAssociatedStas;
44094332d3Sopenharmony_ci    service->interface.GetChipId = WlanInterfaceGetChipId;
45094332d3Sopenharmony_ci    service->interface.GetDeviceMacAddress = WlanInterfaceGetDeviceMacAddress;
46094332d3Sopenharmony_ci    service->interface.GetFeatureByIfName = WlanInterfaceGetFeatureByIfName;
47094332d3Sopenharmony_ci    service->interface.GetFeatureType = WlanInterfaceGetFeatureType;
48094332d3Sopenharmony_ci    service->interface.GetFreqsWithBand = WlanInterfaceGetFreqsWithBand;
49094332d3Sopenharmony_ci    service->interface.GetIfNamesByChipId = WlanInterfaceGetIfNamesByChipId;
50094332d3Sopenharmony_ci    service->interface.GetNetworkIfaceName = WlanInterfaceGetNetworkIfaceName;
51094332d3Sopenharmony_ci    service->interface.GetSupportCombo = WlanInterfaceGetSupportCombo;
52094332d3Sopenharmony_ci    service->interface.GetSupportFeature = WlanInterfaceGetSupportFeature;
53094332d3Sopenharmony_ci    service->interface.RegisterEventCallback = WlanInterfaceRegisterEventCallback;
54094332d3Sopenharmony_ci    service->interface.UnregisterEventCallback = WlanInterfaceUnregisterEventCallback;
55094332d3Sopenharmony_ci    service->interface.ResetDriver = WlanInterfaceResetDriver;
56094332d3Sopenharmony_ci    service->interface.SetCountryCode = WlanInterfaceSetCountryCode;
57094332d3Sopenharmony_ci    service->interface.SetMacAddress = WlanInterfaceSetMacAddress;
58094332d3Sopenharmony_ci    service->interface.SetScanningMacAddress = WlanInterfaceSetScanningMacAddress;
59094332d3Sopenharmony_ci    service->interface.SetTxPower = WlanInterfaceSetTxPower;
60094332d3Sopenharmony_ci    service->interface.GetNetDevInfo = WlanInterfaceGetNetDevInfo;
61094332d3Sopenharmony_ci    service->interface.StartScan = WlanInterfaceStartScan;
62094332d3Sopenharmony_ci    service->interface.GetPowerMode = WlanInterfaceGetPowerMode;
63094332d3Sopenharmony_ci    service->interface.SetPowerMode = WlanInterfaceSetPowerMode;
64094332d3Sopenharmony_ci    service->interface.StartChannelMeas = WlanInterfaceStartChannelMeas;
65094332d3Sopenharmony_ci    service->interface.GetChannelMeasResult = WlanInterfaceGetChannelMeasResult;
66094332d3Sopenharmony_ci    service->interface.SetProjectionScreenParam = WlanInterfaceSetProjectionScreenParam;
67094332d3Sopenharmony_ci    service->interface.WifiSendCmdIoctl = WlanInterfaceWifiSendCmdIoctl;
68094332d3Sopenharmony_ci    service->interface.GetStaInfo = WlanInterfaceGetStaInfo;
69094332d3Sopenharmony_ci    service->interface.StartPnoScan = WlanInterfaceStartPnoScan;
70094332d3Sopenharmony_ci    service->interface.StopPnoScan = WlanInterfaceStopPnoScan;
71094332d3Sopenharmony_ci    service->interface.GetSignalPollInfo = WlanInterfaceGetSignalPollInfo;
72094332d3Sopenharmony_ci    service->interface.GetApBandwidth = WlanInterfaceGetApBandwidth;
73094332d3Sopenharmony_ci    service->interface.ResetToFactoryMacAddress = WlanInterfaceResetToFactoryMacAddress;
74094332d3Sopenharmony_ci    service->interface.SendActionFrame = WlanInterfaceSendActionFrame;
75094332d3Sopenharmony_ci    service->interface.RegisterActionFrameReceiver = WlanInterfaceRegisterActionFrameReceiver;
76094332d3Sopenharmony_ci    service->interface.GetCoexictenceChannelList = WlanInterfaceGetCoexChannelList;
77094332d3Sopenharmony_ci    service->interface.SetPowerSaveMode = WlanInterfaceSetPowerSaveMode;
78094332d3Sopenharmony_ci    service->interface.SetDpiMarkRule = WlanInterfaceSetDpiMarkRule;
79094332d3Sopenharmony_ci    return &service->interface;
80094332d3Sopenharmony_ci}
81094332d3Sopenharmony_ci
82094332d3Sopenharmony_ciint32_t WlanInterfaceServiceInit(void)
83094332d3Sopenharmony_ci{
84094332d3Sopenharmony_ci    int32_t ret;
85094332d3Sopenharmony_ci    ret = WlanInterfaceWifiConstruct();
86094332d3Sopenharmony_ci    if (ret != HDF_SUCCESS) {
87094332d3Sopenharmony_ci        HDF_LOGE("%{public}s construct wifi interface failed! error code: %{public}d", __func__, ret);
88094332d3Sopenharmony_ci        return ret;
89094332d3Sopenharmony_ci    }
90094332d3Sopenharmony_ci    ret = WlanExtendInterfaceWifiConstruct();
91094332d3Sopenharmony_ci    if (ret != HDF_SUCCESS) {
92094332d3Sopenharmony_ci        HDF_LOGE("%{public}s construct wifi extend interface failed! error code: %{public}d", __func__, ret);
93094332d3Sopenharmony_ci        return ret;
94094332d3Sopenharmony_ci    }
95094332d3Sopenharmony_ci    return ret;
96094332d3Sopenharmony_ci}
97094332d3Sopenharmony_ci
98094332d3Sopenharmony_civoid WlanInterfaceImplRelease(struct IWlanInterface *instance)
99094332d3Sopenharmony_ci{
100094332d3Sopenharmony_ci    if (instance == NULL) {
101094332d3Sopenharmony_ci        return;
102094332d3Sopenharmony_ci    }
103094332d3Sopenharmony_ci    OsalMemFree(instance);
104094332d3Sopenharmony_ci    if (WlanInterfaceWifiDestruct() != HDF_SUCCESS) {
105094332d3Sopenharmony_ci        HDF_LOGE("%{public}s destruct WiFi failed!", __func__);
106094332d3Sopenharmony_ci    }
107094332d3Sopenharmony_ci    if (WlanExtendInterfaceWifiDestruct() != HDF_SUCCESS) {
108094332d3Sopenharmony_ci        HDF_LOGE("%{public}s wifi extend interface destruct failed!", __func__);
109094332d3Sopenharmony_ci    }
110094332d3Sopenharmony_ci}
111