Change beacon request fields to appropriate values

This changes the op_class, channel, and SSID fields used to send a
beacon request.  Op_class and channel were set from the UCI config file,
but they are dependent on the band being used--they define the frequency
used.  The values can be taken from the AP's own neighbor report.

The SSID was set with a blank string, which would return beacons from
any SSID.  Since we only care about our own SSID, there's no need to
waste resorces with reports from other SSIDs.

Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
This commit is contained in:
Eneas U de Queiroz 2021-07-26 15:06:28 -03:00 committed by Polynomdivision
parent 009aab9ca4
commit 3ba0fa4947
7 changed files with 20 additions and 36 deletions

View file

@ -82,11 +82,9 @@ struct probe_metric_s {
int chan_util_avg_period;
int set_hostapd_nr;
int kicking;
int op_class;
int duration;
int rrm_mode_mask;
int rrm_mode_order[__RRM_BEACON_RQST_MODE_MAX];
int scan_channel;
};
struct time_config_s {
@ -248,7 +246,7 @@ typedef struct client_s {
typedef struct ap_s {
struct ap_s* next_ap;
struct dawn_mac bssid_addr;
uint32_t freq; // TODO: Never evaluated?
uint32_t freq; // ap_get_nr()
uint8_t ht_support; // eval_probe_metric()
uint8_t vht_support; // eval_probe_metric()
uint32_t channel_utilization; // eval_probe_metric()
@ -256,6 +254,8 @@ typedef struct ap_s {
uint32_t station_count; // compare_station_count() <- better_ap_available()
uint8_t ssid[SSID_MAX_LEN + 1]; // compare_sid() < -better_ap_available()
char neighbor_report[NEIGHBOR_REPORT_LEN];
uint32_t op_class; // ubus_send_beacon_report()
uint32_t channel; // ubus_send_beacon_report()
uint32_t collision_domain; // TODO: ap_get_collision_count() never evaluated?
uint32_t bandwidth; // TODO: Never evaluated?
uint32_t ap_weight; // eval_probe_metric()
@ -340,7 +340,7 @@ int probe_array_set_all_probe_count(struct dawn_mac client_addr, uint32_t probe_
int ap_get_collision_count(int col_domain);
#endif
void send_beacon_reports(struct dawn_mac bssid, int id);
void send_beacon_reports(ap *a, int id);
/* Utils */
// deprecate use of this - it makes things slow

View file

@ -68,7 +68,7 @@ void del_client_all_interfaces(const struct dawn_mac client_addr, uint32_t reaso
*/
void update_hostapd_sockets(struct uloop_timeout *t);
void ubus_send_beacon_report(client *c, int id);
void ubus_send_beacon_report(client *c, ap *a, int id);
void uloop_add_data_cbs();

View file

@ -380,14 +380,14 @@ static struct mac_entry_s** mac_find_first_entry(struct dawn_mac mac)
return lo_ptr;
}
void send_beacon_reports(struct dawn_mac bssid, int id) {
void send_beacon_reports(ap *a, int id) {
pthread_mutex_lock(&client_array_mutex);
// Seach for BSSID
client* i = *client_find_first_bc_entry(bssid, dawn_mac_null, false);
client* i = *client_find_first_bc_entry(a->bssid_addr, dawn_mac_null, false);
// Go threw clients
while (i != NULL && mac_is_equal_bb(i->bssid_addr, bssid)) {
while (i != NULL && mac_is_equal_bb(i->bssid_addr, a->bssid_addr)) {
#ifndef DAWN_NO_OUTPUT
printf("Client " MACSTR ": rrm_enabled_capa=%02x: PASSIVE=%d, ACTIVE=%d, TABLE=%d\n",
MAC2STR(i->client_addr.u8), i->rrm_enabled_capa,
@ -396,7 +396,7 @@ void send_beacon_reports(struct dawn_mac bssid, int id) {
!!(i->rrm_enabled_capa & WLAN_RRM_CAPS_BEACON_REPORT_TABLE));
#endif
if (i->rrm_enabled_capa & dawn_metric.rrm_mode_mask)
ubus_send_beacon_report(i, id);
ubus_send_beacon_report(i, a, id);
i = i->next_entry_bc;
}

View file

@ -11,7 +11,7 @@
#include "test_storage.h"
/*** Test Stub Functions - Called by SUT ***/
void ubus_send_beacon_report(client *c, int id)
void ubus_send_beacon_report(client *c, ap *a, int id)
{
printf("send_beacon_report() was called...\n");
}
@ -654,7 +654,6 @@ static int consume_actions(int argc, char* argv[], int harness_verbosity)
dawn_metric.chan_util_avg_period = 3;
dawn_metric.set_hostapd_nr = 1;
dawn_metric.kicking = 0;
dawn_metric.op_class = 0;
dawn_metric.duration = 0;
dawn_metric.rrm_mode_mask = WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE |
WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE |
@ -662,7 +661,6 @@ static int consume_actions(int argc, char* argv[], int harness_verbosity)
dawn_metric.rrm_mode_order[0] = WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE;
dawn_metric.rrm_mode_order[1] = WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE;
dawn_metric.rrm_mode_order[2] = WLAN_RRM_CAPS_BEACON_REPORT_TABLE;
dawn_metric.scan_channel = 0;
}
else if (!strncmp(fn, "ap_weight=", 10)) load_int(&dawn_metric.ap_weight, fn + 10);
else if (!strncmp(fn, "ht_support=", 11)) load_int(&dawn_metric.ht_support, fn + 11);
@ -692,10 +690,8 @@ static int consume_actions(int argc, char* argv[], int harness_verbosity)
else if (!strncmp(fn, "chan_util_avg_period=", 21)) load_int(&dawn_metric.chan_util_avg_period, fn + 21);
else if (!strncmp(fn, "set_hostapd_nr=", 15)) load_int(&dawn_metric.set_hostapd_nr, fn + 15);
else if (!strncmp(fn, "kicking=", 8)) load_int(&dawn_metric.kicking, fn + 8);
else if (!strncmp(fn, "op_class=", 9)) load_int(&dawn_metric.op_class, fn + 9);
else if (!strncmp(fn, "duration=", 9)) load_int(&dawn_metric.duration, fn + 9);
else if (!strncmp(fn, "rrm_mode=", 9)) dawn_metric.rrm_mode_mask = parse_rrm_mode(dawn_metric.rrm_mode_order, fn + 9);
else if (!strncmp(fn, "scan_channel=", 13)) load_int(&dawn_metric.scan_channel, fn + 13);
else {
printf("ERROR: Loading DAWN control metrics, but don't recognise assignment \"%s\"\n", fn);
ret = 1;

View file

@ -153,11 +153,9 @@ struct probe_metric_s uci_get_dawn_metric() {
ret.min_kick_count = uci_lookup_option_int(uci_ctx, s, "min_number_to_kick");
ret.chan_util_avg_period = uci_lookup_option_int(uci_ctx, s, "chan_util_avg_period");
ret.set_hostapd_nr = uci_lookup_option_int(uci_ctx, s, "set_hostapd_nr");
ret.op_class = uci_lookup_option_int(uci_ctx, s, "op_class");
ret.duration = uci_lookup_option_int(uci_ctx, s, "duration");
ret.rrm_mode_mask = parse_rrm_mode(ret.rrm_mode_order,
uci_lookup_option_string(uci_ctx, s, "rrm_mode"));
ret.scan_channel = uci_lookup_option_int(uci_ctx, s, "scan_channel");
return ret;
}
}

View file

@ -519,8 +519,10 @@ int parse_to_clients(struct blob_attr* msg, int do_kick, uint32_t id) {
}
ap_entry->op_class = ap_entry->channel = 0;
if (tb[CLIENT_TABLE_NEIGHBOR]) {
strncpy(ap_entry->neighbor_report, blobmsg_get_string(tb[CLIENT_TABLE_NEIGHBOR]), NEIGHBOR_REPORT_LEN);
sscanf(ap_entry->neighbor_report + NR_OP_CLASS, "%2x%2x", &ap_entry->op_class, &ap_entry->channel);
}
else {
ap_entry->neighbor_report[0] = '\0';
@ -584,10 +586,8 @@ enum {
UCI_MIN_NUMBER_TO_KICK,
UCI_CHAN_UTIL_AVG_PERIOD,
UCI_SET_HOSTAPD_NR,
UCI_OP_CLASS,
UCI_DURATION,
UCI_RRM_MODE,
UCI_SCAN_CHANNEL,
__UCI_METIC_MAX
};
@ -637,10 +637,8 @@ static const struct blobmsg_policy uci_metric_policy[__UCI_METIC_MAX] = {
[UCI_MIN_NUMBER_TO_KICK] = {.name = "min_number_to_kick", .type = BLOBMSG_TYPE_INT32},
[UCI_CHAN_UTIL_AVG_PERIOD] = {.name = "chan_util_avg_period", .type = BLOBMSG_TYPE_INT32},
[UCI_SET_HOSTAPD_NR] = {.name = "set_hostapd_nr", .type = BLOBMSG_TYPE_INT32},
[UCI_OP_CLASS] = {.name = "op_class", .type = BLOBMSG_TYPE_INT32},
[UCI_DURATION] = {.name = "duration", .type = BLOBMSG_TYPE_INT32},
[UCI_RRM_MODE] = {.name = "rrm_mode", .type = BLOBMSG_TYPE_STRING},
[UCI_SCAN_CHANNEL] = {.name = "scan_channel", .type = BLOBMSG_TYPE_INT32},
};
static const struct blobmsg_policy uci_times_policy[__UCI_TIMES_MAX] = {
@ -746,18 +744,12 @@ static int handle_uci_config(struct blob_attr* msg) {
sprintf(cmd_buffer, "dawn.@metric[0].set_hostapd_nr=%d", blobmsg_get_u32(tb_metric[UCI_SET_HOSTAPD_NR]));
uci_set_network(cmd_buffer);
sprintf(cmd_buffer, "dawn.@metric[0].op_class=%d", blobmsg_get_u32(tb_metric[UCI_OP_CLASS]));
uci_set_network(cmd_buffer);
sprintf(cmd_buffer, "dawn.@metric[0].duration=%d", blobmsg_get_u32(tb_metric[UCI_DURATION]));
uci_set_network(cmd_buffer);
sprintf(cmd_buffer, "dawn.@metric[0].rrm_mode=%s", blobmsg_get_string(tb_metric[UCI_RRM_MODE]));
uci_set_network(cmd_buffer);
sprintf(cmd_buffer, "dawn.@metric[0].scan_channel=%d", blobmsg_get_u32(tb_metric[UCI_SCAN_CHANNEL]));
uci_set_network(cmd_buffer);
struct blob_attr* tb_times[__UCI_TIMES_MAX];
blobmsg_parse(uci_times_policy, __UCI_TIMES_MAX, tb_times, blobmsg_data(tb[UCI_TABLE_TIMES]), blobmsg_len(tb[UCI_TABLE_TIMES]));

View file

@ -815,25 +815,25 @@ static int get_mode_from_capability(int capability) {
return -1;
}
void ubus_send_beacon_report(client *c, int id)
void ubus_send_beacon_report(client *c, ap *a, int id)
{
printf("Crafting Beacon Report\n");
int timeout = 1;
blob_buf_init(&b_beacon, 0);
blobmsg_add_macaddr(&b_beacon, "addr", c->client_addr);
blobmsg_add_u32(&b_beacon, "op_class", dawn_metric.op_class);
blobmsg_add_u32(&b_beacon, "channel", dawn_metric.scan_channel);
blobmsg_add_u32(&b_beacon, "op_class", a->op_class);
blobmsg_add_u32(&b_beacon, "channel", a->channel);
blobmsg_add_u32(&b_beacon, "duration", dawn_metric.duration);
blobmsg_add_u32(&b_beacon, "mode", get_mode_from_capability(c->rrm_enabled_capa));
printf("Adding string\n");
blobmsg_add_string(&b_beacon, "ssid", "");
blobmsg_add_string(&b_beacon, "ssid", (char*)a->ssid);
printf("Invoking beacon report!\n");
ubus_invoke(ctx, id, "rrm_beacon_req", b_beacon.head, NULL, NULL, timeout * 1000);
}
void update_beacon_reports(struct uloop_timeout *t) {
ap *a;
if(!timeout_config.update_beacon_reports) // if 0 just return
{
return;
@ -842,9 +842,9 @@ void update_beacon_reports(struct uloop_timeout *t) {
struct hostapd_sock_entry *sub;
list_for_each_entry(sub, &hostapd_sock_list, list)
{
if (sub->subscribed) {
if (sub->subscribed && (a = ap_array_get_ap(sub->bssid_addr, (uint8_t*)sub->ssid))) {
printf("Sending beacon report Sub!\n");
send_beacon_reports(sub->bssid_addr, sub->id);
send_beacon_reports(a, sub->id);
}
}
uloop_timeout_set(&beacon_reports_timer, timeout_config.update_beacon_reports * 1000);
@ -1397,10 +1397,8 @@ int uci_send_via_network()
blobmsg_add_u32(&b, "min_number_to_kick", dawn_metric.min_kick_count);
blobmsg_add_u32(&b, "chan_util_avg_period", dawn_metric.chan_util_avg_period);
blobmsg_add_u32(&b, "set_hostapd_nr", dawn_metric.set_hostapd_nr);
blobmsg_add_u32(&b, "op_class", dawn_metric.op_class);
blobmsg_add_u32(&b, "duration", dawn_metric.duration);
blobmsg_add_string(&b, "rrm_mode", get_rrm_mode_string(dawn_metric.rrm_mode_order));
blobmsg_add_u32(&b, "scan_channel", dawn_metric.scan_channel);
blobmsg_close_table(&b, metric);
times = blobmsg_open_table(&b, "times");