reformat code

This commit is contained in:
PolynomialDivision 2018-04-12 22:22:40 +02:00
parent f2348e0ae7
commit 40ba9d7f8d
8 changed files with 76 additions and 109 deletions

View file

@ -131,6 +131,7 @@ typedef struct auth_entry_s assoc_entry;
#define DENY_REQ_ARRAY_LEN 100 #define DENY_REQ_ARRAY_LEN 100
struct auth_entry_s denied_req_array[DENY_REQ_ARRAY_LEN]; struct auth_entry_s denied_req_array[DENY_REQ_ARRAY_LEN];
pthread_mutex_t denied_array_mutex; pthread_mutex_t denied_array_mutex;
auth_entry insert_to_denied_req_array(auth_entry entry, int inc_counter); auth_entry insert_to_denied_req_array(auth_entry entry, int inc_counter);
// ---------------- Defines ---------------- // ---------------- Defines ----------------

View file

@ -42,14 +42,12 @@ int init_socket_runopts(const char *_ip, int _port, int _multicast_socket) {
} }
pthread_t sniffer_thread; pthread_t sniffer_thread;
if(network_config.use_symm_enc) if (network_config.use_symm_enc) {
{
if (pthread_create(&sniffer_thread, NULL, receive_msg_enc, NULL)) { if (pthread_create(&sniffer_thread, NULL, receive_msg_enc, NULL)) {
fprintf(stderr, "Could not create receiving thread!"); fprintf(stderr, "Could not create receiving thread!");
return -1; return -1;
} }
} else } else {
{
if (pthread_create(&sniffer_thread, NULL, receive_msg, NULL)) { if (pthread_create(&sniffer_thread, NULL, receive_msg, NULL)) {
fprintf(stderr, "Could not create receiving thread!"); fprintf(stderr, "Could not create receiving thread!");
return -1; return -1;

View file

@ -46,6 +46,7 @@ int is_connected_somehwere(uint8_t client_addr[]);
int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, uint8_t *client_addr, int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare, uint8_t *client_addr,
int automatic_kick); int automatic_kick);
int compare_ssid(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare); int compare_ssid(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare);
void denied_req_array_insert(auth_entry entry); void denied_req_array_insert(auth_entry entry);
@ -88,8 +89,7 @@ struct uloop_timeout denied_req_timeout = {
.cb = denied_req_array_cb .cb = denied_req_array_cb
}; };
int build_hearing_map_sort_client(struct blob_buf *b) int build_hearing_map_sort_client(struct blob_buf *b) {
{
print_probe_array(); print_probe_array();
pthread_mutex_lock(&probe_array_mutex); pthread_mutex_lock(&probe_array_mutex);
@ -101,10 +101,8 @@ int build_hearing_map_sort_client(struct blob_buf *b)
int m; int m;
for (m = 0; m <= ap_entry_last; m++) { for (m = 0; m <= ap_entry_last; m++) {
printf("COMPARING!\n"); printf("COMPARING!\n");
if(m > 0) if (m > 0) {
{ if (strcmp((char *) ap_array[m].ssid, (char *) ap_array[m - 1].ssid) == 0) {
if(strcmp((char*)ap_array[m].ssid, (char*)ap_array[m-1].ssid) == 0)
{
continue; continue;
} }
} }
@ -124,8 +122,7 @@ int build_hearing_map_sort_client(struct blob_buf *b)
continue; continue;
} }
if(strcmp((char*)ap_entry_i.ssid, (char*)ap_array[m].ssid) != 0) if (strcmp((char *) ap_entry_i.ssid, (char *) ap_array[m].ssid) != 0) {
{
continue; continue;
} }
@ -139,16 +136,14 @@ int build_hearing_map_sort_client(struct blob_buf *b)
continue; continue;
} }
if(strcmp((char*)ap_entry.ssid, (char*)ap_array[m].ssid) != 0) if (strcmp((char *) ap_entry.ssid, (char *) ap_array[m].ssid) != 0) {
{
continue; continue;
} }
if (!mac_is_equal(probe_array[k].client_addr, probe_array[i].client_addr)) { if (!mac_is_equal(probe_array[k].client_addr, probe_array[i].client_addr)) {
i = k - 1; i = k - 1;
break; break;
} else if(k == probe_entry_last) } else if (k == probe_entry_last) {
{
i = k; i = k;
} }
@ -177,8 +172,7 @@ int build_hearing_map_sort_client(struct blob_buf *b)
return 0; return 0;
} }
int build_network_overview(struct blob_buf *b) int build_network_overview(struct blob_buf *b) {
{
void *client_list, *ap_list, *ssid_list; void *client_list, *ap_list, *ssid_list;
char ap_mac_buf[20]; char ap_mac_buf[20];
char client_mac_buf[20]; char client_mac_buf[20];
@ -187,10 +181,8 @@ int build_network_overview(struct blob_buf *b)
int m; int m;
for (m = 0; m <= ap_entry_last; m++) { for (m = 0; m <= ap_entry_last; m++) {
printf("COMPARING!\n"); printf("COMPARING!\n");
if(m > 0) if (m > 0) {
{ if (strcmp((char *) ap_array[m].ssid, (char *) ap_array[m - 1].ssid) == 0) {
if(strcmp((char*)ap_array[m].ssid, (char*)ap_array[m-1].ssid) == 0)
{
continue; continue;
} }
} }
@ -201,8 +193,7 @@ int build_network_overview(struct blob_buf *b)
for (i = 0; i <= client_entry_last; i++) { for (i = 0; i <= client_entry_last; i++) {
ap ap_entry_i = ap_array_get_ap(client_array[i].bssid_addr); ap ap_entry_i = ap_array_get_ap(client_array[i].bssid_addr);
if(strcmp((char*)ap_entry_i.ssid, (char*)ap_array[m].ssid) != 0) if (strcmp((char *) ap_entry_i.ssid, (char *) ap_array[m].ssid) != 0) {
{
continue; continue;
} }
int k; int k;
@ -210,12 +201,10 @@ int build_network_overview(struct blob_buf *b)
ap_list = blobmsg_open_table(b, ap_mac_buf); ap_list = blobmsg_open_table(b, ap_mac_buf);
printf("AP MAC BUF: %s\n", ap_mac_buf); printf("AP MAC BUF: %s\n", ap_mac_buf);
for (k = i; k <= client_entry_last; k++) { for (k = i; k <= client_entry_last; k++) {
if(!mac_is_equal(client_array[k].bssid_addr, client_array[i].bssid_addr)) if (!mac_is_equal(client_array[k].bssid_addr, client_array[i].bssid_addr)) {
{
i = k - 1; i = k - 1;
break; break;
} else if(k == client_entry_last) } else if (k == client_entry_last) {
{
i = k; i = k;
} }
@ -246,8 +235,7 @@ int eval_probe_metric(struct probe_entry_s probe_entry) {
score += !probe_entry.ht_support && !ap_entry.ht ? dawn_metric.no_ht_support : 0; score += !probe_entry.ht_support && !ap_entry.ht ? dawn_metric.no_ht_support : 0;
// performance anomaly? // performance anomaly?
if(network_config.bandwidth >= 1000 || network_config.bandwidth == -1) if (network_config.bandwidth >= 1000 || network_config.bandwidth == -1) {
{
score += probe_entry.vht_support && ap_entry.vht ? dawn_metric.vht_support : 0; score += probe_entry.vht_support && ap_entry.vht ? dawn_metric.vht_support : 0;
} }
@ -274,8 +262,7 @@ int compare_ssid(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compare) {
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);
if (mac_is_equal(ap_entry_own.bssid_addr, bssid_addr_own) && if (mac_is_equal(ap_entry_own.bssid_addr, bssid_addr_own) &&
mac_is_equal(ap_entry_to_compre.bssid_addr, bssid_addr_to_compare)) mac_is_equal(ap_entry_to_compre.bssid_addr, bssid_addr_to_compare)) {
{
return (strcmp((char *) ap_entry_own.ssid, (char *) ap_entry_to_compre.ssid) == 0); return (strcmp((char *) ap_entry_own.ssid, (char *) ap_entry_to_compre.ssid) == 0);
} }
return 0; return 0;
@ -296,14 +283,12 @@ int compare_station_count(uint8_t *bssid_addr_own, uint8_t *bssid_addr_to_compar
int sta_count = ap_entry_own.station_count; int sta_count = ap_entry_own.station_count;
int sta_count_to_compare = ap_entry_to_compre.station_count; int sta_count_to_compare = ap_entry_to_compre.station_count;
if(is_connected(bssid_addr_own, client_addr)) if (is_connected(bssid_addr_own, client_addr)) {
{
printf("OWN IS ALREADY CONNECTED! DECREASE COUNTER!!!\n"); printf("OWN IS ALREADY CONNECTED! DECREASE COUNTER!!!\n");
sta_count--; sta_count--;
} }
if(is_connected(bssid_addr_to_compare, client_addr)) if (is_connected(bssid_addr_to_compare, client_addr)) {
{
printf("COMPARE IS ALREADY CONNECTED! DECREASE COUNTER!!!\n"); printf("COMPARE IS ALREADY CONNECTED! DECREASE COUNTER!!!\n");
sta_count_to_compare--; sta_count_to_compare--;
} }
@ -363,8 +348,7 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat
} }
// check if same ssid! // check if same ssid!
if(!compare_ssid(bssid_addr, probe_array[k].bssid_addr)) if (!compare_ssid(bssid_addr, probe_array[k].bssid_addr)) {
{
continue; continue;
} }
@ -391,7 +375,8 @@ int better_ap_available(uint8_t bssid_addr[], uint8_t client_addr[], int automat
} }
int kick_client(struct client_s client_entry) { int kick_client(struct client_s client_entry) {
return !mac_in_maclist(client_entry.client_addr) && better_ap_available(client_entry.bssid_addr, client_entry.client_addr, 1); return !mac_in_maclist(client_entry.client_addr) &&
better_ap_available(client_entry.bssid_addr, client_entry.client_addr, 1);
} }
void kick_clients(uint8_t bssid[], uint32_t id) { void kick_clients(uint8_t bssid[], uint32_t id) {
@ -444,7 +429,8 @@ void kick_clients(uint8_t bssid[], uint32_t id) {
// + chan util is changing a lot // + chan util is changing a lot
// + ping pong behavior of clients will be reduced // + ping pong behavior of clients will be reduced
client_array[j].kick_count++; client_array[j].kick_count++;
printf("Comparing kick count kickcount: %d to min_kick_count: %d!\n", client_array[j].kick_count, dawn_metric.min_kick_count); printf("Comparing kick count kickcount: %d to min_kick_count: %d!\n", client_array[j].kick_count,
dawn_metric.min_kick_count);
if (client_array[j].kick_count < dawn_metric.min_kick_count) { if (client_array[j].kick_count < dawn_metric.min_kick_count) {
continue; continue;
} }
@ -683,8 +669,7 @@ int probe_array_set_all_probe_count(uint8_t client_addr[], uint32_t probe_count)
if (mac_is_equal(client_addr, probe_array[i].client_addr)) { if (mac_is_equal(client_addr, probe_array[i].client_addr)) {
printf("SETTING MAC!!!\n"); printf("SETTING MAC!!!\n");
probe_array[i].counter = probe_count; probe_array[i].counter = probe_count;
}else if(!mac_is_greater(client_addr, probe_array[i].client_addr)) } else if (!mac_is_greater(client_addr, probe_array[i].client_addr)) {
{
printf("MAC NOT FOUND!!!\n"); printf("MAC NOT FOUND!!!\n");
break; break;
} }
@ -952,8 +937,7 @@ void denied_req_array_cb(struct uloop_timeout *t) {
if (denied_req_array[i].time < current_time - timeout_config.denied_req_threshold) { if (denied_req_array[i].time < current_time - timeout_config.denied_req_threshold) {
// client is not connected for a given time threshold! // client is not connected for a given time threshold!
if(!is_connected_somehwere(denied_req_array[i].client_addr)) if (!is_connected_somehwere(denied_req_array[i].client_addr)) {
{
printf("Client has propaly a BAD DRIVER!\n"); printf("Client has propaly a BAD DRIVER!\n");
// problem that somehow station will land into this list // problem that somehow station will land into this list
@ -986,8 +970,7 @@ void insert_client_to_array(client entry) {
pthread_mutex_unlock(&client_array_mutex); pthread_mutex_unlock(&client_array_mutex);
} }
void insert_macs_from_file() void insert_macs_from_file() {
{
FILE *fp; FILE *fp;
char *line = NULL; char *line = NULL;
size_t len = 0; size_t len = 0;
@ -1011,8 +994,7 @@ void insert_macs_from_file()
} }
printf("Printing MAC List:\n"); printf("Printing MAC List:\n");
for(int i = 0; i <= mac_list_entry_last; i++) for (int i = 0; i <= mac_list_entry_last; i++) {
{
char mac_buf_target[20]; char mac_buf_target[20];
sprintf(mac_buf_target, MACSTR, MAC2STR(mac_list[i])); sprintf(mac_buf_target, MACSTR, MAC2STR(mac_list[i]));
printf("%d: %s\n", i, mac_buf_target); printf("%d: %s\n", i, mac_buf_target);
@ -1024,10 +1006,8 @@ void insert_macs_from_file()
//exit(EXIT_SUCCESS); //exit(EXIT_SUCCESS);
} }
int insert_to_maclist(uint8_t mac[]) int insert_to_maclist(uint8_t mac[]) {
{ if (mac_in_maclist(mac)) {
if(mac_in_maclist(mac))
{
return -1; return -1;
} }
@ -1040,12 +1020,9 @@ int insert_to_maclist(uint8_t mac[])
} }
int mac_in_maclist(uint8_t mac[]) int mac_in_maclist(uint8_t mac[]) {
{ for (int i = 0; i <= mac_list_entry_last; i++) {
for(int i = 0; i <= mac_list_entry_last; i++) if (mac_is_equal(mac, mac_list[i])) {
{
if(mac_is_equal(mac, mac_list[i]))
{
return 1; return 1;
} }
} }
@ -1156,13 +1133,6 @@ auth_entry denied_req_array_delete(auth_entry entry) {
} }
node *delete_probe_req(node **ret_remove, node *head, uint8_t bssid_addr[], node *delete_probe_req(node **ret_remove, node *head, uint8_t bssid_addr[],
uint8_t client_addr[]); uint8_t client_addr[]);
@ -1482,7 +1452,8 @@ void print_probe_entry(probe_entry entry) {
printf( printf(
"bssid_addr: %s, client_addr: %s, signal: %d, freq: " "bssid_addr: %s, client_addr: %s, signal: %d, freq: "
"%d, counter: %d, vht: %d, min_rate: %d, max_rate: %d\n", "%d, counter: %d, vht: %d, min_rate: %d, max_rate: %d\n",
mac_buf_ap, mac_buf_client, entry.signal, entry.freq, entry.counter, entry.vht_support, entry.min_supp_datarate, entry.max_supp_datarate); mac_buf_ap, mac_buf_client, entry.signal, entry.freq, entry.counter, entry.vht_support,
entry.min_supp_datarate, entry.max_supp_datarate);
} }
void print_auth_entry(auth_entry entry) { void print_auth_entry(auth_entry entry) {
@ -1508,7 +1479,8 @@ void print_client_entry(client entry) {
sprintf(mac_buf_client, MACSTR, MAC2STR(entry.client_addr)); sprintf(mac_buf_client, MACSTR, MAC2STR(entry.client_addr));
printf("bssid_addr: %s, client_addr: %s, freq: %d, ht_supported: %d, vht_supported: %d, ht: %d, vht: %d, kick: %d\n", printf("bssid_addr: %s, client_addr: %s, freq: %d, ht_supported: %d, vht_supported: %d, ht: %d, vht: %d, kick: %d\n",
mac_buf_ap, mac_buf_client, entry.freq, entry.ht_supported, entry.vht_supported, entry.ht, entry.vht, entry.kick_count); mac_buf_ap, mac_buf_client, entry.freq, entry.ht_supported, entry.vht_supported, entry.ht, entry.vht,
entry.kick_count);
} }
void print_client_array() { void print_client_array() {

View file

@ -2,12 +2,10 @@
#include <stdint.h> #include <stdint.h>
double iee80211_calculate_bitrate(uint8_t supp_rate_val) double iee80211_calculate_bitrate(uint8_t supp_rate_val) {
{
return ((double) supp_rate_val) / 2; return ((double) supp_rate_val) / 2;
} }
double iee80211_calculate_expected_throughput_mbit(int exp_thr) double iee80211_calculate_expected_throughput_mbit(int exp_thr) {
{
return (((double) exp_thr) / 1000); return (((double) exp_thr) / 1000);
} }

View file

@ -637,11 +637,9 @@ int send_blob_attr_via_network(struct blob_attr *msg, char *method) {
if (network_config.network_option == 2) { if (network_config.network_option == 2) {
send_tcp(str); send_tcp(str);
} else { } else {
if(network_config.use_symm_enc) if (network_config.use_symm_enc) {
{
send_string_enc(str); send_string_enc(str);
} else } else {
{
send_string(str); send_string(str);
} }
} }