offchannel.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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->bcn_mon_timer);
  29. del_timer_sync(&ifmgd->conn_mon_timer);
  30. cancel_work_sync(&local->dynamic_ps_enable_work);
  31. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  32. local->offchannel_ps_enabled = true;
  33. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  34. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  35. }
  36. if (!(local->offchannel_ps_enabled) ||
  37. !(local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK))
  38. /*
  39. * If power save was enabled, no need to send a nullfunc
  40. * frame because AP knows that we are sleeping. But if the
  41. * hardware is creating the nullfunc frame for power save
  42. * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not
  43. * enabled) and power save was enabled, the firmware just
  44. * sent a null frame with power save disabled. So we need
  45. * to send a new nullfunc frame to inform the AP that we
  46. * are again sleeping.
  47. */
  48. ieee80211_send_nullfunc(local, sdata, 1);
  49. }
  50. /* inform AP that we are awake again, unless power save is enabled */
  51. static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data *sdata)
  52. {
  53. struct ieee80211_local *local = sdata->local;
  54. if (!local->ps_sdata)
  55. ieee80211_send_nullfunc(local, sdata, 0);
  56. else if (local->offchannel_ps_enabled) {
  57. /*
  58. * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware
  59. * will send a nullfunc frame with the powersave bit set
  60. * even though the AP already knows that we are sleeping.
  61. * This could be avoided by sending a null frame with power
  62. * save bit disabled before enabling the power save, but
  63. * this doesn't gain anything.
  64. *
  65. * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need
  66. * to send a nullfunc frame because AP already knows that
  67. * we are sleeping, let's just enable power save mode in
  68. * hardware.
  69. */
  70. local->hw.conf.flags |= IEEE80211_CONF_PS;
  71. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  72. } else if (local->hw.conf.dynamic_ps_timeout > 0) {
  73. /*
  74. * If IEEE80211_CONF_PS was not set and the dynamic_ps_timer
  75. * had been running before leaving the operating channel,
  76. * restart the timer now and send a nullfunc frame to inform
  77. * the AP that we are awake.
  78. */
  79. ieee80211_send_nullfunc(local, sdata, 0);
  80. mod_timer(&local->dynamic_ps_timer, jiffies +
  81. msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
  82. }
  83. ieee80211_sta_reset_beacon_monitor(sdata);
  84. ieee80211_sta_reset_conn_monitor(sdata);
  85. }
  86. void ieee80211_offchannel_stop_beaconing(struct ieee80211_local *local)
  87. {
  88. struct ieee80211_sub_if_data *sdata;
  89. mutex_lock(&local->iflist_mtx);
  90. list_for_each_entry(sdata, &local->interfaces, list) {
  91. if (!ieee80211_sdata_running(sdata))
  92. continue;
  93. /* disable beaconing */
  94. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  95. sdata->vif.type == NL80211_IFTYPE_ADHOC ||
  96. sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  97. ieee80211_bss_info_change_notify(
  98. sdata, BSS_CHANGED_BEACON_ENABLED);
  99. /*
  100. * only handle non-STA interfaces here, STA interfaces
  101. * are handled in ieee80211_offchannel_stop_station(),
  102. * e.g., from the background scan state machine.
  103. *
  104. * In addition, do not stop monitor interface to allow it to be
  105. * used from user space controlled off-channel operations.
  106. */
  107. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  108. sdata->vif.type != NL80211_IFTYPE_MONITOR) {
  109. set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
  110. netif_tx_stop_all_queues(sdata->dev);
  111. }
  112. }
  113. mutex_unlock(&local->iflist_mtx);
  114. }
  115. void ieee80211_offchannel_stop_station(struct ieee80211_local *local)
  116. {
  117. struct ieee80211_sub_if_data *sdata;
  118. /*
  119. * notify the AP about us leaving the channel and stop all STA interfaces
  120. */
  121. mutex_lock(&local->iflist_mtx);
  122. list_for_each_entry(sdata, &local->interfaces, list) {
  123. if (!ieee80211_sdata_running(sdata))
  124. continue;
  125. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  126. set_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
  127. netif_tx_stop_all_queues(sdata->dev);
  128. if (sdata->u.mgd.associated)
  129. ieee80211_offchannel_ps_enable(sdata);
  130. }
  131. }
  132. mutex_unlock(&local->iflist_mtx);
  133. }
  134. void ieee80211_offchannel_return(struct ieee80211_local *local,
  135. bool enable_beaconing)
  136. {
  137. struct ieee80211_sub_if_data *sdata;
  138. mutex_lock(&local->iflist_mtx);
  139. list_for_each_entry(sdata, &local->interfaces, list) {
  140. if (!ieee80211_sdata_running(sdata))
  141. continue;
  142. /* Tell AP we're back */
  143. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  144. if (sdata->u.mgd.associated)
  145. ieee80211_offchannel_ps_disable(sdata);
  146. }
  147. if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
  148. clear_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
  149. /*
  150. * This may wake up queues even though the driver
  151. * currently has them stopped. This is not very
  152. * likely, since the driver won't have gotten any
  153. * (or hardly any) new packets while we weren't
  154. * on the right channel, and even if it happens
  155. * it will at most lead to queueing up one more
  156. * packet per queue in mac80211 rather than on
  157. * the interface qdisc.
  158. */
  159. netif_tx_wake_all_queues(sdata->dev);
  160. }
  161. /* re-enable beaconing */
  162. if (enable_beaconing &&
  163. (sdata->vif.type == NL80211_IFTYPE_AP ||
  164. sdata->vif.type == NL80211_IFTYPE_ADHOC ||
  165. sdata->vif.type == NL80211_IFTYPE_MESH_POINT))
  166. ieee80211_bss_info_change_notify(
  167. sdata, BSS_CHANGED_BEACON_ENABLED);
  168. }
  169. mutex_unlock(&local->iflist_mtx);
  170. }