add init.d + fix init option in *.h
This commit is contained in:
parent
62d73930ec
commit
93bbd53481
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -2,11 +2,13 @@
|
|||
#include <stdarg.h>
|
||||
#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);
|
||||
|
|
|
@ -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, ...);
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
#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();
|
||||
void wifi_clients_close();
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include <getopt.h>
|
||||
#include <libubox/uloop.h>
|
||||
#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");
|
||||
|
||||
|
|
Loading…
Reference in New Issue