xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852bs/include/rtw_wnm.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 
16 #ifndef __RTW_WNM_H_
17 #define __RTW_WNM_H_
18 
19 #define RTW_RRM_NB_RPT_EN		BIT(1)
20 #define RTW_MAX_NB_RPT_NUM	8
21 
22 #define RTW_WNM_FEATURE_BTM_REQ_EN		BIT(0)
23 
24 #define rtw_roam_busy_scan(a, nb)	\
25 	(((a)->mlmepriv.LinkDetectInfo.bBusyTraffic == _TRUE) && \
26 	(((a)->mlmepriv.ch_cnt) < ((nb)->nb_rpt_ch_list_num)))
27 
28 #define rtw_wnm_btm_preference_cap(a) \
29 	((a)->mlmepriv.nb_info.preference_en == _TRUE)
30 
31 #define rtw_wnm_btm_roam_triggered(a) \
32 	(((a)->mlmepriv.nb_info.preference_en == _TRUE) \
33 	&& (rtw_ft_chk_flags((a), RTW_FT_BTM_ROAM))	\
34 	)
35 
36 #define rtw_wnm_btm_diff_bss(a) \
37 	((rtw_wnm_btm_preference_cap(a)) && \
38 	(is_zero_mac_addr((a)->mlmepriv.nb_info.roam_target_addr) == _FALSE) && \
39 	(_rtw_memcmp((a)->mlmepriv.nb_info.roam_target_addr,\
40 		(a)->mlmepriv.cur_network.network.MacAddress, ETH_ALEN) == _FALSE))
41 
42 #define rtw_wnm_btm_roam_candidate(a, c) \
43 	((rtw_wnm_btm_preference_cap(a)) && \
44 	(is_zero_mac_addr((a)->mlmepriv.nb_info.roam_target_addr) == _FALSE) && \
45 	(_rtw_memcmp((a)->mlmepriv.nb_info.roam_target_addr,\
46 		(c)->network.MacAddress, ETH_ALEN)))
47 
48 #define rtw_wnm_add_btm_ext_cap(d, l)	rtw_add_ext_cap_info(d, l, BSS_TRANSITION)
49 
50 #define wnm_btm_bss_term_inc(p) (*((u8 *)((p)+3)) & BSS_TERMINATION_INCLUDED)
51 
52 #define wnm_btm_ess_disassoc_im(p) (*((u8 *)((p)+3)) & ESS_DISASSOC_IMMINENT)
53 
54 #define wnm_btm_dialog_token(p) (*((u8 *)((p)+2)))
55 
56 #define wnm_btm_query_reason(p) (*((u8 *)((p)+3)))
57 
58 #define wnm_btm_req_mode(p) (*((u8 *)((p)+3)))
59 
60 #define wnm_btm_disassoc_timer(p) (*((u16 *)((p)+4)))
61 
62 #define wnm_btm_valid_interval(p) (*((u8 *)((p)+6)))
63 
64 #define wnm_btm_term_duration_offset(p) ((p)+7)
65 
66 #define wnm_btm_rsp_status(p) (*((u8 *)((p)+3)))
67 
68 #define wnm_btm_rsp_term_delay(p) (*((u8 *)((p)+4)))
69 
70 #define RTW_WLAN_ACTION_WNM_NB_RPT_ELEM	0x34
71 
72 enum rtw_ieee80211_wnm_actioncode {
73 	RTW_WLAN_ACTION_WNM_BTM_QUERY = 6,
74 	RTW_WLAN_ACTION_WNM_BTM_REQ = 7,
75 	RTW_WLAN_ACTION_WNM_BTM_RSP = 8,
76 	RTW_WLAN_ACTION_WNM_NOTIF_REQ = 26,
77 	RTW_WLAN_ACTION_WNM_NOTIF_RSP = 27,
78 };
79 
80 /*IEEE Std 80211k Figure 7-95b Neighbor Report element format*/
81 struct nb_rpt_hdr {
82 	u8 id; /*0x34: Neighbor Report Element ID*/
83 	u8 len;
84 	u8 bssid[ETH_ALEN];
85 	u32 bss_info;
86 	u8 reg_class;
87 	u8 ch_num;
88 	u8 phy_type;
89 };
90 
91 /*IEEE Std 80211v, Figure 7-9 BSS Termination Duration subelement field format */
92 struct btm_term_duration {
93 	u8 id;
94 	u8 len;
95 	u64 tsf;		/* value of the TSF counter when BSS termination will occur in the future */
96 	u16 duration;		/* number of minutes for which the BSS is not present*/
97 };
98 
99 /*IEEE Std 80211v, Figure 7-10 BSS Transition Management Request frame body format */
100 struct btm_req_hdr {
101 	u8 dialog_token;
102 	u8 req_mode;
103 	/* number of TBTTs until the AP sends a Disassociation frame to this STA */
104 	u16 disassoc_timer;
105 	/* number of TBTTs until the BSS transition candidate list is no longer valid */
106 	u8 validity_interval;
107 	struct btm_term_duration term_duration;
108 };
109 
110 struct btm_rsp_hdr {
111 	u8 dialog_token;
112 	u8 status;
113 	/* the number of minutes that
114 		the responding STA requests the BSS to delay termination */
115 	u8 termination_delay;
116 	u8 bssid[ETH_ALEN];
117 	u8 *pcandidates;
118 	u32 candidates_num;
119 };
120 
121 struct btm_rpt_cache {
122 	u8 dialog_token;
123 	u8 req_mode;
124 	u16 disassoc_timer;
125 	u8 validity_interval;
126 	struct btm_term_duration term_duration;
127 
128 	/* from BTM req */
129 	u32 validity_time;
130 	u32 disassoc_time;
131 
132 	systime req_stime;
133 };
134 
135 /*IEEE Std 80211v,  Table 7-43b Optional Subelement IDs for Neighbor Report*/
136 /* BSS Transition Candidate Preference */
137 #define WNM_BTM_CAND_PREF_SUBEID 0x03
138 
139 /* BSS Termination Duration */
140 #define WNM_BTM_TERM_DUR_SUBEID		0x04
141 
142 struct wnm_btm_cant {
143 	struct nb_rpt_hdr nb_rpt;
144 	u8 preference;	/* BSS Transition Candidate Preference */
145 };
146 
147 enum rtw_btm_req_mod {
148 	PREFERRED_CANDIDATE_LIST_INCLUDED = BIT0,
149 	ABRIDGED = BIT1,
150 	DISASSOC_IMMINENT = BIT2,
151 	BSS_TERMINATION_INCLUDED = BIT3,
152 	ESS_DISASSOC_IMMINENT = BIT4,
153 };
154 
155 struct roam_nb_info {
156 	struct nb_rpt_hdr nb_rpt[RTW_MAX_NB_RPT_NUM];
157 	struct rtw_ieee80211_channel nb_rpt_ch_list[RTW_MAX_NB_RPT_NUM];
158 	struct btm_rpt_cache btm_cache;
159 	bool	nb_rpt_valid;
160 	u8	nb_rpt_ch_list_num;
161 	u8 preference_en;
162 	u8 roam_target_addr[ETH_ALEN];
163 	u32	last_nb_rpt_entries;
164 	u8 nb_rpt_is_same;
165 	s8 disassoc_waiting;
166 	_timer roam_scan_timer;
167 	_timer disassoc_chk_timer;
168 
169 	u32 features;
170 };
171 
172 u8 rtw_wnm_btm_reassoc_req(_adapter *padapter);
173 
174 void rtw_wnm_roam_scan_hdl(void *ctx);
175 
176 void rtw_wnm_disassoc_chk_hdl(void *ctx);
177 
178 u8 rtw_wnm_try_btm_roam_imnt(_adapter *padapter);
179 
180 void rtw_wnm_process_btm_query(_adapter *padapter,
181 	u8* pframe, u32 frame_len);
182 
183 void rtw_wnm_process_btm_req(_adapter *padapter,
184 	u8* pframe, u32 frame_len);
185 
186 void rtw_wnm_process_notification_req(
187 	_adapter *padapter, u8* pframe, u32 frame_len);
188 
189 void rtw_wnm_reset_btm_candidate(struct roam_nb_info *pnb);
190 
191 void rtw_wnm_reset_btm_state(_adapter *padapter);
192 
193 u32 rtw_wnm_btm_rsp_candidates_sz_get(
194 	_adapter *padapter, u8* pframe, u32 frame_len);
195 
196 void rtw_wnm_process_btm_rsp(_adapter *padapter,
197 	u8* pframe, u32 frame_len, struct btm_rsp_hdr *prsp);
198 
199 void rtw_wnm_issue_btm_req(_adapter *padapter,
200 	u8 *pmac, struct btm_req_hdr *phdr, u8 *purl, u32 url_len,
201 	u8 *pcandidates, u8 candidate_cnt);
202 
203 void rtw_wnm_reset_btm_cache(_adapter *padapter);
204 
205 void rtw_wnm_issue_action(_adapter *padapter, u8 action, u8 reason, u8 dialog);
206 
207 void rtw_wnm_update_reassoc_req_ie(_adapter *padapter);
208 
209 void rtw_roam_nb_info_init(_adapter *padapter);
210 
211 u8 rtw_roam_nb_scan_list_set(_adapter *padapter,
212 	struct sitesurvey_parm *pparm);
213 
214 u32 rtw_wnm_btm_candidates_survey(_adapter *padapter,
215 	u8* pframe, u32 elem_len, u8 is_preference);
216 #endif /* __RTW_WNM_H_ */
217 
218