2 * Off-channel operation helpers
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>
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.
15 #include <linux/export.h>
16 #include <net/mac80211.h>
17 #include "ieee80211_i.h"
18 #include "driver-trace.h"
21 * inform AP that we will go to sleep so that it will buffer the frames
24 static void ieee80211_offchannel_ps_enable(struct ieee80211_sub_if_data
*sdata
)
26 struct ieee80211_local
*local
= sdata
->local
;
27 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
29 local
->offchannel_ps_enabled
= false;
31 /* FIXME: what to do when local->pspolling is true? */
33 del_timer_sync(&local
->dynamic_ps_timer
);
34 del_timer_sync(&ifmgd
->bcn_mon_timer
);
35 del_timer_sync(&ifmgd
->conn_mon_timer
);
37 cancel_work_sync(&local
->dynamic_ps_enable_work
);
39 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
40 local
->offchannel_ps_enabled
= true;
41 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
42 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
45 if (!(local
->offchannel_ps_enabled
) ||
46 !(local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
))
48 * If power save was enabled, no need to send a nullfunc
49 * frame because AP knows that we are sleeping. But if the
50 * hardware is creating the nullfunc frame for power save
51 * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not
52 * enabled) and power save was enabled, the firmware just
53 * sent a null frame with power save disabled. So we need
54 * to send a new nullfunc frame to inform the AP that we
57 ieee80211_send_nullfunc(local
, sdata
, 1);
60 /* inform AP that we are awake again, unless power save is enabled */
61 static void ieee80211_offchannel_ps_disable(struct ieee80211_sub_if_data
*sdata
)
63 struct ieee80211_local
*local
= sdata
->local
;
66 ieee80211_send_nullfunc(local
, sdata
, 0);
67 else if (local
->offchannel_ps_enabled
) {
69 * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware
70 * will send a nullfunc frame with the powersave bit set
71 * even though the AP already knows that we are sleeping.
72 * This could be avoided by sending a null frame with power
73 * save bit disabled before enabling the power save, but
74 * this doesn't gain anything.
76 * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need
77 * to send a nullfunc frame because AP already knows that
78 * we are sleeping, let's just enable power save mode in
81 local
->hw
.conf
.flags
|= IEEE80211_CONF_PS
;
82 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
83 } else if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
85 * If IEEE80211_CONF_PS was not set and the dynamic_ps_timer
86 * had been running before leaving the operating channel,
87 * restart the timer now and send a nullfunc frame to inform
88 * the AP that we are awake.
90 ieee80211_send_nullfunc(local
, sdata
, 0);
91 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
92 msecs_to_jiffies(local
->hw
.conf
.dynamic_ps_timeout
));
95 ieee80211_sta_reset_beacon_monitor(sdata
);
96 ieee80211_sta_reset_conn_monitor(sdata
);
99 void ieee80211_offchannel_stop_beaconing(struct ieee80211_local
*local
)
101 struct ieee80211_sub_if_data
*sdata
;
103 mutex_lock(&local
->iflist_mtx
);
104 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
105 if (!ieee80211_sdata_running(sdata
))
108 /* disable beaconing */
109 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
||
110 sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
||
111 sdata
->vif
.type
== NL80211_IFTYPE_MESH_POINT
)
112 ieee80211_bss_info_change_notify(
113 sdata
, BSS_CHANGED_BEACON_ENABLED
);
116 * only handle non-STA interfaces here, STA interfaces
117 * are handled in ieee80211_offchannel_stop_station(),
118 * e.g., from the background scan state machine.
120 * In addition, do not stop monitor interface to allow it to be
121 * used from user space controlled off-channel operations.
123 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
124 sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
) {
125 set_bit(SDATA_STATE_OFFCHANNEL
, &sdata
->state
);
126 netif_tx_stop_all_queues(sdata
->dev
);
129 mutex_unlock(&local
->iflist_mtx
);
132 void ieee80211_offchannel_stop_station(struct ieee80211_local
*local
)
134 struct ieee80211_sub_if_data
*sdata
;
137 * notify the AP about us leaving the channel and stop all STA interfaces
139 mutex_lock(&local
->iflist_mtx
);
140 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
141 if (!ieee80211_sdata_running(sdata
))
144 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
145 set_bit(SDATA_STATE_OFFCHANNEL
, &sdata
->state
);
146 netif_tx_stop_all_queues(sdata
->dev
);
147 if (sdata
->u
.mgd
.associated
)
148 ieee80211_offchannel_ps_enable(sdata
);
151 mutex_unlock(&local
->iflist_mtx
);
154 void ieee80211_offchannel_return(struct ieee80211_local
*local
,
155 bool enable_beaconing
)
157 struct ieee80211_sub_if_data
*sdata
;
159 mutex_lock(&local
->iflist_mtx
);
160 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
161 if (!ieee80211_sdata_running(sdata
))
164 /* Tell AP we're back */
165 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
166 if (sdata
->u
.mgd
.associated
)
167 ieee80211_offchannel_ps_disable(sdata
);
170 if (sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
) {
171 clear_bit(SDATA_STATE_OFFCHANNEL
, &sdata
->state
);
173 * This may wake up queues even though the driver
174 * currently has them stopped. This is not very
175 * likely, since the driver won't have gotten any
176 * (or hardly any) new packets while we weren't
177 * on the right channel, and even if it happens
178 * it will at most lead to queueing up one more
179 * packet per queue in mac80211 rather than on
180 * the interface qdisc.
182 netif_tx_wake_all_queues(sdata
->dev
);
185 /* re-enable beaconing */
186 if (enable_beaconing
&&
187 (sdata
->vif
.type
== NL80211_IFTYPE_AP
||
188 sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
||
189 sdata
->vif
.type
== NL80211_IFTYPE_MESH_POINT
))
190 ieee80211_bss_info_change_notify(
191 sdata
, BSS_CHANGED_BEACON_ENABLED
);
193 mutex_unlock(&local
->iflist_mtx
);
196 static void ieee80211_hw_roc_start(struct work_struct
*work
)
198 struct ieee80211_local
*local
=
199 container_of(work
, struct ieee80211_local
, hw_roc_start
);
200 struct ieee80211_sub_if_data
*sdata
;
202 mutex_lock(&local
->mtx
);
204 if (!local
->hw_roc_channel
) {
205 mutex_unlock(&local
->mtx
);
209 ieee80211_recalc_idle(local
);
211 if (local
->hw_roc_skb
) {
212 sdata
= IEEE80211_DEV_TO_SUB_IF(local
->hw_roc_dev
);
213 ieee80211_tx_skb(sdata
, local
->hw_roc_skb
);
214 local
->hw_roc_skb
= NULL
;
216 cfg80211_ready_on_channel(local
->hw_roc_dev
,
217 local
->hw_roc_cookie
,
218 local
->hw_roc_channel
,
219 local
->hw_roc_channel_type
,
220 local
->hw_roc_duration
,
224 mutex_unlock(&local
->mtx
);
227 void ieee80211_ready_on_channel(struct ieee80211_hw
*hw
)
229 struct ieee80211_local
*local
= hw_to_local(hw
);
231 trace_api_ready_on_channel(local
);
233 ieee80211_queue_work(hw
, &local
->hw_roc_start
);
235 EXPORT_SYMBOL_GPL(ieee80211_ready_on_channel
);
237 static void ieee80211_hw_roc_done(struct work_struct
*work
)
239 struct ieee80211_local
*local
=
240 container_of(work
, struct ieee80211_local
, hw_roc_done
);
242 mutex_lock(&local
->mtx
);
244 if (!local
->hw_roc_channel
) {
245 mutex_unlock(&local
->mtx
);
249 if (!local
->hw_roc_for_tx
)
250 cfg80211_remain_on_channel_expired(local
->hw_roc_dev
,
251 local
->hw_roc_cookie
,
252 local
->hw_roc_channel
,
253 local
->hw_roc_channel_type
,
256 local
->hw_roc_channel
= NULL
;
257 local
->hw_roc_cookie
= 0;
259 ieee80211_recalc_idle(local
);
261 mutex_unlock(&local
->mtx
);
264 void ieee80211_remain_on_channel_expired(struct ieee80211_hw
*hw
)
266 struct ieee80211_local
*local
= hw_to_local(hw
);
268 trace_api_remain_on_channel_expired(local
);
270 ieee80211_queue_work(hw
, &local
->hw_roc_done
);
272 EXPORT_SYMBOL_GPL(ieee80211_remain_on_channel_expired
);
274 void ieee80211_hw_roc_setup(struct ieee80211_local
*local
)
276 INIT_WORK(&local
->hw_roc_start
, ieee80211_hw_roc_start
);
277 INIT_WORK(&local
->hw_roc_done
, ieee80211_hw_roc_done
);