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"
14 #include "common/hw_features_common.h"
16 #include "neighbor_db.h"
17 #include "wps_hostapd.h"
20 #include "ap_drv_ops.h"
25 #include "airtime_policy.h"
26 #include "hw_features.h"
28 static struct ubus_context
*ctx
;
29 static struct blob_buf b
;
32 static inline struct hostapd_data
*get_hapd_from_object(struct ubus_object
*obj
)
34 return container_of(obj
, struct hostapd_data
, ubus
.obj
);
37 struct ubus_banned_client
{
42 static void ubus_reconnect_timeout(void *eloop_data
, void *user_ctx
)
44 if (ubus_reconnect(ctx
, NULL
)) {
45 eloop_register_timeout(1, 0, ubus_reconnect_timeout
, ctx
, NULL
);
52 static void hostapd_ubus_connection_lost(struct ubus_context
*ctx
)
54 uloop_fd_delete(&ctx
->sock
);
55 eloop_register_timeout(1, 0, ubus_reconnect_timeout
, ctx
, NULL
);
58 static bool hostapd_ubus_init(void)
64 ctx
= ubus_connect(NULL
);
68 ctx
->connection_lost
= hostapd_ubus_connection_lost
;
74 static void hostapd_ubus_ref_inc(void)
79 static void hostapd_ubus_ref_dec(void)
88 uloop_fd_delete(&ctx
->sock
);
93 void hostapd_ubus_add_iface(struct hostapd_iface
*iface
)
95 if (!hostapd_ubus_init())
99 void hostapd_ubus_free_iface(struct hostapd_iface
*iface
)
105 static void hostapd_notify_ubus(struct ubus_object
*obj
, char *bssname
, char *event
)
112 if (asprintf(&event_type
, "bss.%s", event
) < 0)
115 blob_buf_init(&b
, 0);
116 blobmsg_add_string(&b
, "name", bssname
);
117 ubus_notify(ctx
, obj
, event_type
, b
.head
, -1);
122 hostapd_bss_del_ban(void *eloop_data
, void *user_ctx
)
124 struct ubus_banned_client
*ban
= eloop_data
;
125 struct hostapd_data
*hapd
= user_ctx
;
127 avl_delete(&hapd
->ubus
.banned
, &ban
->avl
);
132 hostapd_bss_ban_client(struct hostapd_data
*hapd
, u8
*addr
, int time
)
134 struct ubus_banned_client
*ban
;
139 ban
= avl_find_element(&hapd
->ubus
.banned
, addr
, ban
, avl
);
144 ban
= os_zalloc(sizeof(*ban
));
145 memcpy(ban
->addr
, addr
, sizeof(ban
->addr
));
146 ban
->avl
.key
= ban
->addr
;
147 avl_insert(&hapd
->ubus
.banned
, &ban
->avl
);
149 eloop_cancel_timeout(hostapd_bss_del_ban
, ban
, hapd
);
151 hostapd_bss_del_ban(ban
, hapd
);
156 eloop_register_timeout(0, time
* 1000, hostapd_bss_del_ban
, ban
, hapd
);
160 hostapd_bss_reload(struct ubus_context
*ctx
, struct ubus_object
*obj
,
161 struct ubus_request_data
*req
, const char *method
,
162 struct blob_attr
*msg
)
164 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
166 return hostapd_reload_config(hapd
->iface
);
171 hostapd_parse_vht_map_blobmsg(uint16_t map
)
177 for (i
= 0; i
< 8; i
++) {
178 snprintf(label
, 4, "%dss", i
+ 1);
180 val
= (map
& (BIT(1) | BIT(0))) + 7;
181 blobmsg_add_u16(&b
, label
, val
== 10 ? -1 : val
);
187 hostapd_parse_vht_capab_blobmsg(struct ieee80211_vht_capabilities
*vhtc
)
193 static const struct {
197 { "su_beamformee", VHT_CAP_SU_BEAMFORMEE_CAPABLE
},
198 { "mu_beamformee", VHT_CAP_MU_BEAMFORMEE_CAPABLE
},
201 for (i
= 0; i
< ARRAY_SIZE(vht_capas
); i
++)
202 blobmsg_add_u8(&b
, vht_capas
[i
].name
,
203 !!(vhtc
->vht_capabilities_info
& vht_capas
[i
].flag
));
205 supported_mcs
= blobmsg_open_table(&b
, "mcs_map");
208 map
= blobmsg_open_table(&b
, "rx");
209 hostapd_parse_vht_map_blobmsg(le_to_host16(vhtc
->vht_supported_mcs_set
.rx_map
));
210 blobmsg_close_table(&b
, map
);
213 map
= blobmsg_open_table(&b
, "tx");
214 hostapd_parse_vht_map_blobmsg(le_to_host16(vhtc
->vht_supported_mcs_set
.tx_map
));
215 blobmsg_close_table(&b
, map
);
217 blobmsg_close_table(&b
, supported_mcs
);
221 hostapd_parse_capab_blobmsg(struct sta_info
*sta
)
225 v
= blobmsg_open_table(&b
, "capabilities");
227 if (sta
->vht_capabilities
) {
228 r
= blobmsg_open_table(&b
, "vht");
229 hostapd_parse_vht_capab_blobmsg(sta
->vht_capabilities
);
230 blobmsg_close_table(&b
, r
);
233 /* ToDo: Add HT / HE capability parsing */
235 blobmsg_close_table(&b
, v
);
239 hostapd_bss_get_clients(struct ubus_context
*ctx
, struct ubus_object
*obj
,
240 struct ubus_request_data
*req
, const char *method
,
241 struct blob_attr
*msg
)
243 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
244 struct hostap_sta_driver_data sta_driver_data
;
245 struct sta_info
*sta
;
248 static const struct {
252 { "auth", WLAN_STA_AUTH
},
253 { "assoc", WLAN_STA_ASSOC
},
254 { "authorized", WLAN_STA_AUTHORIZED
},
255 { "preauth", WLAN_STA_PREAUTH
},
256 { "wds", WLAN_STA_WDS
},
257 { "wmm", WLAN_STA_WMM
},
258 { "ht", WLAN_STA_HT
},
259 { "vht", WLAN_STA_VHT
},
260 { "he", WLAN_STA_HE
},
261 { "wps", WLAN_STA_WPS
},
262 { "mfp", WLAN_STA_MFP
},
265 blob_buf_init(&b
, 0);
266 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
267 list
= blobmsg_open_table(&b
, "clients");
268 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
272 sprintf(mac_buf
, MACSTR
, MAC2STR(sta
->addr
));
273 c
= blobmsg_open_table(&b
, mac_buf
);
274 for (i
= 0; i
< ARRAY_SIZE(sta_flags
); i
++)
275 blobmsg_add_u8(&b
, sta_flags
[i
].name
,
276 !!(sta
->flags
& sta_flags
[i
].flag
));
279 blobmsg_add_u8(&b
, "mbo", !!(sta
->cell_capa
));
282 r
= blobmsg_open_array(&b
, "rrm");
283 for (i
= 0; i
< ARRAY_SIZE(sta
->rrm_enabled_capa
); i
++)
284 blobmsg_add_u32(&b
, "", sta
->rrm_enabled_capa
[i
]);
285 blobmsg_close_array(&b
, r
);
287 r
= blobmsg_open_array(&b
, "extended_capabilities");
288 /* Check if client advertises extended capabilities */
289 if (sta
->ext_capability
&& sta
->ext_capability
[0] > 0) {
290 for (i
= 0; i
< sta
->ext_capability
[0]; i
++) {
291 blobmsg_add_u32(&b
, "", sta
->ext_capability
[1 + i
]);
294 blobmsg_close_array(&b
, r
);
296 blobmsg_add_u32(&b
, "aid", sta
->aid
);
297 #ifdef CONFIG_TAXONOMY
298 r
= blobmsg_alloc_string_buffer(&b
, "signature", 1024);
299 if (retrieve_sta_taxonomy(hapd
, sta
, r
, 1024) > 0)
300 blobmsg_add_string_buffer(&b
);
303 /* Driver information */
304 if (hostapd_drv_read_sta_data(hapd
, &sta_driver_data
, sta
->addr
) >= 0) {
305 r
= blobmsg_open_table(&b
, "bytes");
306 blobmsg_add_u64(&b
, "rx", sta_driver_data
.rx_bytes
);
307 blobmsg_add_u64(&b
, "tx", sta_driver_data
.tx_bytes
);
308 blobmsg_close_table(&b
, r
);
309 r
= blobmsg_open_table(&b
, "airtime");
310 blobmsg_add_u64(&b
, "rx", sta_driver_data
.rx_airtime
);
311 blobmsg_add_u64(&b
, "tx", sta_driver_data
.tx_airtime
);
312 blobmsg_close_table(&b
, r
);
313 r
= blobmsg_open_table(&b
, "packets");
314 blobmsg_add_u32(&b
, "rx", sta_driver_data
.rx_packets
);
315 blobmsg_add_u32(&b
, "tx", sta_driver_data
.tx_packets
);
316 blobmsg_close_table(&b
, r
);
317 r
= blobmsg_open_table(&b
, "rate");
319 blobmsg_add_u32(&b
, "rx", sta_driver_data
.current_rx_rate
* 100);
320 blobmsg_add_u32(&b
, "tx", sta_driver_data
.current_tx_rate
* 100);
321 blobmsg_close_table(&b
, r
);
322 blobmsg_add_u32(&b
, "signal", sta_driver_data
.signal
);
325 hostapd_parse_capab_blobmsg(sta
);
327 blobmsg_close_table(&b
, c
);
329 blobmsg_close_array(&b
, list
);
330 ubus_send_reply(ctx
, req
, b
.head
);
336 hostapd_bss_get_features(struct ubus_context
*ctx
, struct ubus_object
*obj
,
337 struct ubus_request_data
*req
, const char *method
,
338 struct blob_attr
*msg
)
340 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
342 blob_buf_init(&b
, 0);
343 blobmsg_add_u8(&b
, "ht_supported", ht_supported(hapd
->iface
->hw_features
));
344 blobmsg_add_u8(&b
, "vht_supported", vht_supported(hapd
->iface
->hw_features
));
345 ubus_send_reply(ctx
, req
, b
.head
);
351 hostapd_bss_get_status(struct ubus_context
*ctx
, struct ubus_object
*obj
,
352 struct ubus_request_data
*req
, const char *method
,
353 struct blob_attr
*msg
)
355 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
356 void *airtime_table
, *dfs_table
, *rrm_table
, *wnm_table
;
357 struct os_reltime now
;
358 char ssid
[SSID_MAX_LEN
+ 1];
360 size_t ssid_len
= SSID_MAX_LEN
;
361 u8 channel
= 0, op_class
= 0;
363 if (hapd
->conf
->ssid
.ssid_len
< SSID_MAX_LEN
)
364 ssid_len
= hapd
->conf
->ssid
.ssid_len
;
366 ieee80211_freq_to_channel_ext(hapd
->iface
->freq
,
367 hapd
->iconf
->secondary_channel
,
368 hostapd_get_oper_chwidth(hapd
->iconf
),
369 &op_class
, &channel
);
371 blob_buf_init(&b
, 0);
372 blobmsg_add_string(&b
, "status", hostapd_state_text(hapd
->iface
->state
));
373 blobmsg_printf(&b
, "bssid", MACSTR
, MAC2STR(hapd
->conf
->bssid
));
375 memset(ssid
, 0, SSID_MAX_LEN
+ 1);
376 memcpy(ssid
, hapd
->conf
->ssid
.ssid
, ssid_len
);
377 blobmsg_add_string(&b
, "ssid", ssid
);
379 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
380 blobmsg_add_u32(&b
, "channel", channel
);
381 blobmsg_add_u32(&b
, "op_class", op_class
);
382 blobmsg_add_u32(&b
, "beacon_interval", hapd
->iconf
->beacon_int
);
383 #ifdef CONFIG_IEEE80211AX
384 blobmsg_add_u32(&b
, "bss_color", hapd
->iface
->conf
->he_op
.he_bss_color_disabled
? -1 :
385 hapd
->iface
->conf
->he_op
.he_bss_color
);
387 blobmsg_add_u32(&b
, "bss_color", -1);
390 snprintf(phy_name
, 17, "%s", hapd
->iface
->phy
);
391 blobmsg_add_string(&b
, "phy", phy_name
);
394 rrm_table
= blobmsg_open_table(&b
, "rrm");
395 blobmsg_add_u64(&b
, "neighbor_report_tx", hapd
->openwrt_stats
.rrm
.neighbor_report_tx
);
396 blobmsg_close_table(&b
, rrm_table
);
399 wnm_table
= blobmsg_open_table(&b
, "wnm");
400 blobmsg_add_u64(&b
, "bss_transition_query_rx", hapd
->openwrt_stats
.wnm
.bss_transition_query_rx
);
401 blobmsg_add_u64(&b
, "bss_transition_request_tx", hapd
->openwrt_stats
.wnm
.bss_transition_request_tx
);
402 blobmsg_add_u64(&b
, "bss_transition_response_rx", hapd
->openwrt_stats
.wnm
.bss_transition_response_rx
);
403 blobmsg_close_table(&b
, wnm_table
);
406 airtime_table
= blobmsg_open_table(&b
, "airtime");
407 blobmsg_add_u64(&b
, "time", hapd
->iface
->last_channel_time
);
408 blobmsg_add_u64(&b
, "time_busy", hapd
->iface
->last_channel_time_busy
);
409 blobmsg_add_u16(&b
, "utilization", hapd
->iface
->channel_utilization
);
410 blobmsg_close_table(&b
, airtime_table
);
413 dfs_table
= blobmsg_open_table(&b
, "dfs");
414 blobmsg_add_u32(&b
, "cac_seconds", hapd
->iface
->dfs_cac_ms
/ 1000);
415 blobmsg_add_u8(&b
, "cac_active", !!(hapd
->iface
->cac_started
));
416 os_reltime_age(&hapd
->iface
->dfs_cac_start
, &now
);
417 blobmsg_add_u32(&b
, "cac_seconds_left",
418 hapd
->iface
->cac_started
? hapd
->iface
->dfs_cac_ms
/ 1000 - now
.sec
: 0);
419 blobmsg_close_table(&b
, dfs_table
);
421 ubus_send_reply(ctx
, req
, b
.head
);
431 static const struct blobmsg_policy notify_policy
[__NOTIFY_MAX
] = {
432 [NOTIFY_RESPONSE
] = { "notify_response", BLOBMSG_TYPE_INT32
},
436 hostapd_notify_response(struct ubus_context
*ctx
, struct ubus_object
*obj
,
437 struct ubus_request_data
*req
, const char *method
,
438 struct blob_attr
*msg
)
440 struct blob_attr
*tb
[__NOTIFY_MAX
];
441 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
442 struct wpabuf
*elems
;
446 blobmsg_parse(notify_policy
, __NOTIFY_MAX
, tb
,
447 blob_data(msg
), blob_len(msg
));
449 if (!tb
[NOTIFY_RESPONSE
])
450 return UBUS_STATUS_INVALID_ARGUMENT
;
452 hapd
->ubus
.notify_response
= blobmsg_get_u32(tb
[NOTIFY_RESPONSE
]);
454 return UBUS_STATUS_OK
;
465 static const struct blobmsg_policy del_policy
[__DEL_CLIENT_MAX
] = {
466 [DEL_CLIENT_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
467 [DEL_CLIENT_REASON
] = { "reason", BLOBMSG_TYPE_INT32
},
468 [DEL_CLIENT_DEAUTH
] = { "deauth", BLOBMSG_TYPE_INT8
},
469 [DEL_CLIENT_BAN_TIME
] = { "ban_time", BLOBMSG_TYPE_INT32
},
473 hostapd_bss_del_client(struct ubus_context
*ctx
, struct ubus_object
*obj
,
474 struct ubus_request_data
*req
, const char *method
,
475 struct blob_attr
*msg
)
477 struct blob_attr
*tb
[__DEL_CLIENT_MAX
];
478 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
479 struct sta_info
*sta
;
484 blobmsg_parse(del_policy
, __DEL_CLIENT_MAX
, tb
, blob_data(msg
), blob_len(msg
));
486 if (!tb
[DEL_CLIENT_ADDR
])
487 return UBUS_STATUS_INVALID_ARGUMENT
;
489 if (hwaddr_aton(blobmsg_data(tb
[DEL_CLIENT_ADDR
]), addr
))
490 return UBUS_STATUS_INVALID_ARGUMENT
;
492 if (tb
[DEL_CLIENT_REASON
])
493 reason
= blobmsg_get_u32(tb
[DEL_CLIENT_REASON
]);
495 if (tb
[DEL_CLIENT_DEAUTH
])
496 deauth
= blobmsg_get_bool(tb
[DEL_CLIENT_DEAUTH
]);
498 sta
= ap_get_sta(hapd
, addr
);
501 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
502 ap_sta_deauthenticate(hapd
, sta
, reason
);
504 hostapd_drv_sta_disassoc(hapd
, addr
, reason
);
505 ap_sta_disassociate(hapd
, sta
, reason
);
509 if (tb
[DEL_CLIENT_BAN_TIME
])
510 hostapd_bss_ban_client(hapd
, addr
, blobmsg_get_u32(tb
[DEL_CLIENT_BAN_TIME
]));
516 blobmsg_add_macaddr(struct blob_buf
*buf
, const char *name
, const u8
*addr
)
520 s
= blobmsg_alloc_string_buffer(buf
, name
, 20);
521 sprintf(s
, MACSTR
, MAC2STR(addr
));
522 blobmsg_add_string_buffer(buf
);
526 hostapd_bss_list_bans(struct ubus_context
*ctx
, struct ubus_object
*obj
,
527 struct ubus_request_data
*req
, const char *method
,
528 struct blob_attr
*msg
)
530 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
531 struct ubus_banned_client
*ban
;
534 blob_buf_init(&b
, 0);
535 c
= blobmsg_open_array(&b
, "clients");
536 avl_for_each_element(&hapd
->ubus
.banned
, ban
, avl
)
537 blobmsg_add_macaddr(&b
, NULL
, ban
->addr
);
538 blobmsg_close_array(&b
, c
);
539 ubus_send_reply(ctx
, req
, b
.head
);
546 hostapd_bss_wps_start(struct ubus_context
*ctx
, struct ubus_object
*obj
,
547 struct ubus_request_data
*req
, const char *method
,
548 struct blob_attr
*msg
)
551 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
553 rc
= hostapd_wps_button_pushed(hapd
, NULL
);
556 return UBUS_STATUS_NOT_SUPPORTED
;
562 static const char * pbc_status_enum_str(enum pbc_status status
)
565 case WPS_PBC_STATUS_DISABLE
:
567 case WPS_PBC_STATUS_ACTIVE
:
569 case WPS_PBC_STATUS_TIMEOUT
:
571 case WPS_PBC_STATUS_OVERLAP
:
579 hostapd_bss_wps_status(struct ubus_context
*ctx
, struct ubus_object
*obj
,
580 struct ubus_request_data
*req
, const char *method
,
581 struct blob_attr
*msg
)
584 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
586 blob_buf_init(&b
, 0);
588 blobmsg_add_string(&b
, "pbc_status", pbc_status_enum_str(hapd
->wps_stats
.pbc_status
));
589 blobmsg_add_string(&b
, "last_wps_result",
590 (hapd
->wps_stats
.status
== WPS_STATUS_SUCCESS
?
592 (hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
?
593 "Failed" : "None")));
595 /* If status == Failure - Add possible Reasons */
596 if(hapd
->wps_stats
.status
== WPS_STATUS_FAILURE
&&
597 hapd
->wps_stats
.failure_reason
> 0)
598 blobmsg_add_string(&b
, "reason", wps_ei_str(hapd
->wps_stats
.failure_reason
));
600 if (hapd
->wps_stats
.status
)
601 blobmsg_printf(&b
, "peer_address", MACSTR
, MAC2STR(hapd
->wps_stats
.peer_addr
));
603 ubus_send_reply(ctx
, req
, b
.head
);
609 hostapd_bss_wps_cancel(struct ubus_context
*ctx
, struct ubus_object
*obj
,
610 struct ubus_request_data
*req
, const char *method
,
611 struct blob_attr
*msg
)
614 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
616 rc
= hostapd_wps_cancel(hapd
);
619 return UBUS_STATUS_NOT_SUPPORTED
;
623 #endif /* CONFIG_WPS */
626 hostapd_bss_update_beacon(struct ubus_context
*ctx
, struct ubus_object
*obj
,
627 struct ubus_request_data
*req
, const char *method
,
628 struct blob_attr
*msg
)
631 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
633 rc
= ieee802_11_set_beacon(hapd
);
636 return UBUS_STATUS_NOT_SUPPORTED
;
653 CSA_SEC_CHANNEL_OFFSET
,
662 static const struct blobmsg_policy csa_policy
[__CSA_MAX
] = {
663 [CSA_FREQ
] = { "freq", BLOBMSG_TYPE_INT32
},
664 [CSA_BCN_COUNT
] = { "bcn_count", BLOBMSG_TYPE_INT32
},
665 [CSA_CENTER_FREQ1
] = { "center_freq1", BLOBMSG_TYPE_INT32
},
666 [CSA_CENTER_FREQ2
] = { "center_freq2", BLOBMSG_TYPE_INT32
},
667 [CSA_BANDWIDTH
] = { "bandwidth", BLOBMSG_TYPE_INT32
},
668 [CSA_SEC_CHANNEL_OFFSET
] = { "sec_channel_offset", BLOBMSG_TYPE_INT32
},
669 [CSA_HT
] = { "ht", BLOBMSG_TYPE_BOOL
},
670 [CSA_VHT
] = { "vht", BLOBMSG_TYPE_BOOL
},
671 [CSA_HE
] = { "he", BLOBMSG_TYPE_BOOL
},
672 [CSA_BLOCK_TX
] = { "block_tx", BLOBMSG_TYPE_BOOL
},
673 [CSA_FORCE
] = { "force", BLOBMSG_TYPE_BOOL
},
677 static void switch_chan_fallback_cb(void *eloop_data
, void *user_ctx
)
679 struct hostapd_iface
*iface
= eloop_data
;
680 struct hostapd_freq_params
*freq_params
= user_ctx
;
682 hostapd_switch_channel_fallback(iface
, freq_params
);
687 hostapd_switch_chan(struct ubus_context
*ctx
, struct ubus_object
*obj
,
688 struct ubus_request_data
*req
, const char *method
,
689 struct blob_attr
*msg
)
691 struct blob_attr
*tb
[__CSA_MAX
];
692 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
693 struct hostapd_config
*iconf
= hapd
->iface
->conf
;
694 struct hostapd_freq_params
*freq_params
;
695 struct hostapd_hw_modes
*mode
= hapd
->iface
->current_mode
;
696 struct csa_settings css
= {
698 .ht_enabled
= iconf
->ieee80211n
,
699 .vht_enabled
= iconf
->ieee80211ac
,
700 .he_enabled
= iconf
->ieee80211ax
,
701 .sec_channel_offset
= iconf
->secondary_channel
,
704 u8 chwidth
= hostapd_get_oper_chwidth(iconf
);
705 u8 seg0
= 0, seg1
= 0;
706 int ret
= UBUS_STATUS_OK
;
709 blobmsg_parse(csa_policy
, __CSA_MAX
, tb
, blob_data(msg
), blob_len(msg
));
712 return UBUS_STATUS_INVALID_ARGUMENT
;
714 switch (iconf
->vht_oper_chwidth
) {
715 case CHANWIDTH_USE_HT
:
716 if (iconf
->secondary_channel
)
717 css
.freq_params
.bandwidth
= 40;
719 css
.freq_params
.bandwidth
= 20;
721 case CHANWIDTH_160MHZ
:
722 css
.freq_params
.bandwidth
= 160;
725 css
.freq_params
.bandwidth
= 80;
729 css
.freq_params
.freq
= blobmsg_get_u32(tb
[CSA_FREQ
]);
731 #define SET_CSA_SETTING(name, field, type) \
734 css.field = blobmsg_get_ ## type(tb[name]); \
737 SET_CSA_SETTING(CSA_BCN_COUNT
, cs_count
, u32
);
738 SET_CSA_SETTING(CSA_CENTER_FREQ1
, freq_params
.center_freq1
, u32
);
739 SET_CSA_SETTING(CSA_CENTER_FREQ2
, freq_params
.center_freq2
, u32
);
740 SET_CSA_SETTING(CSA_BANDWIDTH
, freq_params
.bandwidth
, u32
);
741 SET_CSA_SETTING(CSA_SEC_CHANNEL_OFFSET
, freq_params
.sec_channel_offset
, u32
);
742 SET_CSA_SETTING(CSA_HT
, freq_params
.ht_enabled
, bool);
743 SET_CSA_SETTING(CSA_VHT
, freq_params
.vht_enabled
, bool);
744 SET_CSA_SETTING(CSA_HE
, freq_params
.he_enabled
, bool);
745 SET_CSA_SETTING(CSA_BLOCK_TX
, block_tx
, bool);
747 css
.freq_params
.channel
= hostapd_hw_get_channel(hapd
, css
.freq_params
.freq
);
748 if (!css
.freq_params
.channel
)
749 return UBUS_STATUS_NOT_SUPPORTED
;
751 switch (css
.freq_params
.bandwidth
) {
753 chwidth
= CHANWIDTH_160MHZ
;
756 chwidth
= css
.freq_params
.center_freq2
? CHANWIDTH_80P80MHZ
: CHANWIDTH_80MHZ
;
759 chwidth
= CHANWIDTH_USE_HT
;
763 hostapd_set_freq_params(&css
.freq_params
, iconf
->hw_mode
,
764 css
.freq_params
.freq
,
765 css
.freq_params
.channel
, iconf
->enable_edmg
,
767 css
.freq_params
.ht_enabled
,
768 css
.freq_params
.vht_enabled
,
769 css
.freq_params
.he_enabled
,
770 css
.freq_params
.eht_enabled
,
771 css
.freq_params
.sec_channel_offset
,
774 mode
? &mode
->he_capab
[IEEE80211_MODE_AP
] :
776 mode
? &mode
->eht_capab
[IEEE80211_MODE_AP
] :
778 hostapd_get_punct_bitmap(hapd
));
780 for (i
= 0; i
< hapd
->iface
->num_bss
; i
++) {
781 struct hostapd_data
*bss
= hapd
->iface
->bss
[i
];
783 if (hostapd_switch_channel(bss
, &css
) != 0)
784 ret
= UBUS_STATUS_NOT_SUPPORTED
;
787 if (!ret
|| !tb
[CSA_FORCE
] || !blobmsg_get_bool(tb
[CSA_FORCE
]))
790 freq_params
= malloc(sizeof(*freq_params
));
791 memcpy(freq_params
, &css
.freq_params
, sizeof(*freq_params
));
792 eloop_register_timeout(0, 1, switch_chan_fallback_cb
,
793 hapd
->iface
, freq_params
);
796 #undef SET_CSA_SETTING
802 __VENDOR_ELEMENTS_MAX
805 static const struct blobmsg_policy ve_policy
[__VENDOR_ELEMENTS_MAX
] = {
806 /* vendor elements are provided as hex-string */
807 [VENDOR_ELEMENTS
] = { "vendor_elements", BLOBMSG_TYPE_STRING
},
811 hostapd_vendor_elements(struct ubus_context
*ctx
, struct ubus_object
*obj
,
812 struct ubus_request_data
*req
, const char *method
,
813 struct blob_attr
*msg
)
815 struct blob_attr
*tb
[__VENDOR_ELEMENTS_MAX
];
816 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
817 struct hostapd_bss_config
*bss
= hapd
->conf
;
818 struct wpabuf
*elems
;
822 blobmsg_parse(ve_policy
, __VENDOR_ELEMENTS_MAX
, tb
,
823 blob_data(msg
), blob_len(msg
));
825 if (!tb
[VENDOR_ELEMENTS
])
826 return UBUS_STATUS_INVALID_ARGUMENT
;
828 pos
= blobmsg_data(tb
[VENDOR_ELEMENTS
]);
829 len
= os_strlen(pos
);
831 return UBUS_STATUS_INVALID_ARGUMENT
;
835 wpabuf_free(bss
->vendor_elements
);
836 bss
->vendor_elements
= NULL
;
840 elems
= wpabuf_alloc(len
);
844 if (hexstr2bin(pos
, wpabuf_put(elems
, len
), len
)) {
846 return UBUS_STATUS_INVALID_ARGUMENT
;
849 wpabuf_free(bss
->vendor_elements
);
850 bss
->vendor_elements
= elems
;
852 /* update beacons if vendor elements were set successfully */
853 if (ieee802_11_update_beacons(hapd
->iface
) != 0)
854 return UBUS_STATUS_NOT_SUPPORTED
;
855 return UBUS_STATUS_OK
;
859 hostapd_rrm_print_nr(struct hostapd_neighbor_entry
*nr
)
865 blobmsg_printf(&b
, "", MACSTR
, MAC2STR(nr
->bssid
));
867 str
= blobmsg_alloc_string_buffer(&b
, "", nr
->ssid
.ssid_len
+ 1);
868 memcpy(str
, nr
->ssid
.ssid
, nr
->ssid
.ssid_len
);
869 str
[nr
->ssid
.ssid_len
] = 0;
870 blobmsg_add_string_buffer(&b
);
872 len
= wpabuf_len(nr
->nr
);
873 str
= blobmsg_alloc_string_buffer(&b
, "", 2 * len
+ 1);
874 wpa_snprintf_hex(str
, 2 * len
+ 1, wpabuf_head_u8(nr
->nr
), len
);
875 blobmsg_add_string_buffer(&b
);
879 BSS_MGMT_EN_NEIGHBOR
,
881 BSS_MGMT_EN_LINK_MEASUREMENT
,
883 BSS_MGMT_EN_BSS_TRANSITION
,
889 __hostapd_bss_mgmt_enable_f(struct hostapd_data
*hapd
, int flag
)
891 struct hostapd_bss_config
*bss
= hapd
->conf
;
895 case BSS_MGMT_EN_NEIGHBOR
:
896 if (bss
->radio_measurements
[0] &
897 WLAN_RRM_CAPS_NEIGHBOR_REPORT
)
900 bss
->radio_measurements
[0] |=
901 WLAN_RRM_CAPS_NEIGHBOR_REPORT
;
902 hostapd_neighbor_set_own_report(hapd
);
904 case BSS_MGMT_EN_BEACON
:
905 flags
= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE
|
906 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE
|
907 WLAN_RRM_CAPS_BEACON_REPORT_TABLE
;
909 if (bss
->radio_measurements
[0] & flags
== flags
)
912 bss
->radio_measurements
[0] |= (u8
) flags
;
914 case BSS_MGMT_EN_LINK_MEASUREMENT
:
915 flags
= WLAN_RRM_CAPS_LINK_MEASUREMENT
;
917 if (bss
->radio_measurements
[0] & flags
== flags
)
920 bss
->radio_measurements
[0] |= (u8
) flags
;
923 case BSS_MGMT_EN_BSS_TRANSITION
:
924 if (bss
->bss_transition
)
927 bss
->bss_transition
= 1;
934 __hostapd_bss_mgmt_enable(struct hostapd_data
*hapd
, uint32_t flags
)
939 for (i
= 0; i
< __BSS_MGMT_EN_MAX
; i
++) {
940 if (!(flags
& (1 << i
)))
943 update
|= __hostapd_bss_mgmt_enable_f(hapd
, i
);
947 ieee802_11_update_beacons(hapd
->iface
);
951 static const struct blobmsg_policy bss_mgmt_enable_policy
[__BSS_MGMT_EN_MAX
] = {
952 [BSS_MGMT_EN_NEIGHBOR
] = { "neighbor_report", BLOBMSG_TYPE_BOOL
},
953 [BSS_MGMT_EN_BEACON
] = { "beacon_report", BLOBMSG_TYPE_BOOL
},
954 [BSS_MGMT_EN_LINK_MEASUREMENT
] = { "link_measurement", BLOBMSG_TYPE_BOOL
},
956 [BSS_MGMT_EN_BSS_TRANSITION
] = { "bss_transition", BLOBMSG_TYPE_BOOL
},
961 hostapd_bss_mgmt_enable(struct ubus_context
*ctx
, struct ubus_object
*obj
,
962 struct ubus_request_data
*req
, const char *method
,
963 struct blob_attr
*msg
)
966 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
967 struct blob_attr
*tb
[__BSS_MGMT_EN_MAX
];
968 struct blob_attr
*cur
;
971 bool neigh
= false, beacon
= false;
973 blobmsg_parse(bss_mgmt_enable_policy
, __BSS_MGMT_EN_MAX
, tb
, blob_data(msg
), blob_len(msg
));
975 for (i
= 0; i
< ARRAY_SIZE(tb
); i
++) {
976 if (!tb
[i
] || !blobmsg_get_bool(tb
[i
]))
982 __hostapd_bss_mgmt_enable(hapd
, flags
);
989 hostapd_rrm_nr_enable(struct hostapd_data
*hapd
)
991 __hostapd_bss_mgmt_enable(hapd
, 1 << BSS_MGMT_EN_NEIGHBOR
);
995 hostapd_rrm_nr_get_own(struct ubus_context
*ctx
, struct ubus_object
*obj
,
996 struct ubus_request_data
*req
, const char *method
,
997 struct blob_attr
*msg
)
999 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
1000 struct hostapd_neighbor_entry
*nr
;
1003 hostapd_rrm_nr_enable(hapd
);
1005 nr
= hostapd_neighbor_get(hapd
, hapd
->own_addr
, NULL
);
1007 return UBUS_STATUS_NOT_FOUND
;
1009 blob_buf_init(&b
, 0);
1011 c
= blobmsg_open_array(&b
, "value");
1012 hostapd_rrm_print_nr(nr
);
1013 blobmsg_close_array(&b
, c
);
1015 ubus_send_reply(ctx
, req
, b
.head
);
1021 hostapd_rrm_nr_list(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1022 struct ubus_request_data
*req
, const char *method
,
1023 struct blob_attr
*msg
)
1025 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
1026 struct hostapd_neighbor_entry
*nr
;
1029 hostapd_rrm_nr_enable(hapd
);
1030 blob_buf_init(&b
, 0);
1032 c
= blobmsg_open_array(&b
, "list");
1033 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
1036 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
1039 cur
= blobmsg_open_array(&b
, NULL
);
1040 hostapd_rrm_print_nr(nr
);
1041 blobmsg_close_array(&b
, cur
);
1043 blobmsg_close_array(&b
, c
);
1045 ubus_send_reply(ctx
, req
, b
.head
);
1055 static const struct blobmsg_policy nr_set_policy
[__NR_SET_LIST_MAX
] = {
1056 [NR_SET_LIST
] = { "list", BLOBMSG_TYPE_ARRAY
},
1061 hostapd_rrm_nr_clear(struct hostapd_data
*hapd
)
1063 struct hostapd_neighbor_entry
*nr
;
1066 dl_list_for_each(nr
, &hapd
->nr_db
, struct hostapd_neighbor_entry
, list
) {
1067 if (!memcmp(nr
->bssid
, hapd
->own_addr
, ETH_ALEN
))
1070 hostapd_neighbor_remove(hapd
, nr
->bssid
, &nr
->ssid
);
1076 hostapd_rrm_nr_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1077 struct ubus_request_data
*req
, const char *method
,
1078 struct blob_attr
*msg
)
1080 static const struct blobmsg_policy nr_e_policy
[] = {
1081 { .type
= BLOBMSG_TYPE_STRING
},
1082 { .type
= BLOBMSG_TYPE_STRING
},
1083 { .type
= BLOBMSG_TYPE_STRING
},
1085 struct hostapd_data
*hapd
= get_hapd_from_object(obj
);
1086 struct blob_attr
*tb_l
[__NR_SET_LIST_MAX
];
1087 struct blob_attr
*tb
[ARRAY_SIZE(nr_e_policy
)];
1088 struct blob_attr
*cur
;
1091 hostapd_rrm_nr_enable(hapd
);
1093 blobmsg_parse(nr_set_policy
, __NR_SET_LIST_MAX
, tb_l
, blob_data(msg
), blob_len(msg
));
1094 if (!tb_l
[NR_SET_LIST
])
1095 return UBUS_STATUS_INVALID_ARGUMENT
;
1097 hostapd_rrm_nr_clear(hapd
);
1098 blobmsg_for_each_attr(cur
, tb_l
[NR_SET_LIST
], rem
) {
1099 struct wpa_ssid_value ssid
;
1100 struct wpabuf
*data
;
1104 blobmsg_parse_array(nr_e_policy
, ARRAY_SIZE(nr_e_policy
), tb
, blobmsg_data(cur
), blobmsg_data_len(cur
));
1105 if (!tb
[0] || !tb
[1] || !tb
[2])
1108 /* Neighbor Report binary */
1109 nr_s
= blobmsg_get_string(tb
[2]);
1110 data
= wpabuf_parse_bin(nr_s
);
1115 s
= blobmsg_get_string(tb
[0]);
1116 if (strlen(s
) == 0) {
1117 /* Copy BSSID from neighbor report */
1118 if (hwaddr_compact_aton(nr_s
, bssid
))
1120 } else if (hwaddr_aton(s
, bssid
)) {
1125 s
= blobmsg_get_string(tb
[1]);
1126 if (strlen(s
) == 0) {
1127 /* Copy SSID from hostapd BSS conf */
1128 memcpy(&ssid
, &hapd
->conf
->ssid
, sizeof(ssid
));
1130 ssid
.ssid_len
= strlen(s
);
1131 if (ssid
.ssid_len
> sizeof(ssid
.ssid
))
1134 memcpy(&ssid
, s
, ssid
.ssid_len
);
1137 hostapd_neighbor_set(hapd
, bssid
, &ssid
, data
, NULL
, NULL
, 0, 0);
1142 return UBUS_STATUS_INVALID_ARGUMENT
;
1151 BEACON_REQ_OP_CLASS
,
1153 BEACON_REQ_DURATION
,
1159 static const struct blobmsg_policy beacon_req_policy
[__BEACON_REQ_MAX
] = {
1160 [BEACON_REQ_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
1161 [BEACON_REQ_OP_CLASS
] { "op_class", BLOBMSG_TYPE_INT32
},
1162 [BEACON_REQ_CHANNEL
] { "channel", BLOBMSG_TYPE_INT32
},
1163 [BEACON_REQ_DURATION
] { "duration", BLOBMSG_TYPE_INT32
},
1164 [BEACON_REQ_MODE
] { "mode", BLOBMSG_TYPE_INT32
},
1165 [BEACON_REQ_BSSID
] { "bssid", BLOBMSG_TYPE_STRING
},
1166 [BEACON_REQ_SSID
] { "ssid", BLOBMSG_TYPE_STRING
},
1170 hostapd_rrm_beacon_req(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1171 struct ubus_request_data
*ureq
, const char *method
,
1172 struct blob_attr
*msg
)
1174 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1175 struct blob_attr
*tb
[__BEACON_REQ_MAX
];
1176 struct blob_attr
*cur
;
1178 u8 bssid
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1183 blobmsg_parse(beacon_req_policy
, __BEACON_REQ_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1185 if (!tb
[BEACON_REQ_ADDR
] || !tb
[BEACON_REQ_MODE
] || !tb
[BEACON_REQ_DURATION
] ||
1186 !tb
[BEACON_REQ_OP_CLASS
] || !tb
[BEACON_REQ_CHANNEL
])
1187 return UBUS_STATUS_INVALID_ARGUMENT
;
1189 if (tb
[BEACON_REQ_SSID
])
1190 buf_len
+= blobmsg_data_len(tb
[BEACON_REQ_SSID
]) + 2 - 1;
1192 mode
= blobmsg_get_u32(tb
[BEACON_REQ_MODE
]);
1193 if (hwaddr_aton(blobmsg_data(tb
[BEACON_REQ_ADDR
]), addr
))
1194 return UBUS_STATUS_INVALID_ARGUMENT
;
1196 if (tb
[BEACON_REQ_BSSID
] &&
1197 hwaddr_aton(blobmsg_data(tb
[BEACON_REQ_BSSID
]), bssid
))
1198 return UBUS_STATUS_INVALID_ARGUMENT
;
1200 req
= wpabuf_alloc(buf_len
);
1202 return UBUS_STATUS_UNKNOWN_ERROR
;
1204 /* 1: regulatory class */
1205 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_OP_CLASS
]));
1207 /* 2: channel number */
1208 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_CHANNEL
]));
1210 /* 3-4: randomization interval */
1211 wpabuf_put_le16(req
, 0);
1214 wpabuf_put_le16(req
, blobmsg_get_u32(tb
[BEACON_REQ_DURATION
]));
1217 wpabuf_put_u8(req
, blobmsg_get_u32(tb
[BEACON_REQ_MODE
]));
1220 wpabuf_put_data(req
, bssid
, ETH_ALEN
);
1222 if ((cur
= tb
[BEACON_REQ_SSID
]) != NULL
) {
1223 wpabuf_put_u8(req
, WLAN_EID_SSID
);
1224 wpabuf_put_u8(req
, blobmsg_data_len(cur
) - 1);
1225 wpabuf_put_data(req
, blobmsg_data(cur
), blobmsg_data_len(cur
) - 1);
1228 ret
= hostapd_send_beacon_req(hapd
, addr
, 0, req
);
1237 LM_REQ_TX_POWER_USED
,
1238 LM_REQ_TX_POWER_MAX
,
1242 static const struct blobmsg_policy lm_req_policy
[__LM_REQ_MAX
] = {
1243 [LM_REQ_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
1244 [LM_REQ_TX_POWER_USED
] = { "tx-power-used", BLOBMSG_TYPE_INT32
},
1245 [LM_REQ_TX_POWER_MAX
] = { "tx-power-max", BLOBMSG_TYPE_INT32
},
1249 hostapd_rrm_lm_req(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1250 struct ubus_request_data
*ureq
, const char *method
,
1251 struct blob_attr
*msg
)
1253 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1254 struct blob_attr
*tb
[__LM_REQ_MAX
];
1258 int8_t txp_used
, txp_max
;
1263 blobmsg_parse(lm_req_policy
, __LM_REQ_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1265 if (!tb
[LM_REQ_ADDR
])
1266 return UBUS_STATUS_INVALID_ARGUMENT
;
1268 if (tb
[LM_REQ_TX_POWER_USED
])
1269 txp_used
= (int8_t) blobmsg_get_u32(tb
[LM_REQ_TX_POWER_USED
]);
1271 if (tb
[LM_REQ_TX_POWER_MAX
])
1272 txp_max
= (int8_t) blobmsg_get_u32(tb
[LM_REQ_TX_POWER_MAX
]);
1274 if (hwaddr_aton(blobmsg_data(tb
[LM_REQ_ADDR
]), addr
))
1275 return UBUS_STATUS_INVALID_ARGUMENT
;
1277 buf
= wpabuf_alloc(5);
1279 return UBUS_STATUS_UNKNOWN_ERROR
;
1281 wpabuf_put_u8(buf
, WLAN_ACTION_RADIO_MEASUREMENT
);
1282 wpabuf_put_u8(buf
, WLAN_RRM_LINK_MEASUREMENT_REQUEST
);
1283 wpabuf_put_u8(buf
, 1);
1285 wpabuf_put_u8(buf
, txp_used
);
1287 wpabuf_put_u8(buf
, txp_max
);
1289 ret
= hostapd_drv_send_action(hapd
, hapd
->iface
->freq
, 0, addr
,
1290 wpabuf_head(buf
), wpabuf_len(buf
));
1300 void hostapd_ubus_handle_link_measurement(struct hostapd_data
*hapd
, const u8
*data
, size_t len
)
1302 const struct ieee80211_mgmt
*mgmt
= (const struct ieee80211_mgmt
*) data
;
1303 const u8
*pos
, *end
;
1307 token
= mgmt
->u
.action
.u
.rrm
.dialog_token
;
1308 pos
= mgmt
->u
.action
.u
.rrm
.variable
;
1313 if (!hapd
->ubus
.obj
.has_subscribers
)
1316 blob_buf_init(&b
, 0);
1317 blobmsg_add_macaddr(&b
, "address", mgmt
->sa
);
1318 blobmsg_add_u16(&b
, "dialog-token", token
);
1319 blobmsg_add_u16(&b
, "rx-antenna-id", pos
[4]);
1320 blobmsg_add_u16(&b
, "tx-antenna-id", pos
[5]);
1321 blobmsg_add_u16(&b
, "rcpi", pos
[6]);
1322 blobmsg_add_u16(&b
, "rsni", pos
[7]);
1324 ubus_notify(ctx
, &hapd
->ubus
.obj
, "link-measurement-report", b
.head
, -1);
1328 #ifdef CONFIG_WNM_AP
1331 hostapd_bss_tr_send(struct hostapd_data
*hapd
, u8
*addr
, bool disassoc_imminent
, bool abridged
,
1332 u16 disassoc_timer
, u8 validity_period
, u8 dialog_token
,
1333 struct blob_attr
*neighbors
, u8 mbo_reason
, u8 cell_pref
, u8 reassoc_delay
)
1335 struct blob_attr
*cur
;
1336 struct sta_info
*sta
;
1344 sta
= ap_get_sta(hapd
, addr
);
1346 return UBUS_STATUS_NOT_FOUND
;
1351 if (blobmsg_check_array(neighbors
,
1352 BLOBMSG_TYPE_STRING
) < 0)
1353 return UBUS_STATUS_INVALID_ARGUMENT
;
1355 blobmsg_for_each_attr(cur
, neighbors
, rem
) {
1356 int len
= strlen(blobmsg_get_string(cur
));
1359 return UBUS_STATUS_INVALID_ARGUMENT
;
1361 nr_len
+= (len
/ 2) + 2;
1365 nr
= os_zalloc(nr_len
);
1367 return UBUS_STATUS_UNKNOWN_ERROR
;
1371 blobmsg_for_each_attr(cur
, neighbors
, rem
) {
1372 int len
= strlen(blobmsg_get_string(cur
)) / 2;
1374 *nr_cur
++ = WLAN_EID_NEIGHBOR_REPORT
;
1375 *nr_cur
++ = (u8
) len
;
1376 if (hexstr2bin(blobmsg_data(cur
), nr_cur
, len
)) {
1378 return UBUS_STATUS_INVALID_ARGUMENT
;
1386 req_mode
|= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED
;
1389 req_mode
|= WNM_BSS_TM_REQ_ABRIDGED
;
1391 if (disassoc_imminent
)
1392 req_mode
|= WNM_BSS_TM_REQ_DISASSOC_IMMINENT
;
1397 if (mbo_reason
> MBO_TRANSITION_REASON_PREMIUM_AP
)
1398 return UBUS_STATUS_INVALID_ARGUMENT
;
1400 if (cell_pref
!= 0 && cell_pref
!= 1 && cell_pref
!= 255)
1401 return UBUS_STATUS_INVALID_ARGUMENT
;
1403 if (reassoc_delay
> 65535 || (reassoc_delay
&& !disassoc_imminent
))
1404 return UBUS_STATUS_INVALID_ARGUMENT
;
1406 *mbo_pos
++ = MBO_ATTR_ID_TRANSITION_REASON
;
1408 *mbo_pos
++ = mbo_reason
;
1409 *mbo_pos
++ = MBO_ATTR_ID_CELL_DATA_PREF
;
1411 *mbo_pos
++ = cell_pref
;
1413 if (reassoc_delay
) {
1414 *mbo_pos
++ = MBO_ATTR_ID_ASSOC_RETRY_DELAY
;
1416 WPA_PUT_LE16(mbo_pos
, reassoc_delay
);
1420 mbo_len
= mbo_pos
- mbo
;
1423 if (wnm_send_bss_tm_req(hapd
, sta
, req_mode
, disassoc_timer
, validity_period
, NULL
,
1424 dialog_token
, NULL
, nr
, nr_len
, mbo_len
? mbo
: NULL
, mbo_len
))
1425 return UBUS_STATUS_UNKNOWN_ERROR
;
1434 BSS_TR_VALID_PERIOD
,
1437 BSS_TR_DIALOG_TOKEN
,
1441 BSS_TR_REASSOC_DELAY
,
1443 __BSS_TR_DISASSOC_MAX
1446 static const struct blobmsg_policy bss_tr_policy
[__BSS_TR_DISASSOC_MAX
] = {
1447 [BSS_TR_ADDR
] = { "addr", BLOBMSG_TYPE_STRING
},
1448 [BSS_TR_DA_IMMINENT
] = { "disassociation_imminent", BLOBMSG_TYPE_BOOL
},
1449 [BSS_TR_DA_TIMER
] = { "disassociation_timer", BLOBMSG_TYPE_INT32
},
1450 [BSS_TR_VALID_PERIOD
] = { "validity_period", BLOBMSG_TYPE_INT32
},
1451 [BSS_TR_NEIGHBORS
] = { "neighbors", BLOBMSG_TYPE_ARRAY
},
1452 [BSS_TR_ABRIDGED
] = { "abridged", BLOBMSG_TYPE_BOOL
},
1453 [BSS_TR_DIALOG_TOKEN
] = { "dialog_token", BLOBMSG_TYPE_INT32
},
1455 [BSS_TR_MBO_REASON
] = { "mbo_reason", BLOBMSG_TYPE_INT32
},
1456 [BSS_TR_CELL_PREF
] = { "cell_pref", BLOBMSG_TYPE_INT32
},
1457 [BSS_TR_REASSOC_DELAY
] = { "reassoc_delay", BLOBMSG_TYPE_INT32
},
1462 hostapd_bss_transition_request(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1463 struct ubus_request_data
*ureq
, const char *method
,
1464 struct blob_attr
*msg
)
1466 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1467 struct blob_attr
*tb
[__BSS_TR_DISASSOC_MAX
];
1468 struct sta_info
*sta
;
1470 u32 valid_period
= 0;
1472 u32 dialog_token
= 1;
1479 blobmsg_parse(bss_tr_policy
, __BSS_TR_DISASSOC_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1481 if (!tb
[BSS_TR_ADDR
])
1482 return UBUS_STATUS_INVALID_ARGUMENT
;
1484 if (hwaddr_aton(blobmsg_data(tb
[BSS_TR_ADDR
]), addr
))
1485 return UBUS_STATUS_INVALID_ARGUMENT
;
1487 if (tb
[BSS_TR_DA_TIMER
])
1488 da_timer
= blobmsg_get_u32(tb
[BSS_TR_DA_TIMER
]);
1490 if (tb
[BSS_TR_VALID_PERIOD
])
1491 valid_period
= blobmsg_get_u32(tb
[BSS_TR_VALID_PERIOD
]);
1493 if (tb
[BSS_TR_DIALOG_TOKEN
])
1494 dialog_token
= blobmsg_get_u32(tb
[BSS_TR_DIALOG_TOKEN
]);
1496 da_imminent
= !!(tb
[BSS_TR_DA_IMMINENT
] && blobmsg_get_bool(tb
[BSS_TR_DA_IMMINENT
]));
1497 abridged
= !!(tb
[BSS_TR_ABRIDGED
] && blobmsg_get_bool(tb
[BSS_TR_ABRIDGED
]));
1500 if (tb
[BSS_TR_MBO_REASON
])
1501 mbo_reason
= blobmsg_get_u32(tb
[BSS_TR_MBO_REASON
]);
1503 if (tb
[BSS_TR_CELL_PREF
])
1504 cell_pref
= blobmsg_get_u32(tb
[BSS_TR_CELL_PREF
]);
1506 if (tb
[BSS_TR_REASSOC_DELAY
])
1507 reassoc_delay
= blobmsg_get_u32(tb
[BSS_TR_REASSOC_DELAY
]);
1510 return hostapd_bss_tr_send(hapd
, addr
, da_imminent
, abridged
, da_timer
, valid_period
,
1511 dialog_token
, tb
[BSS_TR_NEIGHBORS
], mbo_reason
, cell_pref
, reassoc_delay
);
1515 #ifdef CONFIG_AIRTIME_POLICY
1518 UPDATE_AIRTIME_WEIGHT
,
1519 __UPDATE_AIRTIME_MAX
,
1523 static const struct blobmsg_policy airtime_policy
[__UPDATE_AIRTIME_MAX
] = {
1524 [UPDATE_AIRTIME_STA
] = { "sta", BLOBMSG_TYPE_STRING
},
1525 [UPDATE_AIRTIME_WEIGHT
] = { "weight", BLOBMSG_TYPE_INT32
},
1529 hostapd_bss_update_airtime(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1530 struct ubus_request_data
*ureq
, const char *method
,
1531 struct blob_attr
*msg
)
1533 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1534 struct blob_attr
*tb
[__UPDATE_AIRTIME_MAX
];
1535 struct sta_info
*sta
= NULL
;
1539 blobmsg_parse(airtime_policy
, __UPDATE_AIRTIME_MAX
, tb
, blob_data(msg
), blob_len(msg
));
1541 if (!tb
[UPDATE_AIRTIME_WEIGHT
])
1542 return UBUS_STATUS_INVALID_ARGUMENT
;
1544 weight
= blobmsg_get_u32(tb
[UPDATE_AIRTIME_WEIGHT
]);
1546 if (!tb
[UPDATE_AIRTIME_STA
]) {
1548 return UBUS_STATUS_INVALID_ARGUMENT
;
1550 hapd
->conf
->airtime_weight
= weight
;
1554 if (hwaddr_aton(blobmsg_data(tb
[UPDATE_AIRTIME_STA
]), addr
))
1555 return UBUS_STATUS_INVALID_ARGUMENT
;
1557 sta
= ap_get_sta(hapd
, addr
);
1559 return UBUS_STATUS_NOT_FOUND
;
1561 sta
->dyn_airtime_weight
= weight
;
1562 airtime_policy_new_sta(hapd
, sta
);
1568 #ifdef CONFIG_TAXONOMY
1569 static const struct blobmsg_policy addr_policy
[] = {
1570 { "address", BLOBMSG_TYPE_STRING
}
1574 hostapd_add_b64_data(const char *name
, const struct wpabuf
*buf
)
1581 str
= blobmsg_alloc_string_buffer(&b
, name
, B64_ENCODE_LEN(wpabuf_len(buf
)));
1582 b64_encode(wpabuf_head(buf
), wpabuf_len(buf
), str
, B64_ENCODE_LEN(wpabuf_len(buf
)));
1583 blobmsg_add_string_buffer(&b
);
1589 hostapd_bss_get_sta_ies(struct ubus_context
*ctx
, struct ubus_object
*obj
,
1590 struct ubus_request_data
*req
, const char *method
,
1591 struct blob_attr
*msg
)
1593 struct hostapd_data
*hapd
= container_of(obj
, struct hostapd_data
, ubus
.obj
);
1594 struct blob_attr
*tb
;
1595 struct sta_info
*sta
;
1598 blobmsg_parse(addr_policy
, 1, &tb
, blobmsg_data(msg
), blobmsg_len(msg
));
1600 if (!tb
|| hwaddr_aton(blobmsg_data(tb
), addr
))
1601 return UBUS_STATUS_INVALID_ARGUMENT
;
1603 sta
= ap_get_sta(hapd
, addr
);
1604 if (!sta
|| (!sta
->probe_ie_taxonomy
&& !sta
->assoc_ie_taxonomy
))
1605 return UBUS_STATUS_NOT_FOUND
;
1607 blob_buf_init(&b
, 0);
1608 hostapd_add_b64_data("probe_ie", sta
->probe_ie_taxonomy
);
1609 hostapd_add_b64_data("assoc_ie", sta
->assoc_ie_taxonomy
);
1610 ubus_send_reply(ctx
, req
, b
.head
);
1617 static const struct ubus_method bss_methods
[] = {
1618 UBUS_METHOD_NOARG("reload", hostapd_bss_reload
),
1619 UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients
),
1620 #ifdef CONFIG_TAXONOMY
1621 UBUS_METHOD("get_sta_ies", hostapd_bss_get_sta_ies
, addr_policy
),
1623 UBUS_METHOD_NOARG("get_status", hostapd_bss_get_status
),
1624 UBUS_METHOD("del_client", hostapd_bss_del_client
, del_policy
),
1625 #ifdef CONFIG_AIRTIME_POLICY
1626 UBUS_METHOD("update_airtime", hostapd_bss_update_airtime
, airtime_policy
),
1628 UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans
),
1630 UBUS_METHOD_NOARG("wps_start", hostapd_bss_wps_start
),
1631 UBUS_METHOD_NOARG("wps_status", hostapd_bss_wps_status
),
1632 UBUS_METHOD_NOARG("wps_cancel", hostapd_bss_wps_cancel
),
1634 UBUS_METHOD_NOARG("update_beacon", hostapd_bss_update_beacon
),
1635 UBUS_METHOD_NOARG("get_features", hostapd_bss_get_features
),
1637 UBUS_METHOD("switch_chan", hostapd_switch_chan
, csa_policy
),
1639 UBUS_METHOD("set_vendor_elements", hostapd_vendor_elements
, ve_policy
),
1640 UBUS_METHOD("notify_response", hostapd_notify_response
, notify_policy
),
1641 UBUS_METHOD("bss_mgmt_enable", hostapd_bss_mgmt_enable
, bss_mgmt_enable_policy
),
1642 UBUS_METHOD_NOARG("rrm_nr_get_own", hostapd_rrm_nr_get_own
),
1643 UBUS_METHOD_NOARG("rrm_nr_list", hostapd_rrm_nr_list
),
1644 UBUS_METHOD("rrm_nr_set", hostapd_rrm_nr_set
, nr_set_policy
),
1645 UBUS_METHOD("rrm_beacon_req", hostapd_rrm_beacon_req
, beacon_req_policy
),
1646 UBUS_METHOD("link_measurement_req", hostapd_rrm_lm_req
, lm_req_policy
),
1647 #ifdef CONFIG_WNM_AP
1648 UBUS_METHOD("bss_transition_request", hostapd_bss_transition_request
, bss_tr_policy
),
1652 static struct ubus_object_type bss_object_type
=
1653 UBUS_OBJECT_TYPE("hostapd_bss", bss_methods
);
1655 static int avl_compare_macaddr(const void *k1
, const void *k2
, void *ptr
)
1657 return memcmp(k1
, k2
, ETH_ALEN
);
1660 void hostapd_ubus_add_bss(struct hostapd_data
*hapd
)
1662 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
1667 if (hapd
->conf
->mesh
& MESH_ENABLED
)
1671 if (!hostapd_ubus_init())
1674 if (asprintf(&name
, "hostapd.%s", hapd
->conf
->iface
) < 0)
1677 avl_init(&hapd
->ubus
.banned
, avl_compare_macaddr
, false, NULL
);
1679 obj
->type
= &bss_object_type
;
1680 obj
->methods
= bss_object_type
.methods
;
1681 obj
->n_methods
= bss_object_type
.n_methods
;
1682 ret
= ubus_add_object(ctx
, obj
);
1683 hostapd_ubus_ref_inc();
1686 void hostapd_ubus_free_bss(struct hostapd_data
*hapd
)
1688 struct ubus_object
*obj
= &hapd
->ubus
.obj
;
1689 char *name
= (char *) obj
->name
;
1692 if (hapd
->conf
->mesh
& MESH_ENABLED
)
1700 ubus_remove_object(ctx
, obj
);
1701 hostapd_ubus_ref_dec();
1708 hostapd_ubus_vlan_action(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
,
1711 struct vlan_description
*desc
= &vlan
->vlan_desc
;
1715 if (!hapd
->ubus
.obj
.has_subscribers
)
1718 blob_buf_init(&b
, 0);
1719 blobmsg_add_string(&b
, "ifname", vlan
->ifname
);
1720 blobmsg_add_string(&b
, "bridge", vlan
->bridge
);
1721 blobmsg_add_u32(&b
, "vlan_id", vlan
->vlan_id
);
1723 if (desc
->notempty
) {
1724 blobmsg_add_u32(&b
, "untagged", desc
->untagged
);
1725 c
= blobmsg_open_array(&b
, "tagged");
1726 for (i
= 0; i
< ARRAY_SIZE(desc
->tagged
) && desc
->tagged
[i
]; i
++)
1727 blobmsg_add_u32(&b
, "", desc
->tagged
[i
]);
1728 blobmsg_close_array(&b
, c
);
1731 ubus_notify(ctx
, &hapd
->ubus
.obj
, action
, b
.head
, -1);
1734 void hostapd_ubus_add_vlan(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
)
1736 hostapd_ubus_vlan_action(hapd
, vlan
, "vlan_add");
1739 void hostapd_ubus_remove_vlan(struct hostapd_data
*hapd
, struct hostapd_vlan
*vlan
)
1741 hostapd_ubus_vlan_action(hapd
, vlan
, "vlan_remove");
1744 struct ubus_event_req
{
1745 struct ubus_notify_request nreq
;
1750 ubus_event_cb(struct ubus_notify_request
*req
, int idx
, int ret
)
1752 struct ubus_event_req
*ureq
= container_of(req
, struct ubus_event_req
, nreq
);
1757 int hostapd_ubus_handle_event(struct hostapd_data
*hapd
, struct hostapd_ubus_request
*req
)
1759 struct ubus_banned_client
*ban
;
1760 const char *types
[HOSTAPD_UBUS_TYPE_MAX
] = {
1761 [HOSTAPD_UBUS_PROBE_REQ
] = "probe",
1762 [HOSTAPD_UBUS_AUTH_REQ
] = "auth",
1763 [HOSTAPD_UBUS_ASSOC_REQ
] = "assoc",
1765 const char *type
= "mgmt";
1766 struct ubus_event_req ureq
= {};
1769 if (req
->mgmt_frame
)
1770 addr
= req
->mgmt_frame
->sa
;
1774 ban
= avl_find_element(&hapd
->ubus
.banned
, addr
, ban
, avl
);
1776 return WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1778 if (!hapd
->ubus
.obj
.has_subscribers
)
1779 return WLAN_STATUS_SUCCESS
;
1781 if (req
->type
< ARRAY_SIZE(types
))
1782 type
= types
[req
->type
];
1784 blob_buf_init(&b
, 0);
1785 blobmsg_add_macaddr(&b
, "address", addr
);
1786 if (req
->mgmt_frame
)
1787 blobmsg_add_macaddr(&b
, "target", req
->mgmt_frame
->da
);
1788 if (req
->ssi_signal
)
1789 blobmsg_add_u32(&b
, "signal", req
->ssi_signal
);
1790 blobmsg_add_u32(&b
, "freq", hapd
->iface
->freq
);
1793 if(req
->elems
->ht_capabilities
)
1795 struct ieee80211_ht_capabilities
*ht_capabilities
;
1796 void *ht_cap
, *ht_cap_mcs_set
, *mcs_set
;
1799 ht_capabilities
= (struct ieee80211_ht_capabilities
*) req
->elems
->ht_capabilities
;
1800 ht_cap
= blobmsg_open_table(&b
, "ht_capabilities");
1801 blobmsg_add_u16(&b
, "ht_capabilities_info", ht_capabilities
->ht_capabilities_info
);
1802 ht_cap_mcs_set
= blobmsg_open_table(&b
, "supported_mcs_set");
1803 blobmsg_add_u16(&b
, "a_mpdu_params", ht_capabilities
->a_mpdu_params
);
1804 blobmsg_add_u16(&b
, "ht_extended_capabilities", ht_capabilities
->ht_extended_capabilities
);
1805 blobmsg_add_u32(&b
, "tx_bf_capability_info", ht_capabilities
->tx_bf_capability_info
);
1806 blobmsg_add_u16(&b
, "asel_capabilities", ht_capabilities
->asel_capabilities
);
1807 mcs_set
= blobmsg_open_array(&b
, "supported_mcs_set");
1808 for (int i
= 0; i
< 16; i
++) {
1809 blobmsg_add_u16(&b
, NULL
, (u16
) ht_capabilities
->supported_mcs_set
[i
]);
1811 blobmsg_close_array(&b
, mcs_set
);
1812 blobmsg_close_table(&b
, ht_cap_mcs_set
);
1813 blobmsg_close_table(&b
, ht_cap
);
1815 if(req
->elems
->vht_capabilities
)
1817 struct ieee80211_vht_capabilities
*vht_capabilities
;
1818 void *vht_cap
, *vht_cap_mcs_set
;
1820 vht_capabilities
= (struct ieee80211_vht_capabilities
*) req
->elems
->vht_capabilities
;
1821 vht_cap
= blobmsg_open_table(&b
, "vht_capabilities");
1822 blobmsg_add_u32(&b
, "vht_capabilities_info", vht_capabilities
->vht_capabilities_info
);
1823 vht_cap_mcs_set
= blobmsg_open_table(&b
, "vht_supported_mcs_set");
1824 blobmsg_add_u16(&b
, "rx_map", vht_capabilities
->vht_supported_mcs_set
.rx_map
);
1825 blobmsg_add_u16(&b
, "rx_highest", vht_capabilities
->vht_supported_mcs_set
.rx_highest
);
1826 blobmsg_add_u16(&b
, "tx_map", vht_capabilities
->vht_supported_mcs_set
.tx_map
);
1827 blobmsg_add_u16(&b
, "tx_highest", vht_capabilities
->vht_supported_mcs_set
.tx_highest
);
1828 blobmsg_close_table(&b
, vht_cap_mcs_set
);
1829 blobmsg_close_table(&b
, vht_cap
);
1833 if (!hapd
->ubus
.notify_response
) {
1834 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);
1835 return WLAN_STATUS_SUCCESS
;
1838 if (ubus_notify_async(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, &ureq
.nreq
))
1839 return WLAN_STATUS_SUCCESS
;
1841 ureq
.nreq
.status_cb
= ubus_event_cb
;
1842 ubus_complete_request(ctx
, &ureq
.nreq
.req
, 100);
1847 return WLAN_STATUS_SUCCESS
;
1850 void hostapd_ubus_notify(struct hostapd_data
*hapd
, const char *type
, const u8
*addr
)
1852 if (!hapd
->ubus
.obj
.has_subscribers
)
1858 blob_buf_init(&b
, 0);
1859 blobmsg_add_macaddr(&b
, "address", addr
);
1861 ubus_notify(ctx
, &hapd
->ubus
.obj
, type
, b
.head
, -1);
1864 void hostapd_ubus_notify_authorized(struct hostapd_data
*hapd
, struct sta_info
*sta
,
1865 const char *auth_alg
)
1867 if (!hapd
->ubus
.obj
.has_subscribers
)
1870 blob_buf_init(&b
, 0);
1871 blobmsg_add_macaddr(&b
, "address", sta
->addr
);
1873 blobmsg_add_string(&b
, "auth-alg", auth_alg
);
1875 ubus_notify(ctx
, &hapd
->ubus
.obj
, "sta-authorized", b
.head
, -1);
1878 void hostapd_ubus_notify_beacon_report(
1879 struct hostapd_data
*hapd
, const u8
*addr
, u8 token
, u8 rep_mode
,
1880 struct rrm_measurement_beacon_report
*rep
, size_t len
)
1882 if (!hapd
->ubus
.obj
.has_subscribers
)
1888 blob_buf_init(&b
, 0);
1889 blobmsg_add_macaddr(&b
, "address", addr
);
1890 blobmsg_add_u16(&b
, "op-class", rep
->op_class
);
1891 blobmsg_add_u16(&b
, "channel", rep
->channel
);
1892 blobmsg_add_u64(&b
, "start-time", rep
->start_time
);
1893 blobmsg_add_u16(&b
, "duration", rep
->duration
);
1894 blobmsg_add_u16(&b
, "report-info", rep
->report_info
);
1895 blobmsg_add_u16(&b
, "rcpi", rep
->rcpi
);
1896 blobmsg_add_u16(&b
, "rsni", rep
->rsni
);
1897 blobmsg_add_macaddr(&b
, "bssid", rep
->bssid
);
1898 blobmsg_add_u16(&b
, "antenna-id", rep
->antenna_id
);
1899 blobmsg_add_u16(&b
, "parent-tsf", rep
->parent_tsf
);
1900 blobmsg_add_u16(&b
, "rep-mode", rep_mode
);
1902 ubus_notify(ctx
, &hapd
->ubus
.obj
, "beacon-report", b
.head
, -1);
1905 void hostapd_ubus_notify_radar_detected(struct hostapd_iface
*iface
, int frequency
,
1906 int chan_width
, int cf1
, int cf2
)
1908 struct hostapd_data
*hapd
;
1914 blob_buf_init(&b
, 0);
1915 blobmsg_add_u16(&b
, "frequency", frequency
);
1916 blobmsg_add_u16(&b
, "width", chan_width
);
1917 blobmsg_add_u16(&b
, "center1", cf1
);
1918 blobmsg_add_u16(&b
, "center2", cf2
);
1920 for (i
= 0; i
< iface
->num_bss
; i
++) {
1921 hapd
= iface
->bss
[i
];
1922 ubus_notify(ctx
, &hapd
->ubus
.obj
, "radar-detected", b
.head
, -1);
1926 #ifdef CONFIG_WNM_AP
1927 static void hostapd_ubus_notify_bss_transition_add_candidate_list(
1928 const u8
*candidate_list
, u16 candidate_list_len
)
1933 if (candidate_list_len
== 0)
1936 cl_str
= blobmsg_alloc_string_buffer(&b
, "candidate-list", candidate_list_len
* 2 + 1);
1937 for (i
= 0; i
< candidate_list_len
; i
++)
1938 snprintf(&cl_str
[i
*2], 3, "%02X", candidate_list
[i
]);
1939 blobmsg_add_string_buffer(&b
);
1944 void hostapd_ubus_notify_bss_transition_response(
1945 struct hostapd_data
*hapd
, const u8
*addr
, u8 dialog_token
, u8 status_code
,
1946 u8 bss_termination_delay
, const u8
*target_bssid
,
1947 const u8
*candidate_list
, u16 candidate_list_len
)
1949 #ifdef CONFIG_WNM_AP
1952 if (!hapd
->ubus
.obj
.has_subscribers
)
1958 blob_buf_init(&b
, 0);
1959 blobmsg_add_macaddr(&b
, "address", addr
);
1960 blobmsg_add_u8(&b
, "dialog-token", dialog_token
);
1961 blobmsg_add_u8(&b
, "status-code", status_code
);
1962 blobmsg_add_u8(&b
, "bss-termination-delay", bss_termination_delay
);
1964 blobmsg_add_macaddr(&b
, "target-bssid", target_bssid
);
1966 hostapd_ubus_notify_bss_transition_add_candidate_list(candidate_list
, candidate_list_len
);
1968 ubus_notify(ctx
, &hapd
->ubus
.obj
, "bss-transition-response", b
.head
, -1);
1972 int hostapd_ubus_notify_bss_transition_query(
1973 struct hostapd_data
*hapd
, const u8
*addr
, u8 dialog_token
, u8 reason
,
1974 const u8
*candidate_list
, u16 candidate_list_len
)
1976 #ifdef CONFIG_WNM_AP
1977 struct ubus_event_req ureq
= {};
1981 if (!hapd
->ubus
.obj
.has_subscribers
)
1987 blob_buf_init(&b
, 0);
1988 blobmsg_add_macaddr(&b
, "address", addr
);
1989 blobmsg_add_u8(&b
, "dialog-token", dialog_token
);
1990 blobmsg_add_u8(&b
, "reason", reason
);
1991 hostapd_ubus_notify_bss_transition_add_candidate_list(candidate_list
, candidate_list_len
);
1993 if (!hapd
->ubus
.notify_response
) {
1994 ubus_notify(ctx
, &hapd
->ubus
.obj
, "bss-transition-query", b
.head
, -1);
1998 if (ubus_notify_async(ctx
, &hapd
->ubus
.obj
, "bss-transition-query", b
.head
, &ureq
.nreq
))
2001 ureq
.nreq
.status_cb
= ubus_event_cb
;
2002 ubus_complete_request(ctx
, &ureq
.nreq
.req
, 100);