• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 /* ****************************************************************************
20   1 头文件包含
21 **************************************************************************** */
22 #include "oam_ext_if.h"
23 #include "oal_ext_if.h"
24 #include "wal_main.h"
25 #include "mac_device.h"
26 #include "mac_resource.h"
27 #include "mac_regdomain.h"
28 #include "mac_vap.h"
29 #include "hmac_device.h"
30 #include "hmac_vap.h"
31 #include "hmac_rx_filter.h"
32 #include "hmac_chan_mgmt.h"
33 #include "hmac_rx_filter.h"
34 #include "hmac_config.h"
35 #include "hmac_device.h"
36 #include "hmac_scan.h"
37 #include "hmac_rx_data.h"
38 
39 #ifdef __cplusplus
40 #if __cplusplus
41 extern "C" {
42 #endif
43 #endif
44 
45 /* ****************************************************************************
46   2 全局变量定义
47 **************************************************************************** */
48 hmac_device_stru g_hmac_device;
49 
50 /* ****************************************************************************
51   3 函数实现
52 **************************************************************************** */
53 /* ****************************************************************************
54  功能描述  : 获取对应HMAC DEVICE全局变量
55 **************************************************************************** */
hmac_get_device_stru(hi_void)56 hmac_device_stru *hmac_get_device_stru(hi_void)
57 {
58     return &g_hmac_device;
59 }
60 
61 /* ****************************************************************************
62  功能描述  : 去初始化hmac device级别参数
63  修改历史      :
64   1.日    期   : 2015年1月31日
65     作    者   : HiSilicon
66     修改内容   : 新生成函数
67 **************************************************************************** */
hmac_device_exit(hi_void)68 hi_u32 hmac_device_exit(hi_void)
69 {
70     mac_device_stru             *mac_dev = HI_NULL;
71     hmac_device_stru            *hmac_dev = HI_NULL;
72     hi_u32                       return_code;
73     hmac_vap_stru               *hmac_vap = HI_NULL;
74     mac_cfg_down_vap_param_stru  down_vap = {0};
75     const hi_u8                 vap_idx = 0;
76 
77     hmac_dev = hmac_get_device_stru();
78     /* 扫描模块去初始化 */
79     hmac_scan_exit(hmac_dev);
80 #ifdef _PRE_WLAN_FEATURE_PKT_MEM_OPT
81     hmac_pkt_mem_opt_exit(hmac_dev);
82 #endif
83 
84     /* 由于配置vap初始化在HMAC做,所以配置VAP卸载也在HMAC做 */
85     hmac_vap = hmac_vap_get_vap_stru(WLAN_CFG_VAP_ID);
86     if (hmac_vap == HI_NULL) {
87         oam_error_log0(0, OAM_SF_ANY, "{hmac_device_exit::pst_vap null.}");
88         return HI_ERR_CODE_PTR_NULL;
89     }
90     return_code = hmac_config_del_vap(hmac_vap->base_vap, sizeof(mac_cfg_down_vap_param_stru), (hi_u8 *)&down_vap);
91     if (return_code != HI_SUCCESS) {
92         oam_warning_log1(0, OAM_SF_ANY, "{hmac_device_exit::hmac_config_del_vap failed[%d].}", return_code);
93         return return_code;
94     }
95     mac_dev = mac_res_get_dev();
96     while (mac_dev->auc_vap_id[0] != 0) {
97         hmac_vap = hmac_vap_get_vap_stru(mac_dev->auc_vap_id[vap_idx]);
98         if (hmac_vap == HI_NULL) {
99             oam_error_log0(0, OAM_SF_ANY, "{hmac_device_exit::hmac_vap null.}");
100             return HI_ERR_CODE_PTR_NULL;
101         }
102         return_code = hmac_vap_destroy(hmac_vap);
103         if (return_code != HI_SUCCESS) {
104             oam_warning_log1(0, OAM_SF_ANY, "{hmac_device_exit::hmac_vap_destroy failed[%d].}", return_code);
105             return return_code;
106         }
107     }
108     /* 卸载用户资源 */
109     hmac_user_res_exit();
110     /* 卸载VAP资源 */
111     hmac_vap_res_exit();
112 
113     return HI_SUCCESS;
114 }
115 
116 /* ****************************************************************************
117  函 数 名  : hmac_cfg_vap_init
118  功能描述  : 配置VAP初始化
119  输入参数  : uc_dev_id: 设备id
120  返 回 值  : 错误码
121  修改历史      :
122   1.日    期   : 2013年1月15日
123     作    者   : HiSilicon
124     修改内容   : 新生成函数
125 **************************************************************************** */
hmac_cfg_vap_init(const mac_device_stru * mac_dev)126 static hi_u32 hmac_cfg_vap_init(const mac_device_stru *mac_dev)
127 {
128     hi_u32           ret;
129     hmac_vap_stru   *hmac_vap = HI_NULL;
130     hi_u8            vap_idx;
131 
132     /* 初始化流程中,只初始化配置vap,其他vap需要通过配置添加 配置vap id必须为0 否则异常 */
133     vap_idx = mac_vap_alloc_vap_res();
134     if (oal_unlikely(vap_idx != WLAN_CFG_VAP_ID)) {
135         oam_error_log1(0, OAM_SF_CFG, "{hmac_cfg_vap_init::alloc_vap_res fail. id=[%d].}", vap_idx);
136         return HI_FAIL;
137     }
138 
139     hmac_vap = hmac_vap_get_vap_stru(WLAN_CFG_VAP_ID);
140     if (hmac_vap == HI_NULL) {
141         oam_error_log0(WLAN_CFG_VAP_ID, OAM_SF_ANY, "{hmac_cfg_vap_init::pst_vap null.}");
142         return HI_ERR_CODE_PTR_NULL;
143     }
144 
145     mac_cfg_add_vap_param_stru param = { 0 }; /* 构造配置VAP参数结构体 */
146     param.vap_mode = WLAN_VAP_MODE_CONFIG;
147     ret = hmac_vap_init(hmac_vap, WLAN_CFG_VAP_ID, &param);
148     if (ret != HI_SUCCESS) {
149         oam_error_log1(WLAN_CFG_VAP_ID, OAM_SF_ANY, "{hmac_cfg_vap_init::hmac_vap_init failed[%d].}", ret);
150         return ret;
151     }
152 
153 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
154     /* 此时dmac未上电,帧过滤无法下发 */
155 #else
156     /* 设置帧过滤寄存器 */
157     hmac_set_rx_filter_value(hmac_vap->base_vap);
158 #endif
159 
160     ret = hmac_vap_creat_netdev(hmac_vap, WLAN_CFG_VAP_NAME, (hi_s8 *)(mac_dev->auc_hw_addr), WLAN_MAC_ADDR_LEN);
161     if (ret != HI_SUCCESS) {
162         oam_error_log1(WLAN_CFG_VAP_ID, OAM_SF_ANY, "{hmac_cfg_vap_init::hmac_vap_creat_netdev failed[%d].}", ret);
163         return ret;
164     }
165 
166 #if (_PRE_MULTI_CORE_MODE == _PRE_MULTI_CORE_MODE_OFFLOAD_DMAC)
167     ret = hmac_cfg_vap_send_event(mac_dev);
168     if (oal_unlikely(ret != HI_SUCCESS)) {
169         oam_warning_log1(0, OAM_SF_CFG, "{hmac_cfg_vap_send_event::hmac_config_send_event fail[%d].", ret);
170         return ret;
171     }
172 #endif
173 
174     return HI_SUCCESS;
175 }
176 
177 /* ****************************************************************************
178  功能描述  : 初始化hmac device级别参数
179  修改历史      :
180   1.日    期   : 2015年1月31日
181     作    者   : HiSilicon
182     修改内容   : 新生成函数
183 **************************************************************************** */
hmac_device_init(hi_void)184 hi_u32 hmac_device_init(hi_void)
185 {
186     mac_device_stru     *mac_dev = HI_NULL;
187     hmac_device_stru    *hmac_dev = HI_NULL;
188     hi_u32           ret;
189 
190     mac_dev = mac_res_get_dev();
191 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
192     mac_device_init(mac_dev);
193 #endif
194     hmac_dev = hmac_get_device_stru();
195     /* 结构体初始化 */
196     if (memset_s(hmac_dev, sizeof(hmac_device_stru), 0, sizeof(hmac_device_stru)) != EOK) {
197         return HI_FAIL;
198     }
199     /* 扫描模块初始化 */
200     hmac_scan_init(hmac_dev);
201     /* 初始化P2P 等待队列 */
202     hi_wait_queue_init_head(&(hmac_dev->netif_change_event));
203 
204 #ifndef _PRE_WLAN_FEATURE_AMPDU_VAP
205     /* 初始化device下的rx tx BA会话数目 */
206     hmac_dev->rx_ba_session_num = 0;
207     hmac_dev->tx_ba_session_num = 0;
208 #endif
209     /* hmac mac vap资源初始化 */
210     ret = hmac_vap_res_init();
211     if (oal_unlikely(ret != HI_SUCCESS)) {
212         oam_error_log0(0, OAM_SF_ANY, "{hmac_device_init::hmac_init_vap_res failed.}");
213         return HI_FAIL;
214     }
215     /* hmac mac user 资源初始化 */
216     ret = hmac_user_res_init();
217     if (oal_unlikely(ret != HI_SUCCESS)) {
218         oam_error_log0(0, OAM_SF_ANY, "{hmac_device_init::hmac_user_res_init failed.}");
219         return HI_FAIL;
220     }
221     /* 配置vap初始化 */
222     ret = hmac_cfg_vap_init(mac_dev);
223     if (oal_unlikely(ret != HI_SUCCESS)) {
224         oam_error_log1(0, OAM_SF_ANY, "{hmac_device_init::cfg_vap_init failed[%d].}", ret);
225         return HI_FAIL;
226     }
227     return HI_SUCCESS;
228 }
229 
230 #if (_PRE_MULTI_CORE_MODE == _PRE_MULTI_CORE_MODE_OFFLOAD_DMAC)
231 /* 功能描述  : 上下电流程中host device_stru的初始化函数 */
hmac_config_host_dev_init(mac_vap_stru * mac_vap,hi_u16 len,const hi_u8 * param)232 hi_u32 hmac_config_host_dev_init(mac_vap_stru *mac_vap, hi_u16 len, const hi_u8 *param)
233 {
234 #ifdef _PRE_WLAN_FEATURE_20_40_80_COEXIST
235     mac_device_stru     *mac_device;
236     hi_u32              ul_loop = 0;
237 #endif
238 #ifdef _PRE_WLAN_FEATURE_PKT_MEM_OPT
239     hmac_device_stru *hmac_device;
240 #endif
241     hi_unref_param(param);
242     hi_unref_param(len);
243 
244     if (mac_vap == HI_NULL) {
245         oam_error_log0(0, OAM_SF_ANY, "{hmac_device_init:: pst_mac_device NULL pointer!}");
246         return HI_FALSE;
247     }
248 
249 #ifdef _PRE_WLAN_FEATURE_20_40_80_COEXIST
250     mac_device = mac_res_get_dev();
251     if (mac_device == HI_NULL) {
252         oam_error_log0(0, OAM_SF_ANY, "{hmac_device_init:: pst_mac_device NULL pointer!}");
253         return HI_FALSE;
254     }
255 
256     for (ul_loop = 0; ul_loop < MAC_MAX_SUPP_CHANNEL; ul_loop++) {
257         mac_device->st_ap_channel_list[ul_loop].us_num_networks = 0;
258         mac_device->st_ap_channel_list[ul_loop].en_ch_type      = MAC_CH_TYPE_NONE;
259     }
260 #endif
261 
262 #ifdef _PRE_WLAN_FEATURE_PKT_MEM_OPT
263     hmac_device = hmac_get_device_stru();
264     if (oal_unlikely(hmac_device == HI_NULL)) {
265         oam_error_log0(0, OAM_SF_ANY, "{hmac_config_host_dev_init::pst_hmac_device null!}");
266         return HI_FALSE;
267     }
268     hmac_pkt_mem_opt_init(hmac_device);
269 #endif
270 
271     /* 补充上下电时候需要初始化的hmac_device_stru下的信息 */
272     return HI_SUCCESS;
273 }
274 
275 /* ****************************************************************************
276  功能描述  : 下电流程中host device_stru的去初始化函数
277 **************************************************************************** */
hmac_config_host_dev_exit(mac_vap_stru * pst_mac_vap,hi_u16 len,const hi_u8 * param)278 hi_u32 hmac_config_host_dev_exit(mac_vap_stru *pst_mac_vap, hi_u16 len, const hi_u8 *param)
279 {
280 #ifdef _PRE_WLAN_FEATURE_PKT_MEM_OPT
281     hmac_device_stru *hmac_device = hmac_get_device_stru();
282     if (oal_unlikely(hmac_device == HI_NULL)) {
283         oam_error_log0(0, OAM_SF_ANY, "{hmac_config_host_dev_exit::pst_hmac_device null!}");
284         return HI_FALSE;
285     }
286 
287     hmac_pkt_mem_opt_exit(hmac_device);
288 #endif
289 
290     hi_unref_param(pst_mac_vap);
291     hi_unref_param(len);
292     hi_unref_param(param);
293     return HI_SUCCESS;
294 }
295 #endif
296 
297 #ifdef __cplusplus
298 #if __cplusplus
299 }
300 #endif
301 #endif
302