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"
24 #include "airtime_policy.h"
26 static struct ubus_context
*ctx
;
27 static struct blob_buf b
;
30 static inline struct hapd_interfaces
*get_hapd_interfaces_from_object(struct ubus_object
*obj
)
32 return container_of(obj
, struct hapd_interfaces
, ubus
);
35 static inline struct hostapd_data
*get_hapd_from_object(struct ubus_object
*obj
)
37 return container_of(obj
, struct hostapd_data
, ubus
.obj
);
40 struct ubus_banned_client
{
45 static void ubus_receive(int sock
, void *eloop_ctx
, void *sock_ctx
)
47 struct ubus_context
*ctx
= eloop_ctx
;
48 ubus_handle_event(ctx
);
51 static void ubus_reconnect_timeout(void *eloop_data
, void *user_ctx
)
53 if (ubus_reconnect(ctx
, NULL
)) {
54 eloop_register_timeout(1, 0, ubus_reconnect_timeout
, ctx
, NULL
);
58 eloop_register_read_sock(ctx
->sock
.fd
, ubus_receive
, ctx
, NULL
);
61 static void hostapd_ubus_connection_lost(struct ubus_context
*ctx
)
63 eloop_unregister_read_sock(ctx
->sock
.fd
);
64 eloop_register_timeout(1, 0, ubus_reconnect_timeout
, ctx
, NULL
);
67 static bool hostapd_ubus_init(void)
72 ctx
= ubus_connect(NULL
);
76 ctx
->connection_lost
= hostapd_ubus_connection_lost
;
77 eloop_register_read_sock(ctx
->sock
.fd
, ubus_receive
, ctx
, NULL
);
81 static void hostapd_ubus_ref_inc(void)
86 static void hostapd_ubus_ref_dec(void)
95 eloop_unregister_read_sock(ctx
->sock
.fd
);
100 void hostapd_ubus_add_iface(struct hostapd_iface
*iface
)
102 if (!hostapd_ubus_init())
106 void hostapd_ubus_free_iface(struct hostapd_iface
*iface
)
112 static void hostapd_notify_ubus(struct ubus_object
*obj
, char *bssname
, char *event
)
119 if (asprintf(&event_type
, "bss.%s", event
) < 0)
122 blob_buf_init(&b
, 0);
123 blobmsg_add_string(&b
, "name", bssname
);
124 ubus_notify(ctx
, obj
, event_type
, b
.head
, -1);
128 static void hostapd_send_procd_event(char *bssname
, char *event
)
134 if (!ctx
|| ubus_lookup_id(ctx
, "service", &id
))
137 if (asprintf(&name
, "hostapd.%s.%s", bssname
, event
) < 0)
140 blob_buf_init(&b
, 0);
142 s
= blobmsg_alloc_string_buffer(&b
, "type", strlen(name
) + 1);
143 sprintf(s
, "%s", name
);
144 blobmsg_add_string_buffer(&b
);
146 v
= blobmsg_open_table(&b
, "data");
147 blobmsg_close_table(&b
, v
);
149 ubus_invoke(ctx
, id
, "event", b
.head
, NULL
, NULL
, 1000);
154 static void hostapd_send_shared_event(struct ubus_object
*obj
, char *bssname
, char *event
)
156 hostapd_send_procd_event(bssname
, event
);
157 hostapd_notify_ubus(obj
, bssname
, event
);
161 hostapd_bss_del_ban(void *eloop_data
, void *user_ctx
)
163 struct ubus_banned_client
*ban
= eloop_data
;
164 struct hostapd_data
*hapd
= user_ctx
;
166 avl_delete(&hapd
->ubus
.banned
, &ban
->avl
);
171 hostapd_bss_ban_client(struct hostapd_data
*hapd
, u8
*addr
, int time
)
173 struct ubus_banned_client
*ban
;
178 ban
= avl_find_element(&hapd
->ubus
.banned
, addr
, ban
, avl
);
183 ban
= os_zalloc(sizeof(*ban
));
184 memcpy(ban
->addr
, addr
, sizeof(ban
->addr
));
185 ban
->avl
.key
= ban
->addr
;
186 avl_insert(&hapd
->ubus
.banned
, &ban
->avl
);
188 eloop_cancel_timeout(hostapd_bss_del_ban
, ban
, hapd
);
190 hostapd_bss_del_ban(ban
, hapd
);
195 eloop_register_timeout(0, time
* 1000, hostapd_bss_del_ban
, ban
, hapd
);
199 hostapd_bss_reload(struct ubus_context
*ctx
, struct ubus_object
*obj
,
200 struct ubus_request_data
*req
, const char *method
,
201 struct blob_attr
*msg
)
203 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
204 int ret
= hostapd_reload_config(hapd
->iface
, 1);
206 hostapd_send_shared_event(&hapd
->iface
->interfaces
->ubus
, hapd
->conf
->iface
, "reload");
212 hostapd_parse_vht_map_blobmsg(uint16_t map
)
218 for (i
= 0; i
< 8; i
++) {
219 snprintf(label
, 4, "%dss", i
+ 1);
221 val
= (map
& (BIT(1) | BIT(0))) + 7;
222 blobmsg_add_u16(&b
, label
, val
== 10 ? -1 : val
);
228 hostapd_parse_vht_capab_blobmsg(struct ieee80211_vht_capabilities
*vhtc
)
234 static const struct {
238 { "su_beamformee", VHT_CAP_SU_BEAMFORMEE_CAPABLE
},
239 { "mu_beamformee", VHT_CAP_MU_BEAMFORMEE_CAPABLE
},
242 for (i
= 0; i
< ARRAY_SIZE(vht_capas
); i
++)
243 blobmsg_add_u8(&b
, vht_capas
[i
].name
,
244 !!(vhtc
->vht_capabilities_info
& vht_capas
[i
].flag
));
246 supported_mcs
= blobmsg_open_table(&b
, "mcs_map");
249 map
= blobmsg_open_table(&b
, "rx");
250 hostapd_parse_vht_map_blobmsg(le_to_host16(vhtc
->vht_supported_mcs_set
.rx_map
));
251 blobmsg_close_table(&b
, map
);
254 map
= blobmsg_open_table(&b
, "tx");
255 hostapd_parse_vht_map_blobmsg(le_to_host16(vhtc
->vht_supported_mcs_set
.tx_map
));
256 blobmsg_close_table(&b
, map
);
258 blobmsg_close_table(&b
, supported_mcs
);
262 hostapd_parse_capab_blobmsg(struct sta_info
*sta
)
266 v
= blobmsg_open_table(&b
, "capabilities");
268 if (sta
->vht_capabilities
) {
269 r
= blobmsg_open_table(&b
, "vht");
270 hostapd_parse_vht_capab_blobmsg(sta
->vht_capabilities
);
271 blobmsg_close_table(&b
, r
);
274 /* ToDo: Add HT / HE capability parsing */
276 blobmsg_close_table(&b
, v
);
280 hostapd_bss_get_clients(struct ubus_context
*ctx
, struct ubus_object
*obj
,
281 struct ubus_request_data
*req
, const char *method
,
282 struct blob_attr
*msg
)
284 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
285 struct hostap_sta_driver_data sta_driver_data
;
286 struct sta_info
*sta
;
289 static const struct {
293 { "auth", WLAN_STA_AUTH
},
294 { "assoc", WLAN_STA_ASSOC
},
295 { "authorized", WLAN_STA_AUTHORIZED
},
296 { "preauth", WLAN_STA_PREAUTH
},
297 { "wds", WLAN_STA_WDS
},
298 { "wmm", WLAN_STA_WMM
},
299 { "ht", WLAN_STA_HT
},
300 { "vht", WLAN_STA_VHT
},
301 { "he", WLAN_STA_HE
},
302 { "wps", WLAN_STA_WPS
},
303 { "mfp", WLAN_STA_MFP
},
306 blob_buf_init(&b
, 0);
307 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
308 list
= blobmsg_open_table(&b
, "clients");
309 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
313 sprintf(mac_buf
, MACSTR
, MAC2STR(sta
->addr
));
314 c
= blobmsg_open_table(&b
, mac_buf
);
315 for (i
= 0; i
< ARRAY_SIZE(sta_flags
); i
++)
316 blobmsg_add_u8(&b
, sta_flags
[i
].name
,
317 !!(sta
->flags
& sta_flags
[i
].flag
));
319 r
= blobmsg_open_array(&b
, "rrm");
320 for (i
= 0; i
< ARRAY_SIZE(sta
->rrm_enabled_capa
); i
++)
321 blobmsg_add_u32(&b
, "", sta
->rrm_enabled_capa
[i
]);
322 blobmsg_close_array(&b
, r
);
323 blobmsg_add_u32(&b
, "aid", sta
->aid
);
324 #ifdef CONFIG_TAXONOMY
325 r
= blobmsg_alloc_string_buffer(&b
, "signature", 1024);
326 if (retrieve_sta_taxonomy(hapd
, sta
, r
, 1024) > 0)
327 blobmsg_add_string_buffer(&b
);
330 /* Driver information */
331 if (hostapd_drv_read_sta_data(hapd
, &sta_driver_data
, sta
->addr
) >= 0) {
332 r
= blobmsg_open_table(&b
, "bytes");
333 blobmsg_add_u64(&b
, "rx", sta_driver_data
.rx_bytes
);
334 blobmsg_add_u64(&b
, "tx", sta_driver_data
.tx_bytes
);
335 blobmsg_close_table(&b
, r
);
336 r
= blobmsg_open_table(&b
, "airtime");
337 blobmsg_add_u64(&b
, "rx", sta_driver_data
.rx_airtime
);
338 blobmsg_add_u64(&b
, "tx", sta_driver_data
.tx_airtime
);
339 blobmsg_close_table(&b
, r
);
340 r
= blobmsg_open_table(&b
, "packets");
341 blobmsg_add_u32(&b
, "rx", sta_driver_data
.rx_packets
);
342 blobmsg_add_u32(&b
, "tx", sta_driver_data
.tx_packets
);
343 blobmsg_close_table(&b
, r
);
344 r
= blobmsg_open_table(&b
, "rate");
346 blobmsg_add_u32(&b
, "rx", sta_driver_data
.current_rx_rate
* 100);
347 blobmsg_add_u32(&b
, "tx", sta_driver_data
.current_tx_rate
* 100);
348 blobmsg_close_table(&b
, r
);
349 blobmsg_add_u32(&b
, "signal", sta_driver_data
.signal
);
352 hostapd_parse_capab_blobmsg(sta
);
354 blobmsg_close_table(&b
, c
);
356 blobmsg_close_array(&b
, list
);
357 ubus_send_reply(ctx
, req
, b
.head
);
363 hostapd_bss_get_features(struct ubus_context
*ctx
, struct ubus_object
*obj
,
364 struct ubus_request_data
*req
, const char *method
,
365 struct blob_attr
*msg
)
367 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
369 blob_buf_init(&b
, 0);
370 blobmsg_add_u8(&b
, "ht_supported", ht_supported(hapd
->iface
->hw_features
));
371 blobmsg_add_u8(&b
, "vht_supported", vht_supported(hapd
->iface
->hw_features
));
372 ubus_send_reply(ctx
, req
, b
.head
);
377 /* Imported from iw/util.c
378 * https://git.kernel.org/pub/scm/linux/kernel/git/jberg/iw.git/tree/util.c?id=4b25ae3537af48dbf9d0abf94132e5ba01b32c18#n200
380 int ieee80211_frequency_to_channel(int freq
)
382 /* see 802.11-2007 17.3.8.3.2 and Annex J */
385 /* see 802.11ax D6.1 27.3.23.2 and Annex E */
386 else if (freq
== 5935)
388 else if (freq
< 2484)
389 return (freq
- 2407) / 5;
390 else if (freq
>= 4910 && freq
<= 4980)
391 return (freq
- 4000) / 5;
392 else if (freq
< 5950)
393 return (freq
- 5000) / 5;
394 else if (freq
<= 45000) /* DMG band lower limit */
395 /* see 802.11ax D6.1 27.3.23.2 */
396 return (freq
- 5950) / 5;
397 else if (freq
>= 58320 && freq
<= 70200)
398 return (freq
- 56160) / 2160;
404 hostapd_bss_get_status(struct ubus_context
*ctx
, struct ubus_object
*obj
,
405 struct ubus_request_data
*req
, const char *method
,
406 struct blob_attr
*msg
)
408 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
409 void *airtime_table
, *dfs_table
, *rrm_table
, *wnm_table
;
410 struct os_reltime now
;
411 char ssid
[SSID_MAX_LEN
+ 1];
413 size_t ssid_len
= SSID_MAX_LEN
;
415 if (hapd
->conf
->ssid
.ssid_len
< SSID_MAX_LEN
)
416 ssid_len
= hapd
->conf
->ssid
.ssid_len
;
418 blob_buf_init(&b
, 0);
419 blobmsg_add_string(&b
, "status", hostapd_state_text(hapd
->iface
->state
));
420 blobmsg_printf(&b
, "bssid", MACSTR
, MAC2STR(hapd
->conf
->bssid
));
422 memset(ssid
, 0, SSID_MAX_LEN
+ 1);
423 memcpy(ssid
, hapd
->conf
->ssid
.ssid
, ssid_len
);
424 blobmsg_add_string(&b
, "ssid", ssid
);
426 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
427 blobmsg_add_u32(&b
, "channel", ieee80211_frequency_to_channel(hapd
->iface
->freq
));
428 blobmsg_add_u32(&b
, "beacon_interval", hapd
->iconf
->beacon_int
);
430 snprintf(phy_name
, 17, "%s", hapd
->iface
->phy
);
431 blobmsg_add_string(&b
, "phy", phy_name
);
434 rrm_table
= blobmsg_open_table(&b
, "rrm");
435 blobmsg_add_u64(&b
, "neighbor_report_tx", hapd
->iface
->openwrt_stats
.rrm
.neighbor_report_tx
);
436 blobmsg_close_table(&b
, rrm_table
);
439 wnm_table
= blobmsg_open_table(&b
, "wnm");
440 blobmsg_add_u64(&b
, "bss_transition_query_rx", hapd
->iface
->openwrt_stats
.wnm
.bss_transition_query_rx
);
441 blobmsg_add_u64(&b
, "bss_transition_request_tx", hapd
->iface
->openwrt_stats
.wnm
.bss_transition_request_tx
);
442 blobmsg_add_u64(&b
, "bss_transition_response_rx", hapd
->iface
->openwrt_stats
.wnm
.bss_transition_response_rx
);
443 blobmsg_close_table(&b
, rrm_table
);
446 airtime_table
= blobmsg_open_table(&b
, "airtime");
447 blobmsg_add_u64(&b
, "time", hapd
->iface
->last_channel_time
);
448 blobmsg_add_u64(&b
, "time_busy", hapd
->iface
->last_channel_time_busy
);
449 blobmsg_add_u16(&b
, "utilization", hapd
->iface
->channel_utilization
);
450 blobmsg_close_table(&b
, airtime_table
);
453 dfs_table
= blobmsg_open_table(&b
, "dfs");
454 blobmsg_add_u32(&b
, "cac_seconds", hapd
->iface
->dfs_cac_ms
/ 1000);
455 blobmsg_add_u8(&b
, "cac_active", !!(hapd
->iface
->cac_started
));
456 os_reltime_age(&hapd
->iface
->dfs_cac_start
, &now
);
457 blobmsg_add_u32(&b
, "cac_seconds_left",
458 hapd
->iface
->cac_started
? hapd
->iface
->dfs_cac_ms
/ 1000 - now
.sec
: 0);
459 blobmsg_close_table(&b
, dfs_table
);
461 ubus_send_reply(ctx
, req
, b
.head
);
471 static const struct blobmsg_policy notify_policy
[__NOTIFY_MAX
] = {
472 [NOTIFY_RESPONSE
] = { "notify_response", BLOBMSG_TYPE_INT32
},
476 hostapd_notify_response(struct ubus_context
*ctx
, struct ubus_object
*obj
,
477 struct ubus_request_data
*req
, const char *method
,
478 struct blob_attr
*msg
)
480 struct blob_attr
*tb
[__NOTIFY_MAX
];
481 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
482 struct wpabuf
*elems
;
486 blobmsg_parse(notify_policy
, __NOTIFY_MAX
, tb
,
487 blob_data(msg
), blob_len(msg
));
489 if (!tb
[NOTIFY_RESPONSE
])
490 return UBUS_STATUS_INVALID_ARGUMENT
;
492 hapd
->ubus
.notify_response
= blobmsg_get_u32(tb
[NOTIFY_RESPONSE
]);
494 return UBUS_STATUS_OK
;
505 static const struct blobmsg_policy del_policy
[__DEL_CLIENT_MAX
] = {
506 [DEL_CLIENT_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
507 [DEL_CLIENT_REASON
] = { "reason", BLOBMSG_TYPE_INT32
},
508 [DEL_CLIENT_DEAUTH
] = { "deauth", BLOBMSG_TYPE_INT8
},
509 [DEL_CLIENT_BAN_TIME
] = { "ban_time", BLOBMSG_TYPE_INT32
},
513 hostapd_bss_del_client(struct ubus_context
*ctx
, struct ubus_object
*obj
,
514 struct ubus_request_data
*req
, const char *method
,
515 struct blob_attr
*msg
)
517 struct blob_attr
*tb
[__DEL_CLIENT_MAX
];
518 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
519 struct sta_info
*sta
;
524 blobmsg_parse(del_policy
, __DEL_CLIENT_MAX
, tb
, blob_data(msg
), blob_len(msg
));
526 if (!tb
[DEL_CLIENT_ADDR
])
527 return UBUS_STATUS_INVALID_ARGUMENT
;
529 if (hwaddr_aton(blobmsg_data(tb
[DEL_CLIENT_ADDR
]), addr
))
530 return UBUS_STATUS_INVALID_ARGUMENT
;
532 if (tb
[DEL_CLIENT_REASON
])
533 reason
= blobmsg_get_u32(tb
[DEL_CLIENT_REASON
]);
535 if (tb
[DEL_CLIENT_DEAUTH
])
536 deauth
= blobmsg_get_bool(tb
[DEL_CLIENT_DEAUTH
]);
538 sta
= ap_get_sta(hapd
, addr
);
541 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
542 ap_sta_deauthenticate(hapd
, sta
, reason
);
544 hostapd_drv_sta_disassoc(hapd
, addr
, reason
);
545 ap_sta_disassociate(hapd
, sta
, reason
);
549 if (tb
[DEL_CLIENT_BAN_TIME
])
550 hostapd_bss_ban_client(hapd
, addr
, blobmsg_get_u32(tb
[DEL_CLIENT_BAN_TIME
]));
556 blobmsg_add_macaddr(struct blob_buf
*buf
, const char *name
, const u8
*addr
)
560 s
= blobmsg_alloc_string_buffer(buf
, name
, 20);
561 sprintf(s
, MACSTR
, MAC2STR(addr
));
562 blobmsg_add_string_buffer(buf
);
566 hostapd_bss_list_bans(struct ubus_context
*ctx
, struct ubus_object
*obj
,
567 struct ubus_request_data
*req
, const char *method
,
568 struct blob_attr
*msg
)
570 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
571 struct ubus_banned_client
*ban
;
574 blob_buf_init(&b
, 0);
575 c
= blobmsg_open_array(&b
, "clients");
576 avl_for_each_element(&hapd
->ubus
.banned
, ban
, avl
)
577 blobmsg_add_macaddr(&b
, NULL
, ban
->addr
);
578 blobmsg_close_array(&b
, c
);
579 ubus_send_reply(ctx
, req
, b
.head
);
586 hostapd_bss_wps_start(struct ubus_context
*ctx
, struct ubus_object
*obj
,
587 struct ubus_request_data
*req
, const char *method
,
588 struct blob_attr
*msg
)
591 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
593 rc
= hostapd_wps_button_pushed(hapd
, NULL
);
596 return UBUS_STATUS_NOT_SUPPORTED
;
602 static const char * pbc_status_enum_str(enum pbc_status status
)
605 case WPS_PBC_STATUS_DISABLE
:
607 case WPS_PBC_STATUS_ACTIVE
:
609 case WPS_PBC_STATUS_TIMEOUT
:
611 case WPS_PBC_STATUS_OVERLAP
:
619 hostapd_bss_wps_status(struct ubus_context
*ctx
, struct ubus_object
*obj
,
620 struct ubus_request_data
*req
, const char *method
,
621 struct blob_attr
*msg
)
624 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
626 blob_buf_init(&b
, 0);
628 blobmsg_add_string(&b
, "pbc_status", pbc_status_enum_str(hapd
->wps_stats
.pbc_status
));
629 blobmsg_add_string(&b
, "last_wps_result",
630 (hapd
->wps_stats
.status
== WPS_STATUS_SUCCESS
?
632 (hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
?
633 "Failed" : "None")));
635 /* If status == Failure - Add possible Reasons */
636 if(hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
&&
637 hapd
->wps_stats
.failure_reason
> 0)
638 blobmsg_add_string(&b
, "reason", wps_ei_str(hapd
->wps_stats
.failure_reason
));
640 if (hapd
->wps_stats
.status
)
641 blobmsg_printf(&b
, "peer_address", MACSTR
, MAC2STR(hapd
->wps_stats
.peer_addr
));
643 ubus_send_reply(ctx
, req
, b
.head
);
649 hostapd_bss_wps_cancel(struct ubus_context
*ctx
, struct ubus_object
*obj
,
650 struct ubus_request_data
*req
, const char *method
,
651 struct blob_attr
*msg
)
654 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
656 rc
= hostapd_wps_cancel(hapd
);
659 return UBUS_STATUS_NOT_SUPPORTED
;
663 #endif /* CONFIG_WPS */
666 hostapd_bss_update_beacon(struct ubus_context
*ctx
, struct ubus_object
*obj
,
667 struct ubus_request_data
*req
, const char *method
,
668 struct blob_attr
*msg
)
671 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
673 rc
= ieee802_11_set_beacon(hapd
);
676 return UBUS_STATUS_NOT_SUPPORTED
;
687 static const struct blobmsg_policy config_add_policy
[__CONFIG_MAX
] = {
688 [CONFIG_IFACE
] = { "iface", BLOBMSG_TYPE_STRING
},
689 [CONFIG_FILE
] = { "config", BLOBMSG_TYPE_STRING
},
693 hostapd_config_add(struct ubus_context
*ctx
, struct ubus_object
*obj
,
694 struct ubus_request_data
*req
, const char *method
,
695 struct blob_attr
*msg
)
697 struct blob_attr
*tb
[__CONFIG_MAX
];
698 struct hapd_interfaces
*interfaces
= get_hapd_interfaces_from_object(obj
);
701 blobmsg_parse(config_add_policy
, __CONFIG_MAX
, tb
, blob_data(msg
), blob_len(msg
));
703 if (!tb
[CONFIG_FILE
] || !tb
[CONFIG_IFACE
])
704 return UBUS_STATUS_INVALID_ARGUMENT
;
706 snprintf(buf
, sizeof(buf
), "bss_config=%s:%s",
707 blobmsg_get_string(tb
[CONFIG_IFACE
]),
708 blobmsg_get_string(tb
[CONFIG_FILE
]));
710 if (hostapd_add_iface(interfaces
, buf
))
711 return UBUS_STATUS_INVALID_ARGUMENT
;
713 blob_buf_init(&b
, 0);
714 blobmsg_add_u32(&b
, "pid", getpid());
715 ubus_send_reply(ctx
, req
, b
.head
);
717 return UBUS_STATUS_OK
;
725 static const struct blobmsg_policy config_remove_policy
[__CONFIG_REM_MAX
] = {
726 [CONFIG_REM_IFACE
] = { "iface", BLOBMSG_TYPE_STRING
},
730 hostapd_config_remove(struct ubus_context
*ctx
, struct ubus_object
*obj
,
731 struct ubus_request_data
*req
, const char *method
,
732 struct blob_attr
*msg
)
734 struct blob_attr
*tb
[__CONFIG_REM_MAX
];
735 struct hapd_interfaces
*interfaces
= get_hapd_interfaces_from_object(obj
);
738 blobmsg_parse(config_remove_policy
, __CONFIG_REM_MAX
, tb
, blob_data(msg
), blob_len(msg
));
740 if (!tb
[CONFIG_REM_IFACE
])
741 return UBUS_STATUS_INVALID_ARGUMENT
;
743 if (hostapd_remove_iface(interfaces
, blobmsg_get_string(tb
[CONFIG_REM_IFACE
])))
744 return UBUS_STATUS_INVALID_ARGUMENT
;
746 return UBUS_STATUS_OK
;
755 CSA_SEC_CHANNEL_OFFSET
,
764 static const struct blobmsg_policy csa_policy
[__CSA_MAX
] = {
765 [CSA_FREQ
] = { "freq", BLOBMSG_TYPE_INT32
},
766 [CSA_BCN_COUNT
] = { "bcn_count", BLOBMSG_TYPE_INT32
},
767 [CSA_CENTER_FREQ1
] = { "center_freq1", BLOBMSG_TYPE_INT32
},
768 [CSA_CENTER_FREQ2
] = { "center_freq2", BLOBMSG_TYPE_INT32
},
769 [CSA_BANDWIDTH
] = { "bandwidth", BLOBMSG_TYPE_INT32
},
770 [CSA_SEC_CHANNEL_OFFSET
] = { "sec_channel_offset", BLOBMSG_TYPE_INT32
},
771 [CSA_HT
] = { "ht", BLOBMSG_TYPE_BOOL
},
772 [CSA_VHT
] = { "vht", BLOBMSG_TYPE_BOOL
},
773 [CSA_HE
] = { "he", BLOBMSG_TYPE_BOOL
},
774 [CSA_BLOCK_TX
] = { "block_tx", BLOBMSG_TYPE_BOOL
},
775 [CSA_FORCE
] = { "force", BLOBMSG_TYPE_BOOL
},
779 static void switch_chan_fallback_cb(void *eloop_data
, void *user_ctx
)
781 struct hostapd_iface
*iface
= eloop_data
;
782 struct hostapd_freq_params
*freq_params
= user_ctx
;
784 hostapd_switch_channel_fallback(iface
, freq_params
);
789 hostapd_switch_chan(struct ubus_context
*ctx
, struct ubus_object
*obj
,
790 struct ubus_request_data
*req
, const char *method
,
791 struct blob_attr
*msg
)
793 struct blob_attr
*tb
[__CSA_MAX
];
794 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
795 struct hostapd_config
*iconf
= hapd
->iface
->conf
;
796 struct hostapd_freq_params
*freq_params
;
797 struct csa_settings css
= {
799 .ht_enabled
= iconf
->ieee80211n
,
800 .vht_enabled
= iconf
->ieee80211ac
,
801 .he_enabled
= iconf
->ieee80211ax
,
802 .sec_channel_offset
= iconf
->secondary_channel
,
805 int ret
= UBUS_STATUS_OK
;
808 blobmsg_parse(csa_policy
, __CSA_MAX
, tb
, blob_data(msg
), blob_len(msg
));
811 return UBUS_STATUS_INVALID_ARGUMENT
;
813 switch (iconf
->vht_oper_chwidth
) {
814 case CHANWIDTH_USE_HT
:
815 if (iconf
->secondary_channel
)
816 css
.freq_params
.bandwidth
= 40;
818 css
.freq_params
.bandwidth
= 20;
820 case CHANWIDTH_160MHZ
:
821 css
.freq_params
.bandwidth
= 160;
824 css
.freq_params
.bandwidth
= 80;
828 css
.freq_params
.freq
= blobmsg_get_u32(tb
[CSA_FREQ
]);
830 #define SET_CSA_SETTING(name, field, type) \
833 css.field = blobmsg_get_ ## type(tb[name]); \
836 SET_CSA_SETTING(CSA_BCN_COUNT
, cs_count
, u32
);
837 SET_CSA_SETTING(CSA_CENTER_FREQ1
, freq_params
.center_freq1
, u32
);
838 SET_CSA_SETTING(CSA_CENTER_FREQ2
, freq_params
.center_freq2
, u32
);
839 SET_CSA_SETTING(CSA_BANDWIDTH
, freq_params
.bandwidth
, u32
);
840 SET_CSA_SETTING(CSA_SEC_CHANNEL_OFFSET
, freq_params
.sec_channel_offset
, u32
);
841 SET_CSA_SETTING(CSA_HT
, freq_params
.ht_enabled
, bool);
842 SET_CSA_SETTING(CSA_VHT
, freq_params
.vht_enabled
, bool);
843 SET_CSA_SETTING(CSA_HE
, freq_params
.he_enabled
, bool);
844 SET_CSA_SETTING(CSA_BLOCK_TX
, block_tx
, bool);
846 for (i
= 0; i
< hapd
->iface
->num_bss
; i
++) {
847 struct hostapd_data
*bss
= hapd
->iface
->bss
[i
];
849 if (hostapd_switch_channel(bss
, &css
) != 0)
850 ret
= UBUS_STATUS_NOT_SUPPORTED
;
853 if (!ret
|| !tb
[CSA_FORCE
] || !blobmsg_get_bool(tb
[CSA_FORCE
]))
856 freq_params
= malloc(sizeof(*freq_params
));
857 memcpy(freq_params
, &css
.freq_params
, sizeof(*freq_params
));
858 eloop_register_timeout(0, 1, switch_chan_fallback_cb
,
859 hapd
->iface
, freq_params
);
862 #undef SET_CSA_SETTING
868 __VENDOR_ELEMENTS_MAX
871 static const struct blobmsg_policy ve_policy
[__VENDOR_ELEMENTS_MAX
] = {
872 /* vendor elements are provided as hex-string */
873 [VENDOR_ELEMENTS
] = { "vendor_elements", BLOBMSG_TYPE_STRING
},
877 hostapd_vendor_elements(struct ubus_context
*ctx
, struct ubus_object
*obj
,
878 struct ubus_request_data
*req
, const char *method
,
879 struct blob_attr
*msg
)
881 struct blob_attr
*tb
[__VENDOR_ELEMENTS_MAX
];
882 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
883 struct hostapd_bss_config
*bss
= hapd
->conf
;
884 struct wpabuf
*elems
;
888 blobmsg_parse(ve_policy
, __VENDOR_ELEMENTS_MAX
, tb
,
889 blob_data(msg
), blob_len(msg
));
891 if (!tb
[VENDOR_ELEMENTS
])
892 return UBUS_STATUS_INVALID_ARGUMENT
;
894 pos
= blobmsg_data(tb
[VENDOR_ELEMENTS
]);
895 len
= os_strlen(pos
);
897 return UBUS_STATUS_INVALID_ARGUMENT
;
901 wpabuf_free(bss
->vendor_elements
);
902 bss
->vendor_elements
= NULL
;
906 elems
= wpabuf_alloc(len
);
910 if (hexstr2bin(pos
, wpabuf_put(elems
, len
), len
)) {
912 return UBUS_STATUS_INVALID_ARGUMENT
;
915 wpabuf_free(bss
->vendor_elements
);
916 bss
->vendor_elements
= elems
;
918 /* update beacons if vendor elements were set successfully */
919 if (ieee802_11_update_beacons(hapd
->iface
) != 0)
920 return UBUS_STATUS_NOT_SUPPORTED
;
921 return UBUS_STATUS_OK
;
925 hostapd_rrm_print_nr(struct hostapd_neighbor_entry
*nr
)
931 blobmsg_printf(&b
, "", MACSTR
, MAC2STR(nr
->bssid
));
933 str
= blobmsg_alloc_string_buffer(&b
, "", nr
->ssid
.ssid_len
+ 1);
934 memcpy(str
, nr
->ssid
.ssid
, nr
->ssid
.ssid_len
);
935 str
[nr
->ssid
.ssid_len
] = 0;
936 blobmsg_add_string_buffer(&b
);
938 len
= wpabuf_len(nr
->nr
);
939 str
= blobmsg_alloc_string_buffer(&b
, "", 2 * len
+ 1);
940 wpa_snprintf_hex(str
, 2 * len
+ 1, wpabuf_head_u8(nr
->nr
), len
);
941 blobmsg_add_string_buffer(&b
);
945 BSS_MGMT_EN_NEIGHBOR
,
948 BSS_MGMT_EN_BSS_TRANSITION
,
954 __hostapd_bss_mgmt_enable_f(struct hostapd_data
*hapd
, int flag
)
956 struct hostapd_bss_config
*bss
= hapd
->conf
;
960 case BSS_MGMT_EN_NEIGHBOR
:
961 if (bss
->radio_measurements
[0] &
962 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)
965 bss
->radio_measurements
[0] |=
966 WLAN_RRM_CAPS_NEIGHBOR_REPORT
;
967 hostapd_neighbor_set_own_report(hapd
);
969 case BSS_MGMT_EN_BEACON
:
970 flags
= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE
|
971 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE
|
972 WLAN_RRM_CAPS_BEACON_REPORT_TABLE
;
974 if (bss
->radio_measurements
[0] & flags
== flags
)
977 bss
->radio_measurements
[0] |= (u8
) flags
;
980 case BSS_MGMT_EN_BSS_TRANSITION
:
981 if (bss
->bss_transition
)
984 bss
->bss_transition
= 1;
991 __hostapd_bss_mgmt_enable(struct hostapd_data
*hapd
, uint32_t flags
)
996 for (i
= 0; i
< __BSS_MGMT_EN_MAX
; i
++) {
997 if (!(flags
& (1 << i
)))
1000 update
|= __hostapd_bss_mgmt_enable_f(hapd
, i
);
1004 ieee802_11_update_beacons(hapd
->iface
);
1008 static const struct blobmsg_policy bss_mgmt_enable_policy
[__BSS_MGMT_EN_MAX
] = {
1009 [BSS_MGMT_EN_NEIGHBOR
] = { "neighbor_report", BLOBMSG_TYPE_BOOL
},
1010 [BSS_MGMT_EN_BEACON
] = { "beacon_report", BLOBMSG_TYPE_BOOL
},
1011 #ifdef CONFIG_WNM_AP
1012 [BSS_MGMT_EN_BSS_TRANSITION
] = { "bss_transition", BLOBMSG_TYPE_BOOL
},
1017 hostapd_bss_mgmt_enable(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1018 struct ubus_request_data
*req
, const char *method
,
1019 struct blob_attr
*msg
)
1022 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
1023 struct blob_attr
*tb
[__BSS_MGMT_EN_MAX
];
1024 struct blob_attr
*cur
;
1027 bool neigh
= false, beacon
= false;
1029 blobmsg_parse(bss_mgmt_enable_policy
, __BSS_MGMT_EN_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1031 for (i
= 0; i
< ARRAY_SIZE(tb
); i
++) {
1032 if (!tb
[i
] || !blobmsg_get_bool(tb
[i
]))
1038 __hostapd_bss_mgmt_enable(hapd
, flags
);
1043 hostapd_rrm_nr_enable(struct hostapd_data
*hapd
)
1045 __hostapd_bss_mgmt_enable(hapd
, 1 << BSS_MGMT_EN_NEIGHBOR
);
1049 hostapd_rrm_nr_get_own(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1050 struct ubus_request_data
*req
, const char *method
,
1051 struct blob_attr
*msg
)
1053 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
1054 struct hostapd_neighbor_entry
*nr
;
1057 hostapd_rrm_nr_enable(hapd
);
1059 nr
= hostapd_neighbor_get(hapd
, hapd
->own_addr
, NULL
);
1061 return UBUS_STATUS_NOT_FOUND
;
1063 blob_buf_init(&b
, 0);
1065 c
= blobmsg_open_array(&b
, "value");
1066 hostapd_rrm_print_nr(nr
);
1067 blobmsg_close_array(&b
, c
);
1069 ubus_send_reply(ctx
, req
, b
.head
);
1075 hostapd_rrm_nr_list(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1076 struct ubus_request_data
*req
, const char *method
,
1077 struct blob_attr
*msg
)
1079 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
1080 struct hostapd_neighbor_entry
*nr
;
1083 hostapd_rrm_nr_enable(hapd
);
1084 blob_buf_init(&b
, 0);
1086 c
= blobmsg_open_array(&b
, "list");
1087 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
1090 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
1093 cur
= blobmsg_open_array(&b
, NULL
);
1094 hostapd_rrm_print_nr(nr
);
1095 blobmsg_close_array(&b
, cur
);
1097 blobmsg_close_array(&b
, c
);
1099 ubus_send_reply(ctx
, req
, b
.head
);
1109 static const struct blobmsg_policy nr_set_policy
[__NR_SET_LIST_MAX
] = {
1110 [NR_SET_LIST
] = { "list", BLOBMSG_TYPE_ARRAY
},
1115 hostapd_rrm_nr_clear(struct hostapd_data
*hapd
)
1117 struct hostapd_neighbor_entry
*nr
;
1120 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
1121 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
1124 hostapd_neighbor_remove(hapd
, nr
->bssid
, &nr
->ssid
);
1130 hostapd_rrm_nr_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1131 struct ubus_request_data
*req
, const char *method
,
1132 struct blob_attr
*msg
)
1134 static const struct blobmsg_policy nr_e_policy
[] = {
1135 { .type
= BLOBMSG_TYPE_STRING
},
1136 { .type
= BLOBMSG_TYPE_STRING
},
1137 { .type
= BLOBMSG_TYPE_STRING
},
1139 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
1140 struct blob_attr
*tb_l
[__NR_SET_LIST_MAX
];
1141 struct blob_attr
*tb
[ARRAY_SIZE(nr_e_policy
)];
1142 struct blob_attr
*cur
;
1145 hostapd_rrm_nr_enable(hapd
);
1147 blobmsg_parse(nr_set_policy
, __NR_SET_LIST_MAX
, tb_l
, blob_data(msg
), blob_len(msg
));
1148 if (!tb_l
[NR_SET_LIST
])
1149 return UBUS_STATUS_INVALID_ARGUMENT
;
1151 hostapd_rrm_nr_clear(hapd
);
1152 blobmsg_for_each_attr(cur
, tb_l
[NR_SET_LIST
], rem
) {
1153 struct wpa_ssid_value ssid
;
1154 struct wpabuf
*data
;
1158 blobmsg_parse_array(nr_e_policy
, ARRAY_SIZE(nr_e_policy
), tb
, blobmsg_data(cur
), blobmsg_data_len(cur
));
1159 if (!tb
[0] || !tb
[1] || !tb
[2])
1162 /* Neighbor Report binary */
1163 nr_s
= blobmsg_get_string(tb
[2]);
1164 data
= wpabuf_parse_bin(nr_s
);
1169 s
= blobmsg_get_string(tb
[0]);
1170 if (strlen(s
) == 0) {
1171 /* Copy BSSID from neighbor report */
1172 if (hwaddr_compact_aton(nr_s
, bssid
))
1174 } else if (hwaddr_aton(s
, bssid
)) {
1179 s
= blobmsg_get_string(tb
[1]);
1180 if (strlen(s
) == 0) {
1181 /* Copy SSID from hostapd BSS conf */
1182 memcpy(&ssid
, &hapd
->conf
->ssid
, sizeof(ssid
));
1184 ssid
.ssid_len
= strlen(s
);
1185 if (ssid
.ssid_len
> sizeof(ssid
.ssid
))
1188 memcpy(&ssid
, s
, ssid
.ssid_len
);
1191 hostapd_neighbor_set(hapd
, bssid
, &ssid
, data
, NULL
, NULL
, 0);
1196 return UBUS_STATUS_INVALID_ARGUMENT
;
1205 BEACON_REQ_OP_CLASS
,
1207 BEACON_REQ_DURATION
,
1213 static const struct blobmsg_policy beacon_req_policy
[__BEACON_REQ_MAX
] = {
1214 [BEACON_REQ_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
1215 [BEACON_REQ_OP_CLASS
] { "op_class", BLOBMSG_TYPE_INT32
},
1216 [BEACON_REQ_CHANNEL
] { "channel", BLOBMSG_TYPE_INT32
},
1217 [BEACON_REQ_DURATION
] { "duration", BLOBMSG_TYPE_INT32
},
1218 [BEACON_REQ_MODE
] { "mode", BLOBMSG_TYPE_INT32
},
1219 [BEACON_REQ_BSSID
] { "bssid", BLOBMSG_TYPE_STRING
},
1220 [BEACON_REQ_SSID
] { "ssid", BLOBMSG_TYPE_STRING
},
1224 hostapd_rrm_beacon_req(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1225 struct ubus_request_data
*ureq
, const char *method
,
1226 struct blob_attr
*msg
)
1228 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1229 struct blob_attr
*tb
[__BEACON_REQ_MAX
];
1230 struct blob_attr
*cur
;
1232 u8 bssid
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1237 blobmsg_parse(beacon_req_policy
, __BEACON_REQ_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1239 if (!tb
[BEACON_REQ_ADDR
] || !tb
[BEACON_REQ_MODE
] || !tb
[BEACON_REQ_DURATION
] ||
1240 !tb
[BEACON_REQ_OP_CLASS
] || !tb
[BEACON_REQ_CHANNEL
])
1241 return UBUS_STATUS_INVALID_ARGUMENT
;
1243 if (tb
[BEACON_REQ_SSID
])
1244 buf_len
+= blobmsg_data_len(tb
[BEACON_REQ_SSID
]) + 2 - 1;
1246 mode
= blobmsg_get_u32(tb
[BEACON_REQ_MODE
]);
1247 if (hwaddr_aton(blobmsg_data(tb
[BEACON_REQ_ADDR
]), addr
))
1248 return UBUS_STATUS_INVALID_ARGUMENT
;
1250 if (tb
[BEACON_REQ_BSSID
] &&
1251 hwaddr_aton(blobmsg_data(tb
[BEACON_REQ_BSSID
]), bssid
))
1252 return UBUS_STATUS_INVALID_ARGUMENT
;
1254 req
= wpabuf_alloc(buf_len
);
1256 return UBUS_STATUS_UNKNOWN_ERROR
;
1258 /* 1: regulatory class */
1259 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_OP_CLASS
]));
1261 /* 2: channel number */
1262 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_CHANNEL
]));
1264 /* 3-4: randomization interval */
1265 wpabuf_put_le16(req
, 0);
1268 wpabuf_put_le16(req
, blobmsg_get_u32(tb
[BEACON_REQ_DURATION
]));
1271 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_MODE
]));
1274 wpabuf_put_data(req
, bssid
, ETH_ALEN
);
1276 if ((cur
= tb
[BEACON_REQ_SSID
]) != NULL
) {
1277 wpabuf_put_u8(req
, WLAN_EID_SSID
);
1278 wpabuf_put_u8(req
, blobmsg_data_len(cur
) - 1);
1279 wpabuf_put_data(req
, blobmsg_data(cur
), blobmsg_data_len(cur
) - 1);
1282 ret
= hostapd_send_beacon_req(hapd
, addr
, 0, req
);
1290 #ifdef CONFIG_WNM_AP
1293 hostapd_bss_tr_send(struct hostapd_data
*hapd
, u8
*addr
, bool disassoc_imminent
, bool abridged
,
1294 u16 disassoc_timer
, u8 validity_period
, struct blob_attr
*neighbors
)
1296 struct blob_attr
*cur
;
1297 struct sta_info
*sta
;
1303 sta
= ap_get_sta(hapd
, addr
);
1305 return UBUS_STATUS_NOT_FOUND
;
1310 if (blobmsg_check_array(neighbors
,
1311 BLOBMSG_TYPE_STRING
) < 0)
1312 return UBUS_STATUS_INVALID_ARGUMENT
;
1314 blobmsg_for_each_attr(cur
, neighbors
, rem
) {
1315 int len
= strlen(blobmsg_get_string(cur
));
1318 return UBUS_STATUS_INVALID_ARGUMENT
;
1320 nr_len
+= (len
/ 2) + 2;
1324 nr
= os_zalloc(nr_len
);
1326 return UBUS_STATUS_UNKNOWN_ERROR
;
1330 blobmsg_for_each_attr(cur
, neighbors
, rem
) {
1331 int len
= strlen(blobmsg_get_string(cur
)) / 2;
1333 *nr_cur
++ = WLAN_EID_NEIGHBOR_REPORT
;
1334 *nr_cur
++ = (u8
) len
;
1335 if (hexstr2bin(blobmsg_data(cur
), nr_cur
, len
)) {
1337 return UBUS_STATUS_INVALID_ARGUMENT
;
1345 req_mode
|= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED
;
1348 req_mode
|= WNM_BSS_TM_REQ_ABRIDGED
;
1350 if (disassoc_imminent
)
1351 req_mode
|= WNM_BSS_TM_REQ_DISASSOC_IMMINENT
;
1353 if (wnm_send_bss_tm_req(hapd
, sta
, req_mode
, disassoc_timer
, validity_period
, NULL
,
1354 NULL
, nr
, nr_len
, NULL
, 0))
1355 return UBUS_STATUS_UNKNOWN_ERROR
;
1364 BSS_TR_VALID_PERIOD
,
1367 __BSS_TR_DISASSOC_MAX
1370 static const struct blobmsg_policy bss_tr_policy
[__BSS_TR_DISASSOC_MAX
] = {
1371 [BSS_TR_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
1372 [BSS_TR_DA_IMMINENT
] = { "disassociation_imminent", BLOBMSG_TYPE_BOOL
},
1373 [BSS_TR_DA_TIMER
] = { "disassociation_timer", BLOBMSG_TYPE_INT32
},
1374 [BSS_TR_VALID_PERIOD
] = { "validity_period", BLOBMSG_TYPE_INT32
},
1375 [BSS_TR_NEIGHBORS
] = { "neighbors", BLOBMSG_TYPE_ARRAY
},
1376 [BSS_TR_ABRIDGED
] = { "abridged", BLOBMSG_TYPE_BOOL
},
1380 hostapd_bss_transition_request(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1381 struct ubus_request_data
*ureq
, const char *method
,
1382 struct blob_attr
*msg
)
1384 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1385 struct blob_attr
*tb
[__BSS_TR_DISASSOC_MAX
];
1386 struct sta_info
*sta
;
1388 u32 valid_period
= 0;
1393 blobmsg_parse(bss_tr_policy
, __BSS_TR_DISASSOC_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1395 if (!tb
[BSS_TR_ADDR
])
1396 return UBUS_STATUS_INVALID_ARGUMENT
;
1398 if (hwaddr_aton(blobmsg_data(tb
[BSS_TR_ADDR
]), addr
))
1399 return UBUS_STATUS_INVALID_ARGUMENT
;
1401 if (tb
[BSS_TR_DA_TIMER
])
1402 da_timer
= blobmsg_get_u32(tb
[BSS_TR_DA_TIMER
]);
1404 if (tb
[BSS_TR_VALID_PERIOD
])
1405 valid_period
= blobmsg_get_u32(tb
[BSS_TR_VALID_PERIOD
]);
1407 da_imminent
= !!(tb
[BSS_TR_DA_IMMINENT
] && blobmsg_get_bool(tb
[BSS_TR_DA_IMMINENT
]));
1408 abridged
= !!(tb
[BSS_TR_ABRIDGED
] && blobmsg_get_bool(tb
[BSS_TR_ABRIDGED
]));
1410 return hostapd_bss_tr_send(hapd
, addr
, da_imminent
, abridged
, da_timer
, valid_period
,
1411 tb
[BSS_TR_NEIGHBORS
]);
1416 WNM_DISASSOC_DURATION
,
1417 WNM_DISASSOC_NEIGHBORS
,
1418 WNM_DISASSOC_ABRIDGED
,
1422 static const struct blobmsg_policy wnm_disassoc_policy
[__WNM_DISASSOC_MAX
] = {
1423 [WNM_DISASSOC_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
1424 [WNM_DISASSOC_DURATION
] { "duration", BLOBMSG_TYPE_INT32
},
1425 [WNM_DISASSOC_NEIGHBORS
] { "neighbors", BLOBMSG_TYPE_ARRAY
},
1426 [WNM_DISASSOC_ABRIDGED
] { "abridged", BLOBMSG_TYPE_BOOL
},
1430 hostapd_wnm_disassoc_imminent(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1431 struct ubus_request_data
*ureq
, const char *method
,
1432 struct blob_attr
*msg
)
1434 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1435 struct blob_attr
*tb
[__WNM_DISASSOC_MAX
];
1436 struct sta_info
*sta
;
1441 blobmsg_parse(wnm_disassoc_policy
, __WNM_DISASSOC_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1443 if (!tb
[WNM_DISASSOC_ADDR
])
1444 return UBUS_STATUS_INVALID_ARGUMENT
;
1446 if (hwaddr_aton(blobmsg_data(tb
[WNM_DISASSOC_ADDR
]), addr
))
1447 return UBUS_STATUS_INVALID_ARGUMENT
;
1449 if (tb
[WNM_DISASSOC_DURATION
])
1450 duration
= blobmsg_get_u32(tb
[WNM_DISASSOC_DURATION
]);
1452 abridged
= !!(tb
[WNM_DISASSOC_ABRIDGED
] && blobmsg_get_bool(tb
[WNM_DISASSOC_ABRIDGED
]));
1454 return hostapd_bss_tr_send(hapd
, addr
, true, abridged
, duration
, duration
,
1455 tb
[WNM_DISASSOC_NEIGHBORS
]);
1459 #ifdef CONFIG_AIRTIME_POLICY
1462 UPDATE_AIRTIME_WEIGHT
,
1463 __UPDATE_AIRTIME_MAX
,
1467 static const struct blobmsg_policy airtime_policy
[__UPDATE_AIRTIME_MAX
] = {
1468 [UPDATE_AIRTIME_STA
] = { "sta", BLOBMSG_TYPE_STRING
},
1469 [UPDATE_AIRTIME_WEIGHT
] = { "weight", BLOBMSG_TYPE_INT32
},
1473 hostapd_bss_update_airtime(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1474 struct ubus_request_data
*ureq
, const char *method
,
1475 struct blob_attr
*msg
)
1477 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1478 struct blob_attr
*tb
[__UPDATE_AIRTIME_MAX
];
1479 struct sta_info
*sta
= NULL
;
1483 blobmsg_parse(airtime_policy
, __UPDATE_AIRTIME_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1485 if (!tb
[UPDATE_AIRTIME_WEIGHT
])
1486 return UBUS_STATUS_INVALID_ARGUMENT
;
1488 weight
= blobmsg_get_u32(tb
[UPDATE_AIRTIME_WEIGHT
]);
1490 if (!tb
[UPDATE_AIRTIME_STA
]) {
1492 return UBUS_STATUS_INVALID_ARGUMENT
;
1494 hapd
->conf
->airtime_weight
= weight
;
1498 if (hwaddr_aton(blobmsg_data(tb
[UPDATE_AIRTIME_STA
]), addr
))
1499 return UBUS_STATUS_INVALID_ARGUMENT
;
1501 sta
= ap_get_sta(hapd
, addr
);
1503 return UBUS_STATUS_NOT_FOUND
;
1505 sta
->dyn_airtime_weight
= weight
;
1506 airtime_policy_new_sta(hapd
, sta
);
1513 static const struct ubus_method bss_methods
[] = {
1514 UBUS_METHOD_NOARG("reload", hostapd_bss_reload
),
1515 UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients
),
1516 UBUS_METHOD_NOARG("get_status", hostapd_bss_get_status
),
1517 UBUS_METHOD("del_client", hostapd_bss_del_client
, del_policy
),
1518 #ifdef CONFIG_AIRTIME_POLICY
1519 UBUS_METHOD("update_airtime", hostapd_bss_update_airtime
, airtime_policy
),
1521 UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans
),
1523 UBUS_METHOD_NOARG("wps_start", hostapd_bss_wps_start
),
1524 UBUS_METHOD_NOARG("wps_status", hostapd_bss_wps_status
),
1525 UBUS_METHOD_NOARG("wps_cancel", hostapd_bss_wps_cancel
),
1527 UBUS_METHOD_NOARG("update_beacon", hostapd_bss_update_beacon
),
1528 UBUS_METHOD_NOARG("get_features", hostapd_bss_get_features
),
1530 UBUS_METHOD("switch_chan", hostapd_switch_chan
, csa_policy
),
1532 UBUS_METHOD("set_vendor_elements", hostapd_vendor_elements
, ve_policy
),
1533 UBUS_METHOD("notify_response", hostapd_notify_response
, notify_policy
),
1534 UBUS_METHOD("bss_mgmt_enable", hostapd_bss_mgmt_enable
, bss_mgmt_enable_policy
),
1535 UBUS_METHOD_NOARG("rrm_nr_get_own", hostapd_rrm_nr_get_own
),
1536 UBUS_METHOD_NOARG("rrm_nr_list", hostapd_rrm_nr_list
),
1537 UBUS_METHOD("rrm_nr_set", hostapd_rrm_nr_set
, nr_set_policy
),
1538 UBUS_METHOD("rrm_beacon_req", hostapd_rrm_beacon_req
, beacon_req_policy
),
1539 #ifdef CONFIG_WNM_AP
1540 UBUS_METHOD("wnm_disassoc_imminent", hostapd_wnm_disassoc_imminent
, wnm_disassoc_policy
),
1541 UBUS_METHOD("bss_transition_request", hostapd_bss_transition_request
, bss_tr_policy
),
1545 static struct ubus_object_type bss_object_type
=
1546 UBUS_OBJECT_TYPE("hostapd_bss", bss_methods
);
1548 static int avl_compare_macaddr(const void *k1
, const void *k2
, void *ptr
)
1550 return memcmp(k1
, k2
, ETH_ALEN
);
1553 void hostapd_ubus_add_bss(struct hostapd_data
*hapd
)
1555 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
1560 if (hapd
->conf
->mesh
& MESH_ENABLED
)
1564 if (!hostapd_ubus_init())
1567 if (asprintf(&name
, "hostapd.%s", hapd
->conf
->iface
) < 0)
1570 avl_init(&hapd
->ubus
.banned
, avl_compare_macaddr
, false, NULL
);
1572 obj
->type
= &bss_object_type
;
1573 obj
->methods
= bss_object_type
.methods
;
1574 obj
->n_methods
= bss_object_type
.n_methods
;
1575 ret
= ubus_add_object(ctx
, obj
);
1576 hostapd_ubus_ref_inc();
1578 hostapd_send_shared_event(&hapd
->iface
->interfaces
->ubus
, hapd
->conf
->iface
, "add");
1581 void hostapd_ubus_free_bss(struct hostapd_data
*hapd
)
1583 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
1584 char *name
= (char *) obj
->name
;
1587 if (hapd
->conf
->mesh
& MESH_ENABLED
)
1594 hostapd_send_shared_event(&hapd
->iface
->interfaces
->ubus
, hapd
->conf
->iface
, "remove");
1597 ubus_remove_object(ctx
, obj
);
1598 hostapd_ubus_ref_dec();
1605 hostapd_ubus_vlan_action(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
,
1608 struct vlan_description
*desc
= &vlan
->vlan_desc
;
1612 if (!hapd
->ubus
.obj
.has_subscribers
)
1615 blob_buf_init(&b
, 0);
1616 blobmsg_add_string(&b
, "ifname", vlan
->ifname
);
1617 blobmsg_add_string(&b
, "bridge", vlan
->bridge
);
1618 blobmsg_add_u32(&b
, "vlan_id", vlan
->vlan_id
);
1620 if (desc
->notempty
) {
1621 blobmsg_add_u32(&b
, "untagged", desc
->untagged
);
1622 c
= blobmsg_open_array(&b
, "tagged");
1623 for (i
= 0; i
< ARRAY_SIZE(desc
->tagged
) && desc
->tagged
[i
]; i
++)
1624 blobmsg_add_u32(&b
, "", desc
->tagged
[i
]);
1625 blobmsg_close_array(&b
, c
);
1628 ubus_notify(ctx
, &hapd
->ubus
.obj
, action
, b
.head
, -1);
1631 void hostapd_ubus_add_vlan(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
)
1633 hostapd_ubus_vlan_action(hapd
, vlan
, "vlan_add");
1636 void hostapd_ubus_remove_vlan(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
)
1638 hostapd_ubus_vlan_action(hapd
, vlan
, "vlan_remove");
1641 static const struct ubus_method daemon_methods
[] = {
1642 UBUS_METHOD("config_add", hostapd_config_add
, config_add_policy
),
1643 UBUS_METHOD("config_remove", hostapd_config_remove
, config_remove_policy
),
1646 static struct ubus_object_type daemon_object_type
=
1647 UBUS_OBJECT_TYPE("hostapd", daemon_methods
);
1649 void hostapd_ubus_add(struct hapd_interfaces
*interfaces
)
1651 struct ubus_object
*obj
= &interfaces
->ubus
;
1654 if (!hostapd_ubus_init())
1657 obj
->name
= strdup("hostapd");
1659 obj
->type
= &daemon_object_type
;
1660 obj
->methods
= daemon_object_type
.methods
;
1661 obj
->n_methods
= daemon_object_type
.n_methods
;
1662 ret
= ubus_add_object(ctx
, obj
);
1663 hostapd_ubus_ref_inc();
1666 void hostapd_ubus_free(struct hapd_interfaces
*interfaces
)
1668 struct ubus_object
*obj
= &interfaces
->ubus
;
1669 char *name
= (char *) obj
->name
;
1675 ubus_remove_object(ctx
, obj
);
1676 hostapd_ubus_ref_dec();
1682 struct ubus_event_req
{
1683 struct ubus_notify_request nreq
;
1688 ubus_event_cb(struct ubus_notify_request
*req
, int idx
, int ret
)
1690 struct ubus_event_req
*ureq
= container_of(req
, struct ubus_event_req
, nreq
);
1695 int hostapd_ubus_handle_event(struct hostapd_data
*hapd
, struct hostapd_ubus_request
*req
)
1697 struct ubus_banned_client
*ban
;
1698 const char *types
[HOSTAPD_UBUS_TYPE_MAX
] = {
1699 [HOSTAPD_UBUS_PROBE_REQ
] = "probe",
1700 [HOSTAPD_UBUS_AUTH_REQ
] = "auth",
1701 [HOSTAPD_UBUS_ASSOC_REQ
] = "assoc",
1703 const char *type
= "mgmt";
1704 struct ubus_event_req ureq
= {};
1707 if (req
->mgmt_frame
)
1708 addr
= req
->mgmt_frame
->sa
;
1712 ban
= avl_find_element(&hapd
->ubus
.banned
, addr
, ban
, avl
);
1714 return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1716 if (!hapd
->ubus
.obj
.has_subscribers
)
1717 return WLAN_STATUS_SUCCESS
;
1719 if (req
->type
< ARRAY_SIZE(types
))
1720 type
= types
[req
->type
];
1722 blob_buf_init(&b
, 0);
1723 blobmsg_add_macaddr(&b
, "address", addr
);
1724 if (req
->mgmt_frame
)
1725 blobmsg_add_macaddr(&b
, "target", req
->mgmt_frame
->da
);
1726 if (req
->ssi_signal
)
1727 blobmsg_add_u32(&b
, "signal", req
->ssi_signal
);
1728 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
1731 if(req
->elems
->ht_capabilities
)
1733 struct ieee80211_ht_capabilities
*ht_capabilities
;
1734 void *ht_cap
, *ht_cap_mcs_set
, *mcs_set
;
1737 ht_capabilities
= (struct ieee80211_ht_capabilities
*) req
->elems
->ht_capabilities
;
1738 ht_cap
= blobmsg_open_table(&b
, "ht_capabilities");
1739 blobmsg_add_u16(&b
, "ht_capabilities_info", ht_capabilities
->ht_capabilities_info
);
1740 ht_cap_mcs_set
= blobmsg_open_table(&b
, "supported_mcs_set");
1741 blobmsg_add_u16(&b
, "a_mpdu_params", ht_capabilities
->a_mpdu_params
);
1742 blobmsg_add_u16(&b
, "ht_extended_capabilities", ht_capabilities
->ht_extended_capabilities
);
1743 blobmsg_add_u32(&b
, "tx_bf_capability_info", ht_capabilities
->tx_bf_capability_info
);
1744 blobmsg_add_u16(&b
, "asel_capabilities", ht_capabilities
->asel_capabilities
);
1745 mcs_set
= blobmsg_open_array(&b
, "supported_mcs_set");
1746 for (int i
= 0; i
< 16; i
++) {
1747 blobmsg_add_u16(&b
, NULL
, (u16
) ht_capabilities
->supported_mcs_set
[i
]);
1749 blobmsg_close_array(&b
, mcs_set
);
1750 blobmsg_close_table(&b
, ht_cap_mcs_set
);
1751 blobmsg_close_table(&b
, ht_cap
);
1753 if(req
->elems
->vht_capabilities
)
1755 struct ieee80211_vht_capabilities
*vht_capabilities
;
1756 void *vht_cap
, *vht_cap_mcs_set
;
1758 vht_capabilities
= (struct ieee80211_vht_capabilities
*) req
->elems
->vht_capabilities
;
1759 vht_cap
= blobmsg_open_table(&b
, "vht_capabilities");
1760 blobmsg_add_u32(&b
, "vht_capabilities_info", vht_capabilities
->vht_capabilities_info
);
1761 vht_cap_mcs_set
= blobmsg_open_table(&b
, "vht_supported_mcs_set");
1762 blobmsg_add_u16(&b
, "rx_map", vht_capabilities
->vht_supported_mcs_set
.rx_map
);
1763 blobmsg_add_u16(&b
, "rx_highest", vht_capabilities
->vht_supported_mcs_set
.rx_highest
);
1764 blobmsg_add_u16(&b
, "tx_map", vht_capabilities
->vht_supported_mcs_set
.tx_map
);
1765 blobmsg_add_u16(&b
, "tx_highest", vht_capabilities
->vht_supported_mcs_set
.tx_highest
);
1766 blobmsg_close_table(&b
, vht_cap_mcs_set
);
1767 blobmsg_close_table(&b
, vht_cap
);
1771 if (!hapd
->ubus
.notify_response
) {
1772 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);
1773 return WLAN_STATUS_SUCCESS
;
1776 if (ubus_notify_async(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, &ureq
.nreq
))
1777 return WLAN_STATUS_SUCCESS
;
1779 ureq
.nreq
.status_cb
= ubus_event_cb
;
1780 ubus_complete_request(ctx
, &ureq
.nreq
.req
, 100);
1785 return WLAN_STATUS_SUCCESS
;
1788 void hostapd_ubus_notify(struct hostapd_data
*hapd
, const char *type
, const u8
*addr
)
1790 if (!hapd
->ubus
.obj
.has_subscribers
)
1796 blob_buf_init(&b
, 0);
1797 blobmsg_add_macaddr(&b
, "address", addr
);
1799 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);
1802 void hostapd_ubus_notify_beacon_report(
1803 struct hostapd_data
*hapd
, const u8
*addr
, u8 token
, u8 rep_mode
,
1804 struct rrm_measurement_beacon_report
*rep
, size_t len
)
1806 if (!hapd
->ubus
.obj
.has_subscribers
)
1812 blob_buf_init(&b
, 0);
1813 blobmsg_add_macaddr(&b
, "address", addr
);
1814 blobmsg_add_u16(&b
, "op-class", rep
->op_class
);
1815 blobmsg_add_u16(&b
, "channel", rep
->channel
);
1816 blobmsg_add_u64(&b
, "start-time", rep
->start_time
);
1817 blobmsg_add_u16(&b
, "duration", rep
->duration
);
1818 blobmsg_add_u16(&b
, "report-info", rep
->report_info
);
1819 blobmsg_add_u16(&b
, "rcpi", rep
->rcpi
);
1820 blobmsg_add_u16(&b
, "rsni", rep
->rsni
);
1821 blobmsg_add_macaddr(&b
, "bssid", rep
->bssid
);
1822 blobmsg_add_u16(&b
, "antenna-id", rep
->antenna_id
);
1823 blobmsg_add_u16(&b
, "parent-tsf", rep
->parent_tsf
);
1825 ubus_notify(ctx
, &hapd
->ubus
.obj
, "beacon-report", b
.head
, -1);
1828 void hostapd_ubus_notify_radar_detected(struct hostapd_iface
*iface
, int frequency
,
1829 int chan_width
, int cf1
, int cf2
)
1831 struct hostapd_data
*hapd
;
1834 blob_buf_init(&b
, 0);
1835 blobmsg_add_u16(&b
, "frequency", frequency
);
1836 blobmsg_add_u16(&b
, "width", chan_width
);
1837 blobmsg_add_u16(&b
, "center1", cf1
);
1838 blobmsg_add_u16(&b
, "center2", cf2
);
1840 for (i
= 0; i
< iface
->num_bss
; i
++) {
1841 hapd
= iface
->bss
[i
];
1842 ubus_notify(ctx
, &hapd
->ubus
.obj
, "radar-detected", b
.head
, -1);
1846 void hostapd_ubus_notify_bss_transition_response(
1847 struct hostapd_data
*hapd
, const u8
*addr
, u8 dialog_token
, u8 status_code
,
1848 u8 bss_termination_delay
, const u8
*target_bssid
,
1849 const u8
*candidate_list
, u16 candidate_list_len
)
1851 #ifdef CONFIG_WNM_AP
1855 if (!hapd
->ubus
.obj
.has_subscribers
)
1861 blob_buf_init(&b
, 0);
1862 blobmsg_add_macaddr(&b
, "address", addr
);
1863 blobmsg_add_u8(&b
, "dialog-token", dialog_token
);
1864 blobmsg_add_u8(&b
, "status-code", status_code
);
1865 blobmsg_add_u8(&b
, "bss-termination-delay", bss_termination_delay
);
1867 blobmsg_add_macaddr(&b
, "target-bssid", target_bssid
);
1868 if (candidate_list_len
> 0) {
1869 cl_str
= blobmsg_alloc_string_buffer(&b
, "candidate-list", candidate_list_len
* 2 + 1);
1870 for (i
= 0; i
< candidate_list_len
; i
++)
1871 snprintf(&cl_str
[i
*2], 3, "%02X", candidate_list
[i
]);
1872 blobmsg_add_string_buffer(&b
);
1875 ubus_notify(ctx
, &hapd
->ubus
.obj
, "bss-transition-response", b
.head
, -1);