Wait x times before accepting

This commit is contained in:
PolynomialDivision 2017-06-25 15:16:46 +02:00
parent 20616d7ef9
commit cfa2251ae3
6 changed files with 44 additions and 14 deletions

View file

@ -37,7 +37,7 @@ start_service()
echo "${command}"
procd_set_param respawn
# procd_set_param respawn
procd_close_instance
echo "Dawn instance started!"

View file

@ -7,22 +7,41 @@ int go_next(char sort_order[], int i, probe_entry entry, probe_entry next_entry)
int mac_is_equal(uint8_t addr1[], uint8_t addr2[]);
int mac_is_greater(uint8_t addr1[], uint8_t addr2[]);
void print_probe_entry(probe_entry entry);
node* delete_probe_req(node* head, uint8_t bssid_addr[], uint8_t client_addr[]);
node* delete_probe_req(node** ret_remove, node* head, uint8_t bssid_addr[], uint8_t client_addr[]);
int mac_is_first_in_list(node* head, uint8_t bssid_addr[], uint8_t client_addr[]);
node* remove_node(node* head, node* curr, node* prev);
node* remove_old_entries(node* head, time_t current_time, long long int threshold);
void print_list_with_head(node* head);
void insert_to_list(probe_entry entry)
void insert_to_list(probe_entry entry, int inc_counter)
{
pthread_mutex_lock(&list_mutex);
entry.time = time(0);
entry.counter = 0;
// first delete probe request
//probe_list_head = remove_old_entries(probe_list_head, time(0), TIME_THRESHOLD);
probe_list_head = delete_probe_req(probe_list_head, entry.bssid_addr, entry.client_addr);
probe_list_head = insert(probe_list_head, entry);
node *tmp_probe_req = NULL;
probe_list_head = delete_probe_req(&tmp_probe_req, probe_list_head, entry.bssid_addr, entry.client_addr);
if(tmp_probe_req) // local ubus
{
tmp_probe_req->data.signal = entry.signal;
tmp_probe_req->data.time = entry.time;
if(inc_counter) // when network don't increase counter...
{
tmp_probe_req->data.counter++;
}
// is this correct?
probe_list_head = insert(probe_list_head, tmp_probe_req->data);
free(tmp_probe_req);
} else
{
printf("New entry!\n");
probe_list_head = insert(probe_list_head, entry);
}
pthread_mutex_unlock(&list_mutex);
}
@ -118,7 +137,7 @@ node* insert(node* head, probe_entry entry) {
}
node* delete_probe_req(node* head, uint8_t bssid_addr[], uint8_t client_addr[])
node* delete_probe_req(node** ret_remove, node* head, uint8_t bssid_addr[], uint8_t client_addr[])
{
if(!head)
{
@ -130,7 +149,9 @@ node* delete_probe_req(node* head, uint8_t bssid_addr[], uint8_t client_addr[])
{
node *temp = head;
head = head->ptr;
free(temp);
*ret_remove = temp;
// don't free pointer
//free(temp);
return head;
}
@ -148,7 +169,8 @@ node* delete_probe_req(node* head, uint8_t bssid_addr[], uint8_t client_addr[])
{
node *temp = next;
prev->ptr = next->ptr;
free(temp);
//free(temp);
*ret_remove = temp;
return head;
}
prev = next;
@ -333,7 +355,7 @@ void print_probe_entry(probe_entry entry)
sprintf(mac_buf_client, "%x:%x:%x:%x:%x:%x", MAC2STR(entry.client_addr));
sprintf(mac_buf_target, "%x:%x:%x:%x:%x:%x", MAC2STR(entry.target_addr));
printf("bssid_addr: %s, client_addr: %s, target_addr: %s, signal: %d, freq: %d\n",
mac_buf_ap, mac_buf_client, mac_buf_target, entry.signal, entry.freq);
printf("bssid_addr: %s, client_addr: %s, target_addr: %s, signal: %d, freq: %d, counter: %d\n",
mac_buf_ap, mac_buf_client, mac_buf_target, entry.signal, entry.freq, entry.counter);
}

View file

@ -24,6 +24,7 @@ typedef struct {
uint32_t signal;
uint32_t freq;
time_t time;
int counter;
}probe_entry;
@ -36,7 +37,7 @@ typedef struct node{
node* insert(node* head, probe_entry entry);
void free_list(node *head);
void print_list();
void insert_to_list(probe_entry entry);
void insert_to_list(probe_entry entry, int inc_counter);
int mac_first_in_probe_list(uint8_t bssid_addr[], uint8_t client_addr[]);
void *remove_thread(void *arg);

View file

@ -112,7 +112,7 @@ void* receive_msg(void *args)
parse_to_probe_req(b.head, &prob_req);
// insert to list
insert_to_list(prob_req);
insert_to_list(prob_req, 0);
}
}

View file

@ -43,6 +43,12 @@ static int subscribe_to_hostapd_interfaces(char* hostapd_dir);
static int decide_function(probe_entry* prob_req)
{
// TODO: Refactor...
if(prob_req->counter < MIN_PROBE_REQ)
{
return 0;
}
int ret = mac_first_in_probe_list(prob_req->bssid_addr, prob_req->client_addr);
if(ret)
{
@ -92,7 +98,7 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
{
probe_entry prob_req;
parse_to_probe_req(msg, &prob_req);
insert_to_list(prob_req);
insert_to_list(prob_req, 1);
// send probe via network
char *str;

View file

@ -3,8 +3,9 @@
#include "datastorage.h"
#define MIN_PROBE_REQ 2 // TODO: Parse from config file...
int dawn_init_ubus(const char *ubus_socket, char* hostapd_dir);
int parse_to_probe_req(struct blob_attr *msg, probe_entry* prob_req);
#endif