• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * 文 件 名   : hmac_roam_alg.h
15  * 生成日期   : 2015年3月18日
16  * 功能描述   : hmac_roam_alg.c 的头文件
17  */
18 
19 
20 #ifndef __HMAC_ROAM_ALG_H__
21 #define __HMAC_ROAM_ALG_H__
22 
23 #include "hmac_roam_connect.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif
30 
31 /*****************************************************************************
32   1 其他头文件包含
33 *****************************************************************************/
34 
35 
36 #undef  THIS_FILE_ID
37 #define THIS_FILE_ID OAM_FILE_ID_HMAC_ROAM_ALG_H
38 /*****************************************************************************
39   2 宏定义
40 *****************************************************************************/
41 #define ROAM_LIST_MAX                     (4)          /* 名单规格 */
42 #define ROAM_BLACKLIST_NORMAL_AP_TIME_OUT (30000)      /* 黑名单正常超时时间 */
43 #define ROAM_BLACKLIST_REJECT_AP_TIME_OUT (30000)      /* 黑名单拒绝模式超时时间 */
44 #define ROAM_BLACKLIST_COUNT_LIMIT        (1)           /* 黑名单超时次数限制 */
45 
46 #define ROAM_HISTORY_BSS_TIME_OUT         (20000)       /* 历史优选名单超时时间 */
47 #define ROAM_HISTORY_COUNT_LIMIT          (1)           /* 历史优选超时次数限制 */
48 #define ROAM_RSSI_LEVEL                   (3)
49 #define ROAM_CONCURRENT_USER_NUMBER       (10)
50 #define ROAM_THROUGHPUT_THRESHOLD         (1000)
51 
52 #define ROAM_RSSI_NE80_DB                 (-80)
53 #define ROAM_RSSI_NE75_DB                 (-75)
54 #define ROAM_RSSI_NE70_DB                 (-70)
55 #define ROAM_RSSI_NE68_DB                 (-68)
56 
57 #define ROAM_RSSI_DIFF_4_DB               (4)
58 #define ROAM_RSSI_DIFF_6_DB               (6)
59 #define ROAM_RSSI_DIFF_8_DB               (8)
60 #define ROAM_RSSI_DIFF_10_DB              (10)
61 
62 #define ROAM_RSSI_CMD_TYPE                (-128)
63 #define ROAM_RSSI_LINKLOSS_TYPE           (-121)
64 #define ROAM_RSSI_MAX_TYPE                (-126)
65 
66 #define ROAM_TRIGGER_COUNT_THRESHOLD (5)
67 #define ROAM_TRIGGER_RSSI_NE80_DB (-80)
68 #define ROAM_TRIGGER_RSSI_NE75_DB (-75)
69 #define ROAM_TRIGGER_RSSI_NE70_DB (-70)
70 #define ROAM_TRIGGER_INTERVAL_10S (10 * 1000)
71 #define ROAM_TRIGGER_INTERVAL_15S (15 * 1000)
72 #define ROAM_TRIGGER_INTERVAL_20S (20 * 1000)
73 #define ROAM_WPA_CONNECT_INTERVAL_TIME (5 * 1000) /* 漫游与正常关联之间的时间间隔,WIFI+ 上层切换频繁 */
74 
75 /*****************************************************************************
76   3 枚举定义
77 *****************************************************************************/
78 /* 漫游黑名单类型 */
79 typedef enum {
80     ROAM_BLACKLIST_TYPE_NORMAL_AP       = 0,
81     ROAM_BLACKLIST_TYPE_REJECT_AP       = 1,
82     ROAM_BLACKLIST_TYPE_BUTT
83 } roam_blacklist_type_enum;
84 typedef osal_u8  roam_blacklist_type_enum_uint8;
85 
86 /* 漫游触发条件 */
87 typedef enum {
88     ROAM_TRIGGER_DMAC                 = 0,
89     ROAM_TRIGGER_APP                  = 1,
90     ROAM_TRIGGER_COEX                 = 2,
91     ROAM_TRIGGER_11V                  = 3,
92 
93     ROAM_TRIGGER_BUTT
94 } roam_trigger_condition_enum;
95 typedef osal_u8 roam_trigger_enum_uint8;
96 
97 /* DMAC触发的漫游场景类型 */
98 typedef enum {
99     ROAM_ENV_SPARSE_AP            = 0,  /* default AP roaming environment, based on [-78, -74] RSSI threshold */
100     ROAM_ENV_LINKLOSS             = 1,
101     ROAM_ENV_DENSE_AP             = 2,  /* dense AP roaming environment, based on [-72, -68] RSSI threshold */
102 
103     ROAM_ENV_BUTT
104 } roam_scenario_enum;
105 typedef osal_u8 roam_scenario_enum_uint8;
106 
107 /* 漫游主状态机状态 */
108 typedef enum {
109     ROAM_MAIN_STATE_INIT               = 0,
110     ROAM_MAIN_STATE_FAIL               = ROAM_MAIN_STATE_INIT,
111     ROAM_MAIN_STATE_SCANING            = 1,
112     ROAM_MAIN_STATE_CONNECTING         = 2,
113     ROAM_MAIN_STATE_UP                 = 3,
114 
115     ROAM_MAIN_STATE_BUTT
116 } roam_main_state_enum;
117 typedef osal_u8  roam_main_state_enum_uint8;
118 
119 /* 漫游主状态机事件类型 */
120 typedef enum {
121     ROAM_MAIN_FSM_EVENT_START          = 0,
122     ROAM_MAIN_FSM_EVENT_SCAN_RESULT    = 1,
123     ROAM_MAIN_FSM_EVENT_START_CONNECT  = 2,
124     ROAM_MAIN_FSM_EVENT_CONNECT_FAIL   = 3,
125     ROAM_MAIN_FSM_EVENT_HANDSHAKE_FAIL = 4,
126     ROAM_MAIN_FSM_EVENT_CONNECT_SUCC   = 5,
127     ROAM_MAIN_FSM_EVENT_TIMEOUT        = 6,
128     ROAM_MAIN_FSM_EVENT_TYPE_BUTT
129 } roam_main_fsm_event_type_enum;
130 
131 /* 漫游扫描信道正交属性参数,命令行传入 */
132 typedef enum {
133     ROAM_SCAN_CHANNEL_ORG_0       = 0, /* no scan */
134     ROAM_SCAN_CHANNEL_ORG_1       = 1, /* scan only one channel */
135     ROAM_SCAN_CHANNEL_ORG_3       = 2, /* 2.4G channel 1\6\11 */
136     ROAM_SCAN_CHANNEL_ORG_4       = 3, /* 2.4G channel 1\5\7\11 */
137     ROAM_SCAN_CHANNEL_ORG_BUTT
138 } roam_channel_org_enum;
139 typedef osal_u8  roam_channel_org_enum_uint8;
140 
141 typedef enum {
142     WPAS_CONNECT_STATE_INIT = 0,
143     WPAS_CONNECT_STATE_START = 1,
144     WPAS_CONNECT_STATE_ASSOCIATED = 2,
145     WPAS_CONNECT_STATE_HANDSHAKED = 3,
146     WPAS_CONNECT_STATE_IPADDR_OBTAINED = 4,
147     WPAS_CONNECT_STATE_IPADDR_REMOVED = 5,
148     WPAS_CONNECT_STATE_BUTT
149 } wpas_connect_state_enum;
150 typedef osal_u32 wpas_connect_state_enum_uint32;
151 
152 /*****************************************************************************
153   4 全局变量声明
154 *****************************************************************************/
155 
156 
157 /*****************************************************************************
158   5 消息头定义
159 *****************************************************************************/
160 
161 
162 /*****************************************************************************
163   6 消息定义
164 *****************************************************************************/
165 
166 
167 /*****************************************************************************
168   7 STRUCT定义
169 *****************************************************************************/
170 /* 漫游配置结构体 */
171 typedef struct {
172     osal_u8                       scan_band;                /* 扫描频段 */
173     roam_channel_org_enum_uint8     scan_orthogonal;          /* 扫描信道正交属性 */
174     osal_s8                        c_trigger_rssi_2g;           /* 2G时的触发门限 */
175     osal_s8                        c_trigger_rssi_5g;           /* 5G时的触发门限 */
176     osal_u8                       delta_rssi_2g;            /* 2G时的增益门限 */
177     osal_u8                       delta_rssi_5g;            /* 5G时的增益门限 */
178     osal_s8                        c_dense_env_trigger_rssi_2g; /* 密集AP环境中2G时的触发门限 */
179     osal_s8                        c_dense_env_trigger_rssi_5g; /* 密集AP环境中5G时的触发门限 */
180     oal_bool_enum_uint8             scenario_enable;          /* 是否使能场景识别 */
181     osal_s8                        c_candidate_good_rssi;       /* 密集AP场景识别,强信号强度AP的门限 */
182     osal_u8                       candidate_good_num;       /* 密集AP场景识别,强信号强度AP的数目 */
183     osal_u8                       candidate_weak_num;       /* 密集AP场景识别,弱信号强度AP的数目 */
184     osal_u32                      blacklist_expire_sec;     /* not used for now */
185     osal_u32                      buffer_max;               /* not used for now */
186 } hmac_roam_config_stru;
187 
188 /* 漫游统计结构体 */
189 typedef struct {
190     osal_u32                 trigger_rssi_cnt;             /* rssi触发漫游扫描计数 */
191     osal_u32                 trigger_linkloss_cnt;         /* linkloss触发漫游扫描计数 */
192     osal_u32                 scan_cnt;                     /* 漫游扫描次数 */
193     osal_u32                 scan_result_cnt;              /* 漫游扫描返回次数 */
194     osal_u32                 connect_cnt;                  /* 漫游连接计数 */
195     osal_u32                 roam_old_cnt;                 /* 漫游失败计数 */
196     osal_u32                 roam_new_cnt;                 /* 漫游成功计数 */
197     osal_u32                 roam_scan_fail;
198     osal_u32                 roam_eap_fail;
199 } hmac_roam_static_stru;
200 
201 typedef struct {
202     osal_u32                 time_stamp;           /* 记录黑名单时间戳 */
203     osal_u32                 timeout;              /* 记录黑名单超时时限 */
204     osal_u16                 count_limit;          /* 记录黑名单超时前的加入次数限制 */
205     osal_u16                 count;                /* 黑名单超时过程中,添加该Bssid的次数 */
206     osal_u8                  bssid[WLAN_MAC_ADDR_LEN];
207 } hmac_roam_bss_info_stru;
208 
209 /* 漫游blacklist结构体 */
210 typedef struct {
211     hmac_roam_bss_info_stru     bss[ROAM_LIST_MAX];
212 } hmac_roam_bss_list_stru;
213 
214 /* 漫游算法结构体 */
215 typedef struct {
216     hmac_roam_bss_list_stru      blacklist;          /* 漫游黑名单AP历史记录 */
217     hmac_roam_bss_list_stru      history;            /* 漫游优选AP历史记录 */
218     osal_u32                   max_capacity;       /* 记录 scan 结果的最大 capacity */
219     mac_bss_dscr_stru           *max_capacity_bss;  /* 记录 scan 结果的最大 capacity 的 bss */
220     osal_s8                     c_current_rssi;        /* 当前 dmac 触发 rssi */
221     osal_s8                     c_max_rssi;            /* 记录 scan 结果的最大 rssi */
222     osal_u8                    another_bss_scaned; /* 是否扫描到了非当前关联的 bss */
223     osal_u8                    invalid_scan_cnt;   /* 连续扫描到当前关联且首次关联的 bss 的次数 */
224     osal_u8                    candidate_bss_num;        /* 相同SSID的BSS Num总数目,包括good, weak, and roaming */
225     osal_u8                    candidate_good_rssi_num;  /* 相同SSID强信号强度的BSS Num */
226     osal_u8                    candidate_weak_rssi_num;  /* 相同SSID弱信号强度的BSS Num */
227     osal_u8                    scan_period;              /* 从高密场景向低密场景切换的扫描周期 */
228     osal_u8                    better_rssi_scan_period;  /* 有更好信号强度AP的连续扫描次数 */
229     osal_u8                    rsv[3];
230     mac_bss_dscr_stru           *max_rssi_bss;      /* 记录 scan 结果的最大 rssi 的 bss */
231 } hmac_roam_alg_stru;
232 
233 /* 漫游connect结构体 */
234 typedef struct {
235     roam_connect_state_enum_uint8   state;
236     mac_status_code_enum_uint16   status_code;
237     osal_u8                       auth_num;
238     osal_u8                       assoc_num;
239     osal_u8                       ft_num;
240     osal_u8                       ft_force_air;    /* 0:可以使用ds,1:ds失败,禁止使用ds */
241     osal_u8                       ft_failed;       /* 0:ds漫游未失败,1:ds漫游失败 */
242     frw_timeout_stru                timer;           /* 漫游connect使用的定时器 */
243     mac_bss_dscr_stru              *bss_dscr;
244 } hmac_roam_connect_stru;
245 typedef struct {
246     osal_s8                       c_rssi;
247     osal_u8                       resv;
248     osal_u16                      capacity_kbps;
249 } hmac_roam_rssi_capacity_stru;
250 
251 /* 旧bss数据结构体 */
252 typedef struct {
253     osal_u8                       bssid[WLAN_MAC_ADDR_LEN];
254     osal_u16                      sta_aid;
255     mac_cap_flag_stru               cap_flag;
256     mac_channel_stru                st_channel;
257     wlan_mib_ieee802dot11_stru      mib_info;
258     mac_user_cap_info_stru          cap_info;
259     mac_key_mgmt_stru               key_info;
260     mac_user_tx_param_stru          user_tx_info;    /* TX相关参数 */
261     mac_rate_stru                   op_rates;
262     mac_user_ht_hdl_stru            ht_hdl;
263     mac_vht_hdl_stru                vht_hdl;
264     wlan_bw_cap_enum_uint8          bandwidth_cap;
265     wlan_bw_cap_enum_uint8          avail_bandwidth;
266     wlan_bw_cap_enum_uint8          cur_bandwidth;
267     wlan_protocol_enum_uint8        protocol_mode;
268     wlan_protocol_enum_uint8        avail_protocol_mode;
269     wlan_protocol_enum_uint8        cur_protocol_mode;
270     wlan_nss_enum_uint8             user_num_spatial_stream;
271     wlan_nss_enum_uint8             avail_num_spatial_stream;
272     wlan_nss_enum_uint8             cur_num_spatial_stream;
273     wlan_nss_enum_uint8             avail_bf_num_spatial_stream;
274     osal_u16                      us_cap_info;        /* 旧的bss的能力位信息 */
275 } hmac_roam_old_bss_stru;
276 
277 typedef struct {
278     osal_s8 trigger_2g;     /* 2G漫游触发门限   */
279     osal_s8 trigger_5g;     /* 5G漫游触发门限   */
280     osal_u8 ip_addr_obtained; /* IP地址是否已获取 */
281     osal_u8 recv;             /* 保留2个字节用于对齐 */
282     osal_u32 cnt;             /* 漫游触发器计数       */
283     osal_u32 time_stamp;      /* 漫游触发器时间戳     */
284     osal_u32 ip_obtain_stamp; /* 上层获取IP地址时间戳 */
285 } hmac_vap_roam_trigger_stru;
286 
287 /* 漫游主结构体 */
288 typedef struct {
289     osal_u8                         enable;          /* 漫游使能开关 */
290     roam_trigger_enum_uint8         roam_trigger;    /* 漫游触发源 */
291     roam_main_state_enum_uint8      main_state;      /* 漫游主状态 */
292     roam_scenario_enum_uint8        rssi_type;       /* 何种rssi类型触发漫游 */
293     osal_u8                         invalid_scan_cnt;    /* 无效扫描统计 */
294     oal_bool_enum_uint8             current_bss_ignore;  /* 是否支持漫游回自己(支持驱动发起重关联) */
295     osal_u8                         ip_addr_obtained; /* IP地址是否获取 */
296     osal_u8                         linkloss_roam_done; /* 记录是否发生过漫游扫描 */
297     hmac_vap_stru                  *hmac_vap;       /* 漫游对应的vap */
298     hmac_user_stru                 *hmac_user;      /* 漫游对应的BSS user */
299     hmac_roam_old_bss_stru          old_bss;         /* 漫游之前保存旧bss相关信息 */
300     mac_scan_req_stru               scan_params;     /* 漫游扫描参数 */
301     hmac_roam_config_stru           config;          /* 漫游相关配置信息 */
302     hmac_roam_connect_stru          connect;         /* 漫游connect信息 */
303     hmac_roam_alg_stru              alg;             /* 漫游算法信息 */
304     hmac_roam_static_stru           st_static;          /* 漫游统计信息 */
305     frw_timeout_stru                timer;           /* 漫游使用的定时器 */
306     wpas_connect_state_enum_uint32  connected_state; /* 外部关联的状态进度 */
307     hmac_vap_roam_trigger_stru      trigger;         /* 实际采用的漫游触发条件 */
308 } hmac_roam_info_stru;
309 
310 /* roam hmac 同步 dmac数据结构体 */
311 typedef struct {
312     osal_u16 sta_aid;
313     osal_u16 pad;
314     mac_channel_stru channel;
315     mac_user_cap_info_stru cap_info;
316     mac_key_mgmt_stru key_info;
317     mac_user_tx_param_stru user_tx_info;
318     osal_u32 back_to_old;
319 } mac_h2d_roam_sync_stru;
320 
321 typedef osal_u32(*hmac_roam_fsm_func)(hmac_roam_info_stru *roam_info, osal_void *p_param);
322 
323 /*****************************************************************************
324   8 UNION定义
325 *****************************************************************************/
326 
327 
328 /*****************************************************************************
329   9 OTHERS定义
330 *****************************************************************************/
331 
332 
333 /*****************************************************************************
334   10 函数声明
335 *****************************************************************************/
336 osal_u32 hmac_roam_alg_add_blacklist_etc(hmac_roam_info_stru *roam_info, osal_u8 *bssid,
337     roam_blacklist_type_enum_uint8 list_type);
338 osal_u32 hmac_roam_alg_add_history_etc(hmac_roam_info_stru *roam_info, osal_u8 *bssid);
339 osal_u32 hmac_roam_alg_bss_check_etc(hmac_roam_info_stru *roam_info, mac_bss_dscr_stru *bss_dscr);
340 osal_u32 hmac_roam_alg_scan_channel_init_etc(hmac_roam_info_stru *roam_info, mac_scan_req_stru *scan_params);
341 osal_void hmac_roam_alg_init_etc(hmac_roam_info_stru *roam_info, osal_s8 c_current_rssi);
342 mac_bss_dscr_stru *hmac_roam_alg_select_bss_etc(hmac_roam_info_stru *roam_info);
343 oal_bool_enum_uint8 hmac_roam_alg_find_in_blacklist_etc(hmac_roam_info_stru *roam_info, osal_u8 *bssid);
344 oal_bool_enum_uint8 hmac_roam_alg_need_to_stop_roam_trigger_etc(hmac_roam_info_stru *roam_info);
345 osal_u32 hmac_roam_alg_bss_in_ess_etc(hmac_roam_info_stru *roam_info, mac_bss_dscr_stru *bss_dscr);
346 
347 #ifdef __cplusplus
348 #if __cplusplus
349 }
350 #endif
351 #endif
352 
353 #endif /* end of hmac_roam_alg.h */
354