#include "ubus.h"
#include "ap_drv_ops.h"
#include "beacon.h"
+#include "rrm.h"
+#include "wnm_ap.h"
+#include "taxonomy.h"
static struct ubus_context *ctx;
static struct blob_buf b;
blobmsg_add_u32(&b, "freq", hapd->iface->freq);
list = blobmsg_open_table(&b, "clients");
for (sta = hapd->sta_list; sta; sta = sta->next) {
+ void *r;
int i;
sprintf(mac_buf, MACSTR, MAC2STR(sta->addr));
for (i = 0; i < ARRAY_SIZE(sta_flags); i++)
blobmsg_add_u8(&b, sta_flags[i].name,
!!(sta->flags & sta_flags[i].flag));
+
+ r = blobmsg_open_array(&b, "rrm");
+ for (i = 0; i < ARRAY_SIZE(sta->rrm_enabled_capa); i++)
+ blobmsg_add_u32(&b, "", sta->rrm_enabled_capa[i]);
+ blobmsg_close_array(&b, r);
blobmsg_add_u32(&b, "aid", sta->aid);
+#ifdef CONFIG_TAXONOMY
+ r = blobmsg_alloc_string_buffer(&b, "signature", 1024);
+ if (retrieve_sta_taxonomy(hapd, sta, r, 1024) > 0)
+ blobmsg_add_string_buffer(&b);
+#endif
blobmsg_close_table(&b, c);
}
blobmsg_close_array(&b, list);
return 0;
}
+enum {
+ BEACON_REQ_ADDR,
+ BEACON_REQ_MODE,
+ BEACON_REQ_OP_CLASS,
+ BEACON_REQ_CHANNEL,
+ BEACON_REQ_DURATION,
+ BEACON_REQ_BSSID,
+ BEACON_REQ_SSID,
+ __BEACON_REQ_MAX,
+};
+
+static const struct blobmsg_policy beacon_req_policy[__BEACON_REQ_MAX] = {
+ [BEACON_REQ_ADDR] = { "addr", BLOBMSG_TYPE_STRING },
+ [BEACON_REQ_OP_CLASS] { "op_class", BLOBMSG_TYPE_INT32 },
+ [BEACON_REQ_CHANNEL] { "channel", BLOBMSG_TYPE_INT32 },
+ [BEACON_REQ_DURATION] { "duration", BLOBMSG_TYPE_INT32 },
+ [BEACON_REQ_MODE] { "mode", BLOBMSG_TYPE_INT32 },
+ [BEACON_REQ_BSSID] { "bssid", BLOBMSG_TYPE_STRING },
+ [BEACON_REQ_SSID] { "ssid", BLOBMSG_TYPE_STRING },
+};
+
+static int
+hostapd_rrm_beacon_req(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *ureq, const char *method,
+ struct blob_attr *msg)
+{
+ struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
+ struct blob_attr *tb[__BEACON_REQ_MAX];
+ struct blob_attr *cur;
+ struct wpabuf *req;
+ u8 bssid[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+ u8 addr[ETH_ALEN];
+ int mode, rem, ret;
+ int buf_len = 13;
+
+ blobmsg_parse(beacon_req_policy, __BEACON_REQ_MAX, tb, blob_data(msg), blob_len(msg));
+
+ if (!tb[BEACON_REQ_ADDR] || !tb[BEACON_REQ_MODE] || !tb[BEACON_REQ_DURATION] ||
+ !tb[BEACON_REQ_OP_CLASS] || !tb[BEACON_REQ_CHANNEL])
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ if (tb[BEACON_REQ_SSID])
+ buf_len += blobmsg_data_len(tb[BEACON_REQ_SSID]) + 2 - 1;
+
+ mode = blobmsg_get_u32(tb[BEACON_REQ_MODE]);
+ if (hwaddr_aton(blobmsg_data(tb[BEACON_REQ_ADDR]), addr))
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ if (tb[BEACON_REQ_BSSID] &&
+ hwaddr_aton(blobmsg_data(tb[BEACON_REQ_BSSID]), bssid))
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ req = wpabuf_alloc(buf_len);
+ if (!req)
+ return UBUS_STATUS_UNKNOWN_ERROR;
+
+ /* 1: regulatory class */
+ wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_OP_CLASS]));
+
+ /* 2: channel number */
+ wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_CHANNEL]));
+
+ /* 3-4: randomization interval */
+ wpabuf_put_le16(req, 0);
+
+ /* 5-6: duration */
+ wpabuf_put_le16(req, blobmsg_get_u32(tb[BEACON_REQ_DURATION]));
+
+ /* 7: mode */
+ wpabuf_put_u8(req, blobmsg_get_u32(tb[BEACON_REQ_MODE]));
+
+ /* 8-13: BSSID */
+ wpabuf_put_data(req, bssid, ETH_ALEN);
+
+ if ((cur = tb[BEACON_REQ_SSID]) != NULL) {
+ wpabuf_put_u8(req, WLAN_EID_SSID);
+ wpabuf_put_u8(req, blobmsg_data_len(cur) - 1);
+ wpabuf_put_data(req, blobmsg_data(cur), blobmsg_data_len(cur) - 1);
+ }
+
+ ret = hostapd_send_beacon_req(hapd, addr, 0, req);
+ if (ret < 0)
+ return -ret;
+
+ return 0;
+}
+
+
+#ifdef CONFIG_WNM_AP
+enum {
+ WNM_DISASSOC_ADDR,
+ WNM_DISASSOC_DURATION,
+ WNM_DISASSOC_NEIGHBORS,
+ __WNM_DISASSOC_MAX,
+};
+
+static const struct blobmsg_policy wnm_disassoc_policy[__WNM_DISASSOC_MAX] = {
+ [WNM_DISASSOC_ADDR] = { "addr", BLOBMSG_TYPE_STRING },
+ [WNM_DISASSOC_DURATION] { "duration", BLOBMSG_TYPE_INT32 },
+ [WNM_DISASSOC_NEIGHBORS] { "neighbors", BLOBMSG_TYPE_ARRAY },
+};
+
+static int
+hostapd_wnm_disassoc_imminent(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *ureq, const char *method,
+ struct blob_attr *msg)
+{
+ struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
+ struct blob_attr *tb[__WNM_DISASSOC_MAX];
+ struct blob_attr *cur;
+ struct sta_info *sta;
+ int duration = 10;
+ int rem;
+ int nr_len = 0;
+ u8 *nr = NULL;
+ u8 req_mode = WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
+ u8 addr[ETH_ALEN];
+
+ blobmsg_parse(wnm_disassoc_policy, __WNM_DISASSOC_MAX, tb, blob_data(msg), blob_len(msg));
+
+ if (!tb[WNM_DISASSOC_ADDR])
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ if (hwaddr_aton(blobmsg_data(tb[WNM_DISASSOC_ADDR]), addr))
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ if ((cur = tb[WNM_DISASSOC_DURATION]) != NULL)
+ duration = blobmsg_get_u32(cur);
+
+ sta = ap_get_sta(hapd, addr);
+ if (!sta)
+ return UBUS_STATUS_NOT_FOUND;
+
+ if (tb[WNM_DISASSOC_NEIGHBORS]) {
+ u8 *nr_cur;
+
+ if (blobmsg_check_array(tb[WNM_DISASSOC_NEIGHBORS],
+ BLOBMSG_TYPE_STRING) < 0)
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ blobmsg_for_each_attr(cur, tb[WNM_DISASSOC_NEIGHBORS], rem) {
+ int len = strlen(blobmsg_get_string(cur));
+
+ if (len % 2)
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ nr_len += (len / 2) + 2;
+ }
+
+ if (nr_len) {
+ nr = os_zalloc(nr_len);
+ if (!nr)
+ return UBUS_STATUS_UNKNOWN_ERROR;
+ }
+
+ nr_cur = nr;
+ blobmsg_for_each_attr(cur, tb[WNM_DISASSOC_NEIGHBORS], rem) {
+ int len = strlen(blobmsg_get_string(cur)) / 2;
+
+ *nr_cur++ = WLAN_EID_NEIGHBOR_REPORT;
+ *nr_cur++ = (u8) len;
+ if (hexstr2bin(blobmsg_data(cur), nr_cur, len)) {
+ free(nr);
+ return UBUS_STATUS_INVALID_ARGUMENT;
+ }
+
+ nr_cur += len;
+ }
+ }
+
+ if (nr)
+ req_mode |= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED;
+
+ if (wnm_send_bss_tm_req(hapd, sta, req_mode, duration, 0, NULL,
+ NULL, nr, nr_len, NULL, 0))
+ return UBUS_STATUS_UNKNOWN_ERROR;
+
+ return 0;
+}
+#endif
+
static const struct ubus_method bss_methods[] = {
UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients),
UBUS_METHOD("del_client", hostapd_bss_del_client, del_policy),
UBUS_METHOD_NOARG("rrm_nr_get_own", hostapd_rrm_nr_get_own),
UBUS_METHOD_NOARG("rrm_nr_list", hostapd_rrm_nr_list),
UBUS_METHOD("rrm_nr_set", hostapd_rrm_nr_set, nr_set_policy),
+ UBUS_METHOD("rrm_beacon_req", hostapd_rrm_beacon_req, beacon_req_policy),
+#ifdef CONFIG_WNM_AP
+ UBUS_METHOD("wnm_disassoc_imminent", hostapd_wnm_disassoc_imminent, wnm_disassoc_policy),
+#endif
};
static struct ubus_object_type bss_object_type =
char *name;
int ret;
+#ifdef CONFIG_MESH
+ if (hapd->conf->mesh & MESH_ENABLED)
+ return;
+#endif
+
if (!hostapd_ubus_init())
return;