1 /*
2 * Copyright (c) 2020-2022 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "wifi_module.h"
10 #include "wifi_base.h"
11 #include "ap.h"
12 #include "sta.h"
13 #include "p2p.h"
14 #include "hdf_wlan_config.h"
15 #include "securec.h"
16
17 #define HDF_LOG_TAG HDF_WIFI_CORE
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 int32_t DelFeature(struct WifiModule *module, uint16_t featureType);
24 int32_t AddFeature(struct WifiModule *module, uint16_t featureType, struct WifiFeature *featureData);
25
InitFeatures(struct WifiModule * module)26 static int32_t InitFeatures(struct WifiModule *module)
27 {
28 int32_t ret;
29 uint32_t i;
30
31 if (module == NULL) {
32 HDF_LOGE("%s: input module is NULL", __func__);
33 return HDF_FAILURE;
34 }
35 ret = BaseInit();
36 if (ret != HDF_SUCCESS) {
37 HDF_LOGE("%s:BaseInit failed!ret=%d", __func__, ret);
38 return ret;
39 }
40
41 module->feList.fe[HDF_WIFI_FEATURE_AP] = GetWifiApFeature();
42 module->feList.fe[HDF_WIFI_FEATURE_STA] = GetWifiStaFeature();
43 module->feList.fe[HDF_WIFI_FEATURE_P2P] = GetWifiP2pFeature();
44
45 for (i = 0; i < HDF_WIFI_FEATURE_NUM; i++) {
46 if ((module->moduleConfig.hslConfig->featureMap & (1 << i)) && module->feList.fe[i] != NULL) {
47 module->feList.fe[i]->init(module->feList.fe[i]);
48 }
49 }
50 HDF_LOGD("%s:InitFeatures finished!", __func__);
51 return HDF_SUCCESS;
52 }
53
DeInitFeatures(struct WifiModule * module)54 static int32_t DeInitFeatures(struct WifiModule *module)
55 {
56 int32_t ret;
57 uint32_t i;
58 if (module == NULL) {
59 HDF_LOGE("%s: no module", __func__);
60 return HDF_FAILURE;
61 }
62 // make sure the features should be free firstly
63 for (i = 0; i < HDF_WIFI_FEATURE_NUM; i++) {
64 if ((module->feList.fe[i] != NULL) && (module->feList.fe[i]->deInit != NULL)) {
65 module->feList.fe[i]->deInit(module->feList.fe[i]);
66 module->feList.fe[i] = NULL;
67 }
68 }
69
70 ret = BaseDeinit();
71 if (ret != HDF_SUCCESS) {
72 HDF_LOGE("%s:BaseDeinit failed!ret=%d", __func__, ret);
73 }
74 HDF_LOGD("%s:DeInitFeatures finished! ret=%d", __func__, ret);
75 return ret;
76 }
77
InitWifiModule(struct WifiModule * module,const struct HdfConfigWlanModuleConfig * config)78 int16_t InitWifiModule(struct WifiModule *module, const struct HdfConfigWlanModuleConfig *config)
79 {
80 int32_t ret;
81 if (module == NULL || config == NULL) {
82 HDF_LOGE("%s:Input is NULL!", __func__);
83 return HDF_FAILURE;
84 }
85 module->iface.deInit = DeInitFeatures;
86 module->iface.addFeature = AddFeature;
87 module->iface.delFeature = DelFeature;
88 module->modulePrivate = NULL;
89 module->moduleConfig.hslConfig = config;
90
91 ret = InitFeatures(module);
92 if (ret != 0) {
93 HDF_LOGE("%s: module int error ret=%d", __func__, ret);
94 return HDF_FAILURE;
95 }
96 HDF_LOGD("%s:hdf wifi module init succ", __func__);
97 return HDF_SUCCESS;
98 }
99
100 #ifdef __cplusplus
101 }
102 #endif
103