From 63a1432652c6afa5c1fdc3c7d207c6d9744d3a50 Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Mon, 31 Jul 2017 19:59:20 +0200 Subject: [PATCH] Change config file --- files/dawn.config | 17 +++++++++-- files/dawn.init | 8 ++--- files/main | Bin 0 -> 9040 bytes files/main.c | 33 +++++++++++++++++++++ src/CMakeLists.txt | 7 +++-- src/include/datastorage.h | 12 ++++++++ src/include/dawn_uci.h | 6 ++++ src/main.c | 1 + src/storage/datastorage.c | 20 ++++--------- src/utils/dawn_uci.c | 60 ++++++++++++++++++++++++++++++++++++++ src/utils/ubus.c | 15 +++++++++- 11 files changed, 154 insertions(+), 25 deletions(-) create mode 100755 files/main create mode 100644 files/main.c create mode 100644 src/include/dawn_uci.h create mode 100644 src/utils/dawn_uci.c 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 0000000000000000000000000000000000000000..f16feda5900aa35d19847657c262c1725d54eaf5 GIT binary patch literal 9040 zcmeHMeQaCR6~DIg;ij$QLZN9|(Z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J)xHDp%WxN>@{ihOu6a}dw{t0fAEbMifZ1+H;N6ex>70H}0Q5g3-XF2; zWDh4nPItl^?}lVg=lQduqIADBv<)AWM!pXoyxWmIo%=6U8d~(-5n`?!(%%nicvmD@ zs*<^(Brd#kzqHoh@Xi>X=dh||Pxpu(i#?TZZT};}-Y*8Gd9{bE{{{&#z zuR=Zde@;SNnCadRDx9#cX3BtIwx|2cjIcjuR)(}&$i%;4v8Q{EEGkO%B{x?2+ZKDe z5A_JeA?jF5x#aJ=7JG_^JX2$6P+WlYt?mDzu%}|?YGkfDC+u;2&19|r&ma@~kL>9l zM*kj^&~fBNAeX&AV%$<6zAfJGWHS~3hsc)WBr>f zIN9&8;HZm49RJ&=vU!GhJuEg3jG>#!B62@8_sx38Mg1kQk6Z_tTi~Jg)Bca^vsC%# NL;&zd7U$OT{{_3~h(Z7W literal 0 HcmV?d00001 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];