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