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
) {
174 sprintf(mac_buf
, MACSTR
, MAC2STR(sta
->addr
));
175 c
= blobmsg_open_table(&b
, mac_buf
);
176 for (i
= 0; i
< ARRAY_SIZE(sta_flags
); i
++)
177 blobmsg_add_u8(&b
, sta_flags
[i
].name
,
178 !!(sta
->flags
& sta_flags
[i
].flag
));
180 r
= blobmsg_open_array(&b
, "rrm");
181 for (i
= 0; i
< ARRAY_SIZE(sta
->rrm_enabled_capa
); i
++)
182 blobmsg_add_u32(&b
, "", sta
->rrm_enabled_capa
[i
]);
183 blobmsg_close_array(&b
, r
);
184 blobmsg_add_u32(&b
, "aid", sta
->aid
);
185 blobmsg_close_table(&b
, c
);
187 blobmsg_close_array(&b
, list
);
188 ubus_send_reply(ctx
, req
, b
.head
);
198 static const struct blobmsg_policy notify_policy
[__NOTIFY_MAX
] = {
199 [NOTIFY_RESPONSE
] = { "notify_response", BLOBMSG_TYPE_INT32
},
203 hostapd_notify_response(struct ubus_context
*ctx
, struct ubus_object
*obj
,
204 struct ubus_request_data
*req
, const char *method
,
205 struct blob_attr
*msg
)
207 struct blob_attr
*tb
[__NOTIFY_MAX
];
208 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
209 struct wpabuf
*elems
;
213 blobmsg_parse(notify_policy
, __NOTIFY_MAX
, tb
,
214 blob_data(msg
), blob_len(msg
));
216 if (!tb
[NOTIFY_RESPONSE
])
217 return UBUS_STATUS_INVALID_ARGUMENT
;
219 hapd
->ubus
.notify_response
= blobmsg_get_u32(tb
[NOTIFY_RESPONSE
]);
221 return UBUS_STATUS_OK
;
232 static const struct blobmsg_policy del_policy
[__DEL_CLIENT_MAX
] = {
233 [DEL_CLIENT_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
234 [DEL_CLIENT_REASON
] = { "reason", BLOBMSG_TYPE_INT32
},
235 [DEL_CLIENT_DEAUTH
] = { "deauth", BLOBMSG_TYPE_INT8
},
236 [DEL_CLIENT_BAN_TIME
] = { "ban_time", BLOBMSG_TYPE_INT32
},
240 hostapd_bss_del_client(struct ubus_context
*ctx
, struct ubus_object
*obj
,
241 struct ubus_request_data
*req
, const char *method
,
242 struct blob_attr
*msg
)
244 struct blob_attr
*tb
[__DEL_CLIENT_MAX
];
245 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
246 struct sta_info
*sta
;
251 blobmsg_parse(del_policy
, __DEL_CLIENT_MAX
, tb
, blob_data(msg
), blob_len(msg
));
253 if (!tb
[DEL_CLIENT_ADDR
])
254 return UBUS_STATUS_INVALID_ARGUMENT
;
256 if (hwaddr_aton(blobmsg_data(tb
[DEL_CLIENT_ADDR
]), addr
))
257 return UBUS_STATUS_INVALID_ARGUMENT
;
259 if (tb
[DEL_CLIENT_REASON
])
260 reason
= blobmsg_get_u32(tb
[DEL_CLIENT_REASON
]);
262 if (tb
[DEL_CLIENT_DEAUTH
])
263 deauth
= blobmsg_get_bool(tb
[DEL_CLIENT_DEAUTH
]);
265 sta
= ap_get_sta(hapd
, addr
);
268 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
269 ap_sta_deauthenticate(hapd
, sta
, reason
);
271 hostapd_drv_sta_disassoc(hapd
, addr
, reason
);
272 ap_sta_disassociate(hapd
, sta
, reason
);
276 if (tb
[DEL_CLIENT_BAN_TIME
])
277 hostapd_bss_ban_client(hapd
, addr
, blobmsg_get_u32(tb
[DEL_CLIENT_BAN_TIME
]));
283 blobmsg_add_macaddr(struct blob_buf
*buf
, const char *name
, const u8
*addr
)
287 s
= blobmsg_alloc_string_buffer(buf
, name
, 20);
288 sprintf(s
, MACSTR
, MAC2STR(addr
));
289 blobmsg_add_string_buffer(buf
);
293 hostapd_bss_list_bans(struct ubus_context
*ctx
, struct ubus_object
*obj
,
294 struct ubus_request_data
*req
, const char *method
,
295 struct blob_attr
*msg
)
297 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
298 struct ubus_banned_client
*ban
;
301 blob_buf_init(&b
, 0);
302 c
= blobmsg_open_array(&b
, "clients");
303 avl_for_each_element(&hapd
->ubus
.banned
, ban
, avl
)
304 blobmsg_add_macaddr(&b
, NULL
, ban
->addr
);
305 blobmsg_close_array(&b
, c
);
306 ubus_send_reply(ctx
, req
, b
.head
);
312 hostapd_bss_wps_start(struct ubus_context
*ctx
, struct ubus_object
*obj
,
313 struct ubus_request_data
*req
, const char *method
,
314 struct blob_attr
*msg
)
317 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
319 rc
= hostapd_wps_button_pushed(hapd
, NULL
);
322 return UBUS_STATUS_NOT_SUPPORTED
;
328 hostapd_bss_wps_cancel(struct ubus_context
*ctx
, struct ubus_object
*obj
,
329 struct ubus_request_data
*req
, const char *method
,
330 struct blob_attr
*msg
)
333 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
335 rc
= hostapd_wps_cancel(hapd
);
338 return UBUS_STATUS_NOT_SUPPORTED
;
344 hostapd_bss_update_beacon(struct ubus_context
*ctx
, struct ubus_object
*obj
,
345 struct ubus_request_data
*req
, const char *method
,
346 struct blob_attr
*msg
)
349 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
351 rc
= ieee802_11_set_beacon(hapd
);
354 return UBUS_STATUS_NOT_SUPPORTED
;
365 static const struct blobmsg_policy csa_policy
[__CSA_MAX
] = {
367 * for now, frequency and beacon count are enough, add more
368 * parameters on demand
370 [CSA_FREQ
] = { "freq", BLOBMSG_TYPE_INT32
},
371 [CSA_BCN_COUNT
] = { "bcn_count", BLOBMSG_TYPE_INT32
},
376 hostapd_switch_chan(struct ubus_context
*ctx
, struct ubus_object
*obj
,
377 struct ubus_request_data
*req
, const char *method
,
378 struct blob_attr
*msg
)
380 struct blob_attr
*tb
[__CSA_MAX
];
381 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
382 struct csa_settings css
;
384 blobmsg_parse(csa_policy
, __CSA_MAX
, tb
, blob_data(msg
), blob_len(msg
));
387 return UBUS_STATUS_INVALID_ARGUMENT
;
389 memset(&css
, 0, sizeof(css
));
390 css
.freq_params
.freq
= blobmsg_get_u32(tb
[CSA_FREQ
]);
391 if (tb
[CSA_BCN_COUNT
])
392 css
.cs_count
= blobmsg_get_u32(tb
[CSA_BCN_COUNT
]);
394 if (hostapd_switch_channel(hapd
, &css
) != 0)
395 return UBUS_STATUS_NOT_SUPPORTED
;
396 return UBUS_STATUS_OK
;
402 __VENDOR_ELEMENTS_MAX
405 static const struct blobmsg_policy ve_policy
[__VENDOR_ELEMENTS_MAX
] = {
406 /* vendor elements are provided as hex-string */
407 [VENDOR_ELEMENTS
] = { "vendor_elements", BLOBMSG_TYPE_STRING
},
411 hostapd_vendor_elements(struct ubus_context
*ctx
, struct ubus_object
*obj
,
412 struct ubus_request_data
*req
, const char *method
,
413 struct blob_attr
*msg
)
415 struct blob_attr
*tb
[__VENDOR_ELEMENTS_MAX
];
416 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
417 struct hostapd_bss_config
*bss
= hapd
->conf
;
418 struct wpabuf
*elems
;
422 blobmsg_parse(ve_policy
, __VENDOR_ELEMENTS_MAX
, tb
,
423 blob_data(msg
), blob_len(msg
));
425 if (!tb
[VENDOR_ELEMENTS
])
426 return UBUS_STATUS_INVALID_ARGUMENT
;
428 pos
= blobmsg_data(tb
[VENDOR_ELEMENTS
]);
429 len
= os_strlen(pos
);
431 return UBUS_STATUS_INVALID_ARGUMENT
;
435 wpabuf_free(bss
->vendor_elements
);
436 bss
->vendor_elements
= NULL
;
440 elems
= wpabuf_alloc(len
);
444 if (hexstr2bin(pos
, wpabuf_put(elems
, len
), len
)) {
446 return UBUS_STATUS_INVALID_ARGUMENT
;
449 wpabuf_free(bss
->vendor_elements
);
450 bss
->vendor_elements
= elems
;
452 /* update beacons if vendor elements were set successfully */
453 if (ieee802_11_update_beacons(hapd
->iface
) != 0)
454 return UBUS_STATUS_NOT_SUPPORTED
;
455 return UBUS_STATUS_OK
;
459 hostapd_rrm_print_nr(struct hostapd_neighbor_entry
*nr
)
465 blobmsg_printf(&b
, "", MACSTR
, MAC2STR(nr
->bssid
));
467 str
= blobmsg_alloc_string_buffer(&b
, "", nr
->ssid
.ssid_len
+ 1);
468 memcpy(str
, nr
->ssid
.ssid
, nr
->ssid
.ssid_len
);
469 str
[nr
->ssid
.ssid_len
] = 0;
470 blobmsg_add_string_buffer(&b
);
472 len
= wpabuf_len(nr
->nr
);
473 str
= blobmsg_alloc_string_buffer(&b
, "", 2 * len
+ 1);
474 wpa_snprintf_hex(str
, 2 * len
+ 1, wpabuf_head_u8(nr
->nr
), len
);
475 blobmsg_add_string_buffer(&b
);
479 BSS_MGMT_EN_NEIGHBOR
,
482 BSS_MGMT_EN_BSS_TRANSITION
,
488 __hostapd_bss_mgmt_enable_f(struct hostapd_data
*hapd
, int flag
)
490 struct hostapd_bss_config
*bss
= hapd
->conf
;
494 case BSS_MGMT_EN_NEIGHBOR
:
495 if (bss
->radio_measurements
[0] &
496 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)
499 bss
->radio_measurements
[0] |=
500 WLAN_RRM_CAPS_NEIGHBOR_REPORT
;
501 hostapd_set_own_neighbor_report(hapd
);
503 case BSS_MGMT_EN_BEACON
:
504 flags
= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE
|
505 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE
|
506 WLAN_RRM_CAPS_BEACON_REPORT_TABLE
;
508 if (bss
->radio_measurements
[0] & flags
== flags
)
511 bss
->radio_measurements
[0] |= (u8
) flags
;
514 case BSS_MGMT_EN_BSS_TRANSITION
:
515 if (bss
->bss_transition
)
518 bss
->bss_transition
= 1;
525 __hostapd_bss_mgmt_enable(struct hostapd_data
*hapd
, uint32_t flags
)
530 for (i
= 0; i
< __BSS_MGMT_EN_MAX
; i
++) {
531 if (!(flags
& (1 << i
)))
534 update
|= __hostapd_bss_mgmt_enable_f(hapd
, i
);
538 ieee802_11_update_beacons(hapd
->iface
);
542 static const struct blobmsg_policy bss_mgmt_enable_policy
[__BSS_MGMT_EN_MAX
] = {
543 [BSS_MGMT_EN_NEIGHBOR
] = { "neighbor_report", BLOBMSG_TYPE_BOOL
},
544 [BSS_MGMT_EN_BEACON
] = { "beacon_report", BLOBMSG_TYPE_BOOL
},
546 [BSS_MGMT_EN_BSS_TRANSITION
] = { "bss_transition", BLOBMSG_TYPE_BOOL
},
551 hostapd_bss_mgmt_enable(struct ubus_context
*ctx
, struct ubus_object
*obj
,
552 struct ubus_request_data
*req
, const char *method
,
553 struct blob_attr
*msg
)
556 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
557 struct blob_attr
*tb
[__BSS_MGMT_EN_MAX
];
558 struct blob_attr
*cur
;
561 bool neigh
= false, beacon
= false;
563 blobmsg_parse(bss_mgmt_enable_policy
, __BSS_MGMT_EN_MAX
, tb
, blob_data(msg
), blob_len(msg
));
565 for (i
= 0; i
< ARRAY_SIZE(tb
); i
++) {
566 if (!tb
[i
] || !blobmsg_get_bool(tb
[i
]))
572 __hostapd_bss_mgmt_enable(hapd
, flags
);
577 hostapd_rrm_nr_enable(struct hostapd_data
*hapd
)
579 __hostapd_bss_mgmt_enable(hapd
, 1 << BSS_MGMT_EN_NEIGHBOR
);
583 hostapd_rrm_nr_get_own(struct ubus_context
*ctx
, struct ubus_object
*obj
,
584 struct ubus_request_data
*req
, const char *method
,
585 struct blob_attr
*msg
)
587 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
588 struct hostapd_neighbor_entry
*nr
;
591 hostapd_rrm_nr_enable(hapd
);
593 nr
= hostapd_neighbor_get(hapd
, hapd
->own_addr
, NULL
);
595 return UBUS_STATUS_NOT_FOUND
;
597 blob_buf_init(&b
, 0);
599 c
= blobmsg_open_array(&b
, "value");
600 hostapd_rrm_print_nr(nr
);
601 blobmsg_close_array(&b
, c
);
603 ubus_send_reply(ctx
, req
, b
.head
);
609 hostapd_rrm_nr_list(struct ubus_context
*ctx
, struct ubus_object
*obj
,
610 struct ubus_request_data
*req
, const char *method
,
611 struct blob_attr
*msg
)
613 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
614 struct hostapd_neighbor_entry
*nr
;
617 hostapd_rrm_nr_enable(hapd
);
618 blob_buf_init(&b
, 0);
620 c
= blobmsg_open_array(&b
, "list");
621 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
624 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
627 cur
= blobmsg_open_array(&b
, NULL
);
628 hostapd_rrm_print_nr(nr
);
629 blobmsg_close_array(&b
, cur
);
631 blobmsg_close_array(&b
, c
);
633 ubus_send_reply(ctx
, req
, b
.head
);
643 static const struct blobmsg_policy nr_set_policy
[__NR_SET_LIST_MAX
] = {
644 [NR_SET_LIST
] = { "list", BLOBMSG_TYPE_ARRAY
},
649 hostapd_rrm_nr_clear(struct hostapd_data
*hapd
)
651 struct hostapd_neighbor_entry
*nr
;
654 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
655 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
658 hostapd_neighbor_remove(hapd
, nr
->bssid
, &nr
->ssid
);
664 hostapd_rrm_nr_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
665 struct ubus_request_data
*req
, const char *method
,
666 struct blob_attr
*msg
)
668 static const struct blobmsg_policy nr_e_policy
[] = {
669 { .type
= BLOBMSG_TYPE_STRING
},
670 { .type
= BLOBMSG_TYPE_STRING
},
671 { .type
= BLOBMSG_TYPE_STRING
},
673 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
674 struct blob_attr
*tb_l
[__NR_SET_LIST_MAX
];
675 struct blob_attr
*tb
[ARRAY_SIZE(nr_e_policy
)];
676 struct blob_attr
*cur
;
680 hostapd_rrm_nr_enable(hapd
);
682 blobmsg_parse(nr_set_policy
, __NR_SET_LIST_MAX
, tb_l
, blob_data(msg
), blob_len(msg
));
683 if (!tb_l
[NR_SET_LIST
])
684 return UBUS_STATUS_INVALID_ARGUMENT
;
686 hostapd_rrm_nr_clear(hapd
);
687 blobmsg_for_each_attr(cur
, tb_l
[NR_SET_LIST
], rem
) {
688 struct wpa_ssid_value ssid
;
693 blobmsg_parse_array(nr_e_policy
, ARRAY_SIZE(nr_e_policy
), tb
, blobmsg_data(cur
), blobmsg_data_len(cur
));
694 if (!tb
[0] || !tb
[1] || !tb
[2])
697 s
= blobmsg_get_string(tb
[0]);
698 if (hwaddr_aton(s
, bssid
))
701 s
= blobmsg_get_string(tb
[1]);
702 ssid
.ssid_len
= strlen(s
);
703 if (ssid
.ssid_len
> sizeof(ssid
.ssid
))
706 memcpy(&ssid
, s
, ssid
.ssid_len
);
707 data
= wpabuf_parse_bin(blobmsg_get_string(tb
[2]));
711 hostapd_neighbor_set(hapd
, bssid
, &ssid
, data
, NULL
, NULL
, 0);
716 ret
= UBUS_STATUS_INVALID_ARGUMENT
;
722 static const struct ubus_method bss_methods
[] = {
723 UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients
),
724 UBUS_METHOD("del_client", hostapd_bss_del_client
, del_policy
),
725 UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans
),
726 UBUS_METHOD_NOARG("wps_start", hostapd_bss_wps_start
),
727 UBUS_METHOD_NOARG("wps_cancel", hostapd_bss_wps_cancel
),
728 UBUS_METHOD_NOARG("update_beacon", hostapd_bss_update_beacon
),
730 UBUS_METHOD("switch_chan", hostapd_switch_chan
, csa_policy
),
732 UBUS_METHOD("set_vendor_elements", hostapd_vendor_elements
, ve_policy
),
733 UBUS_METHOD("notify_response", hostapd_notify_response
, notify_policy
),
734 UBUS_METHOD("bss_mgmt_enable", hostapd_bss_mgmt_enable
, bss_mgmt_enable_policy
),
735 UBUS_METHOD_NOARG("rrm_nr_get_own", hostapd_rrm_nr_get_own
),
736 UBUS_METHOD_NOARG("rrm_nr_list", hostapd_rrm_nr_list
),
737 UBUS_METHOD("rrm_nr_set", hostapd_rrm_nr_set
, nr_set_policy
),
740 static struct ubus_object_type bss_object_type
=
741 UBUS_OBJECT_TYPE("hostapd_bss", bss_methods
);
743 static int avl_compare_macaddr(const void *k1
, const void *k2
, void *ptr
)
745 return memcmp(k1
, k2
, ETH_ALEN
);
748 void hostapd_ubus_add_bss(struct hostapd_data
*hapd
)
750 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
754 if (!hostapd_ubus_init())
757 if (asprintf(&name
, "hostapd.%s", hapd
->conf
->iface
) < 0)
760 avl_init(&hapd
->ubus
.banned
, avl_compare_macaddr
, false, NULL
);
762 obj
->type
= &bss_object_type
;
763 obj
->methods
= bss_object_type
.methods
;
764 obj
->n_methods
= bss_object_type
.n_methods
;
765 ret
= ubus_add_object(ctx
, obj
);
766 hostapd_ubus_ref_inc();
769 void hostapd_ubus_free_bss(struct hostapd_data
*hapd
)
771 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
772 char *name
= (char *) obj
->name
;
778 ubus_remove_object(ctx
, obj
);
779 hostapd_ubus_ref_dec();
785 struct ubus_event_req
{
786 struct ubus_notify_request nreq
;
791 ubus_event_cb(struct ubus_notify_request
*req
, int idx
, int ret
)
793 struct ubus_event_req
*ureq
= container_of(req
, struct ubus_event_req
, nreq
);
798 int hostapd_ubus_handle_event(struct hostapd_data
*hapd
, struct hostapd_ubus_request
*req
)
800 struct ubus_banned_client
*ban
;
801 const char *types
[HOSTAPD_UBUS_TYPE_MAX
] = {
802 [HOSTAPD_UBUS_PROBE_REQ
] = "probe",
803 [HOSTAPD_UBUS_AUTH_REQ
] = "auth",
804 [HOSTAPD_UBUS_ASSOC_REQ
] = "assoc",
806 const char *type
= "mgmt";
807 struct ubus_event_req ureq
= {};
811 addr
= req
->mgmt_frame
->sa
;
815 ban
= avl_find_element(&hapd
->ubus
.banned
, addr
, ban
, avl
);
817 return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
819 if (!hapd
->ubus
.obj
.has_subscribers
)
820 return WLAN_STATUS_SUCCESS
;
822 if (req
->type
< ARRAY_SIZE(types
))
823 type
= types
[req
->type
];
825 blob_buf_init(&b
, 0);
826 blobmsg_add_macaddr(&b
, "address", addr
);
828 blobmsg_add_macaddr(&b
, "target", req
->mgmt_frame
->da
);
830 blobmsg_add_u32(&b
, "signal", req
->frame_info
->ssi_signal
);
831 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
833 if (!hapd
->ubus
.notify_response
) {
834 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);
835 return WLAN_STATUS_SUCCESS
;
838 if (ubus_notify_async(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, &ureq
.nreq
))
839 return WLAN_STATUS_SUCCESS
;
841 ureq
.nreq
.status_cb
= ubus_event_cb
;
842 ubus_complete_request(ctx
, &ureq
.nreq
.req
, 100);
847 return WLAN_STATUS_SUCCESS
;
850 void hostapd_ubus_notify(struct hostapd_data
*hapd
, const char *type
, const u8
*addr
)
852 if (!hapd
->ubus
.obj
.has_subscribers
)
858 blob_buf_init(&b
, 0);
859 blobmsg_add_macaddr(&b
, "address", addr
);
861 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);