diff --git a/files/dawn.config b/files/dawn.config index 2eaef72..a5e8ca1 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -1,6 +1,17 @@ -config 'settings' 'dawn' +config settings network option broadcast_ip '10.0.0.255' option broadcast_port '1025' - option sort_order 'csfb' + +config settings ordering + option sort_order 'csfb' + +config settings hostapd option hostapd_dir '/var/run/hostapd' - option background '0' \ No newline at end of file + +config settings metric + option ht_support '10' + option vht_support '10' + option vht_support '10' + option rssi '10' + option freq '10' + diff --git a/files/dawn.init b/files/dawn.init index 34cdd0b..a9d215e 100755 --- a/files/dawn.init +++ b/files/dawn.init @@ -18,10 +18,10 @@ start_service() local hostapd_dir config_load "${NAME}" - config_get broadcast_ip dawn broadcast_ip - config_get broadcast_port dawn broadcast_port - config_get sort_order dawn sort_order - config_get hostapd_dir dawn hostapd_dir + config_get broadcast_ip network broadcast_ip + config_get broadcast_port network broadcast_port + config_get sort_order ordering sort_order + config_get hostapd_dir hostapd hostapd_dir procd_open_instance diff --git a/files/main b/files/main new file mode 100755 index 0000000..f16feda Binary files /dev/null and b/files/main differ diff --git a/files/main.c b/files/main.c new file mode 100644 index 0000000..00608f4 --- /dev/null +++ b/files/main.c @@ -0,0 +1,33 @@ +#include +#include +#include + + +int main(int argc, char **argv) +{ + config_t cfg; + config_setting_t *root, *setting, *movie; + + config_init(&cfg); + + /* Read the file. If there is an error, report it and exit. */ + if(! config_read_file(&cfg, "dawn.config")) + { + fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), + config_error_line(&cfg), config_error_text(&cfg)); + config_destroy(&cfg); + return(EXIT_FAILURE); + } + + printf("READ CONFIG!!!\n"); + + root = config_root_setting(&cfg); + + int ht_support; + if (config_lookup_int(&cfg, "ht_support", &ht_support)) + printf("Broadcast Port: %d\n\n", ht_support); + else + fprintf(stderr, "No 'name' setting in configuration file.\n"); + + +} \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4417a32..0e9003c 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,12 +29,13 @@ SET(SOURCES utils/runopts.c include/runopts.h - ) + + utils/dawn_uci.c include/dawn_uci.h) SET(LIBS - ubox ubus json-c blobmsg_json config) + ubox ubus json-c blobmsg_json config uci) -ADD_EXECUTABLE(dawn ${SOURCES}) +ADD_EXECUTABLE(dawn ${SOURCES} utils/dawn_uci.c include/dawn_uci.h) TARGET_LINK_LIBRARIES(dawn ${LIBS}) diff --git a/src/include/datastorage.h b/src/include/datastorage.h index 6f0cba9..83c1b47 100644 --- a/src/include/datastorage.h +++ b/src/include/datastorage.h @@ -13,6 +13,18 @@ #define ETH_ALEN 6 #endif +struct probe_metric_s dawn_metric; + +struct probe_metric_s +{ + int ht_support; + int vht_support; + int n_ht_support; + int n_vht_support; + int rssi; + int freq; +}; + #define SORT_NUM 5 #define TIME_THRESHOLD 30 // every minute diff --git a/src/include/dawn_uci.h b/src/include/dawn_uci.h new file mode 100644 index 0000000..8241e9f --- /dev/null +++ b/src/include/dawn_uci.h @@ -0,0 +1,6 @@ +#ifndef DAWN_UCI_H +#define DAWN_UCI_H + +struct probe_metric_s uci_get_dawn_metric(); + +#endif //DAWN_UCI_H_H diff --git a/src/main.c b/src/main.c index 8dc7504..712ce81 100644 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,7 @@ #include "datastorage.h" #include "networksocket.h" #include "ubus.h" +#include "dawn_uci.h" #define BUFSIZE 17 #define BUFSIZE_DIR 255 diff --git a/src/storage/datastorage.c b/src/storage/datastorage.c index f9fbb59..f573f86 100644 --- a/src/storage/datastorage.c +++ b/src/storage/datastorage.c @@ -28,16 +28,6 @@ void remove_old_client_entries(time_t current_time, long long int threshold); int eval_probe_metric(struct client_s client_entry, struct probe_entry_s probe_entry); -struct probe_metric_s -{ - int ht_support; - int vht_support; - int n_ht_support; - int n_vht_support; - int rssi; - int freq; -}; - int kick_client(struct client_s client_entry); int probe_entry_last = -1; @@ -45,7 +35,7 @@ int client_entry_last = -1; int eval_probe_metric(struct client_s client_entry, struct probe_entry_s probe_entry) { - struct probe_metric_s metric = { + /*struct probe_metric_s metric = { .ht_support = 0, .vht_support = 0, .n_ht_support = 0, @@ -53,6 +43,8 @@ int eval_probe_metric(struct client_s client_entry, struct probe_entry_s probe_e .rssi = 0, .freq = 100}; // this is for testing + */ + int score = 0; uint8_t client_supports_ht; @@ -79,13 +71,13 @@ int eval_probe_metric(struct client_s client_entry, struct probe_entry_s probe_e printf("AAAHHHHHHHHHHH IDEAL!!!\n"); } - score += client_supports_vht ? metric.vht_support : metric.n_vht_support; - score += client_supports_ht ? metric.ht_support : metric.n_ht_support; + score += client_supports_vht ? dawn_metric.vht_support : dawn_metric.n_vht_support; + score += client_supports_ht ? dawn_metric.ht_support : dawn_metric.n_ht_support; //score += !client_supports_vht ? metric.n_vht_support : 0; //score += !client_supports_ht ? metric.n_ht_support : 0; - score += (probe_entry.freq > 5000) ? metric.freq : 0; + score += (probe_entry.freq > 5000) ? dawn_metric.freq : 0; //score += (client_entry.signal > -60) ? metric.freq : 0; diff --git a/src/utils/dawn_uci.c b/src/utils/dawn_uci.c new file mode 100644 index 0000000..ef92af8 --- /dev/null +++ b/src/utils/dawn_uci.c @@ -0,0 +1,60 @@ +#include +#include +#include + +#include "dawn_uci.h" + +/* + +dawn.metric.ht_support +dawn.metric.vht_support' +dawn.metric.rssi +dawn.metric.freq + + */ + +struct probe_metric_s uci_get_dawn_metric() +{ + struct probe_metric_s ret; + + struct uci_context *c; + struct uci_ptr ptr; + + 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(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_rssi[] = "dawn.metric.freq"; + 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); + + uci_free_context (c); + + return ret; +} \ No newline at end of file diff --git a/src/utils/ubus.c b/src/utils/ubus.c index e9bd6ab..12cf45a 100644 --- a/src/utils/ubus.c +++ b/src/utils/ubus.c @@ -12,6 +12,7 @@ #include "networksocket.h" #include "utils.h" +#include "dawn_uci.h" static struct ubus_context *ctx; static struct ubus_context *ctx_clients; /* own ubus conext otherwise strange behavior... */ @@ -227,7 +228,7 @@ static int add_subscriber(char *name) { return 0; } -static int subscribe_to_hostapd_interfaces(char *hostapd_dir) { +static int subscribe_to_hostapd_interfaces(char *hostapd_dir) { DIR *dirp; struct dirent *entry; @@ -269,6 +270,9 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) { ubus_add_uloop(ctx); + // set dawn metric + dawn_metric = uci_get_dawn_metric(); + subscribe_to_hostapd_interfaces(hostapd_dir); uloop_run(); @@ -411,6 +415,10 @@ static int ubus_get_clients() { struct dirent *entry; dirp = opendir(hostapd_dir_glob); // error handling? + if(!dirp) { + fprintf(stderr, "No hostapd sockets!\n"); + return -1; + } while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_SOCK) { char hostapd_iface[256]; @@ -480,6 +488,11 @@ void del_client_all_interfaces(const uint8_t *client_addr, uint32_t reason, uint DIR *dirp; struct dirent *entry; dirp = opendir(hostapd_dir_glob); // error handling? + if(!dirp) + { + fprintf(stderr, "No hostapd sockets!\n"); + return; + } while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_SOCK) { char hostapd_iface[256];