]> git.ipfire.org Git - thirdparty/hostap.git/blame - wpa_supplicant/offchannel.c
Revert "Assign QCA vendor command and attribute for Tx/Rx aggregation"
[thirdparty/hostap.git] / wpa_supplicant / offchannel.c
CommitLineData
24f6497c
JM
1/*
2 * wpa_supplicant - Off-channel Action frame TX/RX
3 * Copyright (c) 2009-2010, Atheros Communications
4 * Copyright (c) 2011, Qualcomm Atheros
5 *
e22d4d95
JM
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
24f6497c
JM
8 */
9
10#include "includes.h"
11
12#include "common.h"
13#include "utils/eloop.h"
14#include "wpa_supplicant_i.h"
49e1e9ca 15#include "p2p_supplicant.h"
24f6497c
JM
16#include "driver_i.h"
17#include "offchannel.h"
18
19
20
21static struct wpa_supplicant *
22wpas_get_tx_interface(struct wpa_supplicant *wpa_s, const u8 *src)
23{
24 struct wpa_supplicant *iface;
25
26 if (os_memcmp(src, wpa_s->own_addr, ETH_ALEN) == 0)
27 return wpa_s;
28
29 /*
30 * Try to find a group interface that matches with the source address.
31 */
32 iface = wpa_s->global->ifaces;
33 while (iface) {
8e3afd7f 34 if (os_memcmp(src, iface->own_addr, ETH_ALEN) == 0)
24f6497c
JM
35 break;
36 iface = iface->next;
37 }
38 if (iface) {
39 wpa_printf(MSG_DEBUG, "P2P: Use group interface %s "
40 "instead of interface %s for Action TX",
41 iface->ifname, wpa_s->ifname);
42 return iface;
43 }
44
45 return wpa_s;
46}
47
48
49static void wpas_send_action_cb(void *eloop_ctx, void *timeout_ctx)
50{
51 struct wpa_supplicant *wpa_s = eloop_ctx;
52 struct wpa_supplicant *iface;
53 int res;
54 int without_roc;
55
56 without_roc = wpa_s->pending_action_without_roc;
57 wpa_s->pending_action_without_roc = 0;
d4b951f3
JM
58 wpa_printf(MSG_DEBUG,
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);
24f6497c 62
d4b951f3 63 if (wpa_s->pending_action_tx == NULL || wpa_s->pending_action_tx_done)
24f6497c
JM
64 return;
65
66 /*
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.
74 */
75 iface = wpas_get_tx_interface(wpa_s, wpa_s->pending_action_src);
76
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 "
82 "assoc_freq=%u)",
83 wpa_s->pending_action_freq,
84 wpa_s->off_channel_freq,
85 iface->assoc_freq);
86 if (without_roc && wpa_s->off_channel_freq == 0) {
1f94e4ee 87 unsigned int duration = 200;
24f6497c
JM
88 /*
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.
92 */
93 wpa_printf(MSG_DEBUG, "Off-channel: Schedule "
94 "remain-on-channel to send Action frame");
1f94e4ee
JM
95#ifdef CONFIG_TESTING_OPTIONS
96 if (wpa_s->extra_roc_dur) {
97 wpa_printf(MSG_DEBUG,
98 "TESTING: Increase ROC duration %u -> %u",
99 duration,
100 duration + wpa_s->extra_roc_dur);
101 duration += wpa_s->extra_roc_dur;
102 }
103#endif /* CONFIG_TESTING_OPTIONS */
24f6497c 104 if (wpa_drv_remain_on_channel(
1f94e4ee
JM
105 wpa_s, wpa_s->pending_action_freq,
106 duration) < 0) {
24f6497c
JM
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);
111 } else {
112 wpa_s->off_channel_freq = 0;
113 wpa_s->roc_waiting_drv_freq =
114 wpa_s->pending_action_freq;
115 }
116 }
117 return;
118 }
119
120 wpa_printf(MSG_DEBUG, "Off-channel: Sending pending Action frame to "
e699a7a9
JM
121 MACSTR " using interface %s (pending_action_tx=%p)",
122 MAC2STR(wpa_s->pending_action_dst), iface->ifname,
123 wpa_s->pending_action_tx);
24f6497c
JM
124 res = wpa_drv_send_action(iface, wpa_s->pending_action_freq, 0,
125 wpa_s->pending_action_dst,
126 wpa_s->pending_action_src,
127 wpa_s->pending_action_bssid,
128 wpabuf_head(wpa_s->pending_action_tx),
b106173a
JM
129 wpabuf_len(wpa_s->pending_action_tx),
130 wpa_s->pending_action_no_cck);
24f6497c
JM
131 if (res) {
132 wpa_printf(MSG_DEBUG, "Off-channel: Failed to send the "
133 "pending Action frame");
134 /*
135 * Use fake TX status event to allow state machines to
136 * continue.
137 */
138 offchannel_send_action_tx_status(
139 wpa_s, wpa_s->pending_action_dst,
140 wpabuf_head(wpa_s->pending_action_tx),
141 wpabuf_len(wpa_s->pending_action_tx),
142 OFFCHANNEL_SEND_ACTION_FAILED);
143 }
144}
145
146
b4419c62
JM
147/**
148 * offchannel_send_action_tx_status - TX status callback
149 * @wpa_s: Pointer to wpa_supplicant data
150 * @dst: Destination MAC address of the transmitted Action frame
151 * @data: Transmitted frame payload
152 * @data_len: Length of @data in bytes
153 * @result: TX status
154 *
155 * This function is called whenever the driver indicates a TX status event for
156 * a frame sent by offchannel_send_action() using wpa_drv_send_action().
157 */
24f6497c
JM
158void offchannel_send_action_tx_status(
159 struct wpa_supplicant *wpa_s, const u8 *dst, const u8 *data,
160 size_t data_len, enum offchannel_send_action_result result)
161{
162 if (wpa_s->pending_action_tx == NULL) {
163 wpa_printf(MSG_DEBUG, "Off-channel: Ignore Action TX status - "
164 "no pending operation");
165 return;
166 }
167
168 if (os_memcmp(dst, wpa_s->pending_action_dst, ETH_ALEN) != 0) {
169 wpa_printf(MSG_DEBUG, "Off-channel: Ignore Action TX status - "
170 "unknown destination address");
171 return;
172 }
173
47d986e6
PLL
174 /* Accept report only if the contents of the frame matches */
175 if (data_len - wpabuf_len(wpa_s->pending_action_tx) != 24 ||
176 os_memcmp(data + 24, wpabuf_head(wpa_s->pending_action_tx),
177 wpabuf_len(wpa_s->pending_action_tx)) != 0) {
178 wpa_printf(MSG_DEBUG, "Off-channel: Ignore Action TX status - "
179 "mismatching contents with pending frame");
180 wpa_hexdump(MSG_MSGDUMP, "TX status frame data",
181 data, data_len);
182 wpa_hexdump_buf(MSG_MSGDUMP, "Pending TX frame",
183 wpa_s->pending_action_tx);
184 return;
185 }
186
e699a7a9
JM
187 wpa_printf(MSG_DEBUG,
188 "Off-channel: Delete matching pending action frame (dst="
189 MACSTR " pending_action_tx=%p)", MAC2STR(dst),
190 wpa_s->pending_action_tx);
191 wpa_hexdump_buf(MSG_MSGDUMP, "Pending TX frame",
192 wpa_s->pending_action_tx);
24f6497c
JM
193 wpabuf_free(wpa_s->pending_action_tx);
194 wpa_s->pending_action_tx = NULL;
195
196 wpa_printf(MSG_DEBUG, "Off-channel: TX status result=%d cb=%p",
197 result, wpa_s->pending_action_tx_status_cb);
198
199 if (wpa_s->pending_action_tx_status_cb) {
200 wpa_s->pending_action_tx_status_cb(
201 wpa_s, wpa_s->pending_action_freq,
202 wpa_s->pending_action_dst, wpa_s->pending_action_src,
203 wpa_s->pending_action_bssid,
204 data, data_len, result);
205 }
49e1e9ca
JJ
206
207#ifdef CONFIG_P2P
208 if (wpa_s->p2p_long_listen > 0) {
209 /* Continue the listen */
210 wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state");
211 wpas_p2p_listen_start(wpa_s, wpa_s->p2p_long_listen);
212 }
213#endif /* CONFIG_P2P */
24f6497c
JM
214}
215
216
b4419c62
JM
217/**
218 * offchannel_send_action - Request off-channel Action frame TX
219 * @wpa_s: Pointer to wpa_supplicant data
220 * @freq: The frequency in MHz indicating the channel on which the frame is to
221 * transmitted or 0 for the current channel (only if associated)
222 * @dst: Action frame destination MAC address
223 * @src: Action frame source MAC address
224 * @bssid: Action frame BSSID
225 * @buf: Frame to transmit starting from the Category field
226 * @len: Length of @buf in bytes
227 * @wait_time: Wait time for response in milliseconds
228 * @tx_cb: Callback function for indicating TX status or %NULL for now callback
229 * @no_cck: Whether CCK rates are to be disallowed for TX rate selection
230 * Returns: 0 on success or -1 on failure
231 *
232 * This function is used to request an Action frame to be transmitted on the
233 * current operating channel or on another channel (off-channel). The actual
234 * frame transmission will be delayed until the driver is ready on the specified
235 * channel. The @wait_time parameter can be used to request the driver to remain
236 * awake on the channel to wait for a response.
237 */
24f6497c
JM
238int offchannel_send_action(struct wpa_supplicant *wpa_s, unsigned int freq,
239 const u8 *dst, const u8 *src, const u8 *bssid,
240 const u8 *buf, size_t len, unsigned int wait_time,
241 void (*tx_cb)(struct wpa_supplicant *wpa_s,
242 unsigned int freq, const u8 *dst,
243 const u8 *src, const u8 *bssid,
244 const u8 *data, size_t data_len,
245 enum offchannel_send_action_result
b106173a
JM
246 result),
247 int no_cck)
24f6497c
JM
248{
249 wpa_printf(MSG_DEBUG, "Off-channel: Send action frame: freq=%d dst="
250 MACSTR " src=" MACSTR " bssid=" MACSTR " len=%d",
251 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
252 (int) len);
253
254 wpa_s->pending_action_tx_status_cb = tx_cb;
255
256 if (wpa_s->pending_action_tx) {
257 wpa_printf(MSG_DEBUG, "Off-channel: Dropped pending Action "
e699a7a9
JM
258 "frame TX to " MACSTR " (pending_action_tx=%p)",
259 MAC2STR(wpa_s->pending_action_dst),
260 wpa_s->pending_action_tx);
261 wpa_hexdump_buf(MSG_MSGDUMP, "Pending TX frame",
262 wpa_s->pending_action_tx);
24f6497c
JM
263 wpabuf_free(wpa_s->pending_action_tx);
264 }
d4b951f3 265 wpa_s->pending_action_tx_done = 0;
24f6497c
JM
266 wpa_s->pending_action_tx = wpabuf_alloc(len);
267 if (wpa_s->pending_action_tx == NULL) {
268 wpa_printf(MSG_DEBUG, "Off-channel: Failed to allocate Action "
269 "frame TX buffer (len=%llu)",
270 (unsigned long long) len);
271 return -1;
272 }
273 wpabuf_put_data(wpa_s->pending_action_tx, buf, len);
274 os_memcpy(wpa_s->pending_action_src, src, ETH_ALEN);
275 os_memcpy(wpa_s->pending_action_dst, dst, ETH_ALEN);
276 os_memcpy(wpa_s->pending_action_bssid, bssid, ETH_ALEN);
277 wpa_s->pending_action_freq = freq;
b106173a 278 wpa_s->pending_action_no_cck = no_cck;
e699a7a9
JM
279 wpa_printf(MSG_DEBUG,
280 "Off-channel: Stored pending action frame (dst=" MACSTR
281 " pending_action_tx=%p)",
282 MAC2STR(dst), wpa_s->pending_action_tx);
283 wpa_hexdump_buf(MSG_MSGDUMP, "Pending TX frame",
284 wpa_s->pending_action_tx);
24f6497c
JM
285
286 if (freq != 0 && wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) {
287 struct wpa_supplicant *iface;
d4b951f3 288 int ret;
24f6497c 289
8e3afd7f 290 iface = wpas_get_tx_interface(wpa_s, src);
24f6497c
JM
291 wpa_s->action_tx_wait_time = wait_time;
292
d4b951f3 293 ret = wpa_drv_send_action(
b106173a
JM
294 iface, wpa_s->pending_action_freq,
295 wait_time, wpa_s->pending_action_dst,
296 wpa_s->pending_action_src, wpa_s->pending_action_bssid,
297 wpabuf_head(wpa_s->pending_action_tx),
298 wpabuf_len(wpa_s->pending_action_tx),
299 wpa_s->pending_action_no_cck);
d4b951f3
JM
300 if (ret == 0)
301 wpa_s->pending_action_tx_done = 1;
302 return ret;
24f6497c
JM
303 }
304
305 if (freq) {
306 struct wpa_supplicant *tx_iface;
307 tx_iface = wpas_get_tx_interface(wpa_s, src);
308 if (tx_iface->assoc_freq == freq) {
309 wpa_printf(MSG_DEBUG, "Off-channel: Already on "
310 "requested channel (TX interface operating "
311 "channel)");
312 freq = 0;
313 }
314 }
315
316 if (wpa_s->off_channel_freq == freq || freq == 0) {
317 wpa_printf(MSG_DEBUG, "Off-channel: Already on requested "
318 "channel; send Action frame immediately");
319 /* TODO: Would there ever be need to extend the current
320 * duration on the channel? */
321 wpa_s->pending_action_without_roc = 1;
322 eloop_cancel_timeout(wpas_send_action_cb, wpa_s, NULL);
323 eloop_register_timeout(0, 0, wpas_send_action_cb, wpa_s, NULL);
324 return 0;
325 }
326 wpa_s->pending_action_without_roc = 0;
327
328 if (wpa_s->roc_waiting_drv_freq == freq) {
329 wpa_printf(MSG_DEBUG, "Off-channel: Already waiting for "
330 "driver to get to frequency %u MHz; continue "
331 "waiting to send the Action frame", freq);
332 return 0;
333 }
334
335 wpa_printf(MSG_DEBUG, "Off-channel: Schedule Action frame to be "
336 "transmitted once the driver gets to the requested "
337 "channel");
338 if (wait_time > wpa_s->max_remain_on_chan)
339 wait_time = wpa_s->max_remain_on_chan;
a2ea8d64
WJL
340 else if (wait_time == 0)
341 wait_time = 20;
1f94e4ee
JM
342#ifdef CONFIG_TESTING_OPTIONS
343 if (wpa_s->extra_roc_dur) {
344 wpa_printf(MSG_DEBUG, "TESTING: Increase ROC duration %u -> %u",
345 wait_time, wait_time + wpa_s->extra_roc_dur);
346 wait_time += wpa_s->extra_roc_dur;
347 }
348#endif /* CONFIG_TESTING_OPTIONS */
24f6497c
JM
349 if (wpa_drv_remain_on_channel(wpa_s, freq, wait_time) < 0) {
350 wpa_printf(MSG_DEBUG, "Off-channel: Failed to request driver "
351 "to remain on channel (%u MHz) for Action "
352 "Frame TX", freq);
353 return -1;
354 }
355 wpa_s->off_channel_freq = 0;
356 wpa_s->roc_waiting_drv_freq = freq;
357
358 return 0;
359}
360
361
b4419c62
JM
362/**
363 * offchannel_send_send_action_done - Notify completion of Action frame sequence
364 * @wpa_s: Pointer to wpa_supplicant data
365 *
366 * This function can be used to cancel a wait for additional response frames on
367 * the channel that was used with offchannel_send_action().
368 */
24f6497c
JM
369void offchannel_send_action_done(struct wpa_supplicant *wpa_s)
370{
66eaf8a2
JM
371 wpa_printf(MSG_DEBUG,
372 "Off-channel: Action frame sequence done notification: pending_action_tx=%p drv_offchan_tx=%d action_tx_wait_time=%d off_channel_freq=%d roc_waiting_drv_freq=%d",
373 wpa_s->pending_action_tx,
374 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX),
375 wpa_s->action_tx_wait_time, wpa_s->off_channel_freq,
376 wpa_s->roc_waiting_drv_freq);
24f6497c
JM
377 wpabuf_free(wpa_s->pending_action_tx);
378 wpa_s->pending_action_tx = NULL;
379 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX &&
380 wpa_s->action_tx_wait_time)
381 wpa_drv_send_action_cancel_wait(wpa_s);
66eaf8a2 382 else if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
24f6497c
JM
383 wpa_drv_cancel_remain_on_channel(wpa_s);
384 wpa_s->off_channel_freq = 0;
385 wpa_s->roc_waiting_drv_freq = 0;
386 }
387}
388
389
b4419c62
JM
390/**
391 * offchannel_remain_on_channel_cb - Remain-on-channel callback function
392 * @wpa_s: Pointer to wpa_supplicant data
393 * @freq: Frequency (in MHz) of the selected channel
394 * @duration: Duration of the remain-on-channel operation in milliseconds
395 *
396 * This function is called whenever the driver notifies beginning of a
397 * remain-on-channel operation.
398 */
24f6497c
JM
399void offchannel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
400 unsigned int freq, unsigned int duration)
401{
402 wpa_s->roc_waiting_drv_freq = 0;
403 wpa_s->off_channel_freq = freq;
404 wpas_send_action_cb(wpa_s, NULL);
405}
406
407
b4419c62
JM
408/**
409 * offchannel_cancel_remain_on_channel_cb - Remain-on-channel stopped callback
410 * @wpa_s: Pointer to wpa_supplicant data
411 * @freq: Frequency (in MHz) of the selected channel
412 *
413 * This function is called whenever the driver notifies termination of a
414 * remain-on-channel operation.
415 */
24f6497c
JM
416void offchannel_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
417 unsigned int freq)
418{
419 wpa_s->off_channel_freq = 0;
420}
421
422
2f3101d8
JM
423/**
424 * offchannel_pending_action_tx - Check whether there is a pending Action TX
425 * @wpa_s: Pointer to wpa_supplicant data
426 * Returns: Pointer to pending frame or %NULL if no pending operation
427 *
428 * This function can be used to check whether there is a pending Action frame TX
429 * operation. The returned pointer should be used only for checking whether it
430 * is %NULL (no pending frame) or to print the pointer value in debug
431 * information (i.e., the pointer should not be dereferenced).
432 */
433const void * offchannel_pending_action_tx(struct wpa_supplicant *wpa_s)
434{
435 return wpa_s->pending_action_tx;
436}
437
438
439/**
440 * offchannel_clear_pending_action_tx - Clear pending Action frame TX
441 * @wpa_s: Pointer to wpa_supplicant data
442 */
443void offchannel_clear_pending_action_tx(struct wpa_supplicant *wpa_s)
444{
e699a7a9
JM
445 wpa_printf(MSG_DEBUG,
446 "Off-channel: Clear pending Action frame TX (pending_action_tx=%p",
447 wpa_s->pending_action_tx);
2f3101d8
JM
448 wpabuf_free(wpa_s->pending_action_tx);
449 wpa_s->pending_action_tx = NULL;
450}
451
452
b4419c62
JM
453/**
454 * offchannel_deinit - Deinit off-channel operations
455 * @wpa_s: Pointer to wpa_supplicant data
456 *
457 * This function is used to free up any allocated resources for off-channel
458 * operations.
459 */
24f6497c
JM
460void offchannel_deinit(struct wpa_supplicant *wpa_s)
461{
2f3101d8 462 offchannel_clear_pending_action_tx(wpa_s);
24f6497c
JM
463 eloop_cancel_timeout(wpas_send_action_cb, wpa_s, NULL);
464}