xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8723ds/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_roam_busy_scan(a, nb)	\
24 	(((a)->mlmepriv.LinkDetectInfo.bBusyTraffic == _TRUE) && \
25 	(((a)->mlmepriv.ch_cnt) < ((nb)->nb_rpt_ch_list_num)))
26 
27 #define rtw_wnm_btm_preference_cap(a) \
28 	((a)->mlmepriv.nb_info.preference_en == _TRUE)
29 
30 #define rtw_wnm_btm_roam_triggered(a) \
31 	(((a)->mlmepriv.nb_info.preference_en == _TRUE) \
32 	&& (rtw_ft_chk_flags((a), RTW_FT_BTM_ROAM))	\
33 	)
34 
35 #define rtw_wnm_btm_diff_bss(a) \
36 	((rtw_wnm_btm_preference_cap(a)) && \
37 	(is_zero_mac_addr((a)->mlmepriv.nb_info.roam_target_addr) == _FALSE) && \
38 	(_rtw_memcmp((a)->mlmepriv.nb_info.roam_target_addr,\
39 		(a)->mlmepriv.cur_network.network.MacAddress, ETH_ALEN) == _FALSE))
40 
41 #define rtw_wnm_btm_roam_candidate(a, c) \
42 	((rtw_wnm_btm_preference_cap(a)) && \
43 	(is_zero_mac_addr((a)->mlmepriv.nb_info.roam_target_addr) == _FALSE) && \
44 	(_rtw_memcmp((a)->mlmepriv.nb_info.roam_target_addr,\
45 		(c)->network.MacAddress, ETH_ALEN)))
46 
47 #define rtw_wnm_set_ext_cap_btm(_pEleStart, _val) \
48 	SET_BITS_TO_LE_1BYTE(((u8 *)(_pEleStart))+2, 3, 1, _val)
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_req_mode(p) (*((u8 *)((p)+3)))
57 
58 #define wnm_btm_disassoc_timer(p) (*((u16 *)((p)+4)))
59 
60 #define wnm_btm_valid_interval(p) (*((u8 *)((p)+6)))
61 
62 #define wnm_btm_term_duration_offset(p) ((p)+7)
63 
64 #define RTW_WLAN_ACTION_WNM_NB_RPT_ELEM	0x34
65 
66 enum rtw_ieee80211_wnm_actioncode {
67 	RTW_WLAN_ACTION_WNM_BTM_QUERY = 6,
68 	RTW_WLAN_ACTION_WNM_BTM_REQ = 7,
69 	RTW_WLAN_ACTION_WNM_BTM_RSP = 8,
70 	RTW_WLAN_ACTION_WNM_NOTIF_REQ = 26,
71 	RTW_WLAN_ACTION_WNM_NOTIF_RSP = 27,
72 };
73 
74 /*IEEE Std 80211k Figure 7-95b Neighbor Report element format*/
75 struct nb_rpt_hdr {
76 	u8 id; /*0x34: Neighbor Report Element ID*/
77 	u8 len;
78 	u8 bssid[ETH_ALEN];
79 	u32 bss_info;
80 	u8 reg_class;
81 	u8 ch_num;
82 	u8 phy_type;
83 };
84 
85 /*IEEE Std 80211v, Figure 7-9 BSS Termination Duration subelement field format */
86 struct btm_term_duration {
87 	u8 id;
88 	u8 len;
89 	u64 tsf;		/* value of the TSF counter when BSS termination will occur in the future */
90 	u16 duration;		/* number of minutes for which the BSS is not present*/
91 };
92 
93 /*IEEE Std 80211v, Figure 7-10 BSS Transition Management Request frame body format */
94 struct btm_req_hdr {
95 	u8 dialog_token;
96 	u8 req_mode;
97 	/* number of TBTTs until the AP sends a Disassociation frame to this STA */
98 	u16 disassoc_timer;
99 	/* number of TBTTs until the BSS transition candidate list is no longer valid */
100 	u8 validity_interval;
101 	struct btm_term_duration term_duration;
102 };
103 
104 struct btm_rpt_cache {
105 	u8 dialog_token;
106 	u8 req_mode;
107 	u16 disassoc_timer;
108 	u8 validity_interval;
109 	struct btm_term_duration term_duration;
110 
111 	/* from BTM req */
112 	u32 validity_time;
113 	u32 disassoc_time;
114 
115 	systime req_stime;
116 };
117 
118 /*IEEE Std 80211v,  Table 7-43b Optional Subelement IDs for Neighbor Report*/
119 /* BSS Transition Candidate Preference */
120 #define WNM_BTM_CAND_PREF_SUBEID 0x03
121 
122 /* BSS Termination Duration */
123 #define WNM_BTM_TERM_DUR_SUBEID		0x04
124 
125 struct wnm_btm_cant {
126 	struct nb_rpt_hdr nb_rpt;
127 	u8 preference;	/* BSS Transition Candidate Preference */
128 };
129 
130 enum rtw_btm_req_mod {
131 	PREFERRED_CANDIDATE_LIST_INCLUDED = BIT0,
132 	ABRIDGED = BIT1,
133 	DISASSOC_IMMINENT = BIT2,
134 	BSS_TERMINATION_INCLUDED = BIT3,
135 	ESS_DISASSOC_IMMINENT = BIT4,
136 };
137 
138 struct roam_nb_info {
139 	struct nb_rpt_hdr nb_rpt[RTW_MAX_NB_RPT_NUM];
140 	struct rtw_ieee80211_channel nb_rpt_ch_list[RTW_MAX_NB_RPT_NUM];
141 	struct btm_rpt_cache btm_cache;
142 	bool	nb_rpt_valid;
143 	u8	nb_rpt_ch_list_num;
144 	u8 preference_en;
145 	u8 roam_target_addr[ETH_ALEN];
146 	u32	last_nb_rpt_entries;
147 	u8 nb_rpt_is_same;
148 	s8 disassoc_waiting;
149 	_timer roam_scan_timer;
150 	_timer disassoc_chk_timer;
151 };
152 
153 u8 rtw_wnm_btm_reassoc_req(_adapter *padapter);
154 void rtw_wnm_roam_scan_hdl(void *ctx);
155 void rtw_wnm_disassoc_chk_hdl(void *ctx);
156 u8 rtw_wnm_try_btm_roam_imnt(_adapter *padapter);
157 void rtw_wnm_process_btm_req(_adapter *padapter,  u8* pframe, u32 frame_len);
158 void rtw_wnm_reset_btm_candidate(struct roam_nb_info *pnb);
159 void rtw_wnm_reset_btm_state(_adapter *padapter);
160 void rtw_wnm_reset_btm_cache(_adapter *padapter);
161 void rtw_wnm_issue_action(_adapter *padapter, u8 action, u8 reason, u8 dialog);
162 void rtw_wnm_update_reassoc_req_ie(_adapter *padapter);
163 
164 void rtw_roam_nb_info_init(_adapter *padapter);
165 u8 rtw_roam_nb_scan_list_set(
166 	_adapter *padapter, struct sitesurvey_parm *pparm);
167 u32 rtw_wnm_btm_candidates_survey(_adapter *padapter,
168 	u8* pframe, u32 elem_len, u8 is_preference);
169 #endif /* __RTW_WNM_H_ */
170 
171