mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
Change mode config parameter from int to string
This renames "mode" to "rrm_mode", and its type from int to string. This way, we can set the correct mode for a probe request from the STA reported capabilities, along with the preferred order of modes, set by the "rrm_mode" uci config. rrm_mode is a string of possible mode letters: 'p' = passive report 'a' = active report 'b' or 't' = beacon table report. Setting rrm_mode='pat', will try to send passive reports, if available; if not, it will try an active report, using a beacon table if all else fails. If you don't include a letter, the corresponding report type will be disabled. An empty string will disable beacon reports. Unrecognized letters are ignored, as well as repeated modes. If the configuration is not present, a default value of 'pat' will be used. Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
This commit is contained in:
parent
276ca169a7
commit
009aab9ca4
7 changed files with 163 additions and 29 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#include <ctype.h>
|
||||
#include <uci.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
@ -77,8 +78,46 @@ struct time_config_s uci_get_time_config() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int get_rrm_mode_val(char mode) {
|
||||
switch (tolower(mode)) {
|
||||
case 'a':
|
||||
return WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE;
|
||||
break;
|
||||
case 'p':
|
||||
return WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE;
|
||||
break;
|
||||
case 'b':
|
||||
case 't':
|
||||
return WLAN_RRM_CAPS_BEACON_REPORT_TABLE;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_rrm_mode(int *rrm_mode_order, const char *mode_string) {
|
||||
int len, mode_val;
|
||||
int mask = 0, order = 0, pos = 0;
|
||||
|
||||
if (!mode_string)
|
||||
mode_string = DEFAULT_RRM_MODE_ORDER;
|
||||
len = strlen(mode_string);
|
||||
|
||||
while (order < __RRM_BEACON_RQST_MODE_MAX) {
|
||||
if (pos >= len) {
|
||||
rrm_mode_order[order++] = 0;
|
||||
} else {
|
||||
mode_val = get_rrm_mode_val(mode_string[pos++]);
|
||||
if (mode_val && !(mask & mode_val))
|
||||
mask |= (rrm_mode_order[order++] = mode_val);
|
||||
}
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
struct probe_metric_s uci_get_dawn_metric() {
|
||||
struct probe_metric_s ret;
|
||||
struct probe_metric_s ret = {0};
|
||||
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
|
|
@ -116,7 +155,8 @@ struct probe_metric_s uci_get_dawn_metric() {
|
|||
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.mode = uci_lookup_option_int(uci_ctx, s, "mode");
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -586,7 +586,7 @@ enum {
|
|||
UCI_SET_HOSTAPD_NR,
|
||||
UCI_OP_CLASS,
|
||||
UCI_DURATION,
|
||||
UCI_MODE,
|
||||
UCI_RRM_MODE,
|
||||
UCI_SCAN_CHANNEL,
|
||||
__UCI_METIC_MAX
|
||||
};
|
||||
|
|
@ -639,8 +639,8 @@ static const struct blobmsg_policy uci_metric_policy[__UCI_METIC_MAX] = {
|
|||
[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_MODE] = {.name = "mode", .type = BLOBMSG_TYPE_INT32},
|
||||
[UCI_SCAN_CHANNEL] = {.name = "mode", .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] = {
|
||||
|
|
@ -752,7 +752,7 @@ static int handle_uci_config(struct blob_attr* msg) {
|
|||
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].mode=%d", blobmsg_get_u32(tb_metric[UCI_MODE]));
|
||||
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]));
|
||||
|
|
|
|||
|
|
@ -801,16 +801,31 @@ void update_channel_utilization(struct uloop_timeout *t) {
|
|||
uloop_timeout_set(&channel_utilization_timer, timeout_config.update_chan_util * 1000);
|
||||
}
|
||||
|
||||
void ubus_send_beacon_report(struct dawn_mac client, int id)
|
||||
static int get_mode_from_capability(int capability) {
|
||||
for (int n = 0; n < __RRM_BEACON_RQST_MODE_MAX; n++) {
|
||||
switch (capability & dawn_metric.rrm_mode_order[n]) {
|
||||
case WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE:
|
||||
return RRM_BEACON_RQST_MODE_PASSIVE;
|
||||
case WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE:
|
||||
return RRM_BEACON_RQST_MODE_ACTIVE;
|
||||
case WLAN_RRM_CAPS_BEACON_REPORT_TABLE:
|
||||
return RRM_BEACON_RQST_MODE_BEACON_TABLE;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ubus_send_beacon_report(client *c, int id)
|
||||
{
|
||||
printf("Crafting Beacon Report\n");
|
||||
int timeout = 1;
|
||||
|
||||
blob_buf_init(&b_beacon, 0);
|
||||
blobmsg_add_macaddr(&b_beacon, "addr", client);
|
||||
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, "duration", dawn_metric.duration);
|
||||
blobmsg_add_u32(&b_beacon, "mode", dawn_metric.mode);
|
||||
blobmsg_add_u32(&b_beacon, "mode", get_mode_from_capability(c->rrm_enabled_capa));
|
||||
printf("Adding string\n");
|
||||
blobmsg_add_string(&b_beacon, "ssid", "");
|
||||
|
||||
|
|
@ -1326,6 +1341,27 @@ void subscribe_to_new_interfaces(const char *hostapd_sock_path) {
|
|||
return;
|
||||
}
|
||||
|
||||
static char get_rrm_mode_char(int val)
|
||||
{
|
||||
switch (val) {
|
||||
case WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE:
|
||||
return 'p';
|
||||
case WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE:
|
||||
return 'a';
|
||||
case WLAN_RRM_CAPS_BEACON_REPORT_TABLE:
|
||||
return 't';
|
||||
}
|
||||
return '?';
|
||||
}
|
||||
|
||||
const static char* get_rrm_mode_string(int *rrm_mode_order) {
|
||||
static char rrm_mode_string [__RRM_BEACON_RQST_MODE_MAX + 1] = {0};
|
||||
|
||||
for (int n = 0; n < __RRM_BEACON_RQST_MODE_MAX && rrm_mode_order[n]; n++)
|
||||
rrm_mode_string[n] = get_rrm_mode_char(rrm_mode_order[n]);
|
||||
return rrm_mode_string;
|
||||
}
|
||||
|
||||
int uci_send_via_network()
|
||||
{
|
||||
void *metric, *times;
|
||||
|
|
@ -1363,7 +1399,7 @@ int uci_send_via_network()
|
|||
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_u32(&b, "mode", dawn_metric.mode);
|
||||
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);
|
||||
|
||||
|
|
@ -1572,7 +1608,7 @@ int ap_get_nr(struct blob_buf *b_local, struct dawn_mac own_bssid_addr, const ch
|
|||
|
||||
for (i = ap_set; i != NULL; i = i->next_ap) {
|
||||
if (mac_is_equal_bb(own_bssid_addr, i->bssid_addr) ||
|
||||
strncmp((char *)i->ssid, ssid, SSID_MAX_LEN)) {
|
||||
strncmp((char *)i->ssid, ssid, SSID_MAX_LEN)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue