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
);
375 /* Imported from iw/util.c
376 * https://git.kernel.org/pub/scm/linux/kernel/git/jberg/iw.git/tree/util.c?id=4b25ae3537af48dbf9d0abf94132e5ba01b32c18#n200
378 int ieee80211_frequency_to_channel(int freq
)
380 /* see 802.11-2007 17.3.8.3.2 and Annex J */
383 /* see 802.11ax D6.1 27.3.23.2 and Annex E */
384 else if (freq
== 5935)
386 else if (freq
< 2484)
387 return (freq
- 2407) / 5;
388 else if (freq
>= 4910 && freq
<= 4980)
389 return (freq
- 4000) / 5;
390 else if (freq
< 5950)
391 return (freq
- 5000) / 5;
392 else if (freq
<= 45000) /* DMG band lower limit */
393 /* see 802.11ax D6.1 27.3.23.2 */
394 return (freq
- 5950) / 5;
395 else if (freq
>= 58320 && freq
<= 70200)
396 return (freq
- 56160) / 2160;
402 hostapd_bss_get_status(struct ubus_context
*ctx
, struct ubus_object
*obj
,
403 struct ubus_request_data
*req
, const char *method
,
404 struct blob_attr
*msg
)
406 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
407 void *airtime_table
, *dfs_table
;
408 struct os_reltime now
;
409 char ssid
[SSID_MAX_LEN
+ 1];
412 size_t ssid_len
= SSID_MAX_LEN
;
414 if (hapd
->conf
->ssid
.ssid_len
< SSID_MAX_LEN
)
415 ssid_len
= hapd
->conf
->ssid
.ssid_len
;
417 blob_buf_init(&b
, 0);
418 blobmsg_add_string(&b
, "status", hostapd_state_text(hapd
->iface
->state
));
419 blobmsg_printf(&b
, "bssid", MACSTR
, MAC2STR(hapd
->conf
->bssid
));
421 memset(ssid
, 0, SSID_MAX_LEN
+ 1);
422 memcpy(ssid
, hapd
->conf
->ssid
.ssid
, ssid_len
);
423 blobmsg_add_string(&b
, "ssid", ssid
);
425 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
426 blobmsg_add_u32(&b
, "channel", ieee80211_frequency_to_channel(hapd
->iface
->freq
));
428 snprintf(phy_name
, 17, "%s", hapd
->iface
->phy
);
429 blobmsg_add_string(&b
, "phy", phy_name
);
432 airtime_table
= blobmsg_open_table(&b
, "airtime");
433 blobmsg_add_u64(&b
, "time", hapd
->iface
->last_channel_time
);
434 blobmsg_add_u64(&b
, "time_busy", hapd
->iface
->last_channel_time_busy
);
435 blobmsg_add_u16(&b
, "utilization", hapd
->iface
->channel_utilization
);
436 blobmsg_close_table(&b
, airtime_table
);
439 dfs_table
= blobmsg_open_table(&b
, "dfs");
440 blobmsg_add_u32(&b
, "cac_seconds", hapd
->iface
->dfs_cac_ms
/ 1000);
441 blobmsg_add_u8(&b
, "cac_active", !!(hapd
->iface
->cac_started
));
442 os_reltime_age(&hapd
->iface
->dfs_cac_start
, &now
);
443 blobmsg_add_u32(&b
, "cac_seconds_left",
444 hapd
->iface
->cac_started
? hapd
->iface
->dfs_cac_ms
/ 1000 - now
.sec
: 0);
445 blobmsg_close_table(&b
, dfs_table
);
447 ubus_send_reply(ctx
, req
, b
.head
);
457 static const struct blobmsg_policy notify_policy
[__NOTIFY_MAX
] = {
458 [NOTIFY_RESPONSE
] = { "notify_response", BLOBMSG_TYPE_INT32
},
462 hostapd_notify_response(struct ubus_context
*ctx
, struct ubus_object
*obj
,
463 struct ubus_request_data
*req
, const char *method
,
464 struct blob_attr
*msg
)
466 struct blob_attr
*tb
[__NOTIFY_MAX
];
467 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
468 struct wpabuf
*elems
;
472 blobmsg_parse(notify_policy
, __NOTIFY_MAX
, tb
,
473 blob_data(msg
), blob_len(msg
));
475 if (!tb
[NOTIFY_RESPONSE
])
476 return UBUS_STATUS_INVALID_ARGUMENT
;
478 hapd
->ubus
.notify_response
= blobmsg_get_u32(tb
[NOTIFY_RESPONSE
]);
480 return UBUS_STATUS_OK
;
491 static const struct blobmsg_policy del_policy
[__DEL_CLIENT_MAX
] = {
492 [DEL_CLIENT_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
493 [DEL_CLIENT_REASON
] = { "reason", BLOBMSG_TYPE_INT32
},
494 [DEL_CLIENT_DEAUTH
] = { "deauth", BLOBMSG_TYPE_INT8
},
495 [DEL_CLIENT_BAN_TIME
] = { "ban_time", BLOBMSG_TYPE_INT32
},
499 hostapd_bss_del_client(struct ubus_context
*ctx
, struct ubus_object
*obj
,
500 struct ubus_request_data
*req
, const char *method
,
501 struct blob_attr
*msg
)
503 struct blob_attr
*tb
[__DEL_CLIENT_MAX
];
504 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
505 struct sta_info
*sta
;
510 blobmsg_parse(del_policy
, __DEL_CLIENT_MAX
, tb
, blob_data(msg
), blob_len(msg
));
512 if (!tb
[DEL_CLIENT_ADDR
])
513 return UBUS_STATUS_INVALID_ARGUMENT
;
515 if (hwaddr_aton(blobmsg_data(tb
[DEL_CLIENT_ADDR
]), addr
))
516 return UBUS_STATUS_INVALID_ARGUMENT
;
518 if (tb
[DEL_CLIENT_REASON
])
519 reason
= blobmsg_get_u32(tb
[DEL_CLIENT_REASON
]);
521 if (tb
[DEL_CLIENT_DEAUTH
])
522 deauth
= blobmsg_get_bool(tb
[DEL_CLIENT_DEAUTH
]);
524 sta
= ap_get_sta(hapd
, addr
);
527 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
528 ap_sta_deauthenticate(hapd
, sta
, reason
);
530 hostapd_drv_sta_disassoc(hapd
, addr
, reason
);
531 ap_sta_disassociate(hapd
, sta
, reason
);
535 if (tb
[DEL_CLIENT_BAN_TIME
])
536 hostapd_bss_ban_client(hapd
, addr
, blobmsg_get_u32(tb
[DEL_CLIENT_BAN_TIME
]));
542 blobmsg_add_macaddr(struct blob_buf
*buf
, const char *name
, const u8
*addr
)
546 s
= blobmsg_alloc_string_buffer(buf
, name
, 20);
547 sprintf(s
, MACSTR
, MAC2STR(addr
));
548 blobmsg_add_string_buffer(buf
);
552 hostapd_bss_list_bans(struct ubus_context
*ctx
, struct ubus_object
*obj
,
553 struct ubus_request_data
*req
, const char *method
,
554 struct blob_attr
*msg
)
556 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
557 struct ubus_banned_client
*ban
;
560 blob_buf_init(&b
, 0);
561 c
= blobmsg_open_array(&b
, "clients");
562 avl_for_each_element(&hapd
->ubus
.banned
, ban
, avl
)
563 blobmsg_add_macaddr(&b
, NULL
, ban
->addr
);
564 blobmsg_close_array(&b
, c
);
565 ubus_send_reply(ctx
, req
, b
.head
);
572 hostapd_bss_wps_start(struct ubus_context
*ctx
, struct ubus_object
*obj
,
573 struct ubus_request_data
*req
, const char *method
,
574 struct blob_attr
*msg
)
577 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
579 rc
= hostapd_wps_button_pushed(hapd
, NULL
);
582 return UBUS_STATUS_NOT_SUPPORTED
;
588 static const char * pbc_status_enum_str(enum pbc_status status
)
591 case WPS_PBC_STATUS_DISABLE
:
593 case WPS_PBC_STATUS_ACTIVE
:
595 case WPS_PBC_STATUS_TIMEOUT
:
597 case WPS_PBC_STATUS_OVERLAP
:
605 hostapd_bss_wps_status(struct ubus_context
*ctx
, struct ubus_object
*obj
,
606 struct ubus_request_data
*req
, const char *method
,
607 struct blob_attr
*msg
)
610 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
612 blob_buf_init(&b
, 0);
614 blobmsg_add_string(&b
, "pbc_status", pbc_status_enum_str(hapd
->wps_stats
.pbc_status
));
615 blobmsg_add_string(&b
, "last_wps_result",
616 (hapd
->wps_stats
.status
== WPS_STATUS_SUCCESS
?
618 (hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
?
619 "Failed" : "None")));
621 /* If status == Failure - Add possible Reasons */
622 if(hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
&&
623 hapd
->wps_stats
.failure_reason
> 0)
624 blobmsg_add_string(&b
, "reason", wps_ei_str(hapd
->wps_stats
.failure_reason
));
626 if (hapd
->wps_stats
.status
)
627 blobmsg_printf(&b
, "peer_address", MACSTR
, MAC2STR(hapd
->wps_stats
.peer_addr
));
629 ubus_send_reply(ctx
, req
, b
.head
);
635 hostapd_bss_wps_cancel(struct ubus_context
*ctx
, struct ubus_object
*obj
,
636 struct ubus_request_data
*req
, const char *method
,
637 struct blob_attr
*msg
)
640 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
642 rc
= hostapd_wps_cancel(hapd
);
645 return UBUS_STATUS_NOT_SUPPORTED
;
649 #endif /* CONFIG_WPS */
652 hostapd_bss_update_beacon(struct ubus_context
*ctx
, struct ubus_object
*obj
,
653 struct ubus_request_data
*req
, const char *method
,
654 struct blob_attr
*msg
)
657 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
659 rc
= ieee802_11_set_beacon(hapd
);
662 return UBUS_STATUS_NOT_SUPPORTED
;
673 static const struct blobmsg_policy config_add_policy
[__CONFIG_MAX
] = {
674 [CONFIG_IFACE
] = { "iface", BLOBMSG_TYPE_STRING
},
675 [CONFIG_FILE
] = { "config", BLOBMSG_TYPE_STRING
},
679 hostapd_config_add(struct ubus_context
*ctx
, struct ubus_object
*obj
,
680 struct ubus_request_data
*req
, const char *method
,
681 struct blob_attr
*msg
)
683 struct blob_attr
*tb
[__CONFIG_MAX
];
684 struct hapd_interfaces
*interfaces
= get_hapd_interfaces_from_object(obj
);
687 blobmsg_parse(config_add_policy
, __CONFIG_MAX
, tb
, blob_data(msg
), blob_len(msg
));
689 if (!tb
[CONFIG_FILE
] || !tb
[CONFIG_IFACE
])
690 return UBUS_STATUS_INVALID_ARGUMENT
;
692 snprintf(buf
, sizeof(buf
), "bss_config=%s:%s",
693 blobmsg_get_string(tb
[CONFIG_IFACE
]),
694 blobmsg_get_string(tb
[CONFIG_FILE
]));
696 if (hostapd_add_iface(interfaces
, buf
))
697 return UBUS_STATUS_INVALID_ARGUMENT
;
699 blob_buf_init(&b
, 0);
700 blobmsg_add_u32(&b
, "pid", getpid());
701 ubus_send_reply(ctx
, req
, b
.head
);
703 return UBUS_STATUS_OK
;
711 static const struct blobmsg_policy config_remove_policy
[__CONFIG_REM_MAX
] = {
712 [CONFIG_REM_IFACE
] = { "iface", BLOBMSG_TYPE_STRING
},
716 hostapd_config_remove(struct ubus_context
*ctx
, struct ubus_object
*obj
,
717 struct ubus_request_data
*req
, const char *method
,
718 struct blob_attr
*msg
)
720 struct blob_attr
*tb
[__CONFIG_REM_MAX
];
721 struct hapd_interfaces
*interfaces
= get_hapd_interfaces_from_object(obj
);
724 blobmsg_parse(config_remove_policy
, __CONFIG_REM_MAX
, tb
, blob_data(msg
), blob_len(msg
));
726 if (!tb
[CONFIG_REM_IFACE
])
727 return UBUS_STATUS_INVALID_ARGUMENT
;
729 if (hostapd_remove_iface(interfaces
, blobmsg_get_string(tb
[CONFIG_REM_IFACE
])))
730 return UBUS_STATUS_INVALID_ARGUMENT
;
732 return UBUS_STATUS_OK
;
741 CSA_SEC_CHANNEL_OFFSET
,
748 static const struct blobmsg_policy csa_policy
[__CSA_MAX
] = {
749 [CSA_FREQ
] = { "freq", BLOBMSG_TYPE_INT32
},
750 [CSA_BCN_COUNT
] = { "bcn_count", BLOBMSG_TYPE_INT32
},
751 [CSA_CENTER_FREQ1
] = { "center_freq1", BLOBMSG_TYPE_INT32
},
752 [CSA_CENTER_FREQ2
] = { "center_freq2", BLOBMSG_TYPE_INT32
},
753 [CSA_BANDWIDTH
] = { "bandwidth", BLOBMSG_TYPE_INT32
},
754 [CSA_SEC_CHANNEL_OFFSET
] = { "sec_channel_offset", BLOBMSG_TYPE_INT32
},
755 [CSA_HT
] = { "ht", BLOBMSG_TYPE_BOOL
},
756 [CSA_VHT
] = { "vht", BLOBMSG_TYPE_BOOL
},
757 [CSA_BLOCK_TX
] = { "block_tx", BLOBMSG_TYPE_BOOL
},
762 hostapd_switch_chan(struct ubus_context
*ctx
, struct ubus_object
*obj
,
763 struct ubus_request_data
*req
, const char *method
,
764 struct blob_attr
*msg
)
766 struct blob_attr
*tb
[__CSA_MAX
];
767 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
768 struct csa_settings css
;
769 int ret
= UBUS_STATUS_OK
;
772 blobmsg_parse(csa_policy
, __CSA_MAX
, tb
, blob_data(msg
), blob_len(msg
));
775 return UBUS_STATUS_INVALID_ARGUMENT
;
777 memset(&css
, 0, sizeof(css
));
778 css
.freq_params
.freq
= blobmsg_get_u32(tb
[CSA_FREQ
]);
780 #define SET_CSA_SETTING(name, field, type) \
783 css.field = blobmsg_get_ ## type(tb[name]); \
786 SET_CSA_SETTING(CSA_BCN_COUNT
, cs_count
, u32
);
787 SET_CSA_SETTING(CSA_CENTER_FREQ1
, freq_params
.center_freq1
, u32
);
788 SET_CSA_SETTING(CSA_CENTER_FREQ2
, freq_params
.center_freq2
, u32
);
789 SET_CSA_SETTING(CSA_BANDWIDTH
, freq_params
.bandwidth
, u32
);
790 SET_CSA_SETTING(CSA_SEC_CHANNEL_OFFSET
, freq_params
.sec_channel_offset
, u32
);
791 SET_CSA_SETTING(CSA_HT
, freq_params
.ht_enabled
, bool);
792 SET_CSA_SETTING(CSA_VHT
, freq_params
.vht_enabled
, bool);
793 SET_CSA_SETTING(CSA_BLOCK_TX
, block_tx
, bool);
795 for (i
= 0; i
< hapd
->iface
->num_bss
; i
++) {
796 struct hostapd_data
*bss
= hapd
->iface
->bss
[i
];
798 if (hostapd_switch_channel(bss
, &css
) != 0)
799 ret
= UBUS_STATUS_NOT_SUPPORTED
;
803 #undef SET_CSA_SETTING
809 __VENDOR_ELEMENTS_MAX
812 static const struct blobmsg_policy ve_policy
[__VENDOR_ELEMENTS_MAX
] = {
813 /* vendor elements are provided as hex-string */
814 [VENDOR_ELEMENTS
] = { "vendor_elements", BLOBMSG_TYPE_STRING
},
818 hostapd_vendor_elements(struct ubus_context
*ctx
, struct ubus_object
*obj
,
819 struct ubus_request_data
*req
, const char *method
,
820 struct blob_attr
*msg
)
822 struct blob_attr
*tb
[__VENDOR_ELEMENTS_MAX
];
823 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
824 struct hostapd_bss_config
*bss
= hapd
->conf
;
825 struct wpabuf
*elems
;
829 blobmsg_parse(ve_policy
, __VENDOR_ELEMENTS_MAX
, tb
,
830 blob_data(msg
), blob_len(msg
));
832 if (!tb
[VENDOR_ELEMENTS
])
833 return UBUS_STATUS_INVALID_ARGUMENT
;
835 pos
= blobmsg_data(tb
[VENDOR_ELEMENTS
]);
836 len
= os_strlen(pos
);
838 return UBUS_STATUS_INVALID_ARGUMENT
;
842 wpabuf_free(bss
->vendor_elements
);
843 bss
->vendor_elements
= NULL
;
847 elems
= wpabuf_alloc(len
);
851 if (hexstr2bin(pos
, wpabuf_put(elems
, len
), len
)) {
853 return UBUS_STATUS_INVALID_ARGUMENT
;
856 wpabuf_free(bss
->vendor_elements
);
857 bss
->vendor_elements
= elems
;
859 /* update beacons if vendor elements were set successfully */
860 if (ieee802_11_update_beacons(hapd
->iface
) != 0)
861 return UBUS_STATUS_NOT_SUPPORTED
;
862 return UBUS_STATUS_OK
;
866 hostapd_rrm_print_nr(struct hostapd_neighbor_entry
*nr
)
872 blobmsg_printf(&b
, "", MACSTR
, MAC2STR(nr
->bssid
));
874 str
= blobmsg_alloc_string_buffer(&b
, "", nr
->ssid
.ssid_len
+ 1);
875 memcpy(str
, nr
->ssid
.ssid
, nr
->ssid
.ssid_len
);
876 str
[nr
->ssid
.ssid_len
] = 0;
877 blobmsg_add_string_buffer(&b
);
879 len
= wpabuf_len(nr
->nr
);
880 str
= blobmsg_alloc_string_buffer(&b
, "", 2 * len
+ 1);
881 wpa_snprintf_hex(str
, 2 * len
+ 1, wpabuf_head_u8(nr
->nr
), len
);
882 blobmsg_add_string_buffer(&b
);
886 BSS_MGMT_EN_NEIGHBOR
,
889 BSS_MGMT_EN_BSS_TRANSITION
,
895 __hostapd_bss_mgmt_enable_f(struct hostapd_data
*hapd
, int flag
)
897 struct hostapd_bss_config
*bss
= hapd
->conf
;
901 case BSS_MGMT_EN_NEIGHBOR
:
902 if (bss
->radio_measurements
[0] &
903 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)
906 bss
->radio_measurements
[0] |=
907 WLAN_RRM_CAPS_NEIGHBOR_REPORT
;
908 hostapd_neighbor_set_own_report(hapd
);
910 case BSS_MGMT_EN_BEACON
:
911 flags
= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE
|
912 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE
|
913 WLAN_RRM_CAPS_BEACON_REPORT_TABLE
;
915 if (bss
->radio_measurements
[0] & flags
== flags
)
918 bss
->radio_measurements
[0] |= (u8
) flags
;
921 case BSS_MGMT_EN_BSS_TRANSITION
:
922 if (bss
->bss_transition
)
925 bss
->bss_transition
= 1;
932 __hostapd_bss_mgmt_enable(struct hostapd_data
*hapd
, uint32_t flags
)
937 for (i
= 0; i
< __BSS_MGMT_EN_MAX
; i
++) {
938 if (!(flags
& (1 << i
)))
941 update
|= __hostapd_bss_mgmt_enable_f(hapd
, i
);
945 ieee802_11_update_beacons(hapd
->iface
);
949 static const struct blobmsg_policy bss_mgmt_enable_policy
[__BSS_MGMT_EN_MAX
] = {
950 [BSS_MGMT_EN_NEIGHBOR
] = { "neighbor_report", BLOBMSG_TYPE_BOOL
},
951 [BSS_MGMT_EN_BEACON
] = { "beacon_report", BLOBMSG_TYPE_BOOL
},
953 [BSS_MGMT_EN_BSS_TRANSITION
] = { "bss_transition", BLOBMSG_TYPE_BOOL
},
958 hostapd_bss_mgmt_enable(struct ubus_context
*ctx
, struct ubus_object
*obj
,
959 struct ubus_request_data
*req
, const char *method
,
960 struct blob_attr
*msg
)
963 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
964 struct blob_attr
*tb
[__BSS_MGMT_EN_MAX
];
965 struct blob_attr
*cur
;
968 bool neigh
= false, beacon
= false;
970 blobmsg_parse(bss_mgmt_enable_policy
, __BSS_MGMT_EN_MAX
, tb
, blob_data(msg
), blob_len(msg
));
972 for (i
= 0; i
< ARRAY_SIZE(tb
); i
++) {
973 if (!tb
[i
] || !blobmsg_get_bool(tb
[i
]))
979 __hostapd_bss_mgmt_enable(hapd
, flags
);
984 hostapd_rrm_nr_enable(struct hostapd_data
*hapd
)
986 __hostapd_bss_mgmt_enable(hapd
, 1 << BSS_MGMT_EN_NEIGHBOR
);
990 hostapd_rrm_nr_get_own(struct ubus_context
*ctx
, struct ubus_object
*obj
,
991 struct ubus_request_data
*req
, const char *method
,
992 struct blob_attr
*msg
)
994 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
995 struct hostapd_neighbor_entry
*nr
;
998 hostapd_rrm_nr_enable(hapd
);
1000 nr
= hostapd_neighbor_get(hapd
, hapd
->own_addr
, NULL
);
1002 return UBUS_STATUS_NOT_FOUND
;
1004 blob_buf_init(&b
, 0);
1006 c
= blobmsg_open_array(&b
, "value");
1007 hostapd_rrm_print_nr(nr
);
1008 blobmsg_close_array(&b
, c
);
1010 ubus_send_reply(ctx
, req
, b
.head
);
1016 hostapd_rrm_nr_list(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1017 struct ubus_request_data
*req
, const char *method
,
1018 struct blob_attr
*msg
)
1020 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
1021 struct hostapd_neighbor_entry
*nr
;
1024 hostapd_rrm_nr_enable(hapd
);
1025 blob_buf_init(&b
, 0);
1027 c
= blobmsg_open_array(&b
, "list");
1028 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
1031 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
1034 cur
= blobmsg_open_array(&b
, NULL
);
1035 hostapd_rrm_print_nr(nr
);
1036 blobmsg_close_array(&b
, cur
);
1038 blobmsg_close_array(&b
, c
);
1040 ubus_send_reply(ctx
, req
, b
.head
);
1050 static const struct blobmsg_policy nr_set_policy
[__NR_SET_LIST_MAX
] = {
1051 [NR_SET_LIST
] = { "list", BLOBMSG_TYPE_ARRAY
},
1056 hostapd_rrm_nr_clear(struct hostapd_data
*hapd
)
1058 struct hostapd_neighbor_entry
*nr
;
1061 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
1062 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
1065 hostapd_neighbor_remove(hapd
, nr
->bssid
, &nr
->ssid
);
1071 hostapd_rrm_nr_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1072 struct ubus_request_data
*req
, const char *method
,
1073 struct blob_attr
*msg
)
1075 static const struct blobmsg_policy nr_e_policy
[] = {
1076 { .type
= BLOBMSG_TYPE_STRING
},
1077 { .type
= BLOBMSG_TYPE_STRING
},
1078 { .type
= BLOBMSG_TYPE_STRING
},
1080 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
1081 struct blob_attr
*tb_l
[__NR_SET_LIST_MAX
];
1082 struct blob_attr
*tb
[ARRAY_SIZE(nr_e_policy
)];
1083 struct blob_attr
*cur
;
1086 hostapd_rrm_nr_enable(hapd
);
1088 blobmsg_parse(nr_set_policy
, __NR_SET_LIST_MAX
, tb_l
, blob_data(msg
), blob_len(msg
));
1089 if (!tb_l
[NR_SET_LIST
])
1090 return UBUS_STATUS_INVALID_ARGUMENT
;
1092 hostapd_rrm_nr_clear(hapd
);
1093 blobmsg_for_each_attr(cur
, tb_l
[NR_SET_LIST
], rem
) {
1094 struct wpa_ssid_value ssid
;
1095 struct wpabuf
*data
;
1099 blobmsg_parse_array(nr_e_policy
, ARRAY_SIZE(nr_e_policy
), tb
, blobmsg_data(cur
), blobmsg_data_len(cur
));
1100 if (!tb
[0] || !tb
[1] || !tb
[2])
1103 /* Neighbor Report binary */
1104 nr_s
= blobmsg_get_string(tb
[2]);
1105 data
= wpabuf_parse_bin(nr_s
);
1110 s
= blobmsg_get_string(tb
[0]);
1111 if (strlen(s
) == 0) {
1112 /* Copy BSSID from neighbor report */
1113 if (hwaddr_compact_aton(nr_s
, bssid
))
1115 } else if (hwaddr_aton(s
, bssid
)) {
1120 s
= blobmsg_get_string(tb
[1]);
1121 if (strlen(s
) == 0) {
1122 /* Copy SSID from hostapd BSS conf */
1123 memcpy(&ssid
, &hapd
->conf
->ssid
, sizeof(ssid
));
1125 ssid
.ssid_len
= strlen(s
);
1126 if (ssid
.ssid_len
> sizeof(ssid
.ssid
))
1129 memcpy(&ssid
, s
, ssid
.ssid_len
);
1132 hostapd_neighbor_set(hapd
, bssid
, &ssid
, data
, NULL
, NULL
, 0);
1137 return UBUS_STATUS_INVALID_ARGUMENT
;
1146 BEACON_REQ_OP_CLASS
,
1148 BEACON_REQ_DURATION
,
1154 static const struct blobmsg_policy beacon_req_policy
[__BEACON_REQ_MAX
] = {
1155 [BEACON_REQ_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
1156 [BEACON_REQ_OP_CLASS
] { "op_class", BLOBMSG_TYPE_INT32
},
1157 [BEACON_REQ_CHANNEL
] { "channel", BLOBMSG_TYPE_INT32
},
1158 [BEACON_REQ_DURATION
] { "duration", BLOBMSG_TYPE_INT32
},
1159 [BEACON_REQ_MODE
] { "mode", BLOBMSG_TYPE_INT32
},
1160 [BEACON_REQ_BSSID
] { "bssid", BLOBMSG_TYPE_STRING
},
1161 [BEACON_REQ_SSID
] { "ssid", BLOBMSG_TYPE_STRING
},
1165 hostapd_rrm_beacon_req(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1166 struct ubus_request_data
*ureq
, const char *method
,
1167 struct blob_attr
*msg
)
1169 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1170 struct blob_attr
*tb
[__BEACON_REQ_MAX
];
1171 struct blob_attr
*cur
;
1173 u8 bssid
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1178 blobmsg_parse(beacon_req_policy
, __BEACON_REQ_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1180 if (!tb
[BEACON_REQ_ADDR
] || !tb
[BEACON_REQ_MODE
] || !tb
[BEACON_REQ_DURATION
] ||
1181 !tb
[BEACON_REQ_OP_CLASS
] || !tb
[BEACON_REQ_CHANNEL
])
1182 return UBUS_STATUS_INVALID_ARGUMENT
;
1184 if (tb
[BEACON_REQ_SSID
])
1185 buf_len
+= blobmsg_data_len(tb
[BEACON_REQ_SSID
]) + 2 - 1;
1187 mode
= blobmsg_get_u32(tb
[BEACON_REQ_MODE
]);
1188 if (hwaddr_aton(blobmsg_data(tb
[BEACON_REQ_ADDR
]), addr
))
1189 return UBUS_STATUS_INVALID_ARGUMENT
;
1191 if (tb
[BEACON_REQ_BSSID
] &&
1192 hwaddr_aton(blobmsg_data(tb
[BEACON_REQ_BSSID
]), bssid
))
1193 return UBUS_STATUS_INVALID_ARGUMENT
;
1195 req
= wpabuf_alloc(buf_len
);
1197 return UBUS_STATUS_UNKNOWN_ERROR
;
1199 /* 1: regulatory class */
1200 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_OP_CLASS
]));
1202 /* 2: channel number */
1203 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_CHANNEL
]));
1205 /* 3-4: randomization interval */
1206 wpabuf_put_le16(req
, 0);
1209 wpabuf_put_le16(req
, blobmsg_get_u32(tb
[BEACON_REQ_DURATION
]));
1212 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_MODE
]));
1215 wpabuf_put_data(req
, bssid
, ETH_ALEN
);
1217 if ((cur
= tb
[BEACON_REQ_SSID
]) != NULL
) {
1218 wpabuf_put_u8(req
, WLAN_EID_SSID
);
1219 wpabuf_put_u8(req
, blobmsg_data_len(cur
) - 1);
1220 wpabuf_put_data(req
, blobmsg_data(cur
), blobmsg_data_len(cur
) - 1);
1223 ret
= hostapd_send_beacon_req(hapd
, addr
, 0, req
);
1231 #ifdef CONFIG_WNM_AP
1234 WNM_DISASSOC_DURATION
,
1235 WNM_DISASSOC_NEIGHBORS
,
1236 WNM_DISASSOC_ABRIDGED
,
1240 static const struct blobmsg_policy wnm_disassoc_policy
[__WNM_DISASSOC_MAX
] = {
1241 [WNM_DISASSOC_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
1242 [WNM_DISASSOC_DURATION
] { "duration", BLOBMSG_TYPE_INT32
},
1243 [WNM_DISASSOC_NEIGHBORS
] { "neighbors", BLOBMSG_TYPE_ARRAY
},
1244 [WNM_DISASSOC_ABRIDGED
] { "abridged", BLOBMSG_TYPE_BOOL
},
1248 hostapd_wnm_disassoc_imminent(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1249 struct ubus_request_data
*ureq
, const char *method
,
1250 struct blob_attr
*msg
)
1252 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1253 struct blob_attr
*tb
[__WNM_DISASSOC_MAX
];
1254 struct blob_attr
*cur
;
1255 struct sta_info
*sta
;
1260 u8 req_mode
= WNM_BSS_TM_REQ_DISASSOC_IMMINENT
;
1263 blobmsg_parse(wnm_disassoc_policy
, __WNM_DISASSOC_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1265 if (!tb
[WNM_DISASSOC_ADDR
])
1266 return UBUS_STATUS_INVALID_ARGUMENT
;
1268 if (hwaddr_aton(blobmsg_data(tb
[WNM_DISASSOC_ADDR
]), addr
))
1269 return UBUS_STATUS_INVALID_ARGUMENT
;
1271 if ((cur
= tb
[WNM_DISASSOC_DURATION
]) != NULL
)
1272 duration
= blobmsg_get_u32(cur
);
1274 sta
= ap_get_sta(hapd
, addr
);
1276 return UBUS_STATUS_NOT_FOUND
;
1278 if (tb
[WNM_DISASSOC_NEIGHBORS
]) {
1281 if (blobmsg_check_array(tb
[WNM_DISASSOC_NEIGHBORS
],
1282 BLOBMSG_TYPE_STRING
) < 0)
1283 return UBUS_STATUS_INVALID_ARGUMENT
;
1285 blobmsg_for_each_attr(cur
, tb
[WNM_DISASSOC_NEIGHBORS
], rem
) {
1286 int len
= strlen(blobmsg_get_string(cur
));
1289 return UBUS_STATUS_INVALID_ARGUMENT
;
1291 nr_len
+= (len
/ 2) + 2;
1295 nr
= os_zalloc(nr_len
);
1297 return UBUS_STATUS_UNKNOWN_ERROR
;
1301 blobmsg_for_each_attr(cur
, tb
[WNM_DISASSOC_NEIGHBORS
], rem
) {
1302 int len
= strlen(blobmsg_get_string(cur
)) / 2;
1304 *nr_cur
++ = WLAN_EID_NEIGHBOR_REPORT
;
1305 *nr_cur
++ = (u8
) len
;
1306 if (hexstr2bin(blobmsg_data(cur
), nr_cur
, len
)) {
1308 return UBUS_STATUS_INVALID_ARGUMENT
;
1316 req_mode
|= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED
;
1318 if (tb
[WNM_DISASSOC_ABRIDGED
] && blobmsg_get_bool(tb
[WNM_DISASSOC_ABRIDGED
]))
1319 req_mode
|= WNM_BSS_TM_REQ_ABRIDGED
;
1321 if (wnm_send_bss_tm_req(hapd
, sta
, req_mode
, duration
, duration
, NULL
,
1322 NULL
, nr
, nr_len
, NULL
, 0))
1323 return UBUS_STATUS_UNKNOWN_ERROR
;
1329 static const struct ubus_method bss_methods
[] = {
1330 UBUS_METHOD_NOARG("reload", hostapd_bss_reload
),
1331 UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients
),
1332 UBUS_METHOD_NOARG("get_status", hostapd_bss_get_status
),
1333 UBUS_METHOD("del_client", hostapd_bss_del_client
, del_policy
),
1334 UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans
),
1336 UBUS_METHOD_NOARG("wps_start", hostapd_bss_wps_start
),
1337 UBUS_METHOD_NOARG("wps_status", hostapd_bss_wps_status
),
1338 UBUS_METHOD_NOARG("wps_cancel", hostapd_bss_wps_cancel
),
1340 UBUS_METHOD_NOARG("update_beacon", hostapd_bss_update_beacon
),
1341 UBUS_METHOD_NOARG("get_features", hostapd_bss_get_features
),
1343 UBUS_METHOD("switch_chan", hostapd_switch_chan
, csa_policy
),
1345 UBUS_METHOD("set_vendor_elements", hostapd_vendor_elements
, ve_policy
),
1346 UBUS_METHOD("notify_response", hostapd_notify_response
, notify_policy
),
1347 UBUS_METHOD("bss_mgmt_enable", hostapd_bss_mgmt_enable
, bss_mgmt_enable_policy
),
1348 UBUS_METHOD_NOARG("rrm_nr_get_own", hostapd_rrm_nr_get_own
),
1349 UBUS_METHOD_NOARG("rrm_nr_list", hostapd_rrm_nr_list
),
1350 UBUS_METHOD("rrm_nr_set", hostapd_rrm_nr_set
, nr_set_policy
),
1351 UBUS_METHOD("rrm_beacon_req", hostapd_rrm_beacon_req
, beacon_req_policy
),
1352 #ifdef CONFIG_WNM_AP
1353 UBUS_METHOD("wnm_disassoc_imminent", hostapd_wnm_disassoc_imminent
, wnm_disassoc_policy
),
1357 static struct ubus_object_type bss_object_type
=
1358 UBUS_OBJECT_TYPE("hostapd_bss", bss_methods
);
1360 static int avl_compare_macaddr(const void *k1
, const void *k2
, void *ptr
)
1362 return memcmp(k1
, k2
, ETH_ALEN
);
1365 void hostapd_ubus_add_bss(struct hostapd_data
*hapd
)
1367 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
1372 if (hapd
->conf
->mesh
& MESH_ENABLED
)
1376 if (!hostapd_ubus_init())
1379 if (asprintf(&name
, "hostapd.%s", hapd
->conf
->iface
) < 0)
1382 avl_init(&hapd
->ubus
.banned
, avl_compare_macaddr
, false, NULL
);
1384 obj
->type
= &bss_object_type
;
1385 obj
->methods
= bss_object_type
.methods
;
1386 obj
->n_methods
= bss_object_type
.n_methods
;
1387 ret
= ubus_add_object(ctx
, obj
);
1388 hostapd_ubus_ref_inc();
1390 hostapd_send_shared_event(&hapd
->iface
->interfaces
->ubus
, hapd
->conf
->iface
, "add");
1393 void hostapd_ubus_free_bss(struct hostapd_data
*hapd
)
1395 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
1396 char *name
= (char *) obj
->name
;
1401 hostapd_send_shared_event(&hapd
->iface
->interfaces
->ubus
, hapd
->conf
->iface
, "remove");
1404 ubus_remove_object(ctx
, obj
);
1405 hostapd_ubus_ref_dec();
1412 hostapd_ubus_vlan_action(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
,
1415 struct vlan_description
*desc
= &vlan
->vlan_desc
;
1419 if (!hapd
->ubus
.obj
.has_subscribers
)
1422 blob_buf_init(&b
, 0);
1423 blobmsg_add_string(&b
, "ifname", vlan
->ifname
);
1424 blobmsg_add_string(&b
, "bridge", vlan
->bridge
);
1425 blobmsg_add_u32(&b
, "vlan_id", vlan
->vlan_id
);
1427 if (desc
->notempty
) {
1428 blobmsg_add_u32(&b
, "untagged", desc
->untagged
);
1429 c
= blobmsg_open_array(&b
, "tagged");
1430 for (i
= 0; i
< ARRAY_SIZE(desc
->tagged
) && desc
->tagged
[i
]; i
++)
1431 blobmsg_add_u32(&b
, "", desc
->tagged
[i
]);
1432 blobmsg_close_array(&b
, c
);
1435 ubus_notify(ctx
, &hapd
->ubus
.obj
, action
, b
.head
, -1);
1438 void hostapd_ubus_add_vlan(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
)
1440 hostapd_ubus_vlan_action(hapd
, vlan
, "vlan_add");
1443 void hostapd_ubus_remove_vlan(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
)
1445 hostapd_ubus_vlan_action(hapd
, vlan
, "vlan_remove");
1448 static const struct ubus_method daemon_methods
[] = {
1449 UBUS_METHOD("config_add", hostapd_config_add
, config_add_policy
),
1450 UBUS_METHOD("config_remove", hostapd_config_remove
, config_remove_policy
),
1453 static struct ubus_object_type daemon_object_type
=
1454 UBUS_OBJECT_TYPE("hostapd", daemon_methods
);
1456 void hostapd_ubus_add(struct hapd_interfaces
*interfaces
)
1458 struct ubus_object
*obj
= &interfaces
->ubus
;
1461 if (!hostapd_ubus_init())
1464 obj
->name
= strdup("hostapd");
1466 obj
->type
= &daemon_object_type
;
1467 obj
->methods
= daemon_object_type
.methods
;
1468 obj
->n_methods
= daemon_object_type
.n_methods
;
1469 ret
= ubus_add_object(ctx
, obj
);
1470 hostapd_ubus_ref_inc();
1473 void hostapd_ubus_free(struct hapd_interfaces
*interfaces
)
1475 struct ubus_object
*obj
= &interfaces
->ubus
;
1476 char *name
= (char *) obj
->name
;
1482 ubus_remove_object(ctx
, obj
);
1483 hostapd_ubus_ref_dec();
1489 struct ubus_event_req
{
1490 struct ubus_notify_request nreq
;
1495 ubus_event_cb(struct ubus_notify_request
*req
, int idx
, int ret
)
1497 struct ubus_event_req
*ureq
= container_of(req
, struct ubus_event_req
, nreq
);
1502 int hostapd_ubus_handle_event(struct hostapd_data
*hapd
, struct hostapd_ubus_request
*req
)
1504 struct ubus_banned_client
*ban
;
1505 const char *types
[HOSTAPD_UBUS_TYPE_MAX
] = {
1506 [HOSTAPD_UBUS_PROBE_REQ
] = "probe",
1507 [HOSTAPD_UBUS_AUTH_REQ
] = "auth",
1508 [HOSTAPD_UBUS_ASSOC_REQ
] = "assoc",
1510 const char *type
= "mgmt";
1511 struct ubus_event_req ureq
= {};
1514 if (req
->mgmt_frame
)
1515 addr
= req
->mgmt_frame
->sa
;
1519 ban
= avl_find_element(&hapd
->ubus
.banned
, addr
, ban
, avl
);
1521 return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1523 if (!hapd
->ubus
.obj
.has_subscribers
)
1524 return WLAN_STATUS_SUCCESS
;
1526 if (req
->type
< ARRAY_SIZE(types
))
1527 type
= types
[req
->type
];
1529 blob_buf_init(&b
, 0);
1530 blobmsg_add_macaddr(&b
, "address", addr
);
1531 if (req
->mgmt_frame
)
1532 blobmsg_add_macaddr(&b
, "target", req
->mgmt_frame
->da
);
1533 if (req
->ssi_signal
)
1534 blobmsg_add_u32(&b
, "signal", req
->ssi_signal
);
1535 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
1538 if(req
->elems
->ht_capabilities
)
1540 struct ieee80211_ht_capabilities
*ht_capabilities
;
1541 void *ht_cap
, *ht_cap_mcs_set
, *mcs_set
;
1544 ht_capabilities
= (struct ieee80211_ht_capabilities
*) req
->elems
->ht_capabilities
;
1545 ht_cap
= blobmsg_open_table(&b
, "ht_capabilities");
1546 blobmsg_add_u16(&b
, "ht_capabilities_info", ht_capabilities
->ht_capabilities_info
);
1547 ht_cap_mcs_set
= blobmsg_open_table(&b
, "supported_mcs_set");
1548 blobmsg_add_u16(&b
, "a_mpdu_params", ht_capabilities
->a_mpdu_params
);
1549 blobmsg_add_u16(&b
, "ht_extended_capabilities", ht_capabilities
->ht_extended_capabilities
);
1550 blobmsg_add_u32(&b
, "tx_bf_capability_info", ht_capabilities
->tx_bf_capability_info
);
1551 blobmsg_add_u16(&b
, "asel_capabilities", ht_capabilities
->asel_capabilities
);
1552 mcs_set
= blobmsg_open_array(&b
, "supported_mcs_set");
1553 for (int i
= 0; i
< 16; i
++) {
1554 blobmsg_add_u16(&b
, NULL
, (u16
) ht_capabilities
->supported_mcs_set
[i
]);
1556 blobmsg_close_array(&b
, mcs_set
);
1557 blobmsg_close_table(&b
, ht_cap_mcs_set
);
1558 blobmsg_close_table(&b
, ht_cap
);
1560 if(req
->elems
->vht_capabilities
)
1562 struct ieee80211_vht_capabilities
*vht_capabilities
;
1563 void *vht_cap
, *vht_cap_mcs_set
;
1565 vht_capabilities
= (struct ieee80211_vht_capabilities
*) req
->elems
->vht_capabilities
;
1566 vht_cap
= blobmsg_open_table(&b
, "vht_capabilities");
1567 blobmsg_add_u32(&b
, "vht_capabilities_info", vht_capabilities
->vht_capabilities_info
);
1568 vht_cap_mcs_set
= blobmsg_open_table(&b
, "vht_supported_mcs_set");
1569 blobmsg_add_u16(&b
, "rx_map", vht_capabilities
->vht_supported_mcs_set
.rx_map
);
1570 blobmsg_add_u16(&b
, "rx_highest", vht_capabilities
->vht_supported_mcs_set
.rx_highest
);
1571 blobmsg_add_u16(&b
, "tx_map", vht_capabilities
->vht_supported_mcs_set
.tx_map
);
1572 blobmsg_add_u16(&b
, "tx_highest", vht_capabilities
->vht_supported_mcs_set
.tx_highest
);
1573 blobmsg_close_table(&b
, vht_cap_mcs_set
);
1574 blobmsg_close_table(&b
, vht_cap
);
1578 if (!hapd
->ubus
.notify_response
) {
1579 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);
1580 return WLAN_STATUS_SUCCESS
;
1583 if (ubus_notify_async(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, &ureq
.nreq
))
1584 return WLAN_STATUS_SUCCESS
;
1586 ureq
.nreq
.status_cb
= ubus_event_cb
;
1587 ubus_complete_request(ctx
, &ureq
.nreq
.req
, 100);
1592 return WLAN_STATUS_SUCCESS
;
1595 void hostapd_ubus_notify(struct hostapd_data
*hapd
, const char *type
, const u8
*addr
)
1597 if (!hapd
->ubus
.obj
.has_subscribers
)
1603 blob_buf_init(&b
, 0);
1604 blobmsg_add_macaddr(&b
, "address", addr
);
1606 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);
1609 void hostapd_ubus_notify_beacon_report(
1610 struct hostapd_data
*hapd
, const u8
*addr
, u8 token
, u8 rep_mode
,
1611 struct rrm_measurement_beacon_report
*rep
, size_t len
)
1613 if (!hapd
->ubus
.obj
.has_subscribers
)
1619 blob_buf_init(&b
, 0);
1620 blobmsg_add_macaddr(&b
, "address", addr
);
1621 blobmsg_add_u16(&b
, "op-class", rep
->op_class
);
1622 blobmsg_add_u16(&b
, "channel", rep
->channel
);
1623 blobmsg_add_u64(&b
, "start-time", rep
->start_time
);
1624 blobmsg_add_u16(&b
, "duration", rep
->duration
);
1625 blobmsg_add_u16(&b
, "report-info", rep
->report_info
);
1626 blobmsg_add_u16(&b
, "rcpi", rep
->rcpi
);
1627 blobmsg_add_u16(&b
, "rsni", rep
->rsni
);
1628 blobmsg_add_macaddr(&b
, "bssid", rep
->bssid
);
1629 blobmsg_add_u16(&b
, "antenna-id", rep
->antenna_id
);
1630 blobmsg_add_u16(&b
, "parent-tsf", rep
->parent_tsf
);
1632 ubus_notify(ctx
, &hapd
->ubus
.obj
, "beacon-report", b
.head
, -1);
1635 void hostapd_ubus_notify_radar_detected(struct hostapd_iface
*iface
, int frequency
,
1636 int chan_width
, int cf1
, int cf2
)
1638 struct hostapd_data
*hapd
;
1641 if (!hapd
->ubus
.obj
.has_subscribers
)
1644 blob_buf_init(&b
, 0);
1645 blobmsg_add_u16(&b
, "frequency", frequency
);
1646 blobmsg_add_u16(&b
, "width", chan_width
);
1647 blobmsg_add_u16(&b
, "center1", cf1
);
1648 blobmsg_add_u16(&b
, "center2", cf2
);
1650 for (i
= 0; i
< iface
->num_bss
; i
++) {
1651 hapd
= iface
->bss
[i
];
1652 ubus_notify(ctx
, &hapd
->ubus
.obj
, "radar-detected", b
.head
, -1);