diff --git a/wireless/wifictld/src/ubus.c b/wireless/wifictld/src/ubus.c new file mode 100644 index 0000000..e526c81 --- /dev/null +++ b/wireless/wifictld/src/ubus.c @@ -0,0 +1,40 @@ +#include +#include "log.h" +#include "ubus_events.h" + + +static struct ubus_context *ctx; + +/** + * init ubus connection + * (start everthing need and add themselve to uloop) + */ +int wifictld_ubus_init() +{ + int ret = 0; + + // connect to ubus + ctx = ubus_connect(NULL); + if (!ctx) { + log_error("Failed to connect to ubus"); + return 1; + } + + // connect to ubus + ret = wifictld_ubus_bind_events(ctx); + if (ret) { + log_error("Failed to connect to ubus"); + return 1; + } + + // add to uloop + ubus_add_uloop(ctx); + + return 0; +} + +// close ubus connection +void wifictld_ubus_close() +{ + ubus_free(ctx); +} diff --git a/wireless/wifictld/src/ubus.h b/wireless/wifictld/src/ubus.h new file mode 100644 index 0000000..069ae18 --- /dev/null +++ b/wireless/wifictld/src/ubus.h @@ -0,0 +1,7 @@ +#ifndef __WIFICTLD_UBUS_H +#define __WIFICTLD_UBUS_H + +int wifictld_ubus_init(); +void wifictld_ubus_close(); + +#endif diff --git a/wireless/wifictld/src/ubus_events.c b/wireless/wifictld/src/ubus_events.c index e2fa8bd..640858e 100644 --- a/wireless/wifictld/src/ubus_events.c +++ b/wireless/wifictld/src/ubus_events.c @@ -6,7 +6,6 @@ #include "hostapd/common.h" #include "log.h" #include "wifi_clients.h" -#include "ubus_events.h" int client_probe_learning = 0; @@ -31,42 +30,24 @@ struct ubus_subscriber sub = { /** * init ubus connection and request for all registered hostapd instances - * (start everthing need and add themselve to uloop) */ -int wifictld_ubus_init() +int wifictld_ubus_bind_events(struct ubus_context *ctx) { int ret = 0; - // connect to ubus - ctx_main = ubus_connect(NULL); - if (!ctx_main) { - log_error("Failed to connect to ubus"); - return 1; - } - // register subscriber on ubus - ret = ubus_register_subscriber(ctx_main, &sub); + ret = ubus_register_subscriber(ctx, &sub); if (ret) { log_error("Error while registering subscriber: %s", ubus_strerror(ret)); - ubus_free(ctx_main); + ubus_free(ctx); return 2; } // request for all ubus services - ubus_lookup(ctx_main, NULL, recieve_interfaces, NULL); - - // add to uloop - ubus_add_uloop(ctx_main); - + ubus_lookup(ctx, NULL, recieve_interfaces, NULL); return 0; } -// close ubus connection -void wifictld_ubus_close() -{ - ubus_free(ctx_main); -} - static void recieve_interfaces(struct ubus_context *ctx, struct ubus_object_data *obj, void *priv) { int ret = 0; @@ -123,19 +104,18 @@ static int receive_notify(struct ubus_context *ctx, struct ubus_object *obj, str log_debug("ubus_events.receive_notify(): handle\n"); if (!strcmp(method, "auth")) { - log_info("auth["MACSTR"] freq: %d", MAC2STR(addr), freq); - if (wifi_clients_try(addr, freq)) { - log_info(" -> drop\n"); + if (wifi_clients_try(addr, freq, ssi_signal)) { + log_debug("auth["MACSTR"] freq: %d signal %d -> reject\n", MAC2STR(addr), freq, ssi_signal); return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; } - log_info(" -> accept\n"); + log_debug("auth["MACSTR"] freq: %d signal %d -> accept\n", MAC2STR(addr), freq, ssi_signal); return WLAN_STATUS_SUCCESS; } - log_verbose("%s["MACSTR"] freq: %d", method, MAC2STR(addr), freq); + log_verbose("%s["MACSTR"] freq: %d signal %d", method, MAC2STR(addr), freq, ssi_signal); if (!strcmp(method, "probe") && client_probe_learning) { log_verbose(" learn"); - wifi_clients_learn(addr, freq); + wifi_clients_learn(addr, freq, ssi_signal); } log_verbose("\n"); diff --git a/wireless/wifictld/src/ubus_events.h b/wireless/wifictld/src/ubus_events.h index 2f7700c..0b07683 100644 --- a/wireless/wifictld/src/ubus_events.h +++ b/wireless/wifictld/src/ubus_events.h @@ -1,9 +1,10 @@ #ifndef __WIFICTLD_UBUS_EVENT_H #define __WIFICTLD_UBUS_EVENT_H +#include + extern int client_probe_learning; -int wifictld_ubus_init(); -void wifictld_ubus_close(); +int wifictld_ubus_bind_events(struct ubus_context *ctx); #endif diff --git a/wireless/wifictld/src/wifi_clients.c b/wireless/wifictld/src/wifi_clients.c index 6ee74ed..da1653d 100644 --- a/wireless/wifictld/src/wifi_clients.c +++ b/wireless/wifictld/src/wifi_clients.c @@ -23,6 +23,8 @@ struct wifi_client { int time; int try; uint32_t highfreq; + uint32_t lowsignal; + uint32_t highsignal; }; int wifi_clients_init() { @@ -54,45 +56,50 @@ struct wifi_client *__get_client(const u8 *address){ return client; } -void __client_learn(struct wifi_client *client, uint32_t freq) { - log_debug("wifi_clients.__client_learn(., %d): ", freq); +void __client_learn(struct wifi_client *client, uint32_t freq, uint32_t ssi_signal) { + log_debug("wifi_clients.__client_learn(., %d):", freq); if (client->highfreq < freq) { client->highfreq = freq; - log_debug("new highfreq"); + log_debug(" new highfreq"); + } + if (client->highfreq > WIFI_CLIENT_FREQ_THREASHOLD) { + client->highfreq = ssi_signal; + }else{ + client->lowsignal = ssi_signal; } log_debug("\n"); //TODO time set and reset clean } -void wifi_clients_learn(const u8 *address, uint32_t freq) { +void wifi_clients_learn(const u8 *address, uint32_t freq, uint32_t ssi_signal) { struct wifi_client *client; client = __get_client(address); - __client_learn(client, freq); + __client_learn(client, freq, ssi_signal); } -int wifi_clients_try(const u8 *address, uint32_t freq) { +int wifi_clients_try(const u8 *address, uint32_t freq, uint32_t ssi_signal) { struct wifi_client *client; client = __get_client(address); - __client_learn(client, freq); + __client_learn(client, freq, ssi_signal); - log_debug("wifi_clients.wifi_clients_try("MACSTR", %d): ", MAC2STR(address), freq); + client->try++; + + log_info("auth(mac="MACSTR" freq=%d ssi=%d try=%d): ", MAC2STR(address), freq, ssi_signal, client->try); if (freq > WIFI_CLIENT_FREQ_THREASHOLD) { - log_debug("used correct freq\n"); client->try = 0; + log_info("accept\n"); return 0; } if (client->highfreq > WIFI_CLIENT_FREQ_THREASHOLD) { - log_debug("used wrong freq, but client support freq\n"); + log_info("reject - learned higher 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; + log_info("accept - threashold\n"); return 0; } - client->try++; - log_debug("clients->try now by %d\n",client->try); - + log_info("reject\n"); return client->try; } diff --git a/wireless/wifictld/src/wifi_clients.h b/wireless/wifictld/src/wifi_clients.h index e2c7bbd..e153e2e 100644 --- a/wireless/wifictld/src/wifi_clients.h +++ b/wireless/wifictld/src/wifi_clients.h @@ -10,7 +10,7 @@ extern int client_freq_try_threashold; int wifi_clients_init(); void wifi_clients_close(); -void wifi_clients_learn(const uint8_t *address, uint32_t freq); -int wifi_clients_try(const uint8_t *address, uint32_t freq); +void wifi_clients_learn(const uint8_t *address, uint32_t freq, uint32_t ssi_signal); +int wifi_clients_try(const uint8_t *address, uint32_t freq, uint32_t ssi_signal); #endif diff --git a/wireless/wifictld/src/wifictld.c b/wireless/wifictld/src/wifictld.c index f2e6686..a2bb680 100644 --- a/wireless/wifictld/src/wifictld.c +++ b/wireless/wifictld/src/wifictld.c @@ -3,6 +3,7 @@ #include "log.h" #include "wifi_clients.h" #include "ubus_events.h" +#include "ubus.h" int main(int argc, char *argv[]) {