1f05cddf9SRui Paulo /*
2f05cddf9SRui Paulo * wpa_supplicant - Off-channel Action frame TX/RX
3f05cddf9SRui Paulo * Copyright (c) 2009-2010, Atheros Communications
4f05cddf9SRui Paulo * Copyright (c) 2011, Qualcomm Atheros
5f05cddf9SRui Paulo *
6f05cddf9SRui Paulo * This software may be distributed under the terms of the BSD license.
7f05cddf9SRui Paulo * See README for more details.
8f05cddf9SRui Paulo */
9f05cddf9SRui Paulo
10f05cddf9SRui Paulo #include "includes.h"
11f05cddf9SRui Paulo
12f05cddf9SRui Paulo #include "common.h"
13f05cddf9SRui Paulo #include "utils/eloop.h"
14f05cddf9SRui Paulo #include "wpa_supplicant_i.h"
155b9c547cSRui Paulo #include "p2p_supplicant.h"
16f05cddf9SRui Paulo #include "driver_i.h"
17f05cddf9SRui Paulo #include "offchannel.h"
18f05cddf9SRui Paulo
19f05cddf9SRui Paulo
20f05cddf9SRui Paulo
21f05cddf9SRui Paulo static struct wpa_supplicant *
wpas_get_tx_interface(struct wpa_supplicant * wpa_s,const u8 * src)22f05cddf9SRui Paulo wpas_get_tx_interface(struct wpa_supplicant *wpa_s, const u8 *src)
23f05cddf9SRui Paulo {
24f05cddf9SRui Paulo struct wpa_supplicant *iface;
25f05cddf9SRui Paulo
26*a90b9d01SCy Schubert if (ether_addr_equal(src, wpa_s->own_addr)) {
27780fb4a2SCy Schubert #ifdef CONFIG_P2P
28780fb4a2SCy Schubert if (wpa_s->p2p_mgmt && wpa_s != wpa_s->parent &&
29780fb4a2SCy Schubert wpa_s->parent->ap_iface &&
30*a90b9d01SCy Schubert ether_addr_equal(wpa_s->parent->own_addr,
31*a90b9d01SCy Schubert wpa_s->own_addr) &&
32780fb4a2SCy Schubert wpabuf_len(wpa_s->pending_action_tx) >= 2 &&
33780fb4a2SCy Schubert *wpabuf_head_u8(wpa_s->pending_action_tx) !=
34780fb4a2SCy Schubert WLAN_ACTION_PUBLIC) {
35780fb4a2SCy Schubert /*
36780fb4a2SCy Schubert * When P2P Device interface has same MAC address as
37780fb4a2SCy Schubert * the GO interface, make sure non-Public Action frames
38780fb4a2SCy Schubert * are sent through the GO interface. The P2P Device
39780fb4a2SCy Schubert * interface can only send Public Action frames.
40780fb4a2SCy Schubert */
41780fb4a2SCy Schubert wpa_printf(MSG_DEBUG,
42780fb4a2SCy Schubert "P2P: Use GO interface %s instead of interface %s for Action TX",
43780fb4a2SCy Schubert wpa_s->parent->ifname, wpa_s->ifname);
44780fb4a2SCy Schubert return wpa_s->parent;
45780fb4a2SCy Schubert }
46780fb4a2SCy Schubert #endif /* CONFIG_P2P */
47f05cddf9SRui Paulo return wpa_s;
48780fb4a2SCy Schubert }
49f05cddf9SRui Paulo
50f05cddf9SRui Paulo /*
51f05cddf9SRui Paulo * Try to find a group interface that matches with the source address.
52f05cddf9SRui Paulo */
53f05cddf9SRui Paulo iface = wpa_s->global->ifaces;
54f05cddf9SRui Paulo while (iface) {
55*a90b9d01SCy Schubert if (ether_addr_equal(src, iface->own_addr))
56f05cddf9SRui Paulo break;
57f05cddf9SRui Paulo iface = iface->next;
58f05cddf9SRui Paulo }
59f05cddf9SRui Paulo if (iface) {
60f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "P2P: Use group interface %s "
61f05cddf9SRui Paulo "instead of interface %s for Action TX",
62f05cddf9SRui Paulo iface->ifname, wpa_s->ifname);
63f05cddf9SRui Paulo return iface;
64f05cddf9SRui Paulo }
65f05cddf9SRui Paulo
66f05cddf9SRui Paulo return wpa_s;
67f05cddf9SRui Paulo }
68f05cddf9SRui Paulo
69f05cddf9SRui Paulo
wpas_send_action_cb(void * eloop_ctx,void * timeout_ctx)70f05cddf9SRui Paulo static void wpas_send_action_cb(void *eloop_ctx, void *timeout_ctx)
71f05cddf9SRui Paulo {
72f05cddf9SRui Paulo struct wpa_supplicant *wpa_s = eloop_ctx;
73f05cddf9SRui Paulo struct wpa_supplicant *iface;
74f05cddf9SRui Paulo int res;
75f05cddf9SRui Paulo int without_roc;
76f05cddf9SRui Paulo
77f05cddf9SRui Paulo without_roc = wpa_s->pending_action_without_roc;
78f05cddf9SRui Paulo wpa_s->pending_action_without_roc = 0;
795b9c547cSRui Paulo wpa_printf(MSG_DEBUG,
805b9c547cSRui Paulo "Off-channel: Send Action callback (without_roc=%d pending_action_tx=%p pending_action_tx_done=%d)",
815b9c547cSRui Paulo without_roc, wpa_s->pending_action_tx,
825b9c547cSRui Paulo !!wpa_s->pending_action_tx_done);
83f05cddf9SRui Paulo
845b9c547cSRui Paulo if (wpa_s->pending_action_tx == NULL || wpa_s->pending_action_tx_done)
85f05cddf9SRui Paulo return;
86f05cddf9SRui Paulo
87f05cddf9SRui Paulo /*
88f05cddf9SRui Paulo * This call is likely going to be on the P2P device instance if the
89f05cddf9SRui Paulo * driver uses a separate interface for that purpose. However, some
90f05cddf9SRui Paulo * Action frames are actually sent within a P2P Group and when that is
91f05cddf9SRui Paulo * the case, we need to follow power saving (e.g., GO buffering the
92f05cddf9SRui Paulo * frame for a client in PS mode or a client following the advertised
93f05cddf9SRui Paulo * NoA from its GO). To make that easier for the driver, select the
94f05cddf9SRui Paulo * correct group interface here.
95f05cddf9SRui Paulo */
96f05cddf9SRui Paulo iface = wpas_get_tx_interface(wpa_s, wpa_s->pending_action_src);
97f05cddf9SRui Paulo
98f05cddf9SRui Paulo if (wpa_s->off_channel_freq != wpa_s->pending_action_freq &&
99f05cddf9SRui Paulo wpa_s->pending_action_freq != 0 &&
100f05cddf9SRui Paulo wpa_s->pending_action_freq != iface->assoc_freq) {
101f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Pending Action frame TX "
102f05cddf9SRui Paulo "waiting for another freq=%u (off_channel_freq=%u "
103f05cddf9SRui Paulo "assoc_freq=%u)",
104f05cddf9SRui Paulo wpa_s->pending_action_freq,
105f05cddf9SRui Paulo wpa_s->off_channel_freq,
106f05cddf9SRui Paulo iface->assoc_freq);
107f05cddf9SRui Paulo if (without_roc && wpa_s->off_channel_freq == 0) {
1085b9c547cSRui Paulo unsigned int duration = 200;
109f05cddf9SRui Paulo /*
110f05cddf9SRui Paulo * We may get here if wpas_send_action() found us to be
111f05cddf9SRui Paulo * on the correct channel, but remain-on-channel cancel
112f05cddf9SRui Paulo * event was received before getting here.
113f05cddf9SRui Paulo */
114f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Schedule "
115f05cddf9SRui Paulo "remain-on-channel to send Action frame");
1165b9c547cSRui Paulo #ifdef CONFIG_TESTING_OPTIONS
1175b9c547cSRui Paulo if (wpa_s->extra_roc_dur) {
1185b9c547cSRui Paulo wpa_printf(MSG_DEBUG,
1195b9c547cSRui Paulo "TESTING: Increase ROC duration %u -> %u",
1205b9c547cSRui Paulo duration,
1215b9c547cSRui Paulo duration + wpa_s->extra_roc_dur);
1225b9c547cSRui Paulo duration += wpa_s->extra_roc_dur;
1235b9c547cSRui Paulo }
1245b9c547cSRui Paulo #endif /* CONFIG_TESTING_OPTIONS */
125f05cddf9SRui Paulo if (wpa_drv_remain_on_channel(
1265b9c547cSRui Paulo wpa_s, wpa_s->pending_action_freq,
1275b9c547cSRui Paulo duration) < 0) {
128f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Failed to "
129f05cddf9SRui Paulo "request driver to remain on "
130f05cddf9SRui Paulo "channel (%u MHz) for Action Frame "
131f05cddf9SRui Paulo "TX", wpa_s->pending_action_freq);
132f05cddf9SRui Paulo } else {
133f05cddf9SRui Paulo wpa_s->off_channel_freq = 0;
134f05cddf9SRui Paulo wpa_s->roc_waiting_drv_freq =
135f05cddf9SRui Paulo wpa_s->pending_action_freq;
136f05cddf9SRui Paulo }
137f05cddf9SRui Paulo }
138f05cddf9SRui Paulo return;
139f05cddf9SRui Paulo }
140f05cddf9SRui Paulo
141f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Sending pending Action frame to "
142780fb4a2SCy Schubert MACSTR " using interface %s (pending_action_tx=%p)",
143780fb4a2SCy Schubert MAC2STR(wpa_s->pending_action_dst), iface->ifname,
144780fb4a2SCy Schubert wpa_s->pending_action_tx);
145f05cddf9SRui Paulo res = wpa_drv_send_action(iface, wpa_s->pending_action_freq, 0,
146f05cddf9SRui Paulo wpa_s->pending_action_dst,
147f05cddf9SRui Paulo wpa_s->pending_action_src,
148f05cddf9SRui Paulo wpa_s->pending_action_bssid,
149f05cddf9SRui Paulo wpabuf_head(wpa_s->pending_action_tx),
150f05cddf9SRui Paulo wpabuf_len(wpa_s->pending_action_tx),
151f05cddf9SRui Paulo wpa_s->pending_action_no_cck);
152f05cddf9SRui Paulo if (res) {
153f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Failed to send the "
154f05cddf9SRui Paulo "pending Action frame");
155f05cddf9SRui Paulo /*
156f05cddf9SRui Paulo * Use fake TX status event to allow state machines to
157f05cddf9SRui Paulo * continue.
158f05cddf9SRui Paulo */
159f05cddf9SRui Paulo offchannel_send_action_tx_status(
160f05cddf9SRui Paulo wpa_s, wpa_s->pending_action_dst,
161f05cddf9SRui Paulo wpabuf_head(wpa_s->pending_action_tx),
162f05cddf9SRui Paulo wpabuf_len(wpa_s->pending_action_tx),
163f05cddf9SRui Paulo OFFCHANNEL_SEND_ACTION_FAILED);
164f05cddf9SRui Paulo }
165f05cddf9SRui Paulo }
166f05cddf9SRui Paulo
167f05cddf9SRui Paulo
168f05cddf9SRui Paulo /**
169f05cddf9SRui Paulo * offchannel_send_action_tx_status - TX status callback
170f05cddf9SRui Paulo * @wpa_s: Pointer to wpa_supplicant data
171f05cddf9SRui Paulo * @dst: Destination MAC address of the transmitted Action frame
172f05cddf9SRui Paulo * @data: Transmitted frame payload
173f05cddf9SRui Paulo * @data_len: Length of @data in bytes
174f05cddf9SRui Paulo * @result: TX status
175f05cddf9SRui Paulo *
176f05cddf9SRui Paulo * This function is called whenever the driver indicates a TX status event for
177f05cddf9SRui Paulo * a frame sent by offchannel_send_action() using wpa_drv_send_action().
178f05cddf9SRui Paulo */
offchannel_send_action_tx_status(struct wpa_supplicant * wpa_s,const u8 * dst,const u8 * data,size_t data_len,enum offchannel_send_action_result result)179f05cddf9SRui Paulo void offchannel_send_action_tx_status(
180f05cddf9SRui Paulo struct wpa_supplicant *wpa_s, const u8 *dst, const u8 *data,
181f05cddf9SRui Paulo size_t data_len, enum offchannel_send_action_result result)
182f05cddf9SRui Paulo {
183f05cddf9SRui Paulo if (wpa_s->pending_action_tx == NULL) {
184f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Ignore Action TX status - "
185f05cddf9SRui Paulo "no pending operation");
186f05cddf9SRui Paulo return;
187f05cddf9SRui Paulo }
188f05cddf9SRui Paulo
189*a90b9d01SCy Schubert if (!ether_addr_equal(dst, wpa_s->pending_action_dst)) {
190f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Ignore Action TX status - "
191f05cddf9SRui Paulo "unknown destination address");
192f05cddf9SRui Paulo return;
193f05cddf9SRui Paulo }
194f05cddf9SRui Paulo
1955b9c547cSRui Paulo /* Accept report only if the contents of the frame matches */
1965b9c547cSRui Paulo if (data_len - wpabuf_len(wpa_s->pending_action_tx) != 24 ||
1975b9c547cSRui Paulo os_memcmp(data + 24, wpabuf_head(wpa_s->pending_action_tx),
1985b9c547cSRui Paulo wpabuf_len(wpa_s->pending_action_tx)) != 0) {
1995b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Ignore Action TX status - "
2005b9c547cSRui Paulo "mismatching contents with pending frame");
2015b9c547cSRui Paulo wpa_hexdump(MSG_MSGDUMP, "TX status frame data",
2025b9c547cSRui Paulo data, data_len);
2035b9c547cSRui Paulo wpa_hexdump_buf(MSG_MSGDUMP, "Pending TX frame",
2045b9c547cSRui Paulo wpa_s->pending_action_tx);
2055b9c547cSRui Paulo return;
2065b9c547cSRui Paulo }
2075b9c547cSRui Paulo
208780fb4a2SCy Schubert wpa_printf(MSG_DEBUG,
209780fb4a2SCy Schubert "Off-channel: Delete matching pending action frame (dst="
210780fb4a2SCy Schubert MACSTR " pending_action_tx=%p)", MAC2STR(dst),
211780fb4a2SCy Schubert wpa_s->pending_action_tx);
212780fb4a2SCy Schubert wpa_hexdump_buf(MSG_MSGDUMP, "Pending TX frame",
213780fb4a2SCy Schubert wpa_s->pending_action_tx);
214f05cddf9SRui Paulo wpabuf_free(wpa_s->pending_action_tx);
215f05cddf9SRui Paulo wpa_s->pending_action_tx = NULL;
216f05cddf9SRui Paulo
217f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: TX status result=%d cb=%p",
218f05cddf9SRui Paulo result, wpa_s->pending_action_tx_status_cb);
219f05cddf9SRui Paulo
220f05cddf9SRui Paulo if (wpa_s->pending_action_tx_status_cb) {
221f05cddf9SRui Paulo wpa_s->pending_action_tx_status_cb(
222f05cddf9SRui Paulo wpa_s, wpa_s->pending_action_freq,
223f05cddf9SRui Paulo wpa_s->pending_action_dst, wpa_s->pending_action_src,
224f05cddf9SRui Paulo wpa_s->pending_action_bssid,
225f05cddf9SRui Paulo data, data_len, result);
226f05cddf9SRui Paulo }
2275b9c547cSRui Paulo
2285b9c547cSRui Paulo #ifdef CONFIG_P2P
229c1d255d3SCy Schubert if (wpa_s->global->p2p_long_listen > 0) {
2305b9c547cSRui Paulo /* Continue the listen */
2315b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state");
232c1d255d3SCy Schubert wpas_p2p_listen_start(wpa_s, wpa_s->global->p2p_long_listen);
2335b9c547cSRui Paulo }
2345b9c547cSRui Paulo #endif /* CONFIG_P2P */
235f05cddf9SRui Paulo }
236f05cddf9SRui Paulo
237f05cddf9SRui Paulo
238f05cddf9SRui Paulo /**
239f05cddf9SRui Paulo * offchannel_send_action - Request off-channel Action frame TX
240f05cddf9SRui Paulo * @wpa_s: Pointer to wpa_supplicant data
241f05cddf9SRui Paulo * @freq: The frequency in MHz indicating the channel on which the frame is to
242f05cddf9SRui Paulo * transmitted or 0 for the current channel (only if associated)
243f05cddf9SRui Paulo * @dst: Action frame destination MAC address
244f05cddf9SRui Paulo * @src: Action frame source MAC address
245f05cddf9SRui Paulo * @bssid: Action frame BSSID
246f05cddf9SRui Paulo * @buf: Frame to transmit starting from the Category field
247f05cddf9SRui Paulo * @len: Length of @buf in bytes
248f05cddf9SRui Paulo * @wait_time: Wait time for response in milliseconds
249c1d255d3SCy Schubert * @tx_cb: Callback function for indicating TX status or %NULL for no callback
250f05cddf9SRui Paulo * @no_cck: Whether CCK rates are to be disallowed for TX rate selection
251f05cddf9SRui Paulo * Returns: 0 on success or -1 on failure
252f05cddf9SRui Paulo *
253f05cddf9SRui Paulo * This function is used to request an Action frame to be transmitted on the
254f05cddf9SRui Paulo * current operating channel or on another channel (off-channel). The actual
255f05cddf9SRui Paulo * frame transmission will be delayed until the driver is ready on the specified
256f05cddf9SRui Paulo * channel. The @wait_time parameter can be used to request the driver to remain
257f05cddf9SRui Paulo * awake on the channel to wait for a response.
258f05cddf9SRui Paulo */
offchannel_send_action(struct wpa_supplicant * wpa_s,unsigned int freq,const u8 * dst,const u8 * src,const u8 * bssid,const u8 * buf,size_t len,unsigned int wait_time,void (* tx_cb)(struct wpa_supplicant * wpa_s,unsigned int freq,const u8 * dst,const u8 * src,const u8 * bssid,const u8 * data,size_t data_len,enum offchannel_send_action_result result),int no_cck)259f05cddf9SRui Paulo int offchannel_send_action(struct wpa_supplicant *wpa_s, unsigned int freq,
260f05cddf9SRui Paulo const u8 *dst, const u8 *src, const u8 *bssid,
261f05cddf9SRui Paulo const u8 *buf, size_t len, unsigned int wait_time,
262f05cddf9SRui Paulo void (*tx_cb)(struct wpa_supplicant *wpa_s,
263f05cddf9SRui Paulo unsigned int freq, const u8 *dst,
264f05cddf9SRui Paulo const u8 *src, const u8 *bssid,
265f05cddf9SRui Paulo const u8 *data, size_t data_len,
266f05cddf9SRui Paulo enum offchannel_send_action_result
267f05cddf9SRui Paulo result),
268f05cddf9SRui Paulo int no_cck)
269f05cddf9SRui Paulo {
270f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Send action frame: freq=%d dst="
271f05cddf9SRui Paulo MACSTR " src=" MACSTR " bssid=" MACSTR " len=%d",
272f05cddf9SRui Paulo freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
273f05cddf9SRui Paulo (int) len);
274f05cddf9SRui Paulo
275f05cddf9SRui Paulo wpa_s->pending_action_tx_status_cb = tx_cb;
276f05cddf9SRui Paulo
277f05cddf9SRui Paulo if (wpa_s->pending_action_tx) {
278f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Dropped pending Action "
279780fb4a2SCy Schubert "frame TX to " MACSTR " (pending_action_tx=%p)",
280780fb4a2SCy Schubert MAC2STR(wpa_s->pending_action_dst),
281780fb4a2SCy Schubert wpa_s->pending_action_tx);
282780fb4a2SCy Schubert wpa_hexdump_buf(MSG_MSGDUMP, "Pending TX frame",
283780fb4a2SCy Schubert wpa_s->pending_action_tx);
284f05cddf9SRui Paulo wpabuf_free(wpa_s->pending_action_tx);
285f05cddf9SRui Paulo }
2865b9c547cSRui Paulo wpa_s->pending_action_tx_done = 0;
287f05cddf9SRui Paulo wpa_s->pending_action_tx = wpabuf_alloc(len);
288f05cddf9SRui Paulo if (wpa_s->pending_action_tx == NULL) {
289f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Failed to allocate Action "
290f05cddf9SRui Paulo "frame TX buffer (len=%llu)",
291f05cddf9SRui Paulo (unsigned long long) len);
292f05cddf9SRui Paulo return -1;
293f05cddf9SRui Paulo }
294f05cddf9SRui Paulo wpabuf_put_data(wpa_s->pending_action_tx, buf, len);
295f05cddf9SRui Paulo os_memcpy(wpa_s->pending_action_src, src, ETH_ALEN);
296f05cddf9SRui Paulo os_memcpy(wpa_s->pending_action_dst, dst, ETH_ALEN);
297f05cddf9SRui Paulo os_memcpy(wpa_s->pending_action_bssid, bssid, ETH_ALEN);
298f05cddf9SRui Paulo wpa_s->pending_action_freq = freq;
299f05cddf9SRui Paulo wpa_s->pending_action_no_cck = no_cck;
300780fb4a2SCy Schubert wpa_printf(MSG_DEBUG,
301780fb4a2SCy Schubert "Off-channel: Stored pending action frame (dst=" MACSTR
302780fb4a2SCy Schubert " pending_action_tx=%p)",
303780fb4a2SCy Schubert MAC2STR(dst), wpa_s->pending_action_tx);
304780fb4a2SCy Schubert wpa_hexdump_buf(MSG_MSGDUMP, "Pending TX frame",
305780fb4a2SCy Schubert wpa_s->pending_action_tx);
306f05cddf9SRui Paulo
307f05cddf9SRui Paulo if (freq != 0 && wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) {
308f05cddf9SRui Paulo struct wpa_supplicant *iface;
3095b9c547cSRui Paulo int ret;
310f05cddf9SRui Paulo
3115b9c547cSRui Paulo iface = wpas_get_tx_interface(wpa_s, src);
312f05cddf9SRui Paulo wpa_s->action_tx_wait_time = wait_time;
31385732ac8SCy Schubert if (wait_time)
31485732ac8SCy Schubert wpa_s->action_tx_wait_time_used = 1;
315f05cddf9SRui Paulo
3165b9c547cSRui Paulo ret = wpa_drv_send_action(
317f05cddf9SRui Paulo iface, wpa_s->pending_action_freq,
318f05cddf9SRui Paulo wait_time, wpa_s->pending_action_dst,
319f05cddf9SRui Paulo wpa_s->pending_action_src, wpa_s->pending_action_bssid,
320f05cddf9SRui Paulo wpabuf_head(wpa_s->pending_action_tx),
321f05cddf9SRui Paulo wpabuf_len(wpa_s->pending_action_tx),
322f05cddf9SRui Paulo wpa_s->pending_action_no_cck);
3235b9c547cSRui Paulo if (ret == 0)
3245b9c547cSRui Paulo wpa_s->pending_action_tx_done = 1;
3255b9c547cSRui Paulo return ret;
326f05cddf9SRui Paulo }
327f05cddf9SRui Paulo
328f05cddf9SRui Paulo if (freq) {
329f05cddf9SRui Paulo struct wpa_supplicant *tx_iface;
330f05cddf9SRui Paulo tx_iface = wpas_get_tx_interface(wpa_s, src);
331f05cddf9SRui Paulo if (tx_iface->assoc_freq == freq) {
332f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Already on "
333f05cddf9SRui Paulo "requested channel (TX interface operating "
334f05cddf9SRui Paulo "channel)");
335f05cddf9SRui Paulo freq = 0;
336f05cddf9SRui Paulo }
337f05cddf9SRui Paulo }
338f05cddf9SRui Paulo
339f05cddf9SRui Paulo if (wpa_s->off_channel_freq == freq || freq == 0) {
340f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Already on requested "
341f05cddf9SRui Paulo "channel; send Action frame immediately");
342f05cddf9SRui Paulo /* TODO: Would there ever be need to extend the current
343f05cddf9SRui Paulo * duration on the channel? */
344f05cddf9SRui Paulo wpa_s->pending_action_without_roc = 1;
345f05cddf9SRui Paulo eloop_cancel_timeout(wpas_send_action_cb, wpa_s, NULL);
346f05cddf9SRui Paulo eloop_register_timeout(0, 0, wpas_send_action_cb, wpa_s, NULL);
347f05cddf9SRui Paulo return 0;
348f05cddf9SRui Paulo }
349f05cddf9SRui Paulo wpa_s->pending_action_without_roc = 0;
350f05cddf9SRui Paulo
351f05cddf9SRui Paulo if (wpa_s->roc_waiting_drv_freq == freq) {
352f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Already waiting for "
353f05cddf9SRui Paulo "driver to get to frequency %u MHz; continue "
354f05cddf9SRui Paulo "waiting to send the Action frame", freq);
355f05cddf9SRui Paulo return 0;
356f05cddf9SRui Paulo }
357f05cddf9SRui Paulo
358f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Schedule Action frame to be "
359f05cddf9SRui Paulo "transmitted once the driver gets to the requested "
360f05cddf9SRui Paulo "channel");
361f05cddf9SRui Paulo if (wait_time > wpa_s->max_remain_on_chan)
362f05cddf9SRui Paulo wait_time = wpa_s->max_remain_on_chan;
3635b9c547cSRui Paulo else if (wait_time == 0)
3645b9c547cSRui Paulo wait_time = 20;
3655b9c547cSRui Paulo #ifdef CONFIG_TESTING_OPTIONS
3665b9c547cSRui Paulo if (wpa_s->extra_roc_dur) {
3675b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "TESTING: Increase ROC duration %u -> %u",
3685b9c547cSRui Paulo wait_time, wait_time + wpa_s->extra_roc_dur);
3695b9c547cSRui Paulo wait_time += wpa_s->extra_roc_dur;
3705b9c547cSRui Paulo }
3715b9c547cSRui Paulo #endif /* CONFIG_TESTING_OPTIONS */
372f05cddf9SRui Paulo if (wpa_drv_remain_on_channel(wpa_s, freq, wait_time) < 0) {
373f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Off-channel: Failed to request driver "
374f05cddf9SRui Paulo "to remain on channel (%u MHz) for Action "
375f05cddf9SRui Paulo "Frame TX", freq);
376f05cddf9SRui Paulo return -1;
377f05cddf9SRui Paulo }
378f05cddf9SRui Paulo wpa_s->off_channel_freq = 0;
379f05cddf9SRui Paulo wpa_s->roc_waiting_drv_freq = freq;
380f05cddf9SRui Paulo
381f05cddf9SRui Paulo return 0;
382f05cddf9SRui Paulo }
383f05cddf9SRui Paulo
384f05cddf9SRui Paulo
385f05cddf9SRui Paulo /**
386f05cddf9SRui Paulo * offchannel_send_send_action_done - Notify completion of Action frame sequence
387f05cddf9SRui Paulo * @wpa_s: Pointer to wpa_supplicant data
388f05cddf9SRui Paulo *
389f05cddf9SRui Paulo * This function can be used to cancel a wait for additional response frames on
390f05cddf9SRui Paulo * the channel that was used with offchannel_send_action().
391f05cddf9SRui Paulo */
offchannel_send_action_done(struct wpa_supplicant * wpa_s)392f05cddf9SRui Paulo void offchannel_send_action_done(struct wpa_supplicant *wpa_s)
393f05cddf9SRui Paulo {
3945b9c547cSRui Paulo wpa_printf(MSG_DEBUG,
3955b9c547cSRui Paulo "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",
3965b9c547cSRui Paulo wpa_s->pending_action_tx,
3975b9c547cSRui Paulo !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX),
3985b9c547cSRui Paulo wpa_s->action_tx_wait_time, wpa_s->off_channel_freq,
3995b9c547cSRui Paulo wpa_s->roc_waiting_drv_freq);
400f05cddf9SRui Paulo wpabuf_free(wpa_s->pending_action_tx);
401f05cddf9SRui Paulo wpa_s->pending_action_tx = NULL;
402f05cddf9SRui Paulo if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX &&
40385732ac8SCy Schubert (wpa_s->action_tx_wait_time || wpa_s->action_tx_wait_time_used))
404f05cddf9SRui Paulo wpa_drv_send_action_cancel_wait(wpa_s);
4055b9c547cSRui Paulo else if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
406f05cddf9SRui Paulo wpa_drv_cancel_remain_on_channel(wpa_s);
407f05cddf9SRui Paulo wpa_s->off_channel_freq = 0;
408f05cddf9SRui Paulo wpa_s->roc_waiting_drv_freq = 0;
409f05cddf9SRui Paulo }
41085732ac8SCy Schubert wpa_s->action_tx_wait_time_used = 0;
411f05cddf9SRui Paulo }
412f05cddf9SRui Paulo
413f05cddf9SRui Paulo
414f05cddf9SRui Paulo /**
415f05cddf9SRui Paulo * offchannel_remain_on_channel_cb - Remain-on-channel callback function
416f05cddf9SRui Paulo * @wpa_s: Pointer to wpa_supplicant data
417f05cddf9SRui Paulo * @freq: Frequency (in MHz) of the selected channel
418f05cddf9SRui Paulo * @duration: Duration of the remain-on-channel operation in milliseconds
419f05cddf9SRui Paulo *
420f05cddf9SRui Paulo * This function is called whenever the driver notifies beginning of a
421f05cddf9SRui Paulo * remain-on-channel operation.
422f05cddf9SRui Paulo */
offchannel_remain_on_channel_cb(struct wpa_supplicant * wpa_s,unsigned int freq,unsigned int duration)423f05cddf9SRui Paulo void offchannel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
424f05cddf9SRui Paulo unsigned int freq, unsigned int duration)
425f05cddf9SRui Paulo {
426f05cddf9SRui Paulo wpa_s->roc_waiting_drv_freq = 0;
427f05cddf9SRui Paulo wpa_s->off_channel_freq = freq;
428f05cddf9SRui Paulo wpas_send_action_cb(wpa_s, NULL);
429f05cddf9SRui Paulo }
430f05cddf9SRui Paulo
431f05cddf9SRui Paulo
432f05cddf9SRui Paulo /**
433f05cddf9SRui Paulo * offchannel_cancel_remain_on_channel_cb - Remain-on-channel stopped callback
434f05cddf9SRui Paulo * @wpa_s: Pointer to wpa_supplicant data
435f05cddf9SRui Paulo * @freq: Frequency (in MHz) of the selected channel
436f05cddf9SRui Paulo *
437f05cddf9SRui Paulo * This function is called whenever the driver notifies termination of a
438f05cddf9SRui Paulo * remain-on-channel operation.
439f05cddf9SRui Paulo */
offchannel_cancel_remain_on_channel_cb(struct wpa_supplicant * wpa_s,unsigned int freq)440f05cddf9SRui Paulo void offchannel_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
441f05cddf9SRui Paulo unsigned int freq)
442f05cddf9SRui Paulo {
443f05cddf9SRui Paulo wpa_s->off_channel_freq = 0;
444f05cddf9SRui Paulo }
445f05cddf9SRui Paulo
446f05cddf9SRui Paulo
447f05cddf9SRui Paulo /**
448f05cddf9SRui Paulo * offchannel_pending_action_tx - Check whether there is a pending Action TX
449f05cddf9SRui Paulo * @wpa_s: Pointer to wpa_supplicant data
450f05cddf9SRui Paulo * Returns: Pointer to pending frame or %NULL if no pending operation
451f05cddf9SRui Paulo *
452f05cddf9SRui Paulo * This function can be used to check whether there is a pending Action frame TX
453f05cddf9SRui Paulo * operation. The returned pointer should be used only for checking whether it
454f05cddf9SRui Paulo * is %NULL (no pending frame) or to print the pointer value in debug
455f05cddf9SRui Paulo * information (i.e., the pointer should not be dereferenced).
456f05cddf9SRui Paulo */
offchannel_pending_action_tx(struct wpa_supplicant * wpa_s)457f05cddf9SRui Paulo const void * offchannel_pending_action_tx(struct wpa_supplicant *wpa_s)
458f05cddf9SRui Paulo {
459f05cddf9SRui Paulo return wpa_s->pending_action_tx;
460f05cddf9SRui Paulo }
461f05cddf9SRui Paulo
462f05cddf9SRui Paulo
463f05cddf9SRui Paulo /**
464f05cddf9SRui Paulo * offchannel_clear_pending_action_tx - Clear pending Action frame TX
465f05cddf9SRui Paulo * @wpa_s: Pointer to wpa_supplicant data
466f05cddf9SRui Paulo */
offchannel_clear_pending_action_tx(struct wpa_supplicant * wpa_s)467f05cddf9SRui Paulo void offchannel_clear_pending_action_tx(struct wpa_supplicant *wpa_s)
468f05cddf9SRui Paulo {
469780fb4a2SCy Schubert wpa_printf(MSG_DEBUG,
470780fb4a2SCy Schubert "Off-channel: Clear pending Action frame TX (pending_action_tx=%p",
471780fb4a2SCy Schubert wpa_s->pending_action_tx);
472f05cddf9SRui Paulo wpabuf_free(wpa_s->pending_action_tx);
473f05cddf9SRui Paulo wpa_s->pending_action_tx = NULL;
474f05cddf9SRui Paulo }
475f05cddf9SRui Paulo
476f05cddf9SRui Paulo
477f05cddf9SRui Paulo /**
478f05cddf9SRui Paulo * offchannel_deinit - Deinit off-channel operations
479f05cddf9SRui Paulo * @wpa_s: Pointer to wpa_supplicant data
480f05cddf9SRui Paulo *
481f05cddf9SRui Paulo * This function is used to free up any allocated resources for off-channel
482f05cddf9SRui Paulo * operations.
483f05cddf9SRui Paulo */
offchannel_deinit(struct wpa_supplicant * wpa_s)484f05cddf9SRui Paulo void offchannel_deinit(struct wpa_supplicant *wpa_s)
485f05cddf9SRui Paulo {
486f05cddf9SRui Paulo offchannel_clear_pending_action_tx(wpa_s);
487f05cddf9SRui Paulo eloop_cancel_timeout(wpas_send_action_cb, wpa_s, NULL);
488f05cddf9SRui Paulo }
489