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_msg(wpa_s
, MSG_INFO
, "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_dbg(wpa_s
, 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 */
108 #define EOPNOTSUPP -1
115 /* Measurement Request element + Location Subject + Maximum Age subelement */
116 #define MEASURE_REQUEST_LCI_LEN (3 + 1 + 4)
117 /* Measurement Request element + Location Civic Request */
118 #define MEASURE_REQUEST_CIVIC_LEN (3 + 5)
122 * wpas_rrm_send_neighbor_rep_request - Request a neighbor report from our AP
123 * @wpa_s: Pointer to wpa_supplicant
124 * @ssid: if not null, this is sent in the request. Otherwise, no SSID IE
125 * is sent in the request.
126 * @lci: if set, neighbor request will include LCI request
127 * @civic: if set, neighbor request will include civic location request
128 * @cb: Callback function to be called once the requested report arrives, or
129 * timed out after RRM_NEIGHBOR_REPORT_TIMEOUT seconds.
130 * In the former case, 'neighbor_rep' is a newly allocated wpabuf, and it's
131 * the requester's responsibility to free it.
132 * In the latter case NULL will be sent in 'neighbor_rep'.
133 * @cb_ctx: Context value to send the callback function
134 * Returns: 0 in case of success, negative error code otherwise
136 * In case there is a previous request which has not been answered yet, the
137 * new request fails. The caller may retry after RRM_NEIGHBOR_REPORT_TIMEOUT.
138 * Request must contain a callback function.
140 int wpas_rrm_send_neighbor_rep_request(struct wpa_supplicant
*wpa_s
,
141 const struct wpa_ssid_value
*ssid
,
143 void (*cb
)(void *ctx
,
144 struct wpabuf
*neighbor_rep
),
150 if (wpa_s
->wpa_state
!= WPA_COMPLETED
|| wpa_s
->current_ssid
== NULL
) {
151 wpa_dbg(wpa_s
, MSG_DEBUG
, "RRM: No connection, no RRM.");
155 if (!wpa_s
->rrm
.rrm_used
) {
156 wpa_dbg(wpa_s
, MSG_DEBUG
, "RRM: No RRM in current connection.");
160 rrm_ie
= wpa_bss_get_ie(wpa_s
->current_bss
,
161 WLAN_EID_RRM_ENABLED_CAPABILITIES
);
162 if (!rrm_ie
|| !(wpa_s
->current_bss
->caps
& IEEE80211_CAP_RRM
) ||
163 !(rrm_ie
[2] & WLAN_RRM_CAPS_NEIGHBOR_REPORT
)) {
164 wpa_dbg(wpa_s
, MSG_DEBUG
,
165 "RRM: No network support for Neighbor Report.");
169 /* Refuse if there's a live request */
170 if (wpa_s
->rrm
.notify_neighbor_rep
) {
171 wpa_dbg(wpa_s
, MSG_DEBUG
,
172 "RRM: Currently handling previous Neighbor Report.");
176 /* 3 = action category + action code + dialog token */
177 buf
= wpabuf_alloc(3 + (ssid
? 2 + ssid
->ssid_len
: 0) +
178 (lci
? 2 + MEASURE_REQUEST_LCI_LEN
: 0) +
179 (civic
? 2 + MEASURE_REQUEST_CIVIC_LEN
: 0));
181 wpa_dbg(wpa_s
, MSG_DEBUG
,
182 "RRM: Failed to allocate Neighbor Report Request");
186 wpa_dbg(wpa_s
, MSG_DEBUG
,
187 "RRM: Neighbor report request (for %s), token=%d",
188 (ssid
? wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
) : ""),
189 wpa_s
->rrm
.next_neighbor_rep_token
);
191 wpabuf_put_u8(buf
, WLAN_ACTION_RADIO_MEASUREMENT
);
192 wpabuf_put_u8(buf
, WLAN_RRM_NEIGHBOR_REPORT_REQUEST
);
193 wpabuf_put_u8(buf
, wpa_s
->rrm
.next_neighbor_rep_token
);
195 wpabuf_put_u8(buf
, WLAN_EID_SSID
);
196 wpabuf_put_u8(buf
, ssid
->ssid_len
);
197 wpabuf_put_data(buf
, ssid
->ssid
, ssid
->ssid_len
);
201 /* IEEE P802.11-REVmc/D5.0 9.4.2.21 */
202 wpabuf_put_u8(buf
, WLAN_EID_MEASURE_REQUEST
);
203 wpabuf_put_u8(buf
, MEASURE_REQUEST_LCI_LEN
);
206 * Measurement token; nonzero number that is unique among the
207 * Measurement Request elements in a particular frame.
209 wpabuf_put_u8(buf
, 1); /* Measurement Token */
212 * Parallel, Enable, Request, and Report bits are 0, Duration is
215 wpabuf_put_u8(buf
, 0); /* Measurement Request Mode */
216 wpabuf_put_u8(buf
, MEASURE_TYPE_LCI
); /* Measurement Type */
218 /* IEEE P802.11-REVmc/D5.0 9.4.2.21.10 - LCI request */
219 /* Location Subject */
220 wpabuf_put_u8(buf
, LOCATION_SUBJECT_REMOTE
);
222 /* Optional Subelements */
224 * IEEE P802.11-REVmc/D5.0 Figure 9-170
225 * The Maximum Age subelement is required, otherwise the AP can
226 * send only data that was determined after receiving the
227 * request. Setting it here to unlimited age.
229 wpabuf_put_u8(buf
, LCI_REQ_SUBELEM_MAX_AGE
);
230 wpabuf_put_u8(buf
, 2);
231 wpabuf_put_le16(buf
, 0xffff);
235 /* IEEE P802.11-REVmc/D5.0 9.4.2.21 */
236 wpabuf_put_u8(buf
, WLAN_EID_MEASURE_REQUEST
);
237 wpabuf_put_u8(buf
, MEASURE_REQUEST_CIVIC_LEN
);
240 * Measurement token; nonzero number that is unique among the
241 * Measurement Request elements in a particular frame.
243 wpabuf_put_u8(buf
, 2); /* Measurement Token */
246 * Parallel, Enable, Request, and Report bits are 0, Duration is
249 wpabuf_put_u8(buf
, 0); /* Measurement Request Mode */
250 /* Measurement Type */
251 wpabuf_put_u8(buf
, MEASURE_TYPE_LOCATION_CIVIC
);
253 /* IEEE P802.11-REVmc/D5.0 9.4.2.21.14:
254 * Location Civic request */
255 /* Location Subject */
256 wpabuf_put_u8(buf
, LOCATION_SUBJECT_REMOTE
);
257 wpabuf_put_u8(buf
, 0); /* Civic Location Type: IETF RFC 4776 */
258 /* Location Service Interval Units: Seconds */
259 wpabuf_put_u8(buf
, 0);
260 /* Location Service Interval: 0 - Only one report is requested
262 wpabuf_put_le16(buf
, 0);
263 /* No optional subelements */
266 wpa_s
->rrm
.next_neighbor_rep_token
++;
268 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
269 wpa_s
->own_addr
, wpa_s
->bssid
,
270 wpabuf_head(buf
), wpabuf_len(buf
), 0) < 0) {
271 wpa_dbg(wpa_s
, MSG_DEBUG
,
272 "RRM: Failed to send Neighbor Report Request");
277 wpa_s
->rrm
.neighbor_rep_cb_ctx
= cb_ctx
;
278 wpa_s
->rrm
.notify_neighbor_rep
= cb
;
279 eloop_register_timeout(RRM_NEIGHBOR_REPORT_TIMEOUT
, 0,
280 wpas_rrm_neighbor_rep_timeout_handler
,
288 static int wpas_rrm_report_elem(struct wpabuf
**buf
, u8 token
, u8 mode
, u8 type
,
289 const u8
*data
, size_t data_len
)
291 if (wpabuf_resize(buf
, 5 + data_len
))
294 wpabuf_put_u8(*buf
, WLAN_EID_MEASURE_REPORT
);
295 wpabuf_put_u8(*buf
, 3 + data_len
);
296 wpabuf_put_u8(*buf
, token
);
297 wpabuf_put_u8(*buf
, mode
);
298 wpabuf_put_u8(*buf
, type
);
301 wpabuf_put_data(*buf
, data
, data_len
);
308 wpas_rrm_build_lci_report(struct wpa_supplicant
*wpa_s
,
309 const struct rrm_measurement_request_element
*req
,
314 struct os_reltime t
, diff
;
315 unsigned long diff_l
;
317 const u8
*request
= req
->variable
;
318 size_t len
= req
->len
- 3;
326 subject
= *request
++;
329 wpa_printf(MSG_DEBUG
, "Measurement request location subject=%u",
332 if (subject
!= LOCATION_SUBJECT_REMOTE
) {
334 "Not building LCI report - bad location subject");
338 /* Subelements are formatted exactly like elements */
339 wpa_hexdump(MSG_DEBUG
, "LCI request subelements", request
, len
);
340 subelem
= get_ie(request
, len
, LCI_REQ_SUBELEM_MAX_AGE
);
341 if (subelem
&& subelem
[1] == 2)
342 max_age
= WPA_GET_LE16(subelem
+ 2);
344 if (os_get_reltime(&t
))
347 os_reltime_sub(&t
, &wpa_s
->lci_time
, &diff
);
348 /* LCI age is calculated in 10th of a second units. */
349 diff_l
= diff
.sec
* 10 + diff
.usec
/ 100000;
351 if (max_age
!= 0xffff && max_age
< diff_l
)
354 if (wpas_rrm_report_elem(buf
, req
->token
,
355 MEASUREMENT_REPORT_MODE_ACCEPT
, req
->type
,
356 wpabuf_head_u8(wpa_s
->lci
),
357 wpabuf_len(wpa_s
->lci
)) < 0) {
358 wpa_printf(MSG_DEBUG
, "Failed to add LCI report element");
365 if (!is_multicast_ether_addr(wpa_s
->rrm
.dst_addr
) &&
366 wpas_rrm_report_elem(buf
, req
->token
,
367 MEASUREMENT_REPORT_MODE_REJECT_INCAPABLE
,
368 req
->type
, NULL
, 0) < 0) {
369 wpa_printf(MSG_DEBUG
, "RRM: Failed to add report element");
377 static void wpas_rrm_send_msr_report_mpdu(struct wpa_supplicant
*wpa_s
,
378 const u8
*data
, size_t len
)
380 struct wpabuf
*report
= wpabuf_alloc(len
+ 3);
385 wpabuf_put_u8(report
, WLAN_ACTION_RADIO_MEASUREMENT
);
386 wpabuf_put_u8(report
, WLAN_RRM_RADIO_MEASUREMENT_REPORT
);
387 wpabuf_put_u8(report
, wpa_s
->rrm
.token
);
389 wpabuf_put_data(report
, data
, len
);
391 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
392 wpa_s
->own_addr
, wpa_s
->bssid
,
393 wpabuf_head(report
), wpabuf_len(report
), 0)) {
394 wpa_printf(MSG_ERROR
,
395 "RRM: Radio measurement report failed: Sending Action frame failed");
402 static int wpas_rrm_beacon_rep_update_last_frame(u8
*pos
, size_t len
)
404 struct rrm_measurement_report_element
*msr_rep
;
407 struct rrm_measurement_beacon_report
*rep
= NULL
;
410 /* Find the last beacon report element */
411 while (end
- pos
>= (int) sizeof(*msr_rep
)) {
412 msr_rep
= (struct rrm_measurement_report_element
*) pos
;
413 msr_rep_end
= pos
+ msr_rep
->len
+ 2;
415 if (msr_rep
->eid
!= WLAN_EID_MEASURE_REPORT
||
417 /* Should not happen. This indicates a bug. */
418 wpa_printf(MSG_ERROR
,
419 "RRM: non-measurement report element in measurement report frame");
423 if (msr_rep
->type
== MEASURE_TYPE_BEACON
)
424 rep
= (struct rrm_measurement_beacon_report
*)
433 subelem
= rep
->variable
;
434 while (subelem
+ 2 < msr_rep_end
&&
435 subelem
[0] != WLAN_BEACON_REPORT_SUBELEM_LAST_INDICATION
)
436 subelem
+= 2 + subelem
[1];
438 if (subelem
+ 2 < msr_rep_end
&&
439 subelem
[0] == WLAN_BEACON_REPORT_SUBELEM_LAST_INDICATION
&&
441 subelem
+ BEACON_REPORT_LAST_INDICATION_SUBELEM_LEN
<= end
)
448 static void wpas_rrm_send_msr_report(struct wpa_supplicant
*wpa_s
,
451 int len
= wpabuf_len(buf
);
452 u8
*pos
= wpabuf_mhead_u8(buf
), *next
= pos
;
454 #define MPDU_REPORT_LEN (int) (IEEE80211_MAX_MMPDU_SIZE - IEEE80211_HDRLEN - 3)
457 int send_len
= (len
> MPDU_REPORT_LEN
) ? next
- pos
: len
;
460 wpas_rrm_beacon_rep_update_last_frame(pos
, len
);
462 if (send_len
== len
||
463 (send_len
+ next
[1] + 2) > MPDU_REPORT_LEN
) {
464 wpas_rrm_send_msr_report_mpdu(wpa_s
, pos
, send_len
);
472 #undef MPDU_REPORT_LEN
476 static int wpas_add_channel(u8 op_class
, u8 chan
, u8 num_primary_channels
,
481 for (i
= 0; i
< num_primary_channels
; i
++) {
482 u8 primary_chan
= chan
- (2 * num_primary_channels
- 2) + i
* 4;
484 freqs
[i
] = ieee80211_chan_to_freq(NULL
, op_class
, primary_chan
);
485 /* ieee80211_chan_to_freq() is not really meant for this
486 * conversion of 20 MHz primary channel numbers for wider VHT
487 * channels, so handle those as special cases here for now. */
489 (op_class
== 128 || op_class
== 129 || op_class
== 130))
490 freqs
[i
] = 5000 + 5 * primary_chan
;
492 wpa_printf(MSG_DEBUG
,
493 "Beacon Report: Invalid channel %u",
503 static int * wpas_add_channels(const struct oper_class_map
*op
,
504 struct hostapd_hw_modes
*mode
, int active
,
505 const u8
*channels
, const u8 size
)
507 int *freqs
, *next_freq
;
508 u8 num_primary_channels
, i
;
511 num_chans
= channels
? size
:
512 (op
->max_chan
- op
->min_chan
) / op
->inc
+ 1;
514 if (op
->bw
== BW80
|| op
->bw
== BW80P80
)
515 num_primary_channels
= 4;
516 else if (op
->bw
== BW160
)
517 num_primary_channels
= 8;
519 num_primary_channels
= 1;
521 /* one extra place for the zero-terminator */
522 freqs
= os_calloc(num_chans
* num_primary_channels
+ 1, sizeof(*freqs
));
524 wpa_printf(MSG_ERROR
,
525 "Beacon Report: Failed to allocate freqs array");
530 for (i
= 0; i
< num_chans
; i
++) {
531 u8 chan
= channels
? channels
[i
] : op
->min_chan
+ i
* op
->inc
;
532 enum chan_allowed res
= verify_channel(mode
, op
->op_class
, chan
,
535 if (res
== NOT_ALLOWED
|| (res
== NO_IR
&& active
))
538 if (wpas_add_channel(op
->op_class
, chan
, num_primary_channels
,
544 next_freq
+= num_primary_channels
;
556 static int * wpas_op_class_freqs(const struct oper_class_map
*op
,
557 struct hostapd_hw_modes
*mode
, int active
)
559 u8 channels_80mhz
[] = { 42, 58, 106, 122, 138, 155 };
560 u8 channels_160mhz
[] = { 50, 114 };
563 * When adding all channels in the operating class, 80 + 80 MHz
564 * operating classes are like 80 MHz channels because we add all valid
567 if (op
->bw
== BW80
|| op
->bw
== BW80P80
)
568 return wpas_add_channels(op
, mode
, active
, channels_80mhz
,
569 ARRAY_SIZE(channels_80mhz
));
572 return wpas_add_channels(op
, mode
, active
, channels_160mhz
,
573 ARRAY_SIZE(channels_160mhz
));
575 return wpas_add_channels(op
, mode
, active
, NULL
, 0);
579 static int * wpas_channel_report_freqs(struct wpa_supplicant
*wpa_s
, int active
,
580 const char *country
, const u8
*subelems
,
583 int *freqs
= NULL
, *new_freqs
;
584 const u8
*end
= subelems
+ len
;
586 while (end
- subelems
> 2) {
587 const struct oper_class_map
*op
;
588 const u8
*ap_chan_elem
, *pos
;
590 struct hostapd_hw_modes
*mode
;
592 ap_chan_elem
= get_ie(subelems
, end
- subelems
,
593 WLAN_BEACON_REQUEST_SUBELEM_AP_CHANNEL
);
596 pos
= ap_chan_elem
+ 2;
597 left
= ap_chan_elem
[1];
600 subelems
= ap_chan_elem
+ 2 + left
;
602 op
= get_oper_class(country
, *pos
);
604 wpa_printf(MSG_DEBUG
,
605 "Beacon request: unknown operating class in AP Channel Report subelement %u",
612 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
, op
->mode
,
613 is_6ghz_op_class(op
->op_class
));
618 * For 80 + 80 MHz operating classes, this AP Channel Report
619 * element should be followed by another element specifying
620 * the second 80 MHz channel. For now just add this 80 MHz
621 * channel, the second 80 MHz channel will be added when the
622 * next element is parsed.
623 * TODO: Verify that this AP Channel Report element is followed
624 * by a corresponding AP Channel Report element as specified in
625 * IEEE Std 802.11-2016, 11.11.9.1.
627 new_freqs
= wpas_add_channels(op
, mode
, active
, pos
, left
);
629 int_array_concat(&freqs
, new_freqs
);
641 static int * wpas_beacon_request_freqs(struct wpa_supplicant
*wpa_s
,
642 u8 op_class
, u8 chan
, int active
,
643 const u8
*subelems
, size_t len
)
645 int *freqs
= NULL
, *ext_freqs
= NULL
;
646 struct hostapd_hw_modes
*mode
;
647 const char *country
= NULL
;
648 const struct oper_class_map
*op
;
651 if (!wpa_s
->current_bss
)
653 elem
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_COUNTRY
);
654 if (elem
&& elem
[1] >= 2)
655 country
= (const char *) (elem
+ 2);
657 op
= get_oper_class(country
, op_class
);
659 wpa_printf(MSG_DEBUG
,
660 "Beacon request: invalid operating class %d",
665 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
, op
->mode
,
666 is_6ghz_op_class(op
->op_class
));
672 freqs
= wpas_op_class_freqs(op
, mode
, active
);
677 /* freqs will be added from AP channel subelements */
680 freqs
= wpas_add_channels(op
, mode
, active
, &chan
, 1);
686 ext_freqs
= wpas_channel_report_freqs(wpa_s
, active
, country
, subelems
,
689 int_array_concat(&freqs
, ext_freqs
);
691 int_array_sort_unique(freqs
);
698 int wpas_get_op_chan_phy(int freq
, const u8
*ies
, size_t ies_len
,
699 u8
*op_class
, u8
*chan
, u8
*phy_type
)
702 int sec_chan
= 0, vht
= 0;
703 struct ieee80211_ht_operation
*ht_oper
= NULL
;
704 struct ieee80211_vht_operation
*vht_oper
= NULL
;
707 ie
= get_ie(ies
, ies_len
, WLAN_EID_HT_OPERATION
);
708 if (ie
&& ie
[1] >= sizeof(struct ieee80211_ht_operation
)) {
711 ht_oper
= (struct ieee80211_ht_operation
*) (ie
+ 2);
712 sec_chan_offset
= ht_oper
->ht_param
&
713 HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK
;
714 if (sec_chan_offset
== HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE
)
716 else if (sec_chan_offset
==
717 HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW
)
721 ie
= get_ie(ies
, ies_len
, WLAN_EID_VHT_OPERATION
);
722 if (ie
&& ie
[1] >= sizeof(struct ieee80211_vht_operation
)) {
723 vht_oper
= (struct ieee80211_vht_operation
*) (ie
+ 2);
725 switch (vht_oper
->vht_op_info_chwidth
) {
727 seg0
= vht_oper
->vht_op_info_chan_center_freq_seg0_idx
;
728 seg1
= vht_oper
->vht_op_info_chan_center_freq_seg1_idx
;
729 if (seg1
&& abs(seg1
- seg0
) == 8)
730 vht
= CHANWIDTH_160MHZ
;
732 vht
= CHANWIDTH_80P80MHZ
;
734 vht
= CHANWIDTH_80MHZ
;
737 vht
= CHANWIDTH_160MHZ
;
740 vht
= CHANWIDTH_80P80MHZ
;
743 vht
= CHANWIDTH_USE_HT
;
748 if (ieee80211_freq_to_channel_ext(freq
, sec_chan
, vht
, op_class
,
749 chan
) == NUM_HOSTAPD_MODES
) {
750 wpa_printf(MSG_DEBUG
,
751 "Cannot determine operating class and channel");
755 *phy_type
= ieee80211_get_phy_type(freq
, ht_oper
!= NULL
,
757 if (*phy_type
== PHY_TYPE_UNSPECIFIED
) {
758 wpa_printf(MSG_DEBUG
, "Cannot determine phy type");
766 static int wpas_beacon_rep_add_frame_body(struct bitfield
*eids
,
767 enum beacon_report_detail detail
,
768 struct wpa_bss
*bss
, u8
*buf
,
769 size_t buf_len
, u8
**ies_buf
,
770 size_t *ie_len
, int add_fixed
)
773 size_t ies_len
= *ie_len
;
777 rem_len
= 255 - sizeof(struct rrm_measurement_beacon_report
) -
778 sizeof(struct rrm_measurement_report_element
) - 2 -
779 REPORTED_FRAME_BODY_SUBELEM_LEN
;
781 if (detail
> BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS
) {
782 wpa_printf(MSG_DEBUG
,
783 "Beacon Request: Invalid reporting detail: %d",
788 if (detail
== BEACON_REPORT_DETAIL_NONE
)
792 * Minimal frame body subelement size: EID(1) + length(1) + TSF(8) +
793 * beacon interval(2) + capabilities(2) = 14 bytes
795 if (add_fixed
&& buf_len
< 14)
798 *pos
++ = WLAN_BEACON_REPORT_SUBELEM_FRAME_BODY
;
799 /* The length will be filled later */
803 WPA_PUT_LE64(pos
, bss
->tsf
);
804 pos
+= sizeof(bss
->tsf
);
805 WPA_PUT_LE16(pos
, bss
->beacon_int
);
807 WPA_PUT_LE16(pos
, bss
->caps
);
811 rem_len
-= pos
- buf
;
814 * According to IEEE Std 802.11-2016, 9.4.2.22.7, if the reported frame
815 * body subelement causes the element to exceed the maximum element
816 * size, the subelement is truncated so that the last IE is a complete
817 * IE. So even when required to report all IEs, add elements one after
818 * the other and stop once there is no more room in the measurement
821 while (ies_len
> 2 && 2U + ies
[1] <= ies_len
&& rem_len
> 0) {
822 if (detail
== BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS
||
823 (eids
&& bitfield_is_set(eids
, ies
[0]))) {
826 if (2 + elen
> buf
+ buf_len
- pos
||
832 os_memcpy(pos
, ies
+ 2, elen
);
837 ies_len
-= 2 + ies
[1];
844 /* Now the length is known */
845 buf
[1] = pos
- buf
- 2;
850 static int wpas_add_beacon_rep_elem(struct beacon_rep_data
*data
,
852 struct wpabuf
**wpa_buf
,
853 struct rrm_measurement_beacon_report
*rep
,
854 u8
**ie
, size_t *ie_len
, u8 idx
)
858 u32 subelems_len
= REPORTED_FRAME_BODY_SUBELEM_LEN
+
859 (data
->last_indication
?
860 BEACON_REPORT_LAST_INDICATION_SUBELEM_LEN
: 0);
862 /* Maximum element length: Beacon Report element + Reported Frame Body
863 * subelement + all IEs of the reported Beacon frame + Reported Frame
864 * Body Fragment ID subelement */
865 buf
= os_malloc(sizeof(*rep
) + 14 + *ie_len
+ subelems_len
);
869 os_memcpy(buf
, rep
, sizeof(*rep
));
871 ret
= wpas_beacon_rep_add_frame_body(data
->eids
, data
->report_detail
,
872 bss
, buf
+ sizeof(*rep
),
873 14 + *ie_len
, ie
, ie_len
,
878 pos
= buf
+ ret
+ sizeof(*rep
);
879 pos
[0] = WLAN_BEACON_REPORT_SUBELEM_FRAME_BODY_FRAGMENT_ID
;
883 * Only one Beacon Report Measurement is supported at a time, so
884 * the Beacon Report ID can always be set to 1.
888 /* Fragment ID Number (bits 0..6) and More Frame Body Fragments (bit 7)
891 if (data
->report_detail
!= BEACON_REPORT_DETAIL_NONE
&& *ie_len
)
892 pos
[3] |= REPORTED_FRAME_BODY_MORE_FRAGMENTS
;
894 pos
[3] &= ~REPORTED_FRAME_BODY_MORE_FRAGMENTS
;
896 pos
+= REPORTED_FRAME_BODY_SUBELEM_LEN
;
898 if (data
->last_indication
) {
899 pos
[0] = WLAN_BEACON_REPORT_SUBELEM_LAST_INDICATION
;
902 /* This field will be updated later if this is the last frame */
906 ret
= wpas_rrm_report_elem(wpa_buf
, data
->token
,
907 MEASUREMENT_REPORT_MODE_ACCEPT
,
908 MEASURE_TYPE_BEACON
, buf
,
909 ret
+ sizeof(*rep
) + subelems_len
);
916 static int wpas_add_beacon_rep(struct wpa_supplicant
*wpa_s
,
917 struct wpabuf
**wpa_buf
, struct wpa_bss
*bss
,
918 u64 start
, u64 parent_tsf
)
920 struct beacon_rep_data
*data
= &wpa_s
->beacon_rep_data
;
921 u8
*ies
= (u8
*) (bss
+ 1);
923 size_t ies_len
= bss
->ie_len
? bss
->ie_len
: bss
->beacon_ie_len
;
924 struct rrm_measurement_beacon_report rep
;
927 if (os_memcmp(data
->bssid
, broadcast_ether_addr
, ETH_ALEN
) != 0 &&
928 os_memcmp(data
->bssid
, bss
->bssid
, ETH_ALEN
) != 0)
931 if (data
->ssid_len
&&
932 (data
->ssid_len
!= bss
->ssid_len
||
933 os_memcmp(data
->ssid
, bss
->ssid
, bss
->ssid_len
) != 0))
936 if (wpas_get_op_chan_phy(bss
->freq
, ies
, ies_len
, &rep
.op_class
,
937 &rep
.channel
, &rep
.report_info
) < 0)
940 rep
.start_time
= host_to_le64(start
);
941 rep
.duration
= host_to_le16(data
->scan_params
.duration
);
942 rep
.rcpi
= rssi_to_rcpi(bss
->level
);
943 rep
.rsni
= 255; /* 255 indicates that RSNI is not available */
944 os_memcpy(rep
.bssid
, bss
->bssid
, ETH_ALEN
);
945 rep
.antenna_id
= 0; /* unknown */
946 rep
.parent_tsf
= host_to_le32(parent_tsf
);
951 ret
= wpas_add_beacon_rep_elem(data
, bss
, wpa_buf
, &rep
,
952 &pos
, &ies_len
, idx
++);
955 } while (data
->report_detail
!= BEACON_REPORT_DETAIL_NONE
&&
962 static int wpas_beacon_rep_no_results(struct wpa_supplicant
*wpa_s
,
965 return wpas_rrm_report_elem(buf
, wpa_s
->beacon_rep_data
.token
,
966 MEASUREMENT_REPORT_MODE_ACCEPT
,
967 MEASURE_TYPE_BEACON
, NULL
, 0);
971 static void wpas_beacon_rep_table(struct wpa_supplicant
*wpa_s
,
976 for (i
= 0; i
< wpa_s
->last_scan_res_used
; i
++) {
977 if (wpas_add_beacon_rep(wpa_s
, buf
, wpa_s
->last_scan_res
[i
],
983 wpas_beacon_rep_no_results(wpa_s
, buf
);
985 wpa_hexdump_buf(MSG_DEBUG
, "RRM: Radio Measurement report", *buf
);
989 void wpas_rrm_refuse_request(struct wpa_supplicant
*wpa_s
)
991 if (!is_multicast_ether_addr(wpa_s
->rrm
.dst_addr
)) {
992 struct wpabuf
*buf
= NULL
;
994 if (wpas_rrm_report_elem(&buf
, wpa_s
->beacon_rep_data
.token
,
995 MEASUREMENT_REPORT_MODE_REJECT_REFUSED
,
996 MEASURE_TYPE_BEACON
, NULL
, 0)) {
997 wpa_printf(MSG_ERROR
, "RRM: Memory allocation failed");
1002 wpas_rrm_send_msr_report(wpa_s
, buf
);
1006 wpas_clear_beacon_rep_data(wpa_s
);
1010 static void wpas_rrm_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
1012 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1013 struct wpa_driver_scan_params
*params
=
1014 &wpa_s
->beacon_rep_data
.scan_params
;
1015 u16 prev_duration
= params
->duration
;
1017 if (!wpa_s
->current_bss
)
1020 if (!(wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL
) &&
1022 wpa_printf(MSG_DEBUG
,
1023 "RRM: Cannot set scan duration due to missing driver support");
1024 params
->duration
= 0;
1026 os_get_reltime(&wpa_s
->beacon_rep_scan
);
1027 if (wpa_s
->scanning
|| wpas_p2p_in_progress(wpa_s
) ||
1028 wpa_supplicant_trigger_scan(wpa_s
, params
))
1029 wpas_rrm_refuse_request(wpa_s
);
1030 params
->duration
= prev_duration
;
1034 static int wpas_rm_handle_beacon_req_subelem(struct wpa_supplicant
*wpa_s
,
1035 struct beacon_rep_data
*data
,
1036 u8 sid
, u8 slen
, const u8
*subelem
)
1041 case WLAN_BEACON_REQUEST_SUBELEM_SSID
:
1043 wpa_printf(MSG_DEBUG
,
1044 "SSID subelement with zero length - wildcard SSID");
1048 if (slen
> SSID_MAX_LEN
) {
1049 wpa_printf(MSG_DEBUG
,
1050 "Invalid SSID subelement length: %u", slen
);
1054 data
->ssid_len
= slen
;
1055 os_memcpy(data
->ssid
, subelem
, data
->ssid_len
);
1057 case WLAN_BEACON_REQUEST_SUBELEM_INFO
:
1059 wpa_printf(MSG_DEBUG
,
1060 "Invalid reporting information subelement length: %u",
1065 report_info
= subelem
[0];
1066 if (report_info
!= 0) {
1067 wpa_printf(MSG_DEBUG
,
1068 "reporting information=%u is not supported",
1073 case WLAN_BEACON_REQUEST_SUBELEM_DETAIL
:
1075 wpa_printf(MSG_DEBUG
,
1076 "Invalid reporting detail subelement length: %u",
1081 data
->report_detail
= subelem
[0];
1082 if (data
->report_detail
>
1083 BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS
) {
1084 wpa_printf(MSG_DEBUG
, "Invalid reporting detail: %u",
1090 case WLAN_BEACON_REQUEST_SUBELEM_REQUEST
:
1091 if (data
->report_detail
!=
1092 BEACON_REPORT_DETAIL_REQUESTED_ONLY
) {
1093 wpa_printf(MSG_DEBUG
,
1094 "Beacon request: request subelement is present but report detail is %u",
1095 data
->report_detail
);
1100 wpa_printf(MSG_DEBUG
,
1101 "Invalid request subelement length: %u",
1107 wpa_printf(MSG_DEBUG
,
1108 "Beacon Request: Request subelement appears more than once");
1112 data
->eids
= bitfield_alloc(255);
1114 wpa_printf(MSG_DEBUG
, "Failed to allocate EIDs bitmap");
1118 for (i
= 0; i
< slen
; i
++)
1119 bitfield_set(data
->eids
, subelem
[i
]);
1121 case WLAN_BEACON_REQUEST_SUBELEM_AP_CHANNEL
:
1122 /* Skip - it will be processed when freqs are added */
1124 case WLAN_BEACON_REQUEST_SUBELEM_LAST_INDICATION
:
1126 wpa_printf(MSG_DEBUG
,
1127 "Beacon request: Invalid last indication request subelement length: %u",
1132 data
->last_indication
= subelem
[0];
1135 wpa_printf(MSG_DEBUG
,
1136 "Beacon request: Unknown subelement id %u", sid
);
1145 * Returns 0 if the next element can be processed, 1 if some operation was
1146 * triggered, and -1 if processing failed (i.e., the element is in invalid
1147 * format or an internal error occurred).
1150 wpas_rm_handle_beacon_req(struct wpa_supplicant
*wpa_s
,
1151 u8 elem_token
, int duration_mandatory
,
1152 const struct rrm_measurement_beacon_request
*req
,
1153 size_t len
, struct wpabuf
**buf
)
1155 struct beacon_rep_data
*data
= &wpa_s
->beacon_rep_data
;
1156 struct wpa_driver_scan_params
*params
= &data
->scan_params
;
1165 if (len
< sizeof(*req
))
1168 if (req
->mode
!= BEACON_REPORT_MODE_PASSIVE
&&
1169 req
->mode
!= BEACON_REPORT_MODE_ACTIVE
&&
1170 req
->mode
!= BEACON_REPORT_MODE_TABLE
)
1173 subelems
= req
->variable
;
1174 elems_len
= len
- sizeof(*req
);
1175 rand_interval
= le_to_host16(req
->rand_interval
);
1177 os_free(params
->freqs
);
1178 os_memset(params
, 0, sizeof(*params
));
1180 data
->token
= elem_token
;
1182 /* default reporting detail is all fixed length fields and all
1184 data
->report_detail
= BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS
;
1185 os_memcpy(data
->bssid
, req
->bssid
, ETH_ALEN
);
1187 while (elems_len
>= 2) {
1188 if (subelems
[1] > elems_len
- 2) {
1189 wpa_printf(MSG_DEBUG
,
1190 "Beacon Request: Truncated subelement");
1195 res
= wpas_rm_handle_beacon_req_subelem(
1196 wpa_s
, data
, subelems
[0], subelems
[1], &subelems
[2]);
1201 reject_mode
= MEASUREMENT_REPORT_MODE_REJECT_INCAPABLE
;
1205 elems_len
-= 2 + subelems
[1];
1206 subelems
+= 2 + subelems
[1];
1209 if (req
->mode
== BEACON_REPORT_MODE_TABLE
) {
1210 wpas_beacon_rep_table(wpa_s
, buf
);
1214 params
->freqs
= wpas_beacon_request_freqs(
1215 wpa_s
, req
->oper_class
, req
->channel
,
1216 req
->mode
== BEACON_REPORT_MODE_ACTIVE
,
1217 req
->variable
, len
- sizeof(*req
));
1218 if (!params
->freqs
) {
1219 wpa_printf(MSG_DEBUG
, "Beacon request: No valid channels");
1220 reject_mode
= MEASUREMENT_REPORT_MODE_REJECT_REFUSED
;
1224 params
->duration
= le_to_host16(req
->duration
);
1225 params
->duration_mandatory
= duration_mandatory
;
1226 if (!params
->duration
) {
1227 wpa_printf(MSG_DEBUG
, "Beacon request: Duration is 0");
1232 params
->only_new_results
= 1;
1234 if (req
->mode
== BEACON_REPORT_MODE_ACTIVE
) {
1235 params
->ssids
[params
->num_ssids
].ssid
= data
->ssid
;
1236 params
->ssids
[params
->num_ssids
++].ssid_len
= data
->ssid_len
;
1239 if (os_get_random((u8
*) &_rand
, sizeof(_rand
)) < 0)
1240 _rand
= os_random();
1241 interval_usec
= (_rand
% (rand_interval
+ 1)) * 1024;
1242 eloop_register_timeout(0, interval_usec
, wpas_rrm_scan_timeout
, wpa_s
,
1246 if (!is_multicast_ether_addr(wpa_s
->rrm
.dst_addr
) &&
1247 wpas_rrm_report_elem(buf
, elem_token
, reject_mode
,
1248 MEASURE_TYPE_BEACON
, NULL
, 0) < 0) {
1249 wpa_printf(MSG_DEBUG
, "RRM: Failed to add report element");
1253 wpas_clear_beacon_rep_data(wpa_s
);
1259 wpas_rrm_handle_msr_req_element(
1260 struct wpa_supplicant
*wpa_s
,
1261 const struct rrm_measurement_request_element
*req
,
1262 struct wpabuf
**buf
)
1264 int duration_mandatory
;
1266 wpa_printf(MSG_DEBUG
, "Measurement request type %d token %d",
1267 req
->type
, req
->token
);
1269 if (req
->mode
& MEASUREMENT_REQUEST_MODE_ENABLE
) {
1270 /* Enable bit is not supported for now */
1271 wpa_printf(MSG_DEBUG
, "RRM: Enable bit not supported, ignore");
1275 if ((req
->mode
& MEASUREMENT_REQUEST_MODE_PARALLEL
) &&
1276 req
->type
> MEASURE_TYPE_RPI_HIST
) {
1277 /* Parallel measurements are not supported for now */
1278 wpa_printf(MSG_DEBUG
,
1279 "RRM: Parallel measurements are not supported, reject");
1283 duration_mandatory
=
1284 !!(req
->mode
& MEASUREMENT_REQUEST_MODE_DURATION_MANDATORY
);
1286 switch (req
->type
) {
1287 case MEASURE_TYPE_LCI
:
1288 return wpas_rrm_build_lci_report(wpa_s
, req
, buf
);
1289 case MEASURE_TYPE_BEACON
:
1290 if (duration_mandatory
&&
1291 !(wpa_s
->drv_rrm_flags
&
1292 WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL
)) {
1293 wpa_printf(MSG_DEBUG
,
1294 "RRM: Driver does not support dwell time configuration - reject beacon report with mandatory duration");
1297 return wpas_rm_handle_beacon_req(wpa_s
, req
->token
,
1299 (const void *) req
->variable
,
1302 wpa_printf(MSG_INFO
,
1303 "RRM: Unsupported radio measurement type %u",
1309 if (!is_multicast_ether_addr(wpa_s
->rrm
.dst_addr
) &&
1310 wpas_rrm_report_elem(buf
, req
->token
,
1311 MEASUREMENT_REPORT_MODE_REJECT_INCAPABLE
,
1312 req
->type
, NULL
, 0) < 0) {
1313 wpa_printf(MSG_DEBUG
, "RRM: Failed to add report element");
1321 static struct wpabuf
*
1322 wpas_rrm_process_msr_req_elems(struct wpa_supplicant
*wpa_s
, const u8
*pos
,
1325 struct wpabuf
*buf
= NULL
;
1328 const struct rrm_measurement_request_element
*req
;
1332 wpa_printf(MSG_DEBUG
, "RRM: Truncated element");
1336 req
= (const struct rrm_measurement_request_element
*) pos
;
1337 if (req
->eid
!= WLAN_EID_MEASURE_REQUEST
) {
1338 wpa_printf(MSG_DEBUG
,
1339 "RRM: Expected Measurement Request element, but EID is %u",
1345 wpa_printf(MSG_DEBUG
, "RRM: Element length too short");
1349 if (req
->len
> len
- 2) {
1350 wpa_printf(MSG_DEBUG
, "RRM: Element length too long");
1354 res
= wpas_rrm_handle_msr_req_element(wpa_s
, req
, &buf
);
1358 pos
+= req
->len
+ 2;
1359 len
-= req
->len
+ 2;
1370 void wpas_rrm_handle_radio_measurement_request(struct wpa_supplicant
*wpa_s
,
1371 const u8
*src
, const u8
*dst
,
1372 const u8
*frame
, size_t len
)
1374 struct wpabuf
*report
;
1376 if (wpa_s
->wpa_state
!= WPA_COMPLETED
) {
1377 wpa_printf(MSG_INFO
,
1378 "RRM: Ignoring radio measurement request: Not associated");
1382 if (!wpa_s
->rrm
.rrm_used
) {
1383 wpa_printf(MSG_INFO
,
1384 "RRM: Ignoring radio measurement request: Not RRM network");
1389 wpa_printf(MSG_INFO
,
1390 "RRM: Ignoring too short radio measurement request");
1394 wpa_s
->rrm
.token
= *frame
;
1395 os_memcpy(wpa_s
->rrm
.dst_addr
, dst
, ETH_ALEN
);
1397 /* Number of repetitions is not supported */
1399 report
= wpas_rrm_process_msr_req_elems(wpa_s
, frame
+ 3, len
- 3);
1403 wpas_rrm_send_msr_report(wpa_s
, report
);
1404 wpabuf_free(report
);
1408 void wpas_rrm_handle_link_measurement_request(struct wpa_supplicant
*wpa_s
,
1410 const u8
*frame
, size_t len
,
1414 const struct rrm_link_measurement_request
*req
;
1415 struct rrm_link_measurement_report report
;
1417 if (wpa_s
->wpa_state
!= WPA_COMPLETED
) {
1418 wpa_printf(MSG_INFO
,
1419 "RRM: Ignoring link measurement request. Not associated");
1423 if (!wpa_s
->rrm
.rrm_used
) {
1424 wpa_printf(MSG_INFO
,
1425 "RRM: Ignoring link measurement request. Not RRM network");
1429 if (!(wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
)) {
1430 wpa_printf(MSG_INFO
,
1431 "RRM: Measurement report failed. TX power insertion not supported");
1435 req
= (const struct rrm_link_measurement_request
*) frame
;
1436 if (len
< sizeof(*req
)) {
1437 wpa_printf(MSG_INFO
,
1438 "RRM: Link measurement report failed. Request too short");
1442 os_memset(&report
, 0, sizeof(report
));
1443 report
.dialog_token
= req
->dialog_token
;
1444 report
.tpc
.eid
= WLAN_EID_TPC_REPORT
;
1446 /* Note: The driver is expected to update report.tpc.tx_power and
1447 * report.tpc.link_margin subfields when sending out this frame.
1448 * Similarly, the driver would need to update report.rx_ant_id and
1449 * report.tx_ant_id subfields. */
1450 report
.rsni
= 255; /* 255 indicates that RSNI is not available */
1451 report
.rcpi
= rssi_to_rcpi(rssi
);
1453 /* action_category + action_code */
1454 buf
= wpabuf_alloc(2 + sizeof(report
));
1456 wpa_printf(MSG_ERROR
,
1457 "RRM: Link measurement report failed. Buffer allocation failed");
1461 wpabuf_put_u8(buf
, WLAN_ACTION_RADIO_MEASUREMENT
);
1462 wpabuf_put_u8(buf
, WLAN_RRM_LINK_MEASUREMENT_REPORT
);
1463 wpabuf_put_data(buf
, &report
, sizeof(report
));
1464 wpa_hexdump_buf(MSG_DEBUG
, "RRM: Link measurement report", buf
);
1466 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, src
,
1467 wpa_s
->own_addr
, wpa_s
->bssid
,
1468 wpabuf_head(buf
), wpabuf_len(buf
), 0)) {
1469 wpa_printf(MSG_ERROR
,
1470 "RRM: Link measurement report failed. Send action failed");
1476 int wpas_beacon_rep_scan_process(struct wpa_supplicant
*wpa_s
,
1477 struct wpa_scan_results
*scan_res
,
1478 struct scan_info
*info
)
1481 struct wpabuf
*buf
= NULL
;
1483 if (!wpa_s
->beacon_rep_data
.token
)
1486 if (!wpa_s
->current_bss
)
1489 /* If the measurement was aborted, don't report partial results */
1493 wpa_printf(MSG_DEBUG
, "RRM: TSF BSSID: " MACSTR
" current BSS: " MACSTR
,
1494 MAC2STR(info
->scan_start_tsf_bssid
),
1495 MAC2STR(wpa_s
->current_bss
->bssid
));
1496 if ((wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT
) &&
1497 os_memcmp(info
->scan_start_tsf_bssid
, wpa_s
->current_bss
->bssid
,
1499 wpa_printf(MSG_DEBUG
,
1500 "RRM: Ignore scan results due to mismatching TSF BSSID");
1504 for (i
= 0; i
< scan_res
->num
; i
++) {
1505 struct wpa_bss
*bss
=
1506 wpa_bss_get_bssid(wpa_s
, scan_res
->res
[i
]->bssid
);
1511 if ((wpa_s
->drv_rrm_flags
&
1512 WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT
) &&
1513 os_memcmp(scan_res
->res
[i
]->tsf_bssid
,
1514 wpa_s
->current_bss
->bssid
, ETH_ALEN
) != 0) {
1515 wpa_printf(MSG_DEBUG
,
1516 "RRM: Ignore scan result for " MACSTR
1517 " due to mismatching TSF BSSID" MACSTR
,
1518 MAC2STR(scan_res
->res
[i
]->bssid
),
1519 MAC2STR(scan_res
->res
[i
]->tsf_bssid
));
1524 * Don't report results that were not received during the
1525 * current measurement.
1527 if (!(wpa_s
->drv_rrm_flags
&
1528 WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT
)) {
1529 struct os_reltime update_time
, diff
;
1531 /* For now, allow 8 ms older results due to some
1532 * unknown issue with cfg80211 BSS table updates during
1533 * a scan with the current BSS.
1534 * TODO: Fix this more properly to avoid having to have
1535 * this type of hacks in place. */
1536 calculate_update_time(&scan_res
->fetch_time
,
1537 scan_res
->res
[i
]->age
,
1539 os_reltime_sub(&wpa_s
->beacon_rep_scan
,
1540 &update_time
, &diff
);
1541 if (os_reltime_before(&update_time
,
1542 &wpa_s
->beacon_rep_scan
) &&
1543 (diff
.sec
|| diff
.usec
>= 8000)) {
1544 wpa_printf(MSG_DEBUG
,
1545 "RRM: Ignore scan result for " MACSTR
1546 " due to old update (age(ms) %u, calculated age %u.%06u seconds)",
1547 MAC2STR(scan_res
->res
[i
]->bssid
),
1548 scan_res
->res
[i
]->age
,
1549 (unsigned int) diff
.sec
,
1550 (unsigned int) diff
.usec
);
1553 } else if (info
->scan_start_tsf
>
1554 scan_res
->res
[i
]->parent_tsf
) {
1558 if (wpas_add_beacon_rep(wpa_s
, &buf
, bss
, info
->scan_start_tsf
,
1559 scan_res
->res
[i
]->parent_tsf
) < 0)
1563 if (!buf
&& wpas_beacon_rep_no_results(wpa_s
, &buf
))
1566 wpa_hexdump_buf(MSG_DEBUG
, "RRM: Radio Measurement report", buf
);
1568 wpas_rrm_send_msr_report(wpa_s
, buf
);
1572 wpas_clear_beacon_rep_data(wpa_s
);
1577 void wpas_clear_beacon_rep_data(struct wpa_supplicant
*wpa_s
)
1579 struct beacon_rep_data
*data
= &wpa_s
->beacon_rep_data
;
1581 eloop_cancel_timeout(wpas_rrm_scan_timeout
, wpa_s
, NULL
);
1582 bitfield_free(data
->eids
);
1583 os_free(data
->scan_params
.freqs
);
1584 os_memset(data
, 0, sizeof(*data
));