Give hostapd dir as parameter

This commit is contained in:
PolynomialDivision 2017-06-14 19:38:29 +02:00
parent 29fe04b1f0
commit 976f90efc3
5 changed files with 23 additions and 9 deletions

View file

@ -2,4 +2,5 @@ config 'settings' 'dawn'
option broadcast_ip '192.186.1.255' option broadcast_ip '192.186.1.255'
option broadcast_port '1025' option broadcast_port '1025'
option sort_order 'cfsb' option sort_order 'cfsb'
option hostapd_dir '/var/run/hostapd'
option background '0' option background '0'

View file

@ -14,11 +14,15 @@ start_service()
local broadcast_ip local broadcast_ip
local broadcast_port local broadcast_port
local sort_order
local hostapd_dir
config_load "${NAME}" config_load "${NAME}"
config_get broadcast_ip dawn broadcast_ip config_get broadcast_ip dawn broadcast_ip
config_get broadcast_port dawn broadcast_port config_get broadcast_port dawn broadcast_port
config_get sort_order dawn sort_order config_get sort_order dawn sort_order
config_get hostapd_dir dawn hostapd_dir
procd_open_instance procd_open_instance
echo "$PROG -p $broadcast_port -i $broadcast_ip -o $sort_order" 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 -p "${broadcast_port}"
procd_append_param command -i "${broadcast_ip}" procd_append_param command -i "${broadcast_ip}"
procd_append_param command -o "${sort_order}" procd_append_param command -o "${sort_order}"
procd_append_param command -h "${hostapd_dir}"
procd_set_param stdout 1 procd_set_param stdout 1
procd_set_param stderr 1 procd_set_param stderr 1

View file

@ -6,6 +6,8 @@
#include "networksocket.h" #include "networksocket.h"
#define BUFSIZE 17 #define BUFSIZE 17
#define BUFSIZE_DIR 255
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -14,8 +16,9 @@ int main(int argc, char **argv)
char opt_broadcast_ip[BUFSIZE]; char opt_broadcast_ip[BUFSIZE];
char opt_broadcast_port[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) { switch (ch) {
case 's': case 's':
ubus_socket = optarg; ubus_socket = optarg;
@ -31,10 +34,14 @@ int main(int argc, char **argv)
case 'o': case 'o':
snprintf(sort_string,SORT_NUM,"%s",optarg); snprintf(sort_string,SORT_NUM,"%s",optarg);
printf("sort string: %s\n", sort_string); 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: default:
break; break;
} }
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
@ -53,7 +60,8 @@ int main(int argc, char **argv)
pthread_mutex_destroy(&list_mutex); pthread_mutex_destroy(&list_mutex);
dawn_init_ubus(ubus_socket);
dawn_init_ubus(ubus_socket, opt_hostapd_dir);
return 0; return 0;
} }

View file

@ -39,7 +39,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
struct blob_attr *msg); struct blob_attr *msg);
static int add_subscriber(char* name); static int add_subscriber(char* name);
//int parse_to_probe_req(struct blob_attr *msg, probe_entry* prob_req); //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) static int decide_function(probe_entry* prob_req)
{ {
@ -133,7 +133,7 @@ static int add_subscriber(char* name)
return 0; return 0;
} }
static int subscribe_to_hostapd_interfaces() static int subscribe_to_hostapd_interfaces(char* hostapd_dir)
{ {
DIR * dirp; DIR * dirp;
struct dirent * entry; struct dirent * entry;
@ -145,7 +145,7 @@ static int subscribe_to_hostapd_interfaces()
return -1; return -1;
} }
dirp = opendir("/var/run/hostapd"); // error handling? dirp = opendir(hostapd_dir); // error handling?
while ((entry = readdir(dirp)) != NULL) { while ((entry = readdir(dirp)) != NULL) {
if (entry->d_type == DT_SOCK) { if (entry->d_type == DT_SOCK) {
char subscribe_name[256]; char subscribe_name[256];
@ -154,10 +154,11 @@ static int subscribe_to_hostapd_interfaces()
add_subscriber(subscribe_name); add_subscriber(subscribe_name);
} }
} }
free(hostapd_dir); // free string
return 0; return 0;
} }
int dawn_init_ubus(const char *ubus_socket) int dawn_init_ubus(const char *ubus_socket, char* hostapd_dir)
{ {
uloop_init(); uloop_init();
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
@ -172,7 +173,7 @@ int dawn_init_ubus(const char *ubus_socket)
ubus_add_uloop(ctx); ubus_add_uloop(ctx);
subscribe_to_hostapd_interfaces(); subscribe_to_hostapd_interfaces(hostapd_dir);
uloop_run(); uloop_run();

View file

@ -3,7 +3,7 @@
#include "datastorage.h" #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); int parse_to_probe_req(struct blob_attr *msg, probe_entry* prob_req);