mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-03-09 15:40:12 +00:00
Reformat code
This commit is contained in:
parent
fa52176cd8
commit
325cbc764c
6 changed files with 989 additions and 1048 deletions
|
@ -20,7 +20,7 @@ int setup_broadcast_socket(const char *_broadcast_ip, unsigned short _broadcast_
|
|||
|
||||
/* Allow broadcast */
|
||||
broadcast_permission = 1;
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (void *)&broadcast_permission,
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (void *) &broadcast_permission,
|
||||
sizeof(broadcast_permission)) < 0) {
|
||||
fprintf(stderr, "Failed to create socket.\n");
|
||||
return -1;
|
||||
|
@ -32,7 +32,7 @@ int setup_broadcast_socket(const char *_broadcast_ip, unsigned short _broadcast_
|
|||
addr->sin_addr.s_addr = inet_addr(_broadcast_ip);
|
||||
addr->sin_port = htons(_broadcast_port);
|
||||
|
||||
if (bind(sock, (struct sockaddr *)addr, sizeof(*addr)) <
|
||||
if (bind(sock, (struct sockaddr *) addr, sizeof(*addr)) <
|
||||
0) {
|
||||
fprintf(stderr, "Binding socket failed!\n");
|
||||
return -1;
|
||||
|
|
|
@ -13,59 +13,58 @@
|
|||
|
||||
static struct ip_mreq command; /* static ?! */
|
||||
|
||||
int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_port, struct sockaddr_in *addr)
|
||||
{
|
||||
int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_port, struct sockaddr_in *addr) {
|
||||
int loop = 1;
|
||||
int sock;
|
||||
|
||||
memset (addr, 0, sizeof (*addr));
|
||||
memset(addr, 0, sizeof(*addr));
|
||||
addr->sin_family = AF_INET;
|
||||
addr->sin_addr.s_addr = htonl (INADDR_ANY);
|
||||
addr->sin_port = htons (_multicast_port);
|
||||
|
||||
if ( ( sock = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
perror ("socket()");
|
||||
exit (EXIT_FAILURE);
|
||||
if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
perror("socket()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Mehr Prozessen erlauben, denselben Port zu nutzen */
|
||||
loop = 1;
|
||||
if (setsockopt ( sock,
|
||||
if (setsockopt(sock,
|
||||
SOL_SOCKET,
|
||||
SO_REUSEADDR,
|
||||
&loop, sizeof (loop)) < 0) {
|
||||
perror ("setsockopt:SO_REUSEADDR");
|
||||
exit (EXIT_FAILURE);
|
||||
&loop, sizeof(loop)) < 0) {
|
||||
perror("setsockopt:SO_REUSEADDR");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(bind( sock,
|
||||
(struct sockaddr *)addr,
|
||||
if (bind(sock,
|
||||
(struct sockaddr *) addr,
|
||||
sizeof(*addr)) < 0) {
|
||||
perror ("bind");
|
||||
exit (EXIT_FAILURE);
|
||||
perror("bind");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Broadcast auf dieser Maschine zulassen */
|
||||
loop = 1;
|
||||
if (setsockopt ( sock,
|
||||
if (setsockopt(sock,
|
||||
IPPROTO_IP,
|
||||
IP_MULTICAST_LOOP,
|
||||
&loop, sizeof (loop)) < 0) {
|
||||
perror ("setsockopt:IP_MULTICAST_LOOP");
|
||||
exit (EXIT_FAILURE);
|
||||
&loop, sizeof(loop)) < 0) {
|
||||
perror("setsockopt:IP_MULTICAST_LOOP");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Join the broadcast group: */
|
||||
command.imr_multiaddr.s_addr = inet_addr (_multicast_ip);
|
||||
command.imr_multiaddr.s_addr = inet_addr(_multicast_ip);
|
||||
command.imr_interface.s_addr = htonl (INADDR_ANY);
|
||||
if (command.imr_multiaddr.s_addr == -1) {
|
||||
perror ("224.0.0.1 ist keine Multicast-Adresse\n");
|
||||
exit (EXIT_FAILURE);
|
||||
perror("224.0.0.1 ist keine Multicast-Adresse\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (setsockopt ( sock,
|
||||
if (setsockopt(sock,
|
||||
IPPROTO_IP,
|
||||
IP_ADD_MEMBERSHIP,
|
||||
&command, sizeof (command)) < 0) {
|
||||
perror ("setsockopt:IP_ADD_MEMBERSHIP");
|
||||
&command, sizeof(command)) < 0) {
|
||||
perror("setsockopt:IP_ADD_MEMBERSHIP");
|
||||
}
|
||||
return sock;
|
||||
}
|
|
@ -26,6 +26,7 @@ const char *ip;
|
|||
unsigned short port;
|
||||
char recv_string[MAX_RECV_STRING + 1];
|
||||
int recv_string_len;
|
||||
|
||||
void *receive_msg(void *args);
|
||||
|
||||
int init_socket_runopts(char *_ip, char *_port, int broadcast_socket) {
|
||||
|
@ -33,11 +34,9 @@ int init_socket_runopts(char *_ip, char *_port, int broadcast_socket) {
|
|||
port = atoi(_port);
|
||||
ip = _ip;
|
||||
|
||||
if(broadcast_socket)
|
||||
{
|
||||
if (broadcast_socket) {
|
||||
sock = setup_broadcast_socket(ip, port, &addr);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
printf("Settingup multicastsocket!\n");
|
||||
sock = setup_multicast_socket(ip, port, &addr);
|
||||
}
|
||||
|
@ -61,13 +60,11 @@ void *receive_msg(void *args) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if(recv_string == NULL)
|
||||
{
|
||||
if (recv_string == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strlen(recv_string) <= 0)
|
||||
{
|
||||
if (strlen(recv_string) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
recv_string[recv_string_len] = '\0';
|
||||
|
@ -90,13 +87,11 @@ void *receive_msg(void *args) {
|
|||
|
||||
*/
|
||||
|
||||
if(str == NULL)
|
||||
{
|
||||
if (str == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( strlen(str) <= 0)
|
||||
{
|
||||
if (strlen(str) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -104,12 +99,10 @@ void *receive_msg(void *args) {
|
|||
HERE IS NULLPOINTER PROBABLY
|
||||
*/
|
||||
|
||||
if(strstr(str, "clients") != NULL) {
|
||||
if (strstr(str, "clients") != NULL) {
|
||||
parse_to_clients(b.head);
|
||||
} else if(strstr(str, "target")!= NULL)
|
||||
{
|
||||
if(parse_to_probe_req(b.head, &prob_req) == 0)
|
||||
{
|
||||
} else if (strstr(str, "target") != NULL) {
|
||||
if (parse_to_probe_req(b.head, &prob_req) == 0) {
|
||||
insert_to_array(prob_req, 0);
|
||||
}
|
||||
}
|
||||
|
@ -129,14 +122,14 @@ int send_string(char *msg) {
|
|||
pthread_mutex_lock(&send_mutex);
|
||||
int msglen = strlen(msg);
|
||||
printf("Sending string! %s\n", msg);
|
||||
if (sendto( sock,
|
||||
if (sendto(sock,
|
||||
msg,
|
||||
msglen,
|
||||
0,
|
||||
(struct sockaddr *) &addr,
|
||||
sizeof (addr)) < 0) {
|
||||
perror ("sendto()");
|
||||
exit (EXIT_FAILURE);
|
||||
sizeof(addr)) < 0) {
|
||||
perror("sendto()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
pthread_mutex_unlock(&send_mutex);
|
||||
|
||||
|
|
|
@ -6,30 +6,35 @@
|
|||
|
||||
int go_next_help(char sort_order[], int i, probe_entry entry,
|
||||
probe_entry next_entry);
|
||||
|
||||
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);
|
||||
|
||||
void remove_old_probe_entries(time_t current_time, long long int threshold);
|
||||
|
||||
int client_array_go_next(char sort_order[], int i, client entry,
|
||||
client next_entry);
|
||||
|
||||
int client_array_go_next_help(char sort_order[], int i, client entry,
|
||||
client next_entry);
|
||||
|
||||
void remove_old_client_entries(time_t current_time, long long int threshold);
|
||||
|
||||
int kick_client(uint8_t bssid[], uint8_t client[]);
|
||||
|
||||
int probe_entry_last = -1;
|
||||
int client_entry_last = -1;
|
||||
|
||||
int kick_client(uint8_t bssid[], uint8_t client[])
|
||||
{
|
||||
int kick_client(uint8_t bssid[], uint8_t client[]) {
|
||||
int i;
|
||||
for(i = 0; i <= client_entry_last; i++)
|
||||
{
|
||||
if(mac_is_equal(probe_array[i].client_addr, client))
|
||||
{
|
||||
for (i = 0; i <= client_entry_last; i++) {
|
||||
if (mac_is_equal(probe_array[i].client_addr, client)) {
|
||||
// check if bssid is first in list...
|
||||
return (mac_is_equal(bssid, probe_array[i].bssid_addr));
|
||||
}
|
||||
|
@ -37,35 +42,28 @@ int kick_client(uint8_t bssid[], uint8_t client[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
void kick_clients(uint8_t bssid[])
|
||||
{
|
||||
void kick_clients(uint8_t bssid[]) {
|
||||
// Seach for BSSID
|
||||
int i;
|
||||
for(i = 0; i <= client_entry_last; i++)
|
||||
{
|
||||
if(mac_is_equal(client_array[i].bssid_addr, bssid))
|
||||
{
|
||||
for (i = 0; i <= client_entry_last; i++) {
|
||||
if (mac_is_equal(client_array[i].bssid_addr, bssid)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Go threw clients
|
||||
int j;
|
||||
for(j = i; j <= client_entry_last; j++)
|
||||
{
|
||||
if(!mac_is_equal(client_array[j].bssid_addr, bssid))
|
||||
{
|
||||
for (j = i; j <= client_entry_last; j++) {
|
||||
if (!mac_is_equal(client_array[j].bssid_addr, bssid)) {
|
||||
break;
|
||||
}
|
||||
if(kick_client(bssid, client_array[j].client_addr))
|
||||
{
|
||||
if (kick_client(bssid, client_array[j].client_addr)) {
|
||||
/*
|
||||
TODO: KICK ONLY FROM ONE BSSID?
|
||||
*/
|
||||
printf("KICKING CLIENT!!!!!!!!!!!!!\n");
|
||||
//del_client(client_array[j].client_addr, 5, 1, 60000);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
printf("STAAAY CLIENT!!!!!!!!!!!!!\n");
|
||||
}
|
||||
}
|
||||
|
@ -116,166 +114,135 @@ int client_array_go_next(char sort_order[], int i, client entry,
|
|||
return conditions && client_array_go_next_help(sort_order, i, entry, next_entry);
|
||||
}
|
||||
|
||||
void client_array_insert(client entry)
|
||||
{
|
||||
if(client_entry_last == -1)
|
||||
{
|
||||
void client_array_insert(client entry) {
|
||||
if (client_entry_last == -1) {
|
||||
client_array[0] = entry;
|
||||
client_entry_last++;
|
||||
return;
|
||||
}
|
||||
|
||||
int i;
|
||||
for(i = 0; i <= client_entry_last; i++)
|
||||
{
|
||||
if(!client_array_go_next("bc", 2, entry, client_array[i]))
|
||||
{
|
||||
for (i = 0; i <= client_entry_last; i++) {
|
||||
if (!client_array_go_next("bc", 2, entry, client_array[i])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(int j = client_entry_last; j >= i; j--)
|
||||
{
|
||||
if(j + 1 <= ARRAY_LEN)
|
||||
{
|
||||
for (int j = client_entry_last; j >= i; j--) {
|
||||
if (j + 1 <= ARRAY_LEN) {
|
||||
client_array[j + 1] = client_array[j];
|
||||
}
|
||||
}
|
||||
client_array[i] = entry;
|
||||
|
||||
if(client_entry_last < ARRAY_LEN)
|
||||
{
|
||||
if (client_entry_last < ARRAY_LEN) {
|
||||
client_entry_last++;
|
||||
}
|
||||
}
|
||||
|
||||
client* client_array_delete(client entry)
|
||||
{
|
||||
client *client_array_delete(client entry) {
|
||||
|
||||
int i;
|
||||
int found_in_array = 0;
|
||||
client* tmp = NULL;
|
||||
client *tmp = NULL;
|
||||
|
||||
if(client_entry_last == -1)
|
||||
{
|
||||
if (client_entry_last == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(i = 0; i <= client_entry_last; i++)
|
||||
{
|
||||
if(mac_is_equal(entry.bssid_addr, client_array[i].bssid_addr) &&
|
||||
mac_is_equal(entry.client_addr, client_array[i].client_addr))
|
||||
{
|
||||
for (i = 0; i <= client_entry_last; i++) {
|
||||
if (mac_is_equal(entry.bssid_addr, client_array[i].bssid_addr) &&
|
||||
mac_is_equal(entry.client_addr, client_array[i].client_addr)) {
|
||||
found_in_array = 1;
|
||||
tmp = &client_array[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(int j = i; j <= client_entry_last; j++)
|
||||
{
|
||||
for (int j = i; j <= client_entry_last; j++) {
|
||||
client_array[j] = client_array[j + 1];
|
||||
}
|
||||
|
||||
if(client_entry_last > -1 && found_in_array)
|
||||
{
|
||||
if (client_entry_last > -1 && found_in_array) {
|
||||
client_entry_last--;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
void probe_array_insert(probe_entry entry)
|
||||
{
|
||||
if(probe_entry_last == -1)
|
||||
{
|
||||
void probe_array_insert(probe_entry entry) {
|
||||
if (probe_entry_last == -1) {
|
||||
probe_array[0] = entry;
|
||||
probe_entry_last++;
|
||||
return;
|
||||
}
|
||||
|
||||
int i;
|
||||
for(i = 0; i <= probe_entry_last; i++)
|
||||
{
|
||||
if(!go_next(sort_string, SORT_NUM, entry, probe_array[i]))
|
||||
{
|
||||
for (i = 0; i <= probe_entry_last; i++) {
|
||||
if (!go_next(sort_string, SORT_NUM, entry, probe_array[i])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(int j = probe_entry_last; j >= i; j--)
|
||||
{
|
||||
if(j + 1 <= ARRAY_LEN)
|
||||
{
|
||||
for (int j = probe_entry_last; j >= i; j--) {
|
||||
if (j + 1 <= ARRAY_LEN) {
|
||||
probe_array[j + 1] = probe_array[j];
|
||||
}
|
||||
}
|
||||
probe_array[i] = entry;
|
||||
|
||||
if(probe_entry_last < ARRAY_LEN)
|
||||
{
|
||||
if (probe_entry_last < ARRAY_LEN) {
|
||||
probe_entry_last++;
|
||||
}
|
||||
}
|
||||
|
||||
probe_entry* probe_array_delete(probe_entry entry)
|
||||
{
|
||||
probe_entry *probe_array_delete(probe_entry entry) {
|
||||
int i;
|
||||
int found_in_array = 0;
|
||||
probe_entry* tmp = NULL;
|
||||
probe_entry *tmp = NULL;
|
||||
|
||||
if(probe_entry_last == -1)
|
||||
{
|
||||
if (probe_entry_last == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(i = 0; i <= probe_entry_last; i++)
|
||||
{
|
||||
if(mac_is_equal(entry.bssid_addr, probe_array[i].bssid_addr) &&
|
||||
mac_is_equal(entry.client_addr, probe_array[i].client_addr))
|
||||
{
|
||||
for (i = 0; i <= probe_entry_last; i++) {
|
||||
if (mac_is_equal(entry.bssid_addr, probe_array[i].bssid_addr) &&
|
||||
mac_is_equal(entry.client_addr, probe_array[i].client_addr)) {
|
||||
found_in_array = 1;
|
||||
tmp = &probe_array[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(int j = i; j <= probe_entry_last; j++)
|
||||
{
|
||||
for (int j = i; j <= probe_entry_last; j++) {
|
||||
probe_array[j] = probe_array[j + 1];
|
||||
}
|
||||
|
||||
if(probe_entry_last > -1 && found_in_array)
|
||||
{
|
||||
if (probe_entry_last > -1 && found_in_array) {
|
||||
probe_entry_last--;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void print_array()
|
||||
{
|
||||
void print_array() {
|
||||
printf("------------------\n");
|
||||
printf("Probe Entry Last: %d\n", probe_entry_last);
|
||||
for(int i = 0; i <= probe_entry_last; i++)
|
||||
{
|
||||
for (int i = 0; i <= probe_entry_last; i++) {
|
||||
print_probe_entry(probe_array[i]);
|
||||
}
|
||||
printf("------------------\n");
|
||||
}
|
||||
|
||||
void insert_to_array(probe_entry entry, int inc_counter)
|
||||
{
|
||||
void insert_to_array(probe_entry entry, int inc_counter) {
|
||||
pthread_mutex_lock(&probe_array_mutex);
|
||||
|
||||
entry.time = time(0);
|
||||
entry.counter = 0;
|
||||
probe_entry* tmp = probe_array_delete(entry);
|
||||
probe_entry *tmp = probe_array_delete(entry);
|
||||
|
||||
if(tmp != NULL)
|
||||
{
|
||||
if (tmp != NULL) {
|
||||
entry.counter = tmp->counter;
|
||||
}
|
||||
|
||||
if (inc_counter)
|
||||
{
|
||||
if (inc_counter) {
|
||||
entry.counter++;
|
||||
}
|
||||
|
||||
|
@ -284,23 +251,17 @@ void insert_to_array(probe_entry entry, int inc_counter)
|
|||
pthread_mutex_unlock(&probe_array_mutex);
|
||||
}
|
||||
|
||||
void remove_old_client_entries(time_t current_time, long long int threshold)
|
||||
{
|
||||
for(int i = 0; i < probe_entry_last; i++)
|
||||
{
|
||||
if (client_array[i].time < current_time - threshold)
|
||||
{
|
||||
void remove_old_client_entries(time_t current_time, long long int threshold) {
|
||||
for (int i = 0; i < probe_entry_last; i++) {
|
||||
if (client_array[i].time < current_time - threshold) {
|
||||
client_array_delete(client_array[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void remove_old_probe_entries(time_t current_time, long long int threshold)
|
||||
{
|
||||
for(int i = 0; i < probe_entry_last; i++)
|
||||
{
|
||||
if (probe_array[i].time < current_time - threshold)
|
||||
{
|
||||
void remove_old_probe_entries(time_t current_time, long long int threshold) {
|
||||
for (int i = 0; i < probe_entry_last; i++) {
|
||||
if (probe_array[i].time < current_time - threshold) {
|
||||
probe_array_delete(probe_array[i]);
|
||||
}
|
||||
}
|
||||
|
@ -329,8 +290,7 @@ void *remove_client_array_thread(void *arg) {
|
|||
}
|
||||
|
||||
|
||||
void insert_client_to_array(client entry)
|
||||
{
|
||||
void insert_client_to_array(client entry) {
|
||||
pthread_mutex_lock(&client_array_mutex);
|
||||
entry.time = time(0);
|
||||
|
||||
|
@ -341,19 +301,17 @@ void insert_client_to_array(client entry)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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, int inc_counter) {
|
||||
|
@ -437,7 +395,7 @@ int go_next(char sort_order[], int i, probe_entry entry,
|
|||
|
||||
node *insert(node *head, probe_entry entry) {
|
||||
node *temp, *prev, *next;
|
||||
temp = (node *)malloc(sizeof(node));
|
||||
temp = (node *) malloc(sizeof(node));
|
||||
temp->data = entry;
|
||||
temp->ptr = NULL;
|
||||
|
||||
|
@ -680,8 +638,7 @@ void print_client_entry(client entry) {
|
|||
void print_client_array() {
|
||||
printf("--------Clients------\n");
|
||||
printf("Client Entry Last: %d\n", client_entry_last);
|
||||
for(int i = 0; i <= client_entry_last; i++)
|
||||
{
|
||||
for (int i = 0; i <= client_entry_last; i++) {
|
||||
print_client_entry(client_array[i]);
|
||||
}
|
||||
printf("------------------\n");
|
||||
|
|
|
@ -87,12 +87,17 @@ static const struct blobmsg_policy client_policy[__CLIENT_MAX] = {
|
|||
/* Function Definitions */
|
||||
static void hostapd_handle_remove(struct ubus_context *ctx,
|
||||
struct ubus_subscriber *s, uint32_t id);
|
||||
|
||||
static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg);
|
||||
|
||||
static int add_subscriber(char *name);
|
||||
|
||||
static int subscribe_to_hostapd_interfaces(char *hostapd_dir);
|
||||
|
||||
static int ubus_get_clients();
|
||||
|
||||
/*
|
||||
static int decide_function(probe_entry *prob_req) {
|
||||
// TODO: Refactor...
|
||||
|
@ -235,17 +240,7 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) {
|
|||
subscribe_to_hostapd_interfaces(hostapd_dir);
|
||||
|
||||
ubus_get_clients();
|
||||
/*
|
||||
printf("Deleting Client\n");
|
||||
//"78:02:f8:bc:ac:0b"
|
||||
|
||||
int tmp_int_mac[ETH_ALEN];
|
||||
uint8_t tmp_mac[ETH_ALEN];
|
||||
sscanf("78:02:f8:bc:ac:0b", "%x:%x:%x:%x:%x:%x", STR2MAC(tmp_int_mac));
|
||||
for(int i = 0; i < ETH_ALEN; ++i )
|
||||
tmp_mac[i] = (uint8_t) tmp_int_mac[i];
|
||||
del_client(tmp_mac, 5, 1, 60000);
|
||||
*/
|
||||
uloop_run();
|
||||
|
||||
close_socket();
|
||||
|
@ -256,8 +251,8 @@ int dawn_init_ubus(const char *ubus_socket, char *hostapd_dir) {
|
|||
}
|
||||
|
||||
static void
|
||||
dump_client(struct blob_attr **tb, uint8_t client_addr[], const char* bssid_addr, uint32_t freq, uint8_t ht_supported, uint8_t vht_supported)
|
||||
{
|
||||
dump_client(struct blob_attr **tb, uint8_t client_addr[], const char *bssid_addr, uint32_t freq, uint8_t ht_supported,
|
||||
uint8_t vht_supported) {
|
||||
client client_entry;
|
||||
|
||||
hwaddr_aton(bssid_addr, client_entry.bssid_addr);
|
||||
|
@ -281,32 +276,31 @@ dump_client(struct blob_attr **tb, uint8_t client_addr[], const char* bssid_addr
|
|||
if (tb[CLIENT_ASSOC]) {
|
||||
client_entry.assoc = blobmsg_get_u8(tb[CLIENT_ASSOC]);
|
||||
}
|
||||
if(tb[CLIENT_AUTHORIZED])
|
||||
{
|
||||
if (tb[CLIENT_AUTHORIZED]) {
|
||||
client_entry.authorized = blobmsg_get_u8(tb[CLIENT_AUTHORIZED]);
|
||||
}
|
||||
if(tb[CLIENT_PREAUTH]){
|
||||
if (tb[CLIENT_PREAUTH]) {
|
||||
client_entry.preauth = blobmsg_get_u8(tb[CLIENT_PREAUTH]);
|
||||
}
|
||||
if(tb[CLIENT_WDS]){
|
||||
if (tb[CLIENT_WDS]) {
|
||||
client_entry.wds = blobmsg_get_u8(tb[CLIENT_WDS]);
|
||||
}
|
||||
if(tb[CLIENT_WMM]){
|
||||
if (tb[CLIENT_WMM]) {
|
||||
client_entry.wmm = blobmsg_get_u8(tb[CLIENT_WMM]);
|
||||
}
|
||||
if(tb[CLIENT_HT]){
|
||||
if (tb[CLIENT_HT]) {
|
||||
client_entry.ht = blobmsg_get_u8(tb[CLIENT_HT]);
|
||||
}
|
||||
if(tb[CLIENT_VHT]){
|
||||
if (tb[CLIENT_VHT]) {
|
||||
client_entry.vht = blobmsg_get_u8(tb[CLIENT_VHT]);
|
||||
}
|
||||
if(tb[CLIENT_WPS]){
|
||||
if (tb[CLIENT_WPS]) {
|
||||
client_entry.wps = blobmsg_get_u8(tb[CLIENT_WPS]);
|
||||
}
|
||||
if(tb[CLIENT_MFP]){
|
||||
if (tb[CLIENT_MFP]) {
|
||||
client_entry.mfp = blobmsg_get_u8(tb[CLIENT_MFP]);
|
||||
}
|
||||
if(tb[CLIENT_AID]){
|
||||
if (tb[CLIENT_AID]) {
|
||||
client_entry.aid = blobmsg_get_u32(tb[CLIENT_AID]);
|
||||
}
|
||||
|
||||
|
@ -314,12 +308,13 @@ dump_client(struct blob_attr **tb, uint8_t client_addr[], const char* bssid_addr
|
|||
}
|
||||
|
||||
static void
|
||||
dump_client_table(struct blob_attr *head, int len, const char* bssid_addr, uint32_t freq, uint8_t ht_supported, uint8_t vht_supported)
|
||||
{
|
||||
dump_client_table(struct blob_attr *head, int len, const char *bssid_addr, uint32_t freq, uint8_t ht_supported,
|
||||
uint8_t vht_supported) {
|
||||
struct blob_attr *attr;
|
||||
struct blobmsg_hdr *hdr;
|
||||
|
||||
__blob_for_each_attr(attr, head, len) {
|
||||
__blob_for_each_attr(attr, head, len)
|
||||
{
|
||||
hdr = blob_data(attr);
|
||||
|
||||
struct blob_attr *tb[__CLIENT_MAX];
|
||||
|
@ -328,8 +323,8 @@ dump_client_table(struct blob_attr *head, int len, const char* bssid_addr, uint3
|
|||
|
||||
int tmp_int_mac[ETH_ALEN];
|
||||
uint8_t tmp_mac[ETH_ALEN];
|
||||
sscanf((char*)hdr->name, "%x:%x:%x:%x:%x:%x", STR2MAC(tmp_int_mac));
|
||||
for(int i = 0; i < ETH_ALEN; ++i )
|
||||
sscanf((char *) hdr->name, "%x:%x:%x:%x:%x:%x", STR2MAC(tmp_int_mac));
|
||||
for (int i = 0; i < ETH_ALEN; ++i)
|
||||
tmp_mac[i] = (uint8_t) tmp_int_mac[i];
|
||||
|
||||
dump_client(tb, tmp_mac, bssid_addr, freq, ht_supported, vht_supported);
|
||||
|
@ -341,8 +336,11 @@ int parse_to_clients(struct blob_attr *msg) {
|
|||
|
||||
blobmsg_parse(client_table_policy, __CLIENT_TABLE_MAX, tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
if (tb[CLIENT_TABLE] && tb[CLIENT_TABLE_BSSID] && tb[CLIENT_TABLE_FREQ] && tb[CLIENT_TABLE_HT] && tb[CLIENT_TABLE_VHT]) {
|
||||
dump_client_table(blobmsg_data(tb[CLIENT_TABLE]), blobmsg_data_len(tb[CLIENT_TABLE]), blobmsg_data(tb[CLIENT_TABLE_BSSID]), blobmsg_get_u32(tb[CLIENT_TABLE_FREQ]), blobmsg_get_u8(tb[CLIENT_TABLE_HT]), blobmsg_get_u8(tb[CLIENT_TABLE_VHT]));
|
||||
if (tb[CLIENT_TABLE] && tb[CLIENT_TABLE_BSSID] && tb[CLIENT_TABLE_FREQ] && tb[CLIENT_TABLE_HT] &&
|
||||
tb[CLIENT_TABLE_VHT]) {
|
||||
dump_client_table(blobmsg_data(tb[CLIENT_TABLE]), blobmsg_data_len(tb[CLIENT_TABLE]),
|
||||
blobmsg_data(tb[CLIENT_TABLE_BSSID]), blobmsg_get_u32(tb[CLIENT_TABLE_FREQ]),
|
||||
blobmsg_get_u8(tb[CLIENT_TABLE_HT]), blobmsg_get_u8(tb[CLIENT_TABLE_VHT]));
|
||||
|
||||
/* BSSID */
|
||||
/*
|
||||
|
@ -357,8 +355,7 @@ int parse_to_clients(struct blob_attr *msg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_attr *msg)
|
||||
{
|
||||
static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_attr *msg) {
|
||||
if (!msg)
|
||||
return;
|
||||
|
||||
|
@ -380,8 +377,7 @@ static int ubus_get_clients() {
|
|||
uint32_t id;
|
||||
sprintf(hostapd_iface, "hostapd.%s", entry->d_name);
|
||||
int ret = ubus_lookup_id(ctx, hostapd_iface, &id);
|
||||
if(!ret)
|
||||
{
|
||||
if (!ret) {
|
||||
int timeout = 1;
|
||||
ubus_invoke(ctx, id, "get_clients", NULL, ubus_get_clients_cb, NULL, timeout * 1000);
|
||||
}
|
||||
|
@ -390,9 +386,8 @@ static int ubus_get_clients() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *update_clients_thread(void *arg)
|
||||
{
|
||||
while (1){
|
||||
void *update_clients_thread(void *arg) {
|
||||
while (1) {
|
||||
sleep(TIME_THRESHOLD_CLIENT_UPDATE);
|
||||
printf("[Thread] : Updating clients!\n");
|
||||
ubus_get_clients();
|
||||
|
@ -404,8 +399,7 @@ void *update_clients_thread(void *arg)
|
|||
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
|
||||
|
||||
static void
|
||||
blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr)
|
||||
{
|
||||
bblobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr) {
|
||||
char *s;
|
||||
|
||||
s = blobmsg_alloc_string_buffer(buf, name, 20);
|
||||
|
@ -413,8 +407,7 @@ blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const uint8_t *addr)
|
|||
blobmsg_add_string_buffer(buf);
|
||||
}
|
||||
|
||||
void del_client(const uint8_t* client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time)
|
||||
{
|
||||
void del_client(const uint8_t *client_addr, uint32_t reason, uint8_t deauth, uint32_t ban_time) {
|
||||
/* Problem:
|
||||
On which interface is the client?
|
||||
First send to all ifaces to ban client... xD
|
||||
|
@ -439,8 +432,7 @@ void del_client(const uint8_t* client_addr, uint32_t reason, uint8_t deauth, uin
|
|||
uint32_t id;
|
||||
sprintf(hostapd_iface, "hostapd.%s", entry->d_name);
|
||||
int ret = ubus_lookup_id(ctx, hostapd_iface, &id);
|
||||
if(!ret)
|
||||
{
|
||||
if (!ret) {
|
||||
int timeout = 1;
|
||||
ubus_invoke(ctx, id, "del_client", b.head, NULL, NULL, timeout * 1000);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue