rtl871x_mlme.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
  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. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * Modifications for inclusion into the Linux staging tree are
  19. * Copyright(c) 2010 Larry Finger. All rights reserved.
  20. *
  21. * Contact information:
  22. * WLAN FAE <wlanfae@realtek.com>
  23. * Larry Finger <Larry.Finger@lwfinger.net>
  24. *
  25. ******************************************************************************/
  26. #ifndef __RTL871X_MLME_H_
  27. #define __RTL871X_MLME_H_
  28. #include "osdep_service.h"
  29. #include "drv_types.h"
  30. #include "wlan_bssdef.h"
  31. #define MAX_BSS_CNT 64
  32. #define MAX_JOIN_TIMEOUT 6000
  33. #define SCANNING_TIMEOUT 4500
  34. #define SCANQUEUE_LIFETIME 20 /* unit:sec */
  35. #define WIFI_NULL_STATE 0x00000000
  36. #define WIFI_ASOC_STATE 0x00000001 /* Under Linked state...*/
  37. #define WIFI_REASOC_STATE 0x00000002
  38. #define WIFI_SLEEP_STATE 0x00000004
  39. #define WIFI_STATION_STATE 0x00000008
  40. #define WIFI_AP_STATE 0x00000010
  41. #define WIFI_ADHOC_STATE 0x00000020
  42. #define WIFI_ADHOC_MASTER_STATE 0x00000040
  43. #define WIFI_UNDER_LINKING 0x00000080
  44. #define WIFI_SITE_MONITOR 0x00000800 /* to indicate the station
  45. * is under site surveying*/
  46. #define WIFI_MP_STATE 0x00010000
  47. #define WIFI_MP_CTX_BACKGROUND 0x00020000 /* in cont. tx background*/
  48. #define WIFI_MP_CTX_ST 0x00040000 /* in cont. tx with
  49. * single-tone*/
  50. #define WIFI_MP_CTX_BACKGROUND_PENDING 0x00080000 /* pending in cont, tx
  51. * background due to out of skb*/
  52. #define WIFI_MP_CTX_CCK_HW 0x00100000 /* in continuous tx*/
  53. #define WIFI_MP_CTX_CCK_CS 0x00200000 /* in cont, tx with carrier
  54. * suppression*/
  55. #define WIFI_MP_LPBK_STATE 0x00400000
  56. #define _FW_UNDER_LINKING WIFI_UNDER_LINKING
  57. #define _FW_LINKED WIFI_ASOC_STATE
  58. #define _FW_UNDER_SURVEY WIFI_SITE_MONITOR
  59. /*
  60. there are several "locks" in mlme_priv,
  61. since mlme_priv is a shared resource between many threads,
  62. like ISR/Call-Back functions, the OID handlers, and even timer functions.
  63. Each _queue has its own locks, already.
  64. Other items are protected by mlme_priv.lock.
  65. To avoid possible dead lock, any thread trying to modify mlme_priv
  66. SHALL not lock up more than one lock at a time!
  67. */
  68. #define traffic_threshold 10
  69. #define traffic_scan_period 500
  70. struct sitesurvey_ctrl {
  71. u64 last_tx_pkts;
  72. uint last_rx_pkts;
  73. sint traffic_busy;
  74. struct timer_list sitesurvey_ctrl_timer;
  75. };
  76. struct mlme_priv {
  77. spinlock_t lock;
  78. spinlock_t lock2;
  79. sint fw_state; /*shall we protect this variable? */
  80. u8 to_join; /*flag*/
  81. u8 *nic_hdl;
  82. struct list_head *pscanned;
  83. struct __queue free_bss_pool;
  84. struct __queue scanned_queue;
  85. u8 *free_bss_buf;
  86. unsigned long num_of_scanned;
  87. u8 passive_mode; /*add for Android's SCAN-ACTIVE/SCAN-PASSIVE */
  88. struct ndis_802_11_ssid assoc_ssid;
  89. u8 assoc_bssid[6];
  90. struct wlan_network cur_network;
  91. struct sitesurvey_ctrl sitesurveyctrl;
  92. struct timer_list assoc_timer;
  93. uint assoc_by_bssid;
  94. uint assoc_by_rssi;
  95. struct timer_list scan_to_timer; /* driver handles scan_timeout.*/
  96. struct timer_list dhcp_timer; /* set dhcp to if driver in ps mode.*/
  97. struct qos_priv qospriv;
  98. struct ht_priv htpriv;
  99. struct timer_list wdg_timer; /*watchdog periodic timer*/
  100. };
  101. static inline u8 *get_bssid(struct mlme_priv *pmlmepriv)
  102. {
  103. return pmlmepriv->cur_network.network.MacAddress;
  104. }
  105. static inline u8 check_fwstate(struct mlme_priv *pmlmepriv, sint state)
  106. {
  107. if (pmlmepriv->fw_state & state)
  108. return true;
  109. return false;
  110. }
  111. static inline sint get_fwstate(struct mlme_priv *pmlmepriv)
  112. {
  113. return pmlmepriv->fw_state;
  114. }
  115. /*
  116. * No Limit on the calling context,
  117. * therefore set it to be the critical section...
  118. *
  119. * ### NOTE:#### (!!!!)
  120. * TAKE CARE BEFORE CALLING THIS FUNC, LOCK pmlmepriv->lock
  121. */
  122. static inline void set_fwstate(struct mlme_priv *pmlmepriv, sint state)
  123. {
  124. pmlmepriv->fw_state |= state;
  125. }
  126. static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, sint state)
  127. {
  128. pmlmepriv->fw_state &= ~state;
  129. }
  130. /*
  131. * No Limit on the calling context,
  132. * therefore set it to be the critical section...
  133. */
  134. static inline void clr_fwstate(struct mlme_priv *pmlmepriv, sint state)
  135. {
  136. unsigned long irqL;
  137. spin_lock_irqsave(&pmlmepriv->lock, irqL);
  138. if (check_fwstate(pmlmepriv, state))
  139. pmlmepriv->fw_state ^= state;
  140. spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
  141. }
  142. static inline void up_scanned_network(struct mlme_priv *pmlmepriv)
  143. {
  144. unsigned long irqL;
  145. spin_lock_irqsave(&pmlmepriv->lock, irqL);
  146. pmlmepriv->num_of_scanned++;
  147. spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
  148. }
  149. static inline void down_scanned_network(struct mlme_priv *pmlmepriv)
  150. {
  151. unsigned long irqL;
  152. spin_lock_irqsave(&pmlmepriv->lock, irqL);
  153. pmlmepriv->num_of_scanned--;
  154. spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
  155. }
  156. static inline void set_scanned_network_val(struct mlme_priv *pmlmepriv,
  157. sint val)
  158. {
  159. unsigned long irqL;
  160. spin_lock_irqsave(&pmlmepriv->lock, irqL);
  161. pmlmepriv->num_of_scanned = val;
  162. spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
  163. }
  164. void r8712_survey_event_callback(struct _adapter *adapter, u8 *pbuf);
  165. void r8712_surveydone_event_callback(struct _adapter *adapter, u8 *pbuf);
  166. void r8712_joinbss_event_callback(struct _adapter *adapter, u8 *pbuf);
  167. void r8712_stassoc_event_callback(struct _adapter *adapter, u8 *pbuf);
  168. void r8712_stadel_event_callback(struct _adapter *adapter, u8 *pbuf);
  169. void r8712_atimdone_event_callback(struct _adapter *adapter, u8 *pbuf);
  170. void r8712_cpwm_event_callback(struct _adapter *adapter, u8 *pbuf);
  171. void r8712_wpspbc_event_callback(struct _adapter *adapter, u8 *pbuf);
  172. void r8712_free_network_queue(struct _adapter *adapter);
  173. int r8712_init_mlme_priv(struct _adapter *adapter);
  174. void r8712_free_mlme_priv(struct mlme_priv *pmlmepriv);
  175. sint r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv);
  176. sint r8712_set_key(struct _adapter *adapter,
  177. struct security_priv *psecuritypriv, sint keyid);
  178. sint r8712_set_auth(struct _adapter *adapter,
  179. struct security_priv *psecuritypriv);
  180. uint r8712_get_wlan_bssid_ex_sz(struct wlan_bssid_ex *bss);
  181. void r8712_generate_random_ibss(u8 *pibss);
  182. u8 *r8712_get_capability_from_ie(u8 *ie);
  183. struct wlan_network *r8712_get_oldest_wlan_network(
  184. struct __queue *scanned_queue);
  185. void r8712_free_assoc_resources(struct _adapter *adapter);
  186. void r8712_ind_disconnect(struct _adapter *adapter);
  187. void r8712_indicate_connect(struct _adapter *adapter);
  188. int r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie,
  189. u8 *out_ie, uint in_len);
  190. int r8712_restruct_wmm_ie(struct _adapter *adapter, u8 *in_ie,
  191. u8 *out_ie, uint in_len, uint initial_out_len);
  192. void r8712_init_registrypriv_dev_network(struct _adapter *adapter);
  193. void r8712_update_registrypriv_dev_network(struct _adapter *adapter);
  194. void _r8712_sitesurvey_ctrl_handler(struct _adapter *adapter);
  195. void _r8712_join_timeout_handler(struct _adapter *adapter);
  196. void r8712_scan_timeout_handler(struct _adapter *adapter);
  197. void _r8712_dhcp_timeout_handler(struct _adapter *adapter);
  198. void _r8712_wdg_timeout_handler(struct _adapter *adapter);
  199. struct wlan_network *_r8712_alloc_network(struct mlme_priv *pmlmepriv);
  200. sint r8712_if_up(struct _adapter *padapter);
  201. void r8712_joinbss_reset(struct _adapter *padapter);
  202. unsigned int r8712_restructure_ht_ie(struct _adapter *padapter, u8 *in_ie,
  203. u8 *out_ie, uint in_len, uint *pout_len);
  204. void r8712_issue_addbareq_cmd(struct _adapter *padapter, int priority);
  205. int r8712_is_same_ibss(struct _adapter *adapter, struct wlan_network *pnetwork);
  206. #endif /*__RTL871X_MLME_H_*/