event.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2008-2009 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include "wlcore.h"
  24. #include "debug.h"
  25. #include "io.h"
  26. #include "event.h"
  27. #include "ps.h"
  28. #include "scan.h"
  29. #include "wl12xx_80211.h"
  30. void wlcore_event_rssi_trigger(struct wl1271 *wl, s8 *metric_arr)
  31. {
  32. struct wl12xx_vif *wlvif;
  33. struct ieee80211_vif *vif;
  34. enum nl80211_cqm_rssi_threshold_event event;
  35. s8 metric = metric_arr[0];
  36. wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
  37. /* TODO: check actual multi-role support */
  38. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  39. if (metric <= wlvif->rssi_thold)
  40. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
  41. else
  42. event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  43. vif = wl12xx_wlvif_to_vif(wlvif);
  44. if (event != wlvif->last_rssi_event)
  45. ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
  46. wlvif->last_rssi_event = event;
  47. }
  48. }
  49. EXPORT_SYMBOL_GPL(wlcore_event_rssi_trigger);
  50. static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  51. {
  52. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  53. if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
  54. u8 hlid = wlvif->sta.hlid;
  55. if (!wl->links[hlid].ba_bitmap)
  56. return;
  57. ieee80211_stop_rx_ba_session(vif, wl->links[hlid].ba_bitmap,
  58. vif->bss_conf.bssid);
  59. } else {
  60. u8 hlid;
  61. struct wl1271_link *lnk;
  62. for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
  63. WL12XX_MAX_LINKS) {
  64. lnk = &wl->links[hlid];
  65. if (!lnk->ba_bitmap)
  66. continue;
  67. ieee80211_stop_rx_ba_session(vif,
  68. lnk->ba_bitmap,
  69. lnk->addr);
  70. }
  71. }
  72. }
  73. void wlcore_event_soft_gemini_sense(struct wl1271 *wl, u8 enable)
  74. {
  75. struct wl12xx_vif *wlvif;
  76. if (enable) {
  77. set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  78. } else {
  79. clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  80. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  81. wl1271_recalc_rx_streaming(wl, wlvif);
  82. }
  83. }
  84. }
  85. EXPORT_SYMBOL_GPL(wlcore_event_soft_gemini_sense);
  86. void wlcore_event_sched_scan_completed(struct wl1271 *wl,
  87. u8 status)
  88. {
  89. wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT (status 0x%0x)",
  90. status);
  91. if (wl->sched_vif) {
  92. ieee80211_sched_scan_stopped(wl->hw);
  93. wl->sched_vif = NULL;
  94. }
  95. }
  96. EXPORT_SYMBOL_GPL(wlcore_event_sched_scan_completed);
  97. void wlcore_event_ba_rx_constraint(struct wl1271 *wl,
  98. unsigned long roles_bitmap,
  99. unsigned long allowed_bitmap)
  100. {
  101. struct wl12xx_vif *wlvif;
  102. wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx allowed=0x%lx",
  103. __func__, roles_bitmap, allowed_bitmap);
  104. wl12xx_for_each_wlvif(wl, wlvif) {
  105. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  106. !test_bit(wlvif->role_id , &roles_bitmap))
  107. continue;
  108. wlvif->ba_allowed = !!test_bit(wlvif->role_id,
  109. &allowed_bitmap);
  110. if (!wlvif->ba_allowed)
  111. wl1271_stop_ba_event(wl, wlvif);
  112. }
  113. }
  114. EXPORT_SYMBOL_GPL(wlcore_event_ba_rx_constraint);
  115. void wlcore_event_channel_switch(struct wl1271 *wl,
  116. unsigned long roles_bitmap,
  117. bool success)
  118. {
  119. struct wl12xx_vif *wlvif;
  120. struct ieee80211_vif *vif;
  121. wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx success=%d",
  122. __func__, roles_bitmap, success);
  123. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  124. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  125. !test_bit(wlvif->role_id , &roles_bitmap))
  126. continue;
  127. if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
  128. &wlvif->flags))
  129. continue;
  130. vif = wl12xx_wlvif_to_vif(wlvif);
  131. ieee80211_chswitch_done(vif, success);
  132. cancel_delayed_work(&wlvif->channel_switch_work);
  133. }
  134. }
  135. EXPORT_SYMBOL_GPL(wlcore_event_channel_switch);
  136. void wlcore_event_dummy_packet(struct wl1271 *wl)
  137. {
  138. wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
  139. wl1271_tx_dummy_packet(wl);
  140. }
  141. EXPORT_SYMBOL_GPL(wlcore_event_dummy_packet);
  142. static void wlcore_disconnect_sta(struct wl1271 *wl, unsigned long sta_bitmap)
  143. {
  144. u32 num_packets = wl->conf.tx.max_tx_retries;
  145. struct wl12xx_vif *wlvif;
  146. struct ieee80211_vif *vif;
  147. struct ieee80211_sta *sta;
  148. const u8 *addr;
  149. int h;
  150. for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
  151. bool found = false;
  152. /* find the ap vif connected to this sta */
  153. wl12xx_for_each_wlvif_ap(wl, wlvif) {
  154. if (!test_bit(h, wlvif->ap.sta_hlid_map))
  155. continue;
  156. found = true;
  157. break;
  158. }
  159. if (!found)
  160. continue;
  161. vif = wl12xx_wlvif_to_vif(wlvif);
  162. addr = wl->links[h].addr;
  163. rcu_read_lock();
  164. sta = ieee80211_find_sta(vif, addr);
  165. if (sta) {
  166. wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
  167. ieee80211_report_low_ack(sta, num_packets);
  168. }
  169. rcu_read_unlock();
  170. }
  171. }
  172. void wlcore_event_max_tx_failure(struct wl1271 *wl, unsigned long sta_bitmap)
  173. {
  174. wl1271_debug(DEBUG_EVENT, "MAX_TX_FAILURE_EVENT_ID");
  175. wlcore_disconnect_sta(wl, sta_bitmap);
  176. }
  177. EXPORT_SYMBOL_GPL(wlcore_event_max_tx_failure);
  178. void wlcore_event_inactive_sta(struct wl1271 *wl, unsigned long sta_bitmap)
  179. {
  180. wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
  181. wlcore_disconnect_sta(wl, sta_bitmap);
  182. }
  183. EXPORT_SYMBOL_GPL(wlcore_event_inactive_sta);
  184. void wlcore_event_roc_complete(struct wl1271 *wl)
  185. {
  186. wl1271_debug(DEBUG_EVENT, "REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID");
  187. if (wl->roc_vif)
  188. ieee80211_ready_on_channel(wl->hw);
  189. }
  190. EXPORT_SYMBOL_GPL(wlcore_event_roc_complete);
  191. void wlcore_event_beacon_loss(struct wl1271 *wl, unsigned long roles_bitmap)
  192. {
  193. /*
  194. * We are HW_MONITOR device. On beacon loss - queue
  195. * connection loss work. Cancel it on REGAINED event.
  196. */
  197. struct wl12xx_vif *wlvif;
  198. struct ieee80211_vif *vif;
  199. int delay = wl->conf.conn.synch_fail_thold *
  200. wl->conf.conn.bss_lose_timeout;
  201. wl1271_info("Beacon loss detected. roles:0x%lx", roles_bitmap);
  202. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  203. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  204. !test_bit(wlvif->role_id , &roles_bitmap))
  205. continue;
  206. /*
  207. * if the work is already queued, it should take place.
  208. * We don't want to delay the connection loss
  209. * indication any more.
  210. */
  211. ieee80211_queue_delayed_work(wl->hw,
  212. &wlvif->connection_loss_work,
  213. msecs_to_jiffies(delay));
  214. vif = wl12xx_wlvif_to_vif(wlvif);
  215. ieee80211_cqm_rssi_notify(
  216. vif,
  217. NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
  218. GFP_KERNEL);
  219. }
  220. }
  221. EXPORT_SYMBOL_GPL(wlcore_event_beacon_loss);
  222. int wl1271_event_unmask(struct wl1271 *wl)
  223. {
  224. int ret;
  225. ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
  226. if (ret < 0)
  227. return ret;
  228. return 0;
  229. }
  230. int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
  231. {
  232. int ret;
  233. wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
  234. if (mbox_num > 1)
  235. return -EINVAL;
  236. /* first we read the mbox descriptor */
  237. ret = wlcore_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
  238. wl->mbox_size, false);
  239. if (ret < 0)
  240. return ret;
  241. /* process the descriptor */
  242. ret = wl->ops->process_mailbox_events(wl);
  243. if (ret < 0)
  244. return ret;
  245. /*
  246. * TODO: we just need this because one bit is in a different
  247. * place. Is there any better way?
  248. */
  249. ret = wl->ops->ack_event(wl);
  250. return ret;
  251. }