[Listener] Use verbose levels

This commit is contained in:
Matteo Cypriani 2011-07-24 18:32:06 +02:00
parent a62387e465
commit f71a56bb9a
2 changed files with 58 additions and 48 deletions

View File

@ -64,6 +64,13 @@ enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ;
#define DEFAULT_AUTOCALIBRATION_NBPKT 20
/* Verbosity levels */
#define VERBOSE_QUIET GET_VERBOSE() == 0
#define VERBOSE_WARNING GET_VERBOSE() >= 1
#define VERBOSE_INFO GET_VERBOSE() >= 2
#define VERBOSE_CHATTERBOX GET_VERBOSE() >= 3
/* Error codes */
#define ERR_OPENING_IFACE 2 // Error when opening capture interface
#define ERR_BAD_USAGE 3 // Bad program call

View File

@ -132,10 +132,13 @@ int main(int argc, char *argv[])
sigaction(SIGTERM, &action, NULL) ;
get_mac_addr(GET_WIFI_IFACE(), my_mac_bytes) ;
printf("My MAC address is: %s\n",
owl_mac_bytes_to_string(my_mac_bytes)) ;
get_ip_addr(GET_WIFI_IFACE(), my_ip) ;
printf("My IP address is: %s\n", my_ip) ;
if (VERBOSE_INFO)
{
printf("My MAC address is: %s\n",
owl_mac_bytes_to_string(my_mac_bytes)) ;
printf("My IP address is: %s\n", my_ip) ;
}
#ifdef USE_PTHREAD
/* Set up threads */
@ -180,10 +183,11 @@ int main(int argc, char *argv[])
#ifdef USE_PTHREAD
if (GET_KEEP_MONITOR())
{
fprintf(stderr, "Waiting for the keep mode monitor thread... ") ;
if (VERBOSE_WARNING)
fprintf(stderr, "Waiting for the keep mode monitor thread... ") ;
if (pthread_join(keep_monitor_thread, NULL) != 0)
perror("Cannot join keep mode monitor thread") ;
else
else if (VERBOSE_WARNING)
fprintf(stderr, "OK.\n") ;
}
@ -191,34 +195,36 @@ int main(int argc, char *argv[])
{
// We must cancel this thread because it can be blocked on the
// recvfrom() call:
fprintf(stderr,
"Cancelling the autocalibration thread... ") ;
if (VERBOSE_WARNING)
fprintf(stderr, "Cancelling the autocalibration thread... ") ;
if (pthread_cancel(autocalibration_thread) != 0)
perror("Cannot cancel autocalibration thread") ;
else
else if (VERBOSE_WARNING)
fprintf(stderr, "OK.\n") ;
fprintf(stderr,
"Waiting for the autocalibration thread... ") ;
if (VERBOSE_WARNING)
fprintf(stderr, "Waiting for the autocalibration thread... ") ;
if (pthread_join(autocalibration_thread, NULL) != 0)
perror("Cannot join autocalibration thread") ;
else
else if (VERBOSE_WARNING)
fprintf(stderr, "OK.\n") ;
// We must cancel this thread if we do not want to wait
// autocalibration_hello_delay seconds (in the worst case):
fprintf(stderr,
"Cancelling the autocalibration hello thread... ") ;
if (VERBOSE_WARNING)
fprintf(stderr,
"Cancelling the autocalibration hello thread... ") ;
if (pthread_cancel(autocalibration_hello_thread) != 0)
perror("Cannot cancel autocalibration hello thread") ;
else
else if (VERBOSE_WARNING)
fprintf(stderr, "OK.\n") ;
fprintf(stderr,
"Waiting for the autocalibration hello thread... ") ;
if (VERBOSE_WARNING)
fprintf(stderr,
"Waiting for the autocalibration hello thread... ") ;
if (pthread_join(autocalibration_hello_thread, NULL) != 0)
perror("Cannot join autocalibration hello thread") ;
else
else if (VERBOSE_WARNING)
fprintf(stderr, "OK.\n") ;
}
#else // USE_PTHREAD
@ -244,9 +250,8 @@ void initialise_configuration(int argc, char **argv)
parse_command_line(argc, argv) ;
check_configuration() ;
#ifdef DEBUG
print_configuration() ;
#endif // DEBUG
if (VERBOSE_INFO)
print_configuration() ;
}
@ -540,7 +545,7 @@ void check_configuration()
if (GET_WIFI_IFACE()[0] == '\0')
{
if (GET_VERBOSE())
if (VERBOSE_WARNING)
fprintf(stderr, "No Wi-Fi interface was specified. Failing back"
" to the radiotap interface (%s) instead.\n",
GET_RTAP_IFACE()) ;
@ -550,14 +555,14 @@ void check_configuration()
// Port numbers //
if (GET_AGGREGATION_PORT() < 1 || GET_AGGREGATION_PORT() > 65535)
{
if (GET_VERBOSE())
if (VERBOSE_WARNING)
fprintf(stderr, "Warning! Bad aggregation_port:"
" failing back to the default value.\n") ;
SET_AGGREGATION_PORT(AGGREGATE_DEFAULT_PORT) ;
}
if (GET_LISTENING_PORT() < 1 || GET_LISTENING_PORT() > 65535)
{
if (GET_VERBOSE())
if (VERBOSE_WARNING)
fprintf(stderr, "Warning! Bad listening_port:"
" failing back to the default value.\n") ;
SET_LISTENING_PORT(LOC_REQUEST_DEFAULT_PORT) ;
@ -569,7 +574,7 @@ void check_configuration()
{
if (GET_AUTOCALIBRATION_IP()[0] == '\0')
{
if (GET_VERBOSE())
if (VERBOSE_WARNING)
fprintf(stderr, "No autocalibration IP specified, we will"
" use the aggregation IP as the destination of"
" autocalibration requests.\n") ;
@ -590,7 +595,7 @@ void check_configuration()
if (GET_AUTOCALIBRATION_REQUEST_PORT() < 1 ||
GET_AUTOCALIBRATION_REQUEST_PORT() > 65535)
{
if (GET_VERBOSE())
if (VERBOSE_WARNING)
fprintf(stderr, "Warning! Bad autocalibration_request_port:"
" failing back to the default value.\n") ;
SET_AUTOCALIBRATION_REQUEST_PORT(DEFAULT_AUTOCALIBRATION_REQUEST_PORT) ;
@ -598,7 +603,7 @@ void check_configuration()
if (GET_AUTOCALIBRATION_PORT() < 1 ||
GET_AUTOCALIBRATION_PORT() > 65535)
{
if (GET_VERBOSE())
if (VERBOSE_WARNING)
fprintf(stderr, "Warning! Bad autocalibration_port:"
" failing back to the default value.\n") ;
SET_AUTOCALIBRATION_PORT(DEFAULT_AUTOCALIBRATION_PORT) ;
@ -609,7 +614,6 @@ void check_configuration()
#ifdef DEBUG
void print_configuration()
{
fprintf(stderr, "Configuration:\n") ;
@ -665,7 +669,6 @@ void print_configuration()
) ;
#endif // USE_CONFIG_FILE
}
#endif // DEBUG
@ -676,7 +679,7 @@ void print_configuration()
*/
void* keep_mode_monitor(void *iface)
{
if (GET_VERBOSE())
if (VERBOSE_WARNING)
fprintf(stderr, "Thread for keeping monitor mode launched.\n") ;
while (owl_run)
@ -871,10 +874,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
// Get 802.11 flags from the 802.11 header:
raw_packet_flags = packet[rtap_bytes+1] ;
#ifdef DEBUG
if (IS_RETRY(raw_packet_flags))
if (IS_RETRY(raw_packet_flags) && VERBOSE_CHATTERBOX)
printf("This packet is a Retry.\n") ;
#endif // DEBUG
// Source MAC address is 10 bytes after the 802.11 packet type:
memcpy(request.mobile_mac_addr_bytes, &packet[rtap_bytes+10],
@ -901,12 +902,12 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
switch(request.type)
{
case OWL_REQUEST_NORMAL :
if (GET_VERBOSE())
if (VERBOSE_INFO)
printf("\nExplicit packet received.\n") ;
break ;
case OWL_REQUEST_CALIBRATION :
if (GET_VERBOSE())
if (VERBOSE_INFO)
printf("\nExplicit calibration packet received.\n") ;
request.direction =
packet[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE
@ -926,7 +927,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
break ;
case OWL_REQUEST_AUTOCALIBRATION :
if (GET_VERBOSE())
if (VERBOSE_INFO)
{
printf("\nAutocalibration packet received.") ;
if (! uses_autocalibration_request_port)
@ -951,7 +952,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
break ;
default :
if (GET_VERBOSE())
if (VERBOSE_INFO)
printf("\nStrange explicit packet received\n") ;
fprintf(stderr,
"Error! Unknown request type (%d).\n", request.type) ;
@ -964,7 +965,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
return ;
else
{
if (GET_VERBOSE())
if (VERBOSE_INFO)
printf("\nThis strange explicit packet will be handled"
" as an implicit one.\n") ;
request.type = OWL_REQUEST_IMPLICIT ;
@ -982,7 +983,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
else if (GET_MODE() == MODE_PASSIVE || GET_MODE() == MODE_MIXED)
{
if (GET_VERBOSE())
if (VERBOSE_CHATTERBOX)
printf("\nImplicit packet received.\n") ;
request.type = OWL_REQUEST_IMPLICIT ;
}
@ -1035,7 +1036,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
memcpy(&(request.antenna_signal_dbm),
&packet[rtap_position], RTAP_L_ANTENNASIGNALDBM) ;
check[RTAP_ANTENNASIGNALDBM] = TRUE;
if (GET_VERBOSE())
if (VERBOSE_INFO)
printf("Antenna signal: %d dBm\n",
request.antenna_signal_dbm - 0x100);
rtap_position += RTAP_L_ANTENNASIGNALDBM ;
@ -1197,7 +1198,7 @@ void* autocalibrate_hello(void *NULL_value)
struct sockaddr_in serv;
owl_autocalibration_hello message ;
if (GET_VERBOSE())
if (VERBOSE_WARNING)
fprintf(stderr, "Autocalibration Hello thread launched.\n") ;
send_sockfd =
@ -1231,7 +1232,7 @@ void* autocalibrate(void *NULL_value)
int listen_sockfd ;
owl_autocalibration_order message ;
if (GET_VERBOSE())
if (VERBOSE_WARNING)
fprintf(stderr, "Autocalibration thread launched.\n") ;
// Socket to send autocalibration positioning requests
@ -1266,7 +1267,7 @@ void* autocalibrate(void *NULL_value)
if (message.order == AUTOCALIBRATION_ORDER_SEND)
{
if (GET_VERBOSE())
if (VERBOSE_INFO)
fprintf(stderr, "I was just ordered to send an"
" autocalibration request...\n") ;
send_autocalibration_request() ;
@ -1318,7 +1319,7 @@ uint_fast16_t make_packet(uint8_t **packet)
owl_timestamp_now(&request_time) ;
if (GET_VERBOSE())
if (VERBOSE_CHATTERBOX)
{
char request_time_str[OWL_TIMESTAMP_STR_LEN] ;
owl_timestamp_to_string(request_time_str, request_time) ;
@ -1381,7 +1382,7 @@ void print_usage()
printf("Usage :\n"
"\t%s [-f config_file] [-m mode] [-d aggregation_ip]"
" [-l listening_port] [-p aggregation_port] -r rtap_iface"
" [-w wifi_iface] [-k] [-v | -q] [-c | -Q] [-A]"
" [-w wifi_iface] [-k] [-v[v[v]] | -q] [-c | -Q] [-A]"
" [-D autocalibration_ip]"
" [-P autocalibration_request_port ] [-a autocalibration_port]"
" [-H autocalibration_hello_delay] [-t autocalibration_delay]"
@ -1434,10 +1435,12 @@ void print_usage()
" drivers that disable monitor mode periodically. Available"
" only if the program was compiled with support of POSIX"
" threads.\n"
"\t-v\tVerbose mode (display what we do).\n"
"\t-q\tQuiet mode (default).\n"
"\t-c\tDisplay captured packets.\n"
"\t-Q\tDo not display captured packets (default).\n"
"\t-v\tBe verbose. You can use this option up to 3 times to"
" increase the level of verbosity (1 = warnings, 2 = useful"
" information, 3 = a lot of information.\n"
"\t-q\tQuiet mode (default): sets the verbose level to 0.\n"
"\t-c\tDisplay the captured packets.\n"
"\t-Q\tDo not display the captured packets (default).\n"
,
program_name,
program_name,