1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 * Description: hmac_scan_rom.c 的头文件。
15 * Create: 2020-07-03
16 */
17
18 #ifndef __HMAC_SCAN_H__
19 #define __HMAC_SCAN_H__
20
21 /*****************************************************************************
22 1 其他头文件包含
23 *****************************************************************************/
24 #include "oal_ext_if.h"
25 #include "frw_ext_if.h"
26 #include "hmac_vap.h"
27 #include "mac_device_ext.h"
28 #include "hmac_device.h"
29
30 #ifdef __cplusplus
31 #if __cplusplus
32 extern "C" {
33 #endif
34 #endif
35
36 #undef THIS_FILE_ID
37 #define THIS_FILE_ID OAM_FILE_ID_HMAC_SCAN_H
38
39 /*****************************************************************************
40 2 宏定义
41 *****************************************************************************/
42 #define HMAC_SCAN_CHANNEL_STATICS_PERIOD_US 15 /* MAC信道负载统计周期 15ms */
43 #define HMAC_SCAN_CHANNEL_MEAS_PERIOD_MS 15 /* PHY空闲信道估计窗长15ms(最大15ms) */
44 #define HMAC_SCAN_CTS_MAX_DURATION 32767
45 #define HMAC_SCAN_MAX_TIMER (60 * 1000) /* 支持最大的timer时间 */
46 #define HMAC_SCAN_CHANNEL_DWELL_TIME_MARGIN 2 /* ms */
47 #define HMAC_SCAN_P2PGO_SEND_BEACON_TIME 10 /* ms, go tbtt中断后过多久切信道 */
48 #define HMAC_SCAN_DBAC_SCAN_DELTA_TIME 1500 /* ms */
49 #define HMAC_SCAN_GO_MAX_SCAN_TIME 300 /* ms */
50 #define HMAC_SCAN_CHANENL_NUMS_TO_PRINT_SWITCH_INFO 14 /* 扫描信道数少于此才打印出切换到XX信道的信息 */
51 #define HMAC_SCAN_TIMER_DEVIATION_TIME 20 /* 扫描定时器的执行误差时间ms */
52 #define MSEC_TO_SEC 1000
53 #define HMAC_SCAN_SHIFT 10 /* mac扫描周期单位由1kus转换为1us */
54
55 /*****************************************************************************
56 3 枚举定义
57 *****************************************************************************/
58 typedef enum {
59 SCAN_CHECK_ASSOC_CHANNEL_LINKLOSS = 0,
60 SCAN_CHECK_ASSOC_CHANNEL_CSA = 1,
61
62 SCAN_CHECK_ASSOC_CHANNEL_BUTT
63 } scan_check_assoc_channel_enum;
64 typedef osal_u8 scan_check_assoc_channel_enum_uint8;
65
66 /*****************************************************************************
67 7 STRUCT定义
68 *****************************************************************************/
69 typedef osal_void (*p_dmac_scan_get_ch_statics_measurement_result_cb)(const hal_to_dmac_device_stru *hal_device,
70 hal_ch_statics_irq_event_stru *stats_result);
71 typedef osal_void (*p_dmac_scan_calcu_channel_ratio_cb)(hal_to_dmac_device_stru *hal_device);
72
73 typedef osal_u32 (*hmac_scan_req_entry_cb)(hmac_device_stru *hmac_device, hmac_vap_stru *hmac_vap,
74 const mac_scan_req_stru * const scan_req_params);
75
76 typedef struct {
77 p_dmac_scan_get_ch_statics_measurement_result_cb hmac_scan_get_ch_statics_measurement_result;
78 p_dmac_scan_calcu_channel_ratio_cb hmac_scan_calcu_channel_ratio;
79 } hmac_scan_rom_cb;
80
81 typedef struct {
82 osal_u8 channel_num_offset;
83 wlan_channel_bandwidth_enum_uint8 bandwidth;
84 } hmac_scan_chan_offset_bandwidth;
85 /*****************************************************************************
86 8 内联函数定义
87 *****************************************************************************/
88 /*****************************************************************************
89 函 数 名 : hmac_scan_get_duty_cyc_ratio
90 功能描述 : 根据信道扫描结果和空闲时长获取占空比
91 [0-1000], 越大表示信道越忙
92 理论上
93 信道测量时间 = 信道空闲时间+ //能量低于CCA门限
94 空口的干扰时间+能量高于CCA门限,但是无法解析的能量信号(临频/叠频干扰)
95 信道发送时间+自身竞争获取到的发送时间
96 信道接收时间+空口中别的节点发送的时间
97 蓝牙中断的时间(optional)//蓝牙共存时,蓝牙收发占用的时间
98 所以通过测量到的信道空闲时间就可以用来表征当前信道的繁忙度。
99 *****************************************************************************/
hmac_scan_get_duty_cyc_ratio(const wlan_scan_chan_stats_stru * chan_result,osal_u32 total_free_time_us)100 static INLINE__ osal_u32 hmac_scan_get_duty_cyc_ratio(
101 const wlan_scan_chan_stats_stru* chan_result, osal_u32 total_free_time_us)
102 {
103 return ((total_free_time_us > chan_result->total_stats_time_us) ? 0 :
104 ((chan_result->total_stats_time_us - total_free_time_us) * 1000 /
105 chan_result->total_stats_time_us));
106 }
107
108 /*****************************************************************************
109 函 数 名 : hmac_scan_get_valid_free_time
110 功能描述 : 判断每个周期的统计时间是否越界
111 *****************************************************************************/
hmac_scan_get_valid_free_time(osal_u32 trx_time,osal_u32 total_stat_time,osal_u32 total_free_time)112 static INLINE__ osal_u32 hmac_scan_get_valid_free_time(
113 osal_u32 trx_time, osal_u32 total_stat_time, osal_u32 total_free_time)
114 {
115 return ((total_stat_time >= (trx_time + total_free_time)) ? total_free_time :
116 ((total_stat_time <= trx_time) ? 0 : (total_stat_time - trx_time)));
117 }
118
119 /*****************************************************************************
120 10 函数声明
121 *****************************************************************************/
122
123 osal_u32 hmac_scan_proc_scan_complete_event(hmac_vap_stru *hmac_vap, mac_scan_status_enum_uint8 scan_rsp_status);
124 osal_u32 hmac_scan_mgmt_filter(hmac_vap_stru *hmac_vap, oal_netbuf_stru *netbuf, oal_bool_enum_uint8 *report_bss,
125 osal_u8 *go_on);
126 osal_u32 hmac_scan_check_bss_type(const osal_u8 *frame_body, const mac_scan_req_stru *scan_params);
127 osal_u32 hmac_scan_handle_scan_req_entry(hmac_device_stru *hmac_device, hmac_vap_stru *hmac_vap,
128 const mac_scan_req_stru * const scan_req_params);
129 osal_void hmac_scan_switch_channel_off(const hmac_device_stru *hmac_device);
130 oal_bool_enum_uint8 hmac_scan_switch_channel_back(hmac_device_stru *hmac_device,
131 hal_to_dmac_device_stru *hal_device);
132 osal_void hmac_switch_channel_off(hmac_device_stru *hmac_device, hmac_vap_stru *hmac_vap,
133 const mac_channel_stru * const dst_chl, osal_u16 protect_time);
134 osal_void hmac_scan_begin(hmac_device_stru *hmac_device, hal_to_dmac_device_stru *hal_device);
135 osal_void hmac_scan_end(hmac_device_stru *hmac_device);
136 osal_void hmac_scan_prepare_end(hmac_device_stru *hmac_device, hal_to_dmac_device_stru *hal_device);
137 osal_void hmac_scan_abort(hmac_device_stru *hmac_device);
138
139 /* 中断事件处理函数 */
140 osal_s32 hmac_scan_channel_statistics_complete(hmac_vap_stru *hmac_vap, frw_msg *msg);
141 /* 初始化及释放函数 */
142 osal_u32 hmac_scan_init(hmac_device_stru *hmac_device);
143
144 /* 外部函数引用 */
145 osal_u32 hmac_scan_send_probe_req_frame(hmac_vap_stru *hmac_vap, const osal_u8 *bssid,
146 const osal_char *ssid, osal_u32 ssid_len, osal_u8 is_send_cap_ie);
147 osal_void hmac_dbac_switch_channel_off(hmac_device_stru *hmac_device, hmac_vap_stru *mac_vap1, hmac_vap_stru *mac_vap2,
148 const mac_channel_stru *dst, osal_u16 protect_time);
149 osal_void hmac_scan_switch_home_channel_work(hmac_device_stru *hmac_device, hal_to_dmac_device_stru *hal_device);
150 osal_void hmac_scan_handle_switch_channel_back(hmac_device_stru *hmac_device, hal_to_dmac_device_stru *hal_device,
151 const hal_scan_params_stru *hal_scan_params);
152 osal_void hmac_scan_calcu_channel_ratio(hal_to_dmac_device_stru *hal_device);
153 osal_void hmac_scan_one_channel_start(hal_to_dmac_device_stru *hal_device, oal_bool_enum_uint8 is_scan_start);
154
155 /* 扫描入口钩子 */
156 osal_u32 hmac_scan_handle_scan_req_entry_ext(hmac_device_stru *hmac_device, hmac_vap_stru *hmac_vap,
157 const mac_scan_req_stru * const scan_req_params, osal_u8 *continue_flag);
158
159 /*****************************************************************************
160 2 宏定义
161 *****************************************************************************/
162
163 /* 扫描到的bss的老化时间,小于此值,下发新扫描请求时,不删除此bss信息 */
164 #define HMAC_SCAN_MAX_SCANNED_BSS_EXPIRE 25000 /* 25000 milliseconds */
165
166 /* 扫描结果中有效性高的时间范围,可用于漫游目标的挑选等操作 */
167 #define HMAC_SCAN_MAX_VALID_SCANNED_BSS_EXPIRE 5000 /* 5000 milliseconds */
168
169 /* 扫描结果中DFS信道有效性高的时间范围,可用于漫游目标的挑选等操作 */
170 #define HMAC_SCAN_MAX_VALID_SCANNED_DFS_EXPIRE 15000 /* 15000 milliseconds */
171
172 /* 扫描到的bss的rssi老化时间 */
173 #define HMAC_SCAN_MAX_SCANNED_RSSI_EXPIRE 1000 /* 1000 milliseconds */
174
175 #define HMAC_INIT_SCAN_TIMEOUT_MS 10000
176 /* 扫描到的bss的rssi信号门限,门限以下不考虑对obss的影响 */
177 #define HMAC_OBSS_RSSI_TH (-85)
178
179 /* multi bssid场景中,maxbssid_indicator最大规格为8 */
180 #define HMAC_MULTI_MAX_BSSID_INDICATOR 8
181
182 /* 在Multiple BSSID-Index element中包含DTIM count/period字段的时候,其element len长度为3 */
183 #define MULTI_DTIM_PERIOD_COUNT_LEN 3
184
185 #define EXT_CAPA_GET_MULTI_BSSID_LEN 2
186
187 #define MULTI_BSSID_ELEMENT_MIN_LEN 5
188
189 typedef enum {
190 SCAN_RANDOM_CLOSE = 0,
191 SCAN_RANDOM_WITH_OUI = 1,
192 SCAN_RANDOM_FORCE = 2,
193 SCAN_RANDOM_MAX
194 } scan_random_mac_type;
195
196 typedef struct {
197 mac_scanned_all_bss_info *all_bss_info;
198
199 osal_u8 dtim_period;
200 osal_u8 dtim_count;
201 osal_u8 period_count_valid;
202 osal_u8 resv;
203 } hmac_scanned_bssid_index_info;
204
205 /* 存储单个nontrans_bssid_profile信息 */
206 typedef struct {
207 struct osal_list_head dlist_head; /* 链表指针 */
208 osal_u8 bssid_profile[WLAN_MGMT_NETBUF_SIZE];
209 osal_u32 frame_len;
210 } hmac_scanned_nontrans_bssid_info;
211
212 /*****************************************************************************
213 10 函数声明
214 *****************************************************************************/
215 /* HMAC SCAN对外接口 */
216 osal_void hmac_scan_print_scanned_bss_info_etc(osal_u8 device_id);
217
218 mac_bss_dscr_stru *hmac_scan_find_scanned_bss_dscr_by_index_etc(osal_u8 device_id,
219 osal_u32 bss_index);
220 hmac_scanned_bss_info *hmac_scan_find_scanned_bss_by_bssid_etc(hmac_bss_mgmt_stru *bss_mgmt,
221 const osal_u8 *bssid);
222 osal_void *hmac_scan_get_scanned_bss_by_bssid(hmac_vap_stru *hmac_vap, osal_u8 *mac_addr);
223 hmac_scanned_bss_info *hmac_scan_alloc_scanned_bss(osal_u32 mgmt_len);
224 osal_u32 hmac_scan_get_scanned_bss_item_by_bssid(hmac_vap_stru *hmac_vap, osal_u8 *addr,
225 hmac_scanned_bss_info *bss_buf, osal_u16 buf_size);
226 osal_void hmac_scan_clean_scan(hmac_scan_stru *scan);
227 osal_u32 hmac_scan_proc_scan_req_event_exception_etc(hmac_vap_stru *hmac_vap, osal_void *p_params);
228 osal_u32 hmac_scan_proc_scan_req_event_etc(hmac_vap_stru *hmac_vap, osal_void *p_params);
229 #ifdef _PRE_WLAN_FEATURE_PNO_SCAN
230 osal_u32 hmac_scan_proc_sched_scan_req_event_etc(hmac_vap_stru *hmac_vap, osal_void *p_params);
231
232 /* 停止定时器 */
233 osal_void hmac_scan_stop_pno_sched_scan_timer(mac_pno_sched_scan_mgmt_stru *pno_mgmt);
234 #endif
235
236 osal_void hmac_scan_init_etc(hmac_device_stru *hmac_device);
237 osal_void hmac_scan_exit_etc(hmac_device_stru *hmac_device);
238 osal_s32 hmac_scan_process_chan_result_event_etc(hmac_crx_chan_result_stru *chan_result_param);
239 osal_s32 hmac_scan_proc_scan_comp_event_etc(hmac_vap_stru *hmac_vap, mac_scan_rsp_stru *scan_rsp_info);
240 #ifdef _PRE_WLAN_FEATURE_WS92_MERGE
241 osal_s32 hmac_scan_clean_result(hmac_vap_stru *hmac_vap, frw_msg *msg);
242 osal_s32 hmac_scan_handle_app_service(hmac_vap_stru *hmac_vap, frw_msg *msg);
243 #endif
244 osal_void hmac_scan_handle_channel_randomzie(mac_scan_req_stru *scan_params, osal_u8 channel_num_5g,
245 osal_u8 channel_num_2g);
246 osal_void hmac_scan_set_sour_mac_addr_in_probe_req_etc(hmac_vap_stru *hmac_vap,
247 osal_u8 *sour_mac_addr, oal_bool_enum_uint8 is_rand_mac_scan);
248 osal_u32 hmac_scan_proc_check_ssid(const osal_u8 *ssid, osal_u8 ssid_len);
249 osal_void hmac_scan_delete_bss(hmac_vap_stru *hmac_vap, const osal_u8 *bssid);
250 osal_s32 hmac_config_set_scan_param(hmac_vap_stru *hmac_vap, frw_msg *msg);
251 osal_void hmac_scan_set_probe_req_all_ie_cfg(osal_u8 probe_req_all_ie);
252 osal_u8 hmac_scan_get_probe_req_all_ie_cfg(osal_void);
253 osal_void hmac_scan_set_probe_req_del_wps_ie_cfg(osal_u8 probe_req_del_wps_ie);
254 osal_u8 hmac_scan_get_probe_req_del_wps_ie_cfg(osal_void);
255
256 #ifdef __cplusplus
257 #if __cplusplus
258 }
259 #endif
260 #endif
261
262 #endif /* end of hmac_scan.h */
263