blob: 28e8cc9be3bb413233b1452cccfdb53af378b0c7 [file] [log] [blame]
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001/*
2 * hostapd / Radio Measurement (RRM)
3 * Copyright(c) 2013 - 2016 Intel Mobile Communications GmbH.
4 * Copyright(c) 2011 - 2016 Intel Corporation. All rights reserved.
Dmitry Shmidt29333592017-01-09 12:27:11 -08005 * Copyright (c) 2016-2017, Jouni Malinen <j@w1.fi>
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006 *
7 * This software may be distributed under the terms of the BSD license.
8 * See README for more details.
9 */
10
11#include "utils/includes.h"
12
13#include "utils/common.h"
Dmitry Shmidt29333592017-01-09 12:27:11 -080014#include "common/wpa_ctrl.h"
Dmitry Shmidt849734c2016-05-27 09:59:01 -070015#include "hostapd.h"
16#include "ap_drv_ops.h"
17#include "sta_info.h"
18#include "eloop.h"
19#include "neighbor_db.h"
20#include "rrm.h"
21
22#define HOSTAPD_RRM_REQUEST_TIMEOUT 5
23
24
25static void hostapd_lci_rep_timeout_handler(void *eloop_data, void *user_ctx)
26{
27 struct hostapd_data *hapd = eloop_data;
28
29 wpa_printf(MSG_DEBUG, "RRM: LCI request (token %u) timed out",
30 hapd->lci_req_token);
31 hapd->lci_req_active = 0;
32}
33
34
35static void hostapd_handle_lci_report(struct hostapd_data *hapd, u8 token,
36 const u8 *pos, size_t len)
37{
38 if (!hapd->lci_req_active || hapd->lci_req_token != token) {
39 wpa_printf(MSG_DEBUG, "Unexpected LCI report, token %u", token);
40 return;
41 }
42
43 hapd->lci_req_active = 0;
44 eloop_cancel_timeout(hostapd_lci_rep_timeout_handler, hapd, NULL);
45 wpa_printf(MSG_DEBUG, "LCI report token %u len %zu", token, len);
46}
47
48
49static void hostapd_range_rep_timeout_handler(void *eloop_data, void *user_ctx)
50{
51 struct hostapd_data *hapd = eloop_data;
52
53 wpa_printf(MSG_DEBUG, "RRM: Range request (token %u) timed out",
54 hapd->range_req_token);
55 hapd->range_req_active = 0;
56}
57
58
59static void hostapd_handle_range_report(struct hostapd_data *hapd, u8 token,
60 const u8 *pos, size_t len)
61{
62 if (!hapd->range_req_active || hapd->range_req_token != token) {
63 wpa_printf(MSG_DEBUG, "Unexpected range report, token %u",
64 token);
65 return;
66 }
67
68 hapd->range_req_active = 0;
69 eloop_cancel_timeout(hostapd_range_rep_timeout_handler, hapd, NULL);
70 wpa_printf(MSG_DEBUG, "Range report token %u len %zu", token, len);
71}
72
73
Dmitry Shmidt29333592017-01-09 12:27:11 -080074static void hostapd_handle_beacon_report(struct hostapd_data *hapd,
75 const u8 *addr, u8 token, u8 rep_mode,
76 const u8 *pos, size_t len)
77{
78 char report[2 * 255 + 1];
79
80 wpa_printf(MSG_DEBUG, "Beacon report token %u len %zu from " MACSTR,
81 token, len, MAC2STR(addr));
82 /* Skip to the beginning of the Beacon report */
83 if (len < 3)
84 return;
85 pos += 3;
86 len -= 3;
87 report[0] = '\0';
88 if (wpa_snprintf_hex(report, sizeof(report), pos, len) < 0)
89 return;
90 wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s",
91 MAC2STR(addr), token, rep_mode, report);
92}
93
94
Dmitry Shmidt849734c2016-05-27 09:59:01 -070095static void hostapd_handle_radio_msmt_report(struct hostapd_data *hapd,
96 const u8 *buf, size_t len)
97{
98 const struct ieee80211_mgmt *mgmt = (const struct ieee80211_mgmt *) buf;
99 const u8 *pos, *ie, *end;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800100 u8 token, rep_mode;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700101
102 end = buf + len;
103 token = mgmt->u.action.u.rrm.dialog_token;
104 pos = mgmt->u.action.u.rrm.variable;
105
106 while ((ie = get_ie(pos, end - pos, WLAN_EID_MEASURE_REPORT))) {
Dmitry Shmidt29333592017-01-09 12:27:11 -0800107 if (ie[1] < 3) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700108 wpa_printf(MSG_DEBUG, "Bad Measurement Report element");
109 break;
110 }
111
Dmitry Shmidt29333592017-01-09 12:27:11 -0800112 rep_mode = ie[3];
113 wpa_printf(MSG_DEBUG, "Measurement report mode 0x%x type %u",
114 rep_mode, ie[4]);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700115
116 switch (ie[4]) {
117 case MEASURE_TYPE_LCI:
118 hostapd_handle_lci_report(hapd, token, ie + 2, ie[1]);
119 break;
120 case MEASURE_TYPE_FTM_RANGE:
121 hostapd_handle_range_report(hapd, token, ie + 2, ie[1]);
122 break;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800123 case MEASURE_TYPE_BEACON:
124 hostapd_handle_beacon_report(hapd, mgmt->sa, token,
125 rep_mode, ie + 2, ie[1]);
126 break;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700127 default:
128 wpa_printf(MSG_DEBUG,
129 "Measurement report type %u is not supported",
130 ie[4]);
131 break;
132 }
133
134 pos = ie + ie[1] + 2;
135 }
136}
137
138
139static u16 hostapd_parse_location_lci_req_age(const u8 *buf, size_t len)
140{
141 const u8 *subelem;
142
143 /* Range Request element + Location Subject + Maximum Age subelement */
144 if (len < 3 + 1 + 4)
145 return 0;
146
147 /* Subelements are arranged as IEs */
148 subelem = get_ie(buf + 4, len - 4, LCI_REQ_SUBELEM_MAX_AGE);
149 if (subelem && subelem[1] == 2)
150 return *(u16 *) (subelem + 2);
151
152 return 0;
153}
154
155
156static int hostapd_check_lci_age(struct hostapd_neighbor_entry *nr, u16 max_age)
157{
158 struct os_time curr, diff;
159 unsigned long diff_l;
160
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800161 if (nr->stationary || max_age == 0xffff)
162 return 1;
163
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700164 if (!max_age)
165 return 0;
166
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700167 if (os_get_time(&curr))
168 return 0;
169
170 os_time_sub(&curr, &nr->lci_date, &diff);
171
172 /* avoid overflow */
173 if (diff.sec > 0xffff)
174 return 0;
175
176 /* LCI age is calculated in 10th of a second units. */
177 diff_l = diff.sec * 10 + diff.usec / 100000;
178
179 return max_age > diff_l;
180}
181
182
183static size_t hostapd_neighbor_report_len(struct wpabuf *buf,
184 struct hostapd_neighbor_entry *nr,
185 int send_lci, int send_civic)
186{
187 size_t len = 2 + wpabuf_len(nr->nr);
188
189 if (send_lci && nr->lci)
190 len += 2 + wpabuf_len(nr->lci);
191
192 if (send_civic && nr->civic)
193 len += 2 + wpabuf_len(nr->civic);
194
195 return len;
196}
197
198
199static void hostapd_send_nei_report_resp(struct hostapd_data *hapd,
200 const u8 *addr, u8 dialog_token,
201 struct wpa_ssid_value *ssid, u8 lci,
202 u8 civic, u16 lci_max_age)
203{
204 struct hostapd_neighbor_entry *nr;
205 struct wpabuf *buf;
206 u8 *msmt_token;
207
208 /*
209 * The number and length of the Neighbor Report elements in a Neighbor
210 * Report frame is limited by the maximum allowed MMPDU size; + 3 bytes
211 * of RRM header.
212 */
213 buf = wpabuf_alloc(3 + IEEE80211_MAX_MMPDU_SIZE);
214 if (!buf)
215 return;
216
217 wpabuf_put_u8(buf, WLAN_ACTION_RADIO_MEASUREMENT);
218 wpabuf_put_u8(buf, WLAN_RRM_NEIGHBOR_REPORT_RESPONSE);
219 wpabuf_put_u8(buf, dialog_token);
220
221 dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry,
222 list) {
223 int send_lci;
224 size_t len;
225
226 if (ssid->ssid_len != nr->ssid.ssid_len ||
227 os_memcmp(ssid->ssid, nr->ssid.ssid, ssid->ssid_len) != 0)
228 continue;
229
230 send_lci = (lci != 0) && hostapd_check_lci_age(nr, lci_max_age);
231 len = hostapd_neighbor_report_len(buf, nr, send_lci, civic);
232
233 if (len - 2 > 0xff) {
234 wpa_printf(MSG_DEBUG,
235 "NR entry for " MACSTR " exceeds 0xFF bytes",
236 MAC2STR(nr->bssid));
237 continue;
238 }
239
240 if (len > wpabuf_tailroom(buf))
241 break;
242
243 wpabuf_put_u8(buf, WLAN_EID_NEIGHBOR_REPORT);
244 wpabuf_put_u8(buf, len - 2);
245 wpabuf_put_buf(buf, nr->nr);
246
247 if (send_lci && nr->lci) {
248 wpabuf_put_u8(buf, WLAN_EID_MEASURE_REPORT);
249 wpabuf_put_u8(buf, wpabuf_len(nr->lci));
250 /*
251 * Override measurement token - the first byte of the
252 * Measurement Report element.
253 */
254 msmt_token = wpabuf_put(buf, 0);
255 wpabuf_put_buf(buf, nr->lci);
256 *msmt_token = lci;
257 }
258
259 if (civic && nr->civic) {
260 wpabuf_put_u8(buf, WLAN_EID_MEASURE_REPORT);
261 wpabuf_put_u8(buf, wpabuf_len(nr->civic));
262 /*
263 * Override measurement token - the first byte of the
264 * Measurement Report element.
265 */
266 msmt_token = wpabuf_put(buf, 0);
267 wpabuf_put_buf(buf, nr->civic);
268 *msmt_token = civic;
269 }
270 }
271
272 hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
273 wpabuf_head(buf), wpabuf_len(buf));
274 wpabuf_free(buf);
275}
276
277
278static void hostapd_handle_nei_report_req(struct hostapd_data *hapd,
279 const u8 *buf, size_t len)
280{
281 const struct ieee80211_mgmt *mgmt = (const struct ieee80211_mgmt *) buf;
282 const u8 *pos, *ie, *end;
283 struct wpa_ssid_value ssid = {
284 .ssid_len = 0
285 };
286 u8 token;
287 u8 lci = 0, civic = 0; /* Measurement tokens */
288 u16 lci_max_age = 0;
289
290 if (!(hapd->conf->radio_measurements[0] &
291 WLAN_RRM_CAPS_NEIGHBOR_REPORT))
292 return;
293
294 end = buf + len;
295
296 token = mgmt->u.action.u.rrm.dialog_token;
297 pos = mgmt->u.action.u.rrm.variable;
298 len = end - pos;
299
300 ie = get_ie(pos, len, WLAN_EID_SSID);
301 if (ie && ie[1] && ie[1] <= SSID_MAX_LEN) {
302 ssid.ssid_len = ie[1];
303 os_memcpy(ssid.ssid, ie + 2, ssid.ssid_len);
304 } else {
305 ssid.ssid_len = hapd->conf->ssid.ssid_len;
306 os_memcpy(ssid.ssid, hapd->conf->ssid.ssid, ssid.ssid_len);
307 }
308
309 while ((ie = get_ie(pos, len, WLAN_EID_MEASURE_REQUEST))) {
310 if (ie[1] < 3)
311 break;
312
313 wpa_printf(MSG_DEBUG,
314 "Neighbor report request, measure type %u",
315 ie[4]);
316
317 switch (ie[4]) { /* Measurement Type */
318 case MEASURE_TYPE_LCI:
319 lci = ie[2]; /* Measurement Token */
320 lci_max_age = hostapd_parse_location_lci_req_age(ie + 2,
321 ie[1]);
322 break;
323 case MEASURE_TYPE_LOCATION_CIVIC:
324 civic = ie[2]; /* Measurement token */
325 break;
326 }
327
328 pos = ie + ie[1] + 2;
329 len = end - pos;
330 }
331
332 hostapd_send_nei_report_resp(hapd, mgmt->sa, token, &ssid, lci, civic,
333 lci_max_age);
334}
335
336
337void hostapd_handle_radio_measurement(struct hostapd_data *hapd,
338 const u8 *buf, size_t len)
339{
340 const struct ieee80211_mgmt *mgmt = (const struct ieee80211_mgmt *) buf;
341
342 /*
343 * Check for enough bytes: header + (1B)Category + (1B)Action +
344 * (1B)Dialog Token.
345 */
346 if (len < IEEE80211_HDRLEN + 3)
347 return;
348
349 wpa_printf(MSG_DEBUG, "Radio measurement frame, action %u from " MACSTR,
350 mgmt->u.action.u.rrm.action, MAC2STR(mgmt->sa));
351
352 switch (mgmt->u.action.u.rrm.action) {
353 case WLAN_RRM_RADIO_MEASUREMENT_REPORT:
354 hostapd_handle_radio_msmt_report(hapd, buf, len);
355 break;
356 case WLAN_RRM_NEIGHBOR_REPORT_REQUEST:
357 hostapd_handle_nei_report_req(hapd, buf, len);
358 break;
359 default:
360 wpa_printf(MSG_DEBUG, "RRM action %u is not supported",
361 mgmt->u.action.u.rrm.action);
362 break;
363 }
364}
365
366
367int hostapd_send_lci_req(struct hostapd_data *hapd, const u8 *addr)
368{
369 struct wpabuf *buf;
370 struct sta_info *sta = ap_get_sta(hapd, addr);
371 int ret;
372
373 if (!sta) {
374 wpa_printf(MSG_INFO,
375 "Request LCI: Destination address is not in station list");
376 return -1;
377 }
378
379 if (!(sta->flags & WLAN_STA_AUTHORIZED)) {
380 wpa_printf(MSG_INFO,
381 "Request LCI: Destination address is not connected");
382 return -1;
383 }
384
385 if (!(sta->rrm_enabled_capa[1] & WLAN_RRM_CAPS_LCI_MEASUREMENT)) {
386 wpa_printf(MSG_INFO,
387 "Request LCI: Station does not support LCI in RRM");
388 return -1;
389 }
390
391 if (hapd->lci_req_active) {
392 wpa_printf(MSG_DEBUG,
393 "Request LCI: LCI request is already in process, overriding");
394 hapd->lci_req_active = 0;
395 eloop_cancel_timeout(hostapd_lci_rep_timeout_handler, hapd,
396 NULL);
397 }
398
399 /* Measurement request (5) + Measurement element with LCI (10) */
400 buf = wpabuf_alloc(5 + 10);
401 if (!buf)
402 return -1;
403
404 hapd->lci_req_token++;
405 /* For wraparounds - the token must be nonzero */
406 if (!hapd->lci_req_token)
407 hapd->lci_req_token++;
408
409 wpabuf_put_u8(buf, WLAN_ACTION_RADIO_MEASUREMENT);
410 wpabuf_put_u8(buf, WLAN_RRM_RADIO_MEASUREMENT_REQUEST);
411 wpabuf_put_u8(buf, hapd->lci_req_token);
412 wpabuf_put_le16(buf, 0); /* Number of repetitions */
413
414 wpabuf_put_u8(buf, WLAN_EID_MEASURE_REQUEST);
415 wpabuf_put_u8(buf, 3 + 1 + 4);
416
417 wpabuf_put_u8(buf, 1); /* Measurement Token */
418 /*
419 * Parallel and Enable bits are 0, Duration, Request, and Report are
420 * reserved.
421 */
422 wpabuf_put_u8(buf, 0);
423 wpabuf_put_u8(buf, MEASURE_TYPE_LCI);
424
425 wpabuf_put_u8(buf, LOCATION_SUBJECT_REMOTE);
426
427 wpabuf_put_u8(buf, LCI_REQ_SUBELEM_MAX_AGE);
428 wpabuf_put_u8(buf, 2);
429 wpabuf_put_le16(buf, 0xffff);
430
431 ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
432 wpabuf_head(buf), wpabuf_len(buf));
433 wpabuf_free(buf);
434 if (ret)
435 return ret;
436
437 hapd->lci_req_active = 1;
438
439 eloop_register_timeout(HOSTAPD_RRM_REQUEST_TIMEOUT, 0,
440 hostapd_lci_rep_timeout_handler, hapd, NULL);
441
442 return 0;
443}
444
445
446int hostapd_send_range_req(struct hostapd_data *hapd, const u8 *addr,
447 u16 random_interval, u8 min_ap,
448 const u8 *responders, unsigned int n_responders)
449{
450 struct wpabuf *buf;
451 struct sta_info *sta;
452 u8 *len;
453 unsigned int i;
454 int ret;
455
456 wpa_printf(MSG_DEBUG, "Request range: dest addr " MACSTR
457 " rand interval %u min AP %u n_responders %u", MAC2STR(addr),
458 random_interval, min_ap, n_responders);
459
460 if (min_ap == 0 || min_ap > n_responders) {
461 wpa_printf(MSG_INFO, "Request range: Wrong min AP count");
462 return -1;
463 }
464
465 sta = ap_get_sta(hapd, addr);
466 if (!sta || !(sta->flags & WLAN_STA_AUTHORIZED)) {
467 wpa_printf(MSG_INFO,
468 "Request range: Destination address is not connected");
469 return -1;
470 }
471
472 if (!(sta->rrm_enabled_capa[4] & WLAN_RRM_CAPS_FTM_RANGE_REPORT)) {
473 wpa_printf(MSG_ERROR,
474 "Request range: Destination station does not support FTM range report in RRM");
475 return -1;
476 }
477
478 if (hapd->range_req_active) {
479 wpa_printf(MSG_DEBUG,
480 "Request range: Range request is already in process; overriding");
481 hapd->range_req_active = 0;
482 eloop_register_timeout(HOSTAPD_RRM_REQUEST_TIMEOUT, 0,
483 hostapd_range_rep_timeout_handler, hapd,
484 NULL);
485 }
486
487 /* Action + measurement type + token + reps + EID + len = 7 */
488 buf = wpabuf_alloc(7 + 255);
489 if (!buf)
490 return -1;
491
492 hapd->range_req_token++;
493 if (!hapd->range_req_token) /* For wraparounds */
494 hapd->range_req_token++;
495
496 /* IEEE P802.11-REVmc/D5.0, 9.6.7.2 */
497 wpabuf_put_u8(buf, WLAN_ACTION_RADIO_MEASUREMENT);
498 wpabuf_put_u8(buf, WLAN_RRM_RADIO_MEASUREMENT_REQUEST);
499 wpabuf_put_u8(buf, hapd->range_req_token); /* Dialog Token */
500 wpabuf_put_le16(buf, 0); /* Number of Repetitions */
501
502 /* IEEE P802.11-REVmc/D5.0, 9.4.2.21 */
503 wpabuf_put_u8(buf, WLAN_EID_MEASURE_REQUEST);
504 len = wpabuf_put(buf, 1); /* Length will be set later */
505
506 wpabuf_put_u8(buf, 1); /* Measurement Token */
507 /*
508 * Parallel and Enable bits are 0; Duration, Request, and Report are
509 * reserved.
510 */
511 wpabuf_put_u8(buf, 0); /* Measurement Request Mode */
512 wpabuf_put_u8(buf, MEASURE_TYPE_FTM_RANGE); /* Measurement Type */
513
514 /* IEEE P802.11-REVmc/D5.0, 9.4.2.21.19 */
515 wpabuf_put_le16(buf, random_interval); /* Randomization Interval */
516 wpabuf_put_u8(buf, min_ap); /* Minimum AP Count */
517
518 /* FTM Range Subelements */
519
520 /*
521 * Taking the neighbor report part of the range request from neighbor
522 * database instead of requesting the separate bits of data from the
523 * user.
524 */
525 for (i = 0; i < n_responders; i++) {
526 struct hostapd_neighbor_entry *nr;
527
528 nr = hostapd_neighbor_get(hapd, responders + ETH_ALEN * i,
529 NULL);
530 if (!nr) {
531 wpa_printf(MSG_INFO, "Missing neighbor report for "
532 MACSTR, MAC2STR(responders + ETH_ALEN * i));
533 wpabuf_free(buf);
534 return -1;
535 }
536
537 if (wpabuf_tailroom(buf) < 2 + wpabuf_len(nr->nr)) {
538 wpa_printf(MSG_ERROR, "Too long range request");
539 wpabuf_free(buf);
540 return -1;
541 }
542
543 wpabuf_put_u8(buf, WLAN_EID_NEIGHBOR_REPORT);
544 wpabuf_put_u8(buf, wpabuf_len(nr->nr));
545 wpabuf_put_buf(buf, nr->nr);
546 }
547
548 /* Action + measurement type + token + reps + EID + len = 7 */
549 *len = wpabuf_len(buf) - 7;
550
551 ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
552 wpabuf_head(buf), wpabuf_len(buf));
553 wpabuf_free(buf);
554 if (ret)
555 return ret;
556
557 hapd->range_req_active = 1;
558
559 eloop_register_timeout(HOSTAPD_RRM_REQUEST_TIMEOUT, 0,
560 hostapd_range_rep_timeout_handler, hapd, NULL);
561
562 return 0;
563}
564
565
566void hostapd_clean_rrm(struct hostapd_data *hapd)
567{
568 hostpad_free_neighbor_db(hapd);
569 eloop_cancel_timeout(hostapd_lci_rep_timeout_handler, hapd, NULL);
570 hapd->lci_req_active = 0;
571 eloop_cancel_timeout(hostapd_range_rep_timeout_handler, hapd, NULL);
572 hapd->range_req_active = 0;
573}
Dmitry Shmidt29333592017-01-09 12:27:11 -0800574
575
576int hostapd_send_beacon_req(struct hostapd_data *hapd, const u8 *addr,
577 u8 req_mode, const struct wpabuf *req)
578{
579 struct wpabuf *buf;
580 struct sta_info *sta = ap_get_sta(hapd, addr);
581 int ret;
582 enum beacon_report_mode mode;
583 const u8 *pos;
584
585 /* Request data:
586 * Operating Class (1), Channel Number (1), Randomization Interval (2),
587 * Measurement Duration (2), Measurement Mode (1), BSSID (6),
588 * Optional Subelements (variable)
589 */
590 if (wpabuf_len(req) < 13) {
591 wpa_printf(MSG_INFO, "Beacon request: Too short request data");
592 return -1;
593 }
594 pos = wpabuf_head(req);
595 mode = pos[6];
596
597 if (!sta || !(sta->flags & WLAN_STA_AUTHORIZED)) {
598 wpa_printf(MSG_INFO,
599 "Beacon request: " MACSTR " is not connected",
600 MAC2STR(addr));
601 return -1;
602 }
603
604 switch (mode) {
605 case BEACON_REPORT_MODE_PASSIVE:
606 if (!(sta->rrm_enabled_capa[0] &
607 WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE)) {
608 wpa_printf(MSG_INFO,
609 "Beacon request: " MACSTR
610 " does not support passive beacon report",
611 MAC2STR(addr));
612 return -1;
613 }
614 break;
615 case BEACON_REPORT_MODE_ACTIVE:
616 if (!(sta->rrm_enabled_capa[0] &
617 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE)) {
618 wpa_printf(MSG_INFO,
619 "Beacon request: " MACSTR
620 " does not support active beacon report",
621 MAC2STR(addr));
622 return -1;
623 }
624 break;
625 case BEACON_REPORT_MODE_TABLE:
626 if (!(sta->rrm_enabled_capa[0] &
627 WLAN_RRM_CAPS_BEACON_REPORT_TABLE)) {
628 wpa_printf(MSG_INFO,
629 "Beacon request: " MACSTR
630 " does not support table beacon report",
631 MAC2STR(addr));
632 return -1;
633 }
634 break;
635 default:
636 wpa_printf(MSG_INFO,
637 "Beacon request: Unknown measurement mode %d", mode);
638 return -1;
639 }
640
641 buf = wpabuf_alloc(5 + 2 + 3 + wpabuf_len(req));
642 if (!buf)
643 return -1;
644
645 hapd->beacon_req_token++;
646 if (!hapd->beacon_req_token)
647 hapd->beacon_req_token++;
648
649 wpabuf_put_u8(buf, WLAN_ACTION_RADIO_MEASUREMENT);
650 wpabuf_put_u8(buf, WLAN_RRM_RADIO_MEASUREMENT_REQUEST);
651 wpabuf_put_u8(buf, hapd->beacon_req_token);
652 wpabuf_put_le16(buf, 0); /* Number of repetitions */
653
654 /* Measurement Request element */
655 wpabuf_put_u8(buf, WLAN_EID_MEASURE_REQUEST);
656 wpabuf_put_u8(buf, 3 + wpabuf_len(req));
657 wpabuf_put_u8(buf, 1); /* Measurement Token */
658 wpabuf_put_u8(buf, req_mode); /* Measurement Request Mode */
659 wpabuf_put_u8(buf, MEASURE_TYPE_BEACON); /* Measurement Type */
660 wpabuf_put_buf(buf, req);
661
662 ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
663 wpabuf_head(buf), wpabuf_len(buf));
664 wpabuf_free(buf);
665 if (ret < 0)
666 return ret;
667
668 return hapd->beacon_req_token;
669}
670
671
672void hostapd_rrm_beacon_req_tx_status(struct hostapd_data *hapd,
673 const struct ieee80211_mgmt *mgmt,
674 size_t len, int ok)
675{
676 if (len < 24 + 3)
677 return;
678 wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_REQ_TX_STATUS MACSTR
679 " %u ack=%d", MAC2STR(mgmt->da),
680 mgmt->u.action.u.rrm.dialog_token, ok);
681}