offchannel.c 5.5 KB

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