event.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. if (!wlvif->sta.ba_rx_bitmap)
  55. return;
  56. ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
  57. vif->bss_conf.bssid);
  58. } else {
  59. u8 hlid;
  60. struct wl1271_link *lnk;
  61. for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
  62. WL12XX_MAX_LINKS) {
  63. lnk = &wl->links[hlid];
  64. if (!lnk->ba_bitmap)
  65. continue;
  66. ieee80211_stop_rx_ba_session(vif,
  67. lnk->ba_bitmap,
  68. lnk->addr);
  69. }
  70. }
  71. }
  72. void wlcore_event_soft_gemini_sense(struct wl1271 *wl, u8 enable)
  73. {
  74. struct wl12xx_vif *wlvif;
  75. if (enable) {
  76. set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  77. } else {
  78. clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
  79. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  80. wl1271_recalc_rx_streaming(wl, wlvif);
  81. }
  82. }
  83. }
  84. EXPORT_SYMBOL_GPL(wlcore_event_soft_gemini_sense);
  85. void wlcore_event_sched_scan_report(struct wl1271 *wl,
  86. u8 status)
  87. {
  88. wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT (status 0x%0x)",
  89. status);
  90. wl1271_scan_sched_scan_results(wl);
  91. }
  92. EXPORT_SYMBOL_GPL(wlcore_event_sched_scan_report);
  93. void wlcore_event_sched_scan_completed(struct wl1271 *wl,
  94. u8 status)
  95. {
  96. wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT (status 0x%0x)",
  97. status);
  98. if (wl->sched_vif) {
  99. ieee80211_sched_scan_stopped(wl->hw);
  100. wl->sched_vif = NULL;
  101. }
  102. }
  103. EXPORT_SYMBOL_GPL(wlcore_event_sched_scan_completed);
  104. void wlcore_event_ba_rx_constraint(struct wl1271 *wl,
  105. unsigned long roles_bitmap,
  106. unsigned long allowed_bitmap)
  107. {
  108. struct wl12xx_vif *wlvif;
  109. wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx allowed=0x%lx",
  110. __func__, roles_bitmap, allowed_bitmap);
  111. wl12xx_for_each_wlvif(wl, wlvif) {
  112. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  113. !test_bit(wlvif->role_id , &roles_bitmap))
  114. continue;
  115. wlvif->ba_allowed = !!test_bit(wlvif->role_id,
  116. &allowed_bitmap);
  117. if (!wlvif->ba_allowed)
  118. wl1271_stop_ba_event(wl, wlvif);
  119. }
  120. }
  121. EXPORT_SYMBOL_GPL(wlcore_event_ba_rx_constraint);
  122. void wlcore_event_channel_switch(struct wl1271 *wl,
  123. unsigned long roles_bitmap,
  124. bool success)
  125. {
  126. struct wl12xx_vif *wlvif;
  127. struct ieee80211_vif *vif;
  128. wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx success=%d",
  129. __func__, roles_bitmap, success);
  130. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  131. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  132. !test_bit(wlvif->role_id , &roles_bitmap))
  133. continue;
  134. if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
  135. &wlvif->flags))
  136. continue;
  137. vif = wl12xx_wlvif_to_vif(wlvif);
  138. ieee80211_chswitch_done(vif, success);
  139. cancel_delayed_work(&wlvif->channel_switch_work);
  140. }
  141. }
  142. EXPORT_SYMBOL_GPL(wlcore_event_channel_switch);
  143. void wlcore_event_dummy_packet(struct wl1271 *wl)
  144. {
  145. wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
  146. wl1271_tx_dummy_packet(wl);
  147. }
  148. EXPORT_SYMBOL_GPL(wlcore_event_dummy_packet);
  149. static void wlcore_disconnect_sta(struct wl1271 *wl, unsigned long sta_bitmap)
  150. {
  151. u32 num_packets = wl->conf.tx.max_tx_retries;
  152. struct wl12xx_vif *wlvif;
  153. struct ieee80211_vif *vif;
  154. struct ieee80211_sta *sta;
  155. const u8 *addr;
  156. int h;
  157. for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
  158. bool found = false;
  159. /* find the ap vif connected to this sta */
  160. wl12xx_for_each_wlvif_ap(wl, wlvif) {
  161. if (!test_bit(h, wlvif->ap.sta_hlid_map))
  162. continue;
  163. found = true;
  164. break;
  165. }
  166. if (!found)
  167. continue;
  168. vif = wl12xx_wlvif_to_vif(wlvif);
  169. addr = wl->links[h].addr;
  170. rcu_read_lock();
  171. sta = ieee80211_find_sta(vif, addr);
  172. if (sta) {
  173. wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
  174. ieee80211_report_low_ack(sta, num_packets);
  175. }
  176. rcu_read_unlock();
  177. }
  178. }
  179. void wlcore_event_max_tx_failure(struct wl1271 *wl, unsigned long sta_bitmap)
  180. {
  181. wl1271_debug(DEBUG_EVENT, "MAX_TX_FAILURE_EVENT_ID");
  182. wlcore_disconnect_sta(wl, sta_bitmap);
  183. }
  184. EXPORT_SYMBOL_GPL(wlcore_event_max_tx_failure);
  185. void wlcore_event_inactive_sta(struct wl1271 *wl, unsigned long sta_bitmap)
  186. {
  187. wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
  188. wlcore_disconnect_sta(wl, sta_bitmap);
  189. }
  190. EXPORT_SYMBOL_GPL(wlcore_event_inactive_sta);
  191. void wlcore_event_roc_complete(struct wl1271 *wl)
  192. {
  193. wl1271_debug(DEBUG_EVENT, "REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID");
  194. if (wl->roc_vif)
  195. ieee80211_ready_on_channel(wl->hw);
  196. }
  197. EXPORT_SYMBOL_GPL(wlcore_event_roc_complete);
  198. void wlcore_event_beacon_loss(struct wl1271 *wl, unsigned long roles_bitmap)
  199. {
  200. /*
  201. * We are HW_MONITOR device. On beacon loss - queue
  202. * connection loss work. Cancel it on REGAINED event.
  203. */
  204. struct wl12xx_vif *wlvif;
  205. struct ieee80211_vif *vif;
  206. int delay = wl->conf.conn.synch_fail_thold *
  207. wl->conf.conn.bss_lose_timeout;
  208. wl1271_info("Beacon loss detected. roles:0x%lx", roles_bitmap);
  209. wl12xx_for_each_wlvif_sta(wl, wlvif) {
  210. if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
  211. !test_bit(wlvif->role_id , &roles_bitmap))
  212. continue;
  213. /*
  214. * if the work is already queued, it should take place.
  215. * We don't want to delay the connection loss
  216. * indication any more.
  217. */
  218. ieee80211_queue_delayed_work(wl->hw,
  219. &wlvif->connection_loss_work,
  220. msecs_to_jiffies(delay));
  221. vif = wl12xx_wlvif_to_vif(wlvif);
  222. ieee80211_cqm_rssi_notify(
  223. vif,
  224. NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
  225. GFP_KERNEL);
  226. }
  227. }
  228. EXPORT_SYMBOL_GPL(wlcore_event_beacon_loss);
  229. int wl1271_event_unmask(struct wl1271 *wl)
  230. {
  231. int ret;
  232. ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
  233. if (ret < 0)
  234. return ret;
  235. return 0;
  236. }
  237. int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
  238. {
  239. int ret;
  240. wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
  241. if (mbox_num > 1)
  242. return -EINVAL;
  243. /* first we read the mbox descriptor */
  244. ret = wlcore_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
  245. wl->mbox_size, false);
  246. if (ret < 0)
  247. return ret;
  248. /* process the descriptor */
  249. ret = wl->ops->process_mailbox_events(wl);
  250. if (ret < 0)
  251. return ret;
  252. /*
  253. * TODO: we just need this because one bit is in a different
  254. * place. Is there any better way?
  255. */
  256. ret = wl->ops->ack_event(wl);
  257. return ret;
  258. }