xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8821cs/include/rtw_wnm.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2007 - 2017 Realtek Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  *****************************************************************************/
16 
17 #ifndef __RTW_WNM_H_
18 #define __RTW_WNM_H_
19 
20 #define RTW_RRM_NB_RPT_EN		BIT(1)
21 #define RTW_MAX_NB_RPT_NUM	8
22 
23 #define RTW_WNM_FEATURE_BTM_REQ_EN		BIT(0)
24 
25 #define rtw_roam_busy_scan(a, nb)	\
26 	(((a)->mlmepriv.LinkDetectInfo.bBusyTraffic == _TRUE) && \
27 	(((a)->mlmepriv.ch_cnt) < ((nb)->nb_rpt_ch_list_num)))
28 
29 #define rtw_wnm_btm_preference_cap(a) \
30 	((a)->mlmepriv.nb_info.preference_en == _TRUE)
31 
32 #define rtw_wnm_btm_roam_triggered(a) \
33 	(((a)->mlmepriv.nb_info.preference_en == _TRUE) \
34 	&& (rtw_ft_chk_flags((a), RTW_FT_BTM_ROAM))	\
35 	)
36 
37 #define rtw_wnm_btm_diff_bss(a) \
38 	((rtw_wnm_btm_preference_cap(a)) && \
39 	(is_zero_mac_addr((a)->mlmepriv.nb_info.roam_target_addr) == _FALSE) && \
40 	(_rtw_memcmp((a)->mlmepriv.nb_info.roam_target_addr,\
41 		(a)->mlmepriv.cur_network.network.MacAddress, ETH_ALEN) == _FALSE))
42 
43 #define rtw_wnm_btm_roam_candidate(a, c) \
44 	((rtw_wnm_btm_preference_cap(a)) && \
45 	(is_zero_mac_addr((a)->mlmepriv.nb_info.roam_target_addr) == _FALSE) && \
46 	(_rtw_memcmp((a)->mlmepriv.nb_info.roam_target_addr,\
47 		(c)->network.MacAddress, ETH_ALEN)))
48 
49 #define rtw_wnm_set_ext_cap_btm(_pEleStart, _val) \
50 	SET_BITS_TO_LE_1BYTE(((u8 *)(_pEleStart))+2, 3, 1, _val)
51 
52 #define wnm_btm_bss_term_inc(p) (*((u8 *)((p)+3)) & BSS_TERMINATION_INCLUDED)
53 
54 #define wnm_btm_ess_disassoc_im(p) (*((u8 *)((p)+3)) & ESS_DISASSOC_IMMINENT)
55 
56 #define wnm_btm_dialog_token(p) (*((u8 *)((p)+2)))
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_req(_adapter *padapter,  u8* pframe, u32 frame_len);
181 
182 void rtw_wnm_reset_btm_candidate(struct roam_nb_info *pnb);
183 
184 void rtw_wnm_reset_btm_state(_adapter *padapter);
185 
186 u32 rtw_wnm_btm_rsp_candidates_sz_get(
187 	_adapter *padapter, u8* pframe, u32 frame_len);
188 
189 void rtw_wnm_process_btm_rsp(_adapter *padapter,
190 	u8* pframe, u32 frame_len, struct btm_rsp_hdr *prsp);
191 
192 void rtw_wnm_issue_btm_req(_adapter *padapter,
193 	u8 *pmac, struct btm_req_hdr *phdr, u8 *purl, u32 url_len,
194 	u8 *pcandidates, u8 candidate_cnt);
195 
196 void rtw_wnm_reset_btm_cache(_adapter *padapter);
197 
198 void rtw_wnm_issue_action(_adapter *padapter, u8 action, u8 reason, u8 dialog);
199 
200 void rtw_wnm_update_reassoc_req_ie(_adapter *padapter);
201 
202 void rtw_roam_nb_info_init(_adapter *padapter);
203 
204 u8 rtw_roam_nb_scan_list_set(_adapter *padapter,
205 	struct sitesurvey_parm *pparm);
206 
207 u32 rtw_wnm_btm_candidates_survey(_adapter *padapter,
208 	u8* pframe, u32 elem_len, u8 is_preference);
209 #endif /* __RTW_WNM_H_ */
210 
211