diff --git a/wireless/wifictld/src/config.c b/wireless/wifictld/src/config.c index 6f1e4a8..530e510 100644 --- a/wireless/wifictld/src/config.c +++ b/wireless/wifictld/src/config.c @@ -2,20 +2,22 @@ bool config_verbose = false; -int config_client_try_threashold = 3; +int config_client_try_probe_threashold = 3; +int config_client_try_auth_threashold = 0; + int config_client_signal_threashold = -75; int config_client_clean_every = 600; //in ms = 10min int config_client_clean_older_then = 3600; //in sec = 1h bool config_client_clean_authed = false; -bool config_client_force = false; bool config_client_force_probe = false; -bool config_client_probe_steering = false; +bool config_client_force_auth = false; + // steering contains learning already -bool config_client_probe_learning = true; +bool config_client_learning_probe = true; #ifndef MINI -bool config_client_socket_learning = true; +bool config_client_learning_socket = true; bool config_socket_always_answer = false; #endif diff --git a/wireless/wifictld/src/config.h b/wireless/wifictld/src/config.h index 8a97ff2..7aec7a6 100644 --- a/wireless/wifictld/src/config.h +++ b/wireless/wifictld/src/config.h @@ -7,28 +7,28 @@ extern bool config_verbose; -extern int config_client_try_threashold; +extern int config_client_try_probe_threashold; +extern int config_client_try_auth_threashold; + extern int config_client_signal_threashold; extern int config_client_clean_every; extern int config_client_clean_older_then; extern bool config_client_clean_authed; -// force (disable 2.4 Ghz) -extern bool config_client_force; -// force (disable 2.4 Ghz) for wifi probes +// force (disable 2.4 Ghz) for wifi probes/auth; extern bool config_client_force_probe; -// use client_try_threashold for probes, too -extern bool config_client_probe_steering; +extern bool config_client_force_auth; + /* steering contains learning already: when client_probe_steering is set, client_probe_learning is ignored */ -extern bool config_client_probe_learning; +extern bool config_client_learning_probe; #ifndef MINI -extern bool config_client_socket_learning; +extern bool config_client_learning_socket; extern bool config_socket_always_answer; #endif diff --git a/wireless/wifictld/src/main.c b/wireless/wifictld/src/main.c index 2f135a1..0ac05c7 100644 --- a/wireless/wifictld/src/main.c +++ b/wireless/wifictld/src/main.c @@ -17,12 +17,12 @@ struct option longopts[] = { {"verbose", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, // Bandsteering options - {"try", required_argument, 0, 't'}, + {"try-probe", required_argument, 0, 'p'}, + {"try-auth", required_argument, 0, 'a'}, {"signal", required_argument, 0, 's'}, - {"force", optional_argument, 0, 'f'}, + {"force-auth", optional_argument, 0, 'f'}, {"force-probe", optional_argument, 0, 1}, - {"probe", optional_argument, 0, 'p'}, - {"probe-learning", optional_argument, 0, 2}, + {"learning-probe", optional_argument, 0, 2}, // memory options {"clean-every", required_argument, 0, 3}, {"clean-older-then", required_argument, 0, 4}, @@ -35,7 +35,7 @@ struct option longopts[] = { {"if", required_argument, 0, 9}, {"mif", required_argument, 0, 10}, // other extended option - {"socket-learning", optional_argument, 0, 11}, + {"learning-socket", optional_argument, 0, 11}, {"socket-always-answer", optional_argument, 0, 12}, #endif }; @@ -49,12 +49,12 @@ void usage(int c) { #endif printf(" -h|--help show this help text\n"); printf("\nbandsteering options:\n"); - printf(" -t|--try threashold till allow (current: %d)\n", config_client_try_threashold); + printf(" -p|--try-probe threashold of wifi probe till allow (current: %d)\n", config_client_try_probe_threashold); + printf(" -a|--try-auth threashold of wifi auth till allow (current: %d)\n", config_client_try_auth_threashold); printf(" -s|--signal threashold to allow (current: %d)\n", config_client_signal_threashold); - printf(" -f|--force force steering (current: %s)\n", BOOL2STR(config_client_force)); + printf(" -f|--force-auth force steering (current: %s)\n", BOOL2STR(config_client_force_auth)); printf(" --force-probe force steering only for probes (current: %s)\n", BOOL2STR(config_client_force_probe)); - printf(" -p|--probe probe-steering (current: %s)\n", BOOL2STR(config_client_probe_steering)); - printf(" --probe-learning probe-learing (current: %s)\n", BOOL2STR(config_client_probe_learning)); + printf(" --learning-probe probe-learing (current: %s)\n", BOOL2STR(config_client_learning_probe)); printf(" (parameter ignored if probe-steering on)\n"); printf("\nmemory cleanup options:\n"); printf(" --clean-every run cleaning every (current: %ds)\n", config_client_clean_every); @@ -68,7 +68,7 @@ void usage(int c) { printf(" --if listen on interface (current: %s)\n", ifname); printf(" --mif listen on interface for multicast (current: %s)\n", ifname); printf("\nother extended options:\n"); - printf(" --socket-learning learn clients during listen on socket (current: %s)\n", BOOL2STR(config_client_socket_learning)); + printf(" --learning-socket learn clients during listen on socket (current: %s)\n", BOOL2STR(config_client_learning_socket)); printf(" --socket-always-answer answer on socket only with useful information (current: %s)\n", BOOL2STR(config_socket_always_answer)); #endif printf("\nSome config could be changed by ubus, see `ubus -v list wifictld`\n"); @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) #endif int c = 0, indexptr = 0; - while ((c = getopt_long(argc, argv, "vht:s:fp",longopts, &indexptr)) != -1) { + while ((c = getopt_long(argc, argv, "vh:pas:f",longopts, &indexptr)) != -1) { switch (c) { case 'v': config_verbose = !config_verbose; @@ -96,9 +96,16 @@ int main(int argc, char *argv[]) usage(0); return 0; // Bandsteering options - case 't': - config_client_try_threashold = atoi(optarg); - if (config_client_try_threashold < 0) { + case 'p': + config_client_try_probe_threashold = atoi(optarg); + if (config_client_try_probe_threashold < 0) { + printf("negativ tries count not supported\n"); + return 1; + } + break; + case 'a': + config_client_try_auth_threashold = atoi(optarg); + if (config_client_try_auth_threashold < 0) { printf("negativ tries count not supported\n"); return 1; } @@ -112,9 +119,9 @@ int main(int argc, char *argv[]) break; case 'f': if(optarg) - config_client_force = atoi(optarg); + config_client_force_auth = atoi(optarg); else - config_client_force = !config_client_force; + config_client_force_auth = !config_client_force_auth; break; case 1: if(optarg) @@ -122,17 +129,11 @@ int main(int argc, char *argv[]) else config_client_force_probe = !config_client_force_probe; break; - case 'p': - if(optarg) - config_client_probe_steering = atoi(optarg); - else - config_client_probe_steering = !config_client_probe_steering; - break; case 2: if(optarg) - config_client_probe_learning = atoi(optarg); + config_client_learning_probe = atoi(optarg); else - config_client_probe_learning = !config_client_probe_learning; + config_client_learning_probe = !config_client_learning_probe; break; // memory options case 3: @@ -175,9 +176,9 @@ int main(int argc, char *argv[]) // other extended option case 11: if(optarg) - config_client_socket_learning = atoi(optarg); + config_client_learning_socket = atoi(optarg); else - config_client_socket_learning = !config_client_socket_learning; + config_client_learning_socket = !config_client_learning_socket; break; case 12: if(optarg) @@ -222,7 +223,7 @@ int main(int argc, char *argv[]) } c = 0; indexptr = 0; - while ((c = getopt_long(argc, argv, "vht:s:fp",longopts, &indexptr)) != -1) { + while ((c = getopt_long(argc, argv, "vh:pas:f",longopts, &indexptr)) != -1) { switch (c) { case 10: socket_join_mcast(optarg); diff --git a/wireless/wifictld/src/socket_handler.c b/wireless/wifictld/src/socket_handler.c index b71728e..306619d 100644 --- a/wireless/wifictld/src/socket_handler.c +++ b/wireless/wifictld/src/socket_handler.c @@ -25,7 +25,7 @@ static int handle_client(struct socket_msg *msg, int response) { } return response; } - if(!config_client_socket_learning) + if(!config_client_learning_socket) return SOCKET_HANDLER_SILENCE; // learn client msg->client->try_probe = 0; diff --git a/wireless/wifictld/src/ubus_events.c b/wireless/wifictld/src/ubus_events.c index 84c91e0..cf7799a 100644 --- a/wireless/wifictld/src/ubus_events.c +++ b/wireless/wifictld/src/ubus_events.c @@ -149,18 +149,12 @@ static int receive_notify(struct ubus_context *ctx, struct ubus_object *obj, str } if (!strcmp(method, "probe")) { - if(config_client_probe_steering) { - if (wifi_clients_try(&hclient)) { - log_verbose("%s["MACSTR"] freq: %d signal %d -> reject\n", method, MAC2STR(addr), hclient.freq, hclient.ssi_signal); - return WLAN_STATUS_UNSPECIFIED_FAILURE; - } - log_verbose("%s["MACSTR"] freq: %d signal %d -> accept\n", method, MAC2STR(addr), hclient.freq, hclient.ssi_signal); - return WLAN_STATUS_SUCCESS; - } - if(config_client_probe_learning) { - log_verbose("%s["MACSTR"] freq: %d signal %d -> learn\n", method, MAC2STR(addr), hclient.freq, hclient.ssi_signal); - wifi_clients_learn(&hclient); + if (wifi_clients_try(&hclient)) { + log_verbose("%s["MACSTR"] freq: %d signal %d -> reject\n", method, MAC2STR(addr), hclient.freq, hclient.ssi_signal); + return WLAN_STATUS_UNSPECIFIED_FAILURE; } + log_verbose("%s["MACSTR"] freq: %d signal %d -> accept\n", method, MAC2STR(addr), hclient.freq, hclient.ssi_signal); + return WLAN_STATUS_SUCCESS; } else { wifi_clients_disconnect(&hclient); log_verbose("%s["MACSTR"] freq: %d signal %d -> disconnect\n", method, MAC2STR(addr), hclient.freq, hclient.ssi_signal); diff --git a/wireless/wifictld/src/ubus_service.c b/wireless/wifictld/src/ubus_service.c index 64b9b76..4414b31 100644 --- a/wireless/wifictld/src/ubus_service.c +++ b/wireless/wifictld/src/ubus_service.c @@ -78,17 +78,17 @@ static int ubus_get_config(struct ubus_context *ctx, struct ubus_object *obj, void *list = blobmsg_open_table(&b, "config"); blobmsg_add_bool(&b, "verbose", config_verbose); - blobmsg_add_u32(&b, "client_try_threashold", config_client_try_threashold); + blobmsg_add_u32(&b, "client_try_probe_threashold", config_client_try_probe_threashold); + blobmsg_add_u32(&b, "client_try_auth_threashold", config_client_try_auth_threashold); blobmsg_add_u32(&b, "client_signal_threashold", config_client_signal_threashold); blobmsg_add_u32(&b, "client_clean_every", config_client_clean_every); blobmsg_add_u32(&b, "client_clean_older_then", config_client_clean_older_then); blobmsg_add_bool(&b, "client_clean_authed", config_client_clean_authed); - blobmsg_add_bool(&b, "client_force", config_client_force); blobmsg_add_bool(&b, "client_force_probe", config_client_force_probe); - blobmsg_add_bool(&b, "client_probe_steering", config_client_probe_steering); - blobmsg_add_bool(&b, "client_probe_learning", config_client_probe_learning); + blobmsg_add_bool(&b, "client_force_auth", config_client_force_auth); + blobmsg_add_bool(&b, "client_learning_probe", config_client_learning_probe); #ifndef MINI - blobmsg_add_bool(&b, "client_socket_learning", config_client_socket_learning); + blobmsg_add_bool(&b, "client_learning_socket", config_client_learning_socket); blobmsg_add_bool(&b, "socket_always_answer", config_socket_always_answer); #endif @@ -102,17 +102,17 @@ static int ubus_get_config(struct ubus_context *ctx, struct ubus_object *obj, enum { SET_CONFIG_VERBOSE, - SET_CONFIG_CLIENT_TRY_THREASHOLD, + SET_CONFIG_CLIENT_TRY_PROBE_THREASHOLD, + SET_CONFIG_CLIENT_TRY_AUTH_THREASHOLD, SET_CONFIG_CLIENT_SIGNAL_THREASHOLD, SET_CONFIG_CLIENT_CLEAN_EVERY, SET_CONFIG_CLIENT_CLEAN_OLDER_THEN, SET_CONFIG_CLIENT_CLEAN_AUTHED, - SET_CONFIG_CLIENT_FORCE, SET_CONFIG_CLIENT_FORCE_PROBE, - SET_CONFIG_CLIENT_PROBE_STEERING, - SET_CONFIG_CLIENT_PROBE_LEARNING, + SET_CONFIG_CLIENT_FORCE_AUTH, + SET_CONFIG_CLIENT_LEARNING_PROBE, #ifndef MINI - SET_CONFIG_CLIENT_SOCKET_LEARNING, + SET_CONFIG_CLIENT_LEARNING_SOCKET, SET_CONFIG_SOCKET_ALWAYS_ANSWER, #endif __SET_CONFIG_MAX @@ -120,17 +120,17 @@ enum { static const struct blobmsg_policy ubus_set_config_policy[__SET_CONFIG_MAX] = { [SET_CONFIG_VERBOSE] = { "verbose", BLOBMSG_TYPE_BOOL }, - [SET_CONFIG_CLIENT_TRY_THREASHOLD] = { "client_try_threashold", BLOBMSG_TYPE_INT32 }, + [SET_CONFIG_CLIENT_TRY_PROBE_THREASHOLD] = { "client_try_probe_threashold", BLOBMSG_TYPE_INT32 }, + [SET_CONFIG_CLIENT_TRY_AUTH_THREASHOLD] = { "client_try_auth_threashold", BLOBMSG_TYPE_INT32 }, [SET_CONFIG_CLIENT_SIGNAL_THREASHOLD] = { "client_signal_threashold", BLOBMSG_TYPE_INT32 }, [SET_CONFIG_CLIENT_CLEAN_EVERY] = { "client_clean_every", BLOBMSG_TYPE_INT32 }, [SET_CONFIG_CLIENT_CLEAN_OLDER_THEN] = { "client_clean_older_then", BLOBMSG_TYPE_INT32 }, [SET_CONFIG_CLIENT_CLEAN_AUTHED] = { "client_clean_authed", BLOBMSG_TYPE_BOOL }, - [SET_CONFIG_CLIENT_FORCE] = { "client_force", BLOBMSG_TYPE_BOOL }, [SET_CONFIG_CLIENT_FORCE_PROBE] = { "client_force_probe", BLOBMSG_TYPE_BOOL }, - [SET_CONFIG_CLIENT_PROBE_STEERING] = { "client_probe_steering", BLOBMSG_TYPE_BOOL }, - [SET_CONFIG_CLIENT_PROBE_LEARNING] = { "client_probe_learning", BLOBMSG_TYPE_BOOL }, + [SET_CONFIG_CLIENT_FORCE_AUTH] = { "client_force_auth", BLOBMSG_TYPE_BOOL }, + [SET_CONFIG_CLIENT_LEARNING_PROBE] = { "client_learning_probe", BLOBMSG_TYPE_BOOL }, #ifndef MINI - [SET_CONFIG_CLIENT_SOCKET_LEARNING] = { "client_socket_learning", BLOBMSG_TYPE_BOOL }, + [SET_CONFIG_CLIENT_LEARNING_SOCKET] = { "client_learning_socket", BLOBMSG_TYPE_BOOL }, [SET_CONFIG_SOCKET_ALWAYS_ANSWER] = { "socket_always_answer", BLOBMSG_TYPE_BOOL }, #endif }; @@ -143,26 +143,28 @@ static int ubus_set_config(struct ubus_context *ctx, struct ubus_object *obj, blobmsg_parse(ubus_set_config_policy, __SET_CONFIG_MAX, tb, blob_data(msg), blob_len(msg)); if (!tb[SET_CONFIG_VERBOSE] && - !tb[SET_CONFIG_CLIENT_TRY_THREASHOLD] && + !tb[SET_CONFIG_CLIENT_TRY_PROBE_THREASHOLD] && + !tb[SET_CONFIG_CLIENT_TRY_AUTH_THREASHOLD] && !tb[SET_CONFIG_CLIENT_SIGNAL_THREASHOLD] && !tb[SET_CONFIG_CLIENT_CLEAN_EVERY] && !tb[SET_CONFIG_CLIENT_CLEAN_OLDER_THEN] && !tb[SET_CONFIG_CLIENT_CLEAN_AUTHED] && - !tb[SET_CONFIG_CLIENT_FORCE] && !tb[SET_CONFIG_CLIENT_FORCE_PROBE] && - !tb[SET_CONFIG_CLIENT_PROBE_STEERING] && - !tb[SET_CONFIG_CLIENT_PROBE_LEARNING] + !tb[SET_CONFIG_CLIENT_FORCE_AUTH] && + !tb[SET_CONFIG_CLIENT_LEARNING_PROBE] #ifndef MINI && - !tb[SET_CONFIG_CLIENT_SOCKET_LEARNING] && + !tb[SET_CONFIG_CLIENT_LEARNING_SOCKET] && !tb[SET_CONFIG_SOCKET_ALWAYS_ANSWER] #endif ) return UBUS_STATUS_INVALID_ARGUMENT; if (tb[SET_CONFIG_VERBOSE]) config_verbose = blobmsg_get_bool(tb[SET_CONFIG_VERBOSE]); - if (tb[SET_CONFIG_CLIENT_TRY_THREASHOLD]) - config_client_try_threashold = blobmsg_get_u32(tb[SET_CONFIG_CLIENT_TRY_THREASHOLD]); + if (tb[SET_CONFIG_CLIENT_TRY_PROBE_THREASHOLD]) + config_client_try_probe_threashold = blobmsg_get_u32(tb[SET_CONFIG_CLIENT_TRY_PROBE_THREASHOLD]); + if (tb[SET_CONFIG_CLIENT_TRY_AUTH_THREASHOLD]) + config_client_try_auth_threashold = blobmsg_get_u32(tb[SET_CONFIG_CLIENT_TRY_AUTH_THREASHOLD]); if (tb[SET_CONFIG_CLIENT_SIGNAL_THREASHOLD]) config_client_signal_threashold = blobmsg_get_u32(tb[SET_CONFIG_CLIENT_SIGNAL_THREASHOLD]); if (tb[SET_CONFIG_CLIENT_CLEAN_EVERY]) @@ -171,17 +173,15 @@ static int ubus_set_config(struct ubus_context *ctx, struct ubus_object *obj, config_client_clean_older_then = blobmsg_get_u32(tb[SET_CONFIG_CLIENT_CLEAN_OLDER_THEN]); if (tb[SET_CONFIG_CLIENT_CLEAN_AUTHED]) config_client_clean_authed = blobmsg_get_bool(tb[SET_CONFIG_CLIENT_CLEAN_AUTHED]); - if (tb[SET_CONFIG_CLIENT_FORCE]) - config_client_force = blobmsg_get_bool(tb[SET_CONFIG_CLIENT_FORCE]); if (tb[SET_CONFIG_CLIENT_FORCE_PROBE]) config_client_force_probe = blobmsg_get_bool(tb[SET_CONFIG_CLIENT_FORCE_PROBE]); - if (tb[SET_CONFIG_CLIENT_PROBE_STEERING]) - config_client_probe_steering = blobmsg_get_bool(tb[SET_CONFIG_CLIENT_PROBE_STEERING]); - if (tb[SET_CONFIG_CLIENT_PROBE_LEARNING]) - config_client_probe_learning = blobmsg_get_bool(tb[SET_CONFIG_CLIENT_PROBE_LEARNING]); + if (tb[SET_CONFIG_CLIENT_FORCE_AUTH]) + config_client_force_auth = blobmsg_get_bool(tb[SET_CONFIG_CLIENT_FORCE_AUTH]); + if (tb[SET_CONFIG_CLIENT_LEARNING_PROBE]) + config_client_learning_probe = blobmsg_get_bool(tb[SET_CONFIG_CLIENT_LEARNING_PROBE]); #ifndef MINI - if (tb[SET_CONFIG_CLIENT_SOCKET_LEARNING]) - config_client_socket_learning = blobmsg_get_bool(tb[SET_CONFIG_CLIENT_SOCKET_LEARNING]); + if (tb[SET_CONFIG_CLIENT_LEARNING_SOCKET]) + config_client_learning_socket = blobmsg_get_bool(tb[SET_CONFIG_CLIENT_LEARNING_SOCKET]); if (tb[SET_CONFIG_SOCKET_ALWAYS_ANSWER]) config_socket_always_answer = blobmsg_get_bool(tb[SET_CONFIG_SOCKET_ALWAYS_ANSWER]); #endif diff --git a/wireless/wifictld/src/wifi_clients.c b/wireless/wifictld/src/wifi_clients.c index c77f95e..c010c4b 100644 --- a/wireless/wifictld/src/wifi_clients.c +++ b/wireless/wifictld/src/wifi_clients.c @@ -142,6 +142,10 @@ struct wifi_client *__get_client(struct hostapd_client *hclient){ } #endif + if(!config_client_learning_probe && !hclient->auth) { + return client; + } + client->avl.key = client->addr; log_debug("wifi_clients.__get_client("MACSTR"): add client to mem\n", MAC2STR(hclient->address)); avl_insert(&clients_by_addr, &client->avl); @@ -163,7 +167,7 @@ int wifi_clients_try(struct hostapd_client *hclient) { client->try_probe = 0; }else{ if(config_client_force_probe){ - log_verbose("probe(try=%d mac="MACSTR" freq=%d ssi=%d): ", client->try_auth, MAC2STR(hclient->address), hclient->freq, hclient->ssi_signal); + log_verbose("probe(try_auth=%d mac="MACSTR" freq=%d ssi=%d): ", client->try_auth, MAC2STR(hclient->address), hclient->freq, hclient->ssi_signal); }else{ log_verbose("probe(try=%d mac="MACSTR" freq=%d ssi=%d): ", client->try_probe, MAC2STR(hclient->address), hclient->freq, hclient->ssi_signal); client->try_probe++; @@ -181,7 +185,7 @@ int wifi_clients_try(struct hostapd_client *hclient) { return 0; } if (client->freq_highest > WIFI_CLIENT_FREQ_THREASHOLD) { - if (config_client_force && hclient->auth || config_client_force_probe && !hclient->auth) { + if (config_client_force_auth && hclient->auth || config_client_force_probe && !hclient->auth) { if(!hclient->auth){ log_verbose("reject - force\n"); return -1; @@ -200,8 +204,8 @@ int wifi_clients_try(struct hostapd_client *hclient) { } } - if(hclient->auth && client->try_auth > config_client_try_threashold || - !hclient->auth && client->try_probe > config_client_try_threashold + if(hclient->auth && client->try_auth > config_client_try_auth_threashold || + !hclient->auth && client->try_probe > config_client_try_probe_threashold ) { if(!hclient->auth){ client->try_probe = 0;