mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
use uci context
This commit is contained in:
parent
7e46afec1c
commit
8eb7d68e65
12 changed files with 183 additions and 320 deletions
|
@ -1,24 +1,24 @@
|
|||
config settings network
|
||||
config network
|
||||
option broadcast_ip '225.0.0.37'
|
||||
option broadcast_port '1025'
|
||||
option multicast '1'
|
||||
option shared_key 'Niiiiiiiiiiiiiik'
|
||||
option iv 'Niiiiiiiiiiiiiik'
|
||||
|
||||
config settings ordering
|
||||
config ordering
|
||||
option sort_order 'csfb'
|
||||
|
||||
config settings hostapd
|
||||
config hostapd
|
||||
option hostapd_dir '/var/run/hostapd'
|
||||
|
||||
config settings times
|
||||
config times
|
||||
option update_client '10'
|
||||
option remove_client '120'
|
||||
option remove_probe '120'
|
||||
option remove_ap '460'
|
||||
option update_hostapd '10'
|
||||
|
||||
config settings metric
|
||||
config metric
|
||||
option ht_support '10'
|
||||
option vht_support '100'
|
||||
option no_ht_support '0'
|
||||
|
|
|
@ -11,51 +11,10 @@ NAME=dawn
|
|||
start_service()
|
||||
{
|
||||
echo "Starting Service..."
|
||||
|
||||
local broadcast_ip
|
||||
local broadcast_port
|
||||
local sort_order
|
||||
local hostapd_dir
|
||||
local shared_key
|
||||
local iv
|
||||
|
||||
config_load "${NAME}"
|
||||
config_get broadcast_ip network broadcast_ip
|
||||
config_get broadcast_port network broadcast_port
|
||||
config_get shared_key network shared_key
|
||||
config_get iv network iv
|
||||
|
||||
config_get sort_order ordering sort_order
|
||||
config_get hostapd_dir hostapd hostapd_dir
|
||||
|
||||
config_get multicast network multicast
|
||||
|
||||
procd_open_instance
|
||||
echo "$PROG -p $broadcast_port -i $broadcast_ip -o $sort_order"
|
||||
procd_set_param command "$PROG"
|
||||
procd_append_param command -p "${broadcast_port}"
|
||||
procd_append_param command -i "${broadcast_ip}"
|
||||
procd_append_param command -o "${sort_order}"
|
||||
procd_append_param command -h "${hostapd_dir}"
|
||||
procd_append_param command -k "${shared_key}"
|
||||
procd_append_param command -v "${iv}"
|
||||
|
||||
if [ "${multicast}" -gt 0 ]; then
|
||||
procd_append_param command -m
|
||||
fi
|
||||
|
||||
procd_set_param command $PROG
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
|
||||
echo "${command}"
|
||||
|
||||
# procd_set_param respawn
|
||||
|
||||
echo "Starting mdns"
|
||||
procd_add_mdns "dawn" "udp" "${broadcast_port}" "daemon=dawn" "colour=fuschia"
|
||||
|
||||
echo "MDNS Startet"
|
||||
|
||||
procd_close_instance
|
||||
echo "Dawn instance started!"
|
||||
}
|
|
@ -25,7 +25,7 @@ void gcrypt_init() {
|
|||
}
|
||||
}
|
||||
|
||||
void gcrypt_set_key_and_iv(char *key, char *iv) {
|
||||
void gcrypt_set_key_and_iv(const char *key, const char *iv) {
|
||||
size_t keylen = gcry_cipher_get_algo_keylen(GCRY_CIPHER);
|
||||
size_t blklen = gcry_cipher_get_algo_blklen(GCRY_CIPHER);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ char *unbase_64(unsigned char *input, int length);
|
|||
|
||||
void gcrypt_init();
|
||||
|
||||
void gcrypt_set_key_and_iv(char *key, char *iv);
|
||||
void gcrypt_set_key_and_iv(const char *key, const char *iv);
|
||||
|
||||
//char *gcrypt_encrypt_msg(char *msg, size_t msg_length);
|
||||
char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int *out_length);
|
||||
|
|
|
@ -45,6 +45,15 @@ struct time_config_s {
|
|||
time_t update_hostapd;
|
||||
};
|
||||
|
||||
struct network_config_s {
|
||||
const char* broadcast_ip;
|
||||
int broadcast_port;
|
||||
const char* multicast;
|
||||
const char* shared_key;
|
||||
const char* iv;
|
||||
int bool_multicast;
|
||||
};
|
||||
|
||||
struct time_config_s timeout_config;
|
||||
|
||||
// ---------------- Global variables ----------------
|
||||
|
@ -173,7 +182,7 @@ ap ap_array_get_ap(uint8_t bssid_addr[]);
|
|||
#define TIME_THRESHOLD 120 // every minute
|
||||
|
||||
// ---------------- Global variables ----------------
|
||||
char sort_string[SORT_NUM];
|
||||
char* sort_string;
|
||||
|
||||
// ---------------- Functions -------------------
|
||||
int mac_is_equal(uint8_t addr1[], uint8_t addr2[]);
|
||||
|
|
|
@ -5,4 +5,14 @@ struct probe_metric_s uci_get_dawn_metric();
|
|||
|
||||
struct time_config_s uci_get_time_config();
|
||||
|
||||
struct network_config_s uci_get_dawn_network();
|
||||
|
||||
const char* uci_get_dawn_hostapd_dir();
|
||||
|
||||
const char* uci_get_dawn_sort_order();
|
||||
|
||||
int uci_init();
|
||||
|
||||
int uci_clear();
|
||||
|
||||
#endif //DAWN_UCI_H_H
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
pthread_mutex_t send_mutex;
|
||||
|
||||
int init_socket_runopts(char *_ip, char *_port, int _multicast_socket);
|
||||
int init_socket_runopts(const char *_ip, int _port, int _multicast_socket);
|
||||
|
||||
int send_string(char *msg);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#define MIN_PROBE_REQ 2 // TODO: Parse from config file...
|
||||
|
||||
int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir);
|
||||
int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir);
|
||||
|
||||
int parse_to_probe_req(struct blob_attr *msg, probe_entry *prob_req);
|
||||
|
||||
|
@ -24,7 +24,7 @@ void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint
|
|||
|
||||
void *update_clients_thread(void *arg);
|
||||
|
||||
char *hostapd_dir_glob;
|
||||
const char *hostapd_dir_glob;
|
||||
|
||||
int ubus_call_umdns();
|
||||
|
||||
|
|
70
src/main.c
70
src/main.c
|
@ -8,6 +8,7 @@
|
|||
#include "networksocket.h"
|
||||
#include "ubus.h"
|
||||
#include "dawn_uci.h"
|
||||
#include "dawn_uci.h"
|
||||
#include "crypto.h"
|
||||
|
||||
#define BUFSIZE 17
|
||||
|
@ -22,6 +23,7 @@ struct sigaction newSigAction;
|
|||
void daemon_shutdown() {
|
||||
// kill threads
|
||||
close_socket();
|
||||
uci_clear();
|
||||
printf("Cancelling Threads!\n");
|
||||
uloop_cancelled = true;
|
||||
|
||||
|
@ -52,74 +54,32 @@ int main(int argc, char **argv) {
|
|||
//free_counter = 0;
|
||||
|
||||
const char *ubus_socket = NULL;
|
||||
int ch;
|
||||
|
||||
char opt_broadcast_ip[BUFSIZE];
|
||||
char opt_broadcast_port[BUFSIZE];
|
||||
char opt_hostapd_dir[BUFSIZE_DIR];
|
||||
|
||||
char shared_key[BUFSIZE_DIR];
|
||||
char iv[BUFSIZE_DIR];
|
||||
int multicast = 0;
|
||||
|
||||
while ((ch = getopt(argc, argv, "cs:p:i:b:o:h:i:k:v:m")) != -1) {
|
||||
switch (ch) {
|
||||
case 's':
|
||||
ubus_socket = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
snprintf(opt_broadcast_port, BUFSIZE, "%s", optarg);
|
||||
printf("broadcast port: %s\n", opt_broadcast_port);
|
||||
break;
|
||||
case 'i':
|
||||
snprintf(opt_broadcast_ip, BUFSIZE, "%s", optarg);
|
||||
printf("broadcast ip: %s\n", opt_broadcast_ip);
|
||||
break;
|
||||
case 'o':
|
||||
snprintf(sort_string, SORT_NUM, "%s", optarg);
|
||||
printf("sort string: %s\n", sort_string);
|
||||
break;
|
||||
case 'h':
|
||||
snprintf(opt_hostapd_dir, BUFSIZE_DIR, "%s", optarg);
|
||||
printf("hostapd dir: %s\n", opt_hostapd_dir);
|
||||
hostapd_dir_glob = optarg;
|
||||
break;
|
||||
case 'k':
|
||||
snprintf(shared_key, BUFSIZE_DIR, "%s", optarg);
|
||||
printf("Key: %s\n", shared_key);
|
||||
break;
|
||||
case 'v':
|
||||
snprintf(iv, BUFSIZE_DIR, "%s", optarg);
|
||||
printf("IV: %s\n", iv);
|
||||
break;
|
||||
case 'm':
|
||||
multicast = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// int ch;
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
/* Set up a signal handler */
|
||||
newSigAction.sa_handler = signal_handler;
|
||||
sigemptyset(&newSigAction.sa_mask);
|
||||
newSigAction.sa_flags = 0;
|
||||
|
||||
/* Signals to handle */
|
||||
sigaction(SIGHUP, &newSigAction, NULL); /* catch hangup signal */
|
||||
sigaction(SIGTERM, &newSigAction, NULL); /* catch term signal */
|
||||
sigaction(SIGINT, &newSigAction, NULL); /* catch interrupt signal */
|
||||
sigaction(SIGHUP, &newSigAction, NULL);
|
||||
sigaction(SIGTERM, &newSigAction, NULL);
|
||||
sigaction(SIGINT, &newSigAction, NULL);
|
||||
|
||||
uci_init();
|
||||
struct network_config_s net_config = uci_get_dawn_network();
|
||||
printf("Broadcst bla: %s\n", net_config.broadcast_ip);
|
||||
|
||||
gcrypt_init();
|
||||
gcrypt_set_key_and_iv(shared_key, iv);
|
||||
gcrypt_set_key_and_iv(net_config.shared_key, net_config.iv);
|
||||
|
||||
struct time_config_s time_config = uci_get_time_config();
|
||||
timeout_config = time_config; // TODO: Refactor...
|
||||
|
||||
hostapd_dir_glob = uci_get_dawn_hostapd_dir();
|
||||
sort_string = (char*) uci_get_dawn_sort_order();
|
||||
|
||||
if (pthread_mutex_init(&list_mutex, NULL) != 0) {
|
||||
printf("\n mutex init failed\n");
|
||||
return 1;
|
||||
|
@ -140,9 +100,9 @@ int main(int argc, char **argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, multicast);
|
||||
init_socket_runopts(net_config.broadcast_ip, net_config.broadcast_port, net_config.bool_multicast);
|
||||
|
||||
dawn_init_ubus(ubus_socket, opt_hostapd_dir);
|
||||
dawn_init_ubus(ubus_socket, hostapd_dir_glob);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -35,9 +35,9 @@ void *receive_msg(void *args);
|
|||
|
||||
void *receive_msg_enc(void *args);
|
||||
|
||||
int init_socket_runopts(char *_ip, char *_port, int _multicast_socket) {
|
||||
int init_socket_runopts(const char *_ip, int _port, int _multicast_socket) {
|
||||
|
||||
port = atoi(_port);
|
||||
port = _port;
|
||||
ip = _ip;
|
||||
multicast_socket = _multicast_socket;
|
||||
|
||||
|
|
|
@ -4,76 +4,38 @@
|
|||
|
||||
#include "dawn_uci.h"
|
||||
|
||||
/*
|
||||
|
||||
dawn.metric.ht_support
|
||||
dawn.metric.vht_support'
|
||||
dawn.metric.rssi
|
||||
dawn.metric.freq
|
||||
static struct uci_context *uci_ctx;
|
||||
static struct uci_package *uci_pkg;
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
config settings times
|
||||
option update_client '50'
|
||||
option remove_client '120'
|
||||
option remove_probe '120'
|
||||
*/
|
||||
// why is this not included in uci lib...?!
|
||||
// fund here: https://github.com/br101/pingcheck/blob/master/uci.c
|
||||
static int uci_lookup_option_int(struct uci_context *uci, struct uci_section *s,
|
||||
const char *name)
|
||||
{
|
||||
const char* str = uci_lookup_option_string(uci, s, name);
|
||||
return str == NULL ? -1 : atoi(str);
|
||||
}
|
||||
|
||||
struct time_config_s uci_get_time_config() {
|
||||
struct time_config_s ret;
|
||||
|
||||
struct uci_context *c;
|
||||
struct uci_ptr ptr;
|
||||
printf("Loading Times!");
|
||||
|
||||
c = uci_alloc_context();
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
printf("Loading TImes!");
|
||||
|
||||
|
||||
char tmp_update_client[] = "dawn.times.update_client";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_update_client, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
if (strcmp(s->type, "times") == 0)
|
||||
{
|
||||
ret.update_client = uci_lookup_option_int(uci_ctx, s, "update_client");
|
||||
ret.remove_client = uci_lookup_option_int(uci_ctx, s, "remove_client");
|
||||
ret.remove_probe = uci_lookup_option_int(uci_ctx, s, "remove_probe");
|
||||
ret.update_hostapd = uci_lookup_option_int(uci_ctx, s, "update_hostapd");
|
||||
ret.remove_ap = uci_lookup_option_int(uci_ctx, s, "remove_ap");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.update_client = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_remove_client[] = "dawn.times.remove_client";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_remove_client, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.remove_client = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_remove_probe[] = "dawn.times.remove_probe";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_remove_probe, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.remove_probe = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_update_hostapd[] = "dawn.times.update_hostapd";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_update_hostapd, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.update_hostapd = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_remove_ap[] = "dawn.times.remove_ap";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_remove_ap, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.remove_ap = atoi(ptr.o->v.string);
|
||||
|
||||
printf("Times: %lu, %lu, %lu %lu\n", ret.update_client, ret.remove_client, ret.remove_probe, ret.update_hostapd);
|
||||
|
||||
uci_free_context(c);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -81,153 +43,116 @@ struct time_config_s uci_get_time_config() {
|
|||
struct probe_metric_s uci_get_dawn_metric() {
|
||||
struct probe_metric_s ret;
|
||||
|
||||
struct uci_context *c;
|
||||
struct uci_ptr ptr;
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
c = uci_alloc_context();
|
||||
|
||||
char tmp_ht_support[] = "dawn.metric.ht_support";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_ht_support, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
if (strcmp(s->type, "metric") == 0)
|
||||
{
|
||||
ret.ht_support = uci_lookup_option_int(uci_ctx, s, "ht_support");
|
||||
ret.vht_support = uci_lookup_option_int(uci_ctx, s, "vht_support");
|
||||
ret.no_ht_support = uci_lookup_option_int(uci_ctx, s, "no_ht_support");
|
||||
ret.no_vht_support = uci_lookup_option_int(uci_ctx, s, "no_vht_support");
|
||||
ret.rssi = uci_lookup_option_int(uci_ctx, s, "rssi");
|
||||
ret.freq = uci_lookup_option_int(uci_ctx, s, "freq");
|
||||
ret.rssi_val = uci_lookup_option_int(uci_ctx, s, "rssi_val");
|
||||
ret.chan_util = uci_lookup_option_int(uci_ctx, s, "chan_util");
|
||||
ret.max_chan_util = uci_lookup_option_int(uci_ctx, s, "max_chan_util");
|
||||
ret.chan_util_val = uci_lookup_option_int(uci_ctx, s, "chan_util_val");
|
||||
ret.max_chan_util_val = uci_lookup_option_int(uci_ctx, s, "max_chan_util_val");
|
||||
ret.min_probe_count = uci_lookup_option_int(uci_ctx, s, "min_probe_count");
|
||||
ret.low_rssi = uci_lookup_option_int(uci_ctx, s, "low_rssi");
|
||||
ret.low_rssi_val = uci_lookup_option_int(uci_ctx, s, "low_rssi_val");
|
||||
ret.bandwith_threshold = uci_lookup_option_int(uci_ctx, s, "bandwith_threshold");
|
||||
ret.use_station_count = uci_lookup_option_int(uci_ctx, s, "use_station_count");
|
||||
ret.eval_probe_req = uci_lookup_option_int(uci_ctx, s, "eval_probe_req");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.ht_support = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_vht_support[] = "dawn.metric.vht_support";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_vht_support, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.vht_support = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_no_ht_support[] = "dawn.metric.no_ht_support";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_no_ht_support, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.no_ht_support = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_no_vht_support[] = "dawn.metric.no_vht_support";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_no_vht_support, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.no_vht_support = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_rssi[] = "dawn.metric.rssi";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_rssi, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.rssi = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_freq[] = "dawn.metric.freq";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_freq, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.freq = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_util[] = "dawn.metric.chan_util";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_util, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.chan_util = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_rssi_val[] = "dawn.metric.rssi_val";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_rssi_val, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.rssi_val = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_max_chan_util[] = "dawn.metric.max_chan_util";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_max_chan_util, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.max_chan_util = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_chan_util_val[] = "dawn.metric.chan_util_val";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_chan_util_val, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.chan_util_val = atoi(ptr.o->v.string);
|
||||
|
||||
|
||||
char tmp_max_chan_util_val[] = "dawn.metric.max_chan_util_val";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_max_chan_util_val, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.max_chan_util_val = atoi(ptr.o->v.string);
|
||||
|
||||
|
||||
printf("Try to load min_probe_count\n");
|
||||
char tmp_min_probe_count[] = "dawn.metric.min_probe_count";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_min_probe_count, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.min_probe_count = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_low_rssi[] = "dawn.metric.low_rssi";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_low_rssi, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.low_rssi = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_low_rssi_val[] = "dawn.metric.low_rssi_val";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_low_rssi_val, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.low_rssi_val = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_bandwith_threshold[] = "dawn.metric.bandwith_threshold";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_bandwith_threshold, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.bandwith_threshold = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_use_station_count[] = "dawn.metric.use_station_count";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_use_station_count, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.use_station_count = atoi(ptr.o->v.string);
|
||||
|
||||
char tmp_eval_probe_req[] = "dawn.metric.eval_probe_req";
|
||||
if (uci_lookup_ptr(c, &ptr, tmp_eval_probe_req, 1) != UCI_OK) {
|
||||
uci_perror(c, "uci_get_daw_metric Error");
|
||||
return ret;
|
||||
}
|
||||
if (ptr.o->type == UCI_TYPE_STRING)
|
||||
ret.eval_probe_req = atoi(ptr.o->v.string);
|
||||
|
||||
printf("Loaded metric: %d\n", ret.min_probe_count);
|
||||
|
||||
uci_free_context(c);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct network_config_s uci_get_dawn_network() {
|
||||
struct network_config_s ret;
|
||||
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "network") == 0)
|
||||
{
|
||||
printf("Fronund network entry!\n");
|
||||
ret.broadcast_ip = uci_lookup_option_string(uci_ctx, s, "broadcast_ip");
|
||||
printf("BROADCAST: %s\n", ret.broadcast_ip);
|
||||
ret.broadcast_port = uci_lookup_option_int(uci_ctx, s, "broadcast_port");
|
||||
ret.bool_multicast = uci_lookup_option_int(uci_ctx, s, "multicast");
|
||||
printf("multicast: %s\n", ret.broadcast_ip);
|
||||
ret.shared_key = uci_lookup_option_string(uci_ctx, s, "shared_key");
|
||||
ret.iv = uci_lookup_option_string(uci_ctx, s, "iv");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
const char* uci_get_dawn_hostapd_dir() {
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "hostapd") == 0) {
|
||||
return uci_lookup_option_string(uci_ctx, s, "hostapd_dir");
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* uci_get_dawn_sort_order() {
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
struct uci_section *s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "ordering") == 0)
|
||||
{
|
||||
return uci_lookup_option_string(uci_ctx, s, "sort_order");
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int uci_init()
|
||||
{
|
||||
struct uci_context *ctx = uci_ctx;
|
||||
|
||||
if (!ctx) {
|
||||
ctx = uci_alloc_context();
|
||||
uci_ctx = ctx;
|
||||
|
||||
ctx->flags &= ~UCI_FLAG_STRICT;
|
||||
} else {
|
||||
// shouldn't happen?
|
||||
uci_pkg = uci_lookup_package(ctx, "dawn");
|
||||
if (uci_pkg)
|
||||
uci_unload(ctx, uci_pkg);
|
||||
}
|
||||
|
||||
if (uci_load(ctx, "dawn", &uci_pkg))
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int uci_clear()
|
||||
{
|
||||
if(uci_pkg != NULL)
|
||||
{
|
||||
uci_unload(uci_ctx, uci_pkg);
|
||||
}
|
||||
if(uci_ctx != NULL)
|
||||
{
|
||||
uci_free_context(uci_ctx);
|
||||
}
|
||||
return 1;
|
||||
}
|
|
@ -133,7 +133,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
static int add_subscriber(char *name);
|
||||
|
||||
static int subscribe_to_hostapd_interfaces(char *hostapd_dir);
|
||||
static int subscribe_to_hostapd_interfaces(const char *hostapd_dir);
|
||||
|
||||
static int ubus_get_clients();
|
||||
|
||||
|
@ -392,7 +392,7 @@ static int add_subscriber(char *name) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int subscribe_to_hostapd_interfaces(char *hostapd_dir) {
|
||||
static int subscribe_to_hostapd_interfaces(const char *hostapd_dir) {
|
||||
DIR *dirp;
|
||||
struct dirent *entry;
|
||||
|
||||
|
@ -416,7 +416,7 @@ static int subscribe_to_hostapd_interfaces(char *hostapd_dir) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int subscribe_to_hostapd(char *hostapd_dir) {
|
||||
static int subscribe_to_hostapd(const char *hostapd_dir) {
|
||||
|
||||
if (ctx == NULL) {
|
||||
return 0;
|
||||
|
@ -440,7 +440,7 @@ static int subscribe_to_hostapd(char *hostapd_dir) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) {
|
||||
int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) {
|
||||
uloop_init();
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue