rtw_sta_mgt.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 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. *
  19. ******************************************************************************/
  20. #define _RTW_STA_MGT_C_
  21. #include <osdep_service.h>
  22. #include <drv_types.h>
  23. #include <recv_osdep.h>
  24. #include <xmit_osdep.h>
  25. #include <mlme_osdep.h>
  26. #include <sta_info.h>
  27. #include <linux/vmalloc.h>
  28. static void _rtw_init_stainfo(struct sta_info *psta)
  29. {
  30. memset((u8 *)psta, 0, sizeof(struct sta_info));
  31. spin_lock_init(&psta->lock);
  32. INIT_LIST_HEAD(&psta->list);
  33. INIT_LIST_HEAD(&psta->hash_list);
  34. _rtw_init_queue(&psta->sleep_q);
  35. psta->sleepq_len = 0;
  36. _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
  37. _rtw_init_sta_recv_priv(&psta->sta_recvpriv);
  38. #ifdef CONFIG_88EU_AP_MODE
  39. INIT_LIST_HEAD(&psta->asoc_list);
  40. INIT_LIST_HEAD(&psta->auth_list);
  41. psta->expire_to = 0;
  42. psta->flags = 0;
  43. psta->capability = 0;
  44. psta->bpairwise_key_installed = false;
  45. psta->nonerp_set = 0;
  46. psta->no_short_slot_time_set = 0;
  47. psta->no_short_preamble_set = 0;
  48. psta->no_ht_gf_set = 0;
  49. psta->no_ht_set = 0;
  50. psta->ht_20mhz_set = 0;
  51. psta->under_exist_checking = 0;
  52. psta->keep_alive_trycnt = 0;
  53. #endif /* CONFIG_88EU_AP_MODE */
  54. }
  55. u32 _rtw_init_sta_priv(struct sta_priv *pstapriv)
  56. {
  57. struct sta_info *psta;
  58. s32 i;
  59. pstapriv->pallocated_stainfo_buf = vzalloc(sizeof(struct sta_info) * NUM_STA + 4);
  60. if (!pstapriv->pallocated_stainfo_buf)
  61. return _FAIL;
  62. pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 -
  63. ((size_t)(pstapriv->pallocated_stainfo_buf) & 3);
  64. _rtw_init_queue(&pstapriv->free_sta_queue);
  65. spin_lock_init(&pstapriv->sta_hash_lock);
  66. pstapriv->asoc_sta_count = 0;
  67. _rtw_init_queue(&pstapriv->sleep_q);
  68. _rtw_init_queue(&pstapriv->wakeup_q);
  69. psta = (struct sta_info *)(pstapriv->pstainfo_buf);
  70. for (i = 0; i < NUM_STA; i++) {
  71. _rtw_init_stainfo(psta);
  72. INIT_LIST_HEAD(&(pstapriv->sta_hash[i]));
  73. list_add_tail(&psta->list, get_list_head(&pstapriv->free_sta_queue));
  74. psta++;
  75. }
  76. #ifdef CONFIG_88EU_AP_MODE
  77. pstapriv->sta_dz_bitmap = 0;
  78. pstapriv->tim_bitmap = 0;
  79. INIT_LIST_HEAD(&pstapriv->asoc_list);
  80. INIT_LIST_HEAD(&pstapriv->auth_list);
  81. spin_lock_init(&pstapriv->asoc_list_lock);
  82. spin_lock_init(&pstapriv->auth_list_lock);
  83. pstapriv->asoc_list_cnt = 0;
  84. pstapriv->auth_list_cnt = 0;
  85. pstapriv->auth_to = 3; /* 3*2 = 6 sec */
  86. pstapriv->assoc_to = 3;
  87. pstapriv->expire_to = 3; /* 3*2 = 6 sec */
  88. pstapriv->max_num_sta = NUM_STA;
  89. #endif
  90. return _SUCCESS;
  91. }
  92. inline int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta)
  93. {
  94. int offset = (((u8 *)sta) - stapriv->pstainfo_buf)/sizeof(struct sta_info);
  95. if (!stainfo_offset_valid(offset))
  96. DBG_88E("%s invalid offset(%d), out of range!!!", __func__, offset);
  97. return offset;
  98. }
  99. inline struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset)
  100. {
  101. if (!stainfo_offset_valid(offset))
  102. DBG_88E("%s invalid offset(%d), out of range!!!", __func__, offset);
  103. return (struct sta_info *)(stapriv->pstainfo_buf + offset * sizeof(struct sta_info));
  104. }
  105. u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)
  106. {
  107. struct list_head *phead, *plist;
  108. struct sta_info *psta = NULL;
  109. struct recv_reorder_ctrl *preorder_ctrl;
  110. int index;
  111. if (pstapriv) {
  112. /* delete all reordering_ctrl_timer */
  113. spin_lock_bh(&pstapriv->sta_hash_lock);
  114. for (index = 0; index < NUM_STA; index++) {
  115. phead = &(pstapriv->sta_hash[index]);
  116. plist = phead->next;
  117. while (phead != plist) {
  118. int i;
  119. psta = container_of(plist, struct sta_info,
  120. hash_list);
  121. plist = plist->next;
  122. for (i = 0; i < 16; i++) {
  123. preorder_ctrl = &psta->recvreorder_ctrl[i];
  124. del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
  125. }
  126. }
  127. }
  128. spin_unlock_bh(&pstapriv->sta_hash_lock);
  129. /*===============================*/
  130. if (pstapriv->pallocated_stainfo_buf)
  131. vfree(pstapriv->pallocated_stainfo_buf);
  132. }
  133. return _SUCCESS;
  134. }
  135. struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
  136. {
  137. s32 index;
  138. struct list_head *phash_list;
  139. struct sta_info *psta;
  140. struct __queue *pfree_sta_queue;
  141. struct recv_reorder_ctrl *preorder_ctrl;
  142. int i = 0;
  143. u16 wRxSeqInitialValue = 0xffff;
  144. pfree_sta_queue = &pstapriv->free_sta_queue;
  145. spin_lock_bh(&(pfree_sta_queue->lock));
  146. if (list_empty(&pfree_sta_queue->queue)) {
  147. spin_unlock_bh(&pfree_sta_queue->lock);
  148. psta = NULL;
  149. } else {
  150. psta = container_of((&pfree_sta_queue->queue)->next, struct sta_info, list);
  151. list_del_init(&(psta->list));
  152. spin_unlock_bh(&pfree_sta_queue->lock);
  153. _rtw_init_stainfo(psta);
  154. memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
  155. index = wifi_mac_hash(hwaddr);
  156. RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_info_, ("rtw_alloc_stainfo: index=%x", index));
  157. if (index >= NUM_STA) {
  158. RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_, ("ERROR => rtw_alloc_stainfo: index >= NUM_STA"));
  159. psta = NULL;
  160. goto exit;
  161. }
  162. phash_list = &(pstapriv->sta_hash[index]);
  163. spin_lock_bh(&(pstapriv->sta_hash_lock));
  164. list_add_tail(&psta->hash_list, phash_list);
  165. pstapriv->asoc_sta_count++;
  166. spin_unlock_bh(&pstapriv->sta_hash_lock);
  167. /* Commented by Albert 2009/08/13 */
  168. /* For the SMC router, the sequence number of first packet of WPS handshake will be 0. */
  169. /* In this case, this packet will be dropped by recv_decache function if we use the 0x00 as the default value for tid_rxseq variable. */
  170. /* So, we initialize the tid_rxseq variable as the 0xffff. */
  171. for (i = 0; i < 16; i++)
  172. memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i], &wRxSeqInitialValue, 2);
  173. RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_info_,
  174. ("alloc number_%d stainfo with hwaddr = %pM\n",
  175. pstapriv->asoc_sta_count, hwaddr));
  176. init_addba_retry_timer(pstapriv->padapter, psta);
  177. /* for A-MPDU Rx reordering buffer control */
  178. for (i = 0; i < 16; i++) {
  179. preorder_ctrl = &psta->recvreorder_ctrl[i];
  180. preorder_ctrl->padapter = pstapriv->padapter;
  181. preorder_ctrl->enable = false;
  182. preorder_ctrl->indicate_seq = 0xffff;
  183. preorder_ctrl->wend_b = 0xffff;
  184. preorder_ctrl->wsize_b = 64;/* 64; */
  185. _rtw_init_queue(&preorder_ctrl->pending_recvframe_queue);
  186. rtw_init_recv_timer(preorder_ctrl);
  187. }
  188. /* init for DM */
  189. psta->rssi_stat.UndecoratedSmoothedPWDB = (-1);
  190. psta->rssi_stat.UndecoratedSmoothedCCK = (-1);
  191. /* init for the sequence number of received management frame */
  192. psta->RxMgmtFrameSeqNum = 0xffff;
  193. }
  194. exit:
  195. return psta;
  196. }
  197. /* using pstapriv->sta_hash_lock to protect */
  198. u32 rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
  199. {
  200. int i;
  201. struct __queue *pfree_sta_queue;
  202. struct recv_reorder_ctrl *preorder_ctrl;
  203. struct sta_xmit_priv *pstaxmitpriv;
  204. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  205. struct sta_priv *pstapriv = &padapter->stapriv;
  206. if (!psta)
  207. goto exit;
  208. pfree_sta_queue = &pstapriv->free_sta_queue;
  209. pstaxmitpriv = &psta->sta_xmitpriv;
  210. spin_lock_bh(&pxmitpriv->lock);
  211. rtw_free_xmitframe_queue(pxmitpriv, &psta->sleep_q);
  212. psta->sleepq_len = 0;
  213. rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
  214. list_del_init(&(pstaxmitpriv->vo_q.tx_pending));
  215. rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
  216. list_del_init(&(pstaxmitpriv->vi_q.tx_pending));
  217. rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
  218. list_del_init(&(pstaxmitpriv->bk_q.tx_pending));
  219. rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
  220. list_del_init(&(pstaxmitpriv->be_q.tx_pending));
  221. spin_unlock_bh(&pxmitpriv->lock);
  222. list_del_init(&psta->hash_list);
  223. RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_,
  224. ("\n free number_%d stainfo with hwaddr=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n",
  225. pstapriv->asoc_sta_count, psta->hwaddr[0], psta->hwaddr[1],
  226. psta->hwaddr[2], psta->hwaddr[3], psta->hwaddr[4],
  227. psta->hwaddr[5]));
  228. pstapriv->asoc_sta_count--;
  229. /* re-init sta_info; 20061114 */
  230. _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
  231. _rtw_init_sta_recv_priv(&psta->sta_recvpriv);
  232. del_timer_sync(&psta->addba_retry_timer);
  233. /* for A-MPDU Rx reordering buffer control, cancel reordering_ctrl_timer */
  234. for (i = 0; i < 16; i++) {
  235. struct list_head *phead, *plist;
  236. struct recv_frame *prhdr;
  237. struct recv_frame *prframe;
  238. struct __queue *ppending_recvframe_queue;
  239. struct __queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
  240. preorder_ctrl = &psta->recvreorder_ctrl[i];
  241. del_timer_sync(&preorder_ctrl->reordering_ctrl_timer);
  242. ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
  243. spin_lock_bh(&ppending_recvframe_queue->lock);
  244. phead = get_list_head(ppending_recvframe_queue);
  245. plist = phead->next;
  246. while (!list_empty(phead)) {
  247. prhdr = container_of(plist, struct recv_frame, list);
  248. prframe = (struct recv_frame *)prhdr;
  249. plist = plist->next;
  250. list_del_init(&(prframe->list));
  251. rtw_free_recvframe(prframe, pfree_recv_queue);
  252. }
  253. spin_unlock_bh(&ppending_recvframe_queue->lock);
  254. }
  255. if (!(psta->state & WIFI_AP_STATE))
  256. rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, false);
  257. #ifdef CONFIG_88EU_AP_MODE
  258. spin_lock_bh(&pstapriv->auth_list_lock);
  259. if (!list_empty(&psta->auth_list)) {
  260. list_del_init(&psta->auth_list);
  261. pstapriv->auth_list_cnt--;
  262. }
  263. spin_unlock_bh(&pstapriv->auth_list_lock);
  264. psta->expire_to = 0;
  265. psta->sleepq_ac_len = 0;
  266. psta->qos_info = 0;
  267. psta->max_sp_len = 0;
  268. psta->uapsd_bk = 0;
  269. psta->uapsd_be = 0;
  270. psta->uapsd_vi = 0;
  271. psta->uapsd_vo = 0;
  272. psta->has_legacy_ac = 0;
  273. pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
  274. pstapriv->tim_bitmap &= ~BIT(psta->aid);
  275. if ((psta->aid > 0) && (pstapriv->sta_aid[psta->aid - 1] == psta)) {
  276. pstapriv->sta_aid[psta->aid - 1] = NULL;
  277. psta->aid = 0;
  278. }
  279. psta->under_exist_checking = 0;
  280. #endif /* CONFIG_88EU_AP_MODE */
  281. spin_lock_bh(&(pfree_sta_queue->lock));
  282. list_add_tail(&psta->list, get_list_head(pfree_sta_queue));
  283. spin_unlock_bh(&pfree_sta_queue->lock);
  284. exit:
  285. return _SUCCESS;
  286. }
  287. /* free all stainfo which in sta_hash[all] */
  288. void rtw_free_all_stainfo(struct adapter *padapter)
  289. {
  290. struct list_head *plist, *phead;
  291. s32 index;
  292. struct sta_info *psta = NULL;
  293. struct sta_priv *pstapriv = &padapter->stapriv;
  294. struct sta_info *pbcmc_stainfo = rtw_get_bcmc_stainfo(padapter);
  295. if (pstapriv->asoc_sta_count == 1)
  296. return;
  297. spin_lock_bh(&pstapriv->sta_hash_lock);
  298. for (index = 0; index < NUM_STA; index++) {
  299. phead = &(pstapriv->sta_hash[index]);
  300. plist = phead->next;
  301. while (phead != plist) {
  302. psta = container_of(plist, struct sta_info, hash_list);
  303. plist = plist->next;
  304. if (pbcmc_stainfo != psta)
  305. rtw_free_stainfo(padapter, psta);
  306. }
  307. }
  308. spin_unlock_bh(&pstapriv->sta_hash_lock);
  309. }
  310. /* any station allocated can be searched by hash list */
  311. struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
  312. {
  313. struct list_head *plist, *phead;
  314. struct sta_info *psta = NULL;
  315. u32 index;
  316. u8 *addr;
  317. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  318. if (!hwaddr)
  319. return NULL;
  320. if (IS_MCAST(hwaddr))
  321. addr = bc_addr;
  322. else
  323. addr = hwaddr;
  324. index = wifi_mac_hash(addr);
  325. spin_lock_bh(&pstapriv->sta_hash_lock);
  326. phead = &(pstapriv->sta_hash[index]);
  327. plist = phead->next;
  328. while (phead != plist) {
  329. psta = container_of(plist, struct sta_info, hash_list);
  330. if ((!memcmp(psta->hwaddr, addr, ETH_ALEN)) == true) {
  331. /* if found the matched address */
  332. break;
  333. }
  334. psta = NULL;
  335. plist = plist->next;
  336. }
  337. spin_unlock_bh(&pstapriv->sta_hash_lock);
  338. return psta;
  339. }
  340. u32 rtw_init_bcmc_stainfo(struct adapter *padapter)
  341. {
  342. struct sta_info *psta;
  343. u32 res = _SUCCESS;
  344. unsigned char bcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  345. struct sta_priv *pstapriv = &padapter->stapriv;
  346. psta = rtw_alloc_stainfo(pstapriv, bcast_addr);
  347. if (!psta) {
  348. res = _FAIL;
  349. RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_, ("rtw_alloc_stainfo fail"));
  350. goto exit;
  351. }
  352. /* default broadcast & multicast use macid 1 */
  353. psta->mac_id = 1;
  354. exit:
  355. return res;
  356. }
  357. struct sta_info *rtw_get_bcmc_stainfo(struct adapter *padapter)
  358. {
  359. struct sta_info *psta;
  360. struct sta_priv *pstapriv = &padapter->stapriv;
  361. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  362. psta = rtw_get_stainfo(pstapriv, bc_addr);
  363. return psta;
  364. }
  365. u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr)
  366. {
  367. u8 res = true;
  368. #ifdef CONFIG_88EU_AP_MODE
  369. struct list_head *plist, *phead;
  370. struct rtw_wlan_acl_node *paclnode;
  371. u8 match = false;
  372. struct sta_priv *pstapriv = &padapter->stapriv;
  373. struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
  374. struct __queue *pacl_node_q = &pacl_list->acl_node_q;
  375. spin_lock_bh(&(pacl_node_q->lock));
  376. phead = get_list_head(pacl_node_q);
  377. plist = phead->next;
  378. while (phead != plist) {
  379. paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
  380. plist = plist->next;
  381. if (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) {
  382. if (paclnode->valid) {
  383. match = true;
  384. break;
  385. }
  386. }
  387. }
  388. spin_unlock_bh(&pacl_node_q->lock);
  389. if (pacl_list->mode == 1)/* accept unless in deny list */
  390. res = (match) ? false : true;
  391. else if (pacl_list->mode == 2)/* deny unless in accept list */
  392. res = (match) ? true : false;
  393. else
  394. res = true;
  395. #endif
  396. return res;
  397. }