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_set_ext_cap_btm(_pEleStart, _val) \ 49 SET_BITS_TO_LE_1BYTE(((u8 *)(_pEleStart))+2, 3, 1, _val) 50 51 #define wnm_btm_bss_term_inc(p) (*((u8 *)((p)+3)) & BSS_TERMINATION_INCLUDED) 52 53 #define wnm_btm_ess_disassoc_im(p) (*((u8 *)((p)+3)) & ESS_DISASSOC_IMMINENT) 54 55 #define wnm_btm_dialog_token(p) (*((u8 *)((p)+2))) 56 57 #define wnm_btm_req_mode(p) (*((u8 *)((p)+3))) 58 59 #define wnm_btm_disassoc_timer(p) (*((u16 *)((p)+4))) 60 61 #define wnm_btm_valid_interval(p) (*((u8 *)((p)+6))) 62 63 #define wnm_btm_term_duration_offset(p) ((p)+7) 64 65 #define wnm_btm_rsp_status(p) (*((u8 *)((p)+3))) 66 67 #define wnm_btm_rsp_term_delay(p) (*((u8 *)((p)+4))) 68 69 #define RTW_WLAN_ACTION_WNM_NB_RPT_ELEM 0x34 70 71 enum rtw_ieee80211_wnm_actioncode { 72 RTW_WLAN_ACTION_WNM_BTM_QUERY = 6, 73 RTW_WLAN_ACTION_WNM_BTM_REQ = 7, 74 RTW_WLAN_ACTION_WNM_BTM_RSP = 8, 75 RTW_WLAN_ACTION_WNM_NOTIF_REQ = 26, 76 RTW_WLAN_ACTION_WNM_NOTIF_RSP = 27, 77 }; 78 79 /*IEEE Std 80211k Figure 7-95b Neighbor Report element format*/ 80 struct nb_rpt_hdr { 81 u8 id; /*0x34: Neighbor Report Element ID*/ 82 u8 len; 83 u8 bssid[ETH_ALEN]; 84 u32 bss_info; 85 u8 reg_class; 86 u8 ch_num; 87 u8 phy_type; 88 }; 89 90 /*IEEE Std 80211v, Figure 7-9 BSS Termination Duration subelement field format */ 91 struct btm_term_duration { 92 u8 id; 93 u8 len; 94 u64 tsf; /* value of the TSF counter when BSS termination will occur in the future */ 95 u16 duration; /* number of minutes for which the BSS is not present*/ 96 }; 97 98 /*IEEE Std 80211v, Figure 7-10 BSS Transition Management Request frame body format */ 99 struct btm_req_hdr { 100 u8 dialog_token; 101 u8 req_mode; 102 /* number of TBTTs until the AP sends a Disassociation frame to this STA */ 103 u16 disassoc_timer; 104 /* number of TBTTs until the BSS transition candidate list is no longer valid */ 105 u8 validity_interval; 106 struct btm_term_duration term_duration; 107 }; 108 109 struct btm_rsp_hdr { 110 u8 dialog_token; 111 u8 status; 112 /* the number of minutes that 113 the responding STA requests the BSS to delay termination */ 114 u8 termination_delay; 115 u8 bssid[ETH_ALEN]; 116 u8 *pcandidates; 117 u32 candidates_num; 118 }; 119 120 struct btm_rpt_cache { 121 u8 dialog_token; 122 u8 req_mode; 123 u16 disassoc_timer; 124 u8 validity_interval; 125 struct btm_term_duration term_duration; 126 127 /* from BTM req */ 128 u32 validity_time; 129 u32 disassoc_time; 130 131 systime req_stime; 132 }; 133 134 /*IEEE Std 80211v, Table 7-43b Optional Subelement IDs for Neighbor Report*/ 135 /* BSS Transition Candidate Preference */ 136 #define WNM_BTM_CAND_PREF_SUBEID 0x03 137 138 /* BSS Termination Duration */ 139 #define WNM_BTM_TERM_DUR_SUBEID 0x04 140 141 struct wnm_btm_cant { 142 struct nb_rpt_hdr nb_rpt; 143 u8 preference; /* BSS Transition Candidate Preference */ 144 }; 145 146 enum rtw_btm_req_mod { 147 PREFERRED_CANDIDATE_LIST_INCLUDED = BIT0, 148 ABRIDGED = BIT1, 149 DISASSOC_IMMINENT = BIT2, 150 BSS_TERMINATION_INCLUDED = BIT3, 151 ESS_DISASSOC_IMMINENT = BIT4, 152 }; 153 154 struct roam_nb_info { 155 struct nb_rpt_hdr nb_rpt[RTW_MAX_NB_RPT_NUM]; 156 struct rtw_ieee80211_channel nb_rpt_ch_list[RTW_MAX_NB_RPT_NUM]; 157 struct btm_rpt_cache btm_cache; 158 bool nb_rpt_valid; 159 u8 nb_rpt_ch_list_num; 160 u8 preference_en; 161 u8 roam_target_addr[ETH_ALEN]; 162 u32 last_nb_rpt_entries; 163 u8 nb_rpt_is_same; 164 s8 disassoc_waiting; 165 _timer roam_scan_timer; 166 _timer disassoc_chk_timer; 167 168 u32 features; 169 }; 170 171 u8 rtw_wnm_btm_reassoc_req(_adapter *padapter); 172 173 void rtw_wnm_roam_scan_hdl(void *ctx); 174 175 void rtw_wnm_disassoc_chk_hdl(void *ctx); 176 177 u8 rtw_wnm_try_btm_roam_imnt(_adapter *padapter); 178 179 void rtw_wnm_process_btm_req(_adapter *padapter, u8* pframe, u32 frame_len); 180 181 void rtw_wnm_reset_btm_candidate(struct roam_nb_info *pnb); 182 183 void rtw_wnm_reset_btm_state(_adapter *padapter); 184 185 u32 rtw_wnm_btm_rsp_candidates_sz_get( 186 _adapter *padapter, u8* pframe, u32 frame_len); 187 188 void rtw_wnm_process_btm_rsp(_adapter *padapter, 189 u8* pframe, u32 frame_len, struct btm_rsp_hdr *prsp); 190 191 void rtw_wnm_issue_btm_req(_adapter *padapter, 192 u8 *pmac, struct btm_req_hdr *phdr, u8 *purl, u32 url_len, 193 u8 *pcandidates, u8 candidate_cnt); 194 195 void rtw_wnm_reset_btm_cache(_adapter *padapter); 196 197 void rtw_wnm_issue_action(_adapter *padapter, u8 action, u8 reason, u8 dialog); 198 199 void rtw_wnm_update_reassoc_req_ie(_adapter *padapter); 200 201 void rtw_roam_nb_info_init(_adapter *padapter); 202 203 u8 rtw_roam_nb_scan_list_set(_adapter *padapter, 204 struct sitesurvey_parm *pparm); 205 206 u32 rtw_wnm_btm_candidates_survey(_adapter *padapter, 207 u8* pframe, u32 elem_len, u8 is_preference); 208 #endif /* __RTW_WNM_H_ */ 209 210