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