save ssi_signal in wifi_clients
This commit is contained in:
parent
93bbd53481
commit
c6ee586501
|
@ -0,0 +1,40 @@
|
|||
#include <libubus.h>
|
||||
#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);
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef __WIFICTLD_UBUS_H
|
||||
#define __WIFICTLD_UBUS_H
|
||||
|
||||
int wifictld_ubus_init();
|
||||
void wifictld_ubus_close();
|
||||
|
||||
#endif
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#ifndef __WIFICTLD_UBUS_EVENT_H
|
||||
#define __WIFICTLD_UBUS_EVENT_H
|
||||
|
||||
#include <libubus.h>
|
||||
|
||||
extern int client_probe_learning;
|
||||
|
||||
int wifictld_ubus_init();
|
||||
void wifictld_ubus_close();
|
||||
int wifictld_ubus_bind_events(struct ubus_context *ctx);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "log.h"
|
||||
#include "wifi_clients.h"
|
||||
#include "ubus_events.h"
|
||||
#include "ubus.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue