• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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     return HDF_SUCCESS;
51 }
52 
DeInitFeatures(struct WifiModule * module)53 static int32_t DeInitFeatures(struct WifiModule *module)
54 {
55     int32_t ret;
56     uint32_t i;
57     if (module == NULL) {
58         HDF_LOGE("%s: no  module", __func__);
59         return HDF_FAILURE;
60     }
61     // make sure the features should be free firstly
62     for (i = 0; i < HDF_WIFI_FEATURE_NUM; i++) {
63         if ((module->feList.fe[i] != NULL) && (module->feList.fe[i]->deInit != NULL)) {
64             module->feList.fe[i]->deInit(module->feList.fe[i]);
65             module->feList.fe[i] = NULL;
66         }
67     }
68 
69     ret = BaseDeinit();
70     if (ret != HDF_SUCCESS) {
71         HDF_LOGE("%s:BaseDeinit failed!ret=%d", __func__, ret);
72     }
73     return ret;
74 }
75 
InitWifiModule(struct WifiModule * module,const struct HdfConfigWlanModuleConfig * config)76 int16_t InitWifiModule(struct WifiModule *module, const struct HdfConfigWlanModuleConfig *config)
77 {
78     int32_t ret;
79     if (module == NULL || config == NULL) {
80         HDF_LOGE("%s:Input is NULL!", __func__);
81         return HDF_FAILURE;
82     }
83     module->iface.deInit = DeInitFeatures;
84     module->iface.addFeature = AddFeature;
85     module->iface.delFeature = DelFeature;
86     module->modulePrivate = NULL;
87     module->moduleConfig.hslConfig = config;
88 
89     ret = InitFeatures(module);
90     if (ret != 0) {
91         HDF_LOGE("%s: module int error ret=%d", __func__, ret);
92         return HDF_FAILURE;
93     }
94     HDF_LOGD("%s:hdf wifi module init succ", __func__);
95     return HDF_SUCCESS;
96 }
97 
98 #ifdef __cplusplus
99 }
100 #endif
101