2 * wpa_supplicant - Radio Measurements
3 * Copyright (c) 2003-2016, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_common.h"
14 #include "wpa_supplicant_i.h"
18 #include "p2p_supplicant.h"
21 static void wpas_rrm_neighbor_rep_timeout_handler(void *data
, void *user_ctx
)
23 struct rrm_data
*rrm
= data
;
25 if (!rrm
->notify_neighbor_rep
) {
27 "RRM: Unexpected neighbor report timeout");
31 wpa_printf(MSG_DEBUG
, "RRM: Notifying neighbor report - NONE");
32 rrm
->notify_neighbor_rep(rrm
->neighbor_rep_cb_ctx
, NULL
);
34 rrm
->notify_neighbor_rep
= NULL
;
35 rrm
->neighbor_rep_cb_ctx
= NULL
;
40 * wpas_rrm_reset - Clear and reset all RRM data in wpa_supplicant
41 * @wpa_s: Pointer to wpa_supplicant
43 void wpas_rrm_reset(struct wpa_supplicant
*wpa_s
)
45 wpa_s
->rrm
.rrm_used
= 0;
47 eloop_cancel_timeout(wpas_rrm_neighbor_rep_timeout_handler
, &wpa_s
->rrm
,
49 if (wpa_s
->rrm
.notify_neighbor_rep
)
50 wpas_rrm_neighbor_rep_timeout_handler(&wpa_s
->rrm
, NULL
);
51 wpa_s
->rrm
.next_neighbor_rep_token
= 1;
52 wpas_clear_beacon_rep_data(wpa_s
);
57 * wpas_rrm_process_neighbor_rep - Handle incoming neighbor report
58 * @wpa_s: Pointer to wpa_supplicant
59 * @report: Neighbor report buffer, prefixed by a 1-byte dialog token
60 * @report_len: Length of neighbor report buffer
62 void wpas_rrm_process_neighbor_rep(struct wpa_supplicant
*wpa_s
,
63 const u8
*report
, size_t report_len
)
65 struct wpabuf
*neighbor_rep
;
67 wpa_hexdump(MSG_DEBUG
, "RRM: New Neighbor Report", report
, report_len
);
71 if (report
[0] != wpa_s
->rrm
.next_neighbor_rep_token
- 1) {
73 "RRM: Discarding neighbor report with token %d (expected %d)",
74 report
[0], wpa_s
->rrm
.next_neighbor_rep_token
- 1);
78 eloop_cancel_timeout(wpas_rrm_neighbor_rep_timeout_handler
, &wpa_s
->rrm
,
81 if (!wpa_s
->rrm
.notify_neighbor_rep
) {
82 wpa_printf(MSG_ERROR
, "RRM: Unexpected neighbor report");
86 /* skipping the first byte, which is only an id (dialog token) */
87 neighbor_rep
= wpabuf_alloc(report_len
- 1);
89 wpas_rrm_neighbor_rep_timeout_handler(&wpa_s
->rrm
, NULL
);
92 wpabuf_put_data(neighbor_rep
, report
+ 1, report_len
- 1);
93 wpa_printf(MSG_DEBUG
, "RRM: Notifying neighbor report (token = %d)",
95 wpa_s
->rrm
.notify_neighbor_rep(wpa_s
->rrm
.neighbor_rep_cb_ctx
,
97 wpa_s
->rrm
.notify_neighbor_rep
= NULL
;
98 wpa_s
->rrm
.neighbor_rep_cb_ctx
= NULL
;
102 #if defined(__CYGWIN__) || defined(CONFIG_NATIVE_WINDOWS)
103 /* Workaround different, undefined for Windows, error codes used here */
105 #define EOPNOTSUPP -1
109 /* Measurement Request element + Location Subject + Maximum Age subelement */
110 #define MEASURE_REQUEST_LCI_LEN (3 + 1 + 4)
111 /* Measurement Request element + Location Civic Request */
112 #define MEASURE_REQUEST_CIVIC_LEN (3 + 5)
116 * wpas_rrm_send_neighbor_rep_request - Request a neighbor report from our AP
117 * @wpa_s: Pointer to wpa_supplicant
118 * @ssid: if not null, this is sent in the request. Otherwise, no SSID IE
119 * is sent in the request.
120 * @lci: if set, neighbor request will include LCI request
121 * @civic: if set, neighbor request will include civic location request
122 * @cb: Callback function to be called once the requested report arrives, or
123 * timed out after RRM_NEIGHBOR_REPORT_TIMEOUT seconds.
124 * In the former case, 'neighbor_rep' is a newly allocated wpabuf, and it's
125 * the requester's responsibility to free it.
126 * In the latter case NULL will be sent in 'neighbor_rep'.
127 * @cb_ctx: Context value to send the callback function
128 * Returns: 0 in case of success, negative error code otherwise
130 * In case there is a previous request which has not been answered yet, the
131 * new request fails. The caller may retry after RRM_NEIGHBOR_REPORT_TIMEOUT.
132 * Request must contain a callback function.
134 int wpas_rrm_send_neighbor_rep_request(struct wpa_supplicant
*wpa_s
,
135 const struct wpa_ssid_value
*ssid
,
137 void (*cb
)(void *ctx
,
138 struct wpabuf
*neighbor_rep
),
144 if (wpa_s
->wpa_state
!= WPA_COMPLETED
|| wpa_s
->current_ssid
== NULL
) {
145 wpa_printf(MSG_DEBUG
, "RRM: No connection, no RRM.");
149 if (!wpa_s
->rrm
.rrm_used
) {
150 wpa_printf(MSG_DEBUG
, "RRM: No RRM in current connection.");
154 rrm_ie
= wpa_bss_get_ie(wpa_s
->current_bss
,
155 WLAN_EID_RRM_ENABLED_CAPABILITIES
);
156 if (!rrm_ie
|| !(wpa_s
->current_bss
->caps
& IEEE80211_CAP_RRM
) ||
157 !(rrm_ie
[2] & WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
158 wpa_printf(MSG_DEBUG
,
159 "RRM: No network support for Neighbor Report.");
163 /* Refuse if there's a live request */
164 if (wpa_s
->rrm
.notify_neighbor_rep
) {
165 wpa_printf(MSG_DEBUG
,
166 "RRM: Currently handling previous Neighbor Report.");
170 /* 3 = action category + action code + dialog token */
171 buf
= wpabuf_alloc(3 + (ssid
? 2 + ssid
->ssid_len
: 0) +
172 (lci
? 2 + MEASURE_REQUEST_LCI_LEN
: 0) +
173 (civic
? 2 + MEASURE_REQUEST_CIVIC_LEN
: 0));
175 wpa_printf(MSG_DEBUG
,
176 "RRM: Failed to allocate Neighbor Report Request");
180 wpa_printf(MSG_DEBUG
, "RRM: Neighbor report request (for %s), token=%d",
181 (ssid
? wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
) : ""),
182 wpa_s
->rrm
.next_neighbor_rep_token
);
184 wpabuf_put_u8(buf
, WLAN_ACTION_RADIO_MEASUREMENT
);
185 wpabuf_put_u8(buf
, WLAN_RRM_NEIGHBOR_REPORT_REQUEST
);
186 wpabuf_put_u8(buf
, wpa_s
->rrm
.next_neighbor_rep_token
);
188 wpabuf_put_u8(buf
, WLAN_EID_SSID
);
189 wpabuf_put_u8(buf
, ssid
->ssid_len
);
190 wpabuf_put_data(buf
, ssid
->ssid
, ssid
->ssid_len
);
194 /* IEEE P802.11-REVmc/D5.0 9.4.2.21 */
195 wpabuf_put_u8(buf
, WLAN_EID_MEASURE_REQUEST
);
196 wpabuf_put_u8(buf
, MEASURE_REQUEST_LCI_LEN
);
199 * Measurement token; nonzero number that is unique among the
200 * Measurement Request elements in a particular frame.
202 wpabuf_put_u8(buf
, 1); /* Measurement Token */
205 * Parallel, Enable, Request, and Report bits are 0, Duration is
208 wpabuf_put_u8(buf
, 0); /* Measurement Request Mode */
209 wpabuf_put_u8(buf
, MEASURE_TYPE_LCI
); /* Measurement Type */
211 /* IEEE P802.11-REVmc/D5.0 9.4.2.21.10 - LCI request */
212 /* Location Subject */
213 wpabuf_put_u8(buf
, LOCATION_SUBJECT_REMOTE
);
215 /* Optional Subelements */
217 * IEEE P802.11-REVmc/D5.0 Figure 9-170
218 * The Maximum Age subelement is required, otherwise the AP can
219 * send only data that was determined after receiving the
220 * request. Setting it here to unlimited age.
222 wpabuf_put_u8(buf
, LCI_REQ_SUBELEM_MAX_AGE
);
223 wpabuf_put_u8(buf
, 2);
224 wpabuf_put_le16(buf
, 0xffff);
228 /* IEEE P802.11-REVmc/D5.0 9.4.2.21 */
229 wpabuf_put_u8(buf
, WLAN_EID_MEASURE_REQUEST
);
230 wpabuf_put_u8(buf
, MEASURE_REQUEST_CIVIC_LEN
);
233 * Measurement token; nonzero number that is unique among the
234 * Measurement Request elements in a particular frame.
236 wpabuf_put_u8(buf
, 2); /* Measurement Token */
239 * Parallel, Enable, Request, and Report bits are 0, Duration is
242 wpabuf_put_u8(buf
, 0); /* Measurement Request Mode */
243 /* Measurement Type */
244 wpabuf_put_u8(buf
, MEASURE_TYPE_LOCATION_CIVIC
);
246 /* IEEE P802.11-REVmc/D5.0 9.4.2.21.14:
247 * Location Civic request */
248 /* Location Subject */
249 wpabuf_put_u8(buf
, LOCATION_SUBJECT_REMOTE
);
250 wpabuf_put_u8(buf
, 0); /* Civic Location Type: IETF RFC 4776 */
251 /* Location Service Interval Units: Seconds */
252 wpabuf_put_u8(buf
, 0);
253 /* Location Service Interval: 0 - Only one report is requested
255 wpabuf_put_le16(buf
, 0);
256 /* No optional subelements */
259 wpa_s
->rrm
.next_neighbor_rep_token
++;
261 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
262 wpa_s
->own_addr
, wpa_s
->bssid
,
263 wpabuf_head(buf
), wpabuf_len(buf
), 0) < 0) {
264 wpa_printf(MSG_DEBUG
,
265 "RRM: Failed to send Neighbor Report Request");
270 wpa_s
->rrm
.neighbor_rep_cb_ctx
= cb_ctx
;
271 wpa_s
->rrm
.notify_neighbor_rep
= cb
;
272 eloop_register_timeout(RRM_NEIGHBOR_REPORT_TIMEOUT
, 0,
273 wpas_rrm_neighbor_rep_timeout_handler
,
281 static int wpas_rrm_report_elem(struct wpabuf
**buf
, u8 token
, u8 mode
, u8 type
,
282 const u8
*data
, size_t data_len
)
284 if (wpabuf_resize(buf
, 5 + data_len
))
287 wpabuf_put_u8(*buf
, WLAN_EID_MEASURE_REPORT
);
288 wpabuf_put_u8(*buf
, 3 + data_len
);
289 wpabuf_put_u8(*buf
, token
);
290 wpabuf_put_u8(*buf
, mode
);
291 wpabuf_put_u8(*buf
, type
);
294 wpabuf_put_data(*buf
, data
, data_len
);
301 wpas_rrm_build_lci_report(struct wpa_supplicant
*wpa_s
,
302 const struct rrm_measurement_request_element
*req
,
307 struct os_reltime t
, diff
;
308 unsigned long diff_l
;
310 const u8
*request
= req
->variable
;
311 size_t len
= req
->len
- 3;
319 subject
= *request
++;
322 wpa_printf(MSG_DEBUG
, "Measurement request location subject=%u",
325 if (subject
!= LOCATION_SUBJECT_REMOTE
) {
327 "Not building LCI report - bad location subject");
331 /* Subelements are formatted exactly like elements */
332 wpa_hexdump(MSG_DEBUG
, "LCI request subelements", request
, len
);
333 subelem
= get_ie(request
, len
, LCI_REQ_SUBELEM_MAX_AGE
);
334 if (subelem
&& subelem
[1] == 2)
335 max_age
= WPA_GET_LE16(subelem
+ 2);
337 if (os_get_reltime(&t
))
340 os_reltime_sub(&t
, &wpa_s
->lci_time
, &diff
);
341 /* LCI age is calculated in 10th of a second units. */
342 diff_l
= diff
.sec
* 10 + diff
.usec
/ 100000;
344 if (max_age
!= 0xffff && max_age
< diff_l
)
347 if (wpas_rrm_report_elem(buf
, req
->token
,
348 MEASUREMENT_REPORT_MODE_ACCEPT
, req
->type
,
349 wpabuf_head_u8(wpa_s
->lci
),
350 wpabuf_len(wpa_s
->lci
)) < 0) {
351 wpa_printf(MSG_DEBUG
, "Failed to add LCI report element");
358 if (!is_multicast_ether_addr(wpa_s
->rrm
.dst_addr
) &&
359 wpas_rrm_report_elem(buf
, req
->token
,
360 MEASUREMENT_REPORT_MODE_REJECT_INCAPABLE
,
361 req
->type
, NULL
, 0) < 0) {
362 wpa_printf(MSG_DEBUG
, "RRM: Failed to add report element");
370 static void wpas_rrm_send_msr_report_mpdu(struct wpa_supplicant
*wpa_s
,
371 const u8
*data
, size_t len
)
373 struct wpabuf
*report
= wpabuf_alloc(len
+ 3);
378 wpabuf_put_u8(report
, WLAN_ACTION_RADIO_MEASUREMENT
);
379 wpabuf_put_u8(report
, WLAN_RRM_RADIO_MEASUREMENT_REPORT
);
380 wpabuf_put_u8(report
, wpa_s
->rrm
.token
);
382 wpabuf_put_data(report
, data
, len
);
384 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
385 wpa_s
->own_addr
, wpa_s
->bssid
,
386 wpabuf_head(report
), wpabuf_len(report
), 0)) {
387 wpa_printf(MSG_ERROR
,
388 "RRM: Radio measurement report failed: Sending Action frame failed");
395 static int wpas_rrm_beacon_rep_update_last_frame(u8
*pos
, size_t len
)
397 struct rrm_measurement_report_element
*msr_rep
;
401 while (end
- pos
>= (int) sizeof(*msr_rep
)) {
402 msr_rep
= (struct rrm_measurement_report_element
*) pos
;
403 msr_rep_end
= pos
+ msr_rep
->len
+ 2;
405 if (msr_rep
->eid
!= WLAN_EID_MEASURE_REPORT
||
407 /* Should not happen. This indicates a bug. */
408 wpa_printf(MSG_ERROR
,
409 "RRM: non-measurement report element in measurement report frame");
413 if (msr_rep
->type
== MEASURE_TYPE_BEACON
) {
414 struct rrm_measurement_beacon_report
*rep
;
417 rep
= (struct rrm_measurement_beacon_report
*)
419 subelem
= rep
->variable
;
420 while (subelem
+ 2 < msr_rep_end
&&
422 WLAN_BEACON_REPORT_SUBELEM_LAST_INDICATION
)
423 subelem
+= 2 + subelem
[1];
425 if (subelem
+ 2 < msr_rep_end
&&
427 WLAN_BEACON_REPORT_SUBELEM_LAST_INDICATION
&&
430 BEACON_REPORT_LAST_INDICATION_SUBELEM_LEN
<= end
)
441 static void wpas_rrm_send_msr_report(struct wpa_supplicant
*wpa_s
,
444 int len
= wpabuf_len(buf
);
445 u8
*pos
= wpabuf_mhead_u8(buf
), *next
= pos
;
447 #define MPDU_REPORT_LEN (int) (IEEE80211_MAX_MMPDU_SIZE - IEEE80211_HDRLEN - 3)
450 int send_len
= (len
> MPDU_REPORT_LEN
) ? next
- pos
: len
;
453 wpas_rrm_beacon_rep_update_last_frame(pos
, len
);
455 if (send_len
== len
||
456 (send_len
+ next
[1] + 2) > MPDU_REPORT_LEN
) {
457 wpas_rrm_send_msr_report_mpdu(wpa_s
, pos
, send_len
);
465 #undef MPDU_REPORT_LEN
469 static int wpas_add_channel(u8 op_class
, u8 chan
, u8 num_primary_channels
,
474 for (i
= 0; i
< num_primary_channels
; i
++) {
475 u8 primary_chan
= chan
- (2 * num_primary_channels
- 2) + i
* 4;
477 freqs
[i
] = ieee80211_chan_to_freq(NULL
, op_class
, primary_chan
);
478 /* ieee80211_chan_to_freq() is not really meant for this
479 * conversion of 20 MHz primary channel numbers for wider VHT
480 * channels, so handle those as special cases here for now. */
482 (op_class
== 128 || op_class
== 129 || op_class
== 130))
483 freqs
[i
] = 5000 + 5 * primary_chan
;
485 wpa_printf(MSG_DEBUG
,
486 "Beacon Report: Invalid channel %u",
496 static int * wpas_add_channels(const struct oper_class_map
*op
,
497 struct hostapd_hw_modes
*mode
, int active
,
498 const u8
*channels
, const u8 size
)
500 int *freqs
, *next_freq
;
501 u8 num_primary_channels
, i
;
504 num_chans
= channels
? size
:
505 (op
->max_chan
- op
->min_chan
) / op
->inc
+ 1;
507 if (op
->bw
== BW80
|| op
->bw
== BW80P80
)
508 num_primary_channels
= 4;
509 else if (op
->bw
== BW160
)
510 num_primary_channels
= 8;
512 num_primary_channels
= 1;
514 /* one extra place for the zero-terminator */
515 freqs
= os_calloc(num_chans
* num_primary_channels
+ 1, sizeof(*freqs
));
517 wpa_printf(MSG_ERROR
,
518 "Beacon Report: Failed to allocate freqs array");
523 for (i
= 0; i
< num_chans
; i
++) {
524 u8 chan
= channels
? channels
[i
] : op
->min_chan
+ i
* op
->inc
;
525 enum chan_allowed res
= verify_channel(mode
, chan
, op
->bw
);
527 if (res
== NOT_ALLOWED
|| (res
== NO_IR
&& active
))
530 if (wpas_add_channel(op
->op_class
, chan
, num_primary_channels
,
536 next_freq
+= num_primary_channels
;
548 static int * wpas_op_class_freqs(const struct oper_class_map
*op
,
549 struct hostapd_hw_modes
*mode
, int active
)
551 u8 channels_80mhz
[] = { 42, 58, 106, 122, 138, 155 };
552 u8 channels_160mhz
[] = { 50, 114 };
555 * When adding all channels in the operating class, 80 + 80 MHz
556 * operating classes are like 80 MHz channels because we add all valid
559 if (op
->bw
== BW80
|| op
->bw
== BW80P80
)
560 return wpas_add_channels(op
, mode
, active
, channels_80mhz
,
561 ARRAY_SIZE(channels_80mhz
));
564 return wpas_add_channels(op
, mode
, active
, channels_160mhz
,
565 ARRAY_SIZE(channels_160mhz
));
567 return wpas_add_channels(op
, mode
, active
, NULL
, 0);
571 static int * wpas_channel_report_freqs(struct wpa_supplicant
*wpa_s
, int active
,
572 const char *country
, const u8
*subelems
,
575 int *freqs
= NULL
, *new_freqs
;
576 const u8
*end
= subelems
+ len
;
578 while (end
- subelems
> 2) {
579 const struct oper_class_map
*op
;
580 const u8
*ap_chan_elem
, *pos
;
582 struct hostapd_hw_modes
*mode
;
584 ap_chan_elem
= get_ie(subelems
, end
- subelems
,
585 WLAN_BEACON_REQUEST_SUBELEM_AP_CHANNEL
);
588 pos
= ap_chan_elem
+ 2;
589 left
= ap_chan_elem
[1];
592 subelems
= ap_chan_elem
+ 2 + left
;
594 op
= get_oper_class(country
, *pos
);
596 wpa_printf(MSG_DEBUG
,
597 "Beacon request: unknown operating class in AP Channel Report subelement %u",
604 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
, op
->mode
);
609 * For 80 + 80 MHz operating classes, this AP Channel Report
610 * element should be followed by another element specifying
611 * the second 80 MHz channel. For now just add this 80 MHz
612 * channel, the second 80 MHz channel will be added when the
613 * next element is parsed.
614 * TODO: Verify that this AP Channel Report element is followed
615 * by a corresponding AP Channel Report element as specified in
616 * IEEE Std 802.11-2016, 11.11.9.1.
618 new_freqs
= wpas_add_channels(op
, mode
, active
, pos
, left
);
620 int_array_concat(&freqs
, new_freqs
);
632 static int * wpas_beacon_request_freqs(struct wpa_supplicant
*wpa_s
,
633 u8 op_class
, u8 chan
, int active
,
634 const u8
*subelems
, size_t len
)
636 int *freqs
= NULL
, *ext_freqs
= NULL
;
637 struct hostapd_hw_modes
*mode
;
638 const char *country
= NULL
;
639 const struct oper_class_map
*op
;
642 if (!wpa_s
->current_bss
)
644 elem
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_COUNTRY
);
645 if (elem
&& elem
[1] >= 2)
646 country
= (const char *) (elem
+ 2);
648 op
= get_oper_class(country
, op_class
);
650 wpa_printf(MSG_DEBUG
,
651 "Beacon request: invalid operating class %d",
656 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
, op
->mode
);
662 freqs
= wpas_op_class_freqs(op
, mode
, active
);
667 /* freqs will be added from AP channel subelements */
670 freqs
= wpas_add_channels(op
, mode
, active
, &chan
, 1);
676 ext_freqs
= wpas_channel_report_freqs(wpa_s
, active
, country
, subelems
,
679 int_array_concat(&freqs
, ext_freqs
);
681 int_array_sort_unique(freqs
);
688 static int wpas_get_op_chan_phy(int freq
, const u8
*ies
, size_t ies_len
,
689 u8
*op_class
, u8
*chan
, u8
*phy_type
)
692 int sec_chan
= 0, vht
= 0;
693 struct ieee80211_ht_operation
*ht_oper
= NULL
;
694 struct ieee80211_vht_operation
*vht_oper
= NULL
;
697 ie
= get_ie(ies
, ies_len
, WLAN_EID_HT_OPERATION
);
698 if (ie
&& ie
[1] >= sizeof(struct ieee80211_ht_operation
)) {
701 ht_oper
= (struct ieee80211_ht_operation
*) (ie
+ 2);
702 sec_chan_offset
= ht_oper
->ht_param
&
703 HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK
;
704 if (sec_chan_offset
== HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE
)
706 else if (sec_chan_offset
==
707 HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW
)
711 ie
= get_ie(ies
, ies_len
, WLAN_EID_VHT_OPERATION
);
712 if (ie
&& ie
[1] >= sizeof(struct ieee80211_vht_operation
)) {
713 vht_oper
= (struct ieee80211_vht_operation
*) (ie
+ 2);
715 switch (vht_oper
->vht_op_info_chwidth
) {
717 seg0
= vht_oper
->vht_op_info_chan_center_freq_seg0_idx
;
718 seg1
= vht_oper
->vht_op_info_chan_center_freq_seg1_idx
;
719 if (seg1
&& abs(seg1
- seg0
) == 8)
720 vht
= VHT_CHANWIDTH_160MHZ
;
722 vht
= VHT_CHANWIDTH_80P80MHZ
;
724 vht
= VHT_CHANWIDTH_80MHZ
;
727 vht
= VHT_CHANWIDTH_160MHZ
;
730 vht
= VHT_CHANWIDTH_80P80MHZ
;
733 vht
= VHT_CHANWIDTH_USE_HT
;
738 if (ieee80211_freq_to_channel_ext(freq
, sec_chan
, vht
, op_class
,
739 chan
) == NUM_HOSTAPD_MODES
) {
740 wpa_printf(MSG_DEBUG
,
741 "Cannot determine operating class and channel");
745 *phy_type
= ieee80211_get_phy_type(freq
, ht_oper
!= NULL
,
747 if (*phy_type
== PHY_TYPE_UNSPECIFIED
) {
748 wpa_printf(MSG_DEBUG
, "Cannot determine phy type");
756 static int wpas_beacon_rep_add_frame_body(struct bitfield
*eids
,
757 enum beacon_report_detail detail
,
758 struct wpa_bss
*bss
, u8
*buf
,
759 size_t buf_len
, u8
**ies_buf
,
760 size_t *ie_len
, int add_fixed
)
763 size_t ies_len
= *ie_len
;
767 rem_len
= 255 - sizeof(struct rrm_measurement_beacon_report
) -
768 sizeof(struct rrm_measurement_report_element
) - 2 -
769 REPORTED_FRAME_BODY_SUBELEM_LEN
;
771 if (detail
> BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS
) {
772 wpa_printf(MSG_DEBUG
,
773 "Beacon Request: Invalid reporting detail: %d",
778 if (detail
== BEACON_REPORT_DETAIL_NONE
)
782 * Minimal frame body subelement size: EID(1) + length(1) + TSF(8) +
783 * beacon interval(2) + capabilities(2) = 14 bytes
785 if (add_fixed
&& buf_len
< 14)
788 *pos
++ = WLAN_BEACON_REPORT_SUBELEM_FRAME_BODY
;
789 /* The length will be filled later */
793 WPA_PUT_LE64(pos
, bss
->tsf
);
794 pos
+= sizeof(bss
->tsf
);
795 WPA_PUT_LE16(pos
, bss
->beacon_int
);
797 WPA_PUT_LE16(pos
, bss
->caps
);
801 rem_len
-= pos
- buf
;
804 * According to IEEE Std 802.11-2016, 9.4.2.22.7, if the reported frame
805 * body subelement causes the element to exceed the maximum element
806 * size, the subelement is truncated so that the last IE is a complete
807 * IE. So even when required to report all IEs, add elements one after
808 * the other and stop once there is no more room in the measurement
811 while (ies_len
> 2 && 2U + ies
[1] <= ies_len
&& rem_len
> 0) {
812 if (detail
== BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS
||
813 (eids
&& bitfield_is_set(eids
, ies
[0]))) {
816 if (2 + elen
> buf
+ buf_len
- pos
||
822 os_memcpy(pos
, ies
+ 2, elen
);
827 ies_len
-= 2 + ies
[1];
834 /* Now the length is known */
835 buf
[1] = pos
- buf
- 2;
840 static int wpas_add_beacon_rep_elem(struct beacon_rep_data
*data
,
842 struct wpabuf
**wpa_buf
,
843 struct rrm_measurement_beacon_report
*rep
,
844 u8
**ie
, size_t *ie_len
, u8 idx
)
848 u32 subelems_len
= REPORTED_FRAME_BODY_SUBELEM_LEN
+
849 (data
->last_indication
?
850 BEACON_REPORT_LAST_INDICATION_SUBELEM_LEN
: 0);
852 /* Maximum element length: Beacon Report element + Reported Frame Body
853 * subelement + all IEs of the reported Beacon frame + Reported Frame
854 * Body Fragment ID subelement */
855 buf
= os_malloc(sizeof(*rep
) + 14 + *ie_len
+ subelems_len
);
859 os_memcpy(buf
, rep
, sizeof(*rep
));
861 ret
= wpas_beacon_rep_add_frame_body(data
->eids
, data
->report_detail
,
862 bss
, buf
+ sizeof(*rep
),
863 14 + *ie_len
, ie
, ie_len
,
868 pos
= buf
+ ret
+ sizeof(*rep
);
869 pos
[0] = WLAN_BEACON_REPORT_SUBELEM_FRAME_BODY_FRAGMENT_ID
;
873 * Only one Beacon Report Measurement is supported at a time, so
874 * the Beacon Report ID can always be set to 1.
878 /* Fragment ID Number (bits 0..6) and More Frame Body Fragments (bit 7)
881 if (data
->report_detail
!= BEACON_REPORT_DETAIL_NONE
&& *ie_len
)
882 pos
[3] |= REPORTED_FRAME_BODY_MORE_FRAGMENTS
;
884 pos
[3] &= ~REPORTED_FRAME_BODY_MORE_FRAGMENTS
;
886 pos
+= REPORTED_FRAME_BODY_SUBELEM_LEN
;
888 if (data
->last_indication
) {
889 pos
[0] = WLAN_BEACON_REPORT_SUBELEM_LAST_INDICATION
;
892 /* This field will be updated later if this is the last frame */
896 ret
= wpas_rrm_report_elem(wpa_buf
, data
->token
,
897 MEASUREMENT_REPORT_MODE_ACCEPT
,
898 MEASURE_TYPE_BEACON
, buf
,
899 ret
+ sizeof(*rep
) + subelems_len
);
906 static int wpas_add_beacon_rep(struct wpa_supplicant
*wpa_s
,
907 struct wpabuf
**wpa_buf
, struct wpa_bss
*bss
,
908 u64 start
, u64 parent_tsf
)
910 struct beacon_rep_data
*data
= &wpa_s
->beacon_rep_data
;
911 u8
*ies
= (u8
*) (bss
+ 1);
913 size_t ies_len
= bss
->ie_len
? bss
->ie_len
: bss
->beacon_ie_len
;
914 struct rrm_measurement_beacon_report rep
;
917 if (os_memcmp(data
->bssid
, broadcast_ether_addr
, ETH_ALEN
) != 0 &&
918 os_memcmp(data
->bssid
, bss
->bssid
, ETH_ALEN
) != 0)
921 if (data
->ssid_len
&&
922 (data
->ssid_len
!= bss
->ssid_len
||
923 os_memcmp(data
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0))
926 if (wpas_get_op_chan_phy(bss
->freq
, ies
, ies_len
, &rep
.op_class
,
927 &rep
.channel
, &rep
.report_info
) < 0)
930 rep
.start_time
= host_to_le64(start
);
931 rep
.duration
= host_to_le16(data
->scan_params
.duration
);
932 rep
.rcpi
= rssi_to_rcpi(bss
->level
);
933 rep
.rsni
= 255; /* 255 indicates that RSNI is not available */
934 os_memcpy(rep
.bssid
, bss
->bssid
, ETH_ALEN
);
935 rep
.antenna_id
= 0; /* unknown */
936 rep
.parent_tsf
= host_to_le32(parent_tsf
);
941 ret
= wpas_add_beacon_rep_elem(data
, bss
, wpa_buf
, &rep
,
942 &pos
, &ies_len
, idx
++);
945 } while (data
->report_detail
!= BEACON_REPORT_DETAIL_NONE
&&
952 static int wpas_beacon_rep_no_results(struct wpa_supplicant
*wpa_s
,
955 return wpas_rrm_report_elem(buf
, wpa_s
->beacon_rep_data
.token
,
956 MEASUREMENT_REPORT_MODE_ACCEPT
,
957 MEASURE_TYPE_BEACON
, NULL
, 0);
961 static void wpas_beacon_rep_table(struct wpa_supplicant
*wpa_s
,
966 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
967 if (wpas_add_beacon_rep(wpa_s
, buf
, wpa_s
->last_scan_res
[i
],
973 wpas_beacon_rep_no_results(wpa_s
, buf
);
975 wpa_hexdump_buf(MSG_DEBUG
, "RRM: Radio Measurement report", *buf
);
979 void wpas_rrm_refuse_request(struct wpa_supplicant
*wpa_s
)
981 if (!is_multicast_ether_addr(wpa_s
->rrm
.dst_addr
)) {
982 struct wpabuf
*buf
= NULL
;
984 if (wpas_rrm_report_elem(&buf
, wpa_s
->beacon_rep_data
.token
,
985 MEASUREMENT_REPORT_MODE_REJECT_REFUSED
,
986 MEASURE_TYPE_BEACON
, NULL
, 0)) {
987 wpa_printf(MSG_ERROR
, "RRM: Memory allocation failed");
992 wpas_rrm_send_msr_report(wpa_s
, buf
);
996 wpas_clear_beacon_rep_data(wpa_s
);
1000 static void wpas_rrm_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
1002 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1003 struct wpa_driver_scan_params
*params
=
1004 &wpa_s
->beacon_rep_data
.scan_params
;
1005 u16 prev_duration
= params
->duration
;
1007 if (!wpa_s
->current_bss
)
1010 if (!(wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL
) &&
1012 wpa_printf(MSG_DEBUG
,
1013 "RRM: Cannot set scan duration due to missing driver support");
1014 params
->duration
= 0;
1016 os_get_reltime(&wpa_s
->beacon_rep_scan
);
1017 if (wpa_s
->scanning
|| wpas_p2p_in_progress(wpa_s
) ||
1018 wpa_supplicant_trigger_scan(wpa_s
, params
))
1019 wpas_rrm_refuse_request(wpa_s
);
1020 params
->duration
= prev_duration
;
1024 static int wpas_rm_handle_beacon_req_subelem(struct wpa_supplicant
*wpa_s
,
1025 struct beacon_rep_data
*data
,
1026 u8 sid
, u8 slen
, const u8
*subelem
)
1031 case WLAN_BEACON_REQUEST_SUBELEM_SSID
:
1033 wpa_printf(MSG_DEBUG
,
1034 "SSID subelement with zero length - wildcard SSID");
1038 if (slen
> SSID_MAX_LEN
) {
1039 wpa_printf(MSG_DEBUG
,
1040 "Invalid SSID subelement length: %u", slen
);
1044 data
->ssid_len
= slen
;
1045 os_memcpy(data
->ssid
, subelem
, data
->ssid_len
);
1047 case WLAN_BEACON_REQUEST_SUBELEM_INFO
:
1049 wpa_printf(MSG_DEBUG
,
1050 "Invalid reporting information subelement length: %u",
1055 report_info
= subelem
[0];
1056 if (report_info
!= 0) {
1057 wpa_printf(MSG_DEBUG
,
1058 "reporting information=%u is not supported",
1063 case WLAN_BEACON_REQUEST_SUBELEM_DETAIL
:
1065 wpa_printf(MSG_DEBUG
,
1066 "Invalid reporting detail subelement length: %u",
1071 data
->report_detail
= subelem
[0];
1072 if (data
->report_detail
>
1073 BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS
) {
1074 wpa_printf(MSG_DEBUG
, "Invalid reporting detail: %u",
1080 case WLAN_BEACON_REQUEST_SUBELEM_REQUEST
:
1081 if (data
->report_detail
!=
1082 BEACON_REPORT_DETAIL_REQUESTED_ONLY
) {
1083 wpa_printf(MSG_DEBUG
,
1084 "Beacon request: request subelement is present but report detail is %u",
1085 data
->report_detail
);
1090 wpa_printf(MSG_DEBUG
,
1091 "Invalid request subelement length: %u",
1097 wpa_printf(MSG_DEBUG
,
1098 "Beacon Request: Request subelement appears more than once");
1102 data
->eids
= bitfield_alloc(255);
1104 wpa_printf(MSG_DEBUG
, "Failed to allocate EIDs bitmap");
1108 for (i
= 0; i
< slen
; i
++)
1109 bitfield_set(data
->eids
, subelem
[i
]);
1111 case WLAN_BEACON_REQUEST_SUBELEM_AP_CHANNEL
:
1112 /* Skip - it will be processed when freqs are added */
1114 case WLAN_BEACON_REQUEST_SUBELEM_LAST_INDICATION
:
1116 wpa_printf(MSG_DEBUG
,
1117 "Beacon request: Invalid last indication request subelement length: %u",
1122 data
->last_indication
= subelem
[0];
1125 wpa_printf(MSG_DEBUG
,
1126 "Beacon request: Unknown subelement id %u", sid
);
1135 * Returns 0 if the next element can be processed, 1 if some operation was
1136 * triggered, and -1 if processing failed (i.e., the element is in invalid
1137 * format or an internal error occurred).
1140 wpas_rm_handle_beacon_req(struct wpa_supplicant
*wpa_s
,
1141 u8 elem_token
, int duration_mandatory
,
1142 const struct rrm_measurement_beacon_request
*req
,
1143 size_t len
, struct wpabuf
**buf
)
1145 struct beacon_rep_data
*data
= &wpa_s
->beacon_rep_data
;
1146 struct wpa_driver_scan_params
*params
= &data
->scan_params
;
1155 if (len
< sizeof(*req
))
1158 if (req
->mode
!= BEACON_REPORT_MODE_PASSIVE
&&
1159 req
->mode
!= BEACON_REPORT_MODE_ACTIVE
&&
1160 req
->mode
!= BEACON_REPORT_MODE_TABLE
)
1163 subelems
= req
->variable
;
1164 elems_len
= len
- sizeof(*req
);
1165 rand_interval
= le_to_host16(req
->rand_interval
);
1167 os_free(params
->freqs
);
1168 os_memset(params
, 0, sizeof(*params
));
1170 data
->token
= elem_token
;
1172 /* default reporting detail is all fixed length fields and all
1174 data
->report_detail
= BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS
;
1175 os_memcpy(data
->bssid
, req
->bssid
, ETH_ALEN
);
1177 while (elems_len
>= 2) {
1178 if (subelems
[1] > elems_len
- 2) {
1179 wpa_printf(MSG_DEBUG
,
1180 "Beacon Request: Truncated subelement");
1185 res
= wpas_rm_handle_beacon_req_subelem(
1186 wpa_s
, data
, subelems
[0], subelems
[1], &subelems
[2]);
1191 reject_mode
= MEASUREMENT_REPORT_MODE_REJECT_INCAPABLE
;
1195 elems_len
-= 2 + subelems
[1];
1196 subelems
+= 2 + subelems
[1];
1199 if (req
->mode
== BEACON_REPORT_MODE_TABLE
) {
1200 wpas_beacon_rep_table(wpa_s
, buf
);
1204 params
->freqs
= wpas_beacon_request_freqs(
1205 wpa_s
, req
->oper_class
, req
->channel
,
1206 req
->mode
== BEACON_REPORT_MODE_ACTIVE
,
1207 req
->variable
, len
- sizeof(*req
));
1208 if (!params
->freqs
) {
1209 wpa_printf(MSG_DEBUG
, "Beacon request: No valid channels");
1210 reject_mode
= MEASUREMENT_REPORT_MODE_REJECT_REFUSED
;
1214 params
->duration
= le_to_host16(req
->duration
);
1215 params
->duration_mandatory
= duration_mandatory
;
1216 if (!params
->duration
) {
1217 wpa_printf(MSG_DEBUG
, "Beacon request: Duration is 0");
1222 params
->only_new_results
= 1;
1224 if (req
->mode
== BEACON_REPORT_MODE_ACTIVE
) {
1225 params
->ssids
[params
->num_ssids
].ssid
= data
->ssid
;
1226 params
->ssids
[params
->num_ssids
++].ssid_len
= data
->ssid_len
;
1229 if (os_get_random((u8
*) &_rand
, sizeof(_rand
)) < 0)
1230 _rand
= os_random();
1231 interval_usec
= (_rand
% (rand_interval
+ 1)) * 1024;
1232 eloop_register_timeout(0, interval_usec
, wpas_rrm_scan_timeout
, wpa_s
,
1236 if (!is_multicast_ether_addr(wpa_s
->rrm
.dst_addr
) &&
1237 wpas_rrm_report_elem(buf
, elem_token
, reject_mode
,
1238 MEASURE_TYPE_BEACON
, NULL
, 0) < 0) {
1239 wpa_printf(MSG_DEBUG
, "RRM: Failed to add report element");
1243 wpas_clear_beacon_rep_data(wpa_s
);
1249 wpas_rrm_handle_msr_req_element(
1250 struct wpa_supplicant
*wpa_s
,
1251 const struct rrm_measurement_request_element
*req
,
1252 struct wpabuf
**buf
)
1254 int duration_mandatory
;
1256 wpa_printf(MSG_DEBUG
, "Measurement request type %d token %d",
1257 req
->type
, req
->token
);
1259 if (req
->mode
& MEASUREMENT_REQUEST_MODE_ENABLE
) {
1260 /* Enable bit is not supported for now */
1261 wpa_printf(MSG_DEBUG
, "RRM: Enable bit not supported, ignore");
1265 if ((req
->mode
& MEASUREMENT_REQUEST_MODE_PARALLEL
) &&
1266 req
->type
> MEASURE_TYPE_RPI_HIST
) {
1267 /* Parallel measurements are not supported for now */
1268 wpa_printf(MSG_DEBUG
,
1269 "RRM: Parallel measurements are not supported, reject");
1273 duration_mandatory
=
1274 !!(req
->mode
& MEASUREMENT_REQUEST_MODE_DURATION_MANDATORY
);
1276 switch (req
->type
) {
1277 case MEASURE_TYPE_LCI
:
1278 return wpas_rrm_build_lci_report(wpa_s
, req
, buf
);
1279 case MEASURE_TYPE_BEACON
:
1280 if (duration_mandatory
&&
1281 !(wpa_s
->drv_rrm_flags
&
1282 WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL
)) {
1283 wpa_printf(MSG_DEBUG
,
1284 "RRM: Driver does not support dwell time configuration - reject beacon report with mandatory duration");
1287 return wpas_rm_handle_beacon_req(wpa_s
, req
->token
,
1289 (const void *) req
->variable
,
1292 wpa_printf(MSG_INFO
,
1293 "RRM: Unsupported radio measurement type %u",
1299 if (!is_multicast_ether_addr(wpa_s
->rrm
.dst_addr
) &&
1300 wpas_rrm_report_elem(buf
, req
->token
,
1301 MEASUREMENT_REPORT_MODE_REJECT_INCAPABLE
,
1302 req
->type
, NULL
, 0) < 0) {
1303 wpa_printf(MSG_DEBUG
, "RRM: Failed to add report element");
1311 static struct wpabuf
*
1312 wpas_rrm_process_msr_req_elems(struct wpa_supplicant
*wpa_s
, const u8
*pos
,
1315 struct wpabuf
*buf
= NULL
;
1318 const struct rrm_measurement_request_element
*req
;
1322 wpa_printf(MSG_DEBUG
, "RRM: Truncated element");
1326 req
= (const struct rrm_measurement_request_element
*) pos
;
1327 if (req
->eid
!= WLAN_EID_MEASURE_REQUEST
) {
1328 wpa_printf(MSG_DEBUG
,
1329 "RRM: Expected Measurement Request element, but EID is %u",
1335 wpa_printf(MSG_DEBUG
, "RRM: Element length too short");
1339 if (req
->len
> len
- 2) {
1340 wpa_printf(MSG_DEBUG
, "RRM: Element length too long");
1344 res
= wpas_rrm_handle_msr_req_element(wpa_s
, req
, &buf
);
1348 pos
+= req
->len
+ 2;
1349 len
-= req
->len
+ 2;
1360 void wpas_rrm_handle_radio_measurement_request(struct wpa_supplicant
*wpa_s
,
1361 const u8
*src
, const u8
*dst
,
1362 const u8
*frame
, size_t len
)
1364 struct wpabuf
*report
;
1366 if (wpa_s
->wpa_state
!= WPA_COMPLETED
) {
1367 wpa_printf(MSG_INFO
,
1368 "RRM: Ignoring radio measurement request: Not associated");
1372 if (!wpa_s
->rrm
.rrm_used
) {
1373 wpa_printf(MSG_INFO
,
1374 "RRM: Ignoring radio measurement request: Not RRM network");
1379 wpa_printf(MSG_INFO
,
1380 "RRM: Ignoring too short radio measurement request");
1384 wpa_s
->rrm
.token
= *frame
;
1385 os_memcpy(wpa_s
->rrm
.dst_addr
, dst
, ETH_ALEN
);
1387 /* Number of repetitions is not supported */
1389 report
= wpas_rrm_process_msr_req_elems(wpa_s
, frame
+ 3, len
- 3);
1393 wpas_rrm_send_msr_report(wpa_s
, report
);
1394 wpabuf_free(report
);
1398 void wpas_rrm_handle_link_measurement_request(struct wpa_supplicant
*wpa_s
,
1400 const u8
*frame
, size_t len
,
1404 const struct rrm_link_measurement_request
*req
;
1405 struct rrm_link_measurement_report report
;
1407 if (wpa_s
->wpa_state
!= WPA_COMPLETED
) {
1408 wpa_printf(MSG_INFO
,
1409 "RRM: Ignoring link measurement request. Not associated");
1413 if (!wpa_s
->rrm
.rrm_used
) {
1414 wpa_printf(MSG_INFO
,
1415 "RRM: Ignoring link measurement request. Not RRM network");
1419 if (!(wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
)) {
1420 wpa_printf(MSG_INFO
,
1421 "RRM: Measurement report failed. TX power insertion not supported");
1425 req
= (const struct rrm_link_measurement_request
*) frame
;
1426 if (len
< sizeof(*req
)) {
1427 wpa_printf(MSG_INFO
,
1428 "RRM: Link measurement report failed. Request too short");
1432 os_memset(&report
, 0, sizeof(report
));
1433 report
.dialog_token
= req
->dialog_token
;
1434 report
.tpc
.eid
= WLAN_EID_TPC_REPORT
;
1436 /* Note: The driver is expected to update report.tpc.tx_power and
1437 * report.tpc.link_margin subfields when sending out this frame.
1438 * Similarly, the driver would need to update report.rx_ant_id and
1439 * report.tx_ant_id subfields. */
1440 report
.rsni
= 255; /* 255 indicates that RSNI is not available */
1441 report
.rcpi
= rssi_to_rcpi(rssi
);
1443 /* action_category + action_code */
1444 buf
= wpabuf_alloc(2 + sizeof(report
));
1446 wpa_printf(MSG_ERROR
,
1447 "RRM: Link measurement report failed. Buffer allocation failed");
1451 wpabuf_put_u8(buf
, WLAN_ACTION_RADIO_MEASUREMENT
);
1452 wpabuf_put_u8(buf
, WLAN_RRM_LINK_MEASUREMENT_REPORT
);
1453 wpabuf_put_data(buf
, &report
, sizeof(report
));
1454 wpa_hexdump_buf(MSG_DEBUG
, "RRM: Link measurement report", buf
);
1456 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, src
,
1457 wpa_s
->own_addr
, wpa_s
->bssid
,
1458 wpabuf_head(buf
), wpabuf_len(buf
), 0)) {
1459 wpa_printf(MSG_ERROR
,
1460 "RRM: Link measurement report failed. Send action failed");
1466 int wpas_beacon_rep_scan_process(struct wpa_supplicant
*wpa_s
,
1467 struct wpa_scan_results
*scan_res
,
1468 struct scan_info
*info
)
1471 struct wpabuf
*buf
= NULL
;
1473 if (!wpa_s
->beacon_rep_data
.token
)
1476 if (!wpa_s
->current_bss
)
1479 /* If the measurement was aborted, don't report partial results */
1483 wpa_printf(MSG_DEBUG
, "RRM: TSF BSSID: " MACSTR
" current BSS: " MACSTR
,
1484 MAC2STR(info
->scan_start_tsf_bssid
),
1485 MAC2STR(wpa_s
->current_bss
->bssid
));
1486 if ((wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT
) &&
1487 os_memcmp(info
->scan_start_tsf_bssid
, wpa_s
->current_bss
->bssid
,
1489 wpa_printf(MSG_DEBUG
,
1490 "RRM: Ignore scan results due to mismatching TSF BSSID");
1494 for (i
= 0; i
< scan_res
->num
; i
++) {
1495 struct wpa_bss
*bss
=
1496 wpa_bss_get_bssid(wpa_s
, scan_res
->res
[i
]->bssid
);
1501 if ((wpa_s
->drv_rrm_flags
&
1502 WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT
) &&
1503 os_memcmp(scan_res
->res
[i
]->tsf_bssid
,
1504 wpa_s
->current_bss
->bssid
, ETH_ALEN
) != 0) {
1505 wpa_printf(MSG_DEBUG
,
1506 "RRM: Ignore scan result for " MACSTR
1507 " due to mismatching TSF BSSID" MACSTR
,
1508 MAC2STR(scan_res
->res
[i
]->bssid
),
1509 MAC2STR(scan_res
->res
[i
]->tsf_bssid
));
1514 * Don't report results that were not received during the
1515 * current measurement.
1517 if (!(wpa_s
->drv_rrm_flags
&
1518 WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT
)) {
1519 struct os_reltime update_time
, diff
;
1521 /* For now, allow 8 ms older results due to some
1522 * unknown issue with cfg80211 BSS table updates during
1523 * a scan with the current BSS.
1524 * TODO: Fix this more properly to avoid having to have
1525 * this type of hacks in place. */
1526 calculate_update_time(&scan_res
->fetch_time
,
1527 scan_res
->res
[i
]->age
,
1529 os_reltime_sub(&wpa_s
->beacon_rep_scan
,
1530 &update_time
, &diff
);
1531 if (os_reltime_before(&update_time
,
1532 &wpa_s
->beacon_rep_scan
) &&
1533 (diff
.sec
|| diff
.usec
>= 8000)) {
1534 wpa_printf(MSG_DEBUG
,
1535 "RRM: Ignore scan result for " MACSTR
1536 " due to old update (age(ms) %u, calculated age %u.%06u seconds)",
1537 MAC2STR(scan_res
->res
[i
]->bssid
),
1538 scan_res
->res
[i
]->age
,
1539 (unsigned int) diff
.sec
,
1540 (unsigned int) diff
.usec
);
1543 } else if (info
->scan_start_tsf
>
1544 scan_res
->res
[i
]->parent_tsf
) {
1548 if (wpas_add_beacon_rep(wpa_s
, &buf
, bss
, info
->scan_start_tsf
,
1549 scan_res
->res
[i
]->parent_tsf
) < 0)
1553 if (!buf
&& wpas_beacon_rep_no_results(wpa_s
, &buf
))
1556 wpa_hexdump_buf(MSG_DEBUG
, "RRM: Radio Measurement report", buf
);
1558 wpas_rrm_send_msr_report(wpa_s
, buf
);
1562 wpas_clear_beacon_rep_data(wpa_s
);
1567 void wpas_clear_beacon_rep_data(struct wpa_supplicant
*wpa_s
)
1569 struct beacon_rep_data
*data
= &wpa_s
->beacon_rep_data
;
1571 eloop_cancel_timeout(wpas_rrm_scan_timeout
, wpa_s
, NULL
);
1572 bitfield_free(data
->eids
);
1573 os_free(data
->scan_params
.freqs
);
1574 os_memset(data
, 0, sizeof(*data
));