2 * hostapd / ubus support
3 * Copyright (c) 2013, Felix Fietkau <nbd@nbd.name>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
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"
15 #include "neighbor_db.h"
16 #include "wps_hostapd.h"
19 #include "ap_drv_ops.h"
22 static struct ubus_context
*ctx
;
23 static struct blob_buf b
;
26 static inline struct hostapd_data
*get_hapd_from_object(struct ubus_object
*obj
)
28 return container_of(obj
, struct hostapd_data
, ubus
.obj
);
32 struct ubus_banned_client
{
37 static void ubus_receive(int sock
, void *eloop_ctx
, void *sock_ctx
)
39 struct ubus_context
*ctx
= eloop_ctx
;
40 ubus_handle_event(ctx
);
43 static void ubus_reconnect_timeout(void *eloop_data
, void *user_ctx
)
45 if (ubus_reconnect(ctx
, NULL
)) {
46 eloop_register_timeout(1, 0, ubus_reconnect_timeout
, ctx
, NULL
);
50 eloop_register_read_sock(ctx
->sock
.fd
, ubus_receive
, ctx
, NULL
);
53 static void hostapd_ubus_connection_lost(struct ubus_context
*ctx
)
55 eloop_unregister_read_sock(ctx
->sock
.fd
);
56 eloop_register_timeout(1, 0, ubus_reconnect_timeout
, ctx
, NULL
);
59 static bool hostapd_ubus_init(void)
64 ctx
= ubus_connect(NULL
);
68 ctx
->connection_lost
= hostapd_ubus_connection_lost
;
69 eloop_register_read_sock(ctx
->sock
.fd
, ubus_receive
, ctx
, NULL
);
73 static void hostapd_ubus_ref_inc(void)
78 static void hostapd_ubus_ref_dec(void)
87 eloop_unregister_read_sock(ctx
->sock
.fd
);
92 void hostapd_ubus_add_iface(struct hostapd_iface
*iface
)
94 if (!hostapd_ubus_init())
98 void hostapd_ubus_free_iface(struct hostapd_iface
*iface
)
105 hostapd_bss_del_ban(void *eloop_data
, void *user_ctx
)
107 struct ubus_banned_client
*ban
= eloop_data
;
108 struct hostapd_data
*hapd
= user_ctx
;
110 avl_delete(&hapd
->ubus
.banned
, &ban
->avl
);
115 hostapd_bss_ban_client(struct hostapd_data
*hapd
, u8
*addr
, int time
)
117 struct ubus_banned_client
*ban
;
122 ban
= avl_find_element(&hapd
->ubus
.banned
, addr
, ban
, avl
);
127 ban
= os_zalloc(sizeof(*ban
));
128 memcpy(ban
->addr
, addr
, sizeof(ban
->addr
));
129 ban
->avl
.key
= ban
->addr
;
130 avl_insert(&hapd
->ubus
.banned
, &ban
->avl
);
132 eloop_cancel_timeout(hostapd_bss_del_ban
, ban
, hapd
);
134 hostapd_bss_del_ban(ban
, hapd
);
139 eloop_register_timeout(0, time
* 1000, hostapd_bss_del_ban
, ban
, hapd
);
143 hostapd_bss_get_clients(struct ubus_context
*ctx
, struct ubus_object
*obj
,
144 struct ubus_request_data
*req
, const char *method
,
145 struct blob_attr
*msg
)
147 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
148 struct sta_info
*sta
;
151 static const struct {
155 { "auth", WLAN_STA_AUTH
},
156 { "assoc", WLAN_STA_ASSOC
},
157 { "authorized", WLAN_STA_AUTHORIZED
},
158 { "preauth", WLAN_STA_PREAUTH
},
159 { "wds", WLAN_STA_WDS
},
160 { "wmm", WLAN_STA_WMM
},
161 { "ht", WLAN_STA_HT
},
162 { "vht", WLAN_STA_VHT
},
163 { "wps", WLAN_STA_WPS
},
164 { "mfp", WLAN_STA_MFP
},
167 blob_buf_init(&b
, 0);
168 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
169 list
= blobmsg_open_table(&b
, "clients");
170 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
173 sprintf(mac_buf
, MACSTR
, MAC2STR(sta
->addr
));
174 c
= blobmsg_open_table(&b
, mac_buf
);
175 for (i
= 0; i
< ARRAY_SIZE(sta_flags
); i
++)
176 blobmsg_add_u8(&b
, sta_flags
[i
].name
,
177 !!(sta
->flags
& sta_flags
[i
].flag
));
178 blobmsg_add_u32(&b
, "aid", sta
->aid
);
179 blobmsg_close_table(&b
, c
);
181 blobmsg_close_array(&b
, list
);
182 ubus_send_reply(ctx
, req
, b
.head
);
192 static const struct blobmsg_policy notify_policy
[__NOTIFY_MAX
] = {
193 [NOTIFY_RESPONSE
] = { "notify_response", BLOBMSG_TYPE_INT32
},
197 hostapd_notify_response(struct ubus_context
*ctx
, struct ubus_object
*obj
,
198 struct ubus_request_data
*req
, const char *method
,
199 struct blob_attr
*msg
)
201 struct blob_attr
*tb
[__NOTIFY_MAX
];
202 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
203 struct wpabuf
*elems
;
207 blobmsg_parse(notify_policy
, __NOTIFY_MAX
, tb
,
208 blob_data(msg
), blob_len(msg
));
210 if (!tb
[NOTIFY_RESPONSE
])
211 return UBUS_STATUS_INVALID_ARGUMENT
;
213 hapd
->ubus
.notify_response
= blobmsg_get_u32(tb
[NOTIFY_RESPONSE
]);
215 return UBUS_STATUS_OK
;
226 static const struct blobmsg_policy del_policy
[__DEL_CLIENT_MAX
] = {
227 [DEL_CLIENT_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
228 [DEL_CLIENT_REASON
] = { "reason", BLOBMSG_TYPE_INT32
},
229 [DEL_CLIENT_DEAUTH
] = { "deauth", BLOBMSG_TYPE_INT8
},
230 [DEL_CLIENT_BAN_TIME
] = { "ban_time", BLOBMSG_TYPE_INT32
},
234 hostapd_bss_del_client(struct ubus_context
*ctx
, struct ubus_object
*obj
,
235 struct ubus_request_data
*req
, const char *method
,
236 struct blob_attr
*msg
)
238 struct blob_attr
*tb
[__DEL_CLIENT_MAX
];
239 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
240 struct sta_info
*sta
;
245 blobmsg_parse(del_policy
, __DEL_CLIENT_MAX
, tb
, blob_data(msg
), blob_len(msg
));
247 if (!tb
[DEL_CLIENT_ADDR
])
248 return UBUS_STATUS_INVALID_ARGUMENT
;
250 if (hwaddr_aton(blobmsg_data(tb
[DEL_CLIENT_ADDR
]), addr
))
251 return UBUS_STATUS_INVALID_ARGUMENT
;
253 if (tb
[DEL_CLIENT_REASON
])
254 reason
= blobmsg_get_u32(tb
[DEL_CLIENT_REASON
]);
256 if (tb
[DEL_CLIENT_DEAUTH
])
257 deauth
= blobmsg_get_bool(tb
[DEL_CLIENT_DEAUTH
]);
259 sta
= ap_get_sta(hapd
, addr
);
262 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
263 ap_sta_deauthenticate(hapd
, sta
, reason
);
265 hostapd_drv_sta_disassoc(hapd
, addr
, reason
);
266 ap_sta_disassociate(hapd
, sta
, reason
);
270 if (tb
[DEL_CLIENT_BAN_TIME
])
271 hostapd_bss_ban_client(hapd
, addr
, blobmsg_get_u32(tb
[DEL_CLIENT_BAN_TIME
]));
277 blobmsg_add_macaddr(struct blob_buf
*buf
, const char *name
, const u8
*addr
)
281 s
= blobmsg_alloc_string_buffer(buf
, name
, 20);
282 sprintf(s
, MACSTR
, MAC2STR(addr
));
283 blobmsg_add_string_buffer(buf
);
287 hostapd_bss_list_bans(struct ubus_context
*ctx
, struct ubus_object
*obj
,
288 struct ubus_request_data
*req
, const char *method
,
289 struct blob_attr
*msg
)
291 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
292 struct ubus_banned_client
*ban
;
295 blob_buf_init(&b
, 0);
296 c
= blobmsg_open_array(&b
, "clients");
297 avl_for_each_element(&hapd
->ubus
.banned
, ban
, avl
)
298 blobmsg_add_macaddr(&b
, NULL
, ban
->addr
);
299 blobmsg_close_array(&b
, c
);
300 ubus_send_reply(ctx
, req
, b
.head
);
306 hostapd_bss_wps_start(struct ubus_context
*ctx
, struct ubus_object
*obj
,
307 struct ubus_request_data
*req
, const char *method
,
308 struct blob_attr
*msg
)
311 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
313 rc
= hostapd_wps_button_pushed(hapd
, NULL
);
316 return UBUS_STATUS_NOT_SUPPORTED
;
322 hostapd_bss_wps_cancel(struct ubus_context
*ctx
, struct ubus_object
*obj
,
323 struct ubus_request_data
*req
, const char *method
,
324 struct blob_attr
*msg
)
327 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
329 rc
= hostapd_wps_cancel(hapd
);
332 return UBUS_STATUS_NOT_SUPPORTED
;
338 hostapd_bss_update_beacon(struct ubus_context
*ctx
, struct ubus_object
*obj
,
339 struct ubus_request_data
*req
, const char *method
,
340 struct blob_attr
*msg
)
343 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
345 rc
= ieee802_11_set_beacon(hapd
);
348 return UBUS_STATUS_NOT_SUPPORTED
;
359 static const struct blobmsg_policy csa_policy
[__CSA_MAX
] = {
361 * for now, frequency and beacon count are enough, add more
362 * parameters on demand
364 [CSA_FREQ
] = { "freq", BLOBMSG_TYPE_INT32
},
365 [CSA_BCN_COUNT
] = { "bcn_count", BLOBMSG_TYPE_INT32
},
370 hostapd_switch_chan(struct ubus_context
*ctx
, struct ubus_object
*obj
,
371 struct ubus_request_data
*req
, const char *method
,
372 struct blob_attr
*msg
)
374 struct blob_attr
*tb
[__CSA_MAX
];
375 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
376 struct csa_settings css
;
378 blobmsg_parse(csa_policy
, __CSA_MAX
, tb
, blob_data(msg
), blob_len(msg
));
381 return UBUS_STATUS_INVALID_ARGUMENT
;
383 memset(&css
, 0, sizeof(css
));
384 css
.freq_params
.freq
= blobmsg_get_u32(tb
[CSA_FREQ
]);
385 if (tb
[CSA_BCN_COUNT
])
386 css
.cs_count
= blobmsg_get_u32(tb
[CSA_BCN_COUNT
]);
388 if (hostapd_switch_channel(hapd
, &css
) != 0)
389 return UBUS_STATUS_NOT_SUPPORTED
;
390 return UBUS_STATUS_OK
;
396 __VENDOR_ELEMENTS_MAX
399 static const struct blobmsg_policy ve_policy
[__VENDOR_ELEMENTS_MAX
] = {
400 /* vendor elements are provided as hex-string */
401 [VENDOR_ELEMENTS
] = { "vendor_elements", BLOBMSG_TYPE_STRING
},
405 hostapd_vendor_elements(struct ubus_context
*ctx
, struct ubus_object
*obj
,
406 struct ubus_request_data
*req
, const char *method
,
407 struct blob_attr
*msg
)
409 struct blob_attr
*tb
[__VENDOR_ELEMENTS_MAX
];
410 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
411 struct hostapd_bss_config
*bss
= hapd
->conf
;
412 struct wpabuf
*elems
;
416 blobmsg_parse(ve_policy
, __VENDOR_ELEMENTS_MAX
, tb
,
417 blob_data(msg
), blob_len(msg
));
419 if (!tb
[VENDOR_ELEMENTS
])
420 return UBUS_STATUS_INVALID_ARGUMENT
;
422 pos
= blobmsg_data(tb
[VENDOR_ELEMENTS
]);
423 len
= os_strlen(pos
);
425 return UBUS_STATUS_INVALID_ARGUMENT
;
429 wpabuf_free(bss
->vendor_elements
);
430 bss
->vendor_elements
= NULL
;
434 elems
= wpabuf_alloc(len
);
438 if (hexstr2bin(pos
, wpabuf_put(elems
, len
), len
)) {
440 return UBUS_STATUS_INVALID_ARGUMENT
;
443 wpabuf_free(bss
->vendor_elements
);
444 bss
->vendor_elements
= elems
;
446 /* update beacons if vendor elements were set successfully */
447 if (ieee802_11_update_beacons(hapd
->iface
) != 0)
448 return UBUS_STATUS_NOT_SUPPORTED
;
449 return UBUS_STATUS_OK
;
453 hostapd_rrm_print_nr(struct hostapd_neighbor_entry
*nr
)
459 blobmsg_printf(&b
, "", MACSTR
, MAC2STR(nr
->bssid
));
461 str
= blobmsg_alloc_string_buffer(&b
, "", nr
->ssid
.ssid_len
+ 1);
462 memcpy(str
, nr
->ssid
.ssid
, nr
->ssid
.ssid_len
);
463 str
[nr
->ssid
.ssid_len
] = 0;
464 blobmsg_add_string_buffer(&b
);
466 len
= wpabuf_len(nr
->nr
);
467 str
= blobmsg_alloc_string_buffer(&b
, "", 2 * len
+ 1);
468 wpa_snprintf_hex(str
, 2 * len
+ 1, wpabuf_head_u8(nr
->nr
), len
);
469 blobmsg_add_string_buffer(&b
);
473 BSS_MGMT_EN_NEIGHBOR
,
476 BSS_MGMT_EN_BSS_TRANSITION
,
482 __hostapd_bss_mgmt_enable_f(struct hostapd_data
*hapd
, int flag
)
484 struct hostapd_bss_config
*bss
= hapd
->conf
;
488 case BSS_MGMT_EN_NEIGHBOR
:
489 if (bss
->radio_measurements
[0] &
490 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)
493 bss
->radio_measurements
[0] |=
494 WLAN_RRM_CAPS_NEIGHBOR_REPORT
;
495 hostapd_set_own_neighbor_report(hapd
);
497 case BSS_MGMT_EN_BEACON
:
498 flags
= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE
|
499 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE
|
500 WLAN_RRM_CAPS_BEACON_REPORT_TABLE
;
502 if (bss
->radio_measurements
[0] & flags
== flags
)
505 bss
->radio_measurements
[0] |= (u8
) flags
;
508 case BSS_MGMT_EN_BSS_TRANSITION
:
509 if (bss
->bss_transition
)
512 bss
->bss_transition
= 1;
519 __hostapd_bss_mgmt_enable(struct hostapd_data
*hapd
, uint32_t flags
)
524 for (i
= 0; i
< __BSS_MGMT_EN_MAX
; i
++) {
525 if (!(flags
& (1 << i
)))
528 update
|= __hostapd_bss_mgmt_enable_f(hapd
, i
);
532 ieee802_11_update_beacons(hapd
->iface
);
536 static const struct blobmsg_policy bss_mgmt_enable_policy
[__BSS_MGMT_EN_MAX
] = {
537 [BSS_MGMT_EN_NEIGHBOR
] = { "neighbor_report", BLOBMSG_TYPE_BOOL
},
538 [BSS_MGMT_EN_BEACON
] = { "beacon_report", BLOBMSG_TYPE_BOOL
},
540 [BSS_MGMT_EN_BSS_TRANSITION
] = { "bss_transition", BLOBMSG_TYPE_BOOL
},
545 hostapd_bss_mgmt_enable(struct ubus_context
*ctx
, struct ubus_object
*obj
,
546 struct ubus_request_data
*req
, const char *method
,
547 struct blob_attr
*msg
)
550 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
551 struct blob_attr
*tb
[__BSS_MGMT_EN_MAX
];
552 struct blob_attr
*cur
;
555 bool neigh
= false, beacon
= false;
557 blobmsg_parse(bss_mgmt_enable_policy
, __BSS_MGMT_EN_MAX
, tb
, blob_data(msg
), blob_len(msg
));
559 for (i
= 0; i
< ARRAY_SIZE(tb
); i
++) {
560 if (!tb
[i
] || !blobmsg_get_bool(tb
[i
]))
566 __hostapd_bss_mgmt_enable(hapd
, flags
);
571 hostapd_rrm_nr_enable(struct hostapd_data
*hapd
)
573 __hostapd_bss_mgmt_enable(hapd
, 1 << BSS_MGMT_EN_NEIGHBOR
);
577 hostapd_rrm_nr_get_own(struct ubus_context
*ctx
, struct ubus_object
*obj
,
578 struct ubus_request_data
*req
, const char *method
,
579 struct blob_attr
*msg
)
581 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
582 struct hostapd_neighbor_entry
*nr
;
585 hostapd_rrm_nr_enable(hapd
);
587 nr
= hostapd_neighbor_get(hapd
, hapd
->own_addr
, NULL
);
589 return UBUS_STATUS_NOT_FOUND
;
591 blob_buf_init(&b
, 0);
593 c
= blobmsg_open_array(&b
, "value");
594 hostapd_rrm_print_nr(nr
);
595 blobmsg_close_array(&b
, c
);
597 ubus_send_reply(ctx
, req
, b
.head
);
603 hostapd_rrm_nr_list(struct ubus_context
*ctx
, struct ubus_object
*obj
,
604 struct ubus_request_data
*req
, const char *method
,
605 struct blob_attr
*msg
)
607 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
608 struct hostapd_neighbor_entry
*nr
;
611 hostapd_rrm_nr_enable(hapd
);
612 blob_buf_init(&b
, 0);
614 c
= blobmsg_open_array(&b
, "list");
615 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
618 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
621 cur
= blobmsg_open_array(&b
, NULL
);
622 hostapd_rrm_print_nr(nr
);
623 blobmsg_close_array(&b
, cur
);
625 blobmsg_close_array(&b
, c
);
627 ubus_send_reply(ctx
, req
, b
.head
);
637 static const struct blobmsg_policy nr_set_policy
[__NR_SET_LIST_MAX
] = {
638 [NR_SET_LIST
] = { "list", BLOBMSG_TYPE_ARRAY
},
643 hostapd_rrm_nr_clear(struct hostapd_data
*hapd
)
645 struct hostapd_neighbor_entry
*nr
;
648 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
649 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
652 hostapd_neighbor_remove(hapd
, nr
->bssid
, &nr
->ssid
);
658 hostapd_rrm_nr_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
659 struct ubus_request_data
*req
, const char *method
,
660 struct blob_attr
*msg
)
662 static const struct blobmsg_policy nr_e_policy
[] = {
663 { .type
= BLOBMSG_TYPE_STRING
},
664 { .type
= BLOBMSG_TYPE_STRING
},
665 { .type
= BLOBMSG_TYPE_STRING
},
667 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
668 struct blob_attr
*tb_l
[__NR_SET_LIST_MAX
];
669 struct blob_attr
*tb
[ARRAY_SIZE(nr_e_policy
)];
670 struct blob_attr
*cur
;
674 hostapd_rrm_nr_enable(hapd
);
676 blobmsg_parse(nr_set_policy
, __NR_SET_LIST_MAX
, tb_l
, blob_data(msg
), blob_len(msg
));
677 if (!tb_l
[NR_SET_LIST
])
678 return UBUS_STATUS_INVALID_ARGUMENT
;
680 hostapd_rrm_nr_clear(hapd
);
681 blobmsg_for_each_attr(cur
, tb_l
[NR_SET_LIST
], rem
) {
682 struct wpa_ssid_value ssid
;
687 blobmsg_parse_array(nr_e_policy
, ARRAY_SIZE(nr_e_policy
), tb
, blobmsg_data(cur
), blobmsg_data_len(cur
));
688 if (!tb
[0] || !tb
[1] || !tb
[2])
691 s
= blobmsg_get_string(tb
[0]);
692 if (hwaddr_aton(s
, bssid
))
695 s
= blobmsg_get_string(tb
[1]);
696 ssid
.ssid_len
= strlen(s
);
697 if (ssid
.ssid_len
> sizeof(ssid
.ssid
))
700 memcpy(&ssid
, s
, ssid
.ssid_len
);
701 data
= wpabuf_parse_bin(blobmsg_get_string(tb
[2]));
705 hostapd_neighbor_set(hapd
, bssid
, &ssid
, data
, NULL
, NULL
, 0);
710 ret
= UBUS_STATUS_INVALID_ARGUMENT
;
716 static const struct ubus_method bss_methods
[] = {
717 UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients
),
718 UBUS_METHOD("del_client", hostapd_bss_del_client
, del_policy
),
719 UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans
),
720 UBUS_METHOD_NOARG("wps_start", hostapd_bss_wps_start
),
721 UBUS_METHOD_NOARG("wps_cancel", hostapd_bss_wps_cancel
),
722 UBUS_METHOD_NOARG("update_beacon", hostapd_bss_update_beacon
),
724 UBUS_METHOD("switch_chan", hostapd_switch_chan
, csa_policy
),
726 UBUS_METHOD("set_vendor_elements", hostapd_vendor_elements
, ve_policy
),
727 UBUS_METHOD("notify_response", hostapd_notify_response
, notify_policy
),
728 UBUS_METHOD("bss_mgmt_enable", hostapd_bss_mgmt_enable
, bss_mgmt_enable_policy
),
729 UBUS_METHOD_NOARG("rrm_nr_get_own", hostapd_rrm_nr_get_own
),
730 UBUS_METHOD_NOARG("rrm_nr_list", hostapd_rrm_nr_list
),
731 UBUS_METHOD("rrm_nr_set", hostapd_rrm_nr_set
, nr_set_policy
),
734 static struct ubus_object_type bss_object_type
=
735 UBUS_OBJECT_TYPE("hostapd_bss", bss_methods
);
737 static int avl_compare_macaddr(const void *k1
, const void *k2
, void *ptr
)
739 return memcmp(k1
, k2
, ETH_ALEN
);
742 void hostapd_ubus_add_bss(struct hostapd_data
*hapd
)
744 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
748 if (!hostapd_ubus_init())
751 if (asprintf(&name
, "hostapd.%s", hapd
->conf
->iface
) < 0)
754 avl_init(&hapd
->ubus
.banned
, avl_compare_macaddr
, false, NULL
);
756 obj
->type
= &bss_object_type
;
757 obj
->methods
= bss_object_type
.methods
;
758 obj
->n_methods
= bss_object_type
.n_methods
;
759 ret
= ubus_add_object(ctx
, obj
);
760 hostapd_ubus_ref_inc();
763 void hostapd_ubus_free_bss(struct hostapd_data
*hapd
)
765 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
766 char *name
= (char *) obj
->name
;
772 ubus_remove_object(ctx
, obj
);
773 hostapd_ubus_ref_dec();
779 struct ubus_event_req
{
780 struct ubus_notify_request nreq
;
785 ubus_event_cb(struct ubus_notify_request
*req
, int idx
, int ret
)
787 struct ubus_event_req
*ureq
= container_of(req
, struct ubus_event_req
, nreq
);
793 int hostapd_ubus_handle_event(struct hostapd_data
*hapd
, struct hostapd_ubus_request
*req
)
795 struct ubus_banned_client
*ban
;
796 const char *types
[HOSTAPD_UBUS_TYPE_MAX
] = {
797 [HOSTAPD_UBUS_PROBE_REQ
] = "probe",
798 [HOSTAPD_UBUS_AUTH_REQ
] = "auth",
799 [HOSTAPD_UBUS_ASSOC_REQ
] = "assoc",
801 const char *type
= "mgmt";
802 struct ubus_event_req ureq
= {};
806 addr
= req
->mgmt_frame
->sa
;
810 ban
= avl_find_element(&hapd
->ubus
.banned
, addr
, ban
, avl
);
814 if (!hapd
->ubus
.obj
.has_subscribers
)
817 if (req
->type
< ARRAY_SIZE(types
))
818 type
= types
[req
->type
];
820 blob_buf_init(&b
, 0);
821 blobmsg_add_macaddr(&b
, "address", addr
);
823 blobmsg_add_macaddr(&b
, "target", req
->mgmt_frame
->da
);
825 blobmsg_add_u32(&b
, "signal", req
->frame_info
->ssi_signal
);
826 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
828 if (!hapd
->ubus
.notify_response
) {
829 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);
833 if (ubus_notify_async(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, &ureq
.nreq
))
836 ureq
.nreq
.status_cb
= ubus_event_cb
;
837 ubus_complete_request(ctx
, &ureq
.nreq
.req
, 100);
845 void hostapd_ubus_notify(struct hostapd_data
*hapd
, const char *type
, const u8
*addr
)
847 if (!hapd
->ubus
.obj
.has_subscribers
)
853 blob_buf_init(&b
, 0);
854 blobmsg_add_macaddr(&b
, "address", addr
);
856 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);