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