add init.d + fix init option in *.h

This commit is contained in:
Martin/Geno 2018-07-16 12:27:43 +02:00
parent 62d73930ec
commit 93bbd53481
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
9 changed files with 80 additions and 31 deletions

View File

@ -9,7 +9,7 @@ PKG_LICENSE:=APGL
include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/package.mk
TARGET_CFLAGS += -DDEBUG #TARGET_CFLAGS += -DDEBUG
define Package/wifictld/Default define Package/wifictld/Default
SECTION:=net SECTION:=net
@ -27,7 +27,7 @@ endef
define Package/wifictld-mini define Package/wifictld-mini
$(call Package/wifictld/Default) $(call Package/wifictld/Default)
TITLE+= (local) TITLE+= (mini)
VARIANT:=mini VARIANT:=mini
TARGET_CFLAGS += -DMINI TARGET_CFLAGS += -DMINI
endef endef
@ -54,6 +54,8 @@ endef
define Package/wifictld/install define Package/wifictld/install
$(INSTALL_DIR) $(1)/usr/sbin/ $(INSTALL_DIR) $(1)/usr/sbin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/wifictld $(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 endef
Package/wifictld-mini/install = $(Package/hostapd/install) Package/wifictld-mini/install = $(Package/hostapd/install)

View File

@ -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
}

View File

@ -2,11 +2,13 @@
#include <stdarg.h> #include <stdarg.h>
#include "log.h" #include "log.h"
int verbose = 0;
#ifdef DEBUG #ifdef DEBUG
void log_debug(const char *format, ...) { void log_debug(const char *format, ...) {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vfprintf(stderr, format, args); vprintf(format, args);
va_end(args); va_end(args);
} }
#else #else
@ -14,9 +16,8 @@ void log_debug(const char *format, ...) {
} }
#endif #endif
void log_verbose(const char *format, ...) { void log_verbose(const char *format, ...) {
if (verbose) if (!verbose)
return; return;
va_list args; va_list args;
va_start(args, format); va_start(args, format);

View File

@ -1,7 +1,7 @@
#ifndef __WIFICTLD_LOG_H #ifndef __WIFICTLD_LOG_H
#define __WIFICTLD_LOG_H #define __WIFICTLD_LOG_H
static int verbose = 0; extern int verbose;
void log_info(const char *format, ...); void log_info(const char *format, ...);
void log_verbose(const char *format, ...); void log_verbose(const char *format, ...);

View File

@ -8,6 +8,8 @@
#include "wifi_clients.h" #include "wifi_clients.h"
#include "ubus_events.h" #include "ubus_events.h"
int client_probe_learning = 0;
static struct blob_buf b; static struct blob_buf b;
static struct ubus_context *ctx_main; static struct ubus_context *ctx_main;
@ -120,26 +122,23 @@ static int receive_notify(struct ubus_context *ctx, struct ubus_object *obj, str
// handle // handle
log_debug("ubus_events.receive_notify(): handle\n"); 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")) { 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)) { if (wifi_clients_try(addr, freq)) {
log_info(" -> drop\n"); log_info(" -> drop\n");
return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
} }
log_info(" -> accept\n"); log_info(" -> accept\n");
} else { return WLAN_STATUS_SUCCESS;
log_verbose("%s["MACSTR"]\n", method, MAC2STR(addr));
} }
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; return WLAN_STATUS_SUCCESS;
} }

View File

@ -1,7 +1,7 @@
#ifndef __WIFICTLD_UBUS_EVENT_H #ifndef __WIFICTLD_UBUS_EVENT_H
#define __WIFICTLD_UBUS_EVENT_H #define __WIFICTLD_UBUS_EVENT_H
static int client_probe_learning = 0; extern int client_probe_learning;
int wifictld_ubus_init(); int wifictld_ubus_init();
void wifictld_ubus_close(); void wifictld_ubus_close();

View File

@ -6,6 +6,8 @@
#include "log.h" #include "log.h"
#include "wifi_clients.h" #include "wifi_clients.h"
int client_freq_try_threashold = 3;
static void wifi_clients_del(const u8 *addr); static void wifi_clients_del(const u8 *addr);
static struct avl_tree clients_by_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); __client_learn(client, freq);
log_debug("wifi_clients.wifi_clients_try("MACSTR", %d): ", MAC2STR(address), 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"); log_debug("used correct freq\n");
client->try = 0; client->try = 0;
} else { 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) { if(client->try > client_freq_try_threashold) {
log_debug("clients %d try over threashold %d\n",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; return 0;
} }
client->try++; client->try++;
log_debug("clients->try now by %d\n",client->try); log_debug("clients->try now by %d\n",client->try);
}
return client->try; return client->try;
} }

View File

@ -3,7 +3,9 @@
#include <stdint.h> #include <stdint.h>
static int client_freq_try_threashold = 3; extern int client_freq_try_threashold;
#define WIFI_CLIENT_FREQ_THREASHOLD 5000
int wifi_clients_init(); int wifi_clients_init();
void wifi_clients_close(); void wifi_clients_close();

View File

@ -1,11 +1,11 @@
#include <getopt.h>
#include <libubox/uloop.h> #include <libubox/uloop.h>
#include "log.h" #include "log.h"
#include "wifi_clients.h" #include "wifi_clients.h"
#include "ubus_events.h" #include "ubus_events.h"
int main(void) int main(int argc, char *argv[])
{ {
verbose = 1;
client_probe_learning = 1; client_probe_learning = 1;
int ret = 0; int ret = 0;
@ -16,6 +16,17 @@ int main(void)
log_info("start wifictld (full)\n"); log_info("start wifictld (full)\n");
#endif #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_debug("log: show debug\n");
log_verbose("log: show verbose\n"); log_verbose("log: show verbose\n");