offchannel.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Off-channel operation helpers
  3. *
  4. * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
  5. * Copyright 2004, Instant802 Networks, Inc.
  6. * Copyright 2005, Devicescape Software, Inc.
  7. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  8. * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
  9. * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <net/mac80211.h>
  16. #include "ieee80211_i.h"
  17. /*
  18. * inform AP that we will go to sleep so that it will buffer the frames
  19. * while we scan
  20. */
  21. static void ieee80211_offchannel_ps_enable(struct ieee80211_sub_if_data *sdata)
  22. {
  23. struct ieee80211_local *local = sdata->local;
  24. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  25. local->offchannel_ps_enabled = false;
  26. /* FIXME: what to do when local->pspolling is true? */
  27. del_timer_sync(&local->dynamic_ps_timer);
  28. del_timer_sync(&ifmgd->conn_mon_timer);
  29. cancel_work_sync(&local->dynamic_ps_enable_work);
  30. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  31. local->offchannel_ps_enabled = true;
  32. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  33. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  34. }
  35. if (!(local->offchannel_ps_enabled) ||
  36. !(local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK))
  37. /*
  38. * If power save was enabled, no need to send a nullfunc
  39. * frame because AP knows that we are sleeping. But if the
  40. * hardware is creating the nullfunc frame for power save
  41. * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not
  42. * enabled) and power save was enabled, the firmware just
  43. * sent a null frame with power save disabled. So we need
  44. * to send a new nullfunc frame to inform the AP that we
  45. * are again sleeping.
  46. */
  47. ieee80211_send_nullfunc(local, sdata, 1);
  48. }
  49. /* inform AP that we are awake again, unless power save is enabled */
  50. static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata)
  51. {
  52. struct ieee80211_local *local = sdata->local;
  53. if (!local->ps_sdata)
  54. ieee80211_send_nullfunc(local, sdata, 0);
  55. else if (local->offchannel_ps_enabled) {
  56. /*
  57. * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware
  58. * will send a nullfunc frame with the powersave bit set
  59. * even though the AP already knows that we are sleeping.
  60. * This could be avoided by sending a null frame with power
  61. * save bit disabled before enabling the power save, but
  62. * this doesn't gain anything.
  63. *
  64. * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need
  65. * to send a nullfunc frame because AP already knows that
  66. * we are sleeping, let's just enable power save mode in
  67. * hardware.
  68. */
  69. local->hw.conf.flags |= IEEE80211_CONF_PS;
  70. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  71. } else if (local->hw.conf.dynamic_ps_timeout > 0) {
  72. /*
  73. * If IEEE80211_CONF_PS was not set and the dynamic_ps_timer
  74. * had been running before leaving the operating channel,
  75. * restart the timer now and send a nullfunc frame to inform
  76. * the AP that we are awake.
  77. */
  78. ieee80211_send_nullfunc(local, sdata, 0);
  79. mod_timer(&local->dynamic_ps_timer, jiffies +
  80. msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
  81. }
  82. ieee80211_sta_reset_conn_monitor(sdata);
  83. }
  84. void ieee80211_offchannel_stop_beaconing(struct ieee80211_local *local)
  85. {
  86. struct ieee80211_sub_if_data *sdata;
  87. mutex_lock(&local->iflist_mtx);
  88. list_for_each_entry(sdata, &local->interfaces, list) {
  89. if (!ieee80211_sdata_running(sdata))
  90. continue;
  91. /* disable beaconing */
  92. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  93. sdata->vif.type == NL80211_IFTYPE_ADHOC ||
  94. sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  95. ieee80211_bss_info_change_notify(
  96. sdata, BSS_CHANGED_BEACON_ENABLED);
  97. /*
  98. * only handle non-STA interfaces here, STA interfaces
  99. * are handled in ieee80211_offchannel_stop_station(),
  100. * e.g., from the background scan state machine.
  101. *
  102. * In addition, do not stop monitor interface to allow it to be
  103. * used from user space controlled off-channel operations.
  104. */
  105. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  106. sdata->vif.type != NL80211_IFTYPE_MONITOR) {
  107. set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
  108. netif_tx_stop_all_queues(sdata->dev);
  109. }
  110. }
  111. mutex_unlock(&local->iflist_mtx);
  112. }
  113. void ieee80211_offchannel_stop_station(struct ieee80211_local *local)
  114. {
  115. struct ieee80211_sub_if_data *sdata;
  116. /*
  117. * notify the AP about us leaving the channel and stop all STA interfaces
  118. */
  119. mutex_lock(&local->iflist_mtx);
  120. list_for_each_entry(sdata, &local->interfaces, list) {
  121. if (!ieee80211_sdata_running(sdata))
  122. continue;
  123. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  124. set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
  125. netif_tx_stop_all_queues(sdata->dev);
  126. if (sdata->u.mgd.associated)
  127. ieee80211_offchannel_ps_enable(sdata);
  128. }
  129. }
  130. mutex_unlock(&local->iflist_mtx);
  131. }
  132. void ieee80211_offchannel_return(struct ieee80211_local *local,
  133. bool enable_beaconing)
  134. {
  135. struct ieee80211_sub_if_data *sdata;
  136. mutex_lock(&local->iflist_mtx);
  137. list_for_each_entry(sdata, &local->interfaces, list) {
  138. if (!ieee80211_sdata_running(sdata))
  139. continue;
  140. /* Tell AP we're back */
  141. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  142. if (sdata->u.mgd.associated)
  143. ieee80211_offchannel_ps_disable(sdata);
  144. }
  145. if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
  146. clear_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
  147. /*
  148. * This may wake up queues even though the driver
  149. * currently has them stopped. This is not very
  150. * likely, since the driver won't have gotten any
  151. * (or hardly any) new packets while we weren't
  152. * on the right channel, and even if it happens
  153. * it will at most lead to queueing up one more
  154. * packet per queue in mac80211 rather than on
  155. * the interface qdisc.
  156. */
  157. netif_tx_wake_all_queues(sdata->dev);
  158. }
  159. /* re-enable beaconing */
  160. if (enable_beaconing &&
  161. (sdata->vif.type == NL80211_IFTYPE_AP ||
  162. sdata->vif.type == NL80211_IFTYPE_ADHOC ||
  163. sdata->vif.type == NL80211_IFTYPE_MESH_POINT))
  164. ieee80211_bss_info_change_notify(
  165. sdata, BSS_CHANGED_BEACON_ENABLED);
  166. }
  167. mutex_unlock(&local->iflist_mtx);
  168. }