mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
uci: fix loading of config
This commit is contained in:
parent
b5043ad98e
commit
71536468ff
6 changed files with 38 additions and 23 deletions
|
@ -82,15 +82,16 @@ struct time_config_s {
|
||||||
time_t update_beacon_reports;
|
time_t update_beacon_reports;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define MAX_IP_LENGTH 46
|
||||||
|
#define MAX_KEY_LENGTH 65
|
||||||
|
|
||||||
struct network_config_s {
|
struct network_config_s {
|
||||||
const char *broadcast_ip;
|
char broadcast_ip[MAX_IP_LENGTH];
|
||||||
int broadcast_port;
|
int broadcast_port;
|
||||||
int tcp_port;
|
int tcp_port;
|
||||||
int network_option;
|
int network_option;
|
||||||
const char *multicast;
|
char shared_key[MAX_KEY_LENGTH];
|
||||||
const char *shared_key;
|
char iv[MAX_KEY_LENGTH];
|
||||||
const char *iv;
|
|
||||||
int bool_multicast;
|
|
||||||
int use_symm_enc;
|
int use_symm_enc;
|
||||||
int collision_domain;
|
int collision_domain;
|
||||||
int bandwidth;
|
int bandwidth;
|
||||||
|
@ -280,7 +281,8 @@ void send_beacon_reports(uint8_t bssid[], int id);
|
||||||
#define SORT_NUM 5
|
#define SORT_NUM 5
|
||||||
|
|
||||||
// ---------------- Global variables ----------------
|
// ---------------- Global variables ----------------
|
||||||
char *sort_string;
|
#define SORT_LENGTH 5
|
||||||
|
char sort_string[SORT_LENGTH];
|
||||||
|
|
||||||
// ---------------- Functions -------------------
|
// ---------------- Functions -------------------
|
||||||
int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], char* neighbor_report, int automatic_kick);
|
int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], char* neighbor_report, int automatic_kick);
|
||||||
|
|
|
@ -35,13 +35,13 @@ struct network_config_s uci_get_dawn_network();
|
||||||
* Function that returns the hostapd directory reading from the config file.
|
* Function that returns the hostapd directory reading from the config file.
|
||||||
* @return the hostapd directory.
|
* @return the hostapd directory.
|
||||||
*/
|
*/
|
||||||
const char *uci_get_dawn_hostapd_dir();
|
bool uci_get_dawn_hostapd_dir();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function that returns the sort order.
|
* Function that returns the sort order.
|
||||||
* @return the sort order.
|
* @return the sort order.
|
||||||
*/
|
*/
|
||||||
const char *uci_get_dawn_sort_order();
|
bool uci_get_dawn_sort_order();
|
||||||
|
|
||||||
int uci_set_network(char* uci_cmd);
|
int uci_set_network(char* uci_cmd);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
#define UNSPECIFIED_REASON 0
|
#define UNSPECIFIED_REASON 0
|
||||||
#define NO_MORE_STAS 5
|
#define NO_MORE_STAS 5
|
||||||
|
|
||||||
const char *hostapd_dir_glob;
|
#define HOSTAPD_DIR_LEN 200
|
||||||
|
char hostapd_dir_glob[HOSTAPD_DIR_LEN];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init ubus.
|
* Init ubus.
|
||||||
|
|
|
@ -99,8 +99,8 @@ int main(int argc, char **argv) {
|
||||||
struct time_config_s time_config = uci_get_time_config();
|
struct time_config_s time_config = uci_get_time_config();
|
||||||
timeout_config = time_config; // TODO: Refactor...
|
timeout_config = time_config; // TODO: Refactor...
|
||||||
|
|
||||||
hostapd_dir_glob = uci_get_dawn_hostapd_dir();
|
uci_get_dawn_hostapd_dir();
|
||||||
sort_string = (char *) uci_get_dawn_sort_order();
|
uci_get_dawn_sort_order();
|
||||||
|
|
||||||
init_mutex();
|
init_mutex();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <uci.h>
|
#include <uci.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <datastorage.h>
|
#include <datastorage.h>
|
||||||
|
#include <ubus.h>
|
||||||
|
|
||||||
#include "dawn_uci.h"
|
#include "dawn_uci.h"
|
||||||
|
|
||||||
|
@ -91,6 +92,7 @@ struct probe_metric_s uci_get_dawn_metric() {
|
||||||
|
|
||||||
struct network_config_s uci_get_dawn_network() {
|
struct network_config_s uci_get_dawn_network() {
|
||||||
struct network_config_s ret;
|
struct network_config_s ret;
|
||||||
|
memset(&ret, 0, sizeof(ret));
|
||||||
|
|
||||||
struct uci_element *e;
|
struct uci_element *e;
|
||||||
uci_foreach_element(&uci_pkg->sections, e)
|
uci_foreach_element(&uci_pkg->sections, e)
|
||||||
|
@ -98,11 +100,17 @@ struct network_config_s uci_get_dawn_network() {
|
||||||
struct uci_section *s = uci_to_section(e);
|
struct uci_section *s = uci_to_section(e);
|
||||||
|
|
||||||
if (strcmp(s->type, "network") == 0) {
|
if (strcmp(s->type, "network") == 0) {
|
||||||
ret.broadcast_ip = uci_lookup_option_string(uci_ctx, s, "broadcast_ip");
|
const char* str_broadcast = uci_lookup_option_string(uci_ctx, s, "broadcast_ip");
|
||||||
|
strncpy(ret.broadcast_ip, str_broadcast, MAX_IP_LENGTH);
|
||||||
|
|
||||||
ret.broadcast_port = uci_lookup_option_int(uci_ctx, s, "broadcast_port");
|
ret.broadcast_port = uci_lookup_option_int(uci_ctx, s, "broadcast_port");
|
||||||
ret.bool_multicast = uci_lookup_option_int(uci_ctx, s, "multicast");
|
|
||||||
ret.shared_key = uci_lookup_option_string(uci_ctx, s, "shared_key");
|
const char* str_shared_key = uci_lookup_option_string(uci_ctx, s, "shared_key");
|
||||||
ret.iv = uci_lookup_option_string(uci_ctx, s, "iv");
|
strncpy(ret.shared_key, str_shared_key, MAX_KEY_LENGTH);
|
||||||
|
|
||||||
|
const char* str_iv = uci_lookup_option_string(uci_ctx, s, "iv");
|
||||||
|
strncpy(ret.iv, str_iv, MAX_KEY_LENGTH);
|
||||||
|
|
||||||
ret.network_option = uci_lookup_option_int(uci_ctx, s, "network_option");
|
ret.network_option = uci_lookup_option_int(uci_ctx, s, "network_option");
|
||||||
ret.tcp_port = uci_lookup_option_int(uci_ctx, s, "tcp_port");
|
ret.tcp_port = uci_lookup_option_int(uci_ctx, s, "tcp_port");
|
||||||
ret.use_symm_enc = uci_lookup_option_int(uci_ctx, s, "use_symm_enc");
|
ret.use_symm_enc = uci_lookup_option_int(uci_ctx, s, "use_symm_enc");
|
||||||
|
@ -115,30 +123,34 @@ struct network_config_s uci_get_dawn_network() {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *uci_get_dawn_hostapd_dir() {
|
bool uci_get_dawn_hostapd_dir() {
|
||||||
struct uci_element *e;
|
struct uci_element *e;
|
||||||
uci_foreach_element(&uci_pkg->sections, e)
|
uci_foreach_element(&uci_pkg->sections, e)
|
||||||
{
|
{
|
||||||
struct uci_section *s = uci_to_section(e);
|
struct uci_section *s = uci_to_section(e);
|
||||||
|
|
||||||
if (strcmp(s->type, "hostapd") == 0) {
|
if (strcmp(s->type, "hostapd") == 0) {
|
||||||
return uci_lookup_option_string(uci_ctx, s, "hostapd_dir");
|
const char* str = uci_lookup_option_string(uci_ctx, s, "hostapd_dir");
|
||||||
|
strncpy(hostapd_dir_glob, str, HOSTAPD_DIR_LEN);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *uci_get_dawn_sort_order() {
|
bool uci_get_dawn_sort_order() {
|
||||||
struct uci_element *e;
|
struct uci_element *e;
|
||||||
uci_foreach_element(&uci_pkg->sections, e)
|
uci_foreach_element(&uci_pkg->sections, e)
|
||||||
{
|
{
|
||||||
struct uci_section *s = uci_to_section(e);
|
struct uci_section *s = uci_to_section(e);
|
||||||
|
|
||||||
if (strcmp(s->type, "ordering") == 0) {
|
if (strcmp(s->type, "ordering") == 0) {
|
||||||
return uci_lookup_option_string(uci_ctx, s, "sort_order");
|
const char* str = uci_lookup_option_string(uci_ctx, s, "sort_order");
|
||||||
|
strncpy(sort_string, str, SORT_LENGTH);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uci_reset()
|
int uci_reset()
|
||||||
|
|
|
@ -1485,8 +1485,8 @@ static int reload_config(struct ubus_context *ctx, struct ubus_object *obj,
|
||||||
uci_reset();
|
uci_reset();
|
||||||
dawn_metric = uci_get_dawn_metric();
|
dawn_metric = uci_get_dawn_metric();
|
||||||
timeout_config = uci_get_time_config();
|
timeout_config = uci_get_time_config();
|
||||||
hostapd_dir_glob = uci_get_dawn_hostapd_dir();
|
uci_get_dawn_hostapd_dir();
|
||||||
sort_string = (char *) uci_get_dawn_sort_order();
|
uci_get_dawn_sort_order();
|
||||||
|
|
||||||
if(timeout_config.update_beacon_reports) // allow setting timeout to 0
|
if(timeout_config.update_beacon_reports) // allow setting timeout to 0
|
||||||
uloop_timeout_add(&beacon_reports_timer);
|
uloop_timeout_add(&beacon_reports_timer);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue