Don't display debugging output with DAWN_NO_OUTPUT

This adds #infndef DAWN_NO_OUTPUT to messages printed to stdout that are
not warnings or errors.

Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
This commit is contained in:
Eneas U de Queiroz 2021-07-14 18:41:42 -03:00 committed by Polynomdivision
parent 97e5de157f
commit 14e0f8386c
7 changed files with 202 additions and 9 deletions

View file

@ -361,9 +361,7 @@ ap *ap_array_get_ap(struct dawn_mac bssid_mac, const uint8_t* ssid);
int probe_array_set_all_probe_count(struct dawn_mac client_addr, uint32_t probe_count);
#ifndef DAWN_NO_OUTPUT
int ap_get_collision_count(int col_domain);
#endif
void send_beacon_reports(ap *a, int id);

View file

@ -37,7 +37,9 @@ int init_socket_runopts(const char *_ip, int _port, int _multicast_socket) {
multicast_socket = _multicast_socket;
if (multicast_socket) {
#ifndef DAWN_NO_OUTPUT
printf("Settingup multicastsocket!\n");
#endif
sock = setup_multicast_socket(ip, port, &addr);
} else {
sock = setup_broadcast_socket(ip, port, &addr);
@ -56,7 +58,9 @@ int init_socket_runopts(const char *_ip, int _port, int _multicast_socket) {
}
}
#ifndef DAWN_NO_OUTPUT
fprintf(stdout, "Connected to %s:%d\n", ip, port);
#endif
return 0;
}
@ -79,7 +83,9 @@ void *receive_msg(void *args) {
}
recv_string[recv_string_len] = '\0';
#ifndef DAWN_NO_OUTPUT
printf("Received network message: %s\n", recv_string);
#endif
handle_network_msg(recv_string);
}
}
@ -115,7 +121,9 @@ void *receive_msg_enc(void *args) {
return 0;
}
#ifndef DAWN_NO_OUTPUT
printf("Received network message: %s\n", dec);
#endif
dawn_free(base64_dec_str);
handle_network_msg(dec);
dawn_free(dec);

View file

@ -97,8 +97,10 @@ static void client_read_cb(struct ustream *s, int bytes) {
while(1) {
if (cl->state == READ_STATUS_READY)
{
#ifndef DAWN_NO_OUTPUT
printf("tcp_socket: commencing message...\n");
uint32_t min_len = sizeof(uint32_t); // big enough to get msg length
#endif
cl->str = dawn_malloc(HEADER_SIZE);
if (!cl->str) {
fprintf(stderr,"not enough memory (" STR_QUOTE(__LINE__) ")\n");
@ -108,7 +110,9 @@ static void client_read_cb(struct ustream *s, int bytes) {
uint32_t avail_len = ustream_pending_data(s, false);
if (avail_len < HEADER_SIZE){//ensure recv sizeof(uint32_t)
#ifndef DAWN_NO_OUTPUT
printf("not complete msg, len:%d, expected len:%u\n", avail_len, min_len);
#endif
dawn_free(cl->str);
cl->str = NULL;
break;
@ -142,7 +146,9 @@ static void client_read_cb(struct ustream *s, int bytes) {
if (cl->state == READ_STATUS_COMMENCED)
{
#ifndef DAWN_NO_OUTPUT
printf("tcp_socket: reading message...\n");
#endif
uint32_t read_len = ustream_pending_data(s, false);
if (read_len == 0)
@ -151,22 +157,30 @@ static void client_read_cb(struct ustream *s, int bytes) {
if (read_len > (cl->final_len - cl->curr_len))
read_len = cl->final_len - cl->curr_len;
#ifndef DAWN_NO_OUTPUT
printf("tcp_socket: reading %" PRIu32 " bytes to add to %" PRIu32 " of %" PRIu32 "...\n",
read_len, cl->curr_len, cl->final_len);
#endif
uint32_t this_read = ustream_read(s, cl->str + cl->curr_len, read_len);
cl->curr_len += this_read;
#ifndef DAWN_NO_OUTPUT
printf("tcp_socket: ...and we're back, now have %" PRIu32 " bytes\n", cl->curr_len);
#endif
if (cl->curr_len == cl->final_len){//ensure recv final_len bytes.
// Full message now received
cl->state = READ_STATUS_COMPLETE;
#ifndef DAWN_NO_OUTPUT
printf("tcp_socket: message completed\n");
#endif
}
}
if (cl->state == READ_STATUS_COMPLETE)
{
#ifndef DAWN_NO_OUTPUT
printf("tcp_socket: processing message...\n");
#endif
if (network_config.use_symm_enc) {
char *dec = gcrypt_decrypt_msg(cl->str + HEADER_SIZE, cl->final_len - HEADER_SIZE);//len of str is final_len
if (!dec) {
@ -189,7 +203,9 @@ static void client_read_cb(struct ustream *s, int bytes) {
}
}
#ifndef DAWN_NO_OUTPUT
printf("tcp_socket: leaving\n");
#endif
return;
}
@ -220,7 +236,9 @@ static void server_cb(struct uloop_fd *fd, unsigned int events) {
}
int run_server(int port) {
#ifndef DAWN_NO_OUTPUT
printf("Adding socket!\n");
#endif
char port_str[12];
sprintf(port_str, "%d", port);
@ -242,7 +260,9 @@ static void client_not_be_used_read_cb(struct ustream *s, int bytes) {
len = ustream_read(s, buf, sizeof(buf));
buf[len] = '\0';
#ifndef DAWN_NO_OUTPUT
printf("Read %d bytes from SSL connection: %s\n", len, buf);
#endif
}
static void connect_cb(struct uloop_fd *f, unsigned int events) {
@ -257,7 +277,9 @@ static void connect_cb(struct uloop_fd *f, unsigned int events) {
return;
}
#ifndef DAWN_NO_OUTPUT
fprintf(stderr, "Connection established\n");
#endif
uloop_fd_delete(&entry->fd);
entry->stream.stream.notify_read = client_not_be_used_read_cb;
@ -302,7 +324,9 @@ int add_tcp_conncection(char *ipv4, int port) {
tcp_entry->fd.cb = connect_cb;
uloop_fd_add(&tcp_entry->fd, ULOOP_WRITE | ULOOP_EDGE_TRIGGER);
#ifndef DAWN_NO_OUTPUT
printf("New TCP connection to %s:%d\n", ipv4, port);
#endif
list_add(&tcp_entry->list, &tcp_sock_list);
return 0;
@ -334,7 +358,9 @@ void send_tcp(char *msg) {
{
if (con->connected) {
int len_ustream = ustream_write(&con->stream.stream, final_str, final_len, 0);
#ifndef DAWN_NO_OUTPUT
printf("Ustream send: %d\n", len_ustream);
#endif
if (len_ustream <= 0) {
fprintf(stderr,"Ustream error(" STR_QUOTE(__LINE__) ")!\n");
//ERROR HANDLING!
@ -367,7 +393,9 @@ void send_tcp(char *msg) {
{
if (con->connected) {
int len_ustream = ustream_write(&con->stream.stream, final_str, final_len, 0);
#ifndef DAWN_NO_OUTPUT
printf("Ustream send: %d\n", len_ustream);
#endif
if (len_ustream <= 0) {
//ERROR HANDLING!
fprintf(stderr,"Ustream error(" STR_QUOTE(__LINE__) ")!\n");
@ -398,6 +426,7 @@ struct network_con_s* tcp_list_contains_address(struct sockaddr_in entry) {
}
void print_tcp_array() {
#ifndef DAWN_NO_OUTPUT
struct network_con_s *con;
printf("--------Connections------\n");
@ -406,4 +435,5 @@ void print_tcp_array() {
printf("Connecting to Port: %d, Connected: %s\n", ntohs(con->sock_addr.sin_port), con->connected ? "True" : "False");
}
printf("------------------\n");
#endif
}

View file

@ -22,8 +22,6 @@ static int probe_compare(probe_entry *probe1, probe_entry *probe2);
static int kick_client(ap* kicking_ap, struct client_s *client_entry, struct kicking_nr** neighbor_report);
static void print_ap_entry(ap *entry);
static int is_connected(struct dawn_mac bssid_mac, struct dawn_mac client_mac);
static int compare_station_count(ap* ap_entry_own, ap* ap_entry_to_compare, struct dawn_mac client_addr);
@ -464,8 +462,10 @@ int eval_probe_metric(struct probe_entry_s* probe_entry, ap* ap_entry) {
if (score < 0)
score = -2; // -1 already used...
#ifndef DAWN_NO_OUTPUT
printf("Score: %d of:\n", score);
print_probe_entry(probe_entry);
#endif
return score;
}
@ -473,20 +473,28 @@ int eval_probe_metric(struct probe_entry_s* probe_entry, ap* ap_entry) {
static int compare_station_count(ap* ap_entry_own, ap* ap_entry_to_compare, struct dawn_mac client_addr) {
#ifndef DAWN_NO_OUTPUT
printf("Comparing own %d to %d\n", ap_entry_own->station_count, ap_entry_to_compare->station_count);
#endif
int sta_count = ap_entry_own->station_count;
int sta_count_to_compare = ap_entry_to_compare->station_count;
if (is_connected(ap_entry_own->bssid_addr, client_addr)) {
#ifndef DAWN_NO_OUTPUT
printf("Own is already connected! Decrease counter!\n");
#endif
sta_count--;
}
if (is_connected(ap_entry_to_compare->bssid_addr, client_addr)) {
#ifndef DAWN_NO_OUTPUT
printf("Comparing station is already connected! Decrease counter!\n");
#endif
sta_count_to_compare--;
}
#ifndef DAWN_NO_OUTPUT
printf("Comparing own station count %d to %d\n", sta_count, sta_count_to_compare);
#endif
if (sta_count - sta_count_to_compare > dawn_metric.max_station_diff)
return 1;
@ -523,7 +531,9 @@ int better_ap_available(ap *kicking_ap, struct dawn_mac client_mac, struct kicki
probe_entry* own_probe = *probe_array_find_first_entry(client_mac, kicking_ap->bssid_addr, true);
int own_score = -1;
if (own_probe != NULL && mac_is_equal_bb(own_probe->client_addr, client_mac) && mac_is_equal_bb(own_probe->bssid_addr, kicking_ap->bssid_addr)) {
#ifndef DAWN_NO_OUTPUT
printf("Calculating own score!\n");
#endif
own_score = eval_probe_metric(own_probe, kicking_ap); //TODO: Should the -2 return be handled?
}
@ -540,8 +550,10 @@ int better_ap_available(ap *kicking_ap, struct dawn_mac client_mac, struct kicki
while (i != NULL && mac_is_equal_bb(i->client_addr, client_mac)) {
if (i == own_probe) {
#ifndef DAWN_NO_OUTPUT
printf("Own Score! Skipping!\n");
print_probe_entry(i);
#endif
i = i->next_probe;
continue;
}
@ -559,7 +571,9 @@ int better_ap_available(ap *kicking_ap, struct dawn_mac client_mac, struct kicki
continue;
}
#ifndef DAWN_NO_OUTPUT
printf("Calculating score to compare!\n");
#endif
int score_to_compare = eval_probe_metric(i, candidate_ap);
// Find better score...
@ -624,10 +638,12 @@ int kick_clients(ap* kicking_ap, uint32_t id) {
int kicked_clients = 0;
#ifndef DAWN_NO_OUTPUT
printf("-------- KICKING CLIENTS!!!---------\n");
char mac_buf_ap[20];
sprintf(mac_buf_ap, MACSTR, MAC2STR(kicking_ap->bssid_addr.u8));
printf("EVAL %s\n", mac_buf_ap);
#endif
// Seach for BSSID
client *j = *client_find_first_bc_entry(kicking_ap->bssid_addr, dawn_mac_null, false);
@ -637,8 +653,10 @@ int kick_clients(ap* kicking_ap, uint32_t id) {
struct kicking_nr *neighbor_report = NULL;
int do_kick = kick_client(kicking_ap, j, &neighbor_report);
#ifndef DAWN_NO_OUTPUT
for (struct kicking_nr *n = neighbor_report; n; n = n->next)
printf("Chosen AP candidate: " NR_MACSTR ", score=%d\n", NR_MAC2STR(n->nr), n->score);
#endif
// better ap available
if (do_kick > 0) {
@ -648,17 +666,23 @@ int kick_clients(ap* kicking_ap, uint32_t id) {
// + chan util is changing a lot
// + ping pong behavior of clients will be reduced
j->kick_count++;
#ifndef DAWN_NO_OUTPUT
printf("Comparing kick count! kickcount: %d to min_number_to_kick: %d!\n", j->kick_count,
dawn_metric.min_number_to_kick);
#endif
if (j->kick_count >= dawn_metric.min_number_to_kick) {
#ifndef DAWN_NO_OUTPUT
printf("Better AP available. Kicking client:\n");
print_client_entry(j);
printf("Check if client is active receiving!\n");
#endif
float rx_rate, tx_rate;
bool have_bandwidth_iwinfo = !(get_bandwidth_iwinfo(j->client_addr, &rx_rate, &tx_rate));
if (!have_bandwidth_iwinfo && dawn_metric.bandwidth_threshold > 0) {
#ifndef DAWN_NO_OUTPUT
printf("No active transmission data for client. Don't kick!\n");
#endif
}
else
{
@ -666,15 +690,19 @@ int kick_clients(ap* kicking_ap, uint32_t id) {
// <= 6MBits <- probably no transmission
// tx_rate has always some weird value so don't use ist
if (have_bandwidth_iwinfo && rx_rate > dawn_metric.bandwidth_threshold) {
#ifndef DAWN_NO_OUTPUT
printf("Client is probably in active transmisison. Don't kick! RxRate is: %f\n", rx_rate);
#endif
}
else
{
#ifndef DAWN_NO_OUTPUT
if (have_bandwidth_iwinfo)
printf("Client is probably NOT in active transmisison. KICK! RxRate is: %f\n", rx_rate);
else
printf("No active tranmission data for client, but bandwidth_threshold=%d means we don't care. KICK!\n",
dawn_metric.bandwidth_threshold);
#endif
// here we should send a messsage to set the probe.count for all aps to the min that there is no delay between switching
// the hearing map is full...
@ -708,14 +736,18 @@ int kick_clients(ap* kicking_ap, uint32_t id) {
// no entry in probe array for own bssid
// TODO: Is test against -1 from (1 && -1) portable?
else if (do_kick == -1) {
#ifndef DAWN_NO_OUTPUT
printf("No Information about client. Force reconnect:\n");
print_client_entry(j);
#endif
del_client_interface(id, j->client_addr, 0, 1, 0);
}
// ap is best
else {
#ifndef DAWN_NO_OUTPUT
printf("AP is best. Client will stay:\n");
print_client_entry(j);
#endif
// set kick counter to 0 again
j->kick_count = 0;
}
@ -725,7 +757,9 @@ int kick_clients(ap* kicking_ap, uint32_t id) {
j = j->next_entry_bc;
}
#ifndef DAWN_NO_OUTPUT
printf("---------------------------\n");
#endif
pthread_mutex_unlock(&probe_array_mutex);
pthread_mutex_unlock(&client_array_mutex);
@ -737,10 +771,12 @@ void update_iw_info(struct dawn_mac bssid_mac) {
pthread_mutex_lock(&client_array_mutex);
pthread_mutex_lock(&probe_array_mutex);
#ifndef DAWN_NO_OUTPUT
printf("-------- IW INFO UPDATE!!!---------\n");
char mac_buf_ap[20];
sprintf(mac_buf_ap, MACSTR, MAC2STR(bssid_mac.u8));
printf("EVAL %s\n", mac_buf_ap);
#endif
// Seach for BSSID
// Go threw clients
@ -748,21 +784,29 @@ void update_iw_info(struct dawn_mac bssid_mac) {
j != NULL && mac_is_equal_bb(j->bssid_addr, bssid_mac); j = j->next_entry_bc) {
// update rssi
int rssi = get_rssi_iwinfo(j->client_addr);
#ifndef DAWN_NO_OUTPUT
int exp_thr = get_expected_throughput_iwinfo(j->client_addr);
double exp_thr_tmp = iee80211_calculate_expected_throughput_mbit(exp_thr);
printf("Expected throughput %f Mbit/sec\n", exp_thr_tmp);
#endif
if (rssi != INT_MIN) {
if (!probe_array_update_rssi(j->bssid_addr, j->client_addr, rssi, true)) {
#ifndef DAWN_NO_OUTPUT
printf("Failed to update rssi!\n");
#endif
}
else {
#ifndef DAWN_NO_OUTPUT
printf("Updated rssi: %d\n", rssi);
#endif
}
}
}
#ifndef DAWN_NO_OUTPUT
printf("---------------------------\n");
#endif
pthread_mutex_unlock(&probe_array_mutex);
pthread_mutex_unlock(&client_array_mutex);
@ -987,10 +1031,14 @@ int probe_array_set_all_probe_count(struct dawn_mac client_addr, uint32_t probe_
pthread_mutex_lock(&probe_array_mutex);
for (probe_entry *i = probe_set; i != NULL; i = i->next_probe) {
if (mac_is_equal_bb(client_addr, i->client_addr)) {
#ifndef DAWN_NO_OUTPUT
printf("Setting probecount for given mac!\n");
#endif
i->counter = probe_count;
} else if (mac_compare_bb(client_addr, i->client_addr) > 0) {
#ifndef DAWN_NO_OUTPUT
printf("MAC not found!\n");
#endif
break;
}
}
@ -1050,12 +1098,14 @@ probe_entry *probe_array_get_entry(struct dawn_mac bssid_mac, struct dawn_mac cl
}
void print_probe_array() {
#ifndef DAWN_NO_OUTPUT
printf("------------------\n");
printf("Probe Entry Last: %d\n", probe_entry_last);
for (probe_entry* i = probe_set; i != NULL ; i = i->next_probe) {
print_probe_entry(i);
}
printf("------------------\n");
#endif
}
static struct probe_entry_s* insert_to_skip_array(struct probe_entry_s* entry) {
@ -1342,8 +1392,10 @@ void insert_macs_from_file() {
}
#endif
#ifndef DAWN_NO_OUTPUT
printf("Retrieved line of length %zu :\n", read);
printf("%s", line);
#endif
// Need to scanf to an array of ints as there is no byte format specifier
int tmp_int_mac[ETH_ALEN];
@ -1365,12 +1417,14 @@ void insert_macs_from_file() {
}
}
#ifndef DAWN_NO_OUTPUT
printf("Printing MAC list:\n");
for (struct mac_entry_s *i = mac_set; i != NULL; i = i->next_mac) {
char mac_buf_target[20];
sprintf(mac_buf_target, MACSTR, MAC2STR(i->mac.u8));
printf("%s\n", mac_buf_target);
}
#endif
fclose(fp);
dawn_unregmem(fp);
@ -1554,16 +1608,18 @@ void print_client_entry(client *entry) {
}
void print_client_array() {
#ifndef DAWN_NO_OUTPUT
printf("--------Clients------\n");
printf("Client Entry Last: %d\n", client_entry_last);
for (client* i = client_set_bc; i != NULL; i = i->next_entry_bc) {
print_client_entry(i);
}
printf("------------------\n");
#endif
}
static void print_ap_entry(ap *entry) {
#ifndef DAWN_NO_OUTPUT
static void print_ap_entry(ap *entry) {
char mac_buf_ap[20];
sprintf(mac_buf_ap, MACSTR, MAC2STR(entry->bssid_addr.u8));
@ -1572,21 +1628,25 @@ static void print_ap_entry(ap *entry) {
entry->channel_utilization, entry->collision_domain, entry->bandwidth,
ap_get_collision_count(entry->collision_domain), entry->neighbor_report
);
#endif
}
#endif
void print_ap_array() {
#ifndef DAWN_NO_OUTPUT
printf("--------APs------\n");
for (ap *i = ap_set; i != NULL; i = i->next_ap) {
print_ap_entry(i);
}
printf("------------------\n");
#endif
}
void destroy_mutex() {
// free resources
#ifndef DAWN_NO_OUTPUT
fprintf(stdout, "Freeing mutex resources\n");
#endif
pthread_mutex_destroy(&probe_array_mutex);
pthread_mutex_destroy(&client_array_mutex);
pthread_mutex_destroy(&ap_array_mutex);

View file

@ -72,7 +72,9 @@ int compare_essid_iwinfo(struct dawn_mac bssid_addr, struct dawn_mac bssid_addr_
}
closedir(dirp);
#ifndef DAWN_NO_OUTPUT
printf("Comparing: %s with %s\n", essid, essid_to_compare);
#endif
if (essid == NULL || essid_to_compare == NULL) {
return -1;
@ -120,11 +122,15 @@ int get_bandwidth(const char *ifname, struct dawn_mac client_addr, float *rx_rat
iw = iwinfo_backend(ifname);
if (iw->assoclist(ifname, buf, &len)) {
#ifndef DAWN_NO_OUTPUT
fprintf(stdout, "No information available\n");
#endif
iwinfo_finish();
return 0;
} else if (len <= 0) {
#ifndef DAWN_NO_OUTPUT
fprintf(stdout, "No station connected\n");
#endif
iwinfo_finish();
return 0;
}
@ -177,11 +183,15 @@ int get_rssi(const char *ifname, struct dawn_mac client_addr) {
iw = iwinfo_backend(ifname);
if (iw->assoclist(ifname, buf, &len)) {
#ifndef DAWN_NO_OUTPUT
fprintf(stdout, "No information available\n");
#endif
iwinfo_finish();
return INT_MIN;
} else if (len <= 0) {
#ifndef DAWN_NO_OUTPUT
fprintf(stdout, "No station connected\n");
#endif
iwinfo_finish();
return INT_MIN;
}
@ -233,11 +243,15 @@ int get_expected_throughput(const char *ifname, struct dawn_mac client_addr) {
iw = iwinfo_backend(ifname);
if (iw->assoclist(ifname, buf, &len)) {
#ifndef DAWN_NO_OUTPUT
fprintf(stdout, "No information available\n");
#endif
iwinfo_finish();
return INT_MIN;
} else if (len <= 0) {
#ifndef DAWN_NO_OUTPUT
fprintf(stdout, "No station connected\n");
#endif
iwinfo_finish();
return INT_MIN;
}
@ -348,7 +362,9 @@ int support_ht(const char *ifname) {
if (iw->htmodelist(ifname, &htmodes))
{
#ifndef DAWN_NO_OUTPUT
printf("No HT mode information available\n");
#endif
iwinfo_finish();
return 0;
}

View file

@ -228,7 +228,9 @@ int handle_deauth_req(struct blob_attr* msg) {
pthread_mutex_unlock(&client_array_mutex);
#ifndef DAWN_NO_OUTPUT
printf("[WC] Deauth: %s\n", "deauth");
#endif
return 0;
}
@ -260,7 +262,9 @@ int handle_network_msg(char* msg) {
method = blobmsg_data(tb[NETWORK_METHOD]);
data = blobmsg_data(tb[NETWORK_DATA]);
#ifndef DAWN_NO_OUTPUT
printf("Network Method new: %s : %s\n", method, msg);
#endif
blob_buf_init(&data_buf, 0);
blobmsg_add_json_from_string(&data_buf, data);
@ -294,11 +298,15 @@ int handle_network_msg(char* msg) {
parse_to_clients(data_buf.head, 0, 0);
}
else if (strncmp(method, "deauth", 5) == 0) {
#ifndef DAWN_NO_OUTPUT
printf("METHOD DEAUTH\n");
#endif
handle_deauth_req(data_buf.head);
}
else if (strncmp(method, "setprobe", 5) == 0) {
#ifndef DAWN_NO_OUTPUT
printf("HANDLING SET PROBE!\n");
#endif
handle_set_probe(data_buf.head);
}
else if (strncmp(method, "addmac", 5) == 0) {
@ -308,7 +316,9 @@ int handle_network_msg(char* msg) {
parse_add_mac_to_file(data_buf.head);
}
else if (strncmp(method, "uci", 2) == 0) {
#ifndef DAWN_NO_OUTPUT
printf("HANDLING UCI!\n");
#endif
handle_uci_config(data_buf.head);
}
else if (strncmp(method, "beacon-report", 12) == 0) {
@ -322,7 +332,9 @@ int handle_network_msg(char* msg) {
}
else
{
#ifndef DAWN_NO_OUTPUT
printf("No method fonud for: %s\n", method);
#endif
}
return 0;

View file

@ -349,10 +349,14 @@ int parse_to_beacon_rep(struct blob_attr *msg) {
// HACKY WORKAROUND!
#ifndef DAWN_NO_OUTPUT
printf("Try update RCPI and RSNI for beacon report!\n");
#endif
if(!probe_array_update_rcpi_rsni(msg_bssid, msg_client, rcpi, rsni, true))
{
#ifndef DAWN_NO_OUTPUT
printf("Beacon: No Probe Entry Existing!\n");
#endif
probe_entry* beacon_rep = dawn_malloc(sizeof(probe_entry));
probe_entry* beacon_rep_updated = NULL;
@ -376,7 +380,9 @@ int parse_to_beacon_rep(struct blob_attr *msg) {
beacon_rep->ht_capabilities = false; // that is very problematic!!!
beacon_rep->vht_capabilities = false; // that is very problematic!!!
#ifndef DAWN_NO_OUTPUT
printf("Inserting to array!\n");
#endif
// TODO: kept original code order here - send on network first to simplify?
beacon_rep_updated = insert_to_array(beacon_rep, false, false, true, time(0));
@ -396,15 +402,19 @@ int handle_auth_req(struct blob_attr* msg) {
int ret = WLAN_STATUS_SUCCESS;
bool discard_entry = true;
#ifndef DAWN_NO_OUTPUT
print_probe_array();
#endif
auth_entry *auth_req = dawn_malloc(sizeof(struct auth_entry_s));
if (auth_req == NULL)
return -1;
parse_to_auth_req(msg, auth_req);
#ifndef DAWN_NO_OUTPUT
printf("Auth entry: ");
print_auth_entry(auth_req);
#endif
if (!mac_in_maclist(auth_req->client_addr)) {
pthread_mutex_lock(&probe_array_mutex);
@ -415,11 +425,13 @@ bool discard_entry = true;
// block if entry was not already found in probe database
if (tmp == NULL || !decide_function(tmp, REQ_TYPE_AUTH)) {
#ifndef DAWN_NO_OUTPUT
if (tmp != NULL)
{
printf("Entry found\n");
printf("Deny authentication!\n");
}
#endif
if (dawn_metric.use_driver_recog) {
if (auth_req == insert_to_denied_req_array(auth_req, 1, time(0)))
@ -427,9 +439,11 @@ bool discard_entry = true;
}
ret = dawn_metric.deny_auth_reason;
}
#ifndef DAWN_NO_OUTPUT
else
// maybe send here that the client is connected?
printf("Allow authentication!\n");
#endif
}
if (discard_entry)
@ -442,14 +456,18 @@ static int handle_assoc_req(struct blob_attr *msg) {
int ret = WLAN_STATUS_SUCCESS;
int discard_entry = true;
#ifndef DAWN_NO_OUTPUT
print_probe_array();
#endif
auth_entry* auth_req = dawn_malloc(sizeof(struct auth_entry_s));
if (auth_req == NULL)
return -1;
parse_to_assoc_req(msg, auth_req);
#ifndef DAWN_NO_OUTPUT
printf("Association entry: ");
print_auth_entry(auth_req);
#endif
if (!mac_in_maclist(auth_req->client_addr)) {
pthread_mutex_lock(&probe_array_mutex);
@ -460,6 +478,7 @@ int discard_entry = true;
// block if entry was not already found in probe database
if (tmp == NULL || !decide_function(tmp, REQ_TYPE_ASSOC)) {
#ifndef DAWN_NO_OUTPUT
if (tmp != NULL)
{
printf("Entry found\n");
@ -467,14 +486,17 @@ int discard_entry = true;
}
printf("Deny associtation!\n");
#endif
if (dawn_metric.use_driver_recog) {
if (auth_req == insert_to_denied_req_array(auth_req, 1, time(0)))
discard_entry = false;
}
return dawn_metric.deny_assoc_reason;
}
#ifndef DAWN_NO_OUTPUT
else
printf("Allow association!\n");
#endif
}
if (discard_entry)
@ -513,9 +535,13 @@ static int handle_probe_req(struct blob_attr *msg) {
static int handle_beacon_rep(struct blob_attr *msg) {
if (parse_to_beacon_rep(msg) == 0) {
#ifndef DAWN_NO_OUTPUT
printf("Inserting beacon Report!\n");
#endif
// insert_to_array(beacon_rep, 1);
#ifndef DAWN_NO_OUTPUT
printf("Sending via network!\n");
#endif
// send_blob_attr_via_network(msg, "beacon-report");
}
return 0;
@ -562,7 +588,9 @@ static int hostapd_notify(struct ubus_context *ctx, struct ubus_object *obj,
char *str;
str = blobmsg_format_json(msg, true);
dawn_regmem(str);
#ifndef DAWN_NO_OUTPUT
printf("Method new: %s : %s\n", method, str);
#endif
dawn_free(str);
struct hostapd_sock_entry *entry;
@ -604,7 +632,9 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) {
fprintf(stderr, "Failed to connect to ubus\n");
return -1;
} else {
#ifndef DAWN_NO_OUTPUT
printf("Connected to ubus\n");
#endif
dawn_regmem(ctx);
}
@ -761,7 +791,9 @@ static void ubus_get_rrm_cb(struct ubus_request *req, int type, struct blob_attr
{
char* neighborreport = blobmsg_get_string(attr);
strcpy(entry->neighbor_report,neighborreport);
#ifndef DAWN_NO_OUTPUT
printf("Copied Neighborreport: %s,\n", entry->neighbor_report);
#endif
}
i++;
}
@ -830,7 +862,9 @@ static int get_mode_from_capability(int capability) {
void ubus_send_beacon_report(client *c, ap *a, int id)
{
#ifndef DAWN_NO_OUTPUT
printf("Crafting Beacon Report\n");
#endif
int timeout = 1;
blob_buf_init(&b_beacon, 0);
blobmsg_add_macaddr(&b_beacon, "addr", c->client_addr);
@ -840,7 +874,9 @@ void ubus_send_beacon_report(client *c, ap *a, int id)
blobmsg_add_u32(&b_beacon, "mode", get_mode_from_capability(c->rrm_enabled_capa));
blobmsg_add_string(&b_beacon, "ssid", (char*)a->ssid);
#ifndef DAWN_NO_OUTPUT
printf("Invoking beacon report!\n");
#endif
ubus_invoke(ctx, id, "rrm_beacon_req", b_beacon.head, NULL, NULL, timeout * 1000);
}
@ -851,12 +887,16 @@ void update_beacon_reports(struct uloop_timeout *t) {
{
return;
}
#ifndef DAWN_NO_OUTPUT
printf("Sending beacon report!\n");
#endif
struct hostapd_sock_entry *sub;
list_for_each_entry(sub, &hostapd_sock_list, list)
{
if (sub->subscribed && (a = ap_array_get_ap(sub->bssid_addr, (uint8_t*)sub->ssid))) {
#ifndef DAWN_NO_OUTPUT
printf("Sending beacon report Sub!\n");
#endif
send_beacon_reports(a, sub->id);
}
}
@ -949,7 +989,9 @@ int wnm_disassoc_imminent(uint32_t id, const struct dawn_mac client_addr, struct
void* nbs = blobmsg_open_array(&b, "neighbors");
while(neighbor_list != NULL) {
#ifndef DAWN_NO_OUTPUT
printf("BSS TRANSITION NEIGHBOR " NR_MACSTR ", Score=%d\n", NR_MAC2STR(neighbor_list->nr), neighbor_list->score);
#endif
blobmsg_add_string(&b, NULL, neighbor_list->nr);
neighbor_list = neighbor_list->next;
}
@ -979,20 +1021,23 @@ static void ubus_umdns_cb(struct ubus_request *req, int type, struct blob_attr *
}
struct blob_attr *attr;
struct blobmsg_hdr *hdr;
int len = blobmsg_data_len(tb[DAWN_UMDNS_TABLE]);
__blob_for_each_attr(attr, blobmsg_data(tb[DAWN_UMDNS_TABLE]), len)
{
hdr = blob_data(attr);
#ifndef DAWN_NO_OUTPUT
struct blobmsg_hdr *hdr = blob_data(attr);
printf("Hostname: %s\n", hdr->name);
#endif
struct blob_attr *tb_dawn[__DAWN_UMDNS_MAX];
blobmsg_parse(dawn_umdns_policy, __DAWN_UMDNS_MAX, tb_dawn, blobmsg_data(attr), blobmsg_len(attr));
printf("Hostname: %s\n", hdr->name);
if (tb_dawn[DAWN_UMDNS_IPV4] && tb_dawn[DAWN_UMDNS_PORT]) {
#ifndef DAWN_NO_OUTPUT
printf("IPV4: %s\n", blobmsg_get_string(tb_dawn[DAWN_UMDNS_IPV4]));
printf("Port: %d\n", blobmsg_get_u32(tb_dawn[DAWN_UMDNS_PORT]));
#endif
} else {
return;
}
@ -1086,7 +1131,9 @@ int parse_add_mac_to_file(struct blob_attr *msg) {
struct blob_attr *tb[__ADD_DEL_MAC_MAX];
struct blob_attr *attr;
#ifndef DAWN_NO_OUTPUT
printf("Parsing MAC!\n");
#endif
blobmsg_parse(add_del_policy, __ADD_DEL_MAC_MAX, tb, blob_data(msg), blob_len(msg));
@ -1094,11 +1141,15 @@ int parse_add_mac_to_file(struct blob_attr *msg) {
return UBUS_STATUS_INVALID_ARGUMENT;
int len = blobmsg_data_len(tb[MAC_ADDR]);
#ifndef DAWN_NO_OUTPUT
printf("Length of array maclist: %d\n", len);
#endif
__blob_for_each_attr(attr, blobmsg_data(tb[MAC_ADDR]), len)
{
#ifndef DAWN_NO_OUTPUT
printf("Iteration through MAC-list\n");
#endif
struct dawn_mac addr;
hwaddr_aton(blobmsg_data(attr), addr.u8);
@ -1208,12 +1259,16 @@ static void enable_rrm(uint32_t id) {
static void hostapd_handle_remove(struct ubus_context *ctx,
struct ubus_subscriber *s, uint32_t id) {
#ifndef DAWN_NO_OUTPUT
fprintf(stdout, "Object %08x went away\n", id);
#endif
struct hostapd_sock_entry *hostapd_sock = container_of(s,
struct hostapd_sock_entry, subscriber);
if (hostapd_sock->id != id) {
#ifndef DAWN_NO_OUTPUT
printf("ID is not the same!\n");
#endif
return;
}
@ -1256,7 +1311,9 @@ bool subscribe(struct hostapd_sock_entry *hostapd_entry) {
enable_rrm(hostapd_entry->id);
ubus_get_rrm();
#ifndef DAWN_NO_OUTPUT
printf("Subscribed to: %s\n", hostapd_entry->iface_name);
#endif
return true;
}
@ -1441,7 +1498,9 @@ int uci_send_via_network()
}
int build_hearing_map_sort_client(struct blob_buf *b) {
#ifndef DAWN_NO_OUTPUT
print_probe_array();
#endif
pthread_mutex_lock(&probe_array_mutex);
void *client_list, *ap_list, *ssid_list;
@ -1689,9 +1748,13 @@ void uloop_add_data_cbs() {
// Or not needed as test harness not threaded?
void remove_probe_array_cb(struct uloop_timeout* t) {
pthread_mutex_lock(&probe_array_mutex);
#ifndef DAWN_NO_OUTPUT
printf("[Thread] : Removing old probe entries!\n");
#endif
remove_old_probe_entries(time(0), timeout_config.remove_probe);
#ifndef DAWN_NO_OUTPUT
printf("[Thread] : Removing old entries finished!\n");
#endif
pthread_mutex_unlock(&probe_array_mutex);
uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000);
}
@ -1700,7 +1763,9 @@ void remove_probe_array_cb(struct uloop_timeout* t) {
// Or not needed as test harness not threaded?
void remove_client_array_cb(struct uloop_timeout* t) {
pthread_mutex_lock(&client_array_mutex);
#ifndef DAWN_NO_OUTPUT
printf("[Thread] : Removing old client entries!\n");
#endif
remove_old_client_entries(time(0), timeout_config.update_client);
pthread_mutex_unlock(&client_array_mutex);
uloop_timeout_set(&client_timeout, timeout_config.update_client * 1000);
@ -1710,7 +1775,9 @@ void remove_client_array_cb(struct uloop_timeout* t) {
// Or not needed as test harness not threaded?
void remove_ap_array_cb(struct uloop_timeout* t) {
pthread_mutex_lock(&ap_array_mutex);
#ifndef DAWN_NO_OUTPUT
printf("[ULOOP] : Removing old ap entries!\n");
#endif
remove_old_ap_entries(time(0), timeout_config.remove_ap);
pthread_mutex_unlock(&ap_array_mutex);
uloop_timeout_set(&ap_timeout, timeout_config.remove_ap * 1000);
@ -1720,7 +1787,9 @@ void remove_ap_array_cb(struct uloop_timeout* t) {
// Or not needed as test harness not threaded?
void denied_req_array_cb(struct uloop_timeout* t) {
pthread_mutex_lock(&denied_array_mutex);
#ifndef DAWN_NO_OUTPUT
printf("[ULOOP] : Processing denied authentication!\n");
#endif
remove_old_denied_req_entries(time(0), timeout_config.denied_req_threshold, true);