| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/****************************************************************************** |
| 3 |
* |
| 4 |
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. |
| 5 |
* |
| 6 |
******************************************************************************/ |
| 7 |
#ifndef __RTW_MLME_H_ |
| 8 |
#define __RTW_MLME_H_ |
| 9 |
|
| 10 |
|
| 11 |
#define MAX_BSS_CNT 128 |
| 12 |
/* define MAX_JOIN_TIMEOUT 2000 */ |
| 13 |
/* define MAX_JOIN_TIMEOUT 2500 */ |
| 14 |
#define MAX_JOIN_TIMEOUT 6500 |
| 15 |
|
| 16 |
/* Commented by Albert 20101105 */ |
| 17 |
/* Increase the scanning timeout because of increasing the SURVEY_TO value. */ |
| 18 |
|
| 19 |
#define SCANNING_TIMEOUT 8000 |
| 20 |
|
| 21 |
#define SCANQUEUE_LIFETIME 20000 /* 20sec, unit:msec */ |
| 22 |
|
| 23 |
#define WIFI_NULL_STATE 0x00000000 |
| 24 |
#define WIFI_ASOC_STATE 0x00000001 /* Under Linked state... */ |
| 25 |
#define WIFI_SLEEP_STATE 0x00000004 |
| 26 |
#define WIFI_STATION_STATE 0x00000008 |
| 27 |
#define WIFI_AP_STATE 0x00000010 |
| 28 |
#define WIFI_ADHOC_STATE 0x00000020 |
| 29 |
#define WIFI_ADHOC_MASTER_STATE 0x00000040 |
| 30 |
#define WIFI_UNDER_LINKING 0x00000080 |
| 31 |
|
| 32 |
#define WIFI_UNDER_WPS 0x00000100 |
| 33 |
#define WIFI_STA_ALIVE_CHK_STATE 0x00000400 |
| 34 |
#define WIFI_SITE_MONITOR 0x00000800 /* to indicate the station is under site surveying */ |
| 35 |
|
| 36 |
/* ifdef UNDER_MPTEST */ |
| 37 |
#define WIFI_MP_STATE 0x00010000 |
| 38 |
/* endif */ |
| 39 |
|
| 40 |
/* define _FW_UNDER_CMD WIFI_UNDER_CMD */ |
| 41 |
#define _FW_UNDER_LINKING WIFI_UNDER_LINKING |
| 42 |
#define _FW_LINKED WIFI_ASOC_STATE |
| 43 |
#define _FW_UNDER_SURVEY WIFI_SITE_MONITOR |
| 44 |
|
| 45 |
|
| 46 |
enum { |
| 47 |
dot11AuthAlgrthm_Open = 0, |
| 48 |
dot11AuthAlgrthm_Shared, |
| 49 |
dot11AuthAlgrthm_8021X, |
| 50 |
dot11AuthAlgrthm_Auto, |
| 51 |
dot11AuthAlgrthm_WAPI, |
| 52 |
dot11AuthAlgrthm_MaxNum |
| 53 |
}; |
| 54 |
|
| 55 |
/* Scan type including active and passive scan. */ |
| 56 |
enum rt_scan_type { |
| 57 |
SCAN_PASSIVE, |
| 58 |
SCAN_ACTIVE, |
| 59 |
SCAN_MIX, |
| 60 |
}; |
| 61 |
|
| 62 |
enum { |
| 63 |
GHZ24_50 = 0, |
| 64 |
GHZ_50, |
| 65 |
GHZ_24, |
| 66 |
GHZ_MAX, |
| 67 |
}; |
| 68 |
|
| 69 |
/* |
| 70 |
|
| 71 |
there are several "locks" in mlme_priv, |
| 72 |
since mlme_priv is a shared resource between many threads, |
| 73 |
like ISR/Call-Back functions, the OID handlers, and even timer functions. |
| 74 |
|
| 75 |
Each struct __queue has its own locks, already. |
| 76 |
Other items in mlme_priv are protected by mlme_priv.lock, while items in |
| 77 |
xmit_priv are protected by xmit_priv.lock. |
| 78 |
|
| 79 |
To avoid possible dead lock, any thread trying to modifiying mlme_priv |
| 80 |
SHALL not lock up more than one locks at a time! |
| 81 |
|
| 82 |
The only exception is that queue functions which take the __queue.lock |
| 83 |
may be called with the xmit_priv.lock held. In this case the order |
| 84 |
MUST always be first lock xmit_priv.lock and then call any queue functions |
| 85 |
which take __queue.lock. |
| 86 |
*/ |
| 87 |
|
| 88 |
struct sitesurvey_ctrl { |
| 89 |
u64 last_tx_pkts; |
| 90 |
uint last_rx_pkts; |
| 91 |
signed int traffic_busy; |
| 92 |
struct timer_list sitesurvey_ctrl_timer; |
| 93 |
}; |
| 94 |
|
| 95 |
struct rt_link_detect_t { |
| 96 |
u32 NumTxOkInPeriod; |
| 97 |
u32 NumRxOkInPeriod; |
| 98 |
u32 NumRxUnicastOkInPeriod; |
| 99 |
bool bBusyTraffic; |
| 100 |
bool bTxBusyTraffic; |
| 101 |
bool bRxBusyTraffic; |
| 102 |
bool bHigherBusyTraffic; /* For interrupt migration purpose. */ |
| 103 |
bool bHigherBusyRxTraffic; /* We may disable Tx interrupt according as Rx traffic. */ |
| 104 |
bool bHigherBusyTxTraffic; /* We may disable Tx interrupt according as Tx traffic. */ |
| 105 |
/* u8 TrafficBusyState; */ |
| 106 |
u8 TrafficTransitionCount; |
| 107 |
u32 LowPowerTransitionCount; |
| 108 |
}; |
| 109 |
|
| 110 |
/* used for mlme_priv.roam_flags */ |
| 111 |
enum { |
| 112 |
RTW_ROAM_ON_EXPIRED = BIT0, |
| 113 |
RTW_ROAM_ON_RESUME = BIT1, |
| 114 |
RTW_ROAM_ACTIVE = BIT2, |
| 115 |
}; |
| 116 |
|
| 117 |
struct mlme_priv { |
| 118 |
|
| 119 |
spinlock_t lock; |
| 120 |
signed int fw_state; /* shall we protect this variable? maybe not necessarily... */ |
| 121 |
u8 bScanInProcess; |
| 122 |
u8 to_join; /* flag */ |
| 123 |
|
| 124 |
u8 to_roam; /* roaming trying times */ |
| 125 |
struct wlan_network *roam_network; /* the target of active roam */ |
| 126 |
u8 roam_flags; |
| 127 |
u8 roam_rssi_diff_th; /* rssi difference threshold for active scan candidate selection */ |
| 128 |
u32 roam_scan_int_ms; /* scan interval for active roam */ |
| 129 |
u32 roam_scanr_exp_ms; /* scan result expire time in ms for roam */ |
| 130 |
u8 roam_tgt_addr[ETH_ALEN]; /* request to roam to specific target without other consideration */ |
| 131 |
|
| 132 |
u8 *nic_hdl; |
| 133 |
|
| 134 |
u8 not_indic_disco; |
| 135 |
struct list_head *pscanned; |
| 136 |
struct __queue free_bss_pool; |
| 137 |
struct __queue scanned_queue; |
| 138 |
u8 *free_bss_buf; |
| 139 |
|
| 140 |
struct ndis_802_11_ssid assoc_ssid; |
| 141 |
u8 assoc_bssid[6]; |
| 142 |
|
| 143 |
struct wlan_network cur_network; |
| 144 |
struct wlan_network *cur_network_scanned; |
| 145 |
|
| 146 |
/* uint wireless_mode; no used, remove it */ |
| 147 |
|
| 148 |
u32 auto_scan_int_ms; |
| 149 |
|
| 150 |
struct timer_list assoc_timer; |
| 151 |
|
| 152 |
uint assoc_by_bssid; |
| 153 |
uint assoc_by_rssi; |
| 154 |
|
| 155 |
struct timer_list scan_to_timer; /* driver itself handles scan_timeout status. */ |
| 156 |
unsigned long scan_start_time; /* used to evaluate the time spent in scanning */ |
| 157 |
|
| 158 |
struct timer_list set_scan_deny_timer; |
| 159 |
atomic_t set_scan_deny; /* 0: allowed, 1: deny */ |
| 160 |
|
| 161 |
struct qos_priv qospriv; |
| 162 |
|
| 163 |
/* Number of non-HT AP/stations */ |
| 164 |
int num_sta_no_ht; |
| 165 |
|
| 166 |
/* Number of HT AP/stations 20 MHz */ |
| 167 |
/* int num_sta_ht_20mhz; */ |
| 168 |
|
| 169 |
|
| 170 |
int num_FortyMHzIntolerant; |
| 171 |
|
| 172 |
struct ht_priv htpriv; |
| 173 |
|
| 174 |
struct rt_link_detect_t LinkDetectInfo; |
| 175 |
struct timer_list dynamic_chk_timer; /* dynamic/periodic check timer */ |
| 176 |
|
| 177 |
u8 acm_mask; /* for wmm acm mask */ |
| 178 |
u8 ChannelPlan; |
| 179 |
enum rt_scan_type scan_mode; /* active: 1, passive: 0 */ |
| 180 |
|
| 181 |
u8 *wps_probe_req_ie; |
| 182 |
u32 wps_probe_req_ie_len; |
| 183 |
|
| 184 |
/* Number of associated Non-ERP stations (i.e., stations using 802.11b |
| 185 |
* in 802.11g BSS) */ |
| 186 |
int num_sta_non_erp; |
| 187 |
|
| 188 |
/* Number of associated stations that do not support Short Slot Time */ |
| 189 |
int num_sta_no_short_slot_time; |
| 190 |
|
| 191 |
/* Number of associated stations that do not support Short Preamble */ |
| 192 |
int num_sta_no_short_preamble; |
| 193 |
|
| 194 |
int olbc; /* Overlapping Legacy BSS Condition */ |
| 195 |
|
| 196 |
/* Number of HT associated stations that do not support greenfield */ |
| 197 |
int num_sta_ht_no_gf; |
| 198 |
|
| 199 |
/* Number of associated non-HT stations */ |
| 200 |
/* int num_sta_no_ht; */ |
| 201 |
|
| 202 |
/* Number of HT associated stations 20 MHz */ |
| 203 |
int num_sta_ht_20mhz; |
| 204 |
|
| 205 |
/* Overlapping BSS information */ |
| 206 |
int olbc_ht; |
| 207 |
|
| 208 |
u16 ht_op_mode; |
| 209 |
|
| 210 |
u8 *assoc_req; |
| 211 |
u32 assoc_req_len; |
| 212 |
u8 *assoc_rsp; |
| 213 |
u32 assoc_rsp_len; |
| 214 |
|
| 215 |
u8 *wps_beacon_ie; |
| 216 |
/* u8 *wps_probe_req_ie; */ |
| 217 |
u8 *wps_probe_resp_ie; |
| 218 |
u8 *wps_assoc_resp_ie; /* for CONFIG_IOCTL_CFG80211, this IE could include p2p ie / wfd ie */ |
| 219 |
|
| 220 |
u32 wps_beacon_ie_len; |
| 221 |
/* u32 wps_probe_req_ie_len; */ |
| 222 |
u32 wps_probe_resp_ie_len; |
| 223 |
u32 wps_assoc_resp_ie_len; /* for CONFIG_IOCTL_CFG80211, this IE len could include p2p ie / wfd ie */ |
| 224 |
|
| 225 |
u8 *p2p_beacon_ie; |
| 226 |
u8 *p2p_probe_req_ie; |
| 227 |
u8 *p2p_probe_resp_ie; |
| 228 |
u8 *p2p_go_probe_resp_ie; /* for GO */ |
| 229 |
u8 *p2p_assoc_req_ie; |
| 230 |
|
| 231 |
u32 p2p_beacon_ie_len; |
| 232 |
u32 p2p_probe_req_ie_len; |
| 233 |
u32 p2p_probe_resp_ie_len; |
| 234 |
u32 p2p_go_probe_resp_ie_len; /* for GO */ |
| 235 |
u32 p2p_assoc_req_ie_len; |
| 236 |
|
| 237 |
spinlock_t bcn_update_lock; |
| 238 |
u8 update_bcn; |
| 239 |
|
| 240 |
u8 NumOfBcnInfoChkFail; |
| 241 |
unsigned long timeBcnInfoChkStart; |
| 242 |
}; |
| 243 |
|
| 244 |
void rtw_mlme_reset_auto_scan_int(struct adapter *adapter); |
| 245 |
|
| 246 |
struct hostapd_priv { |
| 247 |
struct adapter *padapter; |
| 248 |
}; |
| 249 |
|
| 250 |
extern int hostapd_mode_init(struct adapter *padapter); |
| 251 |
extern void hostapd_mode_unload(struct adapter *padapter); |
| 252 |
|
| 253 |
extern void rtw_joinbss_event_prehandle(struct adapter *adapter, u8 *pbuf); |
| 254 |
extern void rtw_survey_event_callback(struct adapter *adapter, u8 *pbuf); |
| 255 |
extern void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf); |
| 256 |
extern void rtw_joinbss_event_callback(struct adapter *adapter, u8 *pbuf); |
| 257 |
extern void rtw_stassoc_event_callback(struct adapter *adapter, u8 *pbuf); |
| 258 |
extern void rtw_stadel_event_callback(struct adapter *adapter, u8 *pbuf); |
| 259 |
extern void rtw_atimdone_event_callback(struct adapter *adapter, u8 *pbuf); |
| 260 |
extern void rtw_cpwm_event_callback(struct adapter *adapter, u8 *pbuf); |
| 261 |
extern void rtw_wmm_event_callback(struct adapter *padapter, u8 *pbuf); |
| 262 |
|
| 263 |
extern void rtw_join_timeout_handler(struct timer_list *t); |
| 264 |
extern void _rtw_scan_timeout_handler(struct timer_list *t); |
| 265 |
|
| 266 |
int event_thread(void *context); |
| 267 |
|
| 268 |
extern void rtw_free_network_queue(struct adapter *adapter, u8 isfreeall); |
| 269 |
extern int rtw_init_mlme_priv(struct adapter *adapter);/* (struct mlme_priv *pmlmepriv); */ |
| 270 |
|
| 271 |
extern void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv); |
| 272 |
|
| 273 |
|
| 274 |
extern signed int rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv); |
| 275 |
extern signed int rtw_set_key(struct adapter *adapter, struct security_priv *psecuritypriv, signed int keyid, u8 set_tx, bool enqueue); |
| 276 |
extern signed int rtw_set_auth(struct adapter *adapter, struct security_priv *psecuritypriv); |
| 277 |
|
| 278 |
static inline u8 *get_bssid(struct mlme_priv *pmlmepriv) |
| 279 |
{ /* if sta_mode:pmlmepriv->cur_network.network.mac_address => bssid */ |
| 280 |
/* if adhoc_mode:pmlmepriv->cur_network.network.mac_address => ibss mac address */ |
| 281 |
return pmlmepriv->cur_network.network.mac_address; |
| 282 |
} |
| 283 |
|
| 284 |
static inline signed int check_fwstate(struct mlme_priv *pmlmepriv, signed int state) |
| 285 |
{ |
| 286 |
if (pmlmepriv->fw_state & state) |
| 287 |
return true; |
| 288 |
|
| 289 |
return false; |
| 290 |
} |
| 291 |
|
| 292 |
static inline signed int get_fwstate(struct mlme_priv *pmlmepriv) |
| 293 |
{ |
| 294 |
return pmlmepriv->fw_state; |
| 295 |
} |
| 296 |
|
| 297 |
/* |
| 298 |
* No Limit on the calling context, |
| 299 |
* therefore set it to be the critical section... |
| 300 |
* |
| 301 |
* ### NOTE:#### (!!!!) |
| 302 |
* MUST TAKE CARE THAT BEFORE CALLING THIS FUNC, YOU SHOULD HAVE LOCKED pmlmepriv->lock |
| 303 |
*/ |
| 304 |
static inline void set_fwstate(struct mlme_priv *pmlmepriv, signed int state) |
| 305 |
{ |
| 306 |
pmlmepriv->fw_state |= state; |
| 307 |
/* FOR HW integration */ |
| 308 |
if (state == _FW_UNDER_SURVEY) |
| 309 |
pmlmepriv->bScanInProcess = true; |
| 310 |
} |
| 311 |
|
| 312 |
static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, signed int state) |
| 313 |
{ |
| 314 |
pmlmepriv->fw_state &= ~state; |
| 315 |
/* FOR HW integration */ |
| 316 |
if (state == _FW_UNDER_SURVEY) |
| 317 |
pmlmepriv->bScanInProcess = false; |
| 318 |
} |
| 319 |
|
| 320 |
extern u16 rtw_get_capability(struct wlan_bssid_ex *bss); |
| 321 |
extern void rtw_update_scanned_network(struct adapter *adapter, struct wlan_bssid_ex *target); |
| 322 |
extern void rtw_disconnect_hdl_under_linked(struct adapter *adapter, struct sta_info *psta, u8 free_assoc); |
| 323 |
extern void rtw_generate_random_ibss(u8 *pibss); |
| 324 |
extern struct wlan_network *rtw_find_network(struct __queue *scanned_queue, u8 *addr); |
| 325 |
extern struct wlan_network *rtw_get_oldest_wlan_network(struct __queue *scanned_queue); |
| 326 |
struct wlan_network *_rtw_find_same_network(struct __queue *scanned_queue, struct wlan_network *network); |
| 327 |
|
| 328 |
extern void rtw_free_assoc_resources(struct adapter *adapter, int lock_scanned_queue); |
| 329 |
extern void rtw_indicate_disconnect(struct adapter *adapter); |
| 330 |
extern void rtw_indicate_connect(struct adapter *adapter); |
| 331 |
void rtw_indicate_scan_done(struct adapter *padapter, bool aborted); |
| 332 |
void rtw_scan_abort(struct adapter *adapter); |
| 333 |
|
| 334 |
extern int rtw_restruct_sec_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len); |
| 335 |
extern int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_len, uint initial_out_len); |
| 336 |
extern void rtw_init_registrypriv_dev_network(struct adapter *adapter); |
| 337 |
|
| 338 |
extern void rtw_update_registrypriv_dev_network(struct adapter *adapter); |
| 339 |
|
| 340 |
extern void _rtw_join_timeout_handler(struct timer_list *t); |
| 341 |
extern void rtw_scan_timeout_handler(struct timer_list *t); |
| 342 |
|
| 343 |
extern void rtw_dynamic_check_timer_handler(struct adapter *adapter); |
| 344 |
bool rtw_is_scan_deny(struct adapter *adapter); |
| 345 |
void rtw_clear_scan_deny(struct adapter *adapter); |
| 346 |
void rtw_set_scan_deny(struct adapter *adapter, u32 ms); |
| 347 |
|
| 348 |
void rtw_free_mlme_priv_ie_data(struct mlme_priv *pmlmepriv); |
| 349 |
|
| 350 |
extern void _rtw_free_mlme_priv(struct mlme_priv *pmlmepriv); |
| 351 |
|
| 352 |
/* extern struct wlan_network* _rtw_dequeue_network(struct __queue *queue); */ |
| 353 |
|
| 354 |
extern struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv); |
| 355 |
|
| 356 |
|
| 357 |
extern void _rtw_free_network(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork, u8 isfreeall); |
| 358 |
extern void _rtw_free_network_nolock(struct mlme_priv *pmlmepriv, struct wlan_network *pnetwork); |
| 359 |
|
| 360 |
|
| 361 |
extern struct wlan_network *_rtw_find_network(struct __queue *scanned_queue, u8 *addr); |
| 362 |
|
| 363 |
extern signed int rtw_if_up(struct adapter *padapter); |
| 364 |
|
| 365 |
signed int rtw_linked_check(struct adapter *padapter); |
| 366 |
|
| 367 |
u8 *rtw_get_capability_from_ie(u8 *ie); |
| 368 |
u8 *rtw_get_beacon_interval_from_ie(u8 *ie); |
| 369 |
|
| 370 |
|
| 371 |
void rtw_joinbss_reset(struct adapter *padapter); |
| 372 |
|
| 373 |
void rtw_ht_use_default_setting(struct adapter *padapter); |
| 374 |
void rtw_build_wmm_ie_ht(struct adapter *padapter, u8 *out_ie, uint *pout_len); |
| 375 |
unsigned int rtw_restructure_ht_ie(struct adapter *padapter, u8 *in_ie, u8 *out_ie, uint in_len, uint *pout_len, u8 channel); |
| 376 |
void rtw_update_ht_cap(struct adapter *padapter, u8 *pie, uint ie_len, u8 channel); |
| 377 |
void rtw_issue_addbareq_cmd(struct adapter *padapter, struct xmit_frame *pxmitframe); |
| 378 |
void rtw_append_exented_cap(struct adapter *padapter, u8 *out_ie, uint *pout_len); |
| 379 |
|
| 380 |
int rtw_is_same_ibss(struct adapter *adapter, struct wlan_network *pnetwork); |
| 381 |
int is_same_network(struct wlan_bssid_ex *src, struct wlan_bssid_ex *dst, u8 feature); |
| 382 |
|
| 383 |
#define rtw_roam_flags(adapter) ((adapter)->mlmepriv.roam_flags) |
| 384 |
#define rtw_chk_roam_flags(adapter, flags) ((adapter)->mlmepriv.roam_flags & flags) |
| 385 |
|
| 386 |
void _rtw_roaming(struct adapter *adapter, struct wlan_network *tgt_network); |
| 387 |
void rtw_roaming(struct adapter *adapter, struct wlan_network *tgt_network); |
| 388 |
void rtw_set_to_roam(struct adapter *adapter, u8 to_roam); |
| 389 |
u8 rtw_dec_to_roam(struct adapter *adapter); |
| 390 |
u8 rtw_to_roam(struct adapter *adapter); |
| 391 |
int rtw_select_roaming_candidate(struct mlme_priv *pmlmepriv); |
| 392 |
|
| 393 |
void rtw_sta_media_status_rpt(struct adapter *adapter, struct sta_info *psta, u32 mstatus); |
| 394 |
void rtw_reset_securitypriv(struct adapter *adapter); |
| 395 |
|
| 396 |
#endif /* __RTL871X_MLME_H_ */ |