some changes

This commit is contained in:
PolynomialDivision 2017-12-23 17:39:39 +01:00
parent 8c8a379270
commit 3071d84acd
5 changed files with 58 additions and 27 deletions

View file

@ -10,4 +10,6 @@ int get_rssi_iwinfo(__uint8_t *client_addr);
int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate); int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate);
int get_essid(const char *ifname, uint8_t *bssid_addr);
#endif //DAWN_RSSI_H #endif //DAWN_RSSI_H

View file

@ -9,6 +9,7 @@
#include "ubus.h" #include "ubus.h"
#include "dawn_uci.h" #include "dawn_uci.h"
#include "crypto.h" #include "crypto.h"
#include "dawn_iwinfo.h"
void daemon_shutdown(); void daemon_shutdown();
@ -97,6 +98,8 @@ int main(int argc, char **argv) {
gcrypt_init(); gcrypt_init();
gcrypt_set_key_and_iv(net_config.shared_key, net_config.iv); gcrypt_set_key_and_iv(net_config.shared_key, net_config.iv);
get_essid("wlan0", NULL);
struct time_config_s time_config = uci_get_time_config(); struct time_config_s time_config = uci_get_time_config();
timeout_config = time_config; // TODO: Refactor... timeout_config = time_config; // TODO: Refactor...

View file

@ -43,7 +43,8 @@ int is_connected(uint8_t bssid_addr[], uint8_t client_addr[]);
int mac_in_maclist(uint8_t mac[]); int mac_in_maclist(uint8_t mac[]);
int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, int automatic_kick); int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, uint8_t *client_addr,
int automatic_kick);
int probe_entry_last = -1; int probe_entry_last = -1;
int client_entry_last = -1; int client_entry_last = -1;
@ -173,7 +174,8 @@ int eval_probe_metric(struct probe_entry_s probe_entry) {
return score; return score;
} }
int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, int automatic_kick) { int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, uint8_t *client_addr,
int automatic_kick) {
ap ap_entry_own = ap_array_get_ap(bssid_addr_own); ap ap_entry_own = ap_array_get_ap(bssid_addr_own);
ap ap_entry_to_compre = ap_array_get_ap(bssid_addr_to_compare); ap ap_entry_to_compre = ap_array_get_ap(bssid_addr_to_compare);
@ -188,6 +190,19 @@ int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compar
} else { } else {
return ap_entry_own.station_count > ap_entry_to_compre.station_count; return ap_entry_own.station_count > ap_entry_to_compre.station_count;
} }
/*
int own_count = ap_entry_own.station_count;
if(automatic_kick)
{
own_count--;
}
if (is_connected(bssid_addr_to_compare, client_addr))
{
own_count--;
}
return own_count > ap_entry_to_compre.station_count;*/
} }
return 0; return 0;
@ -247,10 +262,13 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat
return 1; return 1;
} }
if (dawn_metric.use_station_count && own_score == score_to_compare) { if (dawn_metric.use_station_count && own_score == score_to_compare) {
// if ap have same value but station count is different... // if ap have same value but station count is different...
if (compare_station_count(bssid_addr, probe_array[k].bssid_addr, automatic_kick)) { if (compare_station_count(bssid_addr, probe_array[k].bssid_addr, NULL, automatic_kick)) {
return 1; return 1;
} }
} }
} }
return 0; return 0;

View file

@ -15,10 +15,29 @@ int parse_rssi(char *iwinfo_string);
int get_rssi(const char *ifname, uint8_t *client_addr); int get_rssi(const char *ifname, uint8_t *client_addr);
int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate); int get_bandwidth(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate);
#define IWINFO_BUFSIZE 24 * 1024 #define IWINFO_BUFSIZE 24 * 1024
#define IWINFO_ESSID_MAX_SIZE 32
int get_essid(const char *ifname, uint8_t *bssid_addr)
{
struct iwinfo_assoclist_entry *e;
const struct iwinfo_ops *iw;
iw = iwinfo_backend(ifname);
char buf[IWINFO_ESSID_MAX_SIZE+1] = { 0 };
if (iw->ssid(ifname, buf))
memset(buf, 0, sizeof(buf));
printf("ESSID is: %s\n", buf);
}
int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) { int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate) {
DIR *dirp; DIR *dirp;
@ -33,7 +52,7 @@ int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate)
while ((entry = readdir(dirp)) != NULL) { while ((entry = readdir(dirp)) != NULL) {
if (entry->d_type == DT_SOCK) { if (entry->d_type == DT_SOCK) {
if (get_bandwith(entry->d_name, client_addr, rx_rate, tx_rate)) { if (get_bandwidth(entry->d_name, client_addr, rx_rate, tx_rate)) {
sucess = 1; sucess = 1;
break; break;
} }
@ -43,7 +62,7 @@ int get_bandwidth_iwinfo(__uint8_t *client_addr, float *rx_rate, float *tx_rate)
return sucess; return sucess;
} }
int get_bandwith(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate) { int get_bandwidth(const char *ifname, uint8_t *client_addr, float *rx_rate, float *tx_rate) {
int i, len; int i, len;
char buf[IWINFO_BUFSIZE]; char buf[IWINFO_BUFSIZE];

View file

@ -246,13 +246,17 @@ void blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *
static int decide_function(probe_entry *prob_req) { static int decide_function(probe_entry *prob_req) {
// TODO: Refactor...
printf("COUNTER: %d\n", prob_req->counter); printf("COUNTER: %d\n", prob_req->counter);
if (prob_req->counter < dawn_metric.min_probe_count) { if (prob_req->counter < dawn_metric.min_probe_count) {
return 0; return 0;
} }
if(!dawn_metric.eval_probe_req)
{
return 1;
}
if (better_ap_available(prob_req->bssid_addr, prob_req->client_addr, 0)) { if (better_ap_available(prob_req->bssid_addr, prob_req->client_addr, 0)) {
return 0; return 0;
} }
@ -368,6 +372,9 @@ static int handle_auth_req(struct blob_attr *msg) {
return UBUS_STATUS_UNKNOWN_ERROR; return UBUS_STATUS_UNKNOWN_ERROR;
} }
// maybe add here if a client is already connected...
// delay problems...
printf("ALLOW AUTH!\n"); printf("ALLOW AUTH!\n");
return 0; return 0;
} }
@ -382,31 +389,13 @@ static int handle_assoc_req(struct blob_attr *msg) {
static int handle_probe_req(struct blob_attr *msg) { static int handle_probe_req(struct blob_attr *msg) {
//printf("[WC] Parse Probe Request\n"); //printf("[WC] Parse Probe Request\n");
probe_entry prob_req; probe_entry prob_req;
probe_entry tmp_prob_req;
if(parse_to_probe_req(msg, &prob_req) == 0) if(parse_to_probe_req(msg, &prob_req) == 0)
{ {
insert_to_array(prob_req, 1); tmp_prob_req = insert_to_array(prob_req, 1);
//print_probe_array(); //print_probe_array();
send_blob_attr_via_network(msg, "probe"); send_blob_attr_via_network(msg, "probe");
} }
//insert_to_list(prob_req, 1);
//probe_entry tmp_probe =
probe_entry tmp_prob_req = insert_to_array(prob_req, 1);
// send probe via network
/*char *str;
str = blobmsg_format_json(msg, true);
send_string_enc(str);
printf("[WC] Hostapd-Probe: %s : %s\n", "probe", str);*/
//print_probe_array();
// deny access
if (!dawn_metric.eval_probe_req) {
return 0;
}
if (!decide_function(&tmp_prob_req)) { if (!decide_function(&tmp_prob_req)) {
//printf("MAC WILL BE DECLINED!!!\n"); //printf("MAC WILL BE DECLINED!!!\n");