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 "hmac_main.h"
23 #include "hmac_event.h"
24 #include "hmac_hcc_adapt.h"
25 #include "hmac_tx_data.h"
26 #include "hmac_rx_data.h"
27 #include "hmac_11i.h"
28 #include "hmac_mgmt_classifier.h"
29 #include "hmac_scan.h"
30 #include "hmac_blockack.h"
31 #include "frw_main.h"
32 #include "hmac_chan_mgmt.h"
33
34 #ifdef __cplusplus
35 #if __cplusplus
36 extern "C" {
37 #endif
38 #endif
39
40 /* ****************************************************************************
41 2 全局变量定义
42 **************************************************************************** */
43 #if (_PRE_MULTI_CORE_MODE == _PRE_MULTI_CORE_MODE_OFFLOAD_DMAC)
44 hmac_rxdata_thread_stru g_st_rxdata_thread;
45 #endif
46
47 /* ****************************************************************************
48 3 函数实现
49 **************************************************************************** */
50 #if (_PRE_MULTI_CORE_MODE == _PRE_MULTI_CORE_MODE_OFFLOAD_DMAC)
hmac_event_fsm_rx_adapt_subtable_register(hi_void)51 static hi_void hmac_event_fsm_rx_adapt_subtable_register(hi_void)
52 {
53 frw_event_sub_rx_adapt_table_init(g_ast_hmac_wlan_drx_event_sub_table,
54 sizeof(g_ast_hmac_wlan_drx_event_sub_table) / sizeof(frw_event_sub_table_item_stru),
55 hmac_hcc_rx_convert_netbuf_to_event_default);
56
57 frw_event_sub_rx_adapt_table_init(g_ast_hmac_wlan_crx_event_sub_table,
58 sizeof(g_ast_hmac_wlan_crx_event_sub_table) / sizeof(frw_event_sub_table_item_stru),
59 hmac_hcc_rx_convert_netbuf_to_event_default);
60
61 frw_event_sub_rx_adapt_table_init(g_ast_hmac_wlan_ctx_event_sub_table,
62 sizeof(g_ast_hmac_wlan_ctx_event_sub_table) / sizeof(frw_event_sub_table_item_stru),
63 hmac_hcc_rx_convert_netbuf_to_event_default);
64
65 frw_event_sub_rx_adapt_table_init(g_ast_hmac_wlan_misc_event_sub_table,
66 sizeof(g_ast_hmac_wlan_misc_event_sub_table) / sizeof(frw_event_sub_table_item_stru),
67 hmac_hcc_rx_convert_netbuf_to_event_default);
68
69 g_ast_hmac_wlan_drx_event_sub_table[DMAC_WLAN_DRX_EVENT_SUB_TYPE_RX_STA].p_rx_adapt_func =
70 hmac_rx_process_data_sta_rx_adapt;
71 g_ast_hmac_wlan_drx_event_sub_table[DMAC_WLAN_DRX_EVENT_SUB_TYPE_RX_AP].p_rx_adapt_func =
72 hmac_rx_process_data_sta_rx_adapt;
73
74 /* 注册HMAC模块WLAN_CRX事件子表 */
75 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_INIT].p_rx_adapt_func = hmac_rx_convert_netbuf_to_netbuf_default;
76 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_RX].p_rx_adapt_func = hmac_rx_process_mgmt_event_rx_adapt;
77 #ifdef _PRE_WLAN_FEATURE_FLOWCTL
78 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_FLOWCTL_BACKP].p_rx_adapt_func = hmac_alg_flowctl_backp_rx_adapt;
79 #endif
80
81 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_SCAN_RESULT].p_rx_adapt_func =
82 hmac_rx_convert_netbuf_to_netbuf_default;
83 #ifdef _PRE_WLAN_RF_110X_CALI_DPD
84 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_DPD_DATA_SEND].p_rx_adapt_func =
85 hmac_rx_convert_netbuf_to_netbuf_default;
86 #endif
87 #ifdef _PRE_WLAN_FEATURE_WOW
88 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_DEV_SYNC_HOST].p_rx_adapt_func =
89 hmac_rx_convert_netbuf_to_netbuf_default;
90 #endif
91 #ifdef _PRE_WLAN_FEATURE_PROMIS
92 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_EVENT_PROMIS].p_rx_adapt_func =
93 hmac_rx_process_mgmt_event_rx_adapt;
94 #endif
95 }
96
hmac_event_fsm_action_subtable_register(hi_void)97 static hi_void hmac_event_fsm_action_subtable_register(hi_void)
98 {
99 /* 将事件类型和调用函数的数组注册到事件调度模块 */
100 /* 注册WLAN_DTX事件子表 */
101 g_ast_hmac_wlan_dtx_event_sub_table[DMAC_TX_WLAN_DTX].func = hmac_tx_wlan_to_wlan_ap;
102
103 /* AP模式,注册HMAC模块WLAN_DRX事件子表 */
104 g_ast_hmac_wlan_drx_event_sub_table[DMAC_WLAN_DRX_EVENT_SUB_TYPE_RX_AP].func = hmac_rx_process_data_ap;
105
106 /* STA模式,注册HMAC模块WLAN_DRX事件子表 */
107 g_ast_hmac_wlan_drx_event_sub_table[DMAC_WLAN_DRX_EVENT_SUB_TYPE_RX_STA].func = hmac_rx_process_data_sta;
108
109 /* AP 和STA 公共,注册HMAC模块WLAN_DRX事件子表 */
110 g_ast_hmac_wlan_drx_event_sub_table[DMAC_WLAN_DRX_EVENT_SUB_TYPE_TKIP_MIC_FAILE].func =
111 hmac_rx_tkip_mic_failure_process;
112
113 /* 注册HMAC模块WLAN_CRX事件子表 */
114 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_INIT].func = hmac_init_event_process;
115 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_RX].func = hmac_rx_process_mgmt_event;
116 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_DELBA].func = hmac_mgmt_rx_delba_event;
117 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_SCAN_RESULT].func = hmac_scan_proc_scanned_bss;
118 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_SCAN_COMP].func = hmac_scan_proc_scan_comp_event;
119 #ifdef _PRE_WLAN_FEATURE_FLOWCTL
120 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_FLOWCTL_BACKP].func = hmac_flowctl_backp_event;
121 #endif
122 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_DISASSOC].func = hmac_mgmt_send_disasoc_deauth_event;
123 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_DEAUTH].func = hmac_mgmt_send_disasoc_deauth_event;
124 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_CH_SWITCH_COMPLETE].func = hmac_chan_switch_to_new_chan_complete;
125 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_DBAC].func = hmac_dbac_status_notify;
126 #ifdef _PRE_WLAN_RF_110X_CALI_DPD
127 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_DPD_DATA_SEND].func = hmac_dpd_cali_data_recv;
128 #endif
129 #ifdef _PRE_WLAN_FEATURE_WOW
130 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_DEV_SYNC_HOST].func = hmac_wow_proc_dev_sync_host_event;
131 #endif
132 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_CSI_REPORT].func = hmac_csi_data_report_event;
133 #ifdef _PRE_WLAN_FEATURE_PROMIS
134 g_ast_hmac_wlan_crx_event_sub_table[DMAC_WLAN_CRX_EVENT_PROMIS].func = hmac_rx_process_mgmt_promis;
135 #endif
136
137 g_ast_hmac_wlan_ctx_event_sub_table[DMAC_TO_HMAC_CREATE_BA].func = hmac_create_ba_event;
138 g_ast_hmac_wlan_ctx_event_sub_table[DMAC_TO_HMAC_DEL_BA].func = hmac_del_ba_event;
139 g_ast_hmac_wlan_ctx_event_sub_table[DMAC_TO_HMAC_SYN_CFG].func = hmac_event_config_syn;
140 #ifdef _PRE_WLAN_FEATURE_WOW
141 g_ast_hmac_wlan_misc_event_sub_table[DMAC_MISC_SUB_TYPE_DEV_READY_FOR_HOST_SLP].func =
142 hmac_wow_proc_dev_ready_slp_event;
143 #endif
144 g_ast_hmac_wlan_misc_event_sub_table[DMAC_MISC_SUB_TYPE_DISASOC].func = hmac_proc_disasoc_misc_event;
145
146 #ifdef _PRE_WLAN_FEATURE_SMP_SUPPORT
147 g_ast_hmac_host_drx_event_sub_table[HMAC_TX_HOST_DRX].func = hmac_tx_event_process;
148 frw_event_table_register(FRW_EVENT_TYPE_HOST_DRX, FRW_EVENT_PIPELINE_STAGE_0, g_ast_hmac_host_drx_event_sub_table);
149 #endif
150
151 #if (_PRE_MULTI_CORE_MODE == _PRE_MULTI_CORE_MODE_OFFLOAD_DMAC)
152 g_ast_hmac_wlan_ctx_event_sub_table[DMAC_TO_HMAC_ALG_INFO_SYN].func = hmac_syn_info_event;
153 g_ast_hmac_wlan_ctx_event_sub_table[DMAC_TO_HMAC_VOICE_AGGR].func = hmac_voice_aggr_event;
154 g_ast_hmac_wlan_ctx_event_sub_table[DMAC_TO_HMAC_PROTECTION_INFO_SYN].func = hmac_protection_info_sync_event;
155 #endif
156
157 g_ast_wal_host_crx_table[WAL_HOST_CRX_SUBTYPE_CFG].func = wal_config_process_pkt;
158 }
159 #endif
160
161 /* ****************************************************************************
162 功能描述 : hmac模块事件及其处理函数的注册函数
163 修改历史 :
164 1.日 期 : 2014年10月20日
165 作 者 : HiSilicon
166 修改内容 : 新生成函数
167 **************************************************************************** */
hmac_event_fsm_register(hi_void)168 hi_void hmac_event_fsm_register(hi_void)
169 {
170 #if (_PRE_MULTI_CORE_MODE == _PRE_MULTI_CORE_MODE_OFFLOAD_DMAC)
171 /* 注册所有事件的rx_adapt子表 */
172 hmac_event_fsm_rx_adapt_subtable_register();
173
174 /* 注册所有事件的执行函数子表 */
175 hmac_event_fsm_action_subtable_register();
176 #endif
177 hmac_event_fsm_table_register();
178 }
179
180 /* ****************************************************************************
181 功能描述 : HMAC模块初始化总入口,包含HMAC模块内部所有特性的初始化。
182 返 回 值 : 初始化返回值,成功或失败原因
183 修改历史 :
184 1.日 期 : 2012年9月18日
185 作 者 : HiSilicon
186 修改内容 : 新生成函数
187 **************************************************************************** */
hmac_main_init(hi_void)188 hi_u32 hmac_main_init(hi_void)
189 {
190 hi_u32 return_code;
191 frw_init_enum_uint8 init_state = frw_get_init_state();
192 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
193 /* offload模式下 dmac的状态无法传到host侧,故state为frw succ */
194 if ((init_state == FRW_INIT_STATE_BUTT) || (init_state < FRW_INIT_STATE_FRW_SUCC)
195 #else
196 if ((init_state == FRW_INIT_STATE_BUTT) || (init_state < FRW_INIT_STATE_DMAC_CONFIG_VAP_SUCC)
197 #endif
198 ) {
199 oam_error_log1(0, 0, "hmac_main_init:en_init_state is error %d.", init_state);
200 frw_timer_delete_all_timer();
201 return HI_FAIL;
202 }
203 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
204 return_code = mac_res_init();
205 if (return_code != HI_SUCCESS) {
206 oam_error_log1(0, OAM_SF_ANY, "hmac_main_init: mac_res_init return err code %d.", return_code);
207 frw_timer_delete_all_timer();
208 return HI_FAIL;
209 }
210 #endif
211
212 /* 如果初始化状态处于配置VAP成功前的状态,表明此次为HMAC第一次初始化,即重加载或启动初始化 */
213 if (init_state < FRW_INIT_STATE_HMAC_CONFIG_VAP_SUCC) {
214 /* 事件注册 */
215 hmac_event_fsm_register();
216 return_code = hmac_device_init();
217 if (return_code != HI_SUCCESS) {
218 oam_warning_log1(0, OAM_SF_ANY, "{hmac_main_init::hmac_device_init failed[%d].}", return_code);
219 frw_timer_delete_all_timer();
220 hmac_device_exit(); /* 统一释放hmac device资源 */
221 return return_code;
222 }
223 frw_set_init_state(FRW_INIT_STATE_HMAC_CONFIG_VAP_SUCC);
224 /* 启动成功后,输出打印 */
225 } else {
226 oam_error_log1(0, OAM_SF_ANY, "{hmac_main_init::init state error[%d].}", init_state);
227 }
228
229 #ifdef _PRE_WLAN_FEATURE_WOW
230 hmac_wow_init();
231 #endif
232
233 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
234 oal_init_netbuf_stru();
235 #endif
236
237 printk("hmac_main_init SUCCESSULLY\r\n");
238 return HI_SUCCESS;
239 }
240
241 /* ****************************************************************************
242 功能描述 : HMAC模块卸载
243 修改历史 :
244 1.日 期 : 2012年9月18日
245 作 者 : HiSilicon
246 修改内容 : 新生成函数
247 **************************************************************************** */
hmac_main_exit(hi_void)248 hi_void hmac_main_exit(hi_void)
249 {
250 hi_u32 return_code;
251
252 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
253 if (frw_get_init_state() != FRW_INIT_STATE_HAL_SUCC) {
254 oam_warning_log0(0, OAM_SF_ANY, "{hmac_main_exit::frw state error.}");
255 return;
256 }
257 #else
258 if (frw_get_init_state() != FRW_INIT_STATE_HMAC_CONFIG_VAP_SUCC) {
259 oam_warning_log0(0, OAM_SF_ANY, "{hmac_main_exit:: frw state error.}");
260 return;
261 }
262 #endif
263 return_code = hmac_device_exit();
264 if (oal_unlikely(return_code != HI_SUCCESS)) {
265 oam_warning_log1(0, OAM_SF_ANY, "{hmac_main_exit::hmac_device_exit failed[%d].}", return_code);
266 return;
267 }
268 mac_res_exit();
269 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
270 frw_set_init_state(FRW_INIT_STATE_FRW_SUCC);
271 #else
272 frw_set_init_state(FRW_INIT_STATE_DMAC_CONFIG_VAP_SUCC);
273 #endif
274 }
275
276 #if (_PRE_MULTI_CORE_MODE == _PRE_MULTI_CORE_MODE_OFFLOAD_DMAC)
hmac_get_rxthread_enable()277 hi_u8 hmac_get_rxthread_enable()
278 {
279 return g_st_rxdata_thread.rxthread_enable;
280 }
281
hmac_rxdata_netbuf_enqueue(oal_netbuf_stru * netbuf)282 hi_void hmac_rxdata_netbuf_enqueue(oal_netbuf_stru *netbuf)
283 {
284 #define NETBUG_LISET_LEN_MAX 1000
285 if (oal_netbuf_list_len(&g_st_rxdata_thread.rxdata_netbuf_head) > NETBUG_LISET_LEN_MAX) {
286 oal_netbuf_free(netbuf);
287 g_st_rxdata_thread.pkt_loss_cnt++;
288 return;
289 }
290 oal_netbuf_list_tail(&g_st_rxdata_thread.rxdata_netbuf_head, netbuf);
291 return;
292 }
293
294 /* ****************************************************************************
295 功能描述 : dmac 抛给hmac的初始化回复事件
296 输入参数 : event_mem: 事件结构体
297 **************************************************************************** */
hmac_init_event_process(frw_event_mem_stru * event_mem)298 hi_u32 hmac_init_event_process(frw_event_mem_stru *event_mem)
299 {
300 frw_event_stru *pst_event = HI_NULL; /* 事件结构体 */
301 mac_data_rate_stru *pst_data_rate = HI_NULL;
302 hi_u8 *pst_data_mac_addr = HI_NULL;
303 dmac_tx_event_stru *pst_ctx_event = HI_NULL;
304 mac_device_stru *pst_mac_device = HI_NULL;
305 hi_unref_param(pst_data_mac_addr);
306
307 if (oal_unlikely(event_mem == HI_NULL)) {
308 oam_error_log0(0, OAM_SF_ANY, "{hmac_init_event_process::event_mem null.}");
309 return HI_FALSE;
310 }
311
312 pst_event = (frw_event_stru *)event_mem->puc_data;
313
314 pst_ctx_event = (dmac_tx_event_stru *)pst_event->auc_event_data;
315 pst_data_rate = (mac_data_rate_stru *)(oal_netbuf_data((oal_netbuf_stru *)(pst_ctx_event->netbuf)));
316
317 pst_data_mac_addr = (hi_u8 *)(oal_netbuf_data((oal_netbuf_stru *)(pst_ctx_event->netbuf))) +
318 sizeof(mac_data_rate_stru) * MAC_DATARATES_PHY_80211G_NUM;
319 oal_io_print("get rates from device\n");
320 /* 同步mac支持的速率集信息 */
321 pst_mac_device = mac_res_get_dev();
322 if (pst_mac_device == HI_NULL) {
323 oam_error_log0(0, OAM_SF_ANY, "{hmac_init_event_process::pst_mac_device null.}");
324 oal_netbuf_free((oal_netbuf_stru *)pst_ctx_event->netbuf);
325 return HI_FALSE;
326 }
327 if (memcpy_s((hi_u8 *)(pst_mac_device->mac_rates_11g), sizeof(mac_data_rate_stru) * MAC_DATARATES_PHY_80211G_NUM,
328 (hi_u8 *)pst_data_rate, sizeof(mac_data_rate_stru) * MAC_DATARATES_PHY_80211G_NUM) != EOK) {
329 oam_error_log0(0, 0, "{hmac_init_event_process::mem safe func err!}");
330 return HI_FALSE;
331 }
332
333 /* 释放掉02同步消息所用的netbuf信息 */
334 oal_netbuf_free((oal_netbuf_stru *)pst_ctx_event->netbuf);
335
336 return HI_SUCCESS;
337 }
338
hmac_rxdata_sched()339 hi_void hmac_rxdata_sched()
340 {
341 oal_up(&g_st_rxdata_thread.rxdata_sema);
342 return;
343 }
344 #endif
345
346
347 #ifdef __cplusplus
348 #if __cplusplus
349 }
350 #endif
351 #endif
352