event.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 int wlcore_smart_config_sync_event(struct wl1271 *wl, u8 sync_channel,
  45. u8 sync_band)
  46. {
  47. struct sk_buff *skb;
  48. enum ieee80211_band band;
  49. int freq;
  50. if (sync_band == WLCORE_BAND_5GHZ)
  51. band = IEEE80211_BAND_5GHZ;
  52. else
  53. band = IEEE80211_BAND_2GHZ;
  54. freq = ieee80211_channel_to_frequency(sync_channel, band);
  55. wl1271_debug(DEBUG_EVENT,
  56. "SMART_CONFIG_SYNC_EVENT_ID, freq: %d (chan: %d band %d)",
  57. freq, sync_channel, sync_band);
  58. skb = cfg80211_vendor_event_alloc(wl->hw->wiphy, 20,
  59. WLCORE_VENDOR_EVENT_SC_SYNC,
  60. GFP_KERNEL);
  61. if (nla_put_u32(skb, WLCORE_VENDOR_ATTR_FREQ, freq)) {
  62. kfree_skb(skb);
  63. return -EMSGSIZE;
  64. }
  65. cfg80211_vendor_event(skb, GFP_KERNEL);
  66. return 0;
  67. }
  68. static int wlcore_smart_config_decode_event(struct wl1271 *wl,
  69. u8 ssid_len, u8 *ssid,
  70. u8 pwd_len, u8 *pwd)
  71. {
  72. struct sk_buff *skb;
  73. wl1271_debug(DEBUG_EVENT, "SMART_CONFIG_DECODE_EVENT_ID");
  74. wl1271_dump_ascii(DEBUG_EVENT, "SSID:", ssid, ssid_len);
  75. skb = cfg80211_vendor_event_alloc(wl->hw->wiphy,
  76. ssid_len + pwd_len + 20,
  77. WLCORE_VENDOR_EVENT_SC_DECODE,
  78. GFP_KERNEL);
  79. if (nla_put(skb, WLCORE_VENDOR_ATTR_SSID, ssid_len, ssid) ||
  80. nla_put(skb, WLCORE_VENDOR_ATTR_PSK, pwd_len, pwd)) {
  81. kfree_skb(skb);
  82. return -EMSGSIZE;
  83. }
  84. cfg80211_vendor_event(skb, GFP_KERNEL);
  85. return 0;
  86. }
  87. int wl18xx_process_mailbox_events(struct wl1271 *wl)
  88. {
  89. struct wl18xx_event_mailbox *mbox = wl->mbox;
  90. u32 vector;
  91. vector = le32_to_cpu(mbox->events_vector);
  92. wl1271_debug(DEBUG_EVENT, "MBOX vector: 0x%x", vector);
  93. if (vector & SCAN_COMPLETE_EVENT_ID) {
  94. wl1271_debug(DEBUG_EVENT, "scan results: %d",
  95. mbox->number_of_scan_results);
  96. if (wl->scan_wlvif)
  97. wl18xx_scan_completed(wl, wl->scan_wlvif);
  98. }
  99. if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
  100. wl1271_debug(DEBUG_EVENT,
  101. "PERIODIC_SCAN_REPORT_EVENT (results %d)",
  102. mbox->number_of_sched_scan_results);
  103. wlcore_scan_sched_scan_results(wl);
  104. }
  105. if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID)
  106. wlcore_event_sched_scan_completed(wl, 1);
  107. if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID)
  108. wlcore_event_rssi_trigger(wl, mbox->rssi_snr_trigger_metric);
  109. if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID)
  110. wlcore_event_ba_rx_constraint(wl,
  111. le16_to_cpu(mbox->rx_ba_role_id_bitmap),
  112. le16_to_cpu(mbox->rx_ba_allowed_bitmap));
  113. if (vector & BSS_LOSS_EVENT_ID)
  114. wlcore_event_beacon_loss(wl,
  115. le16_to_cpu(mbox->bss_loss_bitmap));
  116. if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID)
  117. wlcore_event_channel_switch(wl,
  118. le16_to_cpu(mbox->channel_switch_role_id_bitmap),
  119. true);
  120. if (vector & DUMMY_PACKET_EVENT_ID)
  121. wlcore_event_dummy_packet(wl);
  122. /*
  123. * "TX retries exceeded" has a different meaning according to mode.
  124. * In AP mode the offending station is disconnected.
  125. */
  126. if (vector & MAX_TX_FAILURE_EVENT_ID)
  127. wlcore_event_max_tx_failure(wl,
  128. le32_to_cpu(mbox->tx_retry_exceeded_bitmap));
  129. if (vector & INACTIVE_STA_EVENT_ID)
  130. wlcore_event_inactive_sta(wl,
  131. le32_to_cpu(mbox->inactive_sta_bitmap));
  132. if (vector & REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID)
  133. wlcore_event_roc_complete(wl);
  134. if (vector & SMART_CONFIG_SYNC_EVENT_ID)
  135. wlcore_smart_config_sync_event(wl, mbox->sc_sync_channel,
  136. mbox->sc_sync_band);
  137. if (vector & SMART_CONFIG_DECODE_EVENT_ID)
  138. wlcore_smart_config_decode_event(wl,
  139. mbox->sc_ssid_len,
  140. mbox->sc_ssid,
  141. mbox->sc_pwd_len,
  142. mbox->sc_pwd);
  143. return 0;
  144. }