Coverage Report

Created: 2025-10-10 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hostap/wpa_supplicant/rrm.c
Line
Count
Source
1
/*
2
 * wpa_supplicant - Radio Measurements
3
 * Copyright (c) 2003-2016, Jouni Malinen <j@w1.fi>
4
 *
5
 * This software may be distributed under the terms of the BSD license.
6
 * See README for more details.
7
 */
8
9
#include "includes.h"
10
11
#include "utils/common.h"
12
#include "utils/eloop.h"
13
#include "common/ieee802_11_common.h"
14
#include "wpa_supplicant_i.h"
15
#include "driver_i.h"
16
#include "bss.h"
17
#include "scan.h"
18
#include "p2p_supplicant.h"
19
20
21
static void wpas_rrm_neighbor_rep_timeout_handler(void *data, void *user_ctx)
22
0
{
23
0
  struct rrm_data *rrm = data;
24
25
0
  if (!rrm->notify_neighbor_rep) {
26
0
    wpa_printf(MSG_ERROR,
27
0
         "RRM: Unexpected neighbor report timeout");
28
0
    return;
29
0
  }
30
31
0
  wpa_printf(MSG_DEBUG, "RRM: Notifying neighbor report - NONE");
32
0
  rrm->notify_neighbor_rep(rrm->neighbor_rep_cb_ctx, NULL);
33
34
0
  rrm->notify_neighbor_rep = NULL;
35
0
  rrm->neighbor_rep_cb_ctx = NULL;
36
0
}
37
38
39
/*
40
 * wpas_rrm_reset - Clear and reset all RRM data in wpa_supplicant
41
 * @wpa_s: Pointer to wpa_supplicant
42
 */
43
void wpas_rrm_reset(struct wpa_supplicant *wpa_s)
44
0
{
45
0
  wpa_s->rrm.rrm_used = 0;
46
47
0
  eloop_cancel_timeout(wpas_rrm_neighbor_rep_timeout_handler, &wpa_s->rrm,
48
0
           NULL);
49
0
  if (wpa_s->rrm.notify_neighbor_rep)
50
0
    wpas_rrm_neighbor_rep_timeout_handler(&wpa_s->rrm, NULL);
51
0
  wpa_s->rrm.next_neighbor_rep_token = 1;
52
0
  wpas_clear_beacon_rep_data(wpa_s);
53
0
}
54
55
56
/*
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
61
 */
62
void wpas_rrm_process_neighbor_rep(struct wpa_supplicant *wpa_s,
63
           const u8 *report, size_t report_len)
64
0
{
65
0
  struct wpabuf *neighbor_rep;
66
67
0
  wpa_hexdump(MSG_DEBUG, "RRM: New Neighbor Report", report, report_len);
68
0
  if (report_len < 1)
69
0
    return;
70
71
0
  if (report[0] != wpa_s->rrm.next_neighbor_rep_token - 1) {
72
0
    wpa_printf(MSG_DEBUG,
73
0
         "RRM: Discarding neighbor report with token %d (expected %d)",
74
0
         report[0], wpa_s->rrm.next_neighbor_rep_token - 1);
75
0
    return;
76
0
  }
77
78
0
  eloop_cancel_timeout(wpas_rrm_neighbor_rep_timeout_handler, &wpa_s->rrm,
79
0
           NULL);
80
81
0
  if (!wpa_s->rrm.notify_neighbor_rep) {
82
0
    wpa_msg(wpa_s, MSG_INFO, "RRM: Unexpected neighbor report");
83
0
    return;
84
0
  }
85
86
  /* skipping the first byte, which is only an id (dialog token) */
87
0
  neighbor_rep = wpabuf_alloc(report_len - 1);
88
0
  if (!neighbor_rep) {
89
0
    wpas_rrm_neighbor_rep_timeout_handler(&wpa_s->rrm, NULL);
90
0
    return;
91
0
  }
92
0
  wpabuf_put_data(neighbor_rep, report + 1, report_len - 1);
93
0
  wpa_dbg(wpa_s, MSG_DEBUG, "RRM: Notifying neighbor report (token = %d)",
94
0
    report[0]);
95
0
  wpa_s->rrm.notify_neighbor_rep(wpa_s->rrm.neighbor_rep_cb_ctx,
96
0
               neighbor_rep);
97
0
  wpa_s->rrm.notify_neighbor_rep = NULL;
98
0
  wpa_s->rrm.neighbor_rep_cb_ctx = NULL;
99
0
}
100
101
102
#if defined(__CYGWIN__) || defined(CONFIG_NATIVE_WINDOWS)
103
/* Workaround different, undefined for Windows, error codes used here */
104
#ifndef ENOTCONN
105
#define ENOTCONN -1
106
#endif
107
#ifndef EOPNOTSUPP
108
#define EOPNOTSUPP -1
109
#endif
110
#ifndef ECANCELED
111
#define ECANCELED -1
112
#endif
113
#endif
114
115
/* Measurement Request element + Location Subject + Maximum Age subelement */
116
0
#define MEASURE_REQUEST_LCI_LEN (3 + 1 + 4)
117
/* Measurement Request element + Location Civic Request */
118
0
#define MEASURE_REQUEST_CIVIC_LEN (3 + 5)
119
120
121
/**
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
135
 *
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.
139
 */
140
int wpas_rrm_send_neighbor_rep_request(struct wpa_supplicant *wpa_s,
141
               const struct wpa_ssid_value *ssid,
142
               int lci, int civic,
143
               void (*cb)(void *ctx,
144
              struct wpabuf *neighbor_rep),
145
               void *cb_ctx)
146
0
{
147
0
  struct wpabuf *buf;
148
0
  const u8 *rrm_ie;
149
150
0
  if (wpa_s->wpa_state != WPA_COMPLETED || wpa_s->current_ssid == NULL) {
151
0
    wpa_dbg(wpa_s, MSG_DEBUG, "RRM: No connection, no RRM.");
152
0
    return -ENOTCONN;
153
0
  }
154
155
0
  if (!wpa_s->rrm.rrm_used) {
156
0
    wpa_dbg(wpa_s, MSG_DEBUG, "RRM: No RRM in current connection.");
157
0
    return -EOPNOTSUPP;
158
0
  }
159
160
0
  rrm_ie = wpa_bss_get_ie(wpa_s->current_bss,
161
0
        WLAN_EID_RRM_ENABLED_CAPABILITIES);
162
0
  if (!rrm_ie || !(wpa_s->current_bss->caps & IEEE80211_CAP_RRM) ||
163
0
      rrm_ie[1] < 1 ||
164
0
      !(rrm_ie[2] & WLAN_RRM_CAPS_NEIGHBOR_REPORT)) {
165
0
    wpa_dbg(wpa_s, MSG_DEBUG,
166
0
      "RRM: No network support for Neighbor Report.");
167
0
    return -EOPNOTSUPP;
168
0
  }
169
170
  /* Refuse if there's a live request */
171
0
  if (wpa_s->rrm.notify_neighbor_rep) {
172
0
    wpa_dbg(wpa_s, MSG_DEBUG,
173
0
      "RRM: Currently handling previous Neighbor Report.");
174
0
    return -EBUSY;
175
0
  }
176
177
  /* 3 = action category + action code + dialog token */
178
0
  buf = wpabuf_alloc(3 + (ssid ? 2 + ssid->ssid_len : 0) +
179
0
         (lci ? 2 + MEASURE_REQUEST_LCI_LEN : 0) +
180
0
         (civic ? 2 + MEASURE_REQUEST_CIVIC_LEN : 0));
181
0
  if (buf == NULL) {
182
0
    wpa_dbg(wpa_s, MSG_DEBUG,
183
0
      "RRM: Failed to allocate Neighbor Report Request");
184
0
    return -ENOMEM;
185
0
  }
186
187
0
  wpa_dbg(wpa_s, MSG_DEBUG,
188
0
    "RRM: Neighbor report request (for %s), token=%d",
189
0
    (ssid ? wpa_ssid_txt(ssid->ssid, ssid->ssid_len) : ""),
190
0
    wpa_s->rrm.next_neighbor_rep_token);
191
192
  /*
193
   * According to IEEE Std 802.11-2024, 11.10.10.2 (Requesting a neighbor
194
   * report) LCI and civic requests depend on FTM responder support.
195
   */
196
0
  if (lci || civic) {
197
0
    const u8 *ext_capab;
198
199
0
    ext_capab = wpa_bss_get_ie(wpa_s->current_bss,
200
0
             WLAN_EID_EXT_CAPAB);
201
0
    if (!ieee802_11_ext_capab(ext_capab,
202
0
            WLAN_EXT_CAPAB_FTM_RESPONDER)) {
203
0
      wpa_printf(MSG_DEBUG,
204
0
           "AP doesn't support FTM responder, can't request LCI and civic");
205
0
      lci = 0;
206
0
      civic = 0;
207
0
    }
208
0
  }
209
210
0
  wpabuf_put_u8(buf, WLAN_ACTION_RADIO_MEASUREMENT);
211
0
  wpabuf_put_u8(buf, WLAN_RRM_NEIGHBOR_REPORT_REQUEST);
212
0
  wpabuf_put_u8(buf, wpa_s->rrm.next_neighbor_rep_token);
213
0
  if (ssid) {
214
0
    wpabuf_put_u8(buf, WLAN_EID_SSID);
215
0
    wpabuf_put_u8(buf, ssid->ssid_len);
216
0
    wpabuf_put_data(buf, ssid->ssid, ssid->ssid_len);
217
0
  }
218
219
0
  if (lci && rrm_ie[1] >= 2 &&
220
0
      (rrm_ie[3] & WLAN_RRM_CAPS_LCI_MEASUREMENT)) {
221
    /* IEEE Std 802.11-2024, 9.4.2.19 (Measurement Request element)
222
     */
223
0
    wpabuf_put_u8(buf, WLAN_EID_MEASURE_REQUEST);
224
0
    wpabuf_put_u8(buf, MEASURE_REQUEST_LCI_LEN);
225
226
    /*
227
     * Measurement token; nonzero number that is unique among the
228
     * Measurement Request elements in a particular frame.
229
     */
230
0
    wpabuf_put_u8(buf, 1); /* Measurement Token */
231
232
    /*
233
     * Parallel, Enable, Request, and Report bits are 0, Duration is
234
     * reserved.
235
     */
236
0
    wpabuf_put_u8(buf, 0); /* Measurement Request Mode */
237
0
    wpabuf_put_u8(buf, MEASURE_TYPE_LCI); /* Measurement Type */
238
239
    /* IEEE Std 802.11-2024, 9.4.2.19.10 (LCI request) */
240
    /* Location Subject */
241
0
    wpabuf_put_u8(buf, LOCATION_SUBJECT_REMOTE);
242
243
    /* Optional Subelements */
244
    /*
245
     * IEEE Std 802.11-2024, Figure 9-265 (Maximum Age subelement
246
     * format)
247
     * The Maximum Age subelement is required, otherwise the AP can
248
     * send only data that was determined after receiving the
249
     * request. Setting it here to unlimited age.
250
     */
251
0
    wpabuf_put_u8(buf, LCI_REQ_SUBELEM_MAX_AGE);
252
0
    wpabuf_put_u8(buf, 2);
253
0
    wpabuf_put_le16(buf, 0xffff);
254
0
  } else if (lci) {
255
0
    wpa_printf(MSG_DEBUG, "RRM: LCI request isn't supported by AP");
256
0
  }
257
258
0
  if (civic && rrm_ie[1] >= 5 &&
259
0
      (rrm_ie[6] & WLAN_RRM_CAPS_CIVIC_LOCATION_MEASUREMENT)) {
260
    /* IEEE Std 802.11-2024, 9.4.2.19 (Measurement Request element)
261
     */
262
0
    wpabuf_put_u8(buf, WLAN_EID_MEASURE_REQUEST);
263
0
    wpabuf_put_u8(buf, MEASURE_REQUEST_CIVIC_LEN);
264
265
    /*
266
     * Measurement token; nonzero number that is unique among the
267
     * Measurement Request elements in a particular frame.
268
     */
269
0
    wpabuf_put_u8(buf, 2); /* Measurement Token */
270
271
    /*
272
     * Parallel, Enable, Request, and Report bits are 0, Duration is
273
     * reserved.
274
     */
275
0
    wpabuf_put_u8(buf, 0); /* Measurement Request Mode */
276
    /* Measurement Type */
277
0
    wpabuf_put_u8(buf, MEASURE_TYPE_LOCATION_CIVIC);
278
279
    /* IEEE Std 802.11-2024, 9.4.2.19.14 (Location Civic request) */
280
    /* Location Subject */
281
0
    wpabuf_put_u8(buf, LOCATION_SUBJECT_REMOTE);
282
0
    wpabuf_put_u8(buf, 0); /* Civic Location Type: IETF RFC 4776 */
283
    /* Location Service Interval Units: Seconds */
284
0
    wpabuf_put_u8(buf, 0);
285
    /* Location Service Interval: 0 - Only one report is requested
286
     */
287
0
    wpabuf_put_le16(buf, 0);
288
    /* No optional subelements */
289
0
  } else if (civic) {
290
0
    wpa_printf(MSG_DEBUG,
291
0
         "RRM: Civic request isn't supported by AP");
292
0
  }
293
294
0
  wpa_s->rrm.next_neighbor_rep_token++;
295
296
0
  if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
297
0
        wpa_s->own_addr, wpa_s->bssid,
298
0
        wpabuf_head(buf), wpabuf_len(buf), 0) < 0) {
299
0
    wpa_dbg(wpa_s, MSG_DEBUG,
300
0
      "RRM: Failed to send Neighbor Report Request");
301
0
    wpabuf_free(buf);
302
0
    return -ECANCELED;
303
0
  }
304
305
0
  wpa_s->rrm.neighbor_rep_cb_ctx = cb_ctx;
306
0
  wpa_s->rrm.notify_neighbor_rep = cb;
307
0
  eloop_register_timeout(RRM_NEIGHBOR_REPORT_TIMEOUT, 0,
308
0
             wpas_rrm_neighbor_rep_timeout_handler,
309
0
             &wpa_s->rrm, NULL);
310
311
0
  wpabuf_free(buf);
312
0
  return 0;
313
0
}
314
315
316
static int wpas_rrm_report_elem(struct wpabuf **buf, u8 token, u8 mode, u8 type,
317
        const u8 *data, size_t data_len)
318
0
{
319
0
  if (wpabuf_resize(buf, 5 + data_len))
320
0
    return -1;
321
322
0
  wpabuf_put_u8(*buf, WLAN_EID_MEASURE_REPORT);
323
0
  wpabuf_put_u8(*buf, 3 + data_len);
324
0
  wpabuf_put_u8(*buf, token);
325
0
  wpabuf_put_u8(*buf, mode);
326
0
  wpabuf_put_u8(*buf, type);
327
328
0
  if (data_len)
329
0
    wpabuf_put_data(*buf, data, data_len);
330
331
0
  return 0;
332
0
}
333
334
335
static int
336
wpas_rrm_build_lci_report(struct wpa_supplicant *wpa_s,
337
        const struct rrm_measurement_request_element *req,
338
        struct wpabuf **buf)
339
0
{
340
0
  u8 subject;
341
0
  u16 max_age = 0;
342
0
  struct os_reltime t, diff;
343
0
  unsigned long diff_l;
344
0
  const u8 *subelem;
345
0
  const u8 *request = req->variable;
346
0
  size_t len = req->len - 3;
347
348
0
  if (len < 1)
349
0
    return -1;
350
351
0
  if (!wpa_s->lci)
352
0
    goto reject;
353
354
0
  subject = *request++;
355
0
  len--;
356
357
0
  wpa_printf(MSG_DEBUG, "Measurement request location subject=%u",
358
0
       subject);
359
360
0
  if (subject != LOCATION_SUBJECT_REMOTE) {
361
0
    wpa_printf(MSG_INFO,
362
0
         "Not building LCI report - bad location subject");
363
0
    return 0;
364
0
  }
365
366
  /* Subelements are formatted exactly like elements */
367
0
  wpa_hexdump(MSG_DEBUG, "LCI request subelements", request, len);
368
0
  subelem = get_ie(request, len, LCI_REQ_SUBELEM_MAX_AGE);
369
0
  if (subelem && subelem[1] == 2)
370
0
    max_age = WPA_GET_LE16(subelem + 2);
371
372
0
  if (os_get_reltime(&t))
373
0
    goto reject;
374
375
0
  os_reltime_sub(&t, &wpa_s->lci_time, &diff);
376
  /* LCI age is calculated in 10th of a second units. */
377
0
  diff_l = diff.sec * 10 + diff.usec / 100000;
378
379
0
  if (max_age != 0xffff && max_age < diff_l)
380
0
    goto reject;
381
382
0
  if (wpas_rrm_report_elem(buf, req->token,
383
0
         MEASUREMENT_REPORT_MODE_ACCEPT, req->type,
384
0
         wpabuf_head_u8(wpa_s->lci),
385
0
         wpabuf_len(wpa_s->lci)) < 0) {
386
0
    wpa_printf(MSG_DEBUG, "Failed to add LCI report element");
387
0
    return -1;
388
0
  }
389
390
0
  return 0;
391
392
0
reject:
393
0
  if (!is_multicast_ether_addr(wpa_s->rrm.dst_addr) &&
394
0
      wpas_rrm_report_elem(buf, req->token,
395
0
         MEASUREMENT_REPORT_MODE_REJECT_INCAPABLE,
396
0
         req->type, NULL, 0) < 0) {
397
0
    wpa_printf(MSG_DEBUG, "RRM: Failed to add report element");
398
0
    return -1;
399
0
  }
400
401
0
  return 0;
402
0
}
403
404
405
static void wpas_rrm_send_msr_report_mpdu(struct wpa_supplicant *wpa_s,
406
            const u8 *data, size_t len)
407
0
{
408
0
  struct wpabuf *report = wpabuf_alloc(len + 3);
409
410
0
  if (!report)
411
0
    return;
412
413
0
  wpabuf_put_u8(report, WLAN_ACTION_RADIO_MEASUREMENT);
414
0
  wpabuf_put_u8(report, WLAN_RRM_RADIO_MEASUREMENT_REPORT);
415
0
  wpabuf_put_u8(report, wpa_s->rrm.token);
416
417
0
  wpabuf_put_data(report, data, len);
418
419
0
  if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
420
0
        wpa_s->own_addr, wpa_s->bssid,
421
0
        wpabuf_head(report), wpabuf_len(report), 0)) {
422
0
    wpa_printf(MSG_ERROR,
423
0
         "RRM: Radio measurement report failed: Sending Action frame failed");
424
0
  }
425
426
0
  wpabuf_free(report);
427
0
}
428
429
430
static int wpas_rrm_beacon_rep_update_last_frame(u8 *pos, size_t len)
431
0
{
432
0
  struct rrm_measurement_report_element *msr_rep;
433
0
  u8 *end = pos + len;
434
0
  u8 *msr_rep_end;
435
0
  struct rrm_measurement_beacon_report *rep = NULL;
436
0
  u8 *subelem;
437
438
  /* Find the last beacon report element */
439
0
  while (end - pos >= (int) sizeof(*msr_rep)) {
440
0
    msr_rep = (struct rrm_measurement_report_element *) pos;
441
0
    msr_rep_end = pos + msr_rep->len + 2;
442
443
0
    if (msr_rep->eid != WLAN_EID_MEASURE_REPORT ||
444
0
        msr_rep_end > end) {
445
      /* Should not happen. This indicates a bug. */
446
0
      wpa_printf(MSG_ERROR,
447
0
           "RRM: non-measurement report element in measurement report frame");
448
0
      return -1;
449
0
    }
450
451
0
    if (msr_rep->type == MEASURE_TYPE_BEACON)
452
0
      rep = (struct rrm_measurement_beacon_report *)
453
0
        msr_rep->variable;
454
455
0
    pos += pos[1] + 2;
456
0
  }
457
458
0
  if (!rep)
459
0
    return 0;
460
461
0
  subelem = rep->variable;
462
0
  while (subelem + 2 < msr_rep_end &&
463
0
         subelem[0] != WLAN_BEACON_REPORT_SUBELEM_LAST_INDICATION)
464
0
    subelem += 2 + subelem[1];
465
466
0
  if (subelem + 2 < msr_rep_end &&
467
0
      subelem[0] == WLAN_BEACON_REPORT_SUBELEM_LAST_INDICATION &&
468
0
      subelem[1] == 1 &&
469
0
      subelem + BEACON_REPORT_LAST_INDICATION_SUBELEM_LEN <= end)
470
0
    subelem[2] = 1;
471
472
0
  return 0;
473
0
}
474
475
476
static void wpas_rrm_send_msr_report(struct wpa_supplicant *wpa_s,
477
             struct wpabuf *buf)
478
0
{
479
0
  int len = wpabuf_len(buf);
480
0
  u8 *pos = wpabuf_mhead_u8(buf), *next = pos;
481
482
0
#define MPDU_REPORT_LEN (int) (IEEE80211_MAX_MMPDU_SIZE - IEEE80211_HDRLEN - 3)
483
484
0
  while (len) {
485
0
    int send_len = (len > MPDU_REPORT_LEN) ? next - pos : len;
486
487
0
    if (send_len == len)
488
0
      wpas_rrm_beacon_rep_update_last_frame(pos, len);
489
490
0
    if (send_len == len ||
491
0
        (send_len + next[1] + 2) > MPDU_REPORT_LEN) {
492
0
      wpas_rrm_send_msr_report_mpdu(wpa_s, pos, send_len);
493
0
      len -= send_len;
494
0
      pos = next;
495
0
    }
496
497
0
    if (len)
498
0
      next += next[1] + 2;
499
0
  }
500
0
#undef MPDU_REPORT_LEN
501
0
}
502
503
504
static int wpas_add_channel(u8 op_class, u8 chan, u8 num_primary_channels,
505
          int *freqs)
506
0
{
507
0
  size_t i;
508
509
0
  for (i = 0; i < num_primary_channels; i++) {
510
0
    u8 primary_chan = chan - (2 * num_primary_channels - 2) + i * 4;
511
512
0
    freqs[i] = ieee80211_chan_to_freq(NULL, op_class, primary_chan);
513
    /* ieee80211_chan_to_freq() is not really meant for this
514
     * conversion of 20 MHz primary channel numbers for wider VHT
515
     * channels, so handle those as special cases here for now. */
516
0
    if (freqs[i] < 0 &&
517
0
        (op_class == 128 || op_class == 129 || op_class == 130))
518
0
      freqs[i] = 5000 + 5 * primary_chan;
519
0
    if (freqs[i] < 0) {
520
0
      wpa_printf(MSG_DEBUG,
521
0
           "Beacon Report: Invalid channel %u",
522
0
           chan);
523
0
      return -1;
524
0
    }
525
0
  }
526
527
0
  return 0;
528
0
}
529
530
531
static int * wpas_add_channels(const struct oper_class_map *op,
532
             struct hostapd_hw_modes *mode,
533
             const u8 *channels, const u8 size)
534
0
{
535
0
  int *freqs, *next_freq;
536
0
  u8 num_primary_channels, i;
537
0
  u8 num_chans;
538
539
0
  num_chans = channels ? size :
540
0
    (op->max_chan - op->min_chan) / op->inc + 1;
541
542
0
  if (op->bw == BW80 || op->bw == BW80P80)
543
0
    num_primary_channels = 4;
544
0
  else if (op->bw == BW160)
545
0
    num_primary_channels = 8;
546
0
  else if (op->bw == BW320)
547
0
    num_primary_channels = 16;
548
0
  else
549
0
    num_primary_channels = 1;
550
551
  /* one extra place for the zero-terminator */
552
0
  freqs = os_calloc(num_chans * num_primary_channels + 1, sizeof(*freqs));
553
0
  if (!freqs) {
554
0
    wpa_printf(MSG_ERROR,
555
0
         "Beacon Report: Failed to allocate freqs array");
556
0
    return NULL;
557
0
  }
558
559
0
  next_freq = freqs;
560
0
  for  (i = 0; i < num_chans; i++) {
561
0
    u8 chan = channels ? channels[i] : op->min_chan + i * op->inc;
562
0
    enum chan_allowed res = verify_channel(mode, op->op_class, chan,
563
0
                   op->bw);
564
565
0
    if (res == NOT_ALLOWED)
566
0
      continue;
567
568
0
    if (wpas_add_channel(op->op_class, chan, num_primary_channels,
569
0
             next_freq) < 0) {
570
0
      os_free(freqs);
571
0
      return NULL;
572
0
    }
573
574
0
    next_freq += num_primary_channels;
575
0
  }
576
577
0
  if (!freqs[0]) {
578
0
    os_free(freqs);
579
0
    return NULL;
580
0
  }
581
582
0
  return freqs;
583
0
}
584
585
586
static int * wpas_op_class_freqs(const struct oper_class_map *op,
587
         struct hostapd_hw_modes *mode)
588
0
{
589
0
  u8 channels_80mhz_5ghz[] = { 42, 58, 106, 122, 138, 155, 171 };
590
0
  u8 channels_160mhz_5ghz[] = { 50, 114, 163 };
591
0
  u8 channels_80mhz_6ghz[] = { 7, 23, 39, 55, 71, 87, 103, 119, 135, 151,
592
0
             167, 183, 199, 215 };
593
0
  u8 channels_160mhz_6ghz[] = { 15, 47, 79, 111, 143, 175, 207 };
594
0
  u8 channels_320mhz_6ghz[] = { 31, 63, 95, 127, 159, 191 };
595
0
  const u8 *channels = NULL;
596
0
  size_t num_chan = 0;
597
0
  bool is_6ghz = is_6ghz_op_class(op->op_class);
598
599
  /*
600
   * When adding all channels in the operating class, 80 + 80 MHz
601
   * operating classes are like 80 MHz channels because we add all valid
602
   * channels anyway.
603
   */
604
0
  if (op->bw == BW80 || op->bw == BW80P80) {
605
0
    channels = is_6ghz ? channels_80mhz_6ghz : channels_80mhz_5ghz;
606
0
    num_chan = is_6ghz ? ARRAY_SIZE(channels_80mhz_6ghz) :
607
0
      ARRAY_SIZE(channels_80mhz_5ghz);
608
0
  } else if (op->bw == BW160) {
609
0
    channels = is_6ghz ? channels_160mhz_6ghz :
610
0
      channels_160mhz_5ghz;
611
0
    num_chan =  is_6ghz ? ARRAY_SIZE(channels_160mhz_6ghz) :
612
0
      ARRAY_SIZE(channels_160mhz_5ghz);
613
0
  } else if (op->bw == BW320) {
614
0
    channels = channels_320mhz_6ghz;
615
0
    num_chan = ARRAY_SIZE(channels_320mhz_6ghz);
616
0
  }
617
618
0
  return wpas_add_channels(op, mode, channels, num_chan);
619
0
}
620
621
622
static int * wpas_channel_report_freqs(struct wpa_supplicant *wpa_s,
623
               const char *country, const u8 *subelems,
624
               size_t len)
625
0
{
626
0
  int *freqs = NULL, *new_freqs;
627
0
  const u8 *end = subelems + len;
628
629
0
  while (end - subelems > 2) {
630
0
    const struct oper_class_map *op;
631
0
    const u8 *ap_chan_elem, *pos;
632
0
    u8 left;
633
0
    struct hostapd_hw_modes *mode;
634
635
0
    ap_chan_elem = get_ie(subelems, end - subelems,
636
0
              WLAN_BEACON_REQUEST_SUBELEM_AP_CHANNEL);
637
0
    if (!ap_chan_elem)
638
0
      break;
639
0
    pos = ap_chan_elem + 2;
640
0
    left = ap_chan_elem[1];
641
0
    if (left < 1)
642
0
      break;
643
0
    subelems = ap_chan_elem + 2 + left;
644
645
0
    op = get_oper_class(country, *pos);
646
0
    if (!op) {
647
0
      wpa_printf(MSG_DEBUG,
648
0
           "Beacon request: unknown operating class in AP Channel Report subelement %u",
649
0
           *pos);
650
0
      goto out;
651
0
    }
652
0
    pos++;
653
0
    left--;
654
655
0
    mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, op->mode,
656
0
        is_6ghz_op_class(op->op_class));
657
0
    if (!mode)
658
0
      continue;
659
660
    /*
661
     * For 80 + 80 MHz operating classes, this AP Channel Report
662
     * element should be followed by another element specifying
663
     * the second 80 MHz channel. For now just add this 80 MHz
664
     * channel, the second 80 MHz channel will be added when the
665
     * next element is parsed.
666
     * TODO: Verify that this AP Channel Report element is followed
667
     * by a corresponding AP Channel Report element as specified in
668
     * IEEE Std 802.11-2016, 11.11.9.1.
669
     */
670
0
    new_freqs = wpas_add_channels(op, mode, pos, left);
671
0
    if (new_freqs)
672
0
      int_array_concat(&freqs, new_freqs);
673
674
0
    os_free(new_freqs);
675
0
  }
676
677
0
  return freqs;
678
0
out:
679
0
  os_free(freqs);
680
0
  return NULL;
681
0
}
682
683
684
static int * wpas_beacon_request_freqs(struct wpa_supplicant *wpa_s,
685
               u8 op_class, u8 chan,
686
               const u8 *subelems, size_t len)
687
0
{
688
0
  int *freqs = NULL, *ext_freqs = NULL;
689
0
  struct hostapd_hw_modes *mode;
690
0
  const char *country = NULL;
691
0
  const struct oper_class_map *op;
692
0
  const u8 *elem;
693
694
0
  if (!wpa_s->current_bss)
695
0
    return NULL;
696
0
  elem = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_COUNTRY);
697
0
  if (elem && elem[1] >= 2)
698
0
    country = (const char *) (elem + 2);
699
700
0
  op = get_oper_class(country, op_class);
701
0
  if (!op) {
702
0
    wpa_printf(MSG_DEBUG,
703
0
         "Beacon request: invalid operating class %d",
704
0
         op_class);
705
0
    return NULL;
706
0
  }
707
708
0
  mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, op->mode,
709
0
      is_6ghz_op_class(op->op_class));
710
0
  if (!mode)
711
0
    return NULL;
712
713
0
  switch (chan) {
714
0
  case 0:
715
0
    freqs = wpas_op_class_freqs(op, mode);
716
0
    if (!freqs)
717
0
      return NULL;
718
0
    break;
719
0
  case 255:
720
    /* freqs will be added from AP channel subelements */
721
0
    break;
722
0
  default:
723
0
    freqs = wpas_add_channels(op, mode, &chan, 1);
724
0
    if (!freqs)
725
0
      return NULL;
726
0
    break;
727
0
  }
728
729
0
  ext_freqs = wpas_channel_report_freqs(wpa_s, country, subelems, len);
730
0
  if (ext_freqs) {
731
0
    int_array_concat(&freqs, ext_freqs);
732
0
    os_free(ext_freqs);
733
0
    int_array_sort_unique(freqs);
734
0
  }
735
736
0
  return freqs;
737
0
}
738
739
740
int wpas_get_op_chan_phy(int freq, const u8 *ies, size_t ies_len,
741
       u8 *op_class, u8 *chan, u8 *phy_type)
742
0
{
743
0
  const u8 *ie;
744
0
  int sec_chan = 0, vht = 0;
745
0
  struct ieee80211_ht_operation *ht_oper = NULL;
746
0
  struct ieee80211_vht_operation *vht_oper = NULL;
747
0
  u8 seg0, seg1;
748
749
0
  ie = get_ie(ies, ies_len, WLAN_EID_HT_OPERATION);
750
0
  if (ie && ie[1] >= sizeof(struct ieee80211_ht_operation)) {
751
0
    u8 sec_chan_offset;
752
753
0
    ht_oper = (struct ieee80211_ht_operation *) (ie + 2);
754
0
    sec_chan_offset = ht_oper->ht_param &
755
0
      HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
756
0
    if (sec_chan_offset == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
757
0
      sec_chan = 1;
758
0
    else if (sec_chan_offset ==
759
0
       HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
760
0
      sec_chan = -1;
761
0
  }
762
763
0
  ie = get_ie(ies, ies_len, WLAN_EID_VHT_OPERATION);
764
0
  if (ie && ie[1] >= sizeof(struct ieee80211_vht_operation)) {
765
0
    vht_oper = (struct ieee80211_vht_operation *) (ie + 2);
766
767
0
    switch (vht_oper->vht_op_info_chwidth) {
768
0
    case CHANWIDTH_80MHZ:
769
0
      seg0 = vht_oper->vht_op_info_chan_center_freq_seg0_idx;
770
0
      seg1 = vht_oper->vht_op_info_chan_center_freq_seg1_idx;
771
0
      if (seg1 && abs(seg1 - seg0) == 8)
772
0
        vht = CONF_OPER_CHWIDTH_160MHZ;
773
0
      else if (seg1)
774
0
        vht = CONF_OPER_CHWIDTH_80P80MHZ;
775
0
      else
776
0
        vht = CONF_OPER_CHWIDTH_80MHZ;
777
0
      break;
778
0
    case CHANWIDTH_160MHZ:
779
0
      vht = CONF_OPER_CHWIDTH_160MHZ;
780
0
      break;
781
0
    case CHANWIDTH_80P80MHZ:
782
0
      vht = CONF_OPER_CHWIDTH_80P80MHZ;
783
0
      break;
784
0
    default:
785
0
      vht = CONF_OPER_CHWIDTH_USE_HT;
786
0
      break;
787
0
    }
788
0
  }
789
790
0
  if (ieee80211_freq_to_channel_ext(freq, sec_chan, vht, op_class,
791
0
            chan) == NUM_HOSTAPD_MODES) {
792
0
    wpa_printf(MSG_DEBUG,
793
0
         "Cannot determine operating class and channel");
794
0
    return -1;
795
0
  }
796
797
0
  *phy_type = ieee80211_get_phy_type(freq, ht_oper != NULL,
798
0
             vht_oper != NULL);
799
0
  if (*phy_type == PHY_TYPE_UNSPECIFIED) {
800
0
    wpa_printf(MSG_DEBUG, "Cannot determine phy type");
801
0
    return -1;
802
0
  }
803
804
0
  return 0;
805
0
}
806
807
808
static int wpas_beacon_rep_add_frame_body(struct bitfield *eids,
809
            struct bitfield *ext_eids,
810
            enum beacon_report_detail detail,
811
            struct wpa_bss *bss, u8 *buf,
812
            size_t buf_len, const u8 **ies_buf,
813
            size_t *ie_len, int add_fixed)
814
0
{
815
0
  const u8 *ies = *ies_buf;
816
0
  size_t ies_len = *ie_len;
817
0
  u8 *pos = buf;
818
0
  int rem_len;
819
820
0
  rem_len = 255 - sizeof(struct rrm_measurement_beacon_report) -
821
0
    sizeof(struct rrm_measurement_report_element) - 2 -
822
0
    REPORTED_FRAME_BODY_SUBELEM_LEN;
823
824
0
  if (detail > BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS) {
825
0
    wpa_printf(MSG_DEBUG,
826
0
         "Beacon Request: Invalid reporting detail: %d",
827
0
         detail);
828
0
    return -1;
829
0
  }
830
831
0
  if (detail == BEACON_REPORT_DETAIL_NONE)
832
0
    return 0;
833
834
  /*
835
   * Minimal frame body subelement size: EID(1) + length(1) + TSF(8) +
836
   * beacon interval(2) + capabilities(2) = 14 bytes
837
   */
838
0
  if (add_fixed && buf_len < 14)
839
0
    return -1;
840
841
0
  *pos++ = WLAN_BEACON_REPORT_SUBELEM_FRAME_BODY;
842
  /* The length will be filled later */
843
0
  pos++;
844
845
0
  if (add_fixed) {
846
0
    WPA_PUT_LE64(pos, bss->tsf);
847
0
    pos += sizeof(bss->tsf);
848
0
    WPA_PUT_LE16(pos, bss->beacon_int);
849
0
    pos += 2;
850
0
    WPA_PUT_LE16(pos, bss->caps);
851
0
    pos += 2;
852
0
  }
853
854
0
  rem_len -= pos - buf;
855
856
  /*
857
   * According to IEEE Std 802.11-2016, 9.4.2.22.7, if the reported frame
858
   * body subelement causes the element to exceed the maximum element
859
   * size, the subelement is truncated so that the last IE is a complete
860
   * IE. So even when required to report all IEs, add elements one after
861
   * the other and stop once there is no more room in the measurement
862
   * element.
863
   */
864
0
  while (ies_len > 2 && 2U + ies[1] <= ies_len && rem_len > 0) {
865
0
    if (detail == BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS ||
866
0
        (eids && bitfield_is_set(eids, ies[0])) ||
867
0
        (ext_eids && ies[0] == WLAN_EID_EXTENSION && ies[1] &&
868
0
         bitfield_is_set(ext_eids, ies[2]))) {
869
0
      u8 elen = ies[1];
870
871
0
      if (2 + elen > buf + buf_len - pos ||
872
0
          2 + elen > rem_len)
873
0
        break;
874
875
0
      *pos++ = ies[0];
876
0
      *pos++ = elen;
877
0
      os_memcpy(pos, ies + 2, elen);
878
0
      pos += elen;
879
0
      rem_len -= 2 + elen;
880
0
    }
881
882
0
    ies_len -= 2 + ies[1];
883
0
    ies += 2 + ies[1];
884
0
  }
885
886
0
  *ie_len = ies_len;
887
0
  *ies_buf = ies;
888
889
  /* Now the length is known */
890
0
  buf[1] = pos - buf - 2;
891
0
  return pos - buf;
892
0
}
893
894
895
static int wpas_add_beacon_rep_elem(struct beacon_rep_data *data,
896
            struct wpa_bss *bss,
897
            struct wpabuf **wpa_buf,
898
            struct rrm_measurement_beacon_report *rep,
899
            const u8 **ie, size_t *ie_len, u8 idx)
900
0
{
901
0
  int ret;
902
0
  u8 *buf, *pos;
903
0
  u32 subelems_len = REPORTED_FRAME_BODY_SUBELEM_LEN +
904
0
    (data->last_indication ?
905
0
     BEACON_REPORT_LAST_INDICATION_SUBELEM_LEN : 0);
906
907
  /* Maximum element length: Beacon Report element + Reported Frame Body
908
   * subelement + all IEs of the reported Beacon frame + Reported Frame
909
   * Body Fragment ID subelement */
910
0
  buf = os_malloc(sizeof(*rep) + 14 + *ie_len + subelems_len);
911
0
  if (!buf)
912
0
    return -1;
913
914
0
  os_memcpy(buf, rep, sizeof(*rep));
915
916
0
  ret = wpas_beacon_rep_add_frame_body(data->eids, data->ext_eids,
917
0
               data->report_detail,
918
0
               bss, buf + sizeof(*rep),
919
0
               14 + *ie_len, ie, ie_len,
920
0
               idx == 0);
921
0
  if (ret < 0)
922
0
    goto out;
923
924
0
  pos = buf + ret + sizeof(*rep);
925
0
  pos[0] = WLAN_BEACON_REPORT_SUBELEM_FRAME_BODY_FRAGMENT_ID;
926
0
  pos[1] = 2;
927
928
  /*
929
   * Only one Beacon Report Measurement is supported at a time, so
930
   * the Beacon Report ID can always be set to 1.
931
   */
932
0
  pos[2] = 1;
933
934
  /* Fragment ID Number (bits 0..6) and More Frame Body Fragments (bit 7)
935
 */
936
0
  pos[3] = idx;
937
0
  if (data->report_detail != BEACON_REPORT_DETAIL_NONE && *ie_len)
938
0
    pos[3] |= REPORTED_FRAME_BODY_MORE_FRAGMENTS;
939
0
  else
940
0
    pos[3] &= ~REPORTED_FRAME_BODY_MORE_FRAGMENTS;
941
942
0
  pos += REPORTED_FRAME_BODY_SUBELEM_LEN;
943
944
0
  if (data->last_indication) {
945
0
    pos[0] = WLAN_BEACON_REPORT_SUBELEM_LAST_INDICATION;
946
0
    pos[1] = 1;
947
948
    /* This field will be updated later if this is the last frame */
949
0
    pos[2] = 0;
950
0
  }
951
952
0
  ret = wpas_rrm_report_elem(wpa_buf, data->token,
953
0
           MEASUREMENT_REPORT_MODE_ACCEPT,
954
0
           MEASURE_TYPE_BEACON, buf,
955
0
           ret + sizeof(*rep) + subelems_len);
956
0
out:
957
0
  os_free(buf);
958
0
  return ret;
959
0
}
960
961
962
static int wpas_add_beacon_rep(struct wpa_supplicant *wpa_s,
963
             struct wpabuf **wpa_buf, struct wpa_bss *bss,
964
             u64 start, u64 parent_tsf)
965
0
{
966
0
  struct beacon_rep_data *data = &wpa_s->beacon_rep_data;
967
0
  const u8 *ies = wpa_bss_ie_ptr(bss);
968
0
  const u8 *pos = ies;
969
0
  size_t ies_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
970
0
  struct rrm_measurement_beacon_report rep;
971
0
  u8 idx = 0;
972
973
0
  if (!ether_addr_equal(data->bssid, broadcast_ether_addr) &&
974
0
      !ether_addr_equal(data->bssid, bss->bssid))
975
0
    return 0;
976
977
0
  if (data->ssid_len &&
978
0
      (data->ssid_len != bss->ssid_len ||
979
0
       os_memcmp(data->ssid, bss->ssid, bss->ssid_len) != 0))
980
0
    return 0;
981
982
0
  if (wpas_get_op_chan_phy(bss->freq, ies, ies_len, &rep.op_class,
983
0
         &rep.channel, &rep.report_info) < 0)
984
0
    return 0;
985
986
0
  rep.start_time = host_to_le64(start);
987
0
  rep.duration = host_to_le16(data->scan_params.duration);
988
0
  rep.rcpi = rssi_to_rcpi(bss->level);
989
0
  rep.rsni = 255; /* 255 indicates that RSNI is not available */
990
0
  os_memcpy(rep.bssid, bss->bssid, ETH_ALEN);
991
0
  rep.antenna_id = 0; /* unknown */
992
0
  rep.parent_tsf = host_to_le32(parent_tsf);
993
994
0
  do {
995
0
    int ret;
996
997
0
    ret = wpas_add_beacon_rep_elem(data, bss, wpa_buf, &rep,
998
0
                 &pos, &ies_len, idx++);
999
0
    if (ret)
1000
0
      return ret;
1001
0
  } while (data->report_detail != BEACON_REPORT_DETAIL_NONE &&
1002
0
     ies_len >= 2);
1003
1004
0
  return 0;
1005
0
}
1006
1007
1008
static int wpas_beacon_rep_no_results(struct wpa_supplicant *wpa_s,
1009
              struct wpabuf **buf)
1010
0
{
1011
0
  return wpas_rrm_report_elem(buf, wpa_s->beacon_rep_data.token,
1012
0
            MEASUREMENT_REPORT_MODE_ACCEPT,
1013
0
            MEASURE_TYPE_BEACON, NULL, 0);
1014
0
}
1015
1016
1017
static void wpas_beacon_rep_table(struct wpa_supplicant *wpa_s,
1018
          struct wpabuf **buf)
1019
0
{
1020
0
  size_t i;
1021
1022
0
  for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1023
0
    if (wpas_add_beacon_rep(wpa_s, buf, wpa_s->last_scan_res[i],
1024
0
          0, 0) < 0)
1025
0
      break;
1026
0
  }
1027
1028
0
  if (!(*buf))
1029
0
    wpas_beacon_rep_no_results(wpa_s, buf);
1030
1031
0
  wpa_hexdump_buf(MSG_DEBUG, "RRM: Radio Measurement report", *buf);
1032
0
}
1033
1034
1035
void wpas_rrm_refuse_request(struct wpa_supplicant *wpa_s)
1036
0
{
1037
0
  if (!is_multicast_ether_addr(wpa_s->rrm.dst_addr)) {
1038
0
    struct wpabuf *buf = NULL;
1039
1040
0
    if (wpas_rrm_report_elem(&buf, wpa_s->beacon_rep_data.token,
1041
0
           MEASUREMENT_REPORT_MODE_REJECT_REFUSED,
1042
0
           MEASURE_TYPE_BEACON, NULL, 0)) {
1043
0
      wpa_printf(MSG_ERROR, "RRM: Memory allocation failed");
1044
0
      wpabuf_free(buf);
1045
0
      return;
1046
0
    }
1047
1048
0
    wpas_rrm_send_msr_report(wpa_s, buf);
1049
0
    wpabuf_free(buf);
1050
0
  }
1051
1052
0
  wpas_clear_beacon_rep_data(wpa_s);
1053
0
}
1054
1055
1056
static void wpas_rrm_scan_timeout(void *eloop_ctx, void *timeout_ctx)
1057
0
{
1058
0
  struct wpa_supplicant *wpa_s = eloop_ctx;
1059
0
  struct wpa_driver_scan_params *params =
1060
0
    &wpa_s->beacon_rep_data.scan_params;
1061
0
  u16 prev_duration = params->duration;
1062
1063
0
  if (!wpa_s->current_bss)
1064
0
    return;
1065
1066
0
  if (!(wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL) &&
1067
0
      params->duration) {
1068
0
    wpa_printf(MSG_DEBUG,
1069
0
         "RRM: Cannot set scan duration due to missing driver support");
1070
0
    params->duration = 0;
1071
0
  }
1072
0
  os_get_reltime(&wpa_s->beacon_rep_scan);
1073
0
  if (wpa_s->scanning || wpas_p2p_in_progress(wpa_s) ||
1074
0
      wpa_supplicant_trigger_scan(wpa_s, params, true, false))
1075
0
    wpas_rrm_refuse_request(wpa_s);
1076
0
  params->duration = prev_duration;
1077
0
}
1078
1079
1080
static int wpas_rm_handle_beacon_req_subelem(struct wpa_supplicant *wpa_s,
1081
               struct beacon_rep_data *data,
1082
               u8 sid, u8 slen, const u8 *subelem)
1083
0
{
1084
0
  struct bitfield *eids;
1085
0
  u8 report_info, i;
1086
1087
0
  switch (sid) {
1088
0
  case WLAN_BEACON_REQUEST_SUBELEM_SSID:
1089
0
    if (!slen) {
1090
0
      wpa_printf(MSG_DEBUG,
1091
0
           "SSID subelement with zero length - wildcard SSID");
1092
0
      break;
1093
0
    }
1094
1095
0
    if (slen > SSID_MAX_LEN) {
1096
0
      wpa_printf(MSG_DEBUG,
1097
0
           "Invalid SSID subelement length: %u", slen);
1098
0
      return -1;
1099
0
    }
1100
1101
0
    data->ssid_len = slen;
1102
0
    os_memcpy(data->ssid, subelem, data->ssid_len);
1103
0
    break;
1104
0
  case WLAN_BEACON_REQUEST_SUBELEM_INFO:
1105
0
    if (slen != 2) {
1106
0
      wpa_printf(MSG_DEBUG,
1107
0
           "Invalid reporting information subelement length: %u",
1108
0
           slen);
1109
0
      return -1;
1110
0
    }
1111
1112
0
    report_info = subelem[0];
1113
0
    if (report_info != 0) {
1114
0
      wpa_printf(MSG_DEBUG,
1115
0
           "reporting information=%u is not supported",
1116
0
           report_info);
1117
0
      return 0;
1118
0
    }
1119
0
    break;
1120
0
  case WLAN_BEACON_REQUEST_SUBELEM_DETAIL:
1121
0
    if (slen != 1) {
1122
0
      wpa_printf(MSG_DEBUG,
1123
0
           "Invalid reporting detail subelement length: %u",
1124
0
           slen);
1125
0
      return -1;
1126
0
    }
1127
1128
0
    data->report_detail = subelem[0];
1129
0
    if (data->report_detail >
1130
0
        BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS) {
1131
0
      wpa_printf(MSG_DEBUG, "Invalid reporting detail: %u",
1132
0
           subelem[0]);
1133
0
      return -1;
1134
0
    }
1135
1136
0
    break;
1137
0
  case WLAN_BEACON_REQUEST_SUBELEM_REQUEST:
1138
0
  case WLAN_BEACON_REQUEST_SUBELEM_EXT_REQUEST:
1139
0
    if (data->report_detail !=
1140
0
        BEACON_REPORT_DETAIL_REQUESTED_ONLY) {
1141
0
      wpa_printf(MSG_DEBUG,
1142
0
           "Beacon request: request subelement is present but report detail is %u",
1143
0
           data->report_detail);
1144
0
      return -1;
1145
0
    }
1146
1147
0
    if (!slen) {
1148
0
      wpa_printf(MSG_DEBUG,
1149
0
           "Invalid request subelement length: %u",
1150
0
           slen);
1151
0
      return -1;
1152
0
    }
1153
1154
0
    if (sid == WLAN_BEACON_REQUEST_SUBELEM_EXT_REQUEST) {
1155
0
      if (slen < 2) {
1156
0
        wpa_printf(MSG_DEBUG,
1157
0
             "Invalid extended request");
1158
0
        return -1;
1159
0
      }
1160
0
      if (subelem[0] != WLAN_EID_EXTENSION) {
1161
0
        wpa_printf(MSG_DEBUG,
1162
0
             "Skip unknown Requested Element ID %u in Extended Request subelement",
1163
0
             subelem[0]);
1164
0
        break;
1165
0
      }
1166
1167
      /* Skip the Requested Element ID field */
1168
0
      subelem++;
1169
0
      slen--;
1170
0
    }
1171
1172
0
    if ((sid == WLAN_BEACON_REQUEST_SUBELEM_REQUEST &&
1173
0
         data->eids) ||
1174
0
        (sid == WLAN_BEACON_REQUEST_SUBELEM_EXT_REQUEST &&
1175
0
        data->ext_eids)) {
1176
0
      wpa_printf(MSG_DEBUG,
1177
0
           "Beacon Request: Request sub elements appear more than once");
1178
0
      return -1;
1179
0
    }
1180
1181
0
    eids = bitfield_alloc(255);
1182
0
    if (!eids) {
1183
0
      wpa_printf(MSG_DEBUG, "Failed to allocate EIDs bitmap");
1184
0
      return -1;
1185
0
    }
1186
1187
0
    if (sid == WLAN_BEACON_REQUEST_SUBELEM_REQUEST)
1188
0
      data->eids = eids;
1189
0
    else
1190
0
      data->ext_eids = eids;
1191
1192
0
    for (i = 0; i < slen; i++)
1193
0
      bitfield_set(eids, subelem[i]);
1194
0
    break;
1195
0
  case WLAN_BEACON_REQUEST_SUBELEM_AP_CHANNEL:
1196
    /* Skip - it will be processed when freqs are added */
1197
0
    break;
1198
0
  case WLAN_BEACON_REQUEST_SUBELEM_LAST_INDICATION:
1199
0
    if (slen != 1) {
1200
0
      wpa_printf(MSG_DEBUG,
1201
0
           "Beacon request: Invalid last indication request subelement length: %u",
1202
0
           slen);
1203
0
      return -1;
1204
0
    }
1205
1206
0
    data->last_indication = subelem[0];
1207
0
    break;
1208
0
  default:
1209
0
    wpa_printf(MSG_DEBUG,
1210
0
         "Beacon request: Unknown subelement id %u", sid);
1211
0
    break;
1212
0
  }
1213
1214
0
  return 1;
1215
0
}
1216
1217
1218
/**
1219
 * Returns 0 if the next element can be processed, 1 if some operation was
1220
 * triggered, and -1 if processing failed (i.e., the element is in invalid
1221
 * format or an internal error occurred).
1222
 */
1223
static int
1224
wpas_rm_handle_beacon_req(struct wpa_supplicant *wpa_s,
1225
        u8 elem_token, int duration_mandatory,
1226
        const struct rrm_measurement_beacon_request *req,
1227
        size_t len, struct wpabuf **buf)
1228
0
{
1229
0
  struct beacon_rep_data *data = &wpa_s->beacon_rep_data;
1230
0
  struct wpa_driver_scan_params *params = &data->scan_params;
1231
0
  const u8 *subelems;
1232
0
  size_t elems_len;
1233
0
  u16 rand_interval;
1234
0
  u32 interval_usec;
1235
0
  u32 _rand;
1236
0
  int ret = 0, res;
1237
0
  u8 reject_mode;
1238
1239
0
  if (len < sizeof(*req))
1240
0
    return -1;
1241
1242
0
  if (req->mode != BEACON_REPORT_MODE_PASSIVE &&
1243
0
      req->mode != BEACON_REPORT_MODE_ACTIVE &&
1244
0
      req->mode != BEACON_REPORT_MODE_TABLE)
1245
0
    return 0;
1246
1247
0
  subelems = req->variable;
1248
0
  elems_len = len - sizeof(*req);
1249
0
  rand_interval = le_to_host16(req->rand_interval);
1250
1251
0
  os_free(params->freqs);
1252
0
  os_memset(params, 0, sizeof(*params));
1253
1254
0
  data->token = elem_token;
1255
1256
  /* default reporting detail is all fixed length fields and all
1257
   * elements */
1258
0
  data->report_detail = BEACON_REPORT_DETAIL_ALL_FIELDS_AND_ELEMENTS;
1259
0
  os_memcpy(data->bssid, req->bssid, ETH_ALEN);
1260
1261
0
  while (elems_len >= 2) {
1262
0
    if (subelems[1] > elems_len - 2) {
1263
0
      wpa_printf(MSG_DEBUG,
1264
0
           "Beacon Request: Truncated subelement");
1265
0
      ret = -1;
1266
0
      goto out;
1267
0
    }
1268
1269
0
    res = wpas_rm_handle_beacon_req_subelem(
1270
0
      wpa_s, data, subelems[0], subelems[1], &subelems[2]);
1271
0
    if (res < 0) {
1272
0
      ret = res;
1273
0
      goto out;
1274
0
    } else if (!res) {
1275
0
      reject_mode = MEASUREMENT_REPORT_MODE_REJECT_INCAPABLE;
1276
0
      goto out_reject;
1277
0
    }
1278
1279
0
    elems_len -= 2 + subelems[1];
1280
0
    subelems += 2 + subelems[1];
1281
0
  }
1282
1283
0
  if (req->mode == BEACON_REPORT_MODE_TABLE) {
1284
0
    wpas_beacon_rep_table(wpa_s, buf);
1285
0
    goto out;
1286
0
  }
1287
1288
0
  params->freqs = wpas_beacon_request_freqs(wpa_s, req->oper_class,
1289
0
              req->channel, req->variable,
1290
0
              len - sizeof(*req));
1291
0
  if (!params->freqs) {
1292
0
    wpa_printf(MSG_DEBUG, "Beacon request: No valid channels");
1293
0
    reject_mode = MEASUREMENT_REPORT_MODE_REJECT_REFUSED;
1294
0
    goto out_reject;
1295
0
  }
1296
1297
0
  params->duration = le_to_host16(req->duration);
1298
0
  params->duration_mandatory = duration_mandatory;
1299
0
  if (!params->duration) {
1300
0
    wpa_printf(MSG_DEBUG, "Beacon request: Duration is 0");
1301
0
    ret = -1;
1302
0
    goto out;
1303
0
  }
1304
1305
0
  params->only_new_results = 1;
1306
1307
0
  if (req->mode == BEACON_REPORT_MODE_ACTIVE) {
1308
0
    params->ssids[params->num_ssids].ssid = data->ssid;
1309
0
    params->ssids[params->num_ssids++].ssid_len = data->ssid_len;
1310
0
  }
1311
1312
0
  if (os_get_random((u8 *) &_rand, sizeof(_rand)) < 0)
1313
0
    _rand = os_random();
1314
0
  interval_usec = (_rand % (rand_interval + 1)) * 1024;
1315
0
  eloop_register_timeout(0, interval_usec, wpas_rrm_scan_timeout, wpa_s,
1316
0
             NULL);
1317
0
  return 1;
1318
0
out_reject:
1319
0
  if (!is_multicast_ether_addr(wpa_s->rrm.dst_addr) &&
1320
0
      wpas_rrm_report_elem(buf, elem_token, reject_mode,
1321
0
         MEASURE_TYPE_BEACON, NULL, 0) < 0) {
1322
0
    wpa_printf(MSG_DEBUG, "RRM: Failed to add report element");
1323
0
    ret = -1;
1324
0
  }
1325
0
out:
1326
0
  wpas_clear_beacon_rep_data(wpa_s);
1327
0
  return ret;
1328
0
}
1329
1330
1331
static int
1332
wpas_rrm_handle_msr_req_element(
1333
  struct wpa_supplicant *wpa_s,
1334
  const struct rrm_measurement_request_element *req,
1335
  struct wpabuf **buf)
1336
0
{
1337
0
  int duration_mandatory;
1338
1339
0
  wpa_printf(MSG_DEBUG, "Measurement request type %d token %d",
1340
0
       req->type, req->token);
1341
1342
0
  if (req->mode & MEASUREMENT_REQUEST_MODE_ENABLE) {
1343
    /* Enable bit is not supported for now */
1344
0
    wpa_printf(MSG_DEBUG, "RRM: Enable bit not supported, ignore");
1345
0
    return 0;
1346
0
  }
1347
1348
0
  if ((req->mode & MEASUREMENT_REQUEST_MODE_PARALLEL) &&
1349
0
      req->type > MEASURE_TYPE_RPI_HIST) {
1350
    /* Parallel measurements are not supported for now */
1351
0
    wpa_printf(MSG_DEBUG,
1352
0
         "RRM: Parallel measurements are not supported, reject");
1353
0
    goto reject;
1354
0
  }
1355
1356
0
  duration_mandatory =
1357
0
    !!(req->mode & MEASUREMENT_REQUEST_MODE_DURATION_MANDATORY);
1358
1359
0
  switch (req->type) {
1360
0
  case MEASURE_TYPE_LCI:
1361
0
    return wpas_rrm_build_lci_report(wpa_s, req, buf);
1362
0
  case MEASURE_TYPE_BEACON:
1363
0
    if (duration_mandatory &&
1364
0
        !(wpa_s->drv_rrm_flags &
1365
0
          WPA_DRIVER_FLAGS_SUPPORT_SET_SCAN_DWELL)) {
1366
0
      wpa_printf(MSG_DEBUG,
1367
0
           "RRM: Driver does not support dwell time configuration - reject beacon report with mandatory duration");
1368
0
      goto reject;
1369
0
    }
1370
0
    return wpas_rm_handle_beacon_req(wpa_s, req->token,
1371
0
             duration_mandatory,
1372
0
             (const void *) req->variable,
1373
0
             req->len - 3, buf);
1374
0
  default:
1375
0
    wpa_printf(MSG_INFO,
1376
0
         "RRM: Unsupported radio measurement type %u",
1377
0
         req->type);
1378
0
    break;
1379
0
  }
1380
1381
0
reject:
1382
0
  if (!is_multicast_ether_addr(wpa_s->rrm.dst_addr) &&
1383
0
      wpas_rrm_report_elem(buf, req->token,
1384
0
         MEASUREMENT_REPORT_MODE_REJECT_INCAPABLE,
1385
0
         req->type, NULL, 0) < 0) {
1386
0
    wpa_printf(MSG_DEBUG, "RRM: Failed to add report element");
1387
0
    return -1;
1388
0
  }
1389
1390
0
  return 0;
1391
0
}
1392
1393
1394
static struct wpabuf *
1395
wpas_rrm_process_msr_req_elems(struct wpa_supplicant *wpa_s, const u8 *pos,
1396
             size_t len)
1397
0
{
1398
0
  struct wpabuf *buf = NULL;
1399
1400
0
  while (len) {
1401
0
    const struct rrm_measurement_request_element *req;
1402
0
    int res;
1403
1404
0
    if (len < 2) {
1405
0
      wpa_printf(MSG_DEBUG, "RRM: Truncated element");
1406
0
      goto out;
1407
0
    }
1408
1409
0
    req = (const struct rrm_measurement_request_element *) pos;
1410
0
    if (req->eid != WLAN_EID_MEASURE_REQUEST) {
1411
0
      wpa_printf(MSG_DEBUG,
1412
0
           "RRM: Expected Measurement Request element, but EID is %u",
1413
0
           req->eid);
1414
0
      goto out;
1415
0
    }
1416
1417
0
    if (req->len < 3) {
1418
0
      wpa_printf(MSG_DEBUG, "RRM: Element length too short");
1419
0
      goto out;
1420
0
    }
1421
1422
0
    if (req->len > len - 2) {
1423
0
      wpa_printf(MSG_DEBUG, "RRM: Element length too long");
1424
0
      goto out;
1425
0
    }
1426
1427
0
    res = wpas_rrm_handle_msr_req_element(wpa_s, req, &buf);
1428
0
    if (res < 0)
1429
0
      goto out;
1430
1431
0
    pos += req->len + 2;
1432
0
    len -= req->len + 2;
1433
0
  }
1434
1435
0
  return buf;
1436
1437
0
out:
1438
0
  wpabuf_free(buf);
1439
0
  return NULL;
1440
0
}
1441
1442
1443
void wpas_rrm_handle_radio_measurement_request(struct wpa_supplicant *wpa_s,
1444
                 const u8 *src, const u8 *dst,
1445
                 const u8 *frame, size_t len)
1446
0
{
1447
0
  struct wpabuf *report;
1448
1449
0
  if (wpa_s->wpa_state != WPA_COMPLETED) {
1450
0
    wpa_printf(MSG_INFO,
1451
0
         "RRM: Ignoring radio measurement request: Not associated");
1452
0
    return;
1453
0
  }
1454
1455
0
  if (!wpa_s->rrm.rrm_used) {
1456
0
    wpa_printf(MSG_INFO,
1457
0
         "RRM: Ignoring radio measurement request: Not RRM network");
1458
0
    return;
1459
0
  }
1460
1461
0
  if (len < 3) {
1462
0
    wpa_printf(MSG_INFO,
1463
0
         "RRM: Ignoring too short radio measurement request");
1464
0
    return;
1465
0
  }
1466
1467
0
  wpa_s->rrm.token = *frame;
1468
0
  os_memcpy(wpa_s->rrm.dst_addr, dst, ETH_ALEN);
1469
1470
  /* Number of repetitions is not supported */
1471
1472
0
  report = wpas_rrm_process_msr_req_elems(wpa_s, frame + 3, len - 3);
1473
0
  if (!report)
1474
0
    return;
1475
1476
0
  wpas_rrm_send_msr_report(wpa_s, report);
1477
0
  wpabuf_free(report);
1478
0
}
1479
1480
1481
void wpas_rrm_handle_link_measurement_request(struct wpa_supplicant *wpa_s,
1482
                const u8 *src,
1483
                const u8 *frame, size_t len,
1484
                int rssi)
1485
0
{
1486
0
  struct wpabuf *buf;
1487
0
  const struct rrm_link_measurement_request *req;
1488
0
  struct rrm_link_measurement_report report;
1489
1490
0
  if (wpa_s->wpa_state != WPA_COMPLETED) {
1491
0
    wpa_printf(MSG_INFO,
1492
0
         "RRM: Ignoring link measurement request. Not associated");
1493
0
    return;
1494
0
  }
1495
1496
0
  if (!wpa_s->rrm.rrm_used) {
1497
0
    wpa_printf(MSG_INFO,
1498
0
         "RRM: Ignoring link measurement request. Not RRM network");
1499
0
    return;
1500
0
  }
1501
1502
0
  if (!(wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION)) {
1503
0
    wpa_printf(MSG_INFO,
1504
0
         "RRM: Measurement report failed. TX power insertion not supported");
1505
0
    return;
1506
0
  }
1507
1508
0
  req = (const struct rrm_link_measurement_request *) frame;
1509
0
  if (len < sizeof(*req)) {
1510
0
    wpa_printf(MSG_INFO,
1511
0
         "RRM: Link measurement report failed. Request too short");
1512
0
    return;
1513
0
  }
1514
1515
0
  os_memset(&report, 0, sizeof(report));
1516
0
  report.dialog_token = req->dialog_token;
1517
0
  report.tpc.eid = WLAN_EID_TPC_REPORT;
1518
0
  report.tpc.len = 2;
1519
  /* Note: The driver is expected to update report.tpc.tx_power and
1520
   * report.tpc.link_margin subfields when sending out this frame.
1521
   * Similarly, the driver would need to update report.rx_ant_id and
1522
   * report.tx_ant_id subfields. */
1523
0
  report.rsni = 255; /* 255 indicates that RSNI is not available */
1524
0
  report.rcpi = rssi_to_rcpi(rssi);
1525
1526
  /* action_category + action_code */
1527
0
  buf = wpabuf_alloc(2 + sizeof(report));
1528
0
  if (buf == NULL) {
1529
0
    wpa_printf(MSG_ERROR,
1530
0
         "RRM: Link measurement report failed. Buffer allocation failed");
1531
0
    return;
1532
0
  }
1533
1534
0
  wpabuf_put_u8(buf, WLAN_ACTION_RADIO_MEASUREMENT);
1535
0
  wpabuf_put_u8(buf, WLAN_RRM_LINK_MEASUREMENT_REPORT);
1536
0
  wpabuf_put_data(buf, &report, sizeof(report));
1537
0
  wpa_hexdump_buf(MSG_DEBUG, "RRM: Link measurement report", buf);
1538
1539
0
  if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, src,
1540
0
        wpa_s->own_addr, wpa_s->bssid,
1541
0
        wpabuf_head(buf), wpabuf_len(buf), 0)) {
1542
0
    wpa_printf(MSG_ERROR,
1543
0
         "RRM: Link measurement report failed. Send action failed");
1544
0
  }
1545
0
  wpabuf_free(buf);
1546
0
}
1547
1548
1549
static bool wpas_beacon_rep_scan_match(struct wpa_supplicant *wpa_s,
1550
               const u8 *bssid)
1551
0
{
1552
0
  u8 i;
1553
1554
0
  if (!wpa_s->valid_links)
1555
0
    return ether_addr_equal(wpa_s->current_bss->bssid, bssid);
1556
1557
0
  for_each_link(wpa_s->valid_links, i) {
1558
0
    if (ether_addr_equal(wpa_s->links[i].bssid, bssid))
1559
0
      return true;
1560
0
  }
1561
1562
0
  wpa_printf(MSG_DEBUG, "RRM: MLD: no match for TSF BSSID=" MACSTR,
1563
0
       MAC2STR(bssid));
1564
1565
0
  return false;
1566
0
}
1567
1568
1569
int wpas_beacon_rep_scan_process(struct wpa_supplicant *wpa_s,
1570
         struct wpa_scan_results *scan_res,
1571
         struct scan_info *info)
1572
0
{
1573
0
  size_t i = 0;
1574
0
  struct wpabuf *buf = NULL;
1575
1576
0
  if (!wpa_s->beacon_rep_data.token)
1577
0
    return 0;
1578
1579
0
  if (!wpa_s->current_bss)
1580
0
    goto out;
1581
1582
  /* If the measurement was aborted, don't report partial results */
1583
0
  if (info->aborted)
1584
0
    goto out_refuse;
1585
1586
0
  wpa_printf(MSG_DEBUG, "RRM: TSF BSSID: " MACSTR " current BSS: " MACSTR,
1587
0
       MAC2STR(info->scan_start_tsf_bssid),
1588
0
       MAC2STR(wpa_s->current_bss->bssid));
1589
0
  if ((wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT) &&
1590
0
      !wpas_beacon_rep_scan_match(wpa_s, info->scan_start_tsf_bssid)) {
1591
0
    wpa_printf(MSG_DEBUG,
1592
0
         "RRM: Ignore scan results due to mismatching TSF BSSID");
1593
0
    goto out_refuse;
1594
0
  }
1595
1596
0
  for (i = 0; i < scan_res->num; i++) {
1597
0
    struct wpa_bss *bss =
1598
0
      wpa_bss_get_bssid(wpa_s, scan_res->res[i]->bssid);
1599
1600
0
    if (!bss)
1601
0
      continue;
1602
1603
0
    if ((wpa_s->drv_rrm_flags &
1604
0
         WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT) &&
1605
0
        !wpas_beacon_rep_scan_match(wpa_s,
1606
0
            scan_res->res[i]->tsf_bssid)) {
1607
0
      wpa_printf(MSG_DEBUG,
1608
0
           "RRM: Ignore scan result for " MACSTR
1609
0
           " due to mismatching TSF BSSID" MACSTR,
1610
0
           MAC2STR(scan_res->res[i]->bssid),
1611
0
           MAC2STR(scan_res->res[i]->tsf_bssid));
1612
0
      continue;
1613
0
    }
1614
1615
    /*
1616
     * Don't report results that were not received during the
1617
     * current measurement.
1618
     */
1619
0
    if (!(wpa_s->drv_rrm_flags &
1620
0
          WPA_DRIVER_FLAGS_SUPPORT_BEACON_REPORT)) {
1621
0
      struct os_reltime update_time, diff;
1622
1623
      /* For now, allow 8 ms older results due to some
1624
       * unknown issue with cfg80211 BSS table updates during
1625
       * a scan with the current BSS.
1626
       * TODO: Fix this more properly to avoid having to have
1627
       * this type of hacks in place. */
1628
0
      calculate_update_time(&scan_res->fetch_time,
1629
0
                scan_res->res[i]->age,
1630
0
                &update_time);
1631
0
      os_reltime_sub(&wpa_s->beacon_rep_scan,
1632
0
               &update_time, &diff);
1633
0
      if (os_reltime_before(&update_time,
1634
0
                &wpa_s->beacon_rep_scan) &&
1635
0
          (diff.sec || diff.usec >= 8000)) {
1636
0
        wpa_printf(MSG_DEBUG,
1637
0
             "RRM: Ignore scan result for " MACSTR
1638
0
             " due to old update (age(ms) %u, calculated age %u.%06u seconds)",
1639
0
             MAC2STR(scan_res->res[i]->bssid),
1640
0
             scan_res->res[i]->age,
1641
0
             (unsigned int) diff.sec,
1642
0
             (unsigned int) diff.usec);
1643
0
        continue;
1644
0
      }
1645
0
    } else if (info->scan_start_tsf >
1646
0
         scan_res->res[i]->parent_tsf) {
1647
0
      continue;
1648
0
    }
1649
1650
0
    if (wpas_add_beacon_rep(wpa_s, &buf, bss, info->scan_start_tsf,
1651
0
          scan_res->res[i]->parent_tsf) < 0)
1652
0
      break;
1653
0
  }
1654
1655
0
  if (!buf && wpas_beacon_rep_no_results(wpa_s, &buf))
1656
0
    goto out;
1657
1658
0
  wpa_hexdump_buf(MSG_DEBUG, "RRM: Radio Measurement report", buf);
1659
1660
0
  wpas_rrm_send_msr_report(wpa_s, buf);
1661
0
  wpabuf_free(buf);
1662
1663
0
  goto out;
1664
1665
0
out_refuse:
1666
0
  wpas_rrm_refuse_request(wpa_s);
1667
0
out:
1668
0
  wpas_clear_beacon_rep_data(wpa_s);
1669
0
  return 1;
1670
0
}
1671
1672
1673
void wpas_clear_beacon_rep_data(struct wpa_supplicant *wpa_s)
1674
0
{
1675
0
  struct beacon_rep_data *data = &wpa_s->beacon_rep_data;
1676
1677
0
  eloop_cancel_timeout(wpas_rrm_scan_timeout, wpa_s, NULL);
1678
0
  bitfield_free(data->eids);
1679
0
  bitfield_free(data->ext_eids);
1680
0
  os_free(data->scan_params.freqs);
1681
0
  os_memset(data, 0, sizeof(*data));
1682
0
}