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

@ -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);