CMake: handle Listener's options
This commit is contained in:
parent
93adfdc55c
commit
dad2e543d1
2
TODO.t2t
2
TODO.t2t
|
@ -61,8 +61,6 @@ Work to do in OwlPS
|
|||
- compilation flags
|
||||
- installation targets
|
||||
- static targets
|
||||
- Listener: handle options (USE_CONFIG_FILE, USE_PTHREAD,
|
||||
ENABLE_KEEP_MONITOR@
|
||||
- compile Positioner
|
||||
|
||||
- Support string-based positioning requests
|
||||
|
|
|
@ -1,5 +1,37 @@
|
|||
### Options ###
|
||||
|
||||
option(OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
"Enable support for configuration files"
|
||||
on)
|
||||
|
||||
option(OWLPS_LISTENER_USES_PTHREAD
|
||||
"Enable support for POSIX threads (mandatory for the autocalibration)"
|
||||
on)
|
||||
|
||||
option(OWLPS_LISTENER_KEEPS_MONITOR
|
||||
"Enable -K (keep monitor mode on); requires POSIX threads support"
|
||||
off)
|
||||
|
||||
configure_file(
|
||||
owlps-listener-config.h.in
|
||||
"${GENERATED_INCLUDE}/owlps-listener-config.h")
|
||||
|
||||
|
||||
### Linked libraries ###
|
||||
|
||||
set(EXTRA_LIBS ${EXTRA_LIBS} pcap)
|
||||
|
||||
if (OWLPS_LISTENER_USES_CONFIG_FILE)
|
||||
set(EXTRA_LIBS ${EXTRA_LIBS} confuse)
|
||||
endif()
|
||||
|
||||
if (OWLPS_LISTENER_USES_PTHREAD)
|
||||
set(EXTRA_LIBS ${EXTRA_LIBS} pthread)
|
||||
endif()
|
||||
|
||||
|
||||
### Targets ###
|
||||
|
||||
add_executable(owlps-listenerd owlps-listenerd.c)
|
||||
target_link_libraries(owlps-listenerd
|
||||
libowlps.so
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* This file is part of the Owl Positioning System (OwlPS).
|
||||
*
|
||||
* Copyright © 2013 Matteo Cypriani <mcy@lm7.fr>
|
||||
*
|
||||
***********************************************************************
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL:
|
||||
* http://www.cecill.info
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided
|
||||
* only with a limited warranty and the software's authors, the holder
|
||||
* of the economic rights, and the successive licensors have only
|
||||
* limited liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks
|
||||
* associated with loading, using, modifying and/or developing or
|
||||
* reproducing the software by the user in light of its specific status
|
||||
* of free software, that may mean that it is complicated to manipulate,
|
||||
* and that also therefore means that it is reserved for developers and
|
||||
* experienced professionals having in-depth computer knowledge. Users
|
||||
* are therefore encouraged to load and test the software's suitability
|
||||
* as regards their requirements in conditions enabling the security of
|
||||
* their systems and/or data to be ensured and, more generally, to use
|
||||
* and operate it in the same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*
|
||||
***********************************************************************
|
||||
*
|
||||
* This is the configuration header file for OwlPS Listener.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _OWLPS_LISTENER_CONFIG_H_
|
||||
#define _OWLPS_LISTENER_CONFIG_H_
|
||||
|
||||
// Use libconfuse to read a config file
|
||||
#cmakedefine OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
|
||||
// POSIX threads available? (mandatory for autocalibration and -K)
|
||||
#cmakedefine OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
// Enable the -K option
|
||||
#cmakedefine OWLPS_LISTENER_KEEPS_MONITOR
|
||||
|
||||
#endif // _OWLPS_LISTENER_CONFIG_H_
|
|
@ -44,18 +44,13 @@
|
|||
#ifndef _OWLPS_LISTENER_H_
|
||||
#define _OWLPS_LISTENER_H_
|
||||
|
||||
/* Compilation-time options: to activate, uncomment or compile with -D
|
||||
* option.
|
||||
*/
|
||||
//#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)
|
||||
#include <owlps-listener-config.h>
|
||||
|
||||
#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
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
# ifndef OWLPS_LISTENER_USES_PTHREAD
|
||||
# error "The option OWLPS_LISTENER_KEEPS_MONITOR requires the option OWLPS_LISTENER_USES_PTHREAD"
|
||||
# endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
|
||||
#include <owlps.h>
|
||||
#include <owlps-client.h>
|
||||
|
@ -199,16 +194,16 @@ int initialise_configuration(int argc, char **argv) ;
|
|||
int parse_config_file(int argc, char **argv) ;
|
||||
int parse_command_line(int argc, char **argv) ;
|
||||
int parse_main_options(int argc, char **argv) ;
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
int parse_calibration_data(int argc, char **argv) ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
int check_configuration(void) ;
|
||||
void print_configuration(void) ;
|
||||
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
void* keep_mode_monitor(void *iface) ;
|
||||
int iface_mode_monitor(const char *const iface) ;
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
int capture(void) ;
|
||||
void read_packet(const struct pcap_pkthdr *pkt_header,
|
||||
const u_char *pkt_data) ;
|
||||
|
@ -224,12 +219,12 @@ void display_captured_request(owl_captured_request *request,
|
|||
void get_mac_addr(char *eth, uint8_t mac_bytes[ETHER_ADDR_LEN]) ;
|
||||
void get_ip_addr(char *eth, char *ip_bytes) ;
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
void* autocalibrate(void *NULL_value) ;
|
||||
void* autocalibrate_hello(void *NULL_value) ;
|
||||
void send_autocalibration_request(void) ;
|
||||
uint_fast16_t make_packet(uint8_t **packet) ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
void sigint_handler(int num) ;
|
||||
void sigterm_handler(int num) ;
|
||||
|
@ -243,7 +238,7 @@ void print_version(void) ;
|
|||
* with libconfuse support).
|
||||
*/
|
||||
/* libconfuse macros */
|
||||
#ifdef USE_CONFIG_FILE
|
||||
#ifdef OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
#define SET_MODE(MODE) \
|
||||
(cfg_setint(cfg, "mode", (MODE)))
|
||||
#define GET_MODE() \
|
||||
|
@ -258,14 +253,14 @@ void print_version(void) ;
|
|||
(cfg_setstr(cfg, "aggregation_ip", (IP)))
|
||||
#define GET_AGGREGATION_IP() \
|
||||
(cfg_getstr(cfg, "aggregation_ip"))
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
#define SET_KEEP_MONITOR() \
|
||||
(cfg_setbool(cfg, "keep_monitor", cfg_true))
|
||||
#define UNSET_KEEP_MONITOR() \
|
||||
(cfg_setbool(cfg, "keep_monitor", cfg_false))
|
||||
#define GET_KEEP_MONITOR() \
|
||||
(cfg_getbool(cfg, "keep_monitor"))
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
#define SET_AGGREGATION_PORT(PORT) \
|
||||
(cfg_setint(cfg, "aggregation_port", (PORT)))
|
||||
#define GET_AGGREGATION_PORT() \
|
||||
|
@ -287,7 +282,7 @@ void print_version(void) ;
|
|||
#define GET_WIFI_IFACE() \
|
||||
(cfg_getstr(cfg, "wifi_iface"))
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
#define SET_AUTOCALIBRATION() \
|
||||
(cfg_setbool(cfg, "autocalibration", cfg_true))
|
||||
#define UNSET_AUTOCALIBRATION() \
|
||||
|
@ -338,7 +333,7 @@ void print_version(void) ;
|
|||
(cfg_setfloat(cfg, "my_position_z", (POSITION)))
|
||||
#define GET_MY_POSITION_Z() \
|
||||
(cfg_getfloat(cfg, "my_position_z"))
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
#define INCREMENT_VERBOSE() \
|
||||
(cfg_setint(cfg, "verbose", cfg_getint(cfg, "verbose") + 1))
|
||||
|
@ -348,7 +343,7 @@ void print_version(void) ;
|
|||
(cfg_getint(cfg, "verbose"))
|
||||
|
||||
/* Home-made structure macros */
|
||||
#else // USE_CONFIG_FILE
|
||||
#else // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
#define SET_DAEMON() \
|
||||
(options.daemon = true)
|
||||
#define UNSET_DAEMON() \
|
||||
|
@ -363,14 +358,14 @@ void print_version(void) ;
|
|||
(strncpy(options.aggregation_ip, (IP), INET_ADDRSTRLEN))
|
||||
#define GET_AGGREGATION_IP() \
|
||||
(options.aggregation_ip)
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
#define SET_KEEP_MONITOR() \
|
||||
(options.keep_monitor = true)
|
||||
#define UNSET_KEEP_MONITOR() \
|
||||
(options.keep_monitor = false)
|
||||
#define GET_KEEP_MONITOR() \
|
||||
(options.keep_monitor)
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
#define SET_AGGREGATION_PORT(PORT) \
|
||||
(options.aggregation_port = (PORT))
|
||||
#define GET_AGGREGATION_PORT() \
|
||||
|
@ -399,7 +394,7 @@ void print_version(void) ;
|
|||
#define GET_WIFI_IFACE() \
|
||||
(options.wifi_iface)
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
#define SET_AUTOCALIBRATION() \
|
||||
(options.autocalibration = true)
|
||||
#define UNSET_AUTOCALIBRATION() \
|
||||
|
@ -450,7 +445,7 @@ void print_version(void) ;
|
|||
(options.my_position_z = (POSITION))
|
||||
#define GET_MY_POSITION_Z() \
|
||||
(options.my_position_z)
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
#define INCREMENT_VERBOSE() \
|
||||
(++options.verbose)
|
||||
|
@ -458,7 +453,7 @@ void print_version(void) ;
|
|||
(options.verbose = 0)
|
||||
#define GET_VERBOSE() \
|
||||
(options.verbose)
|
||||
#endif // USE_CONFIG_FILE
|
||||
#endif // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
|
||||
|
||||
/* Returns true if we are capturing packet from a network interface, or
|
||||
|
|
|
@ -57,17 +57,17 @@
|
|||
#include <net/if.h>
|
||||
#include <net/ethernet.h>
|
||||
|
||||
#ifdef USE_CONFIG_FILE
|
||||
#ifdef OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
# include <confuse.h>
|
||||
#endif // USE_CONFIG_FILE
|
||||
#endif // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
# include <pthread.h>
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
# include <iwlib.h>
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
|
||||
// Used by get_mac_addr():
|
||||
#include <netinet/udp.h>
|
||||
|
@ -85,17 +85,17 @@ pcap_t *capture_handler = NULL ; // Packet capture descriptor
|
|||
int aggregation_sockfd ;
|
||||
struct sockaddr_in aggregation_server ;
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
int autocalibration_send_sockfd ;
|
||||
struct sockaddr_in autocalibration_send_server ;
|
||||
// true if the coordinates of the listener were provided by the user:
|
||||
bool coordinates_provided = false ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
#ifdef USE_CONFIG_FILE
|
||||
#ifdef OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
cfg_t *cfg = NULL ; // Configuration structure
|
||||
|
||||
#else // USE_CONFIG_FILE
|
||||
#else // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
/* If we do not use libconfuse, we declare a structure to store getopt
|
||||
* options.
|
||||
*/
|
||||
|
@ -105,13 +105,13 @@ struct {
|
|||
char aggregation_ip[INET_ADDRSTRLEN] ;
|
||||
uint_fast16_t aggregation_port ;
|
||||
uint_fast16_t listening_port ;
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
bool keep_monitor ;
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
char rtap_iface[IFNAMSIZ + 1] ;
|
||||
char *pcap_file ;
|
||||
char wifi_iface[IFNAMSIZ + 1] ;
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
bool autocalibration ;
|
||||
char autocalibration_ip[INET_ADDRSTRLEN] ;
|
||||
uint_fast16_t autocalibration_request_port ;
|
||||
|
@ -124,7 +124,7 @@ struct {
|
|||
float my_position_x ;
|
||||
float my_position_y ;
|
||||
float my_position_z ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
uint_fast8_t verbose ;
|
||||
} options = { // Initalise default options:
|
||||
false, // daemon
|
||||
|
@ -132,13 +132,13 @@ struct {
|
|||
"127.0.0.1", // aggregation_ip
|
||||
OWL_DEFAULT_LISTENER_PORT, // aggregation_port
|
||||
OWL_DEFAULT_REQUEST_PORT, // listening_port
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
false, // keep_monitor
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
"", // rtap_iface
|
||||
NULL, // pcap_file
|
||||
"", // wifi_iface
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
false, // autocalibration
|
||||
"", // autocalibration_ip
|
||||
0, // autocalibration_request_port
|
||||
|
@ -148,10 +148,10 @@ struct {
|
|||
DEFAULT_AUTOCALIBRATION_DELAY, // autocalibration_delay
|
||||
DEFAULT_AUTOCALIBRATION_NBPKT, // autocalibration_nb_packets
|
||||
0, 0, 0, 0, // Calibration data
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
0 // verbose
|
||||
} ;
|
||||
#endif // USE_CONFIG_FILE
|
||||
#endif // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
|
||||
|
||||
|
||||
|
@ -159,14 +159,14 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
struct sigaction action ; // Signal handler structure
|
||||
int ret ; // Program return value
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
pthread_t
|
||||
autocalibration_thread,
|
||||
autocalibration_hello_thread ;
|
||||
#endif // USE_PTHREAD
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
pthread_t keep_monitor_thread ;
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
|
||||
owl_run = true ;
|
||||
|
||||
|
@ -202,9 +202,9 @@ int main(int argc, char *argv[])
|
|||
my_ip) ;
|
||||
}
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
/* Set up threads */
|
||||
# ifdef ENABLE_KEEP_MONITOR
|
||||
# ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
if (GET_KEEP_MONITOR())
|
||||
{
|
||||
ret = pthread_create(&keep_monitor_thread, NULL,
|
||||
|
@ -216,7 +216,7 @@ int main(int argc, char *argv[])
|
|||
goto exit ;
|
||||
}
|
||||
}
|
||||
# endif // ENABLE_KEEP_MONITOR
|
||||
# endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
|
||||
if (GET_AUTOCALIBRATION())
|
||||
{
|
||||
|
@ -238,14 +238,14 @@ int main(int argc, char *argv[])
|
|||
goto exit ;
|
||||
}
|
||||
}
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
ret = capture() ; // Capture loop
|
||||
|
||||
/* Wait for the threads to terminate */
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
# ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
# ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
if (GET_KEEP_MONITOR())
|
||||
{
|
||||
if (VERBOSE_WARNING)
|
||||
|
@ -255,7 +255,7 @@ int main(int argc, char *argv[])
|
|||
else if (VERBOSE_WARNING)
|
||||
fprintf(stderr, "OK.\n") ;
|
||||
}
|
||||
# endif // ENABLE_KEEP_MONITOR
|
||||
# endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
|
||||
if (GET_AUTOCALIBRATION())
|
||||
{
|
||||
|
@ -293,16 +293,16 @@ int main(int argc, char *argv[])
|
|||
else if (VERBOSE_WARNING)
|
||||
fprintf(stderr, "OK.\n") ;
|
||||
}
|
||||
#else // USE_PTHREAD
|
||||
#else // OWLPS_LISTENER_USES_PTHREAD
|
||||
// Just to avoid a warning when compiling without threads' support:
|
||||
goto exit ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
/* Last cleaning tasks */
|
||||
exit:
|
||||
#ifdef USE_CONFIG_FILE
|
||||
#ifdef OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
cfg_free(cfg) ; // Clean configuration
|
||||
#endif // USE_CONFIG_FILE
|
||||
#endif // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
|
||||
printf("%s: end.\n", program_name) ;
|
||||
return ret ;
|
||||
|
@ -343,7 +343,7 @@ int initialise_configuration(int argc, char **argv)
|
|||
|
||||
int parse_config_file(int argc, char **argv)
|
||||
{
|
||||
#ifdef USE_CONFIG_FILE
|
||||
#ifdef OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
// If we use libconfuse, we declare options:
|
||||
cfg_opt_t opts[] =
|
||||
{
|
||||
|
@ -358,11 +358,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 ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_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 // ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
// Radiotap interface to capture from:
|
||||
CFG_STR("rtap_iface", "", CFGF_NONE),
|
||||
// Pcap file to read packets from:
|
||||
|
@ -370,7 +370,7 @@ int parse_config_file(int argc, char **argv)
|
|||
// Physical interface corresponding to the radiotap interface (used
|
||||
// to get the MAC address):
|
||||
CFG_STR("wifi_iface", "", CFGF_NONE),
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
// Autocalibration activated?
|
||||
CFG_BOOL("autocalibration", cfg_false, CFGF_NONE),
|
||||
// Destination IP address of the autocalibration requests (default:
|
||||
|
@ -403,14 +403,14 @@ int parse_config_file(int argc, char **argv)
|
|||
CFG_FLOAT("my_position_y", 0, CFGF_NONE),
|
||||
// Position Z
|
||||
CFG_FLOAT("my_position_z", 0, CFGF_NONE),
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
// Verbose level:
|
||||
CFG_INT("verbose", 0, CFGF_NONE),
|
||||
CFG_END()
|
||||
} ;
|
||||
|
||||
char *config_file = NULL ; // Configuration file name
|
||||
#endif // USE_CONFIG_FILE
|
||||
#endif // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
|
||||
// Option -f specifies a config file, options -h and -V exit the
|
||||
// program, so we search for them first
|
||||
|
@ -420,7 +420,7 @@ int parse_config_file(int argc, char **argv)
|
|||
switch (opt)
|
||||
{
|
||||
case 'f' :
|
||||
#ifdef USE_CONFIG_FILE
|
||||
#ifdef OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
config_file = malloc((strlen(optarg) + 1) * sizeof(char)) ;
|
||||
if (! config_file)
|
||||
{
|
||||
|
@ -429,12 +429,12 @@ int parse_config_file(int argc, char **argv)
|
|||
return errno ;
|
||||
}
|
||||
strcpy(config_file, optarg) ;
|
||||
#else // USE_CONFIG_FILE
|
||||
#else // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
fprintf(stderr, "Warning! Program was not compiled with"
|
||||
" configuration file support, so -f is not available."
|
||||
" You must specify all options on the command line,"
|
||||
" or default value will be used.\n") ;
|
||||
#endif // USE_CONFIG_FILE
|
||||
#endif // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
break ;
|
||||
case 'h' :
|
||||
print_usage() ;
|
||||
|
@ -447,7 +447,7 @@ int parse_config_file(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef USE_CONFIG_FILE
|
||||
#ifdef OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
// If -f isn't found, we use the default config file
|
||||
if (config_file == NULL)
|
||||
{
|
||||
|
@ -480,7 +480,7 @@ int parse_config_file(int argc, char **argv)
|
|||
return OWL_ERR_CONFIG_FILE ;
|
||||
}
|
||||
free(config_file) ;
|
||||
#endif // USE_CONFIG_FILE
|
||||
#endif // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
@ -495,11 +495,11 @@ int parse_command_line(int argc, char **argv)
|
|||
if (! owl_run)
|
||||
return ret ;
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
ret = parse_calibration_data(argc, argv) ;
|
||||
if (! owl_run)
|
||||
return ret ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
@ -517,15 +517,15 @@ int parse_main_options(int argc, char **argv)
|
|||
switch (opt)
|
||||
{
|
||||
case 'A' :
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
SET_AUTOCALIBRATION() ;
|
||||
#else // USE_PTHREAD
|
||||
#else // OWLPS_LISTENER_USES_PTHREAD
|
||||
fprintf(stderr, "Warning! The program was compiled without"
|
||||
" support of POSIX threads, so -A (autocalibration)"
|
||||
" is not available and will be ignored. All other"
|
||||
" autocalibration-related options will also be"
|
||||
" ignored.\n") ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
break ;
|
||||
case 'D' :
|
||||
SET_DAEMON() ;
|
||||
|
@ -533,26 +533,26 @@ int parse_main_options(int argc, char **argv)
|
|||
case 'f' : // Config file
|
||||
break ; // (already parsed)
|
||||
case 'H' :
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
SET_AUTOCALIBRATION_HELLO_PORT(strtol(optarg, NULL, 0)) ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
break ;
|
||||
case 'i' :
|
||||
SET_AGGREGATION_IP(optarg) ;
|
||||
break ;
|
||||
case 'I' :
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
SET_AUTOCALIBRATION_IP(optarg) ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
break ;
|
||||
case 'K' :
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
SET_KEEP_MONITOR() ;
|
||||
#else // ENABLE_KEEP_MONITOR
|
||||
#else // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
fprintf(stderr, "Warning! The program was compiled without"
|
||||
" enabling the -K option (monitor mode keeping-up)."
|
||||
".\n") ;
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
break ;
|
||||
case 'l' :
|
||||
SET_LISTENING_PORT(strtol(optarg, NULL, 0)) ;
|
||||
|
@ -561,22 +561,22 @@ int parse_main_options(int argc, char **argv)
|
|||
SET_MODE(optarg[0]) ;
|
||||
break ;
|
||||
case 'n' :
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
SET_AUTOCALIBRATION_NBPKT(strtol(optarg, NULL, 0)) ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
break ;
|
||||
case 'O' :
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
SET_AUTOCALIBRATION_ORDER_PORT(strtol(optarg, NULL, 0)) ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
break ;
|
||||
case 'p' :
|
||||
SET_AGGREGATION_PORT(strtol(optarg, NULL, 0)) ;
|
||||
break ;
|
||||
case 'P' :
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
SET_AUTOCALIBRATION_REQUEST_PORT(strtol(optarg, NULL, 0)) ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
break ;
|
||||
case 'q' :
|
||||
RESET_VERBOSE() ;
|
||||
|
@ -588,14 +588,14 @@ int parse_main_options(int argc, char **argv)
|
|||
SET_PCAP_FILE(optarg) ;
|
||||
break ;
|
||||
case 't' :
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
SET_AUTOCALIBRATION_DELAY(strtol(optarg, NULL, 0)) ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
break ;
|
||||
case 'T' :
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
SET_AUTOCALIBRATION_HELLO_DELAY(strtol(optarg, NULL, 0)) ;
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
break ;
|
||||
case 'v' :
|
||||
INCREMENT_VERBOSE() ;
|
||||
|
@ -615,7 +615,7 @@ int parse_main_options(int argc, char **argv)
|
|||
|
||||
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
int parse_calibration_data(int argc, char **argv)
|
||||
{
|
||||
/* Parse remaining arguments (possible calibration data) */
|
||||
|
@ -639,7 +639,7 @@ int parse_calibration_data(int argc, char **argv)
|
|||
|
||||
return 0 ;
|
||||
}
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
|
||||
|
||||
|
@ -674,7 +674,7 @@ int check_configuration()
|
|||
// Ignoring the Wi-Fi interface too:
|
||||
GET_WIFI_IFACE()[0] = '\0' ;
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
if (GET_AUTOCALIBRATION())
|
||||
{
|
||||
if (VERBOSE_WARNING)
|
||||
|
@ -684,10 +684,10 @@ int check_configuration()
|
|||
UNSET_AUTOCALIBRATION() ;
|
||||
}
|
||||
|
||||
# ifdef ENABLE_KEEP_MONITOR
|
||||
# ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
UNSET_KEEP_MONITOR() ;
|
||||
# endif // ENABLE_KEEP_MONITOR
|
||||
#endif // USE_PTHREAD
|
||||
# endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
if (GET_DAEMON())
|
||||
{
|
||||
|
@ -734,7 +734,7 @@ int check_configuration()
|
|||
}
|
||||
|
||||
// Autocalibration stuff //
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
if (GET_AUTOCALIBRATION())
|
||||
{
|
||||
if (GET_AUTOCALIBRATION_IP()[0] == '\0')
|
||||
|
@ -780,7 +780,7 @@ int check_configuration()
|
|||
SET_AUTOCALIBRATION_HELLO_PORT(OWL_DEFAULT_AUTOCALIBRATION_HELLO_PORT) ;
|
||||
}
|
||||
}
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
@ -790,9 +790,9 @@ int check_configuration()
|
|||
void print_configuration()
|
||||
{
|
||||
fprintf(stderr, "Configuration:\n") ;
|
||||
#ifdef USE_CONFIG_FILE
|
||||
#ifdef OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
cfg_print(cfg, stderr) ;
|
||||
#else // USE_CONFIG_FILE
|
||||
#else // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
fprintf(stderr,
|
||||
"mode = %c\n"
|
||||
"aggregation_ip = \"%s\"\n"
|
||||
|
@ -800,10 +800,10 @@ void print_configuration()
|
|||
"listening_port = %"PRIuFAST16"\n"
|
||||
"rtap_iface = \"%s\"\n"
|
||||
"wifi_iface = \"%s\"\n"
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
"keep_monitor = %s\n"
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#ifdef USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
"autocalibration = %s\n"
|
||||
"autocalibration_ip = \"%s\"\n"
|
||||
"autocalibration_request_port = %"PRIuFAST16"\n"
|
||||
|
@ -816,7 +816,7 @@ void print_configuration()
|
|||
"my_position_x = %f\n"
|
||||
"my_position_y = %f\n"
|
||||
"my_position_z = %f\n"
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
"verbose = %"PRIuFAST8"\n"
|
||||
,
|
||||
GET_MODE(),
|
||||
|
@ -825,10 +825,10 @@ void print_configuration()
|
|||
GET_LISTENING_PORT(),
|
||||
GET_RTAP_IFACE(),
|
||||
GET_WIFI_IFACE(),
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
OWL_BOOL_TO_STRING(GET_KEEP_MONITOR()),
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#ifdef USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
OWL_BOOL_TO_STRING(GET_AUTOCALIBRATION()),
|
||||
GET_AUTOCALIBRATION_IP(),
|
||||
GET_AUTOCALIBRATION_REQUEST_PORT(),
|
||||
|
@ -841,15 +841,15 @@ void print_configuration()
|
|||
GET_MY_POSITION_X(),
|
||||
GET_MY_POSITION_Y(),
|
||||
GET_MY_POSITION_Z(),
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
GET_VERBOSE()
|
||||
) ;
|
||||
#endif // USE_CONFIG_FILE
|
||||
#endif // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
/*
|
||||
* Thread function. Switches interface 'iface' to monitor mode every
|
||||
* second.
|
||||
|
@ -902,7 +902,7 @@ int iface_mode_monitor(const char *const iface)
|
|||
|
||||
return 0 ;
|
||||
}
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
|
||||
|
||||
|
||||
|
@ -1060,12 +1060,12 @@ void read_packet(const struct pcap_pkthdr *pkt_header,
|
|||
packet_udp_header = (struct udphdr *) &pkt_data[offset] ;
|
||||
dest_port = ntohs(packet_udp_header->dest) ;
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
if (GET_AUTOCALIBRATION() && dest_port ==
|
||||
(uint_fast16_t) GET_AUTOCALIBRATION_REQUEST_PORT())
|
||||
uses_autocalibration_request_port = true ;
|
||||
else
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
if (dest_port != (uint_fast16_t) GET_LISTENING_PORT())
|
||||
goto not_explicit_packet ;
|
||||
}
|
||||
|
@ -1427,7 +1427,7 @@ void get_ip_addr(char *eth, char ip[INET_ADDRSTRLEN])
|
|||
|
||||
|
||||
/* *** Autocalibration functions *** */
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
|
||||
void* autocalibrate_hello(void *NULL_value)
|
||||
{
|
||||
|
@ -1607,7 +1607,7 @@ uint_fast16_t make_packet(uint8_t **packet)
|
|||
return size ;
|
||||
}
|
||||
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
/* *** End of autocalibration functions *** */
|
||||
|
||||
|
||||
|
@ -1715,7 +1715,7 @@ void print_usage()
|
|||
"\t-K\tKeep the monitor mode up on wifi_iface. Use it with"
|
||||
" buggy\n\t\tdrivers that disable monitor mode periodically."
|
||||
" Available only\n\t\tif the program was compiled with the"
|
||||
" option ENABLE_KEEP_MONITOR.\n"
|
||||
" option OWLPS_LISTENER_KEEPS_MONITOR.\n"
|
||||
,
|
||||
program_name,
|
||||
program_name,
|
||||
|
@ -1747,22 +1747,22 @@ void print_version()
|
|||
"unknown version"
|
||||
#endif // OWLPS_VERSION
|
||||
,
|
||||
#ifdef USE_CONFIG_FILE
|
||||
#ifdef OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
"YES"
|
||||
#else // USE_CONFIG_FILE
|
||||
#else // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
"NO"
|
||||
#endif // USE_CONFIG_FILE
|
||||
#endif // OWLPS_LISTENER_USES_CONFIG_FILE
|
||||
,
|
||||
#ifdef USE_PTHREAD
|
||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||
"YES"
|
||||
#else // USE_PTHREAD
|
||||
#else // OWLPS_LISTENER_USES_PTHREAD
|
||||
"NO"
|
||||
#endif // USE_PTHREAD
|
||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||
,
|
||||
#ifdef ENABLE_KEEP_MONITOR
|
||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||
"YES"
|
||||
#else // ENABLE_KEEP_MONITOR
|
||||
#else // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
"NO"
|
||||
#endif // ENABLE_KEEP_MONITOR
|
||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||
) ;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue