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