rtw_sta_mgt.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  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. #define _RTW_STA_MGT_C_
  16. #include <drv_types.h>
  17. #if defined(PLATFORM_LINUX) && defined (PLATFORM_WINDOWS)
  18. #error "Shall be Linux or Windows, but not both!\n"
  19. #endif
  20. bool test_st_match_rule(_adapter *adapter, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port)
  21. {
  22. if (ntohs(*((u16 *)local_port)) == 5001 || ntohs(*((u16 *)remote_port)) == 5001)
  23. return _TRUE;
  24. return _FALSE;
  25. }
  26. struct st_register test_st_reg = {
  27. .s_proto = 0x06,
  28. .rule = test_st_match_rule,
  29. };
  30. inline void rtw_st_ctl_init(struct st_ctl_t *st_ctl)
  31. {
  32. _rtw_memset(st_ctl->reg, 0 , sizeof(struct st_register) * SESSION_TRACKER_REG_ID_NUM);
  33. _rtw_init_queue(&st_ctl->tracker_q);
  34. }
  35. inline void rtw_st_ctl_clear_tracker_q(struct st_ctl_t *st_ctl)
  36. {
  37. _irqL irqL;
  38. _list *plist, *phead;
  39. struct session_tracker *st;
  40. _enter_critical_bh(&st_ctl->tracker_q.lock, &irqL);
  41. phead = &st_ctl->tracker_q.queue;
  42. plist = get_next(phead);
  43. while (rtw_end_of_queue_search(phead, plist) == _FALSE) {
  44. st = LIST_CONTAINOR(plist, struct session_tracker, list);
  45. plist = get_next(plist);
  46. rtw_list_delete(&st->list);
  47. rtw_mfree((u8 *)st, sizeof(struct session_tracker));
  48. }
  49. _exit_critical_bh(&st_ctl->tracker_q.lock, &irqL);
  50. }
  51. inline void rtw_st_ctl_deinit(struct st_ctl_t *st_ctl)
  52. {
  53. rtw_st_ctl_clear_tracker_q(st_ctl);
  54. _rtw_deinit_queue(&st_ctl->tracker_q);
  55. }
  56. inline void rtw_st_ctl_register(struct st_ctl_t *st_ctl, u8 st_reg_id, struct st_register *reg)
  57. {
  58. if (st_reg_id >= SESSION_TRACKER_REG_ID_NUM) {
  59. rtw_warn_on(1);
  60. return;
  61. }
  62. st_ctl->reg[st_reg_id].s_proto = reg->s_proto;
  63. st_ctl->reg[st_reg_id].rule = reg->rule;
  64. }
  65. inline void rtw_st_ctl_unregister(struct st_ctl_t *st_ctl, u8 st_reg_id)
  66. {
  67. int i;
  68. if (st_reg_id >= SESSION_TRACKER_REG_ID_NUM) {
  69. rtw_warn_on(1);
  70. return;
  71. }
  72. st_ctl->reg[st_reg_id].s_proto = 0;
  73. st_ctl->reg[st_reg_id].rule = NULL;
  74. /* clear tracker queue if no session trecker registered */
  75. for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++)
  76. if (st_ctl->reg[i].s_proto != 0)
  77. break;
  78. if (i >= SESSION_TRACKER_REG_ID_NUM)
  79. rtw_st_ctl_clear_tracker_q(st_ctl);
  80. }
  81. inline bool rtw_st_ctl_chk_reg_s_proto(struct st_ctl_t *st_ctl, u8 s_proto)
  82. {
  83. bool ret = _FALSE;
  84. int i;
  85. for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++) {
  86. if (st_ctl->reg[i].s_proto == s_proto) {
  87. ret = _TRUE;
  88. break;
  89. }
  90. }
  91. return ret;
  92. }
  93. inline bool rtw_st_ctl_chk_reg_rule(struct st_ctl_t *st_ctl, _adapter *adapter, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port)
  94. {
  95. bool ret = _FALSE;
  96. int i;
  97. st_match_rule rule;
  98. for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++) {
  99. rule = st_ctl->reg[i].rule;
  100. if (rule && rule(adapter, local_naddr, local_port, remote_naddr, remote_port) == _TRUE) {
  101. ret = _TRUE;
  102. break;
  103. }
  104. }
  105. return ret;
  106. }
  107. void rtw_st_ctl_rx(struct sta_info *sta, u8 *ehdr_pos)
  108. {
  109. _adapter *adapter = sta->padapter;
  110. struct ethhdr *etherhdr = (struct ethhdr *)ehdr_pos;
  111. if (ntohs(etherhdr->h_proto) == ETH_P_IP) {
  112. u8 *ip = ehdr_pos + ETH_HLEN;
  113. if (GET_IPV4_PROTOCOL(ip) == 0x06 /* TCP */
  114. && rtw_st_ctl_chk_reg_s_proto(&sta->st_ctl, 0x06) == _TRUE
  115. ) {
  116. u8 *tcp = ip + GET_IPV4_IHL(ip) * 4;
  117. if (rtw_st_ctl_chk_reg_rule(&sta->st_ctl, adapter, IPV4_DST(ip), TCP_DST(tcp), IPV4_SRC(ip), TCP_SRC(tcp)) == _TRUE) {
  118. if (GET_TCP_SYN(tcp) && GET_TCP_ACK(tcp)) {
  119. session_tracker_add_cmd(adapter, sta
  120. , IPV4_DST(ip), TCP_DST(tcp)
  121. , IPV4_SRC(ip), TCP_SRC(tcp));
  122. if (DBG_SESSION_TRACKER)
  123. RTW_INFO(FUNC_ADPT_FMT" local:"IP_FMT":"PORT_FMT", remote:"IP_FMT":"PORT_FMT" SYN-ACK\n"
  124. , FUNC_ADPT_ARG(adapter)
  125. , IP_ARG(IPV4_DST(ip)), PORT_ARG(TCP_DST(tcp))
  126. , IP_ARG(IPV4_SRC(ip)), PORT_ARG(TCP_SRC(tcp)));
  127. }
  128. if (GET_TCP_FIN(tcp)) {
  129. session_tracker_del_cmd(adapter, sta
  130. , IPV4_DST(ip), TCP_DST(tcp)
  131. , IPV4_SRC(ip), TCP_SRC(tcp));
  132. if (DBG_SESSION_TRACKER)
  133. RTW_INFO(FUNC_ADPT_FMT" local:"IP_FMT":"PORT_FMT", remote:"IP_FMT":"PORT_FMT" FIN\n"
  134. , FUNC_ADPT_ARG(adapter)
  135. , IP_ARG(IPV4_DST(ip)), PORT_ARG(TCP_DST(tcp))
  136. , IP_ARG(IPV4_SRC(ip)), PORT_ARG(TCP_SRC(tcp)));
  137. }
  138. }
  139. }
  140. }
  141. }
  142. #define SESSION_TRACKER_FMT IP_FMT":"PORT_FMT" "IP_FMT":"PORT_FMT" %u %d"
  143. #define SESSION_TRACKER_ARG(st) IP_ARG(&(st)->local_naddr), PORT_ARG(&(st)->local_port), IP_ARG(&(st)->remote_naddr), PORT_ARG(&(st)->remote_port), (st)->status, rtw_get_passing_time_ms((st)->set_time)
  144. void dump_st_ctl(void *sel, struct st_ctl_t *st_ctl)
  145. {
  146. int i;
  147. _irqL irqL;
  148. _list *plist, *phead;
  149. struct session_tracker *st;
  150. if (!DBG_SESSION_TRACKER)
  151. return;
  152. for (i = 0; i < SESSION_TRACKER_REG_ID_NUM; i++)
  153. RTW_PRINT_SEL(sel, "reg%d: %u %p\n", i, st_ctl->reg[i].s_proto, st_ctl->reg[i].rule);
  154. _enter_critical_bh(&st_ctl->tracker_q.lock, &irqL);
  155. phead = &st_ctl->tracker_q.queue;
  156. plist = get_next(phead);
  157. while (rtw_end_of_queue_search(phead, plist) == _FALSE) {
  158. st = LIST_CONTAINOR(plist, struct session_tracker, list);
  159. plist = get_next(plist);
  160. RTW_PRINT_SEL(sel, SESSION_TRACKER_FMT"\n", SESSION_TRACKER_ARG(st));
  161. }
  162. _exit_critical_bh(&st_ctl->tracker_q.lock, &irqL);
  163. }
  164. void _rtw_init_stainfo(struct sta_info *psta);
  165. void _rtw_init_stainfo(struct sta_info *psta)
  166. {
  167. _rtw_memset((u8 *)psta, 0, sizeof(struct sta_info));
  168. _rtw_spinlock_init(&psta->lock);
  169. _rtw_init_listhead(&psta->list);
  170. _rtw_init_listhead(&psta->hash_list);
  171. /* _rtw_init_listhead(&psta->asoc_list); */
  172. /* _rtw_init_listhead(&psta->sleep_list); */
  173. /* _rtw_init_listhead(&psta->wakeup_list); */
  174. _rtw_init_queue(&psta->sleep_q);
  175. _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv);
  176. _rtw_init_sta_recv_priv(&psta->sta_recvpriv);
  177. #ifdef CONFIG_AP_MODE
  178. _rtw_init_listhead(&psta->asoc_list);
  179. _rtw_init_listhead(&psta->auth_list);
  180. psta->bpairwise_key_installed = _FALSE;
  181. #ifdef CONFIG_RTW_80211R
  182. psta->ft_pairwise_key_installed = _FALSE;
  183. #endif
  184. #endif /* CONFIG_AP_MODE */
  185. rtw_st_ctl_init(&psta->st_ctl);
  186. }
  187. u32 _rtw_init_sta_priv(struct sta_priv *pstapriv)
  188. {
  189. _adapter *adapter = container_of(pstapriv, _adapter, stapriv);
  190. struct macid_ctl_t *macid_ctl = adapter_to_macidctl(adapter);
  191. struct sta_info *psta;
  192. s32 i;
  193. u32 ret = _FAIL;
  194. pstapriv->padapter = adapter;
  195. pstapriv->pallocated_stainfo_buf = rtw_zvmalloc(sizeof(struct sta_info) * NUM_STA + 4);
  196. if (!pstapriv->pallocated_stainfo_buf)
  197. goto exit;
  198. pstapriv->pstainfo_buf = pstapriv->pallocated_stainfo_buf + 4 -
  199. ((SIZE_PTR)(pstapriv->pallocated_stainfo_buf) & 3);
  200. _rtw_init_queue(&pstapriv->free_sta_queue);
  201. _rtw_spinlock_init(&pstapriv->sta_hash_lock);
  202. /* _rtw_init_queue(&pstapriv->asoc_q); */
  203. pstapriv->asoc_sta_count = 0;
  204. _rtw_init_queue(&pstapriv->sleep_q);
  205. _rtw_init_queue(&pstapriv->wakeup_q);
  206. psta = (struct sta_info *)(pstapriv->pstainfo_buf);
  207. for (i = 0; i < NUM_STA; i++) {
  208. _rtw_init_stainfo(psta);
  209. _rtw_init_listhead(&(pstapriv->sta_hash[i]));
  210. rtw_list_insert_tail(&psta->list, get_list_head(&pstapriv->free_sta_queue));
  211. psta++;
  212. }
  213. pstapriv->adhoc_expire_to = 4; /* 4 * 2 = 8 sec */
  214. #ifdef CONFIG_AP_MODE
  215. pstapriv->max_aid = macid_ctl->num;
  216. pstapriv->rr_aid = 0;
  217. pstapriv->started_aid = 1;
  218. pstapriv->sta_aid = rtw_zmalloc(pstapriv->max_aid * sizeof(struct sta_info *));
  219. if (!pstapriv->sta_aid)
  220. goto exit;
  221. pstapriv->aid_bmp_len = AID_BMP_LEN(pstapriv->max_aid);
  222. pstapriv->sta_dz_bitmap = rtw_zmalloc(pstapriv->aid_bmp_len);
  223. if (!pstapriv->sta_dz_bitmap)
  224. goto exit;
  225. pstapriv->tim_bitmap = rtw_zmalloc(pstapriv->aid_bmp_len);
  226. if (!pstapriv->tim_bitmap)
  227. goto exit;
  228. _rtw_init_listhead(&pstapriv->asoc_list);
  229. _rtw_init_listhead(&pstapriv->auth_list);
  230. _rtw_spinlock_init(&pstapriv->asoc_list_lock);
  231. _rtw_spinlock_init(&pstapriv->auth_list_lock);
  232. pstapriv->asoc_list_cnt = 0;
  233. pstapriv->auth_list_cnt = 0;
  234. pstapriv->auth_to = 3; /* 3*2 = 6 sec */
  235. pstapriv->assoc_to = 3;
  236. /* pstapriv->expire_to = 900; */ /* 900*2 = 1800 sec = 30 min, expire after no any traffic. */
  237. /* pstapriv->expire_to = 30; */ /* 30*2 = 60 sec = 1 min, expire after no any traffic. */
  238. #ifdef CONFIG_ACTIVE_KEEP_ALIVE_CHECK
  239. pstapriv->expire_to = 3; /* 3*2 = 6 sec */
  240. #else
  241. pstapriv->expire_to = 60;/* 60*2 = 120 sec = 2 min, expire after no any traffic. */
  242. #endif
  243. #ifdef CONFIG_ATMEL_RC_PATCH
  244. _rtw_memset(pstapriv->atmel_rc_pattern, 0, ETH_ALEN);
  245. #endif
  246. pstapriv->max_num_sta = NUM_STA;
  247. #endif
  248. #if CONFIG_RTW_MACADDR_ACL
  249. for (i = 0; i < RTW_ACL_PERIOD_NUM; i++)
  250. rtw_macaddr_acl_init(adapter, i);
  251. #endif
  252. #if CONFIG_RTW_PRE_LINK_STA
  253. rtw_pre_link_sta_ctl_init(pstapriv);
  254. #endif
  255. ret = _SUCCESS;
  256. exit:
  257. if (ret != _SUCCESS) {
  258. if (pstapriv->pallocated_stainfo_buf)
  259. rtw_vmfree(pstapriv->pallocated_stainfo_buf, sizeof(struct sta_info) * NUM_STA + 4);
  260. #ifdef CONFIG_AP_MODE
  261. if (pstapriv->sta_aid)
  262. rtw_mfree(pstapriv->sta_aid, pstapriv->max_aid * sizeof(struct sta_info *));
  263. if (pstapriv->sta_dz_bitmap)
  264. rtw_mfree(pstapriv->sta_dz_bitmap, pstapriv->aid_bmp_len);
  265. #endif
  266. }
  267. return ret;
  268. }
  269. inline int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta)
  270. {
  271. int offset = (((u8 *)sta) - stapriv->pstainfo_buf) / sizeof(struct sta_info);
  272. if (!stainfo_offset_valid(offset))
  273. RTW_INFO("%s invalid offset(%d), out of range!!!", __func__, offset);
  274. return offset;
  275. }
  276. inline struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset)
  277. {
  278. if (!stainfo_offset_valid(offset))
  279. RTW_INFO("%s invalid offset(%d), out of range!!!", __func__, offset);
  280. return (struct sta_info *)(stapriv->pstainfo_buf + offset * sizeof(struct sta_info));
  281. }
  282. void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv);
  283. void _rtw_free_sta_xmit_priv_lock(struct sta_xmit_priv *psta_xmitpriv)
  284. {
  285. _rtw_spinlock_free(&psta_xmitpriv->lock);
  286. _rtw_spinlock_free(&(psta_xmitpriv->be_q.sta_pending.lock));
  287. _rtw_spinlock_free(&(psta_xmitpriv->bk_q.sta_pending.lock));
  288. _rtw_spinlock_free(&(psta_xmitpriv->vi_q.sta_pending.lock));
  289. _rtw_spinlock_free(&(psta_xmitpriv->vo_q.sta_pending.lock));
  290. }
  291. static void _rtw_free_sta_recv_priv_lock(struct sta_recv_priv *psta_recvpriv)
  292. {
  293. _rtw_spinlock_free(&psta_recvpriv->lock);
  294. _rtw_spinlock_free(&(psta_recvpriv->defrag_q.lock));
  295. }
  296. void rtw_mfree_stainfo(struct sta_info *psta);
  297. void rtw_mfree_stainfo(struct sta_info *psta)
  298. {
  299. if (&psta->lock != NULL)
  300. _rtw_spinlock_free(&psta->lock);
  301. _rtw_free_sta_xmit_priv_lock(&psta->sta_xmitpriv);
  302. _rtw_free_sta_recv_priv_lock(&psta->sta_recvpriv);
  303. }
  304. /* this function is used to free the memory of lock || sema for all stainfos */
  305. void rtw_mfree_all_stainfo(struct sta_priv *pstapriv);
  306. void rtw_mfree_all_stainfo(struct sta_priv *pstapriv)
  307. {
  308. _irqL irqL;
  309. _list *plist, *phead;
  310. struct sta_info *psta = NULL;
  311. _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  312. phead = get_list_head(&pstapriv->free_sta_queue);
  313. plist = get_next(phead);
  314. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  315. psta = LIST_CONTAINOR(plist, struct sta_info , list);
  316. plist = get_next(plist);
  317. rtw_mfree_stainfo(psta);
  318. }
  319. _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  320. }
  321. void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv);
  322. void rtw_mfree_sta_priv_lock(struct sta_priv *pstapriv)
  323. {
  324. rtw_mfree_all_stainfo(pstapriv); /* be done before free sta_hash_lock */
  325. _rtw_spinlock_free(&pstapriv->free_sta_queue.lock);
  326. _rtw_spinlock_free(&pstapriv->sta_hash_lock);
  327. _rtw_spinlock_free(&pstapriv->wakeup_q.lock);
  328. _rtw_spinlock_free(&pstapriv->sleep_q.lock);
  329. #ifdef CONFIG_AP_MODE
  330. _rtw_spinlock_free(&pstapriv->asoc_list_lock);
  331. _rtw_spinlock_free(&pstapriv->auth_list_lock);
  332. #endif
  333. }
  334. u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)
  335. {
  336. _irqL irqL;
  337. _list *phead, *plist;
  338. struct sta_info *psta = NULL;
  339. struct recv_reorder_ctrl *preorder_ctrl;
  340. int index;
  341. if (pstapriv) {
  342. /* delete all reordering_ctrl_timer */
  343. _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  344. for (index = 0; index < NUM_STA; index++) {
  345. phead = &(pstapriv->sta_hash[index]);
  346. plist = get_next(phead);
  347. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  348. int i;
  349. psta = LIST_CONTAINOR(plist, struct sta_info , hash_list);
  350. plist = get_next(plist);
  351. for (i = 0; i < 16 ; i++) {
  352. preorder_ctrl = &psta->recvreorder_ctrl[i];
  353. _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
  354. }
  355. }
  356. }
  357. _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  358. /*===============================*/
  359. rtw_mfree_sta_priv_lock(pstapriv);
  360. #if CONFIG_RTW_MACADDR_ACL
  361. for (index = 0; index < RTW_ACL_PERIOD_NUM; index++)
  362. rtw_macaddr_acl_deinit(pstapriv->padapter, index);
  363. #endif
  364. #if CONFIG_RTW_PRE_LINK_STA
  365. rtw_pre_link_sta_ctl_deinit(pstapriv);
  366. #endif
  367. if (pstapriv->pallocated_stainfo_buf)
  368. rtw_vmfree(pstapriv->pallocated_stainfo_buf, sizeof(struct sta_info) * NUM_STA + 4);
  369. #ifdef CONFIG_AP_MODE
  370. if (pstapriv->sta_aid)
  371. rtw_mfree(pstapriv->sta_aid, pstapriv->max_aid * sizeof(struct sta_info *));
  372. if (pstapriv->sta_dz_bitmap)
  373. rtw_mfree(pstapriv->sta_dz_bitmap, pstapriv->aid_bmp_len);
  374. if (pstapriv->tim_bitmap)
  375. rtw_mfree(pstapriv->tim_bitmap, pstapriv->aid_bmp_len);
  376. #endif
  377. }
  378. return _SUCCESS;
  379. }
  380. static void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl)
  381. {
  382. _adapter *padapter = preorder_ctrl->padapter;
  383. #if defined(CONFIG_80211N_HT) && defined(CONFIG_RECV_REORDERING_CTRL)
  384. rtw_init_timer(&(preorder_ctrl->reordering_ctrl_timer), padapter, rtw_reordering_ctrl_timeout_handler, preorder_ctrl);
  385. #endif
  386. }
  387. /* struct sta_info *rtw_alloc_stainfo(_queue *pfree_sta_queue, unsigned char *hwaddr) */
  388. struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr)
  389. {
  390. _irqL irqL2;
  391. s32 index;
  392. _list *phash_list;
  393. struct sta_info *psta;
  394. _queue *pfree_sta_queue;
  395. struct recv_reorder_ctrl *preorder_ctrl;
  396. int i = 0;
  397. u16 wRxSeqInitialValue = 0xffff;
  398. pfree_sta_queue = &pstapriv->free_sta_queue;
  399. /* _enter_critical_bh(&(pfree_sta_queue->lock), &irqL); */
  400. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
  401. if (_rtw_queue_empty(pfree_sta_queue) == _TRUE) {
  402. /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL); */
  403. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
  404. psta = NULL;
  405. } else {
  406. psta = LIST_CONTAINOR(get_next(&pfree_sta_queue->queue), struct sta_info, list);
  407. rtw_list_delete(&(psta->list));
  408. /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL); */
  409. _rtw_init_stainfo(psta);
  410. psta->padapter = pstapriv->padapter;
  411. _rtw_memcpy(psta->cmn.mac_addr, hwaddr, ETH_ALEN);
  412. index = wifi_mac_hash(hwaddr);
  413. if (index >= NUM_STA) {
  414. psta = NULL;
  415. goto exit;
  416. }
  417. phash_list = &(pstapriv->sta_hash[index]);
  418. /* _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL2); */
  419. rtw_list_insert_tail(&psta->hash_list, phash_list);
  420. pstapriv->asoc_sta_count++;
  421. /* _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2); */
  422. /* Commented by Albert 2009/08/13
  423. * For the SMC router, the sequence number of first packet of WPS handshake will be 0.
  424. * 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.
  425. * So, we initialize the tid_rxseq variable as the 0xffff. */
  426. for (i = 0; i < 16; i++) {
  427. _rtw_memcpy(&psta->sta_recvpriv.rxcache.tid_rxseq[i], &wRxSeqInitialValue, 2);
  428. _rtw_memcpy(&psta->sta_recvpriv.bmc_tid_rxseq[i], &wRxSeqInitialValue, 2);
  429. _rtw_memset(&psta->sta_recvpriv.rxcache.iv[i], 0, sizeof(psta->sta_recvpriv.rxcache.iv[i]));
  430. }
  431. rtw_init_timer(&psta->addba_retry_timer, psta->padapter, addba_timer_hdl, psta);
  432. #ifdef CONFIG_IEEE80211W
  433. rtw_init_timer(&psta->dot11w_expire_timer, psta->padapter, sa_query_timer_hdl, psta);
  434. #endif /* CONFIG_IEEE80211W */
  435. #ifdef CONFIG_TDLS
  436. rtw_init_tdls_timer(pstapriv->padapter, psta);
  437. #endif /* CONFIG_TDLS */
  438. /* for A-MPDU Rx reordering buffer control */
  439. for (i = 0; i < 16 ; i++) {
  440. preorder_ctrl = &psta->recvreorder_ctrl[i];
  441. preorder_ctrl->padapter = pstapriv->padapter;
  442. preorder_ctrl->tid = i;
  443. preorder_ctrl->enable = _FALSE;
  444. preorder_ctrl->indicate_seq = 0xffff;
  445. #ifdef DBG_RX_SEQ
  446. RTW_INFO("DBG_RX_SEQ "FUNC_ADPT_FMT" tid:%u SN_CLEAR indicate_seq:%d\n"
  447. , FUNC_ADPT_ARG(pstapriv->padapter), i, preorder_ctrl->indicate_seq);
  448. #endif
  449. preorder_ctrl->wend_b = 0xffff;
  450. /* preorder_ctrl->wsize_b = (NR_RECVBUFF-2); */
  451. preorder_ctrl->wsize_b = 64;/* 64; */
  452. preorder_ctrl->ampdu_size = RX_AMPDU_SIZE_INVALID;
  453. _rtw_init_queue(&preorder_ctrl->pending_recvframe_queue);
  454. rtw_init_recv_timer(preorder_ctrl);
  455. }
  456. /* init for DM */
  457. psta->cmn.rssi_stat.rssi = (-1);
  458. psta->cmn.rssi_stat.rssi_cck = (-1);
  459. psta->cmn.rssi_stat.rssi_ofdm = (-1);
  460. #ifdef CONFIG_ATMEL_RC_PATCH
  461. psta->flag_atmel_rc = 0;
  462. #endif
  463. /* init for the sequence number of received management frame */
  464. psta->RxMgmtFrameSeqNum = 0xffff;
  465. _rtw_memset(&psta->sta_stats, 0, sizeof(struct stainfo_stats));
  466. rtw_alloc_macid(pstapriv->padapter, psta);
  467. }
  468. exit:
  469. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL2);
  470. if (psta)
  471. rtw_mi_update_iface_status(&(pstapriv->padapter->mlmepriv), 0);
  472. return psta;
  473. }
  474. /* using pstapriv->sta_hash_lock to protect */
  475. u32 rtw_free_stainfo(_adapter *padapter , struct sta_info *psta)
  476. {
  477. int i;
  478. _irqL irqL0;
  479. _queue *pfree_sta_queue;
  480. struct recv_reorder_ctrl *preorder_ctrl;
  481. struct sta_xmit_priv *pstaxmitpriv;
  482. struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
  483. struct sta_priv *pstapriv = &padapter->stapriv;
  484. struct hw_xmit *phwxmit;
  485. struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
  486. struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
  487. int pending_qcnt[4];
  488. u8 is_pre_link_sta = _FALSE;
  489. if (psta == NULL)
  490. goto exit;
  491. #ifdef CONFIG_RTW_80211K
  492. rm_post_event(padapter, RM_ID_FOR_ALL(psta->cmn.aid), RM_EV_cancel);
  493. #endif
  494. is_pre_link_sta = rtw_is_pre_link_sta(pstapriv, psta->cmn.mac_addr);
  495. if (is_pre_link_sta == _FALSE) {
  496. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
  497. rtw_list_delete(&psta->hash_list);
  498. pstapriv->asoc_sta_count--;
  499. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
  500. rtw_mi_update_iface_status(&(padapter->mlmepriv), 0);
  501. } else {
  502. _enter_critical_bh(&psta->lock, &irqL0);
  503. psta->state = WIFI_FW_PRE_LINK;
  504. _exit_critical_bh(&psta->lock, &irqL0);
  505. }
  506. _enter_critical_bh(&psta->lock, &irqL0);
  507. psta->state &= ~_FW_LINKED;
  508. _exit_critical_bh(&psta->lock, &irqL0);
  509. pfree_sta_queue = &pstapriv->free_sta_queue;
  510. pstaxmitpriv = &psta->sta_xmitpriv;
  511. /* rtw_list_delete(&psta->sleep_list); */
  512. /* rtw_list_delete(&psta->wakeup_list); */
  513. _enter_critical_bh(&pxmitpriv->lock, &irqL0);
  514. rtw_free_xmitframe_queue(pxmitpriv, &psta->sleep_q);
  515. psta->sleepq_len = 0;
  516. /* vo */
  517. /* _enter_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0); */
  518. rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vo_q.sta_pending);
  519. rtw_list_delete(&(pstaxmitpriv->vo_q.tx_pending));
  520. phwxmit = pxmitpriv->hwxmits;
  521. phwxmit->accnt -= pstaxmitpriv->vo_q.qcnt;
  522. pending_qcnt[0] = pstaxmitpriv->vo_q.qcnt;
  523. pstaxmitpriv->vo_q.qcnt = 0;
  524. /* _exit_critical_bh(&(pxmitpriv->vo_pending.lock), &irqL0); */
  525. /* vi */
  526. /* _enter_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0); */
  527. rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->vi_q.sta_pending);
  528. rtw_list_delete(&(pstaxmitpriv->vi_q.tx_pending));
  529. phwxmit = pxmitpriv->hwxmits + 1;
  530. phwxmit->accnt -= pstaxmitpriv->vi_q.qcnt;
  531. pending_qcnt[1] = pstaxmitpriv->vi_q.qcnt;
  532. pstaxmitpriv->vi_q.qcnt = 0;
  533. /* _exit_critical_bh(&(pxmitpriv->vi_pending.lock), &irqL0); */
  534. /* be */
  535. /* _enter_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0); */
  536. rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->be_q.sta_pending);
  537. rtw_list_delete(&(pstaxmitpriv->be_q.tx_pending));
  538. phwxmit = pxmitpriv->hwxmits + 2;
  539. phwxmit->accnt -= pstaxmitpriv->be_q.qcnt;
  540. pending_qcnt[2] = pstaxmitpriv->be_q.qcnt;
  541. pstaxmitpriv->be_q.qcnt = 0;
  542. /* _exit_critical_bh(&(pxmitpriv->be_pending.lock), &irqL0); */
  543. /* bk */
  544. /* _enter_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0); */
  545. rtw_free_xmitframe_queue(pxmitpriv, &pstaxmitpriv->bk_q.sta_pending);
  546. rtw_list_delete(&(pstaxmitpriv->bk_q.tx_pending));
  547. phwxmit = pxmitpriv->hwxmits + 3;
  548. phwxmit->accnt -= pstaxmitpriv->bk_q.qcnt;
  549. pending_qcnt[3] = pstaxmitpriv->bk_q.qcnt;
  550. pstaxmitpriv->bk_q.qcnt = 0;
  551. /* _exit_critical_bh(&(pxmitpriv->bk_pending.lock), &irqL0); */
  552. rtw_os_wake_queue_at_free_stainfo(padapter, pending_qcnt);
  553. _exit_critical_bh(&pxmitpriv->lock, &irqL0);
  554. /* re-init sta_info; 20061114 */ /* will be init in alloc_stainfo */
  555. /* _rtw_init_sta_xmit_priv(&psta->sta_xmitpriv); */
  556. /* _rtw_init_sta_recv_priv(&psta->sta_recvpriv); */
  557. #ifdef CONFIG_IEEE80211W
  558. _cancel_timer_ex(&psta->dot11w_expire_timer);
  559. #endif /* CONFIG_IEEE80211W */
  560. _cancel_timer_ex(&psta->addba_retry_timer);
  561. #ifdef CONFIG_TDLS
  562. psta->tdls_sta_state = TDLS_STATE_NONE;
  563. #endif /* CONFIG_TDLS */
  564. /* for A-MPDU Rx reordering buffer control, cancel reordering_ctrl_timer */
  565. for (i = 0; i < 16 ; i++) {
  566. _irqL irqL;
  567. _list *phead, *plist;
  568. union recv_frame *prframe;
  569. _queue *ppending_recvframe_queue;
  570. _queue *pfree_recv_queue = &padapter->recvpriv.free_recv_queue;
  571. preorder_ctrl = &psta->recvreorder_ctrl[i];
  572. _cancel_timer_ex(&preorder_ctrl->reordering_ctrl_timer);
  573. ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
  574. _enter_critical_bh(&ppending_recvframe_queue->lock, &irqL);
  575. phead = get_list_head(ppending_recvframe_queue);
  576. plist = get_next(phead);
  577. while (!rtw_is_list_empty(phead)) {
  578. prframe = LIST_CONTAINOR(plist, union recv_frame, u);
  579. plist = get_next(plist);
  580. rtw_list_delete(&(prframe->u.hdr.list));
  581. rtw_free_recvframe(prframe, pfree_recv_queue);
  582. }
  583. _exit_critical_bh(&ppending_recvframe_queue->lock, &irqL);
  584. }
  585. if (!((psta->state & WIFI_AP_STATE) || MacAddr_isBcst(psta->cmn.mac_addr)) && is_pre_link_sta == _FALSE)
  586. rtw_hal_set_odm_var(padapter, HAL_ODM_STA_INFO, psta, _FALSE);
  587. /* release mac id for non-bc/mc station, */
  588. if (is_pre_link_sta == _FALSE)
  589. rtw_release_macid(pstapriv->padapter, psta);
  590. #ifdef CONFIG_AP_MODE
  591. /*
  592. _enter_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
  593. rtw_list_delete(&psta->asoc_list);
  594. _exit_critical_bh(&pstapriv->asoc_list_lock, &irqL0);
  595. */
  596. _enter_critical_bh(&pstapriv->auth_list_lock, &irqL0);
  597. if (!rtw_is_list_empty(&psta->auth_list)) {
  598. rtw_list_delete(&psta->auth_list);
  599. pstapriv->auth_list_cnt--;
  600. }
  601. _exit_critical_bh(&pstapriv->auth_list_lock, &irqL0);
  602. psta->expire_to = 0;
  603. #ifdef CONFIG_ATMEL_RC_PATCH
  604. psta->flag_atmel_rc = 0;
  605. #endif
  606. psta->sleepq_ac_len = 0;
  607. psta->qos_info = 0;
  608. psta->max_sp_len = 0;
  609. psta->uapsd_bk = 0;
  610. psta->uapsd_be = 0;
  611. psta->uapsd_vi = 0;
  612. psta->uapsd_vo = 0;
  613. psta->has_legacy_ac = 0;
  614. #ifdef CONFIG_NATIVEAP_MLME
  615. if (pmlmeinfo->state == _HW_STATE_AP_) {
  616. rtw_tim_map_clear(padapter, pstapriv->sta_dz_bitmap, psta->cmn.aid);
  617. rtw_tim_map_clear(padapter, pstapriv->tim_bitmap, psta->cmn.aid);
  618. /* rtw_indicate_sta_disassoc_event(padapter, psta); */
  619. if ((psta->cmn.aid > 0) && (pstapriv->sta_aid[psta->cmn.aid - 1] == psta)) {
  620. pstapriv->sta_aid[psta->cmn.aid - 1] = NULL;
  621. psta->cmn.aid = 0;
  622. }
  623. }
  624. #endif /* CONFIG_NATIVEAP_MLME */
  625. #ifdef CONFIG_TX_MCAST2UNI
  626. psta->under_exist_checking = 0;
  627. #endif /* CONFIG_TX_MCAST2UNI */
  628. #endif /* CONFIG_AP_MODE */
  629. rtw_st_ctl_deinit(&psta->st_ctl);
  630. if (is_pre_link_sta == _FALSE) {
  631. _rtw_spinlock_free(&psta->lock);
  632. /* _enter_critical_bh(&(pfree_sta_queue->lock), &irqL0); */
  633. _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
  634. rtw_list_insert_tail(&psta->list, get_list_head(pfree_sta_queue));
  635. _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL0);
  636. /* _exit_critical_bh(&(pfree_sta_queue->lock), &irqL0); */
  637. }
  638. exit:
  639. return _SUCCESS;
  640. }
  641. /* free all stainfo which in sta_hash[all] */
  642. void rtw_free_all_stainfo(_adapter *padapter)
  643. {
  644. _irqL irqL;
  645. _list *plist, *phead;
  646. s32 index;
  647. struct sta_info *psta = NULL;
  648. struct sta_priv *pstapriv = &padapter->stapriv;
  649. struct sta_info *pbcmc_stainfo = rtw_get_bcmc_stainfo(padapter);
  650. u8 free_sta_num = 0;
  651. char free_sta_list[NUM_STA];
  652. int stainfo_offset;
  653. if (pstapriv->asoc_sta_count == 1)
  654. goto exit;
  655. _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  656. for (index = 0; index < NUM_STA; index++) {
  657. phead = &(pstapriv->sta_hash[index]);
  658. plist = get_next(phead);
  659. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  660. psta = LIST_CONTAINOR(plist, struct sta_info , hash_list);
  661. plist = get_next(plist);
  662. if (pbcmc_stainfo != psta) {
  663. if (rtw_is_pre_link_sta(pstapriv, psta->cmn.mac_addr) == _FALSE)
  664. rtw_list_delete(&psta->hash_list);
  665. stainfo_offset = rtw_stainfo_offset(pstapriv, psta);
  666. if (stainfo_offset_valid(stainfo_offset))
  667. free_sta_list[free_sta_num++] = stainfo_offset;
  668. }
  669. }
  670. }
  671. _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  672. for (index = 0; index < free_sta_num; index++) {
  673. psta = rtw_get_stainfo_by_offset(pstapriv, free_sta_list[index]);
  674. rtw_free_stainfo(padapter , psta);
  675. }
  676. exit:
  677. return;
  678. }
  679. /* any station allocated can be searched by hash list */
  680. struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr)
  681. {
  682. _irqL irqL;
  683. _list *plist, *phead;
  684. struct sta_info *psta = NULL;
  685. u32 index;
  686. const u8 *addr;
  687. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  688. if (hwaddr == NULL)
  689. return NULL;
  690. if (IS_MCAST(hwaddr))
  691. addr = bc_addr;
  692. else
  693. addr = hwaddr;
  694. index = wifi_mac_hash(addr);
  695. _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  696. phead = &(pstapriv->sta_hash[index]);
  697. plist = get_next(phead);
  698. while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
  699. psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
  700. if ((_rtw_memcmp(psta->cmn.mac_addr, addr, ETH_ALEN)) == _TRUE) {
  701. /* if found the matched address */
  702. break;
  703. }
  704. psta = NULL;
  705. plist = get_next(plist);
  706. }
  707. _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
  708. return psta;
  709. }
  710. u32 rtw_init_bcmc_stainfo(_adapter *padapter)
  711. {
  712. struct sta_info *psta;
  713. struct tx_servq *ptxservq;
  714. u32 res = _SUCCESS;
  715. NDIS_802_11_MAC_ADDRESS bcast_addr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  716. struct sta_priv *pstapriv = &padapter->stapriv;
  717. /* _queue *pstapending = &padapter->xmitpriv.bm_pending; */
  718. psta = rtw_alloc_stainfo(pstapriv, bcast_addr);
  719. if (psta == NULL) {
  720. res = _FAIL;
  721. goto exit;
  722. }
  723. #ifdef CONFIG_BEAMFORMING
  724. psta->cmn.bf_info.g_id = 63;
  725. psta->cmn.bf_info.p_aid = 0;
  726. #endif
  727. ptxservq = &(psta->sta_xmitpriv.be_q);
  728. /*
  729. _enter_critical(&pstapending->lock, &irqL0);
  730. if (rtw_is_list_empty(&ptxservq->tx_pending))
  731. rtw_list_insert_tail(&ptxservq->tx_pending, get_list_head(pstapending));
  732. _exit_critical(&pstapending->lock, &irqL0);
  733. */
  734. exit:
  735. return _SUCCESS;
  736. }
  737. struct sta_info *rtw_get_bcmc_stainfo(_adapter *padapter)
  738. {
  739. struct sta_info *psta;
  740. struct sta_priv *pstapriv = &padapter->stapriv;
  741. u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  742. psta = rtw_get_stainfo(pstapriv, bc_addr);
  743. return psta;
  744. }
  745. #ifdef CONFIG_AP_MODE
  746. u16 rtw_aid_alloc(_adapter *adapter, struct sta_info *sta)
  747. {
  748. struct sta_priv *stapriv = &adapter->stapriv;
  749. u16 aid, i, used_cnt = 0;
  750. for (i = 0; i < stapriv->max_aid; i++) {
  751. aid = ((i + stapriv->started_aid - 1) % stapriv->max_aid) + 1;
  752. if (stapriv->sta_aid[aid - 1] == NULL)
  753. break;
  754. if (++used_cnt >= stapriv->max_num_sta)
  755. break;
  756. }
  757. /* check for aid limit and assoc limit */
  758. if (i >= stapriv->max_aid || used_cnt >= stapriv->max_num_sta)
  759. aid = 0;
  760. sta->cmn.aid = aid;
  761. if (aid) {
  762. stapriv->sta_aid[aid - 1] = sta;
  763. if (stapriv->rr_aid)
  764. stapriv->started_aid = (aid % stapriv->max_aid) + 1;
  765. }
  766. return aid;
  767. }
  768. void dump_aid_status(void *sel, _adapter *adapter)
  769. {
  770. struct sta_priv *stapriv = &adapter->stapriv;
  771. u8 *aid_bmp;
  772. u16 i, used_cnt = 0;
  773. aid_bmp = rtw_zmalloc(stapriv->aid_bmp_len);
  774. if (!aid_bmp)
  775. return;
  776. for (i = 1; i <= stapriv->max_aid; i++) {
  777. if (stapriv->sta_aid[i - 1]) {
  778. aid_bmp[i / 8] |= BIT(i % 8);
  779. ++used_cnt;
  780. }
  781. }
  782. RTW_PRINT_SEL(sel, "used_cnt:%u/%u\n", used_cnt, stapriv->max_aid);
  783. RTW_MAP_DUMP_SEL(sel, "aid_map:", aid_bmp, stapriv->aid_bmp_len);
  784. RTW_PRINT_SEL(sel, "\n");
  785. RTW_PRINT_SEL(sel, "%-2s %-11s\n", "rr", "started_aid");
  786. RTW_PRINT_SEL(sel, "%2d %11d\n", stapriv->rr_aid, stapriv->started_aid);
  787. rtw_mfree(aid_bmp, stapriv->aid_bmp_len);
  788. }
  789. #endif /* CONFIG_AP_MODE */
  790. #if CONFIG_RTW_MACADDR_ACL
  791. const char *const _acl_period_str[RTW_ACL_PERIOD_NUM] = {
  792. "DEV",
  793. "BSS",
  794. };
  795. const char *const _acl_mode_str[RTW_ACL_MODE_MAX] = {
  796. "DISABLED",
  797. "ACCEPT_UNLESS_LISTED",
  798. "DENY_UNLESS_LISTED",
  799. };
  800. u8 _rtw_access_ctrl(_adapter *adapter, u8 period, const u8 *mac_addr)
  801. {
  802. u8 res = _TRUE;
  803. _irqL irqL;
  804. _list *list, *head;
  805. struct rtw_wlan_acl_node *acl_node;
  806. u8 match = _FALSE;
  807. struct sta_priv *stapriv = &adapter->stapriv;
  808. struct wlan_acl_pool *acl;
  809. _queue *acl_node_q;
  810. if (period >= RTW_ACL_PERIOD_NUM) {
  811. rtw_warn_on(1);
  812. goto exit;
  813. }
  814. acl = &stapriv->acl_list[period];
  815. acl_node_q = &acl->acl_node_q;
  816. if (acl->mode != RTW_ACL_MODE_ACCEPT_UNLESS_LISTED
  817. && acl->mode != RTW_ACL_MODE_DENY_UNLESS_LISTED)
  818. goto exit;
  819. _enter_critical_bh(&(acl_node_q->lock), &irqL);
  820. head = get_list_head(acl_node_q);
  821. list = get_next(head);
  822. while (rtw_end_of_queue_search(head, list) == _FALSE) {
  823. acl_node = LIST_CONTAINOR(list, struct rtw_wlan_acl_node, list);
  824. list = get_next(list);
  825. if (_rtw_memcmp(acl_node->addr, mac_addr, ETH_ALEN)) {
  826. if (acl_node->valid == _TRUE) {
  827. match = _TRUE;
  828. break;
  829. }
  830. }
  831. }
  832. _exit_critical_bh(&(acl_node_q->lock), &irqL);
  833. if (acl->mode == RTW_ACL_MODE_ACCEPT_UNLESS_LISTED)
  834. res = (match == _TRUE) ? _FALSE : _TRUE;
  835. else /* RTW_ACL_MODE_DENY_UNLESS_LISTED */
  836. res = (match == _TRUE) ? _TRUE : _FALSE;
  837. exit:
  838. return res;
  839. }
  840. u8 rtw_access_ctrl(_adapter *adapter, const u8 *mac_addr)
  841. {
  842. int i;
  843. for (i = 0; i < RTW_ACL_PERIOD_NUM; i++)
  844. if (_rtw_access_ctrl(adapter, i, mac_addr) == _FALSE)
  845. return _FALSE;
  846. return _TRUE;
  847. }
  848. void dump_macaddr_acl(void *sel, _adapter *adapter)
  849. {
  850. struct sta_priv *stapriv = &adapter->stapriv;
  851. struct wlan_acl_pool *acl;
  852. int i, j;
  853. for (j = 0; j < RTW_ACL_PERIOD_NUM; j++) {
  854. RTW_PRINT_SEL(sel, "period:%s(%d)\n", acl_period_str(j), j);
  855. acl = &stapriv->acl_list[j];
  856. RTW_PRINT_SEL(sel, "mode:%s(%d)\n", acl_mode_str(acl->mode), acl->mode);
  857. RTW_PRINT_SEL(sel, "num:%d/%d\n", acl->num, NUM_ACL);
  858. for (i = 0; i < NUM_ACL; i++) {
  859. if (acl->aclnode[i].valid == _FALSE)
  860. continue;
  861. RTW_PRINT_SEL(sel, MAC_FMT"\n", MAC_ARG(acl->aclnode[i].addr));
  862. }
  863. RTW_PRINT_SEL(sel, "\n");
  864. }
  865. }
  866. #endif /* CONFIG_RTW_MACADDR_ACL */
  867. bool rtw_is_pre_link_sta(struct sta_priv *stapriv, u8 *addr)
  868. {
  869. #if CONFIG_RTW_PRE_LINK_STA
  870. struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
  871. struct sta_info *sta = NULL;
  872. u8 exist = _FALSE;
  873. int i;
  874. _irqL irqL;
  875. _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
  876. for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
  877. if (pre_link_sta_ctl->node[i].valid == _TRUE
  878. && _rtw_memcmp(pre_link_sta_ctl->node[i].addr, addr, ETH_ALEN) == _TRUE
  879. ) {
  880. exist = _TRUE;
  881. break;
  882. }
  883. }
  884. _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
  885. return exist;
  886. #else
  887. return _FALSE;
  888. #endif
  889. }
  890. #if CONFIG_RTW_PRE_LINK_STA
  891. struct sta_info *rtw_pre_link_sta_add(struct sta_priv *stapriv, u8 *hwaddr)
  892. {
  893. struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
  894. struct pre_link_sta_node_t *node = NULL;
  895. struct sta_info *sta = NULL;
  896. u8 exist = _FALSE;
  897. int i;
  898. _irqL irqL;
  899. if (rtw_check_invalid_mac_address(hwaddr, _FALSE) == _TRUE)
  900. goto exit;
  901. _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
  902. for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
  903. if (pre_link_sta_ctl->node[i].valid == _TRUE
  904. && _rtw_memcmp(pre_link_sta_ctl->node[i].addr, hwaddr, ETH_ALEN) == _TRUE
  905. ) {
  906. node = &pre_link_sta_ctl->node[i];
  907. exist = _TRUE;
  908. break;
  909. }
  910. if (node == NULL && pre_link_sta_ctl->node[i].valid == _FALSE)
  911. node = &pre_link_sta_ctl->node[i];
  912. }
  913. if (exist == _FALSE && node) {
  914. _rtw_memcpy(node->addr, hwaddr, ETH_ALEN);
  915. node->valid = _TRUE;
  916. pre_link_sta_ctl->num++;
  917. }
  918. _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
  919. if (node == NULL)
  920. goto exit;
  921. sta = rtw_get_stainfo(stapriv, hwaddr);
  922. if (sta)
  923. goto odm_hook;
  924. sta = rtw_alloc_stainfo(stapriv, hwaddr);
  925. if (!sta)
  926. goto exit;
  927. sta->state = WIFI_FW_PRE_LINK;
  928. odm_hook:
  929. rtw_hal_set_odm_var(stapriv->padapter, HAL_ODM_STA_INFO, sta, _TRUE);
  930. exit:
  931. return sta;
  932. }
  933. void rtw_pre_link_sta_del(struct sta_priv *stapriv, u8 *hwaddr)
  934. {
  935. struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
  936. struct pre_link_sta_node_t *node = NULL;
  937. struct sta_info *sta = NULL;
  938. u8 exist = _FALSE;
  939. int i;
  940. _irqL irqL;
  941. if (rtw_check_invalid_mac_address(hwaddr, _FALSE) == _TRUE)
  942. goto exit;
  943. _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
  944. for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
  945. if (pre_link_sta_ctl->node[i].valid == _TRUE
  946. && _rtw_memcmp(pre_link_sta_ctl->node[i].addr, hwaddr, ETH_ALEN) == _TRUE
  947. ) {
  948. node = &pre_link_sta_ctl->node[i];
  949. exist = _TRUE;
  950. break;
  951. }
  952. }
  953. if (exist == _TRUE && node) {
  954. node->valid = _FALSE;
  955. pre_link_sta_ctl->num--;
  956. }
  957. _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
  958. if (exist == _FALSE)
  959. goto exit;
  960. sta = rtw_get_stainfo(stapriv, hwaddr);
  961. if (!sta)
  962. goto exit;
  963. if (sta->state == WIFI_FW_PRE_LINK)
  964. rtw_free_stainfo(stapriv->padapter, sta);
  965. exit:
  966. return;
  967. }
  968. void rtw_pre_link_sta_ctl_reset(struct sta_priv *stapriv)
  969. {
  970. struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
  971. struct pre_link_sta_node_t *node = NULL;
  972. struct sta_info *sta = NULL;
  973. int i, j = 0;
  974. _irqL irqL;
  975. u8 addrs[RTW_PRE_LINK_STA_NUM][ETH_ALEN];
  976. _rtw_memset(addrs, 0, RTW_PRE_LINK_STA_NUM * ETH_ALEN);
  977. _enter_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
  978. for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
  979. if (pre_link_sta_ctl->node[i].valid == _FALSE)
  980. continue;
  981. _rtw_memcpy(&(addrs[j][0]), pre_link_sta_ctl->node[i].addr, ETH_ALEN);
  982. pre_link_sta_ctl->node[i].valid = _FALSE;
  983. pre_link_sta_ctl->num--;
  984. j++;
  985. }
  986. _exit_critical_bh(&(pre_link_sta_ctl->lock), &irqL);
  987. for (i = 0; i < j; i++) {
  988. sta = rtw_get_stainfo(stapriv, &(addrs[i][0]));
  989. if (!sta)
  990. continue;
  991. if (sta->state == WIFI_FW_PRE_LINK)
  992. rtw_free_stainfo(stapriv->padapter, sta);
  993. }
  994. }
  995. void rtw_pre_link_sta_ctl_init(struct sta_priv *stapriv)
  996. {
  997. struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
  998. int i;
  999. _rtw_spinlock_init(&pre_link_sta_ctl->lock);
  1000. pre_link_sta_ctl->num = 0;
  1001. for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++)
  1002. pre_link_sta_ctl->node[i].valid = _FALSE;
  1003. }
  1004. void rtw_pre_link_sta_ctl_deinit(struct sta_priv *stapriv)
  1005. {
  1006. struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
  1007. int i;
  1008. rtw_pre_link_sta_ctl_reset(stapriv);
  1009. _rtw_spinlock_free(&pre_link_sta_ctl->lock);
  1010. }
  1011. void dump_pre_link_sta_ctl(void *sel, struct sta_priv *stapriv)
  1012. {
  1013. struct pre_link_sta_ctl_t *pre_link_sta_ctl = &stapriv->pre_link_sta_ctl;
  1014. int i;
  1015. RTW_PRINT_SEL(sel, "num:%d/%d\n", pre_link_sta_ctl->num, RTW_PRE_LINK_STA_NUM);
  1016. for (i = 0; i < RTW_PRE_LINK_STA_NUM; i++) {
  1017. if (pre_link_sta_ctl->node[i].valid == _FALSE)
  1018. continue;
  1019. RTW_PRINT_SEL(sel, MAC_FMT"\n", MAC_ARG(pre_link_sta_ctl->node[i].addr));
  1020. }
  1021. }
  1022. #endif /* CONFIG_RTW_PRE_LINK_STA */