mirror of
https://github.com/berlin-open-wireless-lab/DAWN.git
synced 2025-02-14 17:51:51 +00:00
treewide: improve logging
Provide multi-priority syslog() based logging to improve user and developer experience. Add dawnlog_* functions and macros to convert printf() family and perror() logging to syslog() family. Removed unnecessary sprintf() for building log strings (embed format directly). Add local config settings for log level. Add command line parameters for log level and destination. Set default log level to suppress a lot of previously noisy messages. Restore some previously removed noisy messages as DEBUG level in case they help in future. Eliminate DAWN_NO_OUTPUT static code checks which are no longer used. Signed-off-by: Ian Clowes <clowes_ian@hotmail.com>
This commit is contained in:
parent
ddc007e32c
commit
4df0c986f1
18 changed files with 922 additions and 396 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <gcrypt.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "memory_utils.h"
|
||||
#include "crypto.h"
|
||||
|
||||
|
@ -14,7 +15,7 @@ gcry_cipher_hd_t gcry_cipher_hd;
|
|||
|
||||
void gcrypt_init() {
|
||||
if (!gcry_check_version(GCRYPT_VERSION)) {
|
||||
fprintf(stderr, "gcrypt: library version mismatch");
|
||||
dawnlog_error("gcrypt: library version mismatch");
|
||||
}
|
||||
gcry_error_t err = 0;
|
||||
err = gcry_control(GCRYCTL_SUSPEND_SECMEM_WARN);
|
||||
|
@ -23,7 +24,7 @@ void gcrypt_init() {
|
|||
err |= gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
|
||||
|
||||
if (err) {
|
||||
fprintf(stderr, "gcrypt: failed initialization");
|
||||
dawnlog_error("gcrypt: failed initialization");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +38,7 @@ void gcrypt_set_key_and_iv(const char *key, const char *iv) {
|
|||
GCRY_C_MODE, // int
|
||||
0);
|
||||
if (gcry_error_handle) {
|
||||
fprintf(stderr, "gcry_cipher_open failed: %s/%s\n",
|
||||
dawnlog_error("gcry_cipher_open failed: %s/%s\n",
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
return;
|
||||
|
@ -45,7 +46,7 @@ void gcrypt_set_key_and_iv(const char *key, const char *iv) {
|
|||
|
||||
gcry_error_handle = gcry_cipher_setkey(gcry_cipher_hd, key, keylen);
|
||||
if (gcry_error_handle) {
|
||||
fprintf(stderr, "gcry_cipher_setkey failed: %s/%s\n",
|
||||
dawnlog_error("gcry_cipher_setkey failed: %s/%s\n",
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
return;
|
||||
|
@ -53,7 +54,7 @@ void gcrypt_set_key_and_iv(const char *key, const char *iv) {
|
|||
|
||||
gcry_error_handle = gcry_cipher_setiv(gcry_cipher_hd, iv, blklen);
|
||||
if (gcry_error_handle) {
|
||||
fprintf(stderr, "gcry_cipher_setiv failed: %s/%s\n",
|
||||
dawnlog_error("gcry_cipher_setiv failed: %s/%s\n",
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
return;
|
||||
|
@ -67,12 +68,12 @@ char *gcrypt_encrypt_msg(char *msg, size_t msg_length, int *out_length) {
|
|||
|
||||
char *out = dawn_malloc(msg_length);
|
||||
if (!out){
|
||||
fprintf(stderr, "gcry_cipher_encrypt error: not enought memory\n");
|
||||
dawnlog_error("gcry_cipher_encrypt error: not enough memory\n");
|
||||
return NULL;
|
||||
}
|
||||
gcry_error_handle = gcry_cipher_encrypt(gcry_cipher_hd, out, msg_length, msg, msg_length);
|
||||
if (gcry_error_handle) {
|
||||
fprintf(stderr, "gcry_cipher_encrypt failed: %s/%s\n",
|
||||
dawnlog_error("gcry_cipher_encrypt failed: %s/%s\n",
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
return NULL;
|
||||
|
@ -88,12 +89,12 @@ char *gcrypt_decrypt_msg(char *msg, size_t msg_length) {
|
|||
|
||||
char *out_buffer = dawn_malloc(msg_length);
|
||||
if (!out_buffer){
|
||||
fprintf(stderr, "gcry_cipher_decrypt error: not enought memory\n");
|
||||
dawnlog_error("gcry_cipher_decrypt error: not enough memory\n");
|
||||
return NULL;
|
||||
}
|
||||
gcry_error_handle = gcry_cipher_decrypt(gcry_cipher_hd, out_buffer, msg_length, msg, msg_length);
|
||||
if (gcry_error_handle) {
|
||||
fprintf(stderr, "gcry_cipher_decrypt failed: %s/%s\n",
|
||||
dawnlog_error("gcry_cipher_decrypt failed: %s/%s\n",
|
||||
gcry_strsource(gcry_error_handle),
|
||||
gcry_strerror(gcry_error_handle));
|
||||
dawn_free(out_buffer);
|
||||
|
@ -102,7 +103,7 @@ char *gcrypt_decrypt_msg(char *msg, size_t msg_length) {
|
|||
char *out = dawn_malloc(strlen(out_buffer) + 1);
|
||||
if (!out){
|
||||
dawn_free(out_buffer);
|
||||
fprintf(stderr, "gcry_cipher_decrypt error: not enought memory\n");
|
||||
dawnlog_error("gcry_cipher_decrypt error: not enough memory\n");
|
||||
return NULL;
|
||||
}
|
||||
strcpy(out, out_buffer);
|
||||
|
|
|
@ -127,6 +127,10 @@ struct time_config_s {
|
|||
time_t update_beacon_reports;
|
||||
};
|
||||
|
||||
struct local_config_s {
|
||||
int loglevel;
|
||||
};
|
||||
|
||||
#define MAX_IP_LENGTH 46
|
||||
#define MAX_KEY_LENGTH 65
|
||||
|
||||
|
@ -145,12 +149,10 @@ struct network_config_s {
|
|||
|
||||
extern struct network_config_s network_config;
|
||||
extern struct time_config_s timeout_config;
|
||||
extern struct local_config_s local_config;
|
||||
extern struct probe_metric_s dawn_metric;
|
||||
|
||||
/*** Core DAWN data structures for tracking network devices and status ***/
|
||||
// Define this to remove printing / reporing of fields, and hence observe
|
||||
// which fields are evaluated in use at compile time.
|
||||
// #define DAWN_NO_OUTPUT
|
||||
|
||||
// TODO notes:
|
||||
// Never used? = No code reference
|
||||
|
@ -174,11 +176,9 @@ typedef struct probe_entry_s {
|
|||
uint8_t vht_capabilities; // eval_probe_metric()
|
||||
time_t time; // remove_old...entries
|
||||
int counter;
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
int deny_counter; // TODO: Never used?
|
||||
uint8_t max_supp_datarate; // TODO: Never used?
|
||||
uint8_t min_supp_datarate; // TODO: Never used?
|
||||
#endif
|
||||
uint32_t rcpi;
|
||||
uint32_t rsni;
|
||||
} probe_entry;
|
||||
|
@ -316,7 +316,7 @@ void remove_old_probe_entries(time_t current_time, long long int threshold);
|
|||
|
||||
void print_probe_array();
|
||||
|
||||
void print_probe_entry(probe_entry *entry);
|
||||
void print_probe_entry(int level, probe_entry *entry);
|
||||
|
||||
int eval_probe_metric(struct probe_entry_s * probe_entry, ap *ap_entry);
|
||||
|
||||
|
@ -326,7 +326,7 @@ auth_entry *insert_to_denied_req_array(auth_entry*entry, int inc_counter, time_t
|
|||
|
||||
void remove_old_denied_req_entries(time_t current_time, long long int threshold, int logmac);
|
||||
|
||||
void print_auth_entry(auth_entry *entry);
|
||||
void print_auth_entry(int level, auth_entry *entry);
|
||||
|
||||
// ---------------- Functions ----------------
|
||||
|
||||
|
@ -350,7 +350,7 @@ client *client_array_delete(client *entry, int unlink_only);
|
|||
|
||||
void print_client_array();
|
||||
|
||||
void print_client_entry(client *entry);
|
||||
void print_client_entry(int level, client *entry);
|
||||
|
||||
int is_connected_somehwere(struct dawn_mac client_addr);
|
||||
|
||||
|
|
|
@ -28,6 +28,12 @@ struct probe_metric_s uci_get_dawn_metric();
|
|||
*/
|
||||
struct time_config_s uci_get_time_config();
|
||||
|
||||
/**
|
||||
* Function that returns a struct with all the local config values.
|
||||
* @return the local config values.
|
||||
*/
|
||||
struct local_config_s uci_get_local_config();
|
||||
|
||||
/**
|
||||
* Function that returns all the network informations.
|
||||
* @return the network config values.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define __DAWN_UTILS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <syslog.h>
|
||||
|
||||
/**
|
||||
* Check if a string is greater than another one.
|
||||
|
@ -11,4 +12,91 @@
|
|||
*/
|
||||
int string_is_greater(char *str, char *str_2);
|
||||
|
||||
|
||||
/*
|
||||
** Log handling for dawn process
|
||||
*/
|
||||
#define DAWNLOG_DEST_SYSLOG 0 // Send log output to syslog...
|
||||
#define DAWNLOG_DEST_STDIO 1 // ... or stdout / stderr as appropriate
|
||||
|
||||
#define DAWNLOG_PERROR 0x08 // Bit flag to signal inclusion of errno from system calls
|
||||
|
||||
#define DAWNLOG_PRIMASK 0x07 // Bitmask to obtain only priority value
|
||||
|
||||
#define DAWNLOG_ERROR 5 // Serious malfunction / unexpected behaviour - eg: OS resource exhaustion
|
||||
#define DAWNLOG_WARNING 4 // Something appears wrong, but recoverable - eg: data structures inconsistent
|
||||
#define DAWNLOG_ALWAYS 3 // Standard behaviour always worth reporting - should be very low frequency messages
|
||||
#define DAWNLOG_INFO 2 // Reporting on standard behaviour - should be comprehensible to user
|
||||
#define DAWNLOG_TRACE 1 // More info to help trace where algorithms may be going wrong
|
||||
#define DAWNLOG_DEBUG 0 // Deeper tracing to fix bugs
|
||||
|
||||
#define DAWNLOG_COMPILE_MIN DAWNLOG_DEBUG // Messages lower than this priority are not compiled
|
||||
#define DAWNLOG_COMPILING(level) (level >= DAWNLOG_COMPILE_MIN)
|
||||
|
||||
#define dawnlog_perror(s, ...) dawnlog(DAWNLOG_ERROR|DAWNLOG_PERROR, "%s()=%s@%d %s - " s, __func__, dawnlog_basename(__FILE__), __LINE__, dawnlog_pbuf, ##__VA_ARGS__)
|
||||
#define dawnlog_error(fmt, ...) dawnlog(DAWNLOG_ERROR, "%s()=%s@%d " fmt, __func__, dawnlog_basename(__FILE__), __LINE__, ##__VA_ARGS__)
|
||||
|
||||
#define dawnlog_warning(fmt, ...) dawnlog(DAWNLOG_WARNING, fmt, ##__VA_ARGS__)
|
||||
|
||||
#define dawnlog_always(fmt, ...) dawnlog(DAWNLOG_ALWAYS, fmt, ##__VA_ARGS__)
|
||||
|
||||
#if DAWNLOG_COMPILING(DAWNLOG_INFO)
|
||||
#define dawnlog_info(fmt, ...) dawnlog(DAWNLOG_INFO, fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define dawnlog_info(fmt, ...)
|
||||
#endif
|
||||
|
||||
// Use the ..._func variants to get source code position added automatically: function, filename, line
|
||||
#if DAWNLOG_COMPILING(DAWNLOG_TRACE)
|
||||
#define dawnlog_trace(fmt, ...) dawnlog(DAWNLOG_TRACE, fmt, ##__VA_ARGS__)
|
||||
#define dawnlog_trace_func(fmt, ...) dawnlog(DAWNLOG_TRACE, "%s()=%s@%d " fmt, __func__, dawnlog_basename(__FILE__), __LINE__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define dawnlog_trace(fmt, ...)
|
||||
#define dawnlog_trace_func(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if DAWNLOG_COMPILING(DAWNLOG_DEBUG)
|
||||
#define dawnlog_debug(fmt, ...) dawnlog(DAWNLOG_DEBUG, fmt, ##__VA_ARGS__)
|
||||
#define dawnlog_debug_func(fmt, ...) dawnlog(DAWNLOG_DEBUG, "%s()=%s@%d " fmt, __func__, dawnlog_basename(__FILE__), __LINE__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define dawnlog_debug(fmt, ...)
|
||||
#define dawnlog_debug_func(fmt, ...)
|
||||
#endif
|
||||
|
||||
extern char dawnlog_pbuf[]; // Buffer for errno conversion for dawnlog_perror()
|
||||
|
||||
/**
|
||||
* Set the output target for dawnlog()
|
||||
* @param logdest: DAWNLOG_DEST_*
|
||||
*/
|
||||
void dawnlog_dest(int logdest);
|
||||
|
||||
/**
|
||||
* Minimum priority level to be logged
|
||||
* @param level: A priority level
|
||||
*/
|
||||
void dawnlog_minlevel(int level);
|
||||
|
||||
/**
|
||||
* Check whether a priority level would be actually logged to allow callers
|
||||
* to skip "expensive" preparation such as string manipulation or loops
|
||||
* @param level
|
||||
* @return TRUE if the priority level would be logged
|
||||
*/
|
||||
int dawnlog_showing(int level);
|
||||
|
||||
/**
|
||||
* Log a message.
|
||||
* @param level
|
||||
* @param fmt
|
||||
* @return
|
||||
*/
|
||||
void dawnlog(int level, const char* fmt, ...);
|
||||
|
||||
/**
|
||||
* Return pointer to filename part of full path.
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
const char* dawnlog_basename(const char* file);
|
||||
#endif
|
47
src/main.c
47
src/main.c
|
@ -3,6 +3,7 @@
|
|||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "memory_utils.h"
|
||||
#include "datastorage.h"
|
||||
|
@ -47,11 +48,50 @@ void signal_handler(int sig) {
|
|||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
const char *ubus_socket = NULL;
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
/* Load local config now so command line can override it */
|
||||
uci_init();
|
||||
local_config = uci_get_local_config();
|
||||
|
||||
int logdest = DAWNLOG_DEST_SYSLOG;
|
||||
|
||||
int opt = getopt(argc, argv, "l:o:");
|
||||
|
||||
while (opt != -1) {
|
||||
switch (opt) {
|
||||
case 'l':
|
||||
if (!strcmp(optarg, "info"))
|
||||
dawnlog_minlevel(DAWNLOG_INFO);
|
||||
else if (!strcmp(optarg, "trace"))
|
||||
dawnlog_minlevel(DAWNLOG_TRACE);
|
||||
else if (!strcmp(optarg, "debug"))
|
||||
dawnlog_minlevel(DAWNLOG_DEBUG);
|
||||
else
|
||||
dawnlog_warning("Unrecognised option for -l: %s\n", optarg);
|
||||
break;
|
||||
case 'o':
|
||||
if (!strcmp(optarg, "stdio"))
|
||||
logdest = DAWNLOG_DEST_STDIO;
|
||||
else if (!strcmp(optarg, "syslog"))
|
||||
logdest = DAWNLOG_DEST_SYSLOG;
|
||||
else
|
||||
dawnlog_warning("Unrecognised option for -o: %s\n", optarg);
|
||||
break;
|
||||
default: /* '?' */
|
||||
dawnlog_warning("Unrecognised option (%s), aborting read of them\n", argv[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
opt = getopt(argc, argv, "l:o:");
|
||||
}
|
||||
|
||||
if (logdest == DAWNLOG_DEST_SYSLOG)
|
||||
openlog("dawn", LOG_PID, LOG_DAEMON);
|
||||
|
||||
dawnlog_dest(logdest);
|
||||
|
||||
dawnlog_info("DAWN instance built around %s on %s starting...", __TIME__, __DATE__);
|
||||
|
||||
// connect signals
|
||||
signal_action.sa_handler = signal_handler;
|
||||
|
@ -61,7 +101,6 @@ int main(int argc, char **argv) {
|
|||
sigaction(SIGTERM, &signal_action, NULL);
|
||||
sigaction(SIGINT, &signal_action, NULL);
|
||||
|
||||
uci_init();
|
||||
// TODO: Why the extra loacl struct to retuen into?
|
||||
struct network_config_s net_config = uci_get_dawn_network();
|
||||
network_config = net_config;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "broadcastsocket.h"
|
||||
|
||||
int setup_broadcast_socket(const char *_broadcast_ip, unsigned short _broadcast_port, struct sockaddr_in *addr) {
|
||||
|
@ -10,7 +11,7 @@ int setup_broadcast_socket(const char *_broadcast_ip, unsigned short _broadcast_
|
|||
|
||||
// Create socket
|
||||
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||
fprintf(stderr, "Failed to create socket.\n");
|
||||
dawnlog_error("Failed to create socket.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -18,7 +19,7 @@ int setup_broadcast_socket(const char *_broadcast_ip, unsigned short _broadcast_
|
|||
broadcast_permission = 1;
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (void *) &broadcast_permission,
|
||||
sizeof(broadcast_permission)) < 0) {
|
||||
fprintf(stderr, "Failed to create socket.\n");
|
||||
dawnlog_error("Failed to create socket.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -30,7 +31,7 @@ int setup_broadcast_socket(const char *_broadcast_ip, unsigned short _broadcast_
|
|||
|
||||
// Bind socket
|
||||
while (bind(sock, (struct sockaddr *) addr, sizeof(*addr)) < 0) {
|
||||
fprintf(stderr, "Binding socket failed!\n");
|
||||
dawnlog_error("Binding socket failed!\n");
|
||||
sleep(1);
|
||||
}
|
||||
return sock;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "multicastsocket.h"
|
||||
|
||||
// based on: http://openbook.rheinwerk-verlag.de/linux_unix_programmierung/Kap11-018.htm
|
||||
|
@ -18,7 +19,7 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_
|
|||
addr->sin_port = htons (_multicast_port);
|
||||
|
||||
if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||
perror("socket()");
|
||||
dawnlog_perror("socket()");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -28,13 +29,13 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_
|
|||
SOL_SOCKET,
|
||||
SO_REUSEADDR,
|
||||
&loop, sizeof(loop)) < 0) {
|
||||
perror("setsockopt:SO_REUSEADDR");
|
||||
dawnlog_perror("setsockopt:SO_REUSEADDR");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (bind(sock,
|
||||
(struct sockaddr *) addr,
|
||||
sizeof(*addr)) < 0) {
|
||||
perror("bind");
|
||||
dawnlog_perror("bind");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -44,7 +45,7 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_
|
|||
IPPROTO_IP,
|
||||
IP_MULTICAST_LOOP,
|
||||
&loop, sizeof(loop)) < 0) {
|
||||
perror("setsockopt:IP_MULTICAST_LOOP");
|
||||
dawnlog_perror("setsockopt:IP_MULTICAST_LOOP");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -52,14 +53,14 @@ int setup_multicast_socket(const char *_multicast_ip, unsigned short _multicast_
|
|||
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("Wrong multicast address!\n");
|
||||
dawnlog_perror("Wrong multicast address!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (setsockopt(sock,
|
||||
IPPROTO_IP,
|
||||
IP_ADD_MEMBERSHIP,
|
||||
&command, sizeof(command)) < 0) {
|
||||
perror("setsockopt:IP_ADD_MEMBERSHIP");
|
||||
dawnlog_perror("setsockopt:IP_ADD_MEMBERSHIP");
|
||||
}
|
||||
return sock;
|
||||
}
|
||||
|
@ -69,7 +70,7 @@ int remove_multicast_socket(int socket) {
|
|||
IPPROTO_IP,
|
||||
IP_DROP_MEMBERSHIP,
|
||||
&command, sizeof(command)) < 0) {
|
||||
perror("setsockopt:IP_DROP_MEMBERSHIP");
|
||||
dawnlog_perror("setsockopt:IP_DROP_MEMBERSHIP");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <string.h>
|
||||
#include <libubox/blobmsg_json.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "memory_utils.h"
|
||||
#include "multicastsocket.h"
|
||||
#include "broadcastsocket.h"
|
||||
|
@ -37,9 +38,7 @@ 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
|
||||
dawnlog_info("Settingup multicastsocket!\n");
|
||||
sock = setup_multicast_socket(ip, port, &addr);
|
||||
} else {
|
||||
sock = setup_broadcast_socket(ip, port, &addr);
|
||||
|
@ -48,19 +47,17 @@ int init_socket_runopts(const char *_ip, int _port, int _multicast_socket) {
|
|||
pthread_t sniffer_thread;
|
||||
if (network_config.use_symm_enc) {
|
||||
if (pthread_create(&sniffer_thread, NULL, receive_msg_enc, NULL)) {
|
||||
fprintf(stderr, "Could not create receiving thread!\n");
|
||||
dawnlog_error("Could not create receiving thread!\n");
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (pthread_create(&sniffer_thread, NULL, receive_msg, NULL)) {
|
||||
fprintf(stderr, "Could not create receiving thread!\n");
|
||||
dawnlog_error("Could not create receiving thread!\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
fprintf(stdout, "Connected to %s:%d\n", ip, port);
|
||||
#endif
|
||||
dawnlog_info("Connected to %s:%d\n", ip, port);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -69,7 +66,7 @@ void *receive_msg(void *args) {
|
|||
while (1) {
|
||||
if ((recv_string_len =
|
||||
recvfrom(sock, recv_string, MAX_RECV_STRING, 0, NULL, 0)) < 0) {
|
||||
fprintf(stderr, "Could not receive message!");
|
||||
dawnlog_error("Could not receive message!");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -83,9 +80,7 @@ void *receive_msg(void *args) {
|
|||
}
|
||||
recv_string[recv_string_len] = '\0';
|
||||
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
printf("Received network message: %s\n", recv_string);
|
||||
#endif
|
||||
dawnlog_debug("Received network message: %s\n", recv_string);
|
||||
handle_network_msg(recv_string);
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +89,7 @@ void *receive_msg_enc(void *args) {
|
|||
while (1) {
|
||||
if ((recv_string_len =
|
||||
recvfrom(sock, recv_string, MAX_RECV_STRING, 0, NULL, 0)) < 0) {
|
||||
fprintf(stderr, "Could not receive message!\n");
|
||||
dawnlog_error("Could not receive message!\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -110,20 +105,18 @@ void *receive_msg_enc(void *args) {
|
|||
|
||||
char *base64_dec_str = dawn_malloc(B64_DECODE_LEN(strlen(recv_string)));
|
||||
if (!base64_dec_str){
|
||||
fprintf(stderr, "Received network error: not enough memory\n");
|
||||
dawnlog_error("Received network error: not enough memory\n");
|
||||
return 0;
|
||||
}
|
||||
int base64_dec_length = b64_decode(recv_string, base64_dec_str, B64_DECODE_LEN(strlen(recv_string)));
|
||||
char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length);
|
||||
if (!dec){
|
||||
dawn_free(base64_dec_str);
|
||||
fprintf(stderr, "Received network error: not enough memory\n");
|
||||
dawnlog_error("Received network error: not enough memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
printf("Received network message: %s\n", dec);
|
||||
#endif
|
||||
dawnlog_debug("Received network message: %s\n", dec);
|
||||
dawn_free(base64_dec_str);
|
||||
handle_network_msg(dec);
|
||||
dawn_free(dec);
|
||||
|
@ -140,7 +133,7 @@ int send_string(char *msg) {
|
|||
0,
|
||||
(struct sockaddr *) &addr,
|
||||
sizeof(addr)) < 0) {
|
||||
perror("sendto()");
|
||||
dawnlog_perror("sendto()");
|
||||
pthread_mutex_unlock(&send_mutex);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -156,7 +149,7 @@ int send_string_enc(char *msg) {
|
|||
size_t msglen = strlen(msg);
|
||||
char *enc = gcrypt_encrypt_msg(msg, msglen + 1, &length_enc);
|
||||
if (!enc){
|
||||
fprintf(stderr, "sendto() error: not enough memory\n");
|
||||
dawnlog_error("sendto() error: not enough memory\n");
|
||||
pthread_mutex_unlock(&send_mutex);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -164,7 +157,7 @@ int send_string_enc(char *msg) {
|
|||
char *base64_enc_str = dawn_malloc(B64_ENCODE_LEN(length_enc));
|
||||
if (!base64_enc_str){
|
||||
dawn_free(enc);
|
||||
fprintf(stderr, "sendto() error: not enough memory\n");
|
||||
dawnlog_error("sendto() error: not enough memory\n");
|
||||
pthread_mutex_unlock(&send_mutex);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -176,7 +169,7 @@ int send_string_enc(char *msg) {
|
|||
0,
|
||||
(struct sockaddr *) &addr,
|
||||
sizeof(addr)) < 0) {
|
||||
perror("sendto()");
|
||||
dawnlog_perror("sendto()");
|
||||
pthread_mutex_unlock(&send_mutex);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
@ -40,9 +40,11 @@ struct client {
|
|||
|
||||
|
||||
static void client_close(struct ustream *s) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct client *cl = container_of(s, struct client, s.stream);
|
||||
|
||||
fprintf(stderr, "Connection closed\n");
|
||||
dawnlog_warning("Connection closed\n");
|
||||
ustream_free(s);
|
||||
close(cl->s.fd.fd);
|
||||
dawn_free(cl);
|
||||
|
@ -59,7 +61,7 @@ static void client_notify_state(struct ustream *s) {
|
|||
if (!s->eof)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "eof!, pending: %d, total: %d\n", s->w.data_bytes, cl->ctr);
|
||||
dawnlog_error("eof!, pending: %d, total: %d\n", s->w.data_bytes, cl->ctr);
|
||||
|
||||
if (!s->w.data_bytes)
|
||||
return client_close(s);
|
||||
|
@ -70,7 +72,9 @@ static void client_to_server_close(struct ustream *s) {
|
|||
struct network_con_s *con = container_of(s,
|
||||
struct network_con_s, stream.stream);
|
||||
|
||||
fprintf(stderr, "Connection to server closed\n");
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
dawnlog_warning("Connection to server closed\n");
|
||||
ustream_free(s);
|
||||
close(con->fd.fd);
|
||||
list_del(&con->list);
|
||||
|
@ -81,10 +85,12 @@ static void client_to_server_state(struct ustream *s) {
|
|||
struct client *cl = container_of(s,
|
||||
struct client, s.stream);
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (!s->eof)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "eof!, pending: %d, total: %d\n", s->w.data_bytes, cl->ctr);
|
||||
dawnlog_error("eof!, pending: %d, total: %d\n", s->w.data_bytes, cl->ctr);
|
||||
|
||||
if (!s->w.data_bytes)
|
||||
return client_to_server_close(s);
|
||||
|
@ -94,18 +100,22 @@ static void client_to_server_state(struct ustream *s) {
|
|||
static void client_read_cb(struct ustream *s, int bytes) {
|
||||
struct client *cl = container_of(s, struct client, s.stream);
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
while(1) {
|
||||
if (cl->state == READ_STATUS_READY)
|
||||
{
|
||||
dawnlog_debug("tcp_socket: commencing message...\n");
|
||||
cl->str = dawn_malloc(HEADER_SIZE);
|
||||
if (!cl->str) {
|
||||
fprintf(stderr,"not enough memory (" STR_QUOTE(__LINE__) ")\n");
|
||||
dawnlog_error("not enough memory (" STR_QUOTE(__LINE__) ")\n");
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t avail_len = ustream_pending_data(s, false);
|
||||
|
||||
if (avail_len < HEADER_SIZE){//ensure recv sizeof(uint32_t)
|
||||
dawnlog_debug("not complete msg, len:%d\n", avail_len);
|
||||
dawn_free(cl->str);
|
||||
cl->str = NULL;
|
||||
break;
|
||||
|
@ -113,7 +123,7 @@ static void client_read_cb(struct ustream *s, int bytes) {
|
|||
|
||||
if (ustream_read(s, cl->str, HEADER_SIZE) != HEADER_SIZE) // read msg length bytes
|
||||
{
|
||||
fprintf(stdout,"msg length read failed\n");
|
||||
dawnlog_error("msg length read failed\n");
|
||||
dawn_free(cl->str);
|
||||
cl->str = NULL;
|
||||
break;
|
||||
|
@ -126,7 +136,7 @@ static void client_read_cb(struct ustream *s, int bytes) {
|
|||
// remains valid and may need to be deallocated.
|
||||
char *str_tmp = dawn_realloc(cl->str, cl->final_len);
|
||||
if (!str_tmp) {
|
||||
fprintf(stderr,"not enough memory (%" PRIu32 " @ " STR_QUOTE(__LINE__) ")\n", cl->final_len);
|
||||
dawnlog_error("not enough memory (%" PRIu32 " @ " STR_QUOTE(__LINE__) ")\n", cl->final_len);
|
||||
dawn_free(cl->str);
|
||||
cl->str = NULL;
|
||||
break;
|
||||
|
@ -139,6 +149,7 @@ static void client_read_cb(struct ustream *s, int bytes) {
|
|||
|
||||
if (cl->state == READ_STATUS_COMMENCED)
|
||||
{
|
||||
dawnlog_debug("tcp_socket: reading message...\n");
|
||||
uint32_t read_len = ustream_pending_data(s, false);
|
||||
|
||||
if (read_len == 0)
|
||||
|
@ -147,23 +158,26 @@ 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;
|
||||
|
||||
dawnlog_debug("tcp_socket: reading %" PRIu32 " bytes to add to %" PRIu32 " of %" PRIu32 "...\n",
|
||||
read_len, cl->curr_len, cl->final_len);
|
||||
|
||||
uint32_t this_read = ustream_read(s, cl->str + cl->curr_len, read_len);
|
||||
cl->curr_len += this_read;
|
||||
dawnlog_debug("tcp_socket: ...and we're back, now have %" PRIu32 " bytes\n", cl->curr_len);
|
||||
if (cl->curr_len == cl->final_len){//ensure recv final_len bytes.
|
||||
// Full message now received
|
||||
cl->state = READ_STATUS_COMPLETE;
|
||||
dawnlog_debug("tcp_socket: message completed\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (cl->state == READ_STATUS_COMPLETE)
|
||||
{
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
printf("tcp_socket: processing message...\n");
|
||||
#endif
|
||||
dawnlog_debug("tcp_socket: processing message...\n");
|
||||
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) {
|
||||
fprintf(stderr,"not enough memory (" STR_QUOTE(__LINE__) ")\n");
|
||||
dawnlog_error("not enough memory (" STR_QUOTE(__LINE__) ")\n");
|
||||
dawn_free(cl->str);
|
||||
cl->str = NULL;
|
||||
break;
|
||||
|
@ -182,6 +196,7 @@ static void client_read_cb(struct ustream *s, int bytes) {
|
|||
}
|
||||
}
|
||||
|
||||
dawnlog_debug("tcp_socket: leaving\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -190,6 +205,8 @@ static void server_cb(struct uloop_fd *fd, unsigned int events) {
|
|||
unsigned int sl = sizeof(struct sockaddr_in);
|
||||
int sfd;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (!next_client)
|
||||
next_client = dawn_calloc(1, sizeof(*next_client));
|
||||
|
||||
|
@ -197,7 +214,7 @@ static void server_cb(struct uloop_fd *fd, unsigned int events) {
|
|||
|
||||
sfd = accept(server.fd, (struct sockaddr *) &cl->sin, &sl);
|
||||
if (sfd < 0) {
|
||||
fprintf(stderr, "Accept failed\n");
|
||||
dawnlog_error("Accept failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -207,17 +224,18 @@ static void server_cb(struct uloop_fd *fd, unsigned int events) {
|
|||
cl->s.stream.notify_write = client_notify_write;
|
||||
ustream_fd_init(&cl->s, sfd);
|
||||
next_client = NULL; // TODO: Why is this here? To avoid resetting if above return happens?
|
||||
fprintf(stderr, "New connection\n");
|
||||
dawnlog_info("New connection\n");
|
||||
}
|
||||
|
||||
int run_server(int port) {
|
||||
dawnlog_debug("Adding socket!\n");
|
||||
char port_str[12];
|
||||
sprintf(port_str, "%d", port);
|
||||
sprintf(port_str, "%d", port); // TODO: Manage buffer length
|
||||
|
||||
server.cb = server_cb;
|
||||
server.fd = usock(USOCK_TCP | USOCK_SERVER | USOCK_IPV4ONLY | USOCK_NUMERIC, INADDR_ANY, port_str);
|
||||
if (server.fd < 0) {
|
||||
perror("usock");
|
||||
dawnlog_perror("usock");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -230,22 +248,28 @@ static void client_not_be_used_read_cb(struct ustream *s, int bytes) {
|
|||
int len;
|
||||
char buf[2048];
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
len = ustream_read(s, buf, sizeof(buf));
|
||||
buf[len] = '\0';
|
||||
dawnlog_debug("Read %d bytes from SSL connection: %s\n", len, buf);
|
||||
}
|
||||
|
||||
static void connect_cb(struct uloop_fd *f, unsigned int events) {
|
||||
|
||||
struct network_con_s *entry = container_of(f, struct network_con_s, fd);
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (f->eof || f->error) {
|
||||
fprintf(stderr, "Connection failed (%s)\n", f->eof ? "EOF" : "ERROR");
|
||||
dawnlog_error("Connection failed (%s)\n", f->eof ? "EOF" : "ERROR");
|
||||
close(entry->fd.fd);
|
||||
list_del(&entry->list);
|
||||
dawn_free(entry);
|
||||
return;
|
||||
}
|
||||
|
||||
dawnlog_debug("Connection established\n");
|
||||
uloop_fd_delete(&entry->fd);
|
||||
|
||||
entry->stream.stream.notify_read = client_not_be_used_read_cb;
|
||||
|
@ -258,8 +282,10 @@ static void connect_cb(struct uloop_fd *f, unsigned int events) {
|
|||
int add_tcp_conncection(char *ipv4, int port) {
|
||||
struct sockaddr_in serv_addr;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
char port_str[12];
|
||||
sprintf(port_str, "%d", port);
|
||||
sprintf(port_str, "%d", port); // TODO: Manage buffer length
|
||||
|
||||
memset(&serv_addr, 0, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
|
@ -290,20 +316,25 @@ 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);
|
||||
|
||||
dawnlog_debug("New TCP connection to %s:%d\n", ipv4, port);
|
||||
list_add(&tcp_entry->list, &tcp_sock_list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void send_tcp(char *msg) {
|
||||
print_tcp_array();
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (dawnlog_showing(DAWNLOG_DEBUG))
|
||||
print_tcp_array();
|
||||
|
||||
struct network_con_s *con, *tmp;
|
||||
if (network_config.use_symm_enc) {
|
||||
int length_enc;
|
||||
size_t msglen = strlen(msg)+1;
|
||||
char *enc = gcrypt_encrypt_msg(msg, msglen, &length_enc);
|
||||
if (!enc){
|
||||
fprintf(stderr, "Ustream error: not enought memory (" STR_QUOTE(__LINE__) ")\n");
|
||||
dawnlog_error("Ustream error: not enough memory (" STR_QUOTE(__LINE__) ")\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -311,7 +342,7 @@ void send_tcp(char *msg) {
|
|||
char *final_str = dawn_malloc(final_len);
|
||||
if (!final_str){
|
||||
dawn_free(enc);
|
||||
fprintf(stderr, "Ustream error: not enought memory (" STR_QUOTE(__LINE__) ")\n");
|
||||
dawnlog_error("Ustream error: not enough memory (" STR_QUOTE(__LINE__) ")\n");
|
||||
return;
|
||||
}
|
||||
uint32_t *msg_header = (uint32_t *)final_str;
|
||||
|
@ -321,8 +352,9 @@ void send_tcp(char *msg) {
|
|||
{
|
||||
if (con->connected) {
|
||||
int len_ustream = ustream_write(&con->stream.stream, final_str, final_len, 0);
|
||||
dawnlog_debug("Ustream send: %d\n", len_ustream);
|
||||
if (len_ustream <= 0) {
|
||||
fprintf(stderr,"Ustream error(" STR_QUOTE(__LINE__) ")!\n");
|
||||
dawnlog_error("Ustream error(" STR_QUOTE(__LINE__) ")!\n");
|
||||
//ERROR HANDLING!
|
||||
if (con->stream.stream.write_error) {
|
||||
ustream_free(&con->stream.stream);
|
||||
|
@ -342,7 +374,7 @@ void send_tcp(char *msg) {
|
|||
uint32_t final_len = msglen + sizeof(final_len);
|
||||
char *final_str = dawn_malloc(final_len);
|
||||
if (!final_str){
|
||||
fprintf(stderr, "Ustream error: not enought memory (" STR_QUOTE(__LINE__) ")\n");
|
||||
dawnlog_error("Ustream error: not enough memory (" STR_QUOTE(__LINE__) ")\n");
|
||||
return;
|
||||
}
|
||||
uint32_t *msg_header = (uint32_t *)final_str;
|
||||
|
@ -353,9 +385,10 @@ void send_tcp(char *msg) {
|
|||
{
|
||||
if (con->connected) {
|
||||
int len_ustream = ustream_write(&con->stream.stream, final_str, final_len, 0);
|
||||
dawnlog_debug("Ustream send: %d\n", len_ustream);
|
||||
if (len_ustream <= 0) {
|
||||
//ERROR HANDLING!
|
||||
fprintf(stderr,"Ustream error(" STR_QUOTE(__LINE__) ")!\n");
|
||||
dawnlog_error("Ustream error(" STR_QUOTE(__LINE__) ")!\n");
|
||||
if (con->stream.stream.write_error) {
|
||||
ustream_free(&con->stream.stream);
|
||||
close(con->fd.fd);
|
||||
|
@ -372,6 +405,8 @@ void send_tcp(char *msg) {
|
|||
struct network_con_s* tcp_list_contains_address(struct sockaddr_in entry) {
|
||||
struct network_con_s *con;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
list_for_each_entry(con, &tcp_sock_list, list)
|
||||
{
|
||||
if(entry.sin_addr.s_addr == con->sock_addr.sin_addr.s_addr)
|
||||
|
@ -383,14 +418,11 @@ 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");
|
||||
dawnlog_debug("--------Connections------\n");
|
||||
list_for_each_entry(con, &tcp_sock_list, list)
|
||||
{
|
||||
printf("Connecting to Port: %d, Connected: %s\n", ntohs(con->sock_addr.sin_port), con->connected ? "True" : "False");
|
||||
dawnlog_debug("Connecting to Port: %d, Connected: %s\n", ntohs(con->sock_addr.sin_port), con->connected ? "True" : "False");
|
||||
}
|
||||
printf("------------------\n");
|
||||
#endif
|
||||
dawnlog_debug("------------------\n");
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -493,7 +493,8 @@ static int consume_actions(int argc, char* argv[], int harness_verbosity)
|
|||
{
|
||||
args_required = 1;
|
||||
|
||||
print_probe_array();
|
||||
if (dawnlog_showing(DAWNLOG_INFO))
|
||||
print_probe_array();
|
||||
}
|
||||
else if (strcmp(*argv, "client_show") == 0)
|
||||
{
|
||||
|
@ -505,11 +506,11 @@ static int consume_actions(int argc, char* argv[], int harness_verbosity)
|
|||
{
|
||||
args_required = 1;
|
||||
|
||||
printf("--------APs------\n");
|
||||
dawnlog_info("--------APs------\n");
|
||||
for (auth_entry *i = denied_req_set; i != NULL; i = i->next_auth) {
|
||||
print_auth_entry(i);
|
||||
print_auth_entry(DAWNLOG_INFO, i);
|
||||
}
|
||||
printf("------------------\n");
|
||||
dawnlog_info("------------------\n");
|
||||
}
|
||||
else if (strcmp(*argv, "ap_add_auto") == 0)
|
||||
{
|
||||
|
@ -893,11 +894,9 @@ static int consume_actions(int argc, char* argv[], int harness_verbosity)
|
|||
else if (!strncmp(fn, "vht_cap=", 8)) load_u8(&pr0->vht_capabilities, fn + 8);
|
||||
else if (!strncmp(fn, "time=", 5)) load_time(&pr0->time, fn + 5);
|
||||
else if (!strncmp(fn, "counter=", 8)) load_int(&pr0->counter, fn + 8);
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
else if (!strncmp(fn, "deny=", 5)) load_int(&pr0->deny_counter, fn + 5);
|
||||
else if (!strncmp(fn, "max_rate=", 9)) load_u8(&pr0->max_supp_datarate, fn + 9);
|
||||
else if (!strncmp(fn, "min_rate=", 9)) load_u8(&pr0->min_supp_datarate, fn + 9);
|
||||
#endif
|
||||
else if (!strncmp(fn, "rcpi=", 5)) load_u32(&pr0->rcpi, fn + 5);
|
||||
else if (!strncmp(fn, "rsni=", 5)) load_u32(&pr0->rsni, fn + 5);
|
||||
else {
|
||||
|
@ -936,11 +935,9 @@ static int consume_actions(int argc, char* argv[], int harness_verbosity)
|
|||
pr0->vht_capabilities = 0;
|
||||
pr0->time = faketime;
|
||||
pr0->counter = 0;
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
pr0->deny_counter = 0;
|
||||
pr0->max_supp_datarate = 0;
|
||||
pr0->min_supp_datarate = 0;
|
||||
#endif
|
||||
pr0->rcpi = 0;
|
||||
pr0->rsni = 0;
|
||||
|
||||
|
@ -1072,6 +1069,9 @@ static int consume_actions(int argc, char* argv[], int harness_verbosity)
|
|||
ap* ap_entry = ap_array_get_ap(pr0->bssid_addr, NULL);
|
||||
|
||||
int this_metric = eval_probe_metric(pr0, ap_entry);
|
||||
dawnlog_info("Score: %d of:\n", this_metric);
|
||||
print_probe_entry(DAWNLOG_DEBUG, pr0);
|
||||
|
||||
printf("eval_probe_metric: Returned %d\n", this_metric);
|
||||
}
|
||||
|
||||
|
@ -1184,6 +1184,8 @@ int main(int argc, char* argv[])
|
|||
int ret = 0;
|
||||
int harness_verbosity = 1;
|
||||
|
||||
dawnlog_dest(DAWNLOG_DEST_STDIO); // Send messages to stderr / stdout
|
||||
|
||||
printf("DAWN datastorage.c test harness...\n\n");
|
||||
|
||||
if ((argc == 1) || !strcmp(*(argv + 1), "help") || !strcmp(*(argv + 1), "--help") || !strcmp(*(argv + 1), "-h"))
|
||||
|
|
|
@ -33,7 +33,7 @@ int compare_essid_iwinfo(struct dawn_mac bssid_addr, struct dawn_mac bssid_addr_
|
|||
struct dirent *entry;
|
||||
dirp = opendir(hostapd_dir_glob); // error handling?
|
||||
if (!dirp) {
|
||||
fprintf(stderr, "[COMPARE ESSID] Failed to open %s\n", hostapd_dir_glob);
|
||||
dawnlog_error("[COMPARE ESSID] Failed to open %s\n", hostapd_dir_glob);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,8 @@ int compare_essid_iwinfo(struct dawn_mac bssid_addr, struct dawn_mac bssid_addr_
|
|||
}
|
||||
closedir(dirp);
|
||||
|
||||
dawnlog_debug("Comparing: %s with %s\n", essid, essid_to_compare);
|
||||
|
||||
if (essid == NULL || essid_to_compare == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -89,9 +91,13 @@ int get_bandwidth_iwinfo(struct dawn_mac client_addr, float *rx_rate, float *tx_
|
|||
struct dirent *entry;
|
||||
dirp = opendir(hostapd_dir_glob); // error handling?
|
||||
if (!dirp) {
|
||||
fprintf(stderr, "[BANDWIDTH INFO] Failed to open %s\n", hostapd_dir_glob);
|
||||
dawnlog_error("[BANDWIDTH INFO] Failed to open %s\n", hostapd_dir_glob);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dawnlog_debug("[BANDWIDTH INFO] Opened %s\n", hostapd_dir_glob);
|
||||
}
|
||||
|
||||
int sucess = 0;
|
||||
|
||||
|
@ -145,7 +151,7 @@ int get_rssi_iwinfo(struct dawn_mac client_addr) {
|
|||
struct dirent *entry;
|
||||
dirp = opendir(hostapd_dir_glob); // error handling?
|
||||
if (!dirp) {
|
||||
fprintf(stderr, "[RSSI INFO] No hostapd sockets!\n");
|
||||
dawnlog_error("[RSSI INFO] No hostapd sockets!\n");
|
||||
return INT_MIN;
|
||||
}
|
||||
|
||||
|
@ -173,15 +179,11 @@ 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
|
||||
dawnlog_warning("No information available\n");
|
||||
iwinfo_finish();
|
||||
return INT_MIN;
|
||||
} else if (len <= 0) {
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
fprintf(stdout, "No station connected\n");
|
||||
#endif
|
||||
dawnlog_warning("No station connected\n");
|
||||
iwinfo_finish();
|
||||
return INT_MIN;
|
||||
}
|
||||
|
@ -205,7 +207,7 @@ int get_expected_throughput_iwinfo(struct dawn_mac client_addr) {
|
|||
struct dirent *entry;
|
||||
dirp = opendir(hostapd_dir_glob); // error handling?
|
||||
if (!dirp) {
|
||||
fprintf(stderr, "[RSSI INFO] Failed to open dir:%s\n", hostapd_dir_glob);
|
||||
dawnlog_error("[RSSI INFO] Failed to open dir:%s\n", hostapd_dir_glob);
|
||||
return INT_MIN;
|
||||
}
|
||||
|
||||
|
@ -233,15 +235,11 @@ 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
|
||||
dawnlog_warning("No information available\n");
|
||||
iwinfo_finish();
|
||||
return INT_MIN;
|
||||
} else if (len <= 0) {
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
fprintf(stdout, "No station connected\n");
|
||||
#endif
|
||||
dawnlog_warning("No station connected\n");
|
||||
iwinfo_finish();
|
||||
return INT_MIN;
|
||||
}
|
||||
|
@ -310,13 +308,13 @@ int get_channel_utilization(const char *ifname, uint64_t *last_channel_time, uin
|
|||
|
||||
if (iw->survey(ifname, buf, &len))
|
||||
{
|
||||
fprintf(stderr, "Survey not possible!\n\n");
|
||||
dawnlog_warning("Survey not possible!\n");
|
||||
iwinfo_finish();
|
||||
return 0;
|
||||
}
|
||||
else if (len <= 0)
|
||||
{
|
||||
fprintf(stderr, "No survey results\n\n");
|
||||
dawnlog_warning("No survey results\n");
|
||||
iwinfo_finish();
|
||||
return 0;
|
||||
}
|
||||
|
@ -352,6 +350,7 @@ int support_ht(const char *ifname) {
|
|||
|
||||
if (iw->htmodelist(ifname, &htmodes))
|
||||
{
|
||||
dawnlog_debug("No HT mode information available\n");
|
||||
iwinfo_finish();
|
||||
return 0;
|
||||
}
|
||||
|
@ -371,6 +370,7 @@ int support_vht(const char *ifname) {
|
|||
|
||||
if (iw->htmodelist(ifname, &htmodes))
|
||||
{
|
||||
dawnlog_error("No VHT mode information available\n");
|
||||
iwinfo_finish();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ static void set_if_present_int(int *ret, struct uci_section *s, const char* opti
|
|||
|
||||
void uci_get_hostname(char* hostname)
|
||||
{
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
char path[]= "system.@system[0].hostname";
|
||||
struct uci_ptr ptr;
|
||||
struct uci_context *c = uci_alloc_context();
|
||||
|
@ -80,6 +82,8 @@ struct time_config_s uci_get_time_config() {
|
|||
.update_beacon_reports = 20,
|
||||
};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
|
@ -102,6 +106,43 @@ struct time_config_s uci_get_time_config() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
struct local_config_s uci_get_local_config() {
|
||||
struct local_config_s ret = {
|
||||
.loglevel = 0,
|
||||
};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct uci_element* e;
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
struct uci_section* s = uci_to_section(e);
|
||||
|
||||
if (strcmp(s->type, "local") == 0) {
|
||||
DAWN_SET_CONFIG_INT(ret, s, loglevel);
|
||||
}
|
||||
}
|
||||
|
||||
switch (ret.loglevel)
|
||||
{
|
||||
case 3:
|
||||
dawnlog_minlevel(DAWNLOG_DEBUG);
|
||||
break;
|
||||
case 2:
|
||||
dawnlog_minlevel(DAWNLOG_TRACE);
|
||||
break;
|
||||
case 1:
|
||||
dawnlog_minlevel(DAWNLOG_INFO);
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
dawnlog_minlevel(DAWNLOG_ALWAYS);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int get_rrm_mode_val(char mode) {
|
||||
switch (tolower(mode)) {
|
||||
|
@ -123,6 +164,8 @@ static int parse_rrm_mode(int *rrm_mode_order, const char *mode_string) {
|
|||
int len, mode_val;
|
||||
int mask = 0, order = 0, pos = 0;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (!mode_string)
|
||||
mode_string = DEFAULT_RRM_MODE_ORDER;
|
||||
len = strlen(mode_string);
|
||||
|
@ -141,15 +184,17 @@ static int parse_rrm_mode(int *rrm_mode_order, const char *mode_string) {
|
|||
|
||||
|
||||
static struct mac_entry_s *insert_neighbor_mac(struct mac_entry_s *head, const char* mac) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct mac_entry_s *new;
|
||||
|
||||
if (!(new = dawn_malloc(sizeof (struct mac_entry_s)))) {
|
||||
fprintf(stderr, "Warning: Failed to create neighbor entry for '%s'\n", mac);
|
||||
dawnlog_error("Failed to allocate neighbor entry for '%s'\n", mac);
|
||||
return head;
|
||||
}
|
||||
memset(new, 0, sizeof (struct mac_entry_s));
|
||||
if (hwaddr_aton(mac, new->mac.u8) != 0) {
|
||||
fprintf(stderr, "Warning: Failed to parse MAC from '%s'\n", mac);
|
||||
dawnlog_error("Failed to parse MAC from '%s'\n", mac);
|
||||
dawn_free(new);
|
||||
return head;
|
||||
}
|
||||
|
@ -159,6 +204,8 @@ static struct mac_entry_s *insert_neighbor_mac(struct mac_entry_s *head, const c
|
|||
|
||||
static void free_neighbor_mac_list(struct mac_entry_s *list) {
|
||||
struct mac_entry_s *ptr = list;
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
while (list) {
|
||||
ptr = list;
|
||||
list = list->next_mac;
|
||||
|
@ -171,6 +218,8 @@ static struct mac_entry_s* uci_lookup_mac_list(struct uci_option *o) {
|
|||
struct mac_entry_s *head = NULL;
|
||||
char *str;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (o == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -196,6 +245,8 @@ static struct uci_section *uci_find_metric_section(const char *name) {
|
|||
struct uci_section *s;
|
||||
struct uci_element *e;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
uci_foreach_element(&uci_pkg->sections, e) {
|
||||
s = uci_to_section(e);
|
||||
if (strcmp(s->type, "metric") == 0 &&
|
||||
|
@ -257,9 +308,9 @@ struct probe_metric_s uci_get_dawn_metric() {
|
|||
|
||||
if (!(global_s = uci_find_metric_section("global"))) {
|
||||
if (!(global_s = uci_find_metric_section(NULL))) {
|
||||
fprintf(stderr, "Warning: config metric global section not found! Using defaults.\n");
|
||||
dawnlog_warning("config metric global section not found! Using defaults.\n");
|
||||
} else {
|
||||
fprintf(stderr, "Warning: config metric global section not found. "
|
||||
dawnlog_warning("config metric global section not found. "
|
||||
"Using first unnamed config metric.\n"
|
||||
"Consider naming a 'global' metric section to avoid ambiguity.\n");
|
||||
}
|
||||
|
@ -325,6 +376,8 @@ struct network_config_s uci_get_dawn_network() {
|
|||
.bandwidth = -1,
|
||||
};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
|
@ -362,6 +415,8 @@ struct network_config_s uci_get_dawn_network() {
|
|||
}
|
||||
|
||||
bool uci_get_dawn_hostapd_dir() {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
|
@ -377,6 +432,8 @@ bool uci_get_dawn_hostapd_dir() {
|
|||
}
|
||||
|
||||
bool uci_get_dawn_sort_order() {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct uci_element *e;
|
||||
uci_foreach_element(&uci_pkg->sections, e)
|
||||
{
|
||||
|
@ -393,6 +450,8 @@ bool uci_get_dawn_sort_order() {
|
|||
|
||||
int uci_reset()
|
||||
{
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct uci_context *ctx = uci_ctx;
|
||||
|
||||
if (!ctx) {
|
||||
|
@ -410,6 +469,8 @@ int uci_reset()
|
|||
}
|
||||
|
||||
int uci_init() {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct uci_context *ctx = uci_ctx;
|
||||
|
||||
if (!ctx) {
|
||||
|
@ -439,6 +500,8 @@ int uci_init() {
|
|||
}
|
||||
|
||||
int uci_clear() {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
for (int band = 0; band < __DAWN_BAND_MAX; band++)
|
||||
free_neighbor_mac_list(dawn_metric.neighbors[band]);
|
||||
|
||||
|
@ -456,6 +519,8 @@ int uci_clear() {
|
|||
|
||||
int uci_set_network(char* uci_cmd)
|
||||
{
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct uci_ptr ptr;
|
||||
int ret = UCI_OK;
|
||||
struct uci_context *ctx = uci_ctx;
|
||||
|
@ -480,7 +545,7 @@ int uci_set_network(char* uci_cmd)
|
|||
}
|
||||
|
||||
if (uci_commit(ctx, &ptr.p, 0) != UCI_OK) {
|
||||
fprintf(stderr, "Failed to commit UCI cmd: %s\n", uci_cmd);
|
||||
dawnlog_error("Failed to commit UCI cmd: %s\n", uci_cmd);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -49,7 +49,7 @@ int hwaddr_aton(const char* txt, uint8_t* addr) {
|
|||
void write_mac_to_file(char* path, struct dawn_mac addr) {
|
||||
FILE* f = fopen(path, "a");
|
||||
if (f == NULL) {
|
||||
fprintf(stderr, "Error opening mac file!\n");
|
||||
dawnlog_error("Error opening mac file!\n");
|
||||
|
||||
// TODO: Should this be an exit()?
|
||||
exit(1);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "memory_utils.h"
|
||||
|
||||
#define DAWN_MEM_FILENAME_LEN 20
|
||||
|
@ -73,7 +74,7 @@ void* dawn_memory_register(enum dawn_memop type, char* file, int line, size_t si
|
|||
type_c = 'X';
|
||||
break;
|
||||
default:
|
||||
printf("mem-audit: Unexpected memory op tag!\n");
|
||||
dawnlog_warning("mem-audit: Unexpected memory op tag!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -84,7 +85,7 @@ void* dawn_memory_register(enum dawn_memop type, char* file, int line, size_t si
|
|||
|
||||
if (*ipos != NULL && (*ipos)->ptr == ptr)
|
||||
{
|
||||
printf("mem-audit: attempting to register memory already registered (%c@%s:%d)...\n", type_c, file, line);
|
||||
dawnlog_warning("mem-audit: attempting to register memory already registered (%c@%s:%d)...\n", type_c, file, line);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -92,7 +93,7 @@ void* dawn_memory_register(enum dawn_memop type, char* file, int line, size_t si
|
|||
|
||||
if (this_log == NULL)
|
||||
{
|
||||
printf("mem-audit: Oh the irony! malloc() failed in dawn_memory_register()!\n");
|
||||
dawnlog_warning("mem-audit: Oh the irony! malloc() failed in dawn_memory_register()!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -140,7 +141,7 @@ char type_c = '?';
|
|||
type_c = 'R';
|
||||
break;
|
||||
default:
|
||||
printf("mem-audit: Unexpected memory op tag!\n");
|
||||
dawnlog_warning("mem-audit: Unexpected memory op tag!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -152,7 +153,7 @@ char type_c = '?';
|
|||
}
|
||||
else
|
||||
{
|
||||
printf("mem-audit: Releasing (%c) memory we hadn't registered (%s:%d)...\n", type_c, file, line);
|
||||
dawnlog_warning("mem-audit: Releasing (%c) memory we hadn't registered (%s:%d)...\n", type_c, file, line);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -171,10 +172,10 @@ void dawn_memory_audit()
|
|||
{
|
||||
size_t total = 0;
|
||||
|
||||
printf("mem-audit: Currently recorded allocations...\n");
|
||||
dawnlog_always("mem-audit: Currently recorded allocations...\n");
|
||||
for (struct mem_list* mem = mem_base; mem != NULL; mem = mem->next_mem)
|
||||
{
|
||||
printf("mem-audit: %8" PRIu64 "=%c - %s@%d: %zu\n", mem->ref, mem->type, mem->file, mem->line, mem->size);
|
||||
dawnlog_always("mem-audit: %8" PRIu64 "=%c - %s@%d: %zu\n", mem->ref, mem->type, mem->file, mem->line, mem->size);
|
||||
total += mem->size;
|
||||
}
|
||||
|
||||
|
@ -185,5 +186,5 @@ size_t total = 0;
|
|||
suffix = "kbytes";
|
||||
}
|
||||
|
||||
printf("mem-audit: [End of list: %zu %s]\n", total, suffix);
|
||||
dawnlog_always("mem-audit: [End of list: %zu %s]\n", total, suffix);
|
||||
}
|
||||
|
|
|
@ -133,6 +133,8 @@ static int handle_uci_config(struct blob_attr* msg);
|
|||
int parse_to_hostapd_notify(struct blob_attr* msg, hostapd_notify_entry* notify_req) {
|
||||
struct blob_attr* tb[__HOSTAPD_NOTIFY_MAX];
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
blobmsg_parse(hostapd_notify_policy, __HOSTAPD_NOTIFY_MAX, tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
if (hwaddr_aton(blobmsg_data(tb[HOSTAPD_NOTIFY_BSSID_ADDR]), notify_req->bssid_addr.u8))
|
||||
|
@ -147,10 +149,12 @@ int parse_to_hostapd_notify(struct blob_attr* msg, hostapd_notify_entry* notify_
|
|||
probe_entry *parse_to_probe_req(struct blob_attr* msg) {
|
||||
struct blob_attr* tb[__PROB_MAX];
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
probe_entry* prob_req = dawn_malloc(sizeof(probe_entry));
|
||||
if (prob_req == NULL)
|
||||
{
|
||||
fprintf(stderr, "dawn_malloc of probe_entry failed!\n");
|
||||
dawnlog_error("dawn_malloc of probe_entry failed!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -220,6 +224,8 @@ int handle_deauth_req(struct blob_attr* msg) {
|
|||
hostapd_notify_entry notify_req;
|
||||
parse_to_hostapd_notify(msg, ¬ify_req);
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
pthread_mutex_lock(&client_array_mutex);
|
||||
|
||||
client* client_entry = client_array_get_client(notify_req.client_addr);
|
||||
|
@ -228,11 +234,15 @@ int handle_deauth_req(struct blob_attr* msg) {
|
|||
|
||||
pthread_mutex_unlock(&client_array_mutex);
|
||||
|
||||
dawnlog_debug("[WC] Deauth: %s\n", "deauth");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_set_probe(struct blob_attr* msg) {
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
hostapd_notify_entry notify_req;
|
||||
parse_to_hostapd_notify(msg, ¬ify_req);
|
||||
|
||||
|
@ -246,6 +256,8 @@ int handle_network_msg(char* msg) {
|
|||
char* method;
|
||||
char* data;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
blob_buf_init(&network_buf, 0);
|
||||
blobmsg_add_json_from_string(&network_buf, msg);
|
||||
|
||||
|
@ -258,18 +270,18 @@ 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
|
||||
dawnlog_debug("Network Method new: %s : %s\n", method, msg);
|
||||
|
||||
blob_buf_init(&data_buf, 0);
|
||||
blobmsg_add_json_from_string(&data_buf, data);
|
||||
|
||||
if (!data_buf.head) {
|
||||
dawnlog_warning("Data header not formed!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (blob_len(data_buf.head) <= 0) {
|
||||
dawnlog_warning("Data header invalid length!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -294,15 +306,11 @@ 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
|
||||
dawnlog_debug("METHOD DEAUTH\n");
|
||||
handle_deauth_req(data_buf.head);
|
||||
}
|
||||
else if (strncmp(method, "setprobe", 5) == 0) {
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
printf("HANDLING SET PROBE!\n");
|
||||
#endif
|
||||
dawnlog_debug("HANDLING SET PROBE!\n");
|
||||
handle_set_probe(data_buf.head);
|
||||
}
|
||||
else if (strncmp(method, "addmac", 5) == 0) {
|
||||
|
@ -312,25 +320,21 @@ 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
|
||||
dawnlog_debug("HANDLING UCI!\n");
|
||||
handle_uci_config(data_buf.head);
|
||||
}
|
||||
else if (strncmp(method, "beacon-report", 12) == 0) {
|
||||
// TODO: Check beacon report stuff
|
||||
|
||||
//printf("HANDLING BEACON REPORT NETWORK!\n");
|
||||
//printf("The Method for beacon-report is: %s\n", method);
|
||||
dawnlog_debug("HANDLING BEACON REPORT NETWORK!\n");
|
||||
dawnlog_debug("The Method for beacon-report is: %s\n", method);
|
||||
// ignore beacon reports send via network!, use probe functions for it
|
||||
//probe_entry entry; // for now just stay at probe entry stuff...
|
||||
//parse_to_beacon_rep(data_buf.head, &entry, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
printf("No method fonud for: %s\n", method);
|
||||
#endif
|
||||
dawnlog_warning("No method found for: %s\n", method);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -339,8 +343,10 @@ int handle_network_msg(char* msg) {
|
|||
static uint8_t
|
||||
dump_rrm_data(struct blob_attr* head)
|
||||
{
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (blob_id(head) != BLOBMSG_TYPE_INT32) {
|
||||
fprintf(stderr, "wrong type of rrm array.\n");
|
||||
dawnlog_error("wrong type of rrm array.\n");
|
||||
return 0;
|
||||
}
|
||||
return (uint8_t)blobmsg_get_u32(head);
|
||||
|
@ -350,6 +356,8 @@ dump_rrm_data(struct blob_attr* head)
|
|||
static void
|
||||
dump_client(struct blob_attr** tb, struct dawn_mac client_addr, const char* bssid_addr, uint32_t freq, uint8_t ht_supported,
|
||||
uint8_t vht_supported) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
client *client_entry = dawn_malloc(sizeof(struct client_s));
|
||||
if (client_entry == NULL)
|
||||
{
|
||||
|
@ -430,6 +438,8 @@ dump_client_table(struct blob_attr* head, int len, const char* bssid_addr, uint3
|
|||
struct blobmsg_hdr* hdr;
|
||||
int station_count = 0;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
__blob_for_each_attr(attr, head, len)
|
||||
{
|
||||
hdr = blob_data(attr);
|
||||
|
@ -453,6 +463,8 @@ dump_client_table(struct blob_attr* head, int len, const char* bssid_addr, uint3
|
|||
int parse_to_clients(struct blob_attr* msg, int do_kick, uint32_t id) {
|
||||
struct blob_attr* tb[__CLIENT_TABLE_MAX];
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (!msg) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -682,12 +694,14 @@ static const struct blobmsg_policy uci_times_policy[__UCI_TIMES_MAX] = {
|
|||
|
||||
static int handle_uci_config(struct blob_attr* msg) {
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct blob_attr* tb[__UCI_TABLE_MAX];
|
||||
blobmsg_parse(uci_table_policy, __UCI_TABLE_MAX, tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
const char *version_string = blobmsg_get_string(tb[UCI_CONFIG_VERSION]);
|
||||
if (version_string == NULL || strcmp(version_string, DAWN_CONFIG_VERSION)) {
|
||||
fprintf(stderr, "Ignoring network config message with incompatible version string '%s'.\n",
|
||||
dawnlog_warning("Ignoring network config message with incompatible version string '%s'.\n",
|
||||
version_string ? : "");
|
||||
return -1;
|
||||
}
|
||||
|
@ -768,7 +782,7 @@ static int handle_uci_config(struct blob_attr* msg) {
|
|||
break;
|
||||
}
|
||||
if (band == __DAWN_BAND_MAX) {
|
||||
fprintf(stderr, "handle_uci_config: Warning: unknown band '%s'.\n", band_name);
|
||||
dawnlog_warning("handle_uci_config: unknown band '%s'.\n", band_name);
|
||||
continue; // Should we write the metrics of an unknown band to the config file?
|
||||
}
|
||||
|
||||
|
|
244
src/utils/ubus.c
244
src/utils/ubus.c
|
@ -236,6 +236,8 @@ subscription_wait(struct ubus_event_handler *handler) {
|
|||
void blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const struct dawn_mac addr) {
|
||||
char *s;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
s = blobmsg_alloc_string_buffer(buf, name, 20);
|
||||
sprintf(s, MACSTR, MAC2STR(addr.u8));
|
||||
blobmsg_add_string_buffer(buf);
|
||||
|
@ -276,6 +278,8 @@ static int decide_function(probe_entry *prob_req, int req_type) {
|
|||
int parse_to_auth_req(struct blob_attr *msg, auth_entry *auth_req) {
|
||||
struct blob_attr *tb[__AUTH_MAX];
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
blobmsg_parse(auth_policy, __AUTH_MAX, tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
if (hwaddr_aton(blobmsg_data(tb[AUTH_BSSID_ADDR]), auth_req->bssid_addr.u8))
|
||||
|
@ -299,6 +303,8 @@ int parse_to_auth_req(struct blob_attr *msg, auth_entry *auth_req) {
|
|||
}
|
||||
|
||||
int parse_to_assoc_req(struct blob_attr *msg, assoc_entry *assoc_req) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
return (parse_to_auth_req(msg, assoc_req));
|
||||
}
|
||||
|
||||
|
@ -307,6 +313,8 @@ int parse_to_beacon_rep(struct blob_attr *msg) {
|
|||
struct dawn_mac msg_bssid;
|
||||
struct dawn_mac msg_client;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
blobmsg_parse(beacon_rep_policy, __BEACON_REP_MAX, tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
if(!tb[BEACON_REP_BSSID] || !tb[BEACON_REP_ADDR])
|
||||
|
@ -319,7 +327,7 @@ int parse_to_beacon_rep(struct blob_attr *msg) {
|
|||
|
||||
if(mac_is_null(msg_bssid.u8))
|
||||
{
|
||||
fprintf(stderr, "Received NULL MAC! Client is strange!\n");
|
||||
dawnlog_warning("Received NULL MAC! Client is strange!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -339,14 +347,16 @@ int parse_to_beacon_rep(struct blob_attr *msg) {
|
|||
|
||||
|
||||
// HACKY WORKAROUND!
|
||||
dawnlog_debug("Try update RCPI and RSNI for beacon report!\n");
|
||||
if(!probe_array_update_rcpi_rsni(msg_bssid, msg_client, rcpi, rsni, true))
|
||||
{
|
||||
dawnlog_debug("Beacon: No Probe Entry Existing!\n");
|
||||
|
||||
probe_entry* beacon_rep = dawn_malloc(sizeof(probe_entry));
|
||||
probe_entry* beacon_rep_updated = NULL;
|
||||
if (beacon_rep == NULL)
|
||||
{
|
||||
fprintf(stderr, "dawn_malloc of probe_entry failed!\n");
|
||||
dawnlog_error("dawn_malloc of probe_entry failed!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -364,6 +374,7 @@ 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!!!
|
||||
dawnlog_debug("Inserting to array!\n");
|
||||
|
||||
// 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));
|
||||
|
@ -383,19 +394,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
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
auth_entry *auth_req = dawn_malloc(sizeof(struct auth_entry_s));
|
||||
if (auth_req == NULL)
|
||||
{
|
||||
dawnlog_error("Memory allocation of auth req failed!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
parse_to_auth_req(msg, auth_req);
|
||||
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
printf("Auth entry: ");
|
||||
print_auth_entry(auth_req);
|
||||
#endif
|
||||
dawnlog_debug("Auth entry: ");
|
||||
print_auth_entry(DAWNLOG_DEBUG, auth_req);
|
||||
|
||||
if (!mac_in_maclist(auth_req->client_addr)) {
|
||||
pthread_mutex_lock(&probe_array_mutex);
|
||||
|
@ -424,18 +435,15 @@ static int handle_assoc_req(struct blob_attr *msg) {
|
|||
int ret = WLAN_STATUS_SUCCESS;
|
||||
int discard_entry = true;
|
||||
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
dawnlog_debug_func("Entering...");
|
||||
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
|
||||
dawnlog_debug("Association entry: ");
|
||||
print_auth_entry(DAWNLOG_DEBUG, auth_req);
|
||||
|
||||
if (!mac_in_maclist(auth_req->client_addr)) {
|
||||
pthread_mutex_lock(&probe_array_mutex);
|
||||
|
@ -464,6 +472,7 @@ static int handle_probe_req(struct blob_attr *msg) {
|
|||
// MUSTDO: Untangle dawn_malloc() and linking of probe_entry
|
||||
probe_entry* probe_req = parse_to_probe_req(msg);
|
||||
probe_entry* probe_req_updated = NULL;
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (probe_req != NULL) {
|
||||
probe_req_updated = insert_to_array(probe_req, true, true, false, time(0));
|
||||
|
@ -485,8 +494,11 @@ static int handle_probe_req(struct blob_attr *msg) {
|
|||
}
|
||||
|
||||
static int handle_beacon_rep(struct blob_attr *msg) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
if (parse_to_beacon_rep(msg) == 0) {
|
||||
// dawnlog_debug("Inserting beacon Report!\n");
|
||||
// insert_to_array(beacon_rep, 1);
|
||||
// dawnlog_debug("Sending via network!\n");
|
||||
// send_blob_attr_via_network(msg, "beacon-report");
|
||||
}
|
||||
return 0;
|
||||
|
@ -495,6 +507,8 @@ static int handle_beacon_rep(struct blob_attr *msg) {
|
|||
|
||||
int send_blob_attr_via_network(struct blob_attr* msg, char* method) {
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (!msg) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -530,19 +544,19 @@ int send_blob_attr_via_network(struct blob_attr* msg, char* method) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int hostapd_notify(struct ubus_context *ctx_local, struct ubus_object *obj,
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg) {
|
||||
char *str;
|
||||
static int hostapd_notify(struct ubus_context* ctx_local, struct ubus_object* obj,
|
||||
struct ubus_request_data* req, const char* method,
|
||||
struct blob_attr* msg) {
|
||||
int ret = 0;
|
||||
struct blob_buf b = {0};
|
||||
|
||||
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);
|
||||
if (dawnlog_showing(DAWNLOG_DEBUG))
|
||||
{
|
||||
char* str = blobmsg_format_json(msg, true);
|
||||
dawn_regmem(str);
|
||||
dawnlog_debug("Method new: %s : %s\n", method, str);
|
||||
dawn_free(str);
|
||||
}
|
||||
|
||||
struct hostapd_sock_entry *entry;
|
||||
struct ubus_subscriber *subscriber;
|
||||
|
@ -581,11 +595,14 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) {
|
|||
uloop_init();
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
ctx = ubus_connect(ubus_socket);
|
||||
if (!ctx) {
|
||||
fprintf(stderr, "Failed to connect to ubus\n");
|
||||
dawnlog_error("Failed to connect to ubus\n");
|
||||
return -1;
|
||||
} else {
|
||||
dawnlog_debug("Connected to ubus\n");
|
||||
dawn_regmem(ctx);
|
||||
}
|
||||
|
||||
|
@ -632,6 +649,8 @@ int dawn_init_ubus(const char *ubus_socket, const char *hostapd_dir) {
|
|||
|
||||
static int get_band_from_bssid(struct dawn_mac bssid) {
|
||||
ap *a;
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
for (a = ap_set; a; a = a->next_ap) {
|
||||
if (mac_is_equal_bb(a->bssid_addr, bssid))
|
||||
return get_band(a->freq);
|
||||
|
@ -661,14 +680,14 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_
|
|||
}
|
||||
|
||||
if (entry == NULL) {
|
||||
fprintf(stderr, "Failed to find interface!\n");
|
||||
dawnlog_error("Failed to find interface!\n");
|
||||
dawn_free(data_str);
|
||||
blob_buf_free(&b);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entry->subscribed) {
|
||||
fprintf(stderr, "Interface %s is not subscribed!\n", entry->iface_name);
|
||||
dawnlog_error("Interface %s is not subscribed!\n", entry->iface_name);
|
||||
dawn_free(data_str);
|
||||
blob_buf_free(&b);
|
||||
return;
|
||||
|
@ -706,6 +725,7 @@ static void ubus_get_clients_cb(struct ubus_request *req, int type, struct blob_
|
|||
static int ubus_get_clients() {
|
||||
int timeout = 1;
|
||||
struct hostapd_sock_entry *sub;
|
||||
dawnlog_debug_func("Entering...");
|
||||
list_for_each_entry(sub, &hostapd_sock_list, list)
|
||||
{
|
||||
if (sub->subscribed) {
|
||||
|
@ -722,6 +742,8 @@ static void ubus_get_rrm_cb(struct ubus_request *req, int type, struct blob_attr
|
|||
struct hostapd_sock_entry *sub, *entry = NULL;
|
||||
struct blob_attr *tb[__RRM_MAX];
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (!msg)
|
||||
return;
|
||||
|
||||
|
@ -748,6 +770,7 @@ 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);
|
||||
dawnlog_debug("Copied Neighborreport: %s,\n", entry->neighbor_report);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -757,6 +780,8 @@ static int ubus_get_rrm() {
|
|||
int timeout = 1;
|
||||
struct hostapd_sock_entry *sub;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
list_for_each_entry(sub, &hostapd_sock_list, list)
|
||||
{
|
||||
if (sub->subscribed) {
|
||||
|
@ -770,6 +795,8 @@ static int ubus_get_rrm() {
|
|||
}
|
||||
|
||||
void update_clients(struct uloop_timeout *t) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
ubus_get_clients();
|
||||
if(dawn_metric.set_hostapd_nr)
|
||||
ubus_set_nr();
|
||||
|
@ -778,6 +805,8 @@ void update_clients(struct uloop_timeout *t) {
|
|||
}
|
||||
|
||||
void run_server_update(struct uloop_timeout *t) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if(run_server(network_config.tcp_port))
|
||||
uloop_timeout_set(&usock_timer, 1 * 1000);
|
||||
}
|
||||
|
@ -785,6 +814,8 @@ void run_server_update(struct uloop_timeout *t) {
|
|||
void update_channel_utilization(struct uloop_timeout *t) {
|
||||
struct hostapd_sock_entry *sub;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
list_for_each_entry(sub, &hostapd_sock_list, list)
|
||||
{
|
||||
|
||||
|
@ -804,6 +835,8 @@ void update_channel_utilization(struct uloop_timeout *t) {
|
|||
}
|
||||
|
||||
static int get_mode_from_capability(int capability) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
for (int n = 0; n < __RRM_BEACON_RQST_MODE_MAX; n++) {
|
||||
switch (capability & dawn_metric.rrm_mode_order[n]) {
|
||||
case WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE:
|
||||
|
@ -820,6 +853,9 @@ static int get_mode_from_capability(int capability) {
|
|||
void ubus_send_beacon_report(client *c, ap *a, int id)
|
||||
{
|
||||
struct blob_buf b = {0};
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
dawnlog_debug("Crafting Beacon Report\n");
|
||||
int timeout = 1;
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
|
@ -830,6 +866,7 @@ void ubus_send_beacon_report(client *c, ap *a, int id)
|
|||
blobmsg_add_u32(&b, "mode", get_mode_from_capability(c->rrm_enabled_capa));
|
||||
blobmsg_add_string(&b, "ssid", (char*)a->ssid);
|
||||
|
||||
dawnlog_debug("Invoking beacon report!\n");
|
||||
ubus_invoke(ctx, id, "rrm_beacon_req", b.head, NULL, NULL, timeout * 1000);
|
||||
blob_buf_free(&b);
|
||||
}
|
||||
|
@ -837,14 +874,18 @@ void ubus_send_beacon_report(client *c, ap *a, int id)
|
|||
void update_beacon_reports(struct uloop_timeout *t) {
|
||||
ap *a;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if(!timeout_config.update_beacon_reports) // if 0 just return
|
||||
{
|
||||
return;
|
||||
}
|
||||
dawnlog_debug("Sending beacon report!\n");
|
||||
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))) {
|
||||
dawnlog_debug("Sending beacon report Sub!\n");
|
||||
send_beacon_reports(a, sub->id);
|
||||
}
|
||||
}
|
||||
|
@ -852,6 +893,8 @@ void update_beacon_reports(struct uloop_timeout *t) {
|
|||
}
|
||||
|
||||
void update_tcp_connections(struct uloop_timeout *t) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (strcmp(network_config.server_ip, ""))
|
||||
{
|
||||
// nothing happens if tcp connection is already established
|
||||
|
@ -865,16 +908,22 @@ void update_tcp_connections(struct uloop_timeout *t) {
|
|||
}
|
||||
|
||||
void start_tcp_con_update() {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
// update connections
|
||||
uloop_timeout_add(&tcp_con_timer); // callback = update_tcp_connections
|
||||
}
|
||||
|
||||
void update_hostapd_sockets(struct uloop_timeout *t) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
subscribe_to_new_interfaces(hostapd_dir_glob);
|
||||
uloop_timeout_set(&hostapd_timer, timeout_config.update_hostapd * 1000);
|
||||
}
|
||||
|
||||
void ubus_set_nr(){
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct hostapd_sock_entry *sub;
|
||||
int timeout = 1;
|
||||
|
||||
|
@ -894,6 +943,8 @@ void del_client_all_interfaces(const struct dawn_mac client_addr, uint32_t reaso
|
|||
struct hostapd_sock_entry *sub;
|
||||
struct blob_buf b = {0};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
blobmsg_add_macaddr(&b, "addr", client_addr);
|
||||
blobmsg_add_u32(&b, "reason", reason);
|
||||
|
@ -935,6 +986,8 @@ int wnm_disassoc_imminent(uint32_t id, const struct dawn_mac client_addr, struct
|
|||
struct hostapd_sock_entry *sub;
|
||||
struct blob_buf b = {0};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
blobmsg_add_macaddr(&b, "addr", client_addr);
|
||||
blobmsg_add_u32(&b, "duration", duration);
|
||||
|
@ -942,9 +995,7 @@ 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
|
||||
dawnlog_info("BSS TRANSITION NEIGHBOR " NR_MACSTR ", Score=%d\n", NR_MAC2STR(neighbor_list->nr), neighbor_list->score);
|
||||
blobmsg_add_string(&b, NULL, neighbor_list->nr);
|
||||
neighbor_list = neighbor_list->next;
|
||||
}
|
||||
|
@ -966,6 +1017,8 @@ int wnm_disassoc_imminent(uint32_t id, const struct dawn_mac client_addr, struct
|
|||
static void ubus_umdns_cb(struct ubus_request *req, int type, struct blob_attr *msg) {
|
||||
struct blob_attr *tb[__DAWN_UMDNS_TABLE_MAX];
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (!msg)
|
||||
return;
|
||||
|
||||
|
@ -980,19 +1033,17 @@ static void ubus_umdns_cb(struct ubus_request *req, int type, struct blob_attr *
|
|||
|
||||
__blob_for_each_attr(attr, blobmsg_data(tb[DAWN_UMDNS_TABLE]), len)
|
||||
{
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
#if DAWNLOG_COMPILING(DAWNLOG_DEBUG)
|
||||
struct blobmsg_hdr *hdr = blob_data(attr);
|
||||
printf("Hostname: %s\n", hdr->name);
|
||||
dawnlog_debug("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));
|
||||
|
||||
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
|
||||
dawnlog_debug("IPV4: %s\n", blobmsg_get_string(tb_dawn[DAWN_UMDNS_IPV4]));
|
||||
dawnlog_debug("Port: %d\n", blobmsg_get_u32(tb_dawn[DAWN_UMDNS_PORT]));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -1004,8 +1055,10 @@ int ubus_call_umdns() {
|
|||
u_int32_t id;
|
||||
struct blob_buf b = {0};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (ubus_lookup_id(ctx, "umdns", &id)) {
|
||||
fprintf(stderr, "Failed to look up test object for %s\n", "umdns");
|
||||
dawnlog_error("Failed to look up test object for %s\n", "umdns");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1022,6 +1075,8 @@ int ubus_call_umdns() {
|
|||
int ubus_send_probe_via_network(struct probe_entry_s *probe_entry) { // TODO: probe_entry is also a typedef - fix?
|
||||
struct blob_buf b = {0};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
blobmsg_add_macaddr(&b, "bssid", probe_entry->bssid_addr);
|
||||
blobmsg_add_macaddr(&b, "address", probe_entry->client_addr);
|
||||
|
@ -1056,6 +1111,8 @@ int ubus_send_probe_via_network(struct probe_entry_s *probe_entry) { // TODO: p
|
|||
int send_set_probe(struct dawn_mac client_addr) {
|
||||
struct blob_buf b = {0};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
blobmsg_add_macaddr(&b, "bssid", client_addr);
|
||||
blobmsg_add_macaddr(&b, "address", client_addr);
|
||||
|
@ -1097,15 +1154,21 @@ int parse_add_mac_to_file(struct blob_attr *msg) {
|
|||
struct blob_attr *tb[__ADD_DEL_MAC_MAX];
|
||||
struct blob_attr *attr;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
dawnlog_debug("Parsing MAC!\n");
|
||||
|
||||
blobmsg_parse(add_del_policy, __ADD_DEL_MAC_MAX, tb, blob_data(msg), blob_len(msg));
|
||||
|
||||
if (!tb[MAC_ADDR])
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
|
||||
int len = blobmsg_data_len(tb[MAC_ADDR]);
|
||||
dawnlog_debug("Length of array maclist: %d\n", len);
|
||||
|
||||
__blob_for_each_attr(attr, blobmsg_data(tb[MAC_ADDR]), len)
|
||||
{
|
||||
dawnlog_debug("Iteration through MAC-list\n");
|
||||
struct dawn_mac addr;
|
||||
hwaddr_aton(blobmsg_data(attr), addr.u8);
|
||||
|
||||
|
@ -1122,6 +1185,10 @@ int parse_add_mac_to_file(struct blob_attr *msg) {
|
|||
static int add_mac(struct ubus_context *ctx_local, struct ubus_object *obj,
|
||||
struct ubus_request_data *req, const char *method,
|
||||
struct blob_attr *msg) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
dawnlog_trace("UBUS invoking add_mac()");
|
||||
|
||||
parse_add_mac_to_file(msg);
|
||||
|
||||
// here we need to send it via the network!
|
||||
|
@ -1136,6 +1203,10 @@ static int reload_config(struct ubus_context *ctx_local, struct ubus_object *obj
|
|||
int ret;
|
||||
struct blob_buf b = {0};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
dawnlog_trace("UBUS invoking reload_config()");
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
uci_reset();
|
||||
dawn_metric = uci_get_dawn_metric();
|
||||
|
@ -1149,7 +1220,7 @@ static int reload_config(struct ubus_context *ctx_local, struct ubus_object *obj
|
|||
uci_send_via_network();
|
||||
ret = ubus_send_reply(ctx_local, req, b.head);
|
||||
if (ret)
|
||||
fprintf(stderr, "Failed to send reply: %s\n", ubus_strerror(ret));
|
||||
dawnlog_error("Failed to send reply: %s\n", ubus_strerror(ret));
|
||||
|
||||
blob_buf_free(&b);
|
||||
|
||||
|
@ -1162,11 +1233,15 @@ static int get_hearing_map(struct ubus_context *ctx_local, struct ubus_object *o
|
|||
int ret;
|
||||
struct blob_buf b = {0};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
dawnlog_trace("UBUS invoking get_hearing_map()");
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
build_hearing_map_sort_client(&b);
|
||||
ret = ubus_send_reply(ctx_local, req, b.head);
|
||||
if (ret)
|
||||
fprintf(stderr, "Failed to send reply: %s\n", ubus_strerror(ret));
|
||||
dawnlog_error("Failed to send reply: %s\n", ubus_strerror(ret));
|
||||
blob_buf_free(&b);
|
||||
|
||||
return 0;
|
||||
|
@ -1179,11 +1254,15 @@ static int get_network(struct ubus_context *ctx_local, struct ubus_object *obj,
|
|||
int ret;
|
||||
struct blob_buf b = {0};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
dawnlog_trace("UBUS invoking get_network()");
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
build_network_overview(&b);
|
||||
ret = ubus_send_reply(ctx_local, req, b.head);
|
||||
if (ret)
|
||||
fprintf(stderr, "Failed to send reply: %s\n", ubus_strerror(ret));
|
||||
dawnlog_error("Failed to send reply: %s\n", ubus_strerror(ret));
|
||||
blob_buf_free(&b);
|
||||
|
||||
return 0;
|
||||
|
@ -1192,9 +1271,11 @@ static int get_network(struct ubus_context *ctx_local, struct ubus_object *obj,
|
|||
static void ubus_add_oject() {
|
||||
int ret;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
ret = ubus_add_object(ctx, &dawn_object);
|
||||
if (ret)
|
||||
fprintf(stderr, "Failed to add object: %s\n", ubus_strerror(ret));
|
||||
dawnlog_error("Failed to add object: %s\n", ubus_strerror(ret));
|
||||
}
|
||||
|
||||
static void respond_to_notify(uint32_t id) {
|
||||
|
@ -1205,12 +1286,14 @@ static void respond_to_notify(uint32_t id) {
|
|||
struct blob_buf b = {0};
|
||||
int timeout = 1;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
blobmsg_add_u32(&b, "notify_response", 1);
|
||||
|
||||
ret = ubus_invoke(ctx, id, "notify_response", b.head, NULL, NULL, timeout * 1000);
|
||||
if (ret)
|
||||
fprintf(stderr, "Failed to invoke: %s\n", ubus_strerror(ret));
|
||||
dawnlog_error("Failed to invoke: %s\n", ubus_strerror(ret));
|
||||
|
||||
blob_buf_free(&b);
|
||||
}
|
||||
|
@ -1227,17 +1310,21 @@ static void enable_rrm(uint32_t id) {
|
|||
int timeout = 1;
|
||||
ret = ubus_invoke(ctx, id, "bss_mgmt_enable", b.head, NULL, NULL, timeout * 1000);
|
||||
if (ret)
|
||||
fprintf(stderr, "Failed to invoke: %s\n", ubus_strerror(ret));
|
||||
dawnlog_error("Failed to invoke: %s\n", ubus_strerror(ret));
|
||||
|
||||
blob_buf_free(&b);
|
||||
}
|
||||
|
||||
static void hostapd_handle_remove(struct ubus_context *ctx_local,
|
||||
struct ubus_subscriber *s, uint32_t id) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
dawnlog_debug("Object %08x went away\n", id);
|
||||
struct hostapd_sock_entry *hostapd_sock = container_of(s,
|
||||
struct hostapd_sock_entry, subscriber);
|
||||
|
||||
if (hostapd_sock->id != id) {
|
||||
dawnlog_debug("ID is not the same!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1247,6 +1334,8 @@ static void hostapd_handle_remove(struct ubus_context *ctx_local,
|
|||
}
|
||||
|
||||
bool subscribe(struct ubus_context *ctx_local, struct hostapd_sock_entry *hostapd_entry) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
char subscribe_name[sizeof("hostapd.") + MAX_INTERFACE_NAME + 1];
|
||||
|
||||
if (hostapd_entry->subscribed)
|
||||
|
@ -1255,13 +1344,13 @@ bool subscribe(struct ubus_context *ctx_local, struct hostapd_sock_entry *hostap
|
|||
sprintf(subscribe_name, "hostapd.%s", hostapd_entry->iface_name);
|
||||
|
||||
if (ubus_lookup_id(ctx_local, subscribe_name, &hostapd_entry->id)) {
|
||||
fprintf(stdout, "Failed to lookup ID!");
|
||||
dawnlog_warning("Failed to lookup ID!");
|
||||
subscription_wait(&hostapd_entry->wait_handler);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ubus_subscribe(ctx_local, &hostapd_entry->subscriber, hostapd_entry->id)) {
|
||||
fprintf(stdout, "Failed to register subscriber!");
|
||||
dawnlog_warning("Failed to register subscriber!");
|
||||
subscription_wait(&hostapd_entry->wait_handler);
|
||||
return false;
|
||||
}
|
||||
|
@ -1280,6 +1369,8 @@ bool subscribe(struct ubus_context *ctx_local, struct hostapd_sock_entry *hostap
|
|||
enable_rrm(hostapd_entry->id);
|
||||
ubus_get_rrm();
|
||||
|
||||
dawnlog_debug("Subscribed to: %s\n", hostapd_entry->iface_name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1290,6 +1381,8 @@ wait_cb(struct ubus_context *ctx_local, struct ubus_event_handler *ev_handler,
|
|||
"path", BLOBMSG_TYPE_STRING
|
||||
};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
struct blob_attr *attr;
|
||||
const char *path;
|
||||
struct hostapd_sock_entry *sub = container_of(ev_handler,
|
||||
|
@ -1318,6 +1411,8 @@ bool subscriber_to_interface(const char *ifname) {
|
|||
|
||||
struct hostapd_sock_entry *hostapd_entry;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
hostapd_entry = dawn_calloc(1, sizeof(struct hostapd_sock_entry));
|
||||
strcpy(hostapd_entry->iface_name, ifname);
|
||||
|
||||
|
@ -1331,7 +1426,7 @@ bool subscriber_to_interface(const char *ifname) {
|
|||
hostapd_entry->subscribed = false;
|
||||
|
||||
if (ubus_register_subscriber(ctx, &hostapd_entry->subscriber)) {
|
||||
fprintf(stderr, "Failed to register subscriber!");
|
||||
dawnlog_error("Failed to register subscriber!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1345,13 +1440,15 @@ void subscribe_to_new_interfaces(const char *hostapd_sock_path) {
|
|||
struct dirent *entry;
|
||||
struct hostapd_sock_entry *sub = NULL;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
dirp = opendir(hostapd_sock_path); // error handling?
|
||||
if (!dirp) {
|
||||
fprintf(stderr, "[SUBSCRIBING] No hostapd sockets!\n");
|
||||
dawnlog_error("[SUBSCRIBING] No hostapd sockets!\n");
|
||||
return;
|
||||
}
|
||||
while ((entry = readdir(dirp)) != NULL) {
|
||||
|
@ -1378,6 +1475,8 @@ void subscribe_to_new_interfaces(const char *hostapd_sock_path) {
|
|||
|
||||
static char get_rrm_mode_char(int val)
|
||||
{
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
switch (val) {
|
||||
case WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE:
|
||||
return 'p';
|
||||
|
@ -1392,6 +1491,8 @@ static char get_rrm_mode_char(int val)
|
|||
const static char* get_rrm_mode_string(int *rrm_mode_order) {
|
||||
static char rrm_mode_string [__RRM_BEACON_RQST_MODE_MAX + 1] = {0};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
for (int n = 0; n < __RRM_BEACON_RQST_MODE_MAX && rrm_mode_order[n]; n++)
|
||||
rrm_mode_string[n] = get_rrm_mode_char(rrm_mode_order[n]);
|
||||
return rrm_mode_string;
|
||||
|
@ -1402,6 +1503,8 @@ int uci_send_via_network()
|
|||
void *metric, *times, *band_table, *band_entry;
|
||||
struct blob_buf b = {0};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
blobmsg_add_string(&b, "version", DAWN_CONFIG_VERSION);
|
||||
metric = blobmsg_open_table(&b, "metric");
|
||||
|
@ -1469,6 +1572,11 @@ int uci_send_via_network()
|
|||
}
|
||||
|
||||
int build_hearing_map_sort_client(struct blob_buf *b) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
if (dawnlog_showing(DAWNLOG_DEBUG))
|
||||
print_probe_array();
|
||||
|
||||
pthread_mutex_lock(&probe_array_mutex);
|
||||
|
||||
void *client_list, *ap_list, *ssid_list;
|
||||
|
@ -1554,6 +1662,8 @@ int build_network_overview(struct blob_buf *b) {
|
|||
char client_mac_buf[20];
|
||||
struct hostapd_sock_entry *sub;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
bool add_ssid = true;
|
||||
for (ap* m = ap_set; m != NULL; m = m->next_ap) {
|
||||
if(add_ssid)
|
||||
|
@ -1645,6 +1755,8 @@ static void blobmsg_add_nr(struct blob_buf *b_local, ap *i) {
|
|||
void* nr_entry = blobmsg_open_array(b_local, NULL);
|
||||
char mac_buf[20];
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
sprintf(mac_buf, MACSTRLOWER, MAC2STR(i->bssid_addr.u8));
|
||||
blobmsg_add_string(b_local, NULL, mac_buf);
|
||||
|
||||
|
@ -1654,6 +1766,8 @@ static void blobmsg_add_nr(struct blob_buf *b_local, ap *i) {
|
|||
}
|
||||
|
||||
static int mac_is_in_entry_list(const struct dawn_mac mac, const struct mac_entry_s *list) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
for (const struct mac_entry_s *i = list; i; i = i->next_mac)
|
||||
if (mac_is_equal_bb(i->mac, mac))
|
||||
return 1;
|
||||
|
@ -1670,6 +1784,8 @@ int ap_get_nr(struct blob_buf *b_local, struct dawn_mac own_bssid_addr, const ch
|
|||
ap *i, *own_ap;
|
||||
struct mac_entry_s *preferred_list, *n;
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
void* nbs = blobmsg_open_array(b_local, "list");
|
||||
|
||||
own_ap = ap_array_get_ap(own_bssid_addr, (uint8_t*)ssid);
|
||||
|
@ -1700,6 +1816,8 @@ int ap_get_nr(struct blob_buf *b_local, struct dawn_mac own_bssid_addr, const ch
|
|||
}
|
||||
|
||||
void uloop_add_data_cbs() {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
uloop_timeout_add(&probe_timeout); // callback = remove_probe_array_cb
|
||||
uloop_timeout_add(&client_timeout); // callback = remove_client_array_cb
|
||||
uloop_timeout_add(&ap_timeout); // callback = remove_ap_array_cb
|
||||
|
@ -1712,14 +1830,12 @@ void uloop_add_data_cbs() {
|
|||
// TODO: Move mutex handling to remove_??? function to make test harness simpler?
|
||||
// Or not needed as test harness not threaded?
|
||||
void remove_probe_array_cb(struct uloop_timeout* t) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
pthread_mutex_lock(&probe_array_mutex);
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
printf("[Thread] : Removing old probe entries!\n");
|
||||
#endif
|
||||
dawnlog_debug("[Thread] : Removing old probe entries!\n");
|
||||
remove_old_probe_entries(time(0), timeout_config.remove_probe);
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
printf("[Thread] : Removing old entries finished!\n");
|
||||
#endif
|
||||
dawnlog_debug("[Thread] : Removing old entries finished!\n");
|
||||
pthread_mutex_unlock(&probe_array_mutex);
|
||||
uloop_timeout_set(&probe_timeout, timeout_config.remove_probe * 1000);
|
||||
}
|
||||
|
@ -1727,10 +1843,10 @@ void remove_probe_array_cb(struct uloop_timeout* t) {
|
|||
// TODO: Move mutex handling to remove_??? function to make test harness simpler?
|
||||
// Or not needed as test harness not threaded?
|
||||
void remove_client_array_cb(struct uloop_timeout* t) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
pthread_mutex_lock(&client_array_mutex);
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
printf("[Thread] : Removing old client entries!\n");
|
||||
#endif
|
||||
dawnlog_debug("[Thread] : Removing old client entries!\n");
|
||||
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);
|
||||
|
@ -1739,10 +1855,10 @@ void remove_client_array_cb(struct uloop_timeout* t) {
|
|||
// TODO: Move mutex handling to remove_??? function to make test harness simpler?
|
||||
// Or not needed as test harness not threaded?
|
||||
void remove_ap_array_cb(struct uloop_timeout* t) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
pthread_mutex_lock(&ap_array_mutex);
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
printf("[ULOOP] : Removing old ap entries!\n");
|
||||
#endif
|
||||
dawnlog_debug("[ULOOP] : Removing old ap entries!\n");
|
||||
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);
|
||||
|
@ -1751,10 +1867,10 @@ void remove_ap_array_cb(struct uloop_timeout* t) {
|
|||
// TODO: Move mutex handling to (new) remove_??? function to make test harness simpler?
|
||||
// Or not needed as test harness not threaded?
|
||||
void denied_req_array_cb(struct uloop_timeout* t) {
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
pthread_mutex_lock(&denied_array_mutex);
|
||||
#ifndef DAWN_NO_OUTPUT
|
||||
printf("[ULOOP] : Processing denied authentication!\n");
|
||||
#endif
|
||||
dawnlog_debug("[ULOOP] : Processing denied authentication!\n");
|
||||
|
||||
remove_old_denied_req_entries(time(0), timeout_config.denied_req_threshold, true);
|
||||
|
||||
|
@ -1765,6 +1881,8 @@ void denied_req_array_cb(struct uloop_timeout* t) {
|
|||
int send_add_mac(struct dawn_mac client_addr) {
|
||||
struct blob_buf b = {0};
|
||||
|
||||
dawnlog_debug_func("Entering...");
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
blobmsg_add_macaddr(&b, "addr", client_addr);
|
||||
send_blob_attr_via_network(b.head, "addmac");
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
|
@ -20,3 +25,106 @@ int string_is_greater(char *str, char *str_2) {
|
|||
}
|
||||
return length_1 > length_2;
|
||||
}
|
||||
|
||||
// Size implied by https://man7.org/linux/man-pages/man3/strerror.3.html
|
||||
char dawnlog_pbuf[1024] = "NOT SET";
|
||||
|
||||
static int _logdest = DAWNLOG_DEST_SYSLOG; // Assume daemon, logging to syslog
|
||||
static int _logmin = DAWNLOG_ALWAYS; // Anything of lower priority is suppressed
|
||||
|
||||
void dawnlog_dest(int logdest)
|
||||
{
|
||||
_logdest = logdest;
|
||||
}
|
||||
|
||||
void dawnlog_minlevel(int level)
|
||||
{
|
||||
// Don't allow certain prioriites to be suppressed
|
||||
if (level < DAWNLOG_ALWAYS)
|
||||
{
|
||||
_logmin = level;
|
||||
}
|
||||
}
|
||||
|
||||
int dawnlog_showing(int level)
|
||||
{
|
||||
return(level >= _logmin);
|
||||
}
|
||||
|
||||
void dawnlog(int level, const char* fmt, ...)
|
||||
{
|
||||
|
||||
if ((level & DAWNLOG_PRIMASK) >= _logmin)
|
||||
{
|
||||
// Attempt to replicate what perror() does...
|
||||
// dawnlog_buf is already referenced by macro expanded format string, so set it to a value
|
||||
if ((level & DAWNLOG_PERROR) == DAWNLOG_PERROR)
|
||||
{
|
||||
strerror_r(errno, dawnlog_pbuf, 1024);
|
||||
}
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
int sl = LOG_NOTICE; // Should always be mapped to a different value
|
||||
char *iotag = "default: ";
|
||||
|
||||
switch (level)
|
||||
{
|
||||
case DAWNLOG_ERROR:
|
||||
sl = LOG_ERR;
|
||||
iotag = "error: ";
|
||||
break;
|
||||
case DAWNLOG_WARNING:
|
||||
sl = LOG_WARNING;
|
||||
iotag = "warning: ";
|
||||
break;
|
||||
case DAWNLOG_ALWAYS:
|
||||
sl = LOG_INFO;
|
||||
iotag = "info: ";
|
||||
break;
|
||||
case DAWNLOG_INFO:
|
||||
sl = LOG_INFO;
|
||||
iotag = "info: ";
|
||||
break;
|
||||
case DAWNLOG_TRACE:
|
||||
sl = LOG_DEBUG;
|
||||
iotag = "trace: ";
|
||||
break;
|
||||
case DAWNLOG_DEBUG:
|
||||
sl = LOG_DEBUG;
|
||||
iotag = "debug: ";
|
||||
break;
|
||||
}
|
||||
|
||||
if (_logdest == DAWNLOG_DEST_SYSLOG)
|
||||
{
|
||||
vsyslog(sl, fmt, ap);
|
||||
}
|
||||
else
|
||||
{
|
||||
int l = strlen(fmt);
|
||||
if (l)
|
||||
{
|
||||
FILE* f = (level == DAWNLOG_ERROR || level == DAWNLOG_WARNING) ? stderr : stdout;
|
||||
|
||||
fprintf(f, "%s", iotag);
|
||||
vfprintf(f, fmt, ap);
|
||||
|
||||
// Messages created for syslog() may not have a closing newline, so add one if using stdio
|
||||
if (fmt[l - 1] != '\n')
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return pointer to filename part of full path */
|
||||
const char* dawnlog_basename(const char* file)
|
||||
{
|
||||
char* xfile = strrchr(file, '/');
|
||||
|
||||
return(xfile ? xfile + 1 : file);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue