event.c 7.7 KB

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