2 * wpa_supplicant - Off-channel Action frame TX/RX
3 * Copyright (c) 2009-2010, Atheros Communications
4 * Copyright (c) 2011, Qualcomm Atheros
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
13 #include "utils/eloop.h"
14 #include "wpa_supplicant_i.h"
16 #include "offchannel.h"
20 static struct wpa_supplicant
*
21 wpas_get_tx_interface(struct wpa_supplicant
*wpa_s
, const u8
*src
)
23 struct wpa_supplicant
*iface
;
25 if (os_memcmp(src
, wpa_s
->own_addr
, ETH_ALEN
) == 0)
29 * Try to find a group interface that matches with the source address.
31 iface
= wpa_s
->global
->ifaces
;
33 if (os_memcmp(wpa_s
->pending_action_src
,
34 iface
->own_addr
, ETH_ALEN
) == 0)
39 wpa_printf(MSG_DEBUG
, "P2P: Use group interface %s "
40 "instead of interface %s for Action TX",
41 iface
->ifname
, wpa_s
->ifname
);
49 static void wpas_send_action_cb(void *eloop_ctx
, void *timeout_ctx
)
51 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
52 struct wpa_supplicant
*iface
;
56 without_roc
= wpa_s
->pending_action_without_roc
;
57 wpa_s
->pending_action_without_roc
= 0;
59 "Off-channel: Send Action callback (without_roc=%d pending_action_tx=%p pending_action_tx_done=%d)",
60 without_roc
, wpa_s
->pending_action_tx
,
61 !!wpa_s
->pending_action_tx_done
);
63 if (wpa_s
->pending_action_tx
== NULL
|| wpa_s
->pending_action_tx_done
)
67 * This call is likely going to be on the P2P device instance if the
68 * driver uses a separate interface for that purpose. However, some
69 * Action frames are actually sent within a P2P Group and when that is
70 * the case, we need to follow power saving (e.g., GO buffering the
71 * frame for a client in PS mode or a client following the advertised
72 * NoA from its GO). To make that easier for the driver, select the
73 * correct group interface here.
75 iface
= wpas_get_tx_interface(wpa_s
, wpa_s
->pending_action_src
);
77 if (wpa_s
->off_channel_freq
!= wpa_s
->pending_action_freq
&&
78 wpa_s
->pending_action_freq
!= 0 &&
79 wpa_s
->pending_action_freq
!= iface
->assoc_freq
) {
80 wpa_printf(MSG_DEBUG
, "Off-channel: Pending Action frame TX "
81 "waiting for another freq=%u (off_channel_freq=%u "
83 wpa_s
->pending_action_freq
,
84 wpa_s
->off_channel_freq
,
86 if (without_roc
&& wpa_s
->off_channel_freq
== 0) {
87 unsigned int duration
= 200;
89 * We may get here if wpas_send_action() found us to be
90 * on the correct channel, but remain-on-channel cancel
91 * event was received before getting here.
93 wpa_printf(MSG_DEBUG
, "Off-channel: Schedule "
94 "remain-on-channel to send Action frame");
95 #ifdef CONFIG_TESTING_OPTIONS
96 if (wpa_s
->extra_roc_dur
) {
98 "TESTING: Increase ROC duration %u -> %u",
100 duration
+ wpa_s
->extra_roc_dur
);
101 duration
+= wpa_s
->extra_roc_dur
;
103 #endif /* CONFIG_TESTING_OPTIONS */
104 if (wpa_drv_remain_on_channel(
105 wpa_s
, wpa_s
->pending_action_freq
,
107 wpa_printf(MSG_DEBUG
, "Off-channel: Failed to "
108 "request driver to remain on "
109 "channel (%u MHz) for Action Frame "
110 "TX", wpa_s
->pending_action_freq
);
112 wpa_s
->off_channel_freq
= 0;
113 wpa_s
->roc_waiting_drv_freq
=
114 wpa_s
->pending_action_freq
;
120 wpa_printf(MSG_DEBUG
, "Off-channel: Sending pending Action frame to "
121 MACSTR
" using interface %s",
122 MAC2STR(wpa_s
->pending_action_dst
), iface
->ifname
);
123 res
= wpa_drv_send_action(iface
, wpa_s
->pending_action_freq
, 0,
124 wpa_s
->pending_action_dst
,
125 wpa_s
->pending_action_src
,
126 wpa_s
->pending_action_bssid
,
127 wpabuf_head(wpa_s
->pending_action_tx
),
128 wpabuf_len(wpa_s
->pending_action_tx
),
129 wpa_s
->pending_action_no_cck
);
131 wpa_printf(MSG_DEBUG
, "Off-channel: Failed to send the "
132 "pending Action frame");
134 * Use fake TX status event to allow state machines to
137 offchannel_send_action_tx_status(
138 wpa_s
, wpa_s
->pending_action_dst
,
139 wpabuf_head(wpa_s
->pending_action_tx
),
140 wpabuf_len(wpa_s
->pending_action_tx
),
141 OFFCHANNEL_SEND_ACTION_FAILED
);
147 * offchannel_send_action_tx_status - TX status callback
148 * @wpa_s: Pointer to wpa_supplicant data
149 * @dst: Destination MAC address of the transmitted Action frame
150 * @data: Transmitted frame payload
151 * @data_len: Length of @data in bytes
154 * This function is called whenever the driver indicates a TX status event for
155 * a frame sent by offchannel_send_action() using wpa_drv_send_action().
157 void offchannel_send_action_tx_status(
158 struct wpa_supplicant
*wpa_s
, const u8
*dst
, const u8
*data
,
159 size_t data_len
, enum offchannel_send_action_result result
)
161 if (wpa_s
->pending_action_tx
== NULL
) {
162 wpa_printf(MSG_DEBUG
, "Off-channel: Ignore Action TX status - "
163 "no pending operation");
167 if (os_memcmp(dst
, wpa_s
->pending_action_dst
, ETH_ALEN
) != 0) {
168 wpa_printf(MSG_DEBUG
, "Off-channel: Ignore Action TX status - "
169 "unknown destination address");
173 /* Accept report only if the contents of the frame matches */
174 if (data_len
- wpabuf_len(wpa_s
->pending_action_tx
) != 24 ||
175 os_memcmp(data
+ 24, wpabuf_head(wpa_s
->pending_action_tx
),
176 wpabuf_len(wpa_s
->pending_action_tx
)) != 0) {
177 wpa_printf(MSG_DEBUG
, "Off-channel: Ignore Action TX status - "
178 "mismatching contents with pending frame");
179 wpa_hexdump(MSG_MSGDUMP
, "TX status frame data",
181 wpa_hexdump_buf(MSG_MSGDUMP
, "Pending TX frame",
182 wpa_s
->pending_action_tx
);
186 wpa_printf(MSG_DEBUG
, "Off-channel: Delete matching pending action frame");
188 wpabuf_free(wpa_s
->pending_action_tx
);
189 wpa_s
->pending_action_tx
= NULL
;
191 wpa_printf(MSG_DEBUG
, "Off-channel: TX status result=%d cb=%p",
192 result
, wpa_s
->pending_action_tx_status_cb
);
194 if (wpa_s
->pending_action_tx_status_cb
) {
195 wpa_s
->pending_action_tx_status_cb(
196 wpa_s
, wpa_s
->pending_action_freq
,
197 wpa_s
->pending_action_dst
, wpa_s
->pending_action_src
,
198 wpa_s
->pending_action_bssid
,
199 data
, data_len
, result
);
205 * offchannel_send_action - Request off-channel Action frame TX
206 * @wpa_s: Pointer to wpa_supplicant data
207 * @freq: The frequency in MHz indicating the channel on which the frame is to
208 * transmitted or 0 for the current channel (only if associated)
209 * @dst: Action frame destination MAC address
210 * @src: Action frame source MAC address
211 * @bssid: Action frame BSSID
212 * @buf: Frame to transmit starting from the Category field
213 * @len: Length of @buf in bytes
214 * @wait_time: Wait time for response in milliseconds
215 * @tx_cb: Callback function for indicating TX status or %NULL for now callback
216 * @no_cck: Whether CCK rates are to be disallowed for TX rate selection
217 * Returns: 0 on success or -1 on failure
219 * This function is used to request an Action frame to be transmitted on the
220 * current operating channel or on another channel (off-channel). The actual
221 * frame transmission will be delayed until the driver is ready on the specified
222 * channel. The @wait_time parameter can be used to request the driver to remain
223 * awake on the channel to wait for a response.
225 int offchannel_send_action(struct wpa_supplicant
*wpa_s
, unsigned int freq
,
226 const u8
*dst
, const u8
*src
, const u8
*bssid
,
227 const u8
*buf
, size_t len
, unsigned int wait_time
,
228 void (*tx_cb
)(struct wpa_supplicant
*wpa_s
,
229 unsigned int freq
, const u8
*dst
,
230 const u8
*src
, const u8
*bssid
,
231 const u8
*data
, size_t data_len
,
232 enum offchannel_send_action_result
236 wpa_printf(MSG_DEBUG
, "Off-channel: Send action frame: freq=%d dst="
237 MACSTR
" src=" MACSTR
" bssid=" MACSTR
" len=%d",
238 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
241 wpa_s
->pending_action_tx_status_cb
= tx_cb
;
243 if (wpa_s
->pending_action_tx
) {
244 wpa_printf(MSG_DEBUG
, "Off-channel: Dropped pending Action "
245 "frame TX to " MACSTR
,
246 MAC2STR(wpa_s
->pending_action_dst
));
247 wpabuf_free(wpa_s
->pending_action_tx
);
249 wpa_s
->pending_action_tx_done
= 0;
250 wpa_s
->pending_action_tx
= wpabuf_alloc(len
);
251 if (wpa_s
->pending_action_tx
== NULL
) {
252 wpa_printf(MSG_DEBUG
, "Off-channel: Failed to allocate Action "
253 "frame TX buffer (len=%llu)",
254 (unsigned long long) len
);
257 wpabuf_put_data(wpa_s
->pending_action_tx
, buf
, len
);
258 os_memcpy(wpa_s
->pending_action_src
, src
, ETH_ALEN
);
259 os_memcpy(wpa_s
->pending_action_dst
, dst
, ETH_ALEN
);
260 os_memcpy(wpa_s
->pending_action_bssid
, bssid
, ETH_ALEN
);
261 wpa_s
->pending_action_freq
= freq
;
262 wpa_s
->pending_action_no_cck
= no_cck
;
264 if (freq
!= 0 && wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) {
265 struct wpa_supplicant
*iface
;
268 iface
= wpas_get_tx_interface(wpa_s
,
269 wpa_s
->pending_action_src
);
270 wpa_s
->action_tx_wait_time
= wait_time
;
272 ret
= wpa_drv_send_action(
273 iface
, wpa_s
->pending_action_freq
,
274 wait_time
, wpa_s
->pending_action_dst
,
275 wpa_s
->pending_action_src
, wpa_s
->pending_action_bssid
,
276 wpabuf_head(wpa_s
->pending_action_tx
),
277 wpabuf_len(wpa_s
->pending_action_tx
),
278 wpa_s
->pending_action_no_cck
);
280 wpa_s
->pending_action_tx_done
= 1;
285 struct wpa_supplicant
*tx_iface
;
286 tx_iface
= wpas_get_tx_interface(wpa_s
, src
);
287 if (tx_iface
->assoc_freq
== freq
) {
288 wpa_printf(MSG_DEBUG
, "Off-channel: Already on "
289 "requested channel (TX interface operating "
295 if (wpa_s
->off_channel_freq
== freq
|| freq
== 0) {
296 wpa_printf(MSG_DEBUG
, "Off-channel: Already on requested "
297 "channel; send Action frame immediately");
298 /* TODO: Would there ever be need to extend the current
299 * duration on the channel? */
300 wpa_s
->pending_action_without_roc
= 1;
301 eloop_cancel_timeout(wpas_send_action_cb
, wpa_s
, NULL
);
302 eloop_register_timeout(0, 0, wpas_send_action_cb
, wpa_s
, NULL
);
305 wpa_s
->pending_action_without_roc
= 0;
307 if (wpa_s
->roc_waiting_drv_freq
== freq
) {
308 wpa_printf(MSG_DEBUG
, "Off-channel: Already waiting for "
309 "driver to get to frequency %u MHz; continue "
310 "waiting to send the Action frame", freq
);
314 wpa_printf(MSG_DEBUG
, "Off-channel: Schedule Action frame to be "
315 "transmitted once the driver gets to the requested "
317 if (wait_time
> wpa_s
->max_remain_on_chan
)
318 wait_time
= wpa_s
->max_remain_on_chan
;
319 else if (wait_time
== 0)
321 #ifdef CONFIG_TESTING_OPTIONS
322 if (wpa_s
->extra_roc_dur
) {
323 wpa_printf(MSG_DEBUG
, "TESTING: Increase ROC duration %u -> %u",
324 wait_time
, wait_time
+ wpa_s
->extra_roc_dur
);
325 wait_time
+= wpa_s
->extra_roc_dur
;
327 #endif /* CONFIG_TESTING_OPTIONS */
328 if (wpa_drv_remain_on_channel(wpa_s
, freq
, wait_time
) < 0) {
329 wpa_printf(MSG_DEBUG
, "Off-channel: Failed to request driver "
330 "to remain on channel (%u MHz) for Action "
334 wpa_s
->off_channel_freq
= 0;
335 wpa_s
->roc_waiting_drv_freq
= freq
;
342 * offchannel_send_send_action_done - Notify completion of Action frame sequence
343 * @wpa_s: Pointer to wpa_supplicant data
345 * This function can be used to cancel a wait for additional response frames on
346 * the channel that was used with offchannel_send_action().
348 void offchannel_send_action_done(struct wpa_supplicant
*wpa_s
)
350 wpa_printf(MSG_DEBUG
, "Off-channel: Action frame sequence done "
352 wpabuf_free(wpa_s
->pending_action_tx
);
353 wpa_s
->pending_action_tx
= NULL
;
354 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
&&
355 wpa_s
->action_tx_wait_time
)
356 wpa_drv_send_action_cancel_wait(wpa_s
);
358 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
359 wpa_drv_cancel_remain_on_channel(wpa_s
);
360 wpa_s
->off_channel_freq
= 0;
361 wpa_s
->roc_waiting_drv_freq
= 0;
367 * offchannel_remain_on_channel_cb - Remain-on-channel callback function
368 * @wpa_s: Pointer to wpa_supplicant data
369 * @freq: Frequency (in MHz) of the selected channel
370 * @duration: Duration of the remain-on-channel operation in milliseconds
372 * This function is called whenever the driver notifies beginning of a
373 * remain-on-channel operation.
375 void offchannel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
376 unsigned int freq
, unsigned int duration
)
378 wpa_s
->roc_waiting_drv_freq
= 0;
379 wpa_s
->off_channel_freq
= freq
;
380 wpas_send_action_cb(wpa_s
, NULL
);
385 * offchannel_cancel_remain_on_channel_cb - Remain-on-channel stopped callback
386 * @wpa_s: Pointer to wpa_supplicant data
387 * @freq: Frequency (in MHz) of the selected channel
389 * This function is called whenever the driver notifies termination of a
390 * remain-on-channel operation.
392 void offchannel_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
395 wpa_s
->off_channel_freq
= 0;
400 * offchannel_pending_action_tx - Check whether there is a pending Action TX
401 * @wpa_s: Pointer to wpa_supplicant data
402 * Returns: Pointer to pending frame or %NULL if no pending operation
404 * This function can be used to check whether there is a pending Action frame TX
405 * operation. The returned pointer should be used only for checking whether it
406 * is %NULL (no pending frame) or to print the pointer value in debug
407 * information (i.e., the pointer should not be dereferenced).
409 const void * offchannel_pending_action_tx(struct wpa_supplicant
*wpa_s
)
411 return wpa_s
->pending_action_tx
;
416 * offchannel_clear_pending_action_tx - Clear pending Action frame TX
417 * @wpa_s: Pointer to wpa_supplicant data
419 void offchannel_clear_pending_action_tx(struct wpa_supplicant
*wpa_s
)
421 wpabuf_free(wpa_s
->pending_action_tx
);
422 wpa_s
->pending_action_tx
= NULL
;
427 * offchannel_deinit - Deinit off-channel operations
428 * @wpa_s: Pointer to wpa_supplicant data
430 * This function is used to free up any allocated resources for off-channel
433 void offchannel_deinit(struct wpa_supplicant
*wpa_s
)
435 offchannel_clear_pending_action_tx(wpa_s
);
436 eloop_cancel_timeout(wpas_send_action_cb
, wpa_s
, NULL
);