hostapd: expose beacon reports through ubus
[openwrt/staging/wigyori.git] / package / network / services / hostapd / src / src / ap / ubus.c
1 /*
2 * hostapd / ubus support
3 * Copyright (c) 2013, Felix Fietkau <nbd@nbd.name>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "utils/includes.h"
10 #include "utils/common.h"
11 #include "utils/eloop.h"
12 #include "utils/wpabuf.h"
13 #include "common/ieee802_11_defs.h"
14 #include "hostapd.h"
15 #include "neighbor_db.h"
16 #include "wps_hostapd.h"
17 #include "sta_info.h"
18 #include "ubus.h"
19 #include "ap_drv_ops.h"
20 #include "beacon.h"
21 #include "rrm.h"
22 #include "wnm_ap.h"
23 #include "taxonomy.h"
24
25 static struct ubus_context *ctx;
26 static struct blob_buf b;
27 static int ctx_ref;
28
29 static inline struct hapd_interfaces *get_hapd_interfaces_from_object(struct ubus_object *obj)
30 {
31 return container_of(obj, struct hapd_interfaces, ubus);
32 }
33
34 static inline struct hostapd_data *get_hapd_from_object(struct ubus_object *obj)
35 {
36 return container_of(obj, struct hostapd_data, ubus.obj);
37 }
38
39 struct ubus_banned_client {
40 struct avl_node avl;
41 u8 addr[ETH_ALEN];
42 };
43
44 static void ubus_receive(int sock, void *eloop_ctx, void *sock_ctx)
45 {
46 struct ubus_context *ctx = eloop_ctx;
47 ubus_handle_event(ctx);
48 }
49
50 static void ubus_reconnect_timeout(void *eloop_data, void *user_ctx)
51 {
52 if (ubus_reconnect(ctx, NULL)) {
53 eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL);
54 return;
55 }
56
57 eloop_register_read_sock(ctx->sock.fd, ubus_receive, ctx, NULL);
58 }
59
60 static void hostapd_ubus_connection_lost(struct ubus_context *ctx)
61 {
62 eloop_unregister_read_sock(ctx->sock.fd);
63 eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL);
64 }
65
66 static bool hostapd_ubus_init(void)
67 {
68 if (ctx)
69 return true;
70
71 ctx = ubus_connect(NULL);
72 if (!ctx)
73 return false;
74
75 ctx->connection_lost = hostapd_ubus_connection_lost;
76 eloop_register_read_sock(ctx->sock.fd, ubus_receive, ctx, NULL);
77 return true;
78 }
79
80 static void hostapd_ubus_ref_inc(void)
81 {
82 ctx_ref++;
83 }
84
85 static void hostapd_ubus_ref_dec(void)
86 {
87 ctx_ref--;
88 if (!ctx)
89 return;
90
91 if (ctx_ref)
92 return;
93
94 eloop_unregister_read_sock(ctx->sock.fd);
95 ubus_free(ctx);
96 ctx = NULL;
97 }
98
99 void hostapd_ubus_add_iface(struct hostapd_iface *iface)
100 {
101 if (!hostapd_ubus_init())
102 return;
103 }
104
105 void hostapd_ubus_free_iface(struct hostapd_iface *iface)
106 {
107 if (!ctx)
108 return;
109 }
110
111 static void
112 hostapd_bss_del_ban(void *eloop_data, void *user_ctx)
113 {
114 struct ubus_banned_client *ban = eloop_data;
115 struct hostapd_data *hapd = user_ctx;
116
117 avl_delete(&hapd->ubus.banned, &ban->avl);
118 free(ban);
119 }
120
121 static void
122 hostapd_bss_ban_client(struct hostapd_data *hapd, u8 *addr, int time)
123 {
124 struct ubus_banned_client *ban;
125
126 if (time < 0)
127 time = 0;
128
129 ban = avl_find_element(&hapd->ubus.banned, addr, ban, avl);
130 if (!ban) {
131 if (!time)
132 return;
133
134 ban = os_zalloc(sizeof(*ban));
135 memcpy(ban->addr, addr, sizeof(ban->addr));
136 ban->avl.key = ban->addr;
137 avl_insert(&hapd->ubus.banned, &ban->avl);
138 } else {
139 eloop_cancel_timeout(hostapd_bss_del_ban, ban, hapd);
140 if (!time) {
141 hostapd_bss_del_ban(ban, hapd);
142 return;
143 }
144 }
145
146 eloop_register_timeout(0, time * 1000, hostapd_bss_del_ban, ban, hapd);
147 }
148
149 static int
150 hostapd_bss_reload(struct ubus_context *ctx, struct ubus_object *obj,
151 struct ubus_request_data *req, const char *method,
152 struct blob_attr *msg)
153 {
154 struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
155 return hostapd_reload_config(hapd->iface, 1);
156 }
157
158 static int
159 hostapd_bss_get_clients(struct ubus_context *ctx, struct ubus_object *obj,
160 struct ubus_request_data *req, const char *method,
161 struct blob_attr *msg)
162 {
163 struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
164 struct sta_info *sta;
165 void *list, *c;
166 char mac_buf[20];
167 static const struct {
168 const char *name;
169 uint32_t flag;
170 } sta_flags[] = {
171 { "auth", WLAN_STA_AUTH },
172 { "assoc", WLAN_STA_ASSOC },
173 { "authorized", WLAN_STA_AUTHORIZED },
174 { "preauth", WLAN_STA_PREAUTH },
175 { "wds", WLAN_STA_WDS },
176 { "wmm", WLAN_STA_WMM },
177 { "ht", WLAN_STA_HT },
178 { "vht", WLAN_STA_VHT },
179 { "wps", WLAN_STA_WPS },
180 { "mfp", WLAN_STA_MFP },
181 };
182
183 blob_buf_init(&b, 0);
184 blobmsg_add_u32(&b, "freq", hapd->iface->freq);
185 list = blobmsg_open_table(&b, "clients");
186 for (sta = hapd->sta_list; sta; sta = sta->next) {
187 void *r;
188 int i;
189
190 sprintf(mac_buf, MACSTR, MAC2STR(sta->addr));
191 c = blobmsg_open_table(&b, mac_buf);
192 for (i = 0; i < ARRAY_SIZE(sta_flags); i++)
193 blobmsg_add_u8(&b, sta_flags[i].name,
194 !!(sta->flags & sta_flags[i].flag));
195
196 r = blobmsg_open_array(&b, "rrm");
197 for (i = 0; i < ARRAY_SIZE(sta->rrm_enabled_capa); i++)
198 blobmsg_add_u32(&b, "", sta->rrm_enabled_capa[i]);
199 blobmsg_close_array(&b, r);
200 blobmsg_add_u32(&b, "aid", sta->aid);
201 #ifdef CONFIG_TAXONOMY
202 r = blobmsg_alloc_string_buffer(&b, "signature", 1024);
203 if (retrieve_sta_taxonomy(hapd, sta, r, 1024) > 0)
204 blobmsg_add_string_buffer(&b);
205 #endif
206 blobmsg_close_table(&b, c);
207 }
208 blobmsg_close_array(&b, list);
209 ubus_send_reply(ctx, req, b.head);
210
211 return 0;
212 }
213
214 static int
215 hostapd_bss_get_features(struct ubus_context *ctx, struct ubus_object *obj,
216 struct ubus_request_data *req, const char *method,
217 struct blob_attr *msg)
218 {
219 struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
220
221 blob_buf_init(&b, 0);
222 blobmsg_add_u8(&b, "ht_supported", ht_supported(hapd->iface->hw_features));
223 blobmsg_add_u8(&b, "vht_supported", vht_supported(hapd->iface->hw_features));
224 ubus_send_reply(ctx, req, b.head);
225
226 return 0;
227 }
228
229 enum {
230 NOTIFY_RESPONSE,
231 __NOTIFY_MAX
232 };
233
234 static const struct blobmsg_policy notify_policy[__NOTIFY_MAX] = {
235 [NOTIFY_RESPONSE] = { "notify_response", BLOBMSG_TYPE_INT32 },
236 };
237
238 static int
239 hostapd_notify_response(struct ubus_context *ctx, struct ubus_object *obj,
240 struct ubus_request_data *req, const char *method,
241 struct blob_attr *msg)
242 {
243 struct blob_attr *tb[__NOTIFY_MAX];
244 struct hostapd_data *hapd = get_hapd_from_object(obj);
245 struct wpabuf *elems;
246 const char *pos;
247 size_t len;
248
249 blobmsg_parse(notify_policy, __NOTIFY_MAX, tb,
250 blob_data(msg), blob_len(msg));
251
252 if (!tb[NOTIFY_RESPONSE])
253 return UBUS_STATUS_INVALID_ARGUMENT;
254
255 hapd->ubus.notify_response = blobmsg_get_u32(tb[NOTIFY_RESPONSE]);
256
257 return UBUS_STATUS_OK;
258 }
259
260 enum {
261 DEL_CLIENT_ADDR,
262 DEL_CLIENT_REASON,
263 DEL_CLIENT_DEAUTH,
264 DEL_CLIENT_BAN_TIME,
265 __DEL_CLIENT_MAX
266 };
267
268 static const struct blobmsg_policy del_policy[__DEL_CLIENT_MAX] = {
269 [DEL_CLIENT_ADDR] = { "addr", BLOBMSG_TYPE_STRING },
270 [DEL_CLIENT_REASON] = { "reason", BLOBMSG_TYPE_INT32 },
271 [DEL_CLIENT_DEAUTH] = { "deauth", BLOBMSG_TYPE_INT8 },
272 [DEL_CLIENT_BAN_TIME] = { "ban_time", BLOBMSG_TYPE_INT32 },
273 };
274
275 static int
276 hostapd_bss_del_client(struct ubus_context *ctx, struct ubus_object *obj,
277 struct ubus_request_data *req, const char *method,
278 struct blob_attr *msg)
279 {
280 struct blob_attr *tb[__DEL_CLIENT_MAX];
281 struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
282 struct sta_info *sta;
283 bool deauth = false;
284 int reason;
285 u8 addr[ETH_ALEN];
286
287 blobmsg_parse(del_policy, __DEL_CLIENT_MAX, tb, blob_data(msg), blob_len(msg));
288
289 if (!tb[DEL_CLIENT_ADDR])
290 return UBUS_STATUS_INVALID_ARGUMENT;
291
292 if (hwaddr_aton(blobmsg_data(tb[DEL_CLIENT_ADDR]), addr))
293 return UBUS_STATUS_INVALID_ARGUMENT;
294
295 if (tb[DEL_CLIENT_REASON])
296 reason = blobmsg_get_u32(tb[DEL_CLIENT_REASON]);
297
298 if (tb[DEL_CLIENT_DEAUTH])
299 deauth = blobmsg_get_bool(tb[DEL_CLIENT_DEAUTH]);
300
301 sta = ap_get_sta(hapd, addr);
302 if (sta) {
303 if (deauth) {
304 hostapd_drv_sta_deauth(hapd, addr, reason);
305 ap_sta_deauthenticate(hapd, sta, reason);
306 } else {
307 hostapd_drv_sta_disassoc(hapd, addr, reason);
308 ap_sta_disassociate(hapd, sta, reason);
309 }
310 }
311
312 if (tb[DEL_CLIENT_BAN_TIME])
313 hostapd_bss_ban_client(hapd, addr, blobmsg_get_u32(tb[DEL_CLIENT_BAN_TIME]));
314
315 return 0;
316 }
317
318 static void
319 blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const u8 *addr)
320 {
321 char *s;
322
323 s = blobmsg_alloc_string_buffer(buf, name, 20);
324 sprintf(s, MACSTR, MAC2STR(addr));
325 blobmsg_add_string_buffer(buf);
326 }
327
328 static int
329 hostapd_bss_list_bans(struct ubus_context *ctx, struct ubus_object *obj,
330 struct ubus_request_data *req, const char *method,
331 struct blob_attr *msg)
332 {
333 struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
334 struct ubus_banned_client *ban;
335 void *c;
336
337 blob_buf_init(&b, 0);
338 c = blobmsg_open_array(&b, "clients");
339 avl_for_each_element(&hapd->ubus.banned, ban, avl)
340 blobmsg_add_macaddr(&b, NULL, ban->addr);
341 blobmsg_close_array(&b, c);
342 ubus_send_reply(ctx, req, b.head);
343
344 return 0;
345 }
346
347 static int
348 hostapd_bss_wps_start(struct ubus_context *ctx, struct ubus_object *obj,
349 struct ubus_request_data *req, const char *method,
350 struct blob_attr *msg)
351 {
352 int rc;
353 struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
354
355 rc = hostapd_wps_button_pushed(hapd, NULL);
356
357 if (rc != 0)
358 return UBUS_STATUS_NOT_SUPPORTED;
359
360 return 0;
361 }
362
363 static int
364 hostapd_bss_wps_cancel(struct ubus_context *ctx, struct ubus_object *obj,
365 struct ubus_request_data *req, const char *method,
366 struct blob_attr *msg)
367 {
368 int rc;
369 struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
370
371 rc = hostapd_wps_cancel(hapd);
372
373 if (rc != 0)
374 return UBUS_STATUS_NOT_SUPPORTED;
375
376 return 0;
377 }
378
379 static int
380 hostapd_bss_update_beacon(struct ubus_context *ctx, struct ubus_object *obj,
381 struct ubus_request_data *req, const char *method,
382 struct blob_attr *msg)
383 {
384 int rc;
385 struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
386
387 rc = ieee802_11_set_beacon(hapd);
388
389 if (rc != 0)
390 return UBUS_STATUS_NOT_SUPPORTED;
391
392 return 0;
393 }
394
395 enum {
396 CONFIG_IFACE,
397 CONFIG_FILE,
398 __CONFIG_MAX
399 };
400
401 static const struct blobmsg_policy config_add_policy[__CONFIG_MAX] = {
402 [CONFIG_IFACE] = { "iface", BLOBMSG_TYPE_STRING },
403 [CONFIG_FILE] = { "config", BLOBMSG_TYPE_STRING },
404 };
405
406 static int
407 hostapd_config_add(struct ubus_context *ctx, struct ubus_object *obj,
408 struct ubus_request_data *req, const char *method,
409 struct blob_attr *msg)
410 {
411 struct blob_attr *tb[__CONFIG_MAX];
412 struct hapd_interfaces *interfaces = get_hapd_interfaces_from_object(obj);
413 char buf[128];
414
415 blobmsg_parse(config_add_policy, __CONFIG_MAX, tb, blob_data(msg), blob_len(msg));
416
417 if (!tb[CONFIG_FILE] || !tb[CONFIG_IFACE])
418 return UBUS_STATUS_INVALID_ARGUMENT;
419
420 snprintf(buf, sizeof(buf), "bss_config=%s:%s",
421 blobmsg_get_string(tb[CONFIG_IFACE]),
422 blobmsg_get_string(tb[CONFIG_FILE]));
423
424 if (hostapd_add_iface(interfaces, buf))
425 return UBUS_STATUS_INVALID_ARGUMENT;
426
427 return UBUS_STATUS_OK;
428 }
429
430 enum {
431 CONFIG_REM_IFACE,
432 __CONFIG_REM_MAX
433 };
434
435 static const struct blobmsg_policy config_remove_policy[__CONFIG_REM_MAX] = {
436 [CONFIG_REM_IFACE] = { "iface", BLOBMSG_TYPE_STRING },
437 };
438
439 static int
440 hostapd_config_remove(struct ubus_context *ctx, struct ubus_object *obj,
441 struct ubus_request_data *req, const char *method,
442 struct blob_attr *msg)
443 {
444 struct blob_attr *tb[__CONFIG_REM_MAX];
445 struct hapd_interfaces *interfaces = get_hapd_interfaces_from_object(obj);
446 char buf[128];
447
448 blobmsg_parse(config_remove_policy, __CONFIG_REM_MAX, tb, blob_data(msg), blob_len(msg));
449
450 if (!tb[CONFIG_REM_IFACE])
451 return UBUS_STATUS_INVALID_ARGUMENT;
452
453 if (hostapd_remove_iface(interfaces, blobmsg_get_string(tb[CONFIG_REM_IFACE])))
454 return UBUS_STATUS_INVALID_ARGUMENT;
455
456 return UBUS_STATUS_OK;
457 }
458
459 enum {
460 CSA_FREQ,
461 CSA_BCN_COUNT,
462 CSA_CENTER_FREQ1,
463 CSA_CENTER_FREQ2,
464 CSA_BANDWIDTH,
465 CSA_SEC_CHANNEL_OFFSET,
466 CSA_HT,
467 CSA_VHT,
468 CSA_BLOCK_TX,
469 __CSA_MAX
470 };
471
472 static const struct blobmsg_policy csa_policy[__CSA_MAX] = {
473 [CSA_FREQ] = { "freq", BLOBMSG_TYPE_INT32 },
474 [CSA_BCN_COUNT] = { "bcn_count", BLOBMSG_TYPE_INT32 },
475 [CSA_CENTER_FREQ1] = { "center_freq1", BLOBMSG_TYPE_INT32 },
476 [CSA_CENTER_FREQ2] = { "center_freq2", BLOBMSG_TYPE_INT32 },
477 [CSA_BANDWIDTH] = { "bandwidth", BLOBMSG_TYPE_INT32 },
478 [CSA_SEC_CHANNEL_OFFSET] = { "sec_channel_offset", BLOBMSG_TYPE_INT32 },
479 [CSA_HT] = { "ht", BLOBMSG_TYPE_BOOL },
480 [CSA_VHT] = { "vht", BLOBMSG_TYPE_BOOL },
481 [CSA_BLOCK_TX] = { "block_tx", BLOBMSG_TYPE_BOOL },
482 };
483
484 #ifdef NEED_AP_MLME
485 static int
486 hostapd_switch_chan(struct ubus_context *ctx, struct ubus_object *obj,
487 struct ubus_request_data *req, const char *method,
488 struct blob_attr *msg)
489 {
490 struct blob_attr *tb[__CSA_MAX];
491 struct hostapd_data *hapd = get_hapd_from_object(obj);
492 struct csa_settings css;
493
494 blobmsg_parse(csa_policy, __CSA_MAX, tb, blob_data(msg), blob_len(msg));
495
496 if (!tb[CSA_FREQ])
497 return UBUS_STATUS_INVALID_ARGUMENT;
498
499 memset(&css, 0, sizeof(css));
500 css.freq_params.freq = blobmsg_get_u32(tb[CSA_FREQ]);
501
502 #define SET_CSA_SETTING(name, field, type) \
503 do { \
504 if (tb[name]) \
505 css.field = blobmsg_get_ ## type(tb[name]); \
506 } while(0)
507
508 SET_CSA_SETTING(CSA_BCN_COUNT, cs_count, u32);
509 SET_CSA_SETTING(CSA_CENTER_FREQ1, freq_params.center_freq1, u32);
510 SET_CSA_SETTING(CSA_CENTER_FREQ2, freq_params.center_freq2, u32);
511 SET_CSA_SETTING(CSA_BANDWIDTH, freq_params.bandwidth, u32);
512 SET_CSA_SETTING(CSA_SEC_CHANNEL_OFFSET, freq_params.sec_channel_offset, u32);
513 SET_CSA_SETTING(CSA_HT, freq_params.ht_enabled, bool);
514 SET_CSA_SETTING(CSA_VHT, freq_params.vht_enabled, bool);
515 SET_CSA_SETTING(CSA_BLOCK_TX, block_tx, bool);
516
517
518 if (hostapd_switch_channel(hapd, &css) != 0)
519 return UBUS_STATUS_NOT_SUPPORTED;
520 return UBUS_STATUS_OK;
521 #undef SET_CSA_SETTING
522 }
523 #endif
524
525 enum {
526 VENDOR_ELEMENTS,
527 __VENDOR_ELEMENTS_MAX
528 };
529
530 static const struct blobmsg_policy ve_policy[__VENDOR_ELEMENTS_MAX] = {
531 /* vendor elements are provided as hex-string */
532 [VENDOR_ELEMENTS] = { "vendor_elements", BLOBMSG_TYPE_STRING },
533 };
534
535 static int
536 hostapd_vendor_elements(struct ubus_context *ctx, struct ubus_object *obj,
537 struct ubus_request_data *req, const char *method,
538 struct blob_attr *msg)
539 {
540 struct blob_attr *tb[__VENDOR_ELEMENTS_MAX];
541 struct hostapd_data *hapd = get_hapd_from_object(obj);
542 struct hostapd_bss_config *bss = hapd->conf;
543 struct wpabuf *elems;
544 const char *pos;
545 size_t len;
546
547 blobmsg_parse(ve_policy, __VENDOR_ELEMENTS_MAX, tb,
548 blob_data(msg), blob_len(msg));
549
550 if (!tb[VENDOR_ELEMENTS])
551 return UBUS_STATUS_INVALID_ARGUMENT;
552
553 pos = blobmsg_data(tb[VENDOR_ELEMENTS]);
554 len = os_strlen(pos);
555 if (len & 0x01)
556 return UBUS_STATUS_INVALID_ARGUMENT;
557
558 len /= 2;
559 if (len == 0) {
560 wpabuf_free(bss->vendor_elements);
561 bss->vendor_elements = NULL;
562 return 0;
563 }
564
565 elems = wpabuf_alloc(len);
566 if (elems == NULL)
567 return 1;
568
569 if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
570 wpabuf_free(elems);
571 return UBUS_STATUS_INVALID_ARGUMENT;
572 }
573
574 wpabuf_free(bss->vendor_elements);
575 bss->vendor_elements = elems;
576
577 /* update beacons if vendor elements were set successfully */
578 if (ieee802_11_update_beacons(hapd->iface) != 0)
579 return UBUS_STATUS_NOT_SUPPORTED;
580 return UBUS_STATUS_OK;
581 }
582
583 static void
584 hostapd_rrm_print_nr(struct hostapd_neighbor_entry *nr)
585 {
586 const u8 *data;
587 char *str;
588 int len;
589
590 blobmsg_printf(&b, "", MACSTR, MAC2STR(nr->bssid));
591
592 str = blobmsg_alloc_string_buffer(&b, "", nr->ssid.ssid_len + 1);
593 memcpy(str, nr->ssid.ssid, nr->ssid.ssid_len);
594 str[nr->ssid.ssid_len] = 0;
595 blobmsg_add_string_buffer(&b);
596
597 len = wpabuf_len(nr->nr);
598 str = blobmsg_alloc_string_buffer(&b, "", 2 * len + 1);
599 wpa_snprintf_hex(str, 2 * len + 1, wpabuf_head_u8(nr->nr), len);
600 blobmsg_add_string_buffer(&b);
601 }
602
603 enum {
604 BSS_MGMT_EN_NEIGHBOR,
605 BSS_MGMT_EN_BEACON,
606 #ifdef CONFIG_WNM_AP
607 BSS_MGMT_EN_BSS_TRANSITION,
608 #endif
609 __BSS_MGMT_EN_MAX
610 };
611
612 static bool
613 __hostapd_bss_mgmt_enable_f(struct hostapd_data *hapd, int flag)
614 {
615 struct hostapd_bss_config *bss = hapd->conf;
616 uint32_t flags;
617
618 switch (flag) {
619 case BSS_MGMT_EN_NEIGHBOR:
620 if (bss->radio_measurements[0] &
621 WLAN_RRM_CAPS_NEIGHBOR_REPORT)
622 return false;
623
624 bss->radio_measurements[0] |=
625 WLAN_RRM_CAPS_NEIGHBOR_REPORT;
626 hostapd_neighbor_set_own_report(hapd);
627 return true;
628 case BSS_MGMT_EN_BEACON:
629 flags = WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE |
630 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE |
631 WLAN_RRM_CAPS_BEACON_REPORT_TABLE;
632
633 if (bss->radio_measurements[0] & flags == flags)
634 return false;
635
636 bss->radio_measurements[0] |= (u8) flags;
637 return true;
638 #ifdef CONFIG_WNM_AP
639 case BSS_MGMT_EN_BSS_TRANSITION:
640 if (bss->bss_transition)
641 return false;
642
643 bss->bss_transition = 1;
644 return true;
645 #endif
646 }
647 }
648
649 static void
650 __hostapd_bss_mgmt_enable(struct hostapd_data *hapd, uint32_t flags)
651 {
652 bool update = false;
653 int i;
654
655 for (i = 0; i < __BSS_MGMT_EN_MAX; i++) {
656 if (!(flags & (1 << i)))
657 continue;
658
659 update |= __hostapd_bss_mgmt_enable_f(hapd, i);
660 }
661
662 if (update)
663 ieee802_11_update_beacons(hapd->iface);
664 }
665
666
667 static const struct blobmsg_policy bss_mgmt_enable_policy[__BSS_MGMT_EN_MAX] = {
668 [BSS_MGMT_EN_NEIGHBOR] = { "neighbor_report", BLOBMSG_TYPE_BOOL },
669 [BSS_MGMT_EN_BEACON] = { "beacon_report", BLOBMSG_TYPE_BOOL },
670 #ifdef CONFIG_WNM_AP
671 [BSS_MGMT_EN_BSS_TRANSITION] = { "bss_transition", BLOBMSG_TYPE_BOOL },
672 #endif
673 };
674
675 static int
676 hostapd_bss_mgmt_enable(struct ubus_context *ctx, struct ubus_object *obj,
677 struct ubus_request_data *req, const char *method,
678 struct blob_attr *msg)
679
680 {
681 struct hostapd_data *hapd = get_hapd_from_object(obj);
682 struct blob_attr *tb[__BSS_MGMT_EN_MAX];
683 struct blob_attr *cur;
684 uint32_t flags = 0;
685 int i;
686 bool neigh = false, beacon = false;
687
688 blobmsg_parse(bss_mgmt_enable_policy, __BSS_MGMT_EN_MAX, tb, blob_data(msg), blob_len(msg));
689
690 for (i = 0; i < ARRAY_SIZE(tb); i++) {
691 if (!tb[i] || !blobmsg_get_bool(tb[i]))
692 continue;
693
694 flags |= (1 << i);
695 }
696
697 __hostapd_bss_mgmt_enable(hapd, flags);
698 }
699
700
701 static void
702 hostapd_rrm_nr_enable(struct hostapd_data *hapd)
703 {
704 __hostapd_bss_mgmt_enable(hapd, 1 << BSS_MGMT_EN_NEIGHBOR);
705 }
706
707 static int
708 hostapd_rrm_nr_get_own(struct ubus_context *ctx, struct ubus_object *obj,
709 struct ubus_request_data *req, const char *method,
710 struct blob_attr *msg)
711 {
712 struct hostapd_data *hapd = get_hapd_from_object(obj);
713 struct hostapd_neighbor_entry *nr;
714 void *c;
715
716 hostapd_rrm_nr_enable(hapd);
717
718 nr = hostapd_neighbor_get(hapd, hapd->own_addr, NULL);
719 if (!nr)
720 return UBUS_STATUS_NOT_FOUND;
721
722 blob_buf_init(&b, 0);
723
724 c = blobmsg_open_array(&b, "value");
725 hostapd_rrm_print_nr(nr);
726 blobmsg_close_array(&b, c);
727
728 ubus_send_reply(ctx, req, b.head);
729
730 return 0;
731 }
732
733 static int
734 hostapd_rrm_nr_list(struct ubus_context *ctx, struct ubus_object *obj,
735 struct ubus_request_data *req, const char *method,
736 struct blob_attr *msg)
737 {
738 struct hostapd_data *hapd = get_hapd_from_object(obj);
739 struct hostapd_neighbor_entry *nr;
740 void *c;
741
742 hostapd_rrm_nr_enable(hapd);
743 blob_buf_init(&b, 0);
744
745 c = blobmsg_open_array(&b, "list");
746 dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry, list) {
747 void *cur;
748
749 if (!memcmp(nr->bssid, hapd->own_addr, ETH_ALEN))
750 continue;
751
752 cur = blobmsg_open_array(&b, NULL);
753 hostapd_rrm_print_nr(nr);
754 blobmsg_close_array(&b, cur);
755 }
756 blobmsg_close_array(&b, c);
757
758 ubus_send_reply(ctx, req, b.head);
759
760 return 0;
761 }
762
763 enum {
764 NR_SET_LIST,
765 __NR_SET_LIST_MAX
766 };
767
768 static const struct blobmsg_policy nr_set_policy[__NR_SET_LIST_MAX] = {
769 [NR_SET_LIST] = { "list", BLOBMSG_TYPE_ARRAY },
770 };
771
772
773 static void
774 hostapd_rrm_nr_clear(struct hostapd_data *hapd)
775 {
776 struct hostapd_neighbor_entry *nr;
777
778 restart:
779 dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry, list) {
780 if (!memcmp(nr->bssid, hapd->own_addr, ETH_ALEN))
781 continue;
782
783 hostapd_neighbor_remove(hapd, nr->bssid, &nr->ssid);
784 goto restart;
785 }
786 }
787
788 static int
789 hostapd_rrm_nr_set(struct ubus_context *ctx, struct ubus_object *obj,
790 struct ubus_request_data *req, const char *method,
791 struct blob_attr *msg)
792 {
793 static const struct blobmsg_policy nr_e_policy[] = {
794 { .type = BLOBMSG_TYPE_STRING },
795 { .type = BLOBMSG_TYPE_STRING },
796 { .type = BLOBMSG_TYPE_STRING },
797 };
798 struct hostapd_data *hapd = get_hapd_from_object(obj);
799 struct blob_attr *tb_l[__NR_SET_LIST_MAX];
800 struct blob_attr *tb[ARRAY_SIZE(nr_e_policy)];
801 struct blob_attr *cur;
802 int ret = 0;
803 int rem;
804
805 hostapd_rrm_nr_enable(hapd);
806
807 blobmsg_parse(nr_set_policy, __NR_SET_LIST_MAX, tb_l, blob_data(msg), blob_len(msg));
808 if (!tb_l[NR_SET_LIST])
809 return UBUS_STATUS_INVALID_ARGUMENT;
810
811 hostapd_rrm_nr_clear(hapd);
812 blobmsg_for_each_attr(cur, tb_l[NR_SET_LIST], rem) {
813 struct wpa_ssid_value ssid;
814 struct wpabuf *data;
815 u8 bssid[ETH_ALEN];
816 char *s;
817
818 blobmsg_parse_array(nr_e_policy, ARRAY_SIZE(nr_e_policy), tb, blobmsg_data(cur), blobmsg_data_len(cur));
819 if (!tb[0] || !tb[1] || !tb[2])
820 goto invalid;
821
822 s = blobmsg_get_string(tb[0]);
823 if (hwaddr_aton(s, bssid))
824 goto invalid;
825
826 s = blobmsg_get_string(tb[1]);
827 ssid.ssid_len = strlen(s);
828 if (ssid.ssid_len > sizeof(ssid.ssid))
829 goto invalid;
830
831 memcpy(&ssid, s, ssid.ssid_len);
832 data = wpabuf_parse_bin(blobmsg_get_string(tb[2]));
833 if (!data)
834 goto invalid;
835
836 hostapd_neighbor_set(hapd, bssid, &ssid, data, NULL, NULL, 0);
837 wpabuf_free(data);
838 continue;
839
840 invalid:
841 ret = UBUS_STATUS_INVALID_ARGUMENT;
842 }
843
844 return 0;
845 }
846
847 enum {
848 BEACON_REQ_ADDR,
849 BEACON_REQ_MODE,
850 BEACON_REQ_OP_CLASS,
851 BEACON_REQ_CHANNEL,
852 BEACON_REQ_DURATION,
853 BEACON_REQ_BSSID,
854 BEACON_REQ_SSID,
855 __BEACON_REQ_MAX,
856 };
857
858 static const struct blobmsg_policy beacon_req_policy[__BEACON_REQ_MAX] = {
859 [BEACON_REQ_ADDR] = { "addr", BLOBMSG_TYPE_STRING },
860 [BEACON_REQ_OP_CLASS] { "op_class", BLOBMSG_TYPE_INT32 },
861 [BEACON_REQ_CHANNEL] { "channel", BLOBMSG_TYPE_INT32 },
862 [BEACON_REQ_DURATION] { "duration", BLOBMSG_TYPE_INT32 },
863 [BEACON_REQ_MODE] { "mode", BLOBMSG_TYPE_INT32 },
864 [BEACON_REQ_BSSID] { "bssid", BLOBMSG_TYPE_STRING },
865 [BEACON_REQ_SSID] { "ssid", BLOBMSG_TYPE_STRING },
866 };
867
868 static int
869 hostapd_rrm_beacon_req(struct ubus_context *ctx, struct ubus_object *obj,
870 struct ubus_request_data *ureq, const char *method,
871 struct blob_attr *msg)
872 {
873 struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
874 struct blob_attr *tb[__BEACON_REQ_MAX];
875 struct blob_attr *cur;
876 struct wpabuf *req;
877 u8 bssid[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
878 u8 addr[ETH_ALEN];
879 int mode, rem, ret;
880 int buf_len = 13;
881
882 blobmsg_parse(beacon_req_policy, __BEACON_REQ_MAX, tb, blob_data(msg), blob_len(msg));
883
884 if (!tb[BEACON_REQ_ADDR] || !tb[BEACON_REQ_MODE] || !tb[BEACON_REQ_DURATION] ||
885 !tb[BEACON_REQ_OP_CLASS] || !tb[BEACON_REQ_CHANNEL])
886 return UBUS_STATUS_INVALID_ARGUMENT;
887
888 if (tb[BEACON_REQ_SSID])
889 buf_len += blobmsg_data_len(tb[BEACON_REQ_SSID]) + 2 - 1;
890
891 mode = blobmsg_get_u32(tb[BEACON_REQ_MODE]);
892 if (hwaddr_aton(blobmsg_data(tb[BEACON_REQ_ADDR]), addr))
893 return UBUS_STATUS_INVALID_ARGUMENT;
894
895 if (tb[BEACON_REQ_BSSID] &&
896 hwaddr_aton(blobmsg_data(tb[BEACON_REQ_BSSID]), bssid))
897 return UBUS_STATUS_INVALID_ARGUMENT;
898
899 req = wpabuf_alloc(buf_len);
900 if (!req)
901 return UBUS_STATUS_UNKNOWN_ERROR;
902
903 /* 1: regulatory class */
904 wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_OP_CLASS]));
905
906 /* 2: channel number */
907 wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_CHANNEL]));
908
909 /* 3-4: randomization interval */
910 wpabuf_put_le16(req, 0);
911
912 /* 5-6: duration */
913 wpabuf_put_le16(req, blobmsg_get_u32(tb[BEACON_REQ_DURATION]));
914
915 /* 7: mode */
916 wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_MODE]));
917
918 /* 8-13: BSSID */
919 wpabuf_put_data(req, bssid, ETH_ALEN);
920
921 if ((cur = tb[BEACON_REQ_SSID]) != NULL) {
922 wpabuf_put_u8(req, WLAN_EID_SSID);
923 wpabuf_put_u8(req, blobmsg_data_len(cur) - 1);
924 wpabuf_put_data(req, blobmsg_data(cur), blobmsg_data_len(cur) - 1);
925 }
926
927 ret = hostapd_send_beacon_req(hapd, addr, 0, req);
928 if (ret < 0)
929 return -ret;
930
931 return 0;
932 }
933
934
935 #ifdef CONFIG_WNM_AP
936 enum {
937 WNM_DISASSOC_ADDR,
938 WNM_DISASSOC_DURATION,
939 WNM_DISASSOC_NEIGHBORS,
940 __WNM_DISASSOC_MAX,
941 };
942
943 static const struct blobmsg_policy wnm_disassoc_policy[__WNM_DISASSOC_MAX] = {
944 [WNM_DISASSOC_ADDR] = { "addr", BLOBMSG_TYPE_STRING },
945 [WNM_DISASSOC_DURATION] { "duration", BLOBMSG_TYPE_INT32 },
946 [WNM_DISASSOC_NEIGHBORS] { "neighbors", BLOBMSG_TYPE_ARRAY },
947 };
948
949 static int
950 hostapd_wnm_disassoc_imminent(struct ubus_context *ctx, struct ubus_object *obj,
951 struct ubus_request_data *ureq, const char *method,
952 struct blob_attr *msg)
953 {
954 struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
955 struct blob_attr *tb[__WNM_DISASSOC_MAX];
956 struct blob_attr *cur;
957 struct sta_info *sta;
958 int duration = 10;
959 int rem;
960 int nr_len = 0;
961 u8 *nr = NULL;
962 u8 req_mode = WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
963 u8 addr[ETH_ALEN];
964
965 blobmsg_parse(wnm_disassoc_policy, __WNM_DISASSOC_MAX, tb, blob_data(msg), blob_len(msg));
966
967 if (!tb[WNM_DISASSOC_ADDR])
968 return UBUS_STATUS_INVALID_ARGUMENT;
969
970 if (hwaddr_aton(blobmsg_data(tb[WNM_DISASSOC_ADDR]), addr))
971 return UBUS_STATUS_INVALID_ARGUMENT;
972
973 if ((cur = tb[WNM_DISASSOC_DURATION]) != NULL)
974 duration = blobmsg_get_u32(cur);
975
976 sta = ap_get_sta(hapd, addr);
977 if (!sta)
978 return UBUS_STATUS_NOT_FOUND;
979
980 if (tb[WNM_DISASSOC_NEIGHBORS]) {
981 u8 *nr_cur;
982
983 if (blobmsg_check_array(tb[WNM_DISASSOC_NEIGHBORS],
984 BLOBMSG_TYPE_STRING) < 0)
985 return UBUS_STATUS_INVALID_ARGUMENT;
986
987 blobmsg_for_each_attr(cur, tb[WNM_DISASSOC_NEIGHBORS], rem) {
988 int len = strlen(blobmsg_get_string(cur));
989
990 if (len % 2)
991 return UBUS_STATUS_INVALID_ARGUMENT;
992
993 nr_len += (len / 2) + 2;
994 }
995
996 if (nr_len) {
997 nr = os_zalloc(nr_len);
998 if (!nr)
999 return UBUS_STATUS_UNKNOWN_ERROR;
1000 }
1001
1002 nr_cur = nr;
1003 blobmsg_for_each_attr(cur, tb[WNM_DISASSOC_NEIGHBORS], rem) {
1004 int len = strlen(blobmsg_get_string(cur)) / 2;
1005
1006 *nr_cur++ = WLAN_EID_NEIGHBOR_REPORT;
1007 *nr_cur++ = (u8) len;
1008 if (hexstr2bin(blobmsg_data(cur), nr_cur, len)) {
1009 free(nr);
1010 return UBUS_STATUS_INVALID_ARGUMENT;
1011 }
1012
1013 nr_cur += len;
1014 }
1015 }
1016
1017 if (nr)
1018 req_mode |= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED;
1019
1020 if (wnm_send_bss_tm_req(hapd, sta, req_mode, duration, 0, NULL,
1021 NULL, nr, nr_len, NULL, 0))
1022 return UBUS_STATUS_UNKNOWN_ERROR;
1023
1024 return 0;
1025 }
1026 #endif
1027
1028 static const struct ubus_method bss_methods[] = {
1029 UBUS_METHOD_NOARG("reload", hostapd_bss_reload),
1030 UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients),
1031 UBUS_METHOD("del_client", hostapd_bss_del_client, del_policy),
1032 UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans),
1033 UBUS_METHOD_NOARG("wps_start", hostapd_bss_wps_start),
1034 UBUS_METHOD_NOARG("wps_cancel", hostapd_bss_wps_cancel),
1035 UBUS_METHOD_NOARG("update_beacon", hostapd_bss_update_beacon),
1036 UBUS_METHOD_NOARG("get_features", hostapd_bss_get_features),
1037 #ifdef NEED_AP_MLME
1038 UBUS_METHOD("switch_chan", hostapd_switch_chan, csa_policy),
1039 #endif
1040 UBUS_METHOD("set_vendor_elements", hostapd_vendor_elements, ve_policy),
1041 UBUS_METHOD("notify_response", hostapd_notify_response, notify_policy),
1042 UBUS_METHOD("bss_mgmt_enable", hostapd_bss_mgmt_enable, bss_mgmt_enable_policy),
1043 UBUS_METHOD_NOARG("rrm_nr_get_own", hostapd_rrm_nr_get_own),
1044 UBUS_METHOD_NOARG("rrm_nr_list", hostapd_rrm_nr_list),
1045 UBUS_METHOD("rrm_nr_set", hostapd_rrm_nr_set, nr_set_policy),
1046 UBUS_METHOD("rrm_beacon_req", hostapd_rrm_beacon_req, beacon_req_policy),
1047 #ifdef CONFIG_WNM_AP
1048 UBUS_METHOD("wnm_disassoc_imminent", hostapd_wnm_disassoc_imminent, wnm_disassoc_policy),
1049 #endif
1050 };
1051
1052 static struct ubus_object_type bss_object_type =
1053 UBUS_OBJECT_TYPE("hostapd_bss", bss_methods);
1054
1055 static int avl_compare_macaddr(const void *k1, const void *k2, void *ptr)
1056 {
1057 return memcmp(k1, k2, ETH_ALEN);
1058 }
1059
1060 void hostapd_ubus_add_bss(struct hostapd_data *hapd)
1061 {
1062 struct ubus_object *obj = &hapd->ubus.obj;
1063 char *name;
1064 int ret;
1065
1066 #ifdef CONFIG_MESH
1067 if (hapd->conf->mesh & MESH_ENABLED)
1068 return;
1069 #endif
1070
1071 if (!hostapd_ubus_init())
1072 return;
1073
1074 if (asprintf(&name, "hostapd.%s", hapd->conf->iface) < 0)
1075 return;
1076
1077 avl_init(&hapd->ubus.banned, avl_compare_macaddr, false, NULL);
1078 obj->name = name;
1079 obj->type = &bss_object_type;
1080 obj->methods = bss_object_type.methods;
1081 obj->n_methods = bss_object_type.n_methods;
1082 ret = ubus_add_object(ctx, obj);
1083 hostapd_ubus_ref_inc();
1084 }
1085
1086 void hostapd_ubus_free_bss(struct hostapd_data *hapd)
1087 {
1088 struct ubus_object *obj = &hapd->ubus.obj;
1089 char *name = (char *) obj->name;
1090
1091 if (!ctx)
1092 return;
1093
1094 if (obj->id) {
1095 ubus_remove_object(ctx, obj);
1096 hostapd_ubus_ref_dec();
1097 }
1098
1099 free(name);
1100 }
1101
1102 static const struct ubus_method daemon_methods[] = {
1103 UBUS_METHOD("config_add", hostapd_config_add, config_add_policy),
1104 UBUS_METHOD("config_remove", hostapd_config_remove, config_remove_policy),
1105 };
1106
1107 static struct ubus_object_type daemon_object_type =
1108 UBUS_OBJECT_TYPE("hostapd", daemon_methods);
1109
1110 void hostapd_ubus_add(struct hapd_interfaces *interfaces)
1111 {
1112 struct ubus_object *obj = &interfaces->ubus;
1113 char *name;
1114 int name_len;
1115 int ret;
1116
1117 if (!hostapd_ubus_init())
1118 return;
1119
1120 name_len = strlen("hostapd") + 1;
1121 if (interfaces->name)
1122 name_len += strlen(interfaces->name) + 1;
1123
1124 name = malloc(name_len);
1125 strcpy(name, "hostapd");
1126 if (interfaces->name) {
1127 strcat(name, ".");
1128 strcat(name, interfaces->name);
1129 }
1130 obj->name = name;
1131
1132 obj->type = &daemon_object_type;
1133 obj->methods = daemon_object_type.methods;
1134 obj->n_methods = daemon_object_type.n_methods;
1135 ret = ubus_add_object(ctx, obj);
1136 hostapd_ubus_ref_inc();
1137 }
1138
1139 void hostapd_ubus_free(struct hapd_interfaces *interfaces)
1140 {
1141 struct ubus_object *obj = &interfaces->ubus;
1142 char *name = (char *) obj->name;
1143
1144 if (!ctx)
1145 return;
1146
1147 if (obj->id) {
1148 ubus_remove_object(ctx, obj);
1149 hostapd_ubus_ref_dec();
1150 }
1151
1152 free(name);
1153 }
1154
1155 struct ubus_event_req {
1156 struct ubus_notify_request nreq;
1157 int resp;
1158 };
1159
1160 static void
1161 ubus_event_cb(struct ubus_notify_request *req, int idx, int ret)
1162 {
1163 struct ubus_event_req *ureq = container_of(req, struct ubus_event_req, nreq);
1164
1165 ureq->resp = ret;
1166 }
1167
1168 int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req)
1169 {
1170 struct ubus_banned_client *ban;
1171 const char *types[HOSTAPD_UBUS_TYPE_MAX] = {
1172 [HOSTAPD_UBUS_PROBE_REQ] = "probe",
1173 [HOSTAPD_UBUS_AUTH_REQ] = "auth",
1174 [HOSTAPD_UBUS_ASSOC_REQ] = "assoc",
1175 };
1176 const char *type = "mgmt";
1177 struct ubus_event_req ureq = {};
1178 const u8 *addr;
1179
1180 if (req->mgmt_frame)
1181 addr = req->mgmt_frame->sa;
1182 else
1183 addr = req->addr;
1184
1185 ban = avl_find_element(&hapd->ubus.banned, addr, ban, avl);
1186 if (ban)
1187 return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1188
1189 if (!hapd->ubus.obj.has_subscribers)
1190 return WLAN_STATUS_SUCCESS;
1191
1192 if (req->type < ARRAY_SIZE(types))
1193 type = types[req->type];
1194
1195 blob_buf_init(&b, 0);
1196 blobmsg_add_macaddr(&b, "address", addr);
1197 if (req->mgmt_frame)
1198 blobmsg_add_macaddr(&b, "target", req->mgmt_frame->da);
1199 if (req->ssi_signal)
1200 blobmsg_add_u32(&b, "signal", req->ssi_signal);
1201 blobmsg_add_u32(&b, "freq", hapd->iface->freq);
1202
1203 if (req->elems) {
1204 if(req->elems->ht_capabilities)
1205 {
1206 struct ieee80211_ht_capabilities *ht_capabilities;
1207 void *ht_cap, *ht_cap_mcs_set, *mcs_set;
1208
1209
1210 ht_capabilities = (struct ieee80211_ht_capabilities*) req->elems->ht_capabilities;
1211 ht_cap = blobmsg_open_table(&b, "ht_capabilities");
1212 blobmsg_add_u16(&b, "ht_capabilities_info", ht_capabilities->ht_capabilities_info);
1213 ht_cap_mcs_set = blobmsg_open_table(&b, "supported_mcs_set");
1214 blobmsg_add_u16(&b, "a_mpdu_params", ht_capabilities->a_mpdu_params);
1215 blobmsg_add_u16(&b, "ht_extended_capabilities", ht_capabilities->ht_extended_capabilities);
1216 blobmsg_add_u32(&b, "tx_bf_capability_info", ht_capabilities->tx_bf_capability_info);
1217 blobmsg_add_u16(&b, "asel_capabilities", ht_capabilities->asel_capabilities);
1218 mcs_set = blobmsg_open_array(&b, "supported_mcs_set");
1219 for (int i = 0; i < 16; i++) {
1220 blobmsg_add_u16(&b, NULL, (u16) ht_capabilities->supported_mcs_set[i]);
1221 }
1222 blobmsg_close_array(&b, mcs_set);
1223 blobmsg_close_table(&b, ht_cap_mcs_set);
1224 blobmsg_close_table(&b, ht_cap);
1225 }
1226 if(req->elems->vht_capabilities)
1227 {
1228 struct ieee80211_vht_capabilities *vht_capabilities;
1229 void *vht_cap, *vht_cap_mcs_set;
1230
1231 vht_capabilities = (struct ieee80211_vht_capabilities*) req->elems->vht_capabilities;
1232 vht_cap = blobmsg_open_table(&b, "vht_capabilities");
1233 blobmsg_add_u32(&b, "vht_capabilities_info", vht_capabilities->vht_capabilities_info);
1234 vht_cap_mcs_set = blobmsg_open_table(&b, "vht_supported_mcs_set");
1235 blobmsg_add_u16(&b, "rx_map", vht_capabilities->vht_supported_mcs_set.rx_map);
1236 blobmsg_add_u16(&b, "rx_highest", vht_capabilities->vht_supported_mcs_set.rx_highest);
1237 blobmsg_add_u16(&b, "tx_map", vht_capabilities->vht_supported_mcs_set.tx_map);
1238 blobmsg_add_u16(&b, "tx_highest", vht_capabilities->vht_supported_mcs_set.tx_highest);
1239 blobmsg_close_table(&b, vht_cap_mcs_set);
1240 blobmsg_close_table(&b, vht_cap);
1241 }
1242 }
1243
1244 if (!hapd->ubus.notify_response) {
1245 ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1);
1246 return WLAN_STATUS_SUCCESS;
1247 }
1248
1249 if (ubus_notify_async(ctx, &hapd->ubus.obj, type, b.head, &ureq.nreq))
1250 return WLAN_STATUS_SUCCESS;
1251
1252 ureq.nreq.status_cb = ubus_event_cb;
1253 ubus_complete_request(ctx, &ureq.nreq.req, 100);
1254
1255 if (ureq.resp)
1256 return ureq.resp;
1257
1258 return WLAN_STATUS_SUCCESS;
1259 }
1260
1261 void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 *addr)
1262 {
1263 if (!hapd->ubus.obj.has_subscribers)
1264 return;
1265
1266 if (!addr)
1267 return;
1268
1269 blob_buf_init(&b, 0);
1270 blobmsg_add_macaddr(&b, "address", addr);
1271
1272 ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1);
1273 }
1274
1275 void hostapd_ubus_notify_beacon_report(
1276 struct hostapd_data *hapd, const u8 *addr, u8 token, u8 rep_mode,
1277 struct rrm_measurement_beacon_report *rep, size_t len)
1278 {
1279 if (!hapd->ubus.obj.has_subscribers)
1280 return;
1281
1282 if (!addr || !rep)
1283 return;
1284
1285 blob_buf_init(&b, 0);
1286 blobmsg_add_macaddr(&b, "address", addr);
1287 blobmsg_add_u16(&b, "op-class", rep->op_class);
1288 blobmsg_add_u16(&b, "channel", rep->channel);
1289 blobmsg_add_u64(&b, "start-time", rep->start_time);
1290 blobmsg_add_u16(&b, "duration", rep->duration);
1291 blobmsg_add_u16(&b, "report-info", rep->report_info);
1292 blobmsg_add_u16(&b, "rcpi", rep->rcpi);
1293 blobmsg_add_u16(&b, "rsni", rep->rsni);
1294 blobmsg_add_macaddr(&b, "bssid", rep->bssid);
1295 blobmsg_add_u16(&b, "antenna-id", rep->antenna_id);
1296 blobmsg_add_u16(&b, "parent-tsf", rep->parent_tsf);
1297
1298 ubus_notify(ctx, &hapd->ubus.obj, "beacon-report", b.head, -1);
1299 }