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 "hdf_module_test.h"
10 #include "hdf_base.h"
11 #include "hdf_log.h"
12 #include "hdf_wifi_product.h"
13 #include "ap.h"
14
15 struct HdfConfigWlanModuleConfig *g_hdfWlanModuleCfg = NULL;
16 struct WifiModule *g_hdfWifiModule = NULL;
17
18 struct HdfConfigWlanRoot g_moduleData1 = {
19 .wlanConfig.moduleConfig = {
20 .featureMap = 0xffff,
21 .station = {
22 .name = "sta",
23 .mode = 0x1,
24 },
25 .hostAp = {
26 .name = "ap",
27 .mode = 0x0,
28 .vapResNum = 0x1,
29 .userResNum = 0x8,
30 },
31 .p2p = {
32 .name = "p2p",
33 .mode = 0x0,
34 },
35 }
36 };
37
P2pInit(struct WifiFeature * feature)38 static int32_t P2pInit(struct WifiFeature *feature)
39 {
40 (void)feature;
41 return HDF_SUCCESS;
42 }
43
P2pDeinit(struct WifiFeature * feature)44 static int32_t P2pDeinit(struct WifiFeature *feature)
45 {
46 (void)feature;
47 return HDF_SUCCESS;
48 }
49 struct WifiFeature g_p2pFeature = {
50 .name = "p2p",
51 .init = P2pInit,
52 .deInit = P2pDeinit,
53 };
54
WiFiModuleTestSetEnv(void)55 static int32_t WiFiModuleTestSetEnv(void)
56 {
57 g_hdfWlanModuleCfg = &g_moduleData1.wlanConfig.moduleConfig;
58 if (g_hdfWifiModule == NULL) {
59 int ret;
60 g_hdfWifiModule = OsalMemCalloc(sizeof(struct WifiModule));
61 if (g_hdfWifiModule == NULL) {
62 HDF_LOGE("%s:oom", __func__);
63 return HDF_FAILURE;
64 }
65 ret = InitWifiModule(g_hdfWifiModule, g_hdfWlanModuleCfg);
66 if (ret != HDF_SUCCESS) {
67 HDF_LOGE("%s:Init WifiModule failed!ret=%d", __func__, ret);
68 OsalMemFree(g_hdfWifiModule);
69 g_hdfWifiModule = NULL;
70 return ret;
71 }
72 }
73 return HDF_SUCCESS;
74 }
75
WiFiModuleTestCreateModule(void)76 int32_t WiFiModuleTestCreateModule(void)
77 {
78 int32_t ret;
79 struct WifiModule *module = NULL;
80 ret = WiFiModuleTestSetEnv();
81 if (ret != HDF_SUCCESS) {
82 HDF_LOGE("%s:WiFiModuleTestSetEnv failed.ret=%d", __func__, ret);
83 return ret;
84 }
85 module = OsalMemCalloc(sizeof(struct WifiModule));
86 if (module == NULL) {
87 HDF_LOGE("%s fail WifiModuleCreate FAIL ", __func__);
88 return HDF_FAILURE;
89 }
90
91 ret = InitWifiModule(module, g_hdfWlanModuleCfg);
92 if (ret != HDF_SUCCESS) {
93 HDF_LOGE("%s:Init WifiModule failed!ret=%d", __func__, ret);
94 OsalMemFree(module);
95 return ret;
96 }
97 OsalMemFree(module);
98 module = NULL;
99
100 return HDF_SUCCESS;
101 }
102
WiFiModuleTestAddFeature(void)103 int32_t WiFiModuleTestAddFeature(void)
104 {
105 struct WifiModule *module = HdfWlanGetModule();
106 if (module == NULL) {
107 HDF_LOGE("%s:Cannot get module!", __func__);
108 return HDF_FAILURE;
109 }
110 if (module->iface.addFeature == NULL) {
111 HDF_LOGE("%s:bad module found!", __func__);
112 return HDF_FAILURE;
113 }
114 return module->iface.addFeature(module, HDF_WIFI_FEATURE_P2P, &g_p2pFeature);
115 }
116
WiFiModuleTestDelFeature(void)117 int32_t WiFiModuleTestDelFeature(void)
118 {
119 struct WifiModule *module = HdfWlanGetModule();
120 if (module == NULL) {
121 HDF_LOGE("%s:Cannot get module!", __func__);
122 return HDF_FAILURE;
123 }
124 if (module->iface.delFeature == NULL) {
125 HDF_LOGE("%s:bad module found!", __func__);
126 return HDF_FAILURE;
127 }
128 return module->iface.delFeature(module, HDF_WIFI_FEATURE_P2P);
129 }
130
WiFiModuleTestDeleteModule(void)131 int32_t WiFiModuleTestDeleteModule(void)
132 {
133 int ret = WiFiModuleTestSetEnv();
134 if (ret != HDF_SUCCESS) {
135 HDF_LOGE("%s:Set env failed!", __func__);
136 return ret;
137 }
138 OsalMemFree(g_hdfWifiModule);
139 g_hdfWifiModule = NULL;
140 return HDF_SUCCESS;
141 }