[Listener] Option ENABLE_KEEP_MONITOR

Add the compile-time option ENABLE_KEEP_MONITOR to enable/disable the
option -K. That allows to make optional the dependency on iwlib.
This option is disabled by default in the Makefiles.
This commit is contained in:
Matteo Cypriani 2011-12-20 10:43:40 +01:00
parent 8c070d482e
commit 5ffeafb857
5 changed files with 66 additions and 37 deletions

View File

@ -34,12 +34,13 @@ DEPFLAGS = -MMD
XCFLAGS = $(CFLAGS) $(DEPFLAGS) $(WARN) $(HEADERS)
PICFLAG = -fPIC
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\"
OWLPSFLAGS += -D USE_PTHREAD -pthread
OWLPSFLAGS += -D USE_CONFIG_FILE -lconfuse
OWLPSFLAGS += -D USE_PTHREAD -pthread
#OWLPSFLAGS += -D ENABLE_KEEP_MONITOR -liw
#OWLPSFLAGS += -D NDEBUG
LIBS = -L$(LIBOWLPS_DIR) -lowlps \
-L$(LIBOWLPSCLIENT_DIR) -lowlps-client \
-lpcap -liw
-lpcap
OS := $(shell uname)
ifeq ("$(OS)", "Linux")
@ -89,6 +90,7 @@ purge : clean
help :
@echo "Needed libraries:"
@echo " libpcap0.8-dev"
@echo " libiw-dev (optionnal)"
@echo " libconfuse-dev (optionnal)"
@echo " libowlps-dev"
@echo

View File

@ -39,7 +39,7 @@ PICFLAG = -fPIC
LOWLPS = -L$(LIBOWLPS_DIR) -lowlps
LOWLPSA = $(LIBOWLPS_DIR)/libowlps.a
LOWLPSCLIENTA = $(LIBOWLPSCLIENT_DIR)/libowlps-client.a
LIBS = -lpcap -liw -lm -lrt $(LOWLPSCLIENTA)
LIBS = -lpcap -lm -lrt $(LOWLPSCLIENTA)
DYNAMIC_LIBS = $(TOOLCHAIN1)/lib/ld-uClibc.so.0
SEMISTATIC_LIBS = $(DYNAMIC_LIBS)
STATIC_LIBS =
@ -48,8 +48,9 @@ LATHEROS = -L$(TOOLCHAIN1)/lib -L$(TOOLCHAIN1)/usr/lib \
#-L$(TOOLCHAIN2)/root-atheros/lib
IATHEROS = -I$(TOOLCHAIN1)/usr/include -I$(TOOLCHAIN2)/usr/include
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\"
OWLPSFLAGS += -D USE_PTHREAD -pthread
OWLPSFLAGS += -D USE_CONFIG_FILE -lconfuse
OWLPSFLAGS += -D USE_PTHREAD -pthread
#OWLPSFLAGS += -D ENABLE_KEEP_MONITOR -liw
#OWLPSFLAGS += -D NDEBUG
LDFLAGS = $(OWLPSFLAGS) $(LIBS)

View File

@ -39,13 +39,14 @@ PICFLAG = -fPIC
LOWLPS = -L$(LIBOWLPS_DIR) -lowlps
LOWLPSA = $(LIBOWLPS_DIR)/libowlps.a
LOWLPSCLIENTA = $(LIBOWLPSCLIENT_DIR)/libowlps-client.a
LIBS = -lpcap -liw -lrt $(LOWLPSCLIENTA)
LIBS = -lpcap -lrt $(LOWLPSCLIENTA)
STATIC_LIBS = -lm
LATHEROS = -L$(TOOLCHAIN_USR)/lib -L$(TOOLCHAIN_USR_2)/lib
IATHEROS = -I$(TOOLCHAIN_USR)/include -I$(TOOLCHAIN_USR_2)/include
OWLPSFLAGS = -D OWLPS_VERSION=\"$(OWLPS_VERSION)\"
OWLPSFLAGS += -D USE_PTHREAD -pthread
#OWLPSFLAGS += -D USE_CONFIG_FILE -lconfuse
OWLPSFLAGS += -D USE_PTHREAD -pthread
#OWLPSFLAGS += -D ENABLE_KEEP_MONITOR -liw
#OWLPSFLAGS += -D NDEBUG
LDFLAGS = $(OWLPSFLAGS) $(LIBS)

View File

@ -10,9 +10,15 @@
*/
//#define USE_CONFIG_FILE // Use libconfuse to read a config file
//#define USE_PTHREAD // POSIX threads available?
//#define ENABLE_KEEP_MONITOR // Enable the -K option (requires USE_PTHREAD)
#define DEBUG
#ifdef ENABLE_KEEP_MONITOR
# ifndef USE_PTHREAD
# error "The option ENABLE_KEEP_MONITOR requires the option USE_PTHREAD"
# endif // USE_PTHREAD
#endif // ENABLE_KEEP_MONITOR
#include <owlps.h>
#include <owlps-client.h>
@ -168,10 +174,10 @@ int check_configuration(void) ;
void print_configuration(void) ;
#endif // DEBUG
#ifdef USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
void* keep_mode_monitor(void *iface) ;
int iface_mode_monitor(const char *const iface) ;
#endif // USE_PTHREAD
#endif // ENABLE_KEEP_MONITOR
int capture(void) ;
void read_packet(u_char *args, const struct pcap_pkthdr *header,
const u_char *packet) ;
@ -211,12 +217,12 @@ void print_version(void) ;
(cfg_setstr(cfg, "aggregation_ip", (IP)))
#define GET_AGGREGATION_IP() \
(cfg_getstr(cfg, "aggregation_ip"))
#ifdef USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
#define SET_KEEP_MONITOR() \
(cfg_setbool(cfg, "keep_monitor", cfg_true))
#define GET_KEEP_MONITOR() \
(cfg_getbool(cfg, "keep_monitor"))
#endif // USE_PTHREAD
#endif // ENABLE_KEEP_MONITOR
#define SET_AGGREGATION_PORT(PORT) \
(cfg_setint(cfg, "aggregation_port", (PORT)))
#define GET_AGGREGATION_PORT() \
@ -298,12 +304,12 @@ void print_version(void) ;
(strncpy(options.aggregation_ip, (IP), INET_ADDRSTRLEN))
#define GET_AGGREGATION_IP() \
(options.aggregation_ip)
#ifdef USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
#define SET_KEEP_MONITOR() \
(options.keep_monitor = owl_true)
#define GET_KEEP_MONITOR() \
(options.keep_monitor)
#endif // USE_PTHREAD
#endif // ENABLE_KEEP_MONITOR
#define SET_AGGREGATION_PORT(PORT) \
(options.aggregation_port = (PORT))
#define GET_AGGREGATION_PORT() \

View File

@ -23,9 +23,12 @@
#ifdef USE_PTHREAD
# include <pthread.h>
# include <iwlib.h>
#endif // USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
# include <iwlib.h>
#endif // ENABLE_KEEP_MONITOR
// Used by get_mac_addr():
#include <netinet/udp.h>
#include <netinet/ip.h>
@ -61,9 +64,9 @@ struct {
char aggregation_ip[INET_ADDRSTRLEN] ;
uint_fast16_t aggregation_port ;
uint_fast16_t listening_port ;
#ifdef USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
owl_bool keep_monitor ;
#endif // USE_PTHREAD
#endif // ENABLE_KEEP_MONITOR
char rtap_iface[IFNAMSIZ + 1] ;
char wifi_iface[IFNAMSIZ + 1] ;
#ifdef USE_PTHREAD
@ -85,9 +88,9 @@ struct {
"127.0.0.1",
OWL_DEFAULT_LISTENER_PORT,
OWL_DEFAULT_REQUEST_PORT,
#ifdef USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
owl_false,
#endif // USE_PTHREAD
#endif // ENABLE_KEEP_MONITOR
"",
"",
#ifdef USE_PTHREAD
@ -112,10 +115,12 @@ int main(int argc, char *argv[])
int ret ; // Program return value
#ifdef USE_PTHREAD
pthread_t
keep_monitor_thread,
autocalibration_thread,
autocalibration_hello_thread ;
#endif // USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
pthread_t keep_monitor_thread ;
#endif // ENABLE_KEEP_MONITOR
owl_run = owl_true ;
@ -142,6 +147,7 @@ int main(int argc, char *argv[])
#ifdef USE_PTHREAD
/* Set up threads */
# ifdef ENABLE_KEEP_MONITOR
if (GET_KEEP_MONITOR())
{
ret = pthread_create(&keep_monitor_thread, NULL,
@ -153,6 +159,7 @@ int main(int argc, char *argv[])
goto exit ;
}
}
# endif // ENABLE_KEEP_MONITOR
if (GET_AUTOCALIBRATION())
{
@ -181,6 +188,7 @@ int main(int argc, char *argv[])
/* Wait for the threads to terminate */
#ifdef USE_PTHREAD
# ifdef ENABLE_KEEP_MONITOR
if (GET_KEEP_MONITOR())
{
if (VERBOSE_WARNING)
@ -190,6 +198,7 @@ int main(int argc, char *argv[])
else if (VERBOSE_WARNING)
fprintf(stderr, "OK.\n") ;
}
# endif // ENABLE_KEEP_MONITOR
if (GET_AUTOCALIBRATION())
{
@ -290,11 +299,11 @@ int parse_config_file(int argc, char **argv)
CFG_INT("aggregation_port", OWL_DEFAULT_LISTENER_PORT, CFGF_NONE),
// Port on which mobiles send active requests:
CFG_INT("listening_port", OWL_DEFAULT_REQUEST_PORT, CFGF_NONE),
#ifdef USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
// Activate the active monitor mode keeping-up (read the code if
// you do not understand what I mean):
CFG_BOOL("keep_monitor", cfg_false, CFGF_NONE),
#endif // USE_PTHREAD
#endif // ENABLE_KEEP_MONITOR
// Radiotap interface, used to capture:
CFG_STR("rtap_iface", "", CFGF_NONE),
// Physical interface corresponding to the radiotap interface (used
@ -463,14 +472,13 @@ int parse_main_options(int argc, char **argv)
#endif // USE_PTHREAD
break ;
case 'K' :
#ifdef USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
SET_KEEP_MONITOR() ;
#else // USE_PTHREAD
#else // ENABLE_KEEP_MONITOR
fprintf(stderr, "Warning! The program was compiled without"
" support of POSIX threads, so -K (monitor mode"
" keeping-up) is not available and will be ignored."
"\n") ;
#endif // USE_PTHREAD
" enabling the -K option (monitor mode keeping-up)."
".\n") ;
#endif // ENABLE_KEEP_MONITOR
break ;
case 'l' :
SET_LISTENING_PORT(strtol(optarg, NULL, 0)) ;
@ -658,8 +666,10 @@ void print_configuration()
"listening_port = %"PRIuFAST16"\n"
"rtap_iface = \"%s\"\n"
"wifi_iface = \"%s\"\n"
#ifdef USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
"keep_monitor = %s\n"
#endif // ENABLE_KEEP_MONITOR
#ifdef USE_PTHREAD
"autocalibration = %s\n"
"autocalibration_ip = \"%s\"\n"
"autocalibration_request_port = %"PRIuFAST16"\n"
@ -680,8 +690,10 @@ void print_configuration()
GET_LISTENING_PORT(),
GET_RTAP_IFACE(),
GET_WIFI_IFACE(),
#ifdef USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
OWL_BOOL_TO_STRING(GET_KEEP_MONITOR()),
#endif // ENABLE_KEEP_MONITOR
#ifdef USE_PTHREAD
OWL_BOOL_TO_STRING(GET_AUTOCALIBRATION()),
GET_AUTOCALIBRATION_IP(),
GET_AUTOCALIBRATION_REQUEST_PORT(),
@ -694,14 +706,14 @@ void print_configuration()
GET_MY_POSITION_Y(),
GET_MY_POSITION_Z(),
#endif // USE_PTHREAD
OWL_BOOL_TO_STRING(GET_VERBOSE()),
OWL_BOOL_TO_STRING(GET_VERBOSE())
) ;
#endif // USE_CONFIG_FILE
}
#ifdef USE_PTHREAD
#ifdef ENABLE_KEEP_MONITOR
/*
* Thread function. Switches interface 'iface' to monitor mode every
* second.
@ -754,7 +766,7 @@ int iface_mode_monitor(const char *const iface)
return 0 ;
}
#endif // USE_PTHREAD
#endif // ENABLE_KEEP_MONITOR
@ -1498,8 +1510,8 @@ void print_usage()
"Other options:\n"
"\t-K\tKeep the monitor mode up on wifi_iface. Use it with buggy"
" drivers that disable monitor mode periodically. Available"
" only if the program was compiled with support of POSIX"
" threads.\n"
" only if the program was compiled with the option"
" ENABLE_KEEP_MONITOR.\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, 4 = display each"
@ -1527,24 +1539,31 @@ void print_version()
" System project.\n"
"Version: %s.\n"
"Compilation-time options:\n"
"\tSupport for configuration file (libconfuse): %s.\n"
"\tSupport for POSIX threads: %s.\n"
"\tSupport for configuration file (libconfuse): %s.\n",
"\tOption -K: %s.\n",
#ifdef OWLPS_VERSION
OWLPS_VERSION
#else // OWLPS_VERSION
"unknown version"
#endif // OWLPS_VERSION
,
#ifdef USE_CONFIG_FILE
"YES"
#else // USE_CONFIG_FILE
"NO"
#endif // USE_CONFIG_FILE
,
#ifdef USE_PTHREAD
"YES"
#else // USE_PTHREAD
"NO"
#endif // USE_PTHREAD
,
#ifdef USE_CONFIG_FILE
#ifdef ENABLE_KEEP_MONITOR
"YES"
#else // USE_CONFIG_FILE
#else // ENABLE_KEEP_MONITOR
"NO"
#endif // USE_CONFIG_FILE
#endif // ENABLE_KEEP_MONITOR
) ;
}