event.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * This file is part of wl12xx
  3. *
  4. * Copyright (C) 2012 Texas Instruments. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <net/genetlink.h>
  22. #include "event.h"
  23. #include "scan.h"
  24. #include "../wlcore/cmd.h"
  25. #include "../wlcore/debug.h"
  26. #include "../wlcore/vendor_cmd.h"
  27. int wl18xx_wait_for_event(struct wl1271 *wl, enum wlcore_wait_event event,
  28. bool *timeout)
  29. {
  30. u32 local_event;
  31. switch (event) {
  32. case WLCORE_EVENT_PEER_REMOVE_COMPLETE:
  33. local_event = PEER_REMOVE_COMPLETE_EVENT_ID;
  34. break;
  35. case WLCORE_EVENT_DFS_CONFIG_COMPLETE:
  36. local_event = DFS_CHANNELS_CONFIG_COMPLETE_EVENT;
  37. break;
  38. default:
  39. /* event not implemented */
  40. return 0;
  41. }
  42. return wlcore_cmd_wait_for_event_or_timeout(wl, local_event, timeout);
  43. }
  44. static const char *wl18xx_radar_type_decode(u8 radar_type)
  45. {
  46. switch (radar_type) {
  47. case RADAR_TYPE_REGULAR:
  48. return "REGULAR";
  49. case RADAR_TYPE_CHIRP:
  50. return "CHIRP";
  51. case RADAR_TYPE_NONE:
  52. default:
  53. return "N/A";
  54. }
  55. }
  56. static int wlcore_smart_config_sync_event(struct wl1271 *wl, u8 sync_channel,
  57. u8 sync_band)
  58. {
  59. struct sk_buff *skb;
  60. enum ieee80211_band band;
  61. int freq;
  62. if (sync_band == WLCORE_BAND_5GHZ)
  63. band = IEEE80211_BAND_5GHZ;
  64. else
  65. band = IEEE80211_BAND_2GHZ;
  66. freq = ieee80211_channel_to_frequency(sync_channel, band);
  67. wl1271_debug(DEBUG_EVENT,
  68. "SMART_CONFIG_SYNC_EVENT_ID, freq: %d (chan: %d band %d)",
  69. freq, sync_channel, sync_band);
  70. skb = cfg80211_vendor_event_alloc(wl->hw->wiphy, NULL, 20,
  71. WLCORE_VENDOR_EVENT_SC_SYNC,
  72. GFP_KERNEL);
  73. if (nla_put_u32(skb, WLCORE_VENDOR_ATTR_FREQ, freq)) {
  74. kfree_skb(skb);
  75. return -EMSGSIZE;
  76. }
  77. cfg80211_vendor_event(skb, GFP_KERNEL);
  78. return 0;
  79. }
  80. static int wlcore_smart_config_decode_event(struct wl1271 *wl,
  81. u8 ssid_len, u8 *ssid,
  82. u8 pwd_len, u8 *pwd)
  83. {
  84. struct sk_buff *skb;
  85. wl1271_debug(DEBUG_EVENT, "SMART_CONFIG_DECODE_EVENT_ID");
  86. wl1271_dump_ascii(DEBUG_EVENT, "SSID:", ssid, ssid_len);
  87. skb = cfg80211_vendor_event_alloc(wl->hw->wiphy, NULL,
  88. ssid_len + pwd_len + 20,
  89. WLCORE_VENDOR_EVENT_SC_DECODE,
  90. GFP_KERNEL);
  91. if (nla_put(skb, WLCORE_VENDOR_ATTR_SSID, ssid_len, ssid) ||
  92. nla_put(skb, WLCORE_VENDOR_ATTR_PSK, pwd_len, pwd)) {
  93. kfree_skb(skb);
  94. return -EMSGSIZE;
  95. }
  96. cfg80211_vendor_event(skb, GFP_KERNEL);
  97. return 0;
  98. }
  99. static void wlcore_event_time_sync(struct wl1271 *wl, u16 tsf_msb, u16 tsf_lsb)
  100. {
  101. u32 clock;
  102. /* convert the MSB+LSB to a u32 TSF value */
  103. clock = (tsf_msb << 16) | tsf_lsb;
  104. wl1271_info("TIME_SYNC_EVENT_ID: clock %u", clock);
  105. }
  106. int wl18xx_process_mailbox_events(struct wl1271 *wl)
  107. {
  108. struct wl18xx_event_mailbox *mbox = wl->mbox;
  109. u32 vector;
  110. vector = le32_to_cpu(mbox->events_vector);
  111. wl1271_debug(DEBUG_EVENT, "MBOX vector: 0x%x", vector);
  112. if (vector & SCAN_COMPLETE_EVENT_ID) {
  113. wl1271_debug(DEBUG_EVENT, "scan results: %d",
  114. mbox->number_of_scan_results);
  115. if (wl->scan_wlvif)
  116. wl18xx_scan_completed(wl, wl->scan_wlvif);
  117. }
  118. if (vector & TIME_SYNC_EVENT_ID)
  119. wlcore_event_time_sync(wl,
  120. mbox->time_sync_tsf_msb,
  121. mbox->time_sync_tsf_lsb);
  122. if (vector & RADAR_DETECTED_EVENT_ID) {
  123. wl1271_info("radar event: channel %d type %s",
  124. mbox->radar_channel,
  125. wl18xx_radar_type_decode(mbox->radar_type));
  126. ieee80211_radar_detected(wl->hw);
  127. }
  128. if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
  129. wl1271_debug(DEBUG_EVENT,
  130. "PERIODIC_SCAN_REPORT_EVENT (results %d)",
  131. mbox->number_of_sched_scan_results);
  132. wlcore_scan_sched_scan_results(wl);
  133. }
  134. if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID)
  135. wlcore_event_sched_scan_completed(wl, 1);
  136. if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID)
  137. wlcore_event_rssi_trigger(wl, mbox->rssi_snr_trigger_metric);
  138. if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID)
  139. wlcore_event_ba_rx_constraint(wl,
  140. le16_to_cpu(mbox->rx_ba_role_id_bitmap),
  141. le16_to_cpu(mbox->rx_ba_allowed_bitmap));
  142. if (vector & BSS_LOSS_EVENT_ID)
  143. wlcore_event_beacon_loss(wl,
  144. le16_to_cpu(mbox->bss_loss_bitmap));
  145. if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID)
  146. wlcore_event_channel_switch(wl,
  147. le16_to_cpu(mbox->channel_switch_role_id_bitmap),
  148. true);
  149. if (vector & DUMMY_PACKET_EVENT_ID)
  150. wlcore_event_dummy_packet(wl);
  151. /*
  152. * "TX retries exceeded" has a different meaning according to mode.
  153. * In AP mode the offending station is disconnected.
  154. */
  155. if (vector & MAX_TX_FAILURE_EVENT_ID)
  156. wlcore_event_max_tx_failure(wl,
  157. le32_to_cpu(mbox->tx_retry_exceeded_bitmap));
  158. if (vector & INACTIVE_STA_EVENT_ID)
  159. wlcore_event_inactive_sta(wl,
  160. le32_to_cpu(mbox->inactive_sta_bitmap));
  161. if (vector & REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID)
  162. wlcore_event_roc_complete(wl);
  163. if (vector & SMART_CONFIG_SYNC_EVENT_ID)
  164. wlcore_smart_config_sync_event(wl, mbox->sc_sync_channel,
  165. mbox->sc_sync_band);
  166. if (vector & SMART_CONFIG_DECODE_EVENT_ID)
  167. wlcore_smart_config_decode_event(wl,
  168. mbox->sc_ssid_len,
  169. mbox->sc_ssid,
  170. mbox->sc_pwd_len,
  171. mbox->sc_pwd);
  172. if (vector & RX_BA_WIN_SIZE_CHANGE_EVENT_ID) {
  173. struct wl12xx_vif *wlvif;
  174. struct ieee80211_vif *vif;
  175. struct ieee80211_sta *sta;
  176. u8 link_id = mbox->rx_ba_link_id;
  177. u8 win_size = mbox->rx_ba_win_size;
  178. const u8 *addr;
  179. wlvif = wl->links[link_id].wlvif;
  180. vif = wl12xx_wlvif_to_vif(wlvif);
  181. /* Update RX aggregation window size and call
  182. * MAC routine to stop active RX aggregations for this link
  183. */
  184. if (wlvif->bss_type != BSS_TYPE_AP_BSS)
  185. addr = vif->bss_conf.bssid;
  186. else
  187. addr = wl->links[link_id].addr;
  188. sta = ieee80211_find_sta(vif, addr);
  189. if (sta) {
  190. sta->max_rx_aggregation_subframes = win_size;
  191. ieee80211_stop_rx_ba_session(vif,
  192. wl->links[link_id].ba_bitmap,
  193. addr);
  194. }
  195. }
  196. return 0;
  197. }