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"
25 static struct ubus_context
*ctx
;
26 static struct blob_buf b
;
29 static inline struct hapd_interfaces
*get_hapd_interfaces_from_object(struct ubus_object
*obj
)
31 return container_of(obj
, struct hapd_interfaces
, ubus
);
34 static inline struct hostapd_data
*get_hapd_from_object(struct ubus_object
*obj
)
36 return container_of(obj
, struct hostapd_data
, ubus
.obj
);
39 struct ubus_banned_client
{
44 static void ubus_receive(int sock
, void *eloop_ctx
, void *sock_ctx
)
46 struct ubus_context
*ctx
= eloop_ctx
;
47 ubus_handle_event(ctx
);
50 static void ubus_reconnect_timeout(void *eloop_data
, void *user_ctx
)
52 if (ubus_reconnect(ctx
, NULL
)) {
53 eloop_register_timeout(1, 0, ubus_reconnect_timeout
, ctx
, NULL
);
57 eloop_register_read_sock(ctx
->sock
.fd
, ubus_receive
, ctx
, NULL
);
60 static void hostapd_ubus_connection_lost(struct ubus_context
*ctx
)
62 eloop_unregister_read_sock(ctx
->sock
.fd
);
63 eloop_register_timeout(1, 0, ubus_reconnect_timeout
, ctx
, NULL
);
66 static bool hostapd_ubus_init(void)
71 ctx
= ubus_connect(NULL
);
75 ctx
->connection_lost
= hostapd_ubus_connection_lost
;
76 eloop_register_read_sock(ctx
->sock
.fd
, ubus_receive
, ctx
, NULL
);
80 static void hostapd_ubus_ref_inc(void)
85 static void hostapd_ubus_ref_dec(void)
94 eloop_unregister_read_sock(ctx
->sock
.fd
);
99 void hostapd_ubus_add_iface(struct hostapd_iface
*iface
)
101 if (!hostapd_ubus_init())
105 void hostapd_ubus_free_iface(struct hostapd_iface
*iface
)
111 static void hostapd_notify_ubus(struct ubus_object
*obj
, char *bssname
, char *event
)
118 if (asprintf(&event_type
, "bss.%s", event
) < 0)
121 blob_buf_init(&b
, 0);
122 blobmsg_add_string(&b
, "name", bssname
);
123 ubus_notify(ctx
, obj
, event_type
, b
.head
, -1);
127 static void hostapd_send_procd_event(char *bssname
, char *event
)
133 if (!ctx
|| ubus_lookup_id(ctx
, "service", &id
))
136 if (asprintf(&name
, "hostapd.%s.%s", bssname
, event
) < 0)
139 blob_buf_init(&b
, 0);
141 s
= blobmsg_alloc_string_buffer(&b
, "type", strlen(name
) + 1);
142 sprintf(s
, "%s", name
);
143 blobmsg_add_string_buffer(&b
);
145 v
= blobmsg_open_table(&b
, "data");
146 blobmsg_close_table(&b
, v
);
148 ubus_invoke(ctx
, id
, "event", b
.head
, NULL
, NULL
, 1000);
153 static void hostapd_send_shared_event(struct ubus_object
*obj
, char *bssname
, char *event
)
155 hostapd_send_procd_event(bssname
, event
);
156 hostapd_notify_ubus(obj
, bssname
, event
);
160 hostapd_bss_del_ban(void *eloop_data
, void *user_ctx
)
162 struct ubus_banned_client
*ban
= eloop_data
;
163 struct hostapd_data
*hapd
= user_ctx
;
165 avl_delete(&hapd
->ubus
.banned
, &ban
->avl
);
170 hostapd_bss_ban_client(struct hostapd_data
*hapd
, u8
*addr
, int time
)
172 struct ubus_banned_client
*ban
;
177 ban
= avl_find_element(&hapd
->ubus
.banned
, addr
, ban
, avl
);
182 ban
= os_zalloc(sizeof(*ban
));
183 memcpy(ban
->addr
, addr
, sizeof(ban
->addr
));
184 ban
->avl
.key
= ban
->addr
;
185 avl_insert(&hapd
->ubus
.banned
, &ban
->avl
);
187 eloop_cancel_timeout(hostapd_bss_del_ban
, ban
, hapd
);
189 hostapd_bss_del_ban(ban
, hapd
);
194 eloop_register_timeout(0, time
* 1000, hostapd_bss_del_ban
, ban
, hapd
);
198 hostapd_bss_reload(struct ubus_context
*ctx
, struct ubus_object
*obj
,
199 struct ubus_request_data
*req
, const char *method
,
200 struct blob_attr
*msg
)
202 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
203 int ret
= hostapd_reload_config(hapd
->iface
, 1);
205 hostapd_send_shared_event(&hapd
->iface
->interfaces
->ubus
, hapd
->conf
->iface
, "reload");
211 hostapd_parse_vht_map_blobmsg(uint16_t map
)
217 for (i
= 0; i
< 8; i
++) {
218 snprintf(label
, 4, "%dss", i
+ 1);
220 val
= (map
& (BIT(1) | BIT(0))) + 7;
221 blobmsg_add_u16(&b
, label
, val
== 10 ? -1 : val
);
227 hostapd_parse_vht_capab_blobmsg(struct ieee80211_vht_capabilities
*vhtc
)
233 static const struct {
237 { "su_beamformee", VHT_CAP_SU_BEAMFORMEE_CAPABLE
},
238 { "mu_beamformee", VHT_CAP_MU_BEAMFORMEE_CAPABLE
},
241 for (i
= 0; i
< ARRAY_SIZE(vht_capas
); i
++)
242 blobmsg_add_u8(&b
, vht_capas
[i
].name
,
243 !!(vhtc
->vht_capabilities_info
& vht_capas
[i
].flag
));
245 supported_mcs
= blobmsg_open_table(&b
, "mcs_map");
248 map
= blobmsg_open_table(&b
, "rx");
249 hostapd_parse_vht_map_blobmsg(le_to_host16(vhtc
->vht_supported_mcs_set
.rx_map
));
250 blobmsg_close_table(&b
, map
);
253 map
= blobmsg_open_table(&b
, "tx");
254 hostapd_parse_vht_map_blobmsg(le_to_host16(vhtc
->vht_supported_mcs_set
.tx_map
));
255 blobmsg_close_table(&b
, map
);
257 blobmsg_close_table(&b
, supported_mcs
);
261 hostapd_parse_capab_blobmsg(struct sta_info
*sta
)
265 v
= blobmsg_open_table(&b
, "capabilities");
267 if (sta
->vht_capabilities
) {
268 r
= blobmsg_open_table(&b
, "vht");
269 hostapd_parse_vht_capab_blobmsg(sta
->vht_capabilities
);
270 blobmsg_close_table(&b
, r
);
273 /* ToDo: Add HT / HE capability parsing */
275 blobmsg_close_table(&b
, v
);
279 hostapd_bss_get_clients(struct ubus_context
*ctx
, struct ubus_object
*obj
,
280 struct ubus_request_data
*req
, const char *method
,
281 struct blob_attr
*msg
)
283 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
284 struct hostap_sta_driver_data sta_driver_data
;
285 struct sta_info
*sta
;
288 static const struct {
292 { "auth", WLAN_STA_AUTH
},
293 { "assoc", WLAN_STA_ASSOC
},
294 { "authorized", WLAN_STA_AUTHORIZED
},
295 { "preauth", WLAN_STA_PREAUTH
},
296 { "wds", WLAN_STA_WDS
},
297 { "wmm", WLAN_STA_WMM
},
298 { "ht", WLAN_STA_HT
},
299 { "vht", WLAN_STA_VHT
},
300 { "wps", WLAN_STA_WPS
},
301 { "mfp", WLAN_STA_MFP
},
304 blob_buf_init(&b
, 0);
305 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
306 list
= blobmsg_open_table(&b
, "clients");
307 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
311 sprintf(mac_buf
, MACSTR
, MAC2STR(sta
->addr
));
312 c
= blobmsg_open_table(&b
, mac_buf
);
313 for (i
= 0; i
< ARRAY_SIZE(sta_flags
); i
++)
314 blobmsg_add_u8(&b
, sta_flags
[i
].name
,
315 !!(sta
->flags
& sta_flags
[i
].flag
));
317 r
= blobmsg_open_array(&b
, "rrm");
318 for (i
= 0; i
< ARRAY_SIZE(sta
->rrm_enabled_capa
); i
++)
319 blobmsg_add_u32(&b
, "", sta
->rrm_enabled_capa
[i
]);
320 blobmsg_close_array(&b
, r
);
321 blobmsg_add_u32(&b
, "aid", sta
->aid
);
322 #ifdef CONFIG_TAXONOMY
323 r
= blobmsg_alloc_string_buffer(&b
, "signature", 1024);
324 if (retrieve_sta_taxonomy(hapd
, sta
, r
, 1024) > 0)
325 blobmsg_add_string_buffer(&b
);
328 /* Driver information */
329 if (hostapd_drv_read_sta_data(hapd
, &sta_driver_data
, sta
->addr
) >= 0) {
330 r
= blobmsg_open_table(&b
, "bytes");
331 blobmsg_add_u64(&b
, "rx", sta_driver_data
.rx_bytes
);
332 blobmsg_add_u64(&b
, "tx", sta_driver_data
.tx_bytes
);
333 blobmsg_close_table(&b
, r
);
334 r
= blobmsg_open_table(&b
, "airtime");
335 blobmsg_add_u64(&b
, "rx", sta_driver_data
.rx_airtime
);
336 blobmsg_add_u64(&b
, "tx", sta_driver_data
.tx_airtime
);
337 blobmsg_close_table(&b
, r
);
338 r
= blobmsg_open_table(&b
, "packets");
339 blobmsg_add_u32(&b
, "rx", sta_driver_data
.rx_packets
);
340 blobmsg_add_u32(&b
, "tx", sta_driver_data
.tx_packets
);
341 blobmsg_close_table(&b
, r
);
342 r
= blobmsg_open_table(&b
, "rate");
344 blobmsg_add_u32(&b
, "rx", sta_driver_data
.current_rx_rate
* 100);
345 blobmsg_add_u32(&b
, "tx", sta_driver_data
.current_tx_rate
* 100);
346 blobmsg_close_table(&b
, r
);
347 blobmsg_add_u32(&b
, "signal", sta_driver_data
.signal
);
350 hostapd_parse_capab_blobmsg(sta
);
352 blobmsg_close_table(&b
, c
);
354 blobmsg_close_array(&b
, list
);
355 ubus_send_reply(ctx
, req
, b
.head
);
361 hostapd_bss_get_features(struct ubus_context
*ctx
, struct ubus_object
*obj
,
362 struct ubus_request_data
*req
, const char *method
,
363 struct blob_attr
*msg
)
365 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
367 blob_buf_init(&b
, 0);
368 blobmsg_add_u8(&b
, "ht_supported", ht_supported(hapd
->iface
->hw_features
));
369 blobmsg_add_u8(&b
, "vht_supported", vht_supported(hapd
->iface
->hw_features
));
370 ubus_send_reply(ctx
, req
, b
.head
);
376 hostapd_bss_get_status(struct ubus_context
*ctx
, struct ubus_object
*obj
,
377 struct ubus_request_data
*req
, const char *method
,
378 struct blob_attr
*msg
)
380 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
381 void *airtime_table
, *dfs_table
;
382 struct os_reltime now
;
386 blob_buf_init(&b
, 0);
387 blobmsg_add_string(&b
, "status", hostapd_state_text(hapd
->iface
->state
));
388 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
390 snprintf(phy_name
, 17, "%s", hapd
->iface
->phy
);
391 blobmsg_add_string(&b
, "phy", phy_name
);
394 airtime_table
= blobmsg_open_table(&b
, "airtime");
395 blobmsg_add_u64(&b
, "time", hapd
->iface
->last_channel_time
);
396 blobmsg_add_u64(&b
, "time_busy", hapd
->iface
->last_channel_time_busy
);
397 blobmsg_add_u16(&b
, "utilization", hapd
->iface
->channel_utilization
);
398 blobmsg_close_table(&b
, airtime_table
);
401 dfs_table
= blobmsg_open_table(&b
, "dfs");
402 blobmsg_add_u32(&b
, "cac_seconds", hapd
->iface
->dfs_cac_ms
/ 1000);
403 blobmsg_add_u8(&b
, "cac_active", !!(hapd
->iface
->cac_started
));
404 os_reltime_age(&hapd
->iface
->dfs_cac_start
, &now
);
405 blobmsg_add_u32(&b
, "cac_seconds_left",
406 hapd
->iface
->cac_started
? hapd
->iface
->dfs_cac_ms
/ 1000 - now
.sec
: 0);
407 blobmsg_close_table(&b
, dfs_table
);
409 ubus_send_reply(ctx
, req
, b
.head
);
419 static const struct blobmsg_policy notify_policy
[__NOTIFY_MAX
] = {
420 [NOTIFY_RESPONSE
] = { "notify_response", BLOBMSG_TYPE_INT32
},
424 hostapd_notify_response(struct ubus_context
*ctx
, struct ubus_object
*obj
,
425 struct ubus_request_data
*req
, const char *method
,
426 struct blob_attr
*msg
)
428 struct blob_attr
*tb
[__NOTIFY_MAX
];
429 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
430 struct wpabuf
*elems
;
434 blobmsg_parse(notify_policy
, __NOTIFY_MAX
, tb
,
435 blob_data(msg
), blob_len(msg
));
437 if (!tb
[NOTIFY_RESPONSE
])
438 return UBUS_STATUS_INVALID_ARGUMENT
;
440 hapd
->ubus
.notify_response
= blobmsg_get_u32(tb
[NOTIFY_RESPONSE
]);
442 return UBUS_STATUS_OK
;
453 static const struct blobmsg_policy del_policy
[__DEL_CLIENT_MAX
] = {
454 [DEL_CLIENT_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
455 [DEL_CLIENT_REASON
] = { "reason", BLOBMSG_TYPE_INT32
},
456 [DEL_CLIENT_DEAUTH
] = { "deauth", BLOBMSG_TYPE_INT8
},
457 [DEL_CLIENT_BAN_TIME
] = { "ban_time", BLOBMSG_TYPE_INT32
},
461 hostapd_bss_del_client(struct ubus_context
*ctx
, struct ubus_object
*obj
,
462 struct ubus_request_data
*req
, const char *method
,
463 struct blob_attr
*msg
)
465 struct blob_attr
*tb
[__DEL_CLIENT_MAX
];
466 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
467 struct sta_info
*sta
;
472 blobmsg_parse(del_policy
, __DEL_CLIENT_MAX
, tb
, blob_data(msg
), blob_len(msg
));
474 if (!tb
[DEL_CLIENT_ADDR
])
475 return UBUS_STATUS_INVALID_ARGUMENT
;
477 if (hwaddr_aton(blobmsg_data(tb
[DEL_CLIENT_ADDR
]), addr
))
478 return UBUS_STATUS_INVALID_ARGUMENT
;
480 if (tb
[DEL_CLIENT_REASON
])
481 reason
= blobmsg_get_u32(tb
[DEL_CLIENT_REASON
]);
483 if (tb
[DEL_CLIENT_DEAUTH
])
484 deauth
= blobmsg_get_bool(tb
[DEL_CLIENT_DEAUTH
]);
486 sta
= ap_get_sta(hapd
, addr
);
489 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
490 ap_sta_deauthenticate(hapd
, sta
, reason
);
492 hostapd_drv_sta_disassoc(hapd
, addr
, reason
);
493 ap_sta_disassociate(hapd
, sta
, reason
);
497 if (tb
[DEL_CLIENT_BAN_TIME
])
498 hostapd_bss_ban_client(hapd
, addr
, blobmsg_get_u32(tb
[DEL_CLIENT_BAN_TIME
]));
504 blobmsg_add_macaddr(struct blob_buf
*buf
, const char *name
, const u8
*addr
)
508 s
= blobmsg_alloc_string_buffer(buf
, name
, 20);
509 sprintf(s
, MACSTR
, MAC2STR(addr
));
510 blobmsg_add_string_buffer(buf
);
514 hostapd_bss_list_bans(struct ubus_context
*ctx
, struct ubus_object
*obj
,
515 struct ubus_request_data
*req
, const char *method
,
516 struct blob_attr
*msg
)
518 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
519 struct ubus_banned_client
*ban
;
522 blob_buf_init(&b
, 0);
523 c
= blobmsg_open_array(&b
, "clients");
524 avl_for_each_element(&hapd
->ubus
.banned
, ban
, avl
)
525 blobmsg_add_macaddr(&b
, NULL
, ban
->addr
);
526 blobmsg_close_array(&b
, c
);
527 ubus_send_reply(ctx
, req
, b
.head
);
534 hostapd_bss_wps_start(struct ubus_context
*ctx
, struct ubus_object
*obj
,
535 struct ubus_request_data
*req
, const char *method
,
536 struct blob_attr
*msg
)
539 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
541 rc
= hostapd_wps_button_pushed(hapd
, NULL
);
544 return UBUS_STATUS_NOT_SUPPORTED
;
550 static const char * pbc_status_enum_str(enum pbc_status status
)
553 case WPS_PBC_STATUS_DISABLE
:
555 case WPS_PBC_STATUS_ACTIVE
:
557 case WPS_PBC_STATUS_TIMEOUT
:
559 case WPS_PBC_STATUS_OVERLAP
:
567 hostapd_bss_wps_status(struct ubus_context
*ctx
, struct ubus_object
*obj
,
568 struct ubus_request_data
*req
, const char *method
,
569 struct blob_attr
*msg
)
572 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
574 blob_buf_init(&b
, 0);
576 blobmsg_add_string(&b
, "pbc_status", pbc_status_enum_str(hapd
->wps_stats
.pbc_status
));
577 blobmsg_add_string(&b
, "last_wps_result",
578 (hapd
->wps_stats
.status
== WPS_STATUS_SUCCESS
?
580 (hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
?
581 "Failed" : "None")));
583 /* If status == Failure - Add possible Reasons */
584 if(hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
&&
585 hapd
->wps_stats
.failure_reason
> 0)
586 blobmsg_add_string(&b
, "reason", wps_ei_str(hapd
->wps_stats
.failure_reason
));
588 if (hapd
->wps_stats
.status
)
589 blobmsg_printf(&b
, "peer_address", MACSTR
, MAC2STR(hapd
->wps_stats
.peer_addr
));
591 ubus_send_reply(ctx
, req
, b
.head
);
597 hostapd_bss_wps_cancel(struct ubus_context
*ctx
, struct ubus_object
*obj
,
598 struct ubus_request_data
*req
, const char *method
,
599 struct blob_attr
*msg
)
602 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
604 rc
= hostapd_wps_cancel(hapd
);
607 return UBUS_STATUS_NOT_SUPPORTED
;
611 #endif /* CONFIG_WPS */
614 hostapd_bss_update_beacon(struct ubus_context
*ctx
, struct ubus_object
*obj
,
615 struct ubus_request_data
*req
, const char *method
,
616 struct blob_attr
*msg
)
619 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
621 rc
= ieee802_11_set_beacon(hapd
);
624 return UBUS_STATUS_NOT_SUPPORTED
;
635 static const struct blobmsg_policy config_add_policy
[__CONFIG_MAX
] = {
636 [CONFIG_IFACE
] = { "iface", BLOBMSG_TYPE_STRING
},
637 [CONFIG_FILE
] = { "config", BLOBMSG_TYPE_STRING
},
641 hostapd_config_add(struct ubus_context
*ctx
, struct ubus_object
*obj
,
642 struct ubus_request_data
*req
, const char *method
,
643 struct blob_attr
*msg
)
645 struct blob_attr
*tb
[__CONFIG_MAX
];
646 struct hapd_interfaces
*interfaces
= get_hapd_interfaces_from_object(obj
);
649 blobmsg_parse(config_add_policy
, __CONFIG_MAX
, tb
, blob_data(msg
), blob_len(msg
));
651 if (!tb
[CONFIG_FILE
] || !tb
[CONFIG_IFACE
])
652 return UBUS_STATUS_INVALID_ARGUMENT
;
654 snprintf(buf
, sizeof(buf
), "bss_config=%s:%s",
655 blobmsg_get_string(tb
[CONFIG_IFACE
]),
656 blobmsg_get_string(tb
[CONFIG_FILE
]));
658 if (hostapd_add_iface(interfaces
, buf
))
659 return UBUS_STATUS_INVALID_ARGUMENT
;
661 blob_buf_init(&b
, 0);
662 blobmsg_add_u32(&b
, "pid", getpid());
663 ubus_send_reply(ctx
, req
, b
.head
);
665 return UBUS_STATUS_OK
;
673 static const struct blobmsg_policy config_remove_policy
[__CONFIG_REM_MAX
] = {
674 [CONFIG_REM_IFACE
] = { "iface", BLOBMSG_TYPE_STRING
},
678 hostapd_config_remove(struct ubus_context
*ctx
, struct ubus_object
*obj
,
679 struct ubus_request_data
*req
, const char *method
,
680 struct blob_attr
*msg
)
682 struct blob_attr
*tb
[__CONFIG_REM_MAX
];
683 struct hapd_interfaces
*interfaces
= get_hapd_interfaces_from_object(obj
);
686 blobmsg_parse(config_remove_policy
, __CONFIG_REM_MAX
, tb
, blob_data(msg
), blob_len(msg
));
688 if (!tb
[CONFIG_REM_IFACE
])
689 return UBUS_STATUS_INVALID_ARGUMENT
;
691 if (hostapd_remove_iface(interfaces
, blobmsg_get_string(tb
[CONFIG_REM_IFACE
])))
692 return UBUS_STATUS_INVALID_ARGUMENT
;
694 return UBUS_STATUS_OK
;
703 CSA_SEC_CHANNEL_OFFSET
,
710 static const struct blobmsg_policy csa_policy
[__CSA_MAX
] = {
711 [CSA_FREQ
] = { "freq", BLOBMSG_TYPE_INT32
},
712 [CSA_BCN_COUNT
] = { "bcn_count", BLOBMSG_TYPE_INT32
},
713 [CSA_CENTER_FREQ1
] = { "center_freq1", BLOBMSG_TYPE_INT32
},
714 [CSA_CENTER_FREQ2
] = { "center_freq2", BLOBMSG_TYPE_INT32
},
715 [CSA_BANDWIDTH
] = { "bandwidth", BLOBMSG_TYPE_INT32
},
716 [CSA_SEC_CHANNEL_OFFSET
] = { "sec_channel_offset", BLOBMSG_TYPE_INT32
},
717 [CSA_HT
] = { "ht", BLOBMSG_TYPE_BOOL
},
718 [CSA_VHT
] = { "vht", BLOBMSG_TYPE_BOOL
},
719 [CSA_BLOCK_TX
] = { "block_tx", BLOBMSG_TYPE_BOOL
},
724 hostapd_switch_chan(struct ubus_context
*ctx
, struct ubus_object
*obj
,
725 struct ubus_request_data
*req
, const char *method
,
726 struct blob_attr
*msg
)
728 struct blob_attr
*tb
[__CSA_MAX
];
729 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
730 struct csa_settings css
;
732 blobmsg_parse(csa_policy
, __CSA_MAX
, tb
, blob_data(msg
), blob_len(msg
));
735 return UBUS_STATUS_INVALID_ARGUMENT
;
737 memset(&css
, 0, sizeof(css
));
738 css
.freq_params
.freq
= blobmsg_get_u32(tb
[CSA_FREQ
]);
740 #define SET_CSA_SETTING(name, field, type) \
743 css.field = blobmsg_get_ ## type(tb[name]); \
746 SET_CSA_SETTING(CSA_BCN_COUNT
, cs_count
, u32
);
747 SET_CSA_SETTING(CSA_CENTER_FREQ1
, freq_params
.center_freq1
, u32
);
748 SET_CSA_SETTING(CSA_CENTER_FREQ2
, freq_params
.center_freq2
, u32
);
749 SET_CSA_SETTING(CSA_BANDWIDTH
, freq_params
.bandwidth
, u32
);
750 SET_CSA_SETTING(CSA_SEC_CHANNEL_OFFSET
, freq_params
.sec_channel_offset
, u32
);
751 SET_CSA_SETTING(CSA_HT
, freq_params
.ht_enabled
, bool);
752 SET_CSA_SETTING(CSA_VHT
, freq_params
.vht_enabled
, bool);
753 SET_CSA_SETTING(CSA_BLOCK_TX
, block_tx
, bool);
756 if (hostapd_switch_channel(hapd
, &css
) != 0)
757 return UBUS_STATUS_NOT_SUPPORTED
;
758 return UBUS_STATUS_OK
;
759 #undef SET_CSA_SETTING
765 __VENDOR_ELEMENTS_MAX
768 static const struct blobmsg_policy ve_policy
[__VENDOR_ELEMENTS_MAX
] = {
769 /* vendor elements are provided as hex-string */
770 [VENDOR_ELEMENTS
] = { "vendor_elements", BLOBMSG_TYPE_STRING
},
774 hostapd_vendor_elements(struct ubus_context
*ctx
, struct ubus_object
*obj
,
775 struct ubus_request_data
*req
, const char *method
,
776 struct blob_attr
*msg
)
778 struct blob_attr
*tb
[__VENDOR_ELEMENTS_MAX
];
779 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
780 struct hostapd_bss_config
*bss
= hapd
->conf
;
781 struct wpabuf
*elems
;
785 blobmsg_parse(ve_policy
, __VENDOR_ELEMENTS_MAX
, tb
,
786 blob_data(msg
), blob_len(msg
));
788 if (!tb
[VENDOR_ELEMENTS
])
789 return UBUS_STATUS_INVALID_ARGUMENT
;
791 pos
= blobmsg_data(tb
[VENDOR_ELEMENTS
]);
792 len
= os_strlen(pos
);
794 return UBUS_STATUS_INVALID_ARGUMENT
;
798 wpabuf_free(bss
->vendor_elements
);
799 bss
->vendor_elements
= NULL
;
803 elems
= wpabuf_alloc(len
);
807 if (hexstr2bin(pos
, wpabuf_put(elems
, len
), len
)) {
809 return UBUS_STATUS_INVALID_ARGUMENT
;
812 wpabuf_free(bss
->vendor_elements
);
813 bss
->vendor_elements
= elems
;
815 /* update beacons if vendor elements were set successfully */
816 if (ieee802_11_update_beacons(hapd
->iface
) != 0)
817 return UBUS_STATUS_NOT_SUPPORTED
;
818 return UBUS_STATUS_OK
;
822 hostapd_rrm_print_nr(struct hostapd_neighbor_entry
*nr
)
828 blobmsg_printf(&b
, "", MACSTR
, MAC2STR(nr
->bssid
));
830 str
= blobmsg_alloc_string_buffer(&b
, "", nr
->ssid
.ssid_len
+ 1);
831 memcpy(str
, nr
->ssid
.ssid
, nr
->ssid
.ssid_len
);
832 str
[nr
->ssid
.ssid_len
] = 0;
833 blobmsg_add_string_buffer(&b
);
835 len
= wpabuf_len(nr
->nr
);
836 str
= blobmsg_alloc_string_buffer(&b
, "", 2 * len
+ 1);
837 wpa_snprintf_hex(str
, 2 * len
+ 1, wpabuf_head_u8(nr
->nr
), len
);
838 blobmsg_add_string_buffer(&b
);
842 BSS_MGMT_EN_NEIGHBOR
,
845 BSS_MGMT_EN_BSS_TRANSITION
,
851 __hostapd_bss_mgmt_enable_f(struct hostapd_data
*hapd
, int flag
)
853 struct hostapd_bss_config
*bss
= hapd
->conf
;
857 case BSS_MGMT_EN_NEIGHBOR
:
858 if (bss
->radio_measurements
[0] &
859 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)
862 bss
->radio_measurements
[0] |=
863 WLAN_RRM_CAPS_NEIGHBOR_REPORT
;
864 hostapd_neighbor_set_own_report(hapd
);
866 case BSS_MGMT_EN_BEACON
:
867 flags
= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE
|
868 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE
|
869 WLAN_RRM_CAPS_BEACON_REPORT_TABLE
;
871 if (bss
->radio_measurements
[0] & flags
== flags
)
874 bss
->radio_measurements
[0] |= (u8
) flags
;
877 case BSS_MGMT_EN_BSS_TRANSITION
:
878 if (bss
->bss_transition
)
881 bss
->bss_transition
= 1;
888 __hostapd_bss_mgmt_enable(struct hostapd_data
*hapd
, uint32_t flags
)
893 for (i
= 0; i
< __BSS_MGMT_EN_MAX
; i
++) {
894 if (!(flags
& (1 << i
)))
897 update
|= __hostapd_bss_mgmt_enable_f(hapd
, i
);
901 ieee802_11_update_beacons(hapd
->iface
);
905 static const struct blobmsg_policy bss_mgmt_enable_policy
[__BSS_MGMT_EN_MAX
] = {
906 [BSS_MGMT_EN_NEIGHBOR
] = { "neighbor_report", BLOBMSG_TYPE_BOOL
},
907 [BSS_MGMT_EN_BEACON
] = { "beacon_report", BLOBMSG_TYPE_BOOL
},
909 [BSS_MGMT_EN_BSS_TRANSITION
] = { "bss_transition", BLOBMSG_TYPE_BOOL
},
914 hostapd_bss_mgmt_enable(struct ubus_context
*ctx
, struct ubus_object
*obj
,
915 struct ubus_request_data
*req
, const char *method
,
916 struct blob_attr
*msg
)
919 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
920 struct blob_attr
*tb
[__BSS_MGMT_EN_MAX
];
921 struct blob_attr
*cur
;
924 bool neigh
= false, beacon
= false;
926 blobmsg_parse(bss_mgmt_enable_policy
, __BSS_MGMT_EN_MAX
, tb
, blob_data(msg
), blob_len(msg
));
928 for (i
= 0; i
< ARRAY_SIZE(tb
); i
++) {
929 if (!tb
[i
] || !blobmsg_get_bool(tb
[i
]))
935 __hostapd_bss_mgmt_enable(hapd
, flags
);
940 hostapd_rrm_nr_enable(struct hostapd_data
*hapd
)
942 __hostapd_bss_mgmt_enable(hapd
, 1 << BSS_MGMT_EN_NEIGHBOR
);
946 hostapd_rrm_nr_get_own(struct ubus_context
*ctx
, struct ubus_object
*obj
,
947 struct ubus_request_data
*req
, const char *method
,
948 struct blob_attr
*msg
)
950 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
951 struct hostapd_neighbor_entry
*nr
;
954 hostapd_rrm_nr_enable(hapd
);
956 nr
= hostapd_neighbor_get(hapd
, hapd
->own_addr
, NULL
);
958 return UBUS_STATUS_NOT_FOUND
;
960 blob_buf_init(&b
, 0);
962 c
= blobmsg_open_array(&b
, "value");
963 hostapd_rrm_print_nr(nr
);
964 blobmsg_close_array(&b
, c
);
966 ubus_send_reply(ctx
, req
, b
.head
);
972 hostapd_rrm_nr_list(struct ubus_context
*ctx
, struct ubus_object
*obj
,
973 struct ubus_request_data
*req
, const char *method
,
974 struct blob_attr
*msg
)
976 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
977 struct hostapd_neighbor_entry
*nr
;
980 hostapd_rrm_nr_enable(hapd
);
981 blob_buf_init(&b
, 0);
983 c
= blobmsg_open_array(&b
, "list");
984 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
987 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
990 cur
= blobmsg_open_array(&b
, NULL
);
991 hostapd_rrm_print_nr(nr
);
992 blobmsg_close_array(&b
, cur
);
994 blobmsg_close_array(&b
, c
);
996 ubus_send_reply(ctx
, req
, b
.head
);
1006 static const struct blobmsg_policy nr_set_policy
[__NR_SET_LIST_MAX
] = {
1007 [NR_SET_LIST
] = { "list", BLOBMSG_TYPE_ARRAY
},
1012 hostapd_rrm_nr_clear(struct hostapd_data
*hapd
)
1014 struct hostapd_neighbor_entry
*nr
;
1017 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
1018 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
1021 hostapd_neighbor_remove(hapd
, nr
->bssid
, &nr
->ssid
);
1027 hostapd_rrm_nr_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1028 struct ubus_request_data
*req
, const char *method
,
1029 struct blob_attr
*msg
)
1031 static const struct blobmsg_policy nr_e_policy
[] = {
1032 { .type
= BLOBMSG_TYPE_STRING
},
1033 { .type
= BLOBMSG_TYPE_STRING
},
1034 { .type
= BLOBMSG_TYPE_STRING
},
1036 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
1037 struct blob_attr
*tb_l
[__NR_SET_LIST_MAX
];
1038 struct blob_attr
*tb
[ARRAY_SIZE(nr_e_policy
)];
1039 struct blob_attr
*cur
;
1042 hostapd_rrm_nr_enable(hapd
);
1044 blobmsg_parse(nr_set_policy
, __NR_SET_LIST_MAX
, tb_l
, blob_data(msg
), blob_len(msg
));
1045 if (!tb_l
[NR_SET_LIST
])
1046 return UBUS_STATUS_INVALID_ARGUMENT
;
1048 hostapd_rrm_nr_clear(hapd
);
1049 blobmsg_for_each_attr(cur
, tb_l
[NR_SET_LIST
], rem
) {
1050 struct wpa_ssid_value ssid
;
1051 struct wpabuf
*data
;
1055 blobmsg_parse_array(nr_e_policy
, ARRAY_SIZE(nr_e_policy
), tb
, blobmsg_data(cur
), blobmsg_data_len(cur
));
1056 if (!tb
[0] || !tb
[1] || !tb
[2])
1059 /* Neighbor Report binary */
1060 nr_s
= blobmsg_get_string(tb
[2]);
1061 data
= wpabuf_parse_bin(nr_s
);
1066 s
= blobmsg_get_string(tb
[0]);
1067 if (strlen(s
) == 0) {
1068 /* Copy BSSID from neighbor report */
1069 if (hwaddr_compact_aton(nr_s
, bssid
))
1071 } else if (hwaddr_aton(s
, bssid
)) {
1076 s
= blobmsg_get_string(tb
[1]);
1077 if (strlen(s
) == 0) {
1078 /* Copy SSID from hostapd BSS conf */
1079 memcpy(&ssid
, &hapd
->conf
->ssid
, sizeof(ssid
));
1081 ssid
.ssid_len
= strlen(s
);
1082 if (ssid
.ssid_len
> sizeof(ssid
.ssid
))
1085 memcpy(&ssid
, s
, ssid
.ssid_len
);
1088 hostapd_neighbor_set(hapd
, bssid
, &ssid
, data
, NULL
, NULL
, 0);
1093 return UBUS_STATUS_INVALID_ARGUMENT
;
1102 BEACON_REQ_OP_CLASS
,
1104 BEACON_REQ_DURATION
,
1110 static const struct blobmsg_policy beacon_req_policy
[__BEACON_REQ_MAX
] = {
1111 [BEACON_REQ_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
1112 [BEACON_REQ_OP_CLASS
] { "op_class", BLOBMSG_TYPE_INT32
},
1113 [BEACON_REQ_CHANNEL
] { "channel", BLOBMSG_TYPE_INT32
},
1114 [BEACON_REQ_DURATION
] { "duration", BLOBMSG_TYPE_INT32
},
1115 [BEACON_REQ_MODE
] { "mode", BLOBMSG_TYPE_INT32
},
1116 [BEACON_REQ_BSSID
] { "bssid", BLOBMSG_TYPE_STRING
},
1117 [BEACON_REQ_SSID
] { "ssid", BLOBMSG_TYPE_STRING
},
1121 hostapd_rrm_beacon_req(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1122 struct ubus_request_data
*ureq
, const char *method
,
1123 struct blob_attr
*msg
)
1125 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1126 struct blob_attr
*tb
[__BEACON_REQ_MAX
];
1127 struct blob_attr
*cur
;
1129 u8 bssid
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1134 blobmsg_parse(beacon_req_policy
, __BEACON_REQ_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1136 if (!tb
[BEACON_REQ_ADDR
] || !tb
[BEACON_REQ_MODE
] || !tb
[BEACON_REQ_DURATION
] ||
1137 !tb
[BEACON_REQ_OP_CLASS
] || !tb
[BEACON_REQ_CHANNEL
])
1138 return UBUS_STATUS_INVALID_ARGUMENT
;
1140 if (tb
[BEACON_REQ_SSID
])
1141 buf_len
+= blobmsg_data_len(tb
[BEACON_REQ_SSID
]) + 2 - 1;
1143 mode
= blobmsg_get_u32(tb
[BEACON_REQ_MODE
]);
1144 if (hwaddr_aton(blobmsg_data(tb
[BEACON_REQ_ADDR
]), addr
))
1145 return UBUS_STATUS_INVALID_ARGUMENT
;
1147 if (tb
[BEACON_REQ_BSSID
] &&
1148 hwaddr_aton(blobmsg_data(tb
[BEACON_REQ_BSSID
]), bssid
))
1149 return UBUS_STATUS_INVALID_ARGUMENT
;
1151 req
= wpabuf_alloc(buf_len
);
1153 return UBUS_STATUS_UNKNOWN_ERROR
;
1155 /* 1: regulatory class */
1156 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_OP_CLASS
]));
1158 /* 2: channel number */
1159 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_CHANNEL
]));
1161 /* 3-4: randomization interval */
1162 wpabuf_put_le16(req
, 0);
1165 wpabuf_put_le16(req
, blobmsg_get_u32(tb
[BEACON_REQ_DURATION
]));
1168 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_MODE
]));
1171 wpabuf_put_data(req
, bssid
, ETH_ALEN
);
1173 if ((cur
= tb
[BEACON_REQ_SSID
]) != NULL
) {
1174 wpabuf_put_u8(req
, WLAN_EID_SSID
);
1175 wpabuf_put_u8(req
, blobmsg_data_len(cur
) - 1);
1176 wpabuf_put_data(req
, blobmsg_data(cur
), blobmsg_data_len(cur
) - 1);
1179 ret
= hostapd_send_beacon_req(hapd
, addr
, 0, req
);
1187 #ifdef CONFIG_WNM_AP
1190 WNM_DISASSOC_DURATION
,
1191 WNM_DISASSOC_NEIGHBORS
,
1192 WNM_DISASSOC_ABRIDGED
,
1196 static const struct blobmsg_policy wnm_disassoc_policy
[__WNM_DISASSOC_MAX
] = {
1197 [WNM_DISASSOC_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
1198 [WNM_DISASSOC_DURATION
] { "duration", BLOBMSG_TYPE_INT32
},
1199 [WNM_DISASSOC_NEIGHBORS
] { "neighbors", BLOBMSG_TYPE_ARRAY
},
1200 [WNM_DISASSOC_ABRIDGED
] { "abridged", BLOBMSG_TYPE_BOOL
},
1204 hostapd_wnm_disassoc_imminent(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1205 struct ubus_request_data
*ureq
, const char *method
,
1206 struct blob_attr
*msg
)
1208 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1209 struct blob_attr
*tb
[__WNM_DISASSOC_MAX
];
1210 struct blob_attr
*cur
;
1211 struct sta_info
*sta
;
1216 u8 req_mode
= WNM_BSS_TM_REQ_DISASSOC_IMMINENT
;
1219 blobmsg_parse(wnm_disassoc_policy
, __WNM_DISASSOC_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1221 if (!tb
[WNM_DISASSOC_ADDR
])
1222 return UBUS_STATUS_INVALID_ARGUMENT
;
1224 if (hwaddr_aton(blobmsg_data(tb
[WNM_DISASSOC_ADDR
]), addr
))
1225 return UBUS_STATUS_INVALID_ARGUMENT
;
1227 if ((cur
= tb
[WNM_DISASSOC_DURATION
]) != NULL
)
1228 duration
= blobmsg_get_u32(cur
);
1230 sta
= ap_get_sta(hapd
, addr
);
1232 return UBUS_STATUS_NOT_FOUND
;
1234 if (tb
[WNM_DISASSOC_NEIGHBORS
]) {
1237 if (blobmsg_check_array(tb
[WNM_DISASSOC_NEIGHBORS
],
1238 BLOBMSG_TYPE_STRING
) < 0)
1239 return UBUS_STATUS_INVALID_ARGUMENT
;
1241 blobmsg_for_each_attr(cur
, tb
[WNM_DISASSOC_NEIGHBORS
], rem
) {
1242 int len
= strlen(blobmsg_get_string(cur
));
1245 return UBUS_STATUS_INVALID_ARGUMENT
;
1247 nr_len
+= (len
/ 2) + 2;
1251 nr
= os_zalloc(nr_len
);
1253 return UBUS_STATUS_UNKNOWN_ERROR
;
1257 blobmsg_for_each_attr(cur
, tb
[WNM_DISASSOC_NEIGHBORS
], rem
) {
1258 int len
= strlen(blobmsg_get_string(cur
)) / 2;
1260 *nr_cur
++ = WLAN_EID_NEIGHBOR_REPORT
;
1261 *nr_cur
++ = (u8
) len
;
1262 if (hexstr2bin(blobmsg_data(cur
), nr_cur
, len
)) {
1264 return UBUS_STATUS_INVALID_ARGUMENT
;
1272 req_mode
|= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED
;
1274 if (tb
[WNM_DISASSOC_ABRIDGED
] && blobmsg_get_bool(tb
[WNM_DISASSOC_ABRIDGED
]))
1275 req_mode
|= WNM_BSS_TM_REQ_ABRIDGED
;
1277 if (wnm_send_bss_tm_req(hapd
, sta
, req_mode
, duration
, duration
, NULL
,
1278 NULL
, nr
, nr_len
, NULL
, 0))
1279 return UBUS_STATUS_UNKNOWN_ERROR
;
1285 static const struct ubus_method bss_methods
[] = {
1286 UBUS_METHOD_NOARG("reload", hostapd_bss_reload
),
1287 UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients
),
1288 UBUS_METHOD_NOARG("get_status", hostapd_bss_get_status
),
1289 UBUS_METHOD("del_client", hostapd_bss_del_client
, del_policy
),
1290 UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans
),
1292 UBUS_METHOD_NOARG("wps_start", hostapd_bss_wps_start
),
1293 UBUS_METHOD_NOARG("wps_status", hostapd_bss_wps_status
),
1294 UBUS_METHOD_NOARG("wps_cancel", hostapd_bss_wps_cancel
),
1296 UBUS_METHOD_NOARG("update_beacon", hostapd_bss_update_beacon
),
1297 UBUS_METHOD_NOARG("get_features", hostapd_bss_get_features
),
1299 UBUS_METHOD("switch_chan", hostapd_switch_chan
, csa_policy
),
1301 UBUS_METHOD("set_vendor_elements", hostapd_vendor_elements
, ve_policy
),
1302 UBUS_METHOD("notify_response", hostapd_notify_response
, notify_policy
),
1303 UBUS_METHOD("bss_mgmt_enable", hostapd_bss_mgmt_enable
, bss_mgmt_enable_policy
),
1304 UBUS_METHOD_NOARG("rrm_nr_get_own", hostapd_rrm_nr_get_own
),
1305 UBUS_METHOD_NOARG("rrm_nr_list", hostapd_rrm_nr_list
),
1306 UBUS_METHOD("rrm_nr_set", hostapd_rrm_nr_set
, nr_set_policy
),
1307 UBUS_METHOD("rrm_beacon_req", hostapd_rrm_beacon_req
, beacon_req_policy
),
1308 #ifdef CONFIG_WNM_AP
1309 UBUS_METHOD("wnm_disassoc_imminent", hostapd_wnm_disassoc_imminent
, wnm_disassoc_policy
),
1313 static struct ubus_object_type bss_object_type
=
1314 UBUS_OBJECT_TYPE("hostapd_bss", bss_methods
);
1316 static int avl_compare_macaddr(const void *k1
, const void *k2
, void *ptr
)
1318 return memcmp(k1
, k2
, ETH_ALEN
);
1321 void hostapd_ubus_add_bss(struct hostapd_data
*hapd
)
1323 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
1328 if (hapd
->conf
->mesh
& MESH_ENABLED
)
1332 if (!hostapd_ubus_init())
1335 if (asprintf(&name
, "hostapd.%s", hapd
->conf
->iface
) < 0)
1338 avl_init(&hapd
->ubus
.banned
, avl_compare_macaddr
, false, NULL
);
1340 obj
->type
= &bss_object_type
;
1341 obj
->methods
= bss_object_type
.methods
;
1342 obj
->n_methods
= bss_object_type
.n_methods
;
1343 ret
= ubus_add_object(ctx
, obj
);
1344 hostapd_ubus_ref_inc();
1346 hostapd_send_shared_event(&hapd
->iface
->interfaces
->ubus
, hapd
->conf
->iface
, "add");
1349 void hostapd_ubus_free_bss(struct hostapd_data
*hapd
)
1351 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
1352 char *name
= (char *) obj
->name
;
1357 hostapd_send_shared_event(&hapd
->iface
->interfaces
->ubus
, hapd
->conf
->iface
, "remove");
1360 ubus_remove_object(ctx
, obj
);
1361 hostapd_ubus_ref_dec();
1368 hostapd_ubus_vlan_action(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
,
1371 struct vlan_description
*desc
= &vlan
->vlan_desc
;
1375 if (!hapd
->ubus
.obj
.has_subscribers
)
1378 blob_buf_init(&b
, 0);
1379 blobmsg_add_string(&b
, "ifname", vlan
->ifname
);
1380 blobmsg_add_string(&b
, "bridge", vlan
->bridge
);
1381 blobmsg_add_u32(&b
, "vlan_id", vlan
->vlan_id
);
1383 if (desc
->notempty
) {
1384 blobmsg_add_u32(&b
, "untagged", desc
->untagged
);
1385 c
= blobmsg_open_array(&b
, "tagged");
1386 for (i
= 0; i
< ARRAY_SIZE(desc
->tagged
) && desc
->tagged
[i
]; i
++)
1387 blobmsg_add_u32(&b
, "", desc
->tagged
[i
]);
1388 blobmsg_close_array(&b
, c
);
1391 ubus_notify(ctx
, &hapd
->ubus
.obj
, action
, b
.head
, -1);
1394 void hostapd_ubus_add_vlan(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
)
1396 hostapd_ubus_vlan_action(hapd
, vlan
, "vlan_add");
1399 void hostapd_ubus_remove_vlan(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
)
1401 hostapd_ubus_vlan_action(hapd
, vlan
, "vlan_remove");
1404 static const struct ubus_method daemon_methods
[] = {
1405 UBUS_METHOD("config_add", hostapd_config_add
, config_add_policy
),
1406 UBUS_METHOD("config_remove", hostapd_config_remove
, config_remove_policy
),
1409 static struct ubus_object_type daemon_object_type
=
1410 UBUS_OBJECT_TYPE("hostapd", daemon_methods
);
1412 void hostapd_ubus_add(struct hapd_interfaces
*interfaces
)
1414 struct ubus_object
*obj
= &interfaces
->ubus
;
1417 if (!hostapd_ubus_init())
1420 obj
->name
= strdup("hostapd");
1422 obj
->type
= &daemon_object_type
;
1423 obj
->methods
= daemon_object_type
.methods
;
1424 obj
->n_methods
= daemon_object_type
.n_methods
;
1425 ret
= ubus_add_object(ctx
, obj
);
1426 hostapd_ubus_ref_inc();
1429 void hostapd_ubus_free(struct hapd_interfaces
*interfaces
)
1431 struct ubus_object
*obj
= &interfaces
->ubus
;
1432 char *name
= (char *) obj
->name
;
1438 ubus_remove_object(ctx
, obj
);
1439 hostapd_ubus_ref_dec();
1445 struct ubus_event_req
{
1446 struct ubus_notify_request nreq
;
1451 ubus_event_cb(struct ubus_notify_request
*req
, int idx
, int ret
)
1453 struct ubus_event_req
*ureq
= container_of(req
, struct ubus_event_req
, nreq
);
1458 int hostapd_ubus_handle_event(struct hostapd_data
*hapd
, struct hostapd_ubus_request
*req
)
1460 struct ubus_banned_client
*ban
;
1461 const char *types
[HOSTAPD_UBUS_TYPE_MAX
] = {
1462 [HOSTAPD_UBUS_PROBE_REQ
] = "probe",
1463 [HOSTAPD_UBUS_AUTH_REQ
] = "auth",
1464 [HOSTAPD_UBUS_ASSOC_REQ
] = "assoc",
1466 const char *type
= "mgmt";
1467 struct ubus_event_req ureq
= {};
1470 if (req
->mgmt_frame
)
1471 addr
= req
->mgmt_frame
->sa
;
1475 ban
= avl_find_element(&hapd
->ubus
.banned
, addr
, ban
, avl
);
1477 return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1479 if (!hapd
->ubus
.obj
.has_subscribers
)
1480 return WLAN_STATUS_SUCCESS
;
1482 if (req
->type
< ARRAY_SIZE(types
))
1483 type
= types
[req
->type
];
1485 blob_buf_init(&b
, 0);
1486 blobmsg_add_macaddr(&b
, "address", addr
);
1487 if (req
->mgmt_frame
)
1488 blobmsg_add_macaddr(&b
, "target", req
->mgmt_frame
->da
);
1489 if (req
->ssi_signal
)
1490 blobmsg_add_u32(&b
, "signal", req
->ssi_signal
);
1491 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
1494 if(req
->elems
->ht_capabilities
)
1496 struct ieee80211_ht_capabilities
*ht_capabilities
;
1497 void *ht_cap
, *ht_cap_mcs_set
, *mcs_set
;
1500 ht_capabilities
= (struct ieee80211_ht_capabilities
*) req
->elems
->ht_capabilities
;
1501 ht_cap
= blobmsg_open_table(&b
, "ht_capabilities");
1502 blobmsg_add_u16(&b
, "ht_capabilities_info", ht_capabilities
->ht_capabilities_info
);
1503 ht_cap_mcs_set
= blobmsg_open_table(&b
, "supported_mcs_set");
1504 blobmsg_add_u16(&b
, "a_mpdu_params", ht_capabilities
->a_mpdu_params
);
1505 blobmsg_add_u16(&b
, "ht_extended_capabilities", ht_capabilities
->ht_extended_capabilities
);
1506 blobmsg_add_u32(&b
, "tx_bf_capability_info", ht_capabilities
->tx_bf_capability_info
);
1507 blobmsg_add_u16(&b
, "asel_capabilities", ht_capabilities
->asel_capabilities
);
1508 mcs_set
= blobmsg_open_array(&b
, "supported_mcs_set");
1509 for (int i
= 0; i
< 16; i
++) {
1510 blobmsg_add_u16(&b
, NULL
, (u16
) ht_capabilities
->supported_mcs_set
[i
]);
1512 blobmsg_close_array(&b
, mcs_set
);
1513 blobmsg_close_table(&b
, ht_cap_mcs_set
);
1514 blobmsg_close_table(&b
, ht_cap
);
1516 if(req
->elems
->vht_capabilities
)
1518 struct ieee80211_vht_capabilities
*vht_capabilities
;
1519 void *vht_cap
, *vht_cap_mcs_set
;
1521 vht_capabilities
= (struct ieee80211_vht_capabilities
*) req
->elems
->vht_capabilities
;
1522 vht_cap
= blobmsg_open_table(&b
, "vht_capabilities");
1523 blobmsg_add_u32(&b
, "vht_capabilities_info", vht_capabilities
->vht_capabilities_info
);
1524 vht_cap_mcs_set
= blobmsg_open_table(&b
, "vht_supported_mcs_set");
1525 blobmsg_add_u16(&b
, "rx_map", vht_capabilities
->vht_supported_mcs_set
.rx_map
);
1526 blobmsg_add_u16(&b
, "rx_highest", vht_capabilities
->vht_supported_mcs_set
.rx_highest
);
1527 blobmsg_add_u16(&b
, "tx_map", vht_capabilities
->vht_supported_mcs_set
.tx_map
);
1528 blobmsg_add_u16(&b
, "tx_highest", vht_capabilities
->vht_supported_mcs_set
.tx_highest
);
1529 blobmsg_close_table(&b
, vht_cap_mcs_set
);
1530 blobmsg_close_table(&b
, vht_cap
);
1534 if (!hapd
->ubus
.notify_response
) {
1535 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);
1536 return WLAN_STATUS_SUCCESS
;
1539 if (ubus_notify_async(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, &ureq
.nreq
))
1540 return WLAN_STATUS_SUCCESS
;
1542 ureq
.nreq
.status_cb
= ubus_event_cb
;
1543 ubus_complete_request(ctx
, &ureq
.nreq
.req
, 100);
1548 return WLAN_STATUS_SUCCESS
;
1551 void hostapd_ubus_notify(struct hostapd_data
*hapd
, const char *type
, const u8
*addr
)
1553 if (!hapd
->ubus
.obj
.has_subscribers
)
1559 blob_buf_init(&b
, 0);
1560 blobmsg_add_macaddr(&b
, "address", addr
);
1562 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);
1565 void hostapd_ubus_notify_beacon_report(
1566 struct hostapd_data
*hapd
, const u8
*addr
, u8 token
, u8 rep_mode
,
1567 struct rrm_measurement_beacon_report
*rep
, size_t len
)
1569 if (!hapd
->ubus
.obj
.has_subscribers
)
1575 blob_buf_init(&b
, 0);
1576 blobmsg_add_macaddr(&b
, "address", addr
);
1577 blobmsg_add_u16(&b
, "op-class", rep
->op_class
);
1578 blobmsg_add_u16(&b
, "channel", rep
->channel
);
1579 blobmsg_add_u64(&b
, "start-time", rep
->start_time
);
1580 blobmsg_add_u16(&b
, "duration", rep
->duration
);
1581 blobmsg_add_u16(&b
, "report-info", rep
->report_info
);
1582 blobmsg_add_u16(&b
, "rcpi", rep
->rcpi
);
1583 blobmsg_add_u16(&b
, "rsni", rep
->rsni
);
1584 blobmsg_add_macaddr(&b
, "bssid", rep
->bssid
);
1585 blobmsg_add_u16(&b
, "antenna-id", rep
->antenna_id
);
1586 blobmsg_add_u16(&b
, "parent-tsf", rep
->parent_tsf
);
1588 ubus_notify(ctx
, &hapd
->ubus
.obj
, "beacon-report", b
.head
, -1);