From 93bbd53481b39a0bc602127c3d4b9552c981a355 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Mon, 16 Jul 2018 12:27:43 +0200 Subject: [PATCH] add init.d + fix init option in *.h --- wireless/wifictld/Makefile | 6 +++-- wireless/wifictld/files/etc/init.d/wifictld | 27 +++++++++++++++++++++ wireless/wifictld/src/log.c | 7 +++--- wireless/wifictld/src/log.h | 2 +- wireless/wifictld/src/ubus_events.c | 25 +++++++++---------- wireless/wifictld/src/ubus_events.h | 2 +- wireless/wifictld/src/wifi_clients.c | 23 ++++++++++++------ wireless/wifictld/src/wifi_clients.h | 4 ++- wireless/wifictld/src/wifictld.c | 15 ++++++++++-- 9 files changed, 80 insertions(+), 31 deletions(-) create mode 100644 wireless/wifictld/files/etc/init.d/wifictld diff --git a/wireless/wifictld/Makefile b/wireless/wifictld/Makefile index f614d8a..03ab0c9 100644 --- a/wireless/wifictld/Makefile +++ b/wireless/wifictld/Makefile @@ -9,7 +9,7 @@ PKG_LICENSE:=APGL include $(INCLUDE_DIR)/package.mk -TARGET_CFLAGS += -DDEBUG +#TARGET_CFLAGS += -DDEBUG define Package/wifictld/Default SECTION:=net @@ -27,7 +27,7 @@ endef define Package/wifictld-mini $(call Package/wifictld/Default) - TITLE+= (local) + TITLE+= (mini) VARIANT:=mini TARGET_CFLAGS += -DMINI endef @@ -54,6 +54,8 @@ endef define Package/wifictld/install $(INSTALL_DIR) $(1)/usr/sbin/ $(INSTALL_BIN) $(PKG_BUILD_DIR)/wifictld $(1)/usr/sbin/ + $(INSTALL_DIR) $(1)/etc/init.d/ + $(INSTALL_BIN) ./files/etc/init.d/wifictld $(1)/etc/init.d/ endef Package/wifictld-mini/install = $(Package/hostapd/install) diff --git a/wireless/wifictld/files/etc/init.d/wifictld b/wireless/wifictld/files/etc/init.d/wifictld new file mode 100644 index 0000000..6990313 --- /dev/null +++ b/wireless/wifictld/files/etc/init.d/wifictld @@ -0,0 +1,27 @@ +#!/bin/sh /etc/rc.common + +START=55 + +USE_PROCD=1 +PROG=/usr/sbin/wifictld + +start_service () { + procd_open_instance + [ -e /proc/sys/kernel/core_pattern ] && { + procd_set_param limits core="unlimited" + } + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_set_param respawn ${respawn_threshold:-3660} ${respawn_timeout:-5} ${respawn_retry:-0} + procd_set_param command "$PROG" + procd_close_instance +} + +service_triggers() { + local script=$(readlink "$initscript") + local name=$(basename "${script:-$initscript}") + + procd_open_trigger + procd_add_raw_trigger "hostapd.*" 0 "/etc/init.d/$name" reload + procd_close_trigger +} diff --git a/wireless/wifictld/src/log.c b/wireless/wifictld/src/log.c index c70614d..5243fc9 100644 --- a/wireless/wifictld/src/log.c +++ b/wireless/wifictld/src/log.c @@ -2,11 +2,13 @@ #include #include "log.h" +int verbose = 0; + #ifdef DEBUG void log_debug(const char *format, ...) { va_list args; va_start(args, format); - vfprintf(stderr, format, args); + vprintf(format, args); va_end(args); } #else @@ -14,9 +16,8 @@ void log_debug(const char *format, ...) { } #endif - void log_verbose(const char *format, ...) { - if (verbose) + if (!verbose) return; va_list args; va_start(args, format); diff --git a/wireless/wifictld/src/log.h b/wireless/wifictld/src/log.h index 9e5846f..454917f 100644 --- a/wireless/wifictld/src/log.h +++ b/wireless/wifictld/src/log.h @@ -1,7 +1,7 @@ #ifndef __WIFICTLD_LOG_H #define __WIFICTLD_LOG_H -static int verbose = 0; +extern int verbose; void log_info(const char *format, ...); void log_verbose(const char *format, ...); diff --git a/wireless/wifictld/src/ubus_events.c b/wireless/wifictld/src/ubus_events.c index 7a6f7ff..e2fa8bd 100644 --- a/wireless/wifictld/src/ubus_events.c +++ b/wireless/wifictld/src/ubus_events.c @@ -8,6 +8,8 @@ #include "wifi_clients.h" #include "ubus_events.h" +int client_probe_learning = 0; + static struct blob_buf b; static struct ubus_context *ctx_main; @@ -120,26 +122,23 @@ static int receive_notify(struct ubus_context *ctx, struct ubus_object *obj, str // handle log_debug("ubus_events.receive_notify(): handle\n"); - if (!strcmp(method, "probe")) { - log_verbose("probe["MACSTR"]", MAC2STR(addr)); - if (client_probe_learning) { - log_verbose(" + learn freq[%d]\n", freq); - wifi_clients_learn(addr, freq); - }else{ - log_verbose("\n"); - } - return WLAN_STATUS_SUCCESS; - } if (!strcmp(method, "auth")) { - log_info("auth["MACSTR"]", MAC2STR(addr)); + log_info("auth["MACSTR"] freq: %d", MAC2STR(addr), freq); if (wifi_clients_try(addr, freq)) { log_info(" -> drop\n"); return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; } log_info(" -> accept\n"); - } else { - log_verbose("%s["MACSTR"]\n", method, MAC2STR(addr)); + return WLAN_STATUS_SUCCESS; } + log_verbose("%s["MACSTR"] freq: %d", method, MAC2STR(addr), freq); + if (!strcmp(method, "probe") && client_probe_learning) { + log_verbose(" learn"); + wifi_clients_learn(addr, freq); + } + log_verbose("\n"); + return WLAN_STATUS_SUCCESS; + } diff --git a/wireless/wifictld/src/ubus_events.h b/wireless/wifictld/src/ubus_events.h index 8fbc4d9..2f7700c 100644 --- a/wireless/wifictld/src/ubus_events.h +++ b/wireless/wifictld/src/ubus_events.h @@ -1,7 +1,7 @@ #ifndef __WIFICTLD_UBUS_EVENT_H #define __WIFICTLD_UBUS_EVENT_H -static int client_probe_learning = 0; +extern int client_probe_learning; int wifictld_ubus_init(); void wifictld_ubus_close(); diff --git a/wireless/wifictld/src/wifi_clients.c b/wireless/wifictld/src/wifi_clients.c index d4de7fe..6ee74ed 100644 --- a/wireless/wifictld/src/wifi_clients.c +++ b/wireless/wifictld/src/wifi_clients.c @@ -6,6 +6,8 @@ #include "log.h" #include "wifi_clients.h" +int client_freq_try_threashold = 3; + static void wifi_clients_del(const u8 *addr); static struct avl_tree clients_by_addr; @@ -74,17 +76,22 @@ int wifi_clients_try(const u8 *address, uint32_t freq) { __client_learn(client, freq); log_debug("wifi_clients.wifi_clients_try("MACSTR", %d): ", MAC2STR(address), freq); - if (freq > 5000) { + if (freq > WIFI_CLIENT_FREQ_THREASHOLD) { log_debug("used correct freq\n"); client->try = 0; - } else { - if(client->try > client_freq_try_threashold) { - log_debug("clients %d try over threashold %d\n",client->try, client_freq_try_threashold); - return 0; - } - client->try++; - log_debug("clients->try now by %d\n",client->try); + return 0; } + if (client->highfreq > WIFI_CLIENT_FREQ_THREASHOLD) { + log_debug("used wrong freq, but client support freq\n"); + return -1; + } + if(client->try > client_freq_try_threashold) { + log_debug("clients %d try over threashold %d\n",client->try, client_freq_try_threashold); + client->try = 0; + return 0; + } + client->try++; + log_debug("clients->try now by %d\n",client->try); return client->try; } diff --git a/wireless/wifictld/src/wifi_clients.h b/wireless/wifictld/src/wifi_clients.h index 9801e26..e2c7bbd 100644 --- a/wireless/wifictld/src/wifi_clients.h +++ b/wireless/wifictld/src/wifi_clients.h @@ -3,7 +3,9 @@ #include -static int client_freq_try_threashold = 3; +extern int client_freq_try_threashold; + +#define WIFI_CLIENT_FREQ_THREASHOLD 5000 int wifi_clients_init(); void wifi_clients_close(); diff --git a/wireless/wifictld/src/wifictld.c b/wireless/wifictld/src/wifictld.c index ed69f01..f2e6686 100644 --- a/wireless/wifictld/src/wifictld.c +++ b/wireless/wifictld/src/wifictld.c @@ -1,11 +1,11 @@ +#include #include #include "log.h" #include "wifi_clients.h" #include "ubus_events.h" -int main(void) +int main(int argc, char *argv[]) { - verbose = 1; client_probe_learning = 1; int ret = 0; @@ -16,6 +16,17 @@ int main(void) log_info("start wifictld (full)\n"); #endif + int c; + while ((c = getopt(argc, argv, "v")) != -1) { + switch (c) { + case 'v': + verbose = 1; + break; + default: + log_error("Invalid parameter %c ignored.\n", c); + } + } + log_debug("log: show debug\n"); log_verbose("log: show verbose\n");