rrmd: allow kicking clients globally of from the AP

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2023-11-14 16:35:23 +01:00
parent 78eb88ed26
commit 8f7369a71c
5 changed files with 120 additions and 16 deletions

View File

@@ -508,6 +508,7 @@ enum {
DEL_CLIENT_REASON,
DEL_CLIENT_DEAUTH,
DEL_CLIENT_BAN_TIME,
DEL_CLIENT_GLOBAL_BAN,
__DEL_CLIENT_MAX
};
@@ -516,6 +517,7 @@ static const struct blobmsg_policy del_policy[__DEL_CLIENT_MAX] = {
[DEL_CLIENT_REASON] = { "reason", BLOBMSG_TYPE_INT32 },
[DEL_CLIENT_DEAUTH] = { "deauth", BLOBMSG_TYPE_INT8 },
[DEL_CLIENT_BAN_TIME] = { "ban_time", BLOBMSG_TYPE_INT32 },
[DEL_CLIENT_GLOBAL_BAN] = { "global_ban", BLOBMSG_TYPE_INT8 },
};
static int
@@ -526,7 +528,7 @@ hostapd_bss_del_client(struct ubus_context *ctx, struct ubus_object *obj,
struct blob_attr *tb[__DEL_CLIENT_MAX];
struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
struct sta_info *sta;
bool deauth = false;
bool deauth = false, global = false;
int reason;
u8 addr[ETH_ALEN];
@@ -544,6 +546,9 @@ hostapd_bss_del_client(struct ubus_context *ctx, struct ubus_object *obj,
if (tb[DEL_CLIENT_DEAUTH])
deauth = blobmsg_get_bool(tb[DEL_CLIENT_DEAUTH]);
if (tb[DEL_CLIENT_GLOBAL_BAN])
global = blobmsg_get_bool(tb[DEL_CLIENT_GLOBAL_BAN]);
sta = ap_get_sta(hapd, addr);
if (sta) {
if (deauth) {
@@ -555,8 +560,18 @@ hostapd_bss_del_client(struct ubus_context *ctx, struct ubus_object *obj,
}
}
if (tb[DEL_CLIENT_BAN_TIME])
hostapd_bss_ban_client(hapd, addr, blobmsg_get_u32(tb[DEL_CLIENT_BAN_TIME]));
if (tb[DEL_CLIENT_BAN_TIME]) {
int i;
for (i = 0; i < hapd->iface->num_bss; i++) {
struct hostapd_data *bss = hapd->iface->bss[i];
if (!global && bss != hapd)
continue;
hostapd_bss_ban_client(bss, addr, blobmsg_get_u32(tb[DEL_CLIENT_BAN_TIME]));
}
}
return 0;
}
@@ -820,7 +835,7 @@ hostapd_switch_chan(struct ubus_context *ctx, struct ubus_object *obj,
chwidth, seg0, seg1,
iconf->vht_capab,
mode ? &mode->he_capab[IEEE80211_MODE_AP] :
NULL, NULL);
NULL, 0);
for (i = 0; i < hapd->iface->num_bss; i++) {
struct hostapd_data *bss = hapd->iface->bss[i];

View File

@@ -10,7 +10,7 @@ function result(error, event, text, data) {
}
const actions = {
// ubus call rrmd command '{"action": "kick", "addr": "1c:57:dc:37:3c:b1", "reason": 5, "ban_time": 30 }'
// ubus call rrm command '{"action": "kick", "addr": "1c:57:dc:37:3c:b1", "reason": 5, "ban_time": 30, "global_ban": true }'
kick: function(msg) {
if (!global.station.kick(msg))
return result(1, msg.event, 'station ' + msg.addr + ' is unknown', { action: 'kick', addr: msg.addr });
@@ -18,9 +18,9 @@ const actions = {
return result(0, 0, 'station ' + msg.addr + ' was kicked', { action: 'kick', addr: msg.addr });
},
// ubus call rrmd command '{"action": "beacon_request", "addr": "4e:7f:3e:2c:8a:68", "params": "channel": 1}'
// ubus call rrmd command '{"action": "beacon_request", "addr": "4e:7f:3e:2c:8a:68", "params": "ssid": "Pluto" }'
// ubus call rrmd get_beacon_request '{"addr": "4e:7f:3e:2c:8a:68"}'
// ubus call rrm command '{"action": "beacon_request", "addr": "4e:7f:3e:2c:8a:68", "params": "channel": 1}'
// ubus call rrm command '{"action": "beacon_request", "addr": "4e:7f:3e:2c:8a:68", "params": "ssid": "Pluto" }'
// ubus call rrm get_beacon_request '{"addr": "4e:7f:3e:2c:8a:68"}'
beacon_request: function(msg) {
if (!global.station.beacon_request(msg))
return result(1, msg.event, 'station ' + msg.addr + ' is unknown', { action: 'beacon_request', addr: msg.addr });
@@ -28,7 +28,7 @@ const actions = {
return result(0, 0, 'station ' + msg.addr + ' beacon-request sent', { action: 'beacon_request', addr: msg.addr });
},
// ubus call rrmd command '{"action": "channel_switch", "bssid": "34:eF:b6:aF:48:b1", "channel": 4 }'
// ubus call rrm command '{"action": "channel_switch", "bssid": "34:eF:b6:aF:48:b1", "channel": 4 }'
channel_switch: function(msg) {
if (!global.local.switch_chan(msg))
return result(1, msg.event, 'BSS ' + msg.bssid + ' failed to trigger channel switch', { action: 'channel_switch', bssid: msg.bssid });
@@ -36,7 +36,7 @@ const actions = {
return result(0, msg.event, 'BSS ' + msg.bssid + ' triggered channel switch', { action: 'channel_switch', bssid: msg.bssid });
},
// ubus call rrmd command '{"action": "tx_power", "bssid": "34:eF:b6:aF:48:b1", "level": 20}'
// ubus call rrm command '{"action": "tx_power", "bssid": "34:eF:b6:aF:48:b1", "level": 20}'
tx_power: function(msg) {
if (!global.phy.txpower(msg))
return result(1, msg.event, 'BSS ' + msg.bssid + ' failed to set TX power', { action: 'tx_power', bssid: msg.bssid });
@@ -45,7 +45,7 @@ const actions = {
return result(0, msg.event, 'BSS ' + msg.bssid + ' changed TX power', { action: 'tx_power', bssid: msg.bssid, level });
},
// ubus call rrmd command '{"action": "bss_transition", "addr": "4e:7f:3e:2c:8a:68", "neighbors": ["34:ef:b6:af:48:b1"] }'
// ubus call rrm command '{"action": "bss_transition", "addr": "4e:7f:3e:2c:8a:68", "neighbors": ["34:ef:b6:af:48:b1"] }'
bss_transition: function(msg) {
if (!global.station.bss_transition(msg))
return result(1, msg.event, 'BSS transition ' + msg.addr + ' failed to trigger', { action: 'bss_transition', addr: msg.addr });
@@ -53,7 +53,7 @@ const actions = {
return result(0, 0, 'BSS transition ' + msg.addr + ' triggered');
},
// ubus call rrmd command '{"action": "neighbors", "neighbors": [ [ "00:11:22:33:44:55", "OpenWifi", "34efb6af48b1af4900005301070603010300" ], [ "aa:bb:cc:dd:ee:ff", "OpenWifi2", "34efb6af48b1af4900005301070603010300" ] ] }'
// ubus call rrm command '{"action": "neighbors", "neighbors": [ [ "00:11:22:33:44:55", "OpenWifi", "34efb6af48b1af4900005301070603010300" ], [ "aa:bb:cc:dd:ee:ff", "OpenWifi2", "34efb6af48b1af4900005301070603010300" ] ] }'
neighbors: function(msg) {
if (!global.neighbor.remote(msg))
return result(1, msg.event, 'Failed to set neighbors', { action: 'neighbors' });

View File

@@ -228,7 +228,8 @@ return {
addr: msg.addr,
reason: msg.reason,
deauth: 1,
ban_time: msg.ban_time
ban_time: msg.ban_time,
global_ban: msg.global_ban || false,
};
/* tell hostapd to kick a station via ubus */

View File

@@ -508,6 +508,7 @@ enum {
DEL_CLIENT_REASON,
DEL_CLIENT_DEAUTH,
DEL_CLIENT_BAN_TIME,
DEL_CLIENT_GLOBAL_BAN,
__DEL_CLIENT_MAX
};
@@ -516,6 +517,7 @@ static const struct blobmsg_policy del_policy[__DEL_CLIENT_MAX] = {
[DEL_CLIENT_REASON] = { "reason", BLOBMSG_TYPE_INT32 },
[DEL_CLIENT_DEAUTH] = { "deauth", BLOBMSG_TYPE_INT8 },
[DEL_CLIENT_BAN_TIME] = { "ban_time", BLOBMSG_TYPE_INT32 },
[DEL_CLIENT_GLOBAL_BAN] = { "global_ban", BLOBMSG_TYPE_INT8 },
};
static int
@@ -526,7 +528,7 @@ hostapd_bss_del_client(struct ubus_context *ctx, struct ubus_object *obj,
struct blob_attr *tb[__DEL_CLIENT_MAX];
struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
struct sta_info *sta;
bool deauth = false;
bool deauth = false, global = false;
int reason;
u8 addr[ETH_ALEN];
@@ -544,6 +546,9 @@ hostapd_bss_del_client(struct ubus_context *ctx, struct ubus_object *obj,
if (tb[DEL_CLIENT_DEAUTH])
deauth = blobmsg_get_bool(tb[DEL_CLIENT_DEAUTH]);
if (tb[DEL_CLIENT_GLOBAL_BAN])
global = blobmsg_get_bool(tb[DEL_CLIENT_GLOBAL_BAN]);
sta = ap_get_sta(hapd, addr);
if (sta) {
if (deauth) {
@@ -555,8 +560,18 @@ hostapd_bss_del_client(struct ubus_context *ctx, struct ubus_object *obj,
}
}
if (tb[DEL_CLIENT_BAN_TIME])
hostapd_bss_ban_client(hapd, addr, blobmsg_get_u32(tb[DEL_CLIENT_BAN_TIME]));
if (tb[DEL_CLIENT_BAN_TIME]) {
int i;
for (i = 0; i < hapd->iface->num_bss; i++) {
struct hostapd_data *bss = hapd->iface->bss[i];
if (!global && bss != hapd)
continue;
hostapd_bss_ban_client(bss, addr, blobmsg_get_u32(tb[DEL_CLIENT_BAN_TIME]));
}
}
return 0;
}