From 976f90efc3f08f916d431e8d2892ec70c9d80b5d Mon Sep 17 00:00:00 2001 From: PolynomialDivision Date: Wed, 14 Jun 2017 19:38:29 +0200 Subject: [PATCH] Give hostapd dir as parameter --- files/dawn.config | 1 + files/dawn.init | 6 +++++- src/main.c | 12 ++++++++++-- src/ubus.c | 11 ++++++----- src/ubus.h | 2 +- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/files/dawn.config b/files/dawn.config index 9637436..d539585 100644 --- a/files/dawn.config +++ b/files/dawn.config @@ -2,4 +2,5 @@ config 'settings' 'dawn' option broadcast_ip '192.186.1.255' option broadcast_port '1025' option sort_order 'cfsb' + option hostapd_dir '/var/run/hostapd' option background '0' \ No newline at end of file diff --git a/files/dawn.init b/files/dawn.init index 2ba5819..d28ea87 100755 --- a/files/dawn.init +++ b/files/dawn.init @@ -14,11 +14,15 @@ start_service() local broadcast_ip local broadcast_port + local sort_order + 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 + procd_open_instance echo "$PROG -p $broadcast_port -i $broadcast_ip -o $sort_order" @@ -26,7 +30,7 @@ start_service() 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_set_param stdout 1 procd_set_param stderr 1 diff --git a/src/main.c b/src/main.c index ceb2980..855a622 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,8 @@ #include "networksocket.h" #define BUFSIZE 17 +#define BUFSIZE_DIR 255 + int main(int argc, char **argv) { @@ -14,8 +16,9 @@ int main(int argc, char **argv) char opt_broadcast_ip[BUFSIZE]; char opt_broadcast_port[BUFSIZE]; + char opt_hostapd_dir[BUFSIZE_DIR]; - while ((ch = getopt(argc, argv, "cs:p:i:b:o:")) != -1) { + while ((ch = getopt(argc, argv, "cs:p:i:b:o:h:")) != -1) { switch (ch) { case 's': ubus_socket = optarg; @@ -31,10 +34,14 @@ int main(int argc, char **argv) case 'o': snprintf(sort_string,SORT_NUM,"%s",optarg); printf("sort string: %s\n", sort_string); + case 'h': + snprintf(opt_hostapd_dir,BUFSIZE_DIR,"%s",optarg); + printf("hostapd dir: %s\n", opt_hostapd_dir); default: break; } } + argc -= optind; argv += optind; @@ -53,7 +60,8 @@ int main(int argc, char **argv) pthread_mutex_destroy(&list_mutex); - dawn_init_ubus(ubus_socket); + dawn_init_ubus(ubus_socket, opt_hostapd_dir); + return 0; } \ No newline at end of file diff --git a/src/ubus.c b/src/ubus.c index f989d54..094765e 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -39,7 +39,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj, struct blob_attr *msg); static int add_subscriber(char* name); //int parse_to_probe_req(struct blob_attr *msg, probe_entry* prob_req); -static int subscribe_to_hostapd_interfaces(); +static int subscribe_to_hostapd_interfaces(char* hostapd_dir); static int decide_function(probe_entry* prob_req) { @@ -133,7 +133,7 @@ static int add_subscriber(char* name) return 0; } -static int subscribe_to_hostapd_interfaces() +static int subscribe_to_hostapd_interfaces(char* hostapd_dir) { DIR * dirp; struct dirent * entry; @@ -145,7 +145,7 @@ static int subscribe_to_hostapd_interfaces() return -1; } - dirp = opendir("/var/run/hostapd"); // error handling? + dirp = opendir(hostapd_dir); // error handling? while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_SOCK) { char subscribe_name[256]; @@ -154,10 +154,11 @@ static int subscribe_to_hostapd_interfaces() add_subscriber(subscribe_name); } } + free(hostapd_dir); // free string return 0; } -int dawn_init_ubus(const char *ubus_socket) +int dawn_init_ubus(const char *ubus_socket, char* hostapd_dir) { uloop_init(); signal(SIGPIPE, SIG_IGN); @@ -172,7 +173,7 @@ int dawn_init_ubus(const char *ubus_socket) ubus_add_uloop(ctx); - subscribe_to_hostapd_interfaces(); + subscribe_to_hostapd_interfaces(hostapd_dir); uloop_run(); diff --git a/src/ubus.h b/src/ubus.h index 3d6af65..6dbfe6d 100644 --- a/src/ubus.h +++ b/src/ubus.h @@ -3,7 +3,7 @@ #include "datastorage.h" -int dawn_init_ubus(const char *ubus_socket); +int dawn_init_ubus(const char *ubus_socket, char* hostapd_dir); int parse_to_probe_req(struct blob_attr *msg, probe_entry* prob_req);