2 * wpa_supplicant - Off-channel Action frame TX/RX
3 * Copyright (c) 2009-2010, Atheros Communications
4 * Copyright (c) 2011, Qualcomm Atheros
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
19 #include "utils/eloop.h"
20 #include "wpa_supplicant_i.h"
22 #include "offchannel.h"
26 static struct wpa_supplicant
*
27 wpas_get_tx_interface(struct wpa_supplicant
*wpa_s
, const u8
*src
)
29 struct wpa_supplicant
*iface
;
31 if (os_memcmp(src
, wpa_s
->own_addr
, ETH_ALEN
) == 0)
35 * Try to find a group interface that matches with the source address.
37 iface
= wpa_s
->global
->ifaces
;
39 if (os_memcmp(wpa_s
->pending_action_src
,
40 iface
->own_addr
, ETH_ALEN
) == 0)
45 wpa_printf(MSG_DEBUG
, "P2P: Use group interface %s "
46 "instead of interface %s for Action TX",
47 iface
->ifname
, wpa_s
->ifname
);
55 static void wpas_send_action_cb(void *eloop_ctx
, void *timeout_ctx
)
57 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
58 struct wpa_supplicant
*iface
;
62 without_roc
= wpa_s
->pending_action_without_roc
;
63 wpa_s
->pending_action_without_roc
= 0;
64 wpa_printf(MSG_DEBUG
, "Off-channel: Send Action callback "
65 "(without_roc=%d pending_action_tx=%p)",
66 without_roc
, wpa_s
->pending_action_tx
);
68 if (wpa_s
->pending_action_tx
== NULL
)
72 * This call is likely going to be on the P2P device instance if the
73 * driver uses a separate interface for that purpose. However, some
74 * Action frames are actually sent within a P2P Group and when that is
75 * the case, we need to follow power saving (e.g., GO buffering the
76 * frame for a client in PS mode or a client following the advertised
77 * NoA from its GO). To make that easier for the driver, select the
78 * correct group interface here.
80 iface
= wpas_get_tx_interface(wpa_s
, wpa_s
->pending_action_src
);
82 if (wpa_s
->off_channel_freq
!= wpa_s
->pending_action_freq
&&
83 wpa_s
->pending_action_freq
!= 0 &&
84 wpa_s
->pending_action_freq
!= iface
->assoc_freq
) {
85 wpa_printf(MSG_DEBUG
, "Off-channel: Pending Action frame TX "
86 "waiting for another freq=%u (off_channel_freq=%u "
88 wpa_s
->pending_action_freq
,
89 wpa_s
->off_channel_freq
,
91 if (without_roc
&& wpa_s
->off_channel_freq
== 0) {
93 * We may get here if wpas_send_action() found us to be
94 * on the correct channel, but remain-on-channel cancel
95 * event was received before getting here.
97 wpa_printf(MSG_DEBUG
, "Off-channel: Schedule "
98 "remain-on-channel to send Action frame");
99 if (wpa_drv_remain_on_channel(
100 wpa_s
, wpa_s
->pending_action_freq
, 200) <
102 wpa_printf(MSG_DEBUG
, "Off-channel: Failed to "
103 "request driver to remain on "
104 "channel (%u MHz) for Action Frame "
105 "TX", wpa_s
->pending_action_freq
);
107 wpa_s
->off_channel_freq
= 0;
108 wpa_s
->roc_waiting_drv_freq
=
109 wpa_s
->pending_action_freq
;
115 wpa_printf(MSG_DEBUG
, "Off-channel: Sending pending Action frame to "
116 MACSTR
" using interface %s",
117 MAC2STR(wpa_s
->pending_action_dst
), iface
->ifname
);
118 res
= wpa_drv_send_action(iface
, wpa_s
->pending_action_freq
, 0,
119 wpa_s
->pending_action_dst
,
120 wpa_s
->pending_action_src
,
121 wpa_s
->pending_action_bssid
,
122 wpabuf_head(wpa_s
->pending_action_tx
),
123 wpabuf_len(wpa_s
->pending_action_tx
),
124 wpa_s
->pending_action_no_cck
);
126 wpa_printf(MSG_DEBUG
, "Off-channel: Failed to send the "
127 "pending Action frame");
129 * Use fake TX status event to allow state machines to
132 offchannel_send_action_tx_status(
133 wpa_s
, wpa_s
->pending_action_dst
,
134 wpabuf_head(wpa_s
->pending_action_tx
),
135 wpabuf_len(wpa_s
->pending_action_tx
),
136 OFFCHANNEL_SEND_ACTION_FAILED
);
141 void offchannel_send_action_tx_status(
142 struct wpa_supplicant
*wpa_s
, const u8
*dst
, const u8
*data
,
143 size_t data_len
, enum offchannel_send_action_result result
)
145 if (wpa_s
->pending_action_tx
== NULL
) {
146 wpa_printf(MSG_DEBUG
, "Off-channel: Ignore Action TX status - "
147 "no pending operation");
151 if (os_memcmp(dst
, wpa_s
->pending_action_dst
, ETH_ALEN
) != 0) {
152 wpa_printf(MSG_DEBUG
, "Off-channel: Ignore Action TX status - "
153 "unknown destination address");
157 wpabuf_free(wpa_s
->pending_action_tx
);
158 wpa_s
->pending_action_tx
= NULL
;
160 wpa_printf(MSG_DEBUG
, "Off-channel: TX status result=%d cb=%p",
161 result
, wpa_s
->pending_action_tx_status_cb
);
163 if (wpa_s
->pending_action_tx_status_cb
) {
164 wpa_s
->pending_action_tx_status_cb(
165 wpa_s
, wpa_s
->pending_action_freq
,
166 wpa_s
->pending_action_dst
, wpa_s
->pending_action_src
,
167 wpa_s
->pending_action_bssid
,
168 data
, data_len
, result
);
173 int offchannel_send_action(struct wpa_supplicant
*wpa_s
, unsigned int freq
,
174 const u8
*dst
, const u8
*src
, const u8
*bssid
,
175 const u8
*buf
, size_t len
, unsigned int wait_time
,
176 void (*tx_cb
)(struct wpa_supplicant
*wpa_s
,
177 unsigned int freq
, const u8
*dst
,
178 const u8
*src
, const u8
*bssid
,
179 const u8
*data
, size_t data_len
,
180 enum offchannel_send_action_result
184 wpa_printf(MSG_DEBUG
, "Off-channel: Send action frame: freq=%d dst="
185 MACSTR
" src=" MACSTR
" bssid=" MACSTR
" len=%d",
186 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
189 wpa_s
->pending_action_tx_status_cb
= tx_cb
;
191 if (wpa_s
->pending_action_tx
) {
192 wpa_printf(MSG_DEBUG
, "Off-channel: Dropped pending Action "
193 "frame TX to " MACSTR
,
194 MAC2STR(wpa_s
->pending_action_dst
));
195 wpabuf_free(wpa_s
->pending_action_tx
);
197 wpa_s
->pending_action_tx
= wpabuf_alloc(len
);
198 if (wpa_s
->pending_action_tx
== NULL
) {
199 wpa_printf(MSG_DEBUG
, "Off-channel: Failed to allocate Action "
200 "frame TX buffer (len=%llu)",
201 (unsigned long long) len
);
204 wpabuf_put_data(wpa_s
->pending_action_tx
, buf
, len
);
205 os_memcpy(wpa_s
->pending_action_src
, src
, ETH_ALEN
);
206 os_memcpy(wpa_s
->pending_action_dst
, dst
, ETH_ALEN
);
207 os_memcpy(wpa_s
->pending_action_bssid
, bssid
, ETH_ALEN
);
208 wpa_s
->pending_action_freq
= freq
;
209 wpa_s
->pending_action_no_cck
= no_cck
;
211 if (freq
!= 0 && wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) {
212 struct wpa_supplicant
*iface
;
214 iface
= wpas_get_tx_interface(wpa_s
,
215 wpa_s
->pending_action_src
);
216 wpa_s
->action_tx_wait_time
= wait_time
;
218 return wpa_drv_send_action(
219 iface
, wpa_s
->pending_action_freq
,
220 wait_time
, wpa_s
->pending_action_dst
,
221 wpa_s
->pending_action_src
, wpa_s
->pending_action_bssid
,
222 wpabuf_head(wpa_s
->pending_action_tx
),
223 wpabuf_len(wpa_s
->pending_action_tx
),
224 wpa_s
->pending_action_no_cck
);
228 struct wpa_supplicant
*tx_iface
;
229 tx_iface
= wpas_get_tx_interface(wpa_s
, src
);
230 if (tx_iface
->assoc_freq
== freq
) {
231 wpa_printf(MSG_DEBUG
, "Off-channel: Already on "
232 "requested channel (TX interface operating "
238 if (wpa_s
->off_channel_freq
== freq
|| freq
== 0) {
239 wpa_printf(MSG_DEBUG
, "Off-channel: Already on requested "
240 "channel; send Action frame immediately");
241 /* TODO: Would there ever be need to extend the current
242 * duration on the channel? */
243 wpa_s
->pending_action_without_roc
= 1;
244 eloop_cancel_timeout(wpas_send_action_cb
, wpa_s
, NULL
);
245 eloop_register_timeout(0, 0, wpas_send_action_cb
, wpa_s
, NULL
);
248 wpa_s
->pending_action_without_roc
= 0;
250 if (wpa_s
->roc_waiting_drv_freq
== freq
) {
251 wpa_printf(MSG_DEBUG
, "Off-channel: Already waiting for "
252 "driver to get to frequency %u MHz; continue "
253 "waiting to send the Action frame", freq
);
257 wpa_printf(MSG_DEBUG
, "Off-channel: Schedule Action frame to be "
258 "transmitted once the driver gets to the requested "
260 if (wait_time
> wpa_s
->max_remain_on_chan
)
261 wait_time
= wpa_s
->max_remain_on_chan
;
262 if (wpa_drv_remain_on_channel(wpa_s
, freq
, wait_time
) < 0) {
263 wpa_printf(MSG_DEBUG
, "Off-channel: Failed to request driver "
264 "to remain on channel (%u MHz) for Action "
268 wpa_s
->off_channel_freq
= 0;
269 wpa_s
->roc_waiting_drv_freq
= freq
;
275 void offchannel_send_action_done(struct wpa_supplicant
*wpa_s
)
277 wpa_printf(MSG_DEBUG
, "Off-channel: Action frame sequence done "
279 wpabuf_free(wpa_s
->pending_action_tx
);
280 wpa_s
->pending_action_tx
= NULL
;
281 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
&&
282 wpa_s
->action_tx_wait_time
)
283 wpa_drv_send_action_cancel_wait(wpa_s
);
285 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
286 wpa_drv_cancel_remain_on_channel(wpa_s
);
287 wpa_s
->off_channel_freq
= 0;
288 wpa_s
->roc_waiting_drv_freq
= 0;
293 void offchannel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
294 unsigned int freq
, unsigned int duration
)
296 wpa_s
->roc_waiting_drv_freq
= 0;
297 wpa_s
->off_channel_freq
= freq
;
298 wpas_send_action_cb(wpa_s
, NULL
);
302 void offchannel_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
305 wpa_s
->off_channel_freq
= 0;
309 void offchannel_deinit(struct wpa_supplicant
*wpa_s
)
311 wpabuf_free(wpa_s
->pending_action_tx
);
312 wpa_s
->pending_action_tx
= NULL
;
313 eloop_cancel_timeout(wpas_send_action_cb
, wpa_s
, NULL
);