[Listener] Prepare autocalibration
Send hello messages to the aggregator.
This commit is contained in:
parent
790c9bdaf7
commit
c583e0bb54
|
@ -48,9 +48,10 @@
|
|||
|
||||
|
||||
/* Arguments & program configuration */
|
||||
#define OPTIONS "d:f:hkl:m:p:qr:vw:" // getopt string
|
||||
#define OPTIONS "Aa:d:f:hH:kl:m:p:qr:vw:" // getopt string
|
||||
#define DEFAULT_CONFIG_FILE "/usr/local/etc/owlps/owlps-listener.conf"
|
||||
enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ;
|
||||
#define AUTOCALIBRATION_DEFAULT_HELLO_DELAY 120 // seconds
|
||||
|
||||
|
||||
/* Error codes */
|
||||
|
@ -69,12 +70,17 @@ void print_configuration(void) ;
|
|||
#endif // DEBUG
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
void* keep_mode_monitor(char *iface) ;
|
||||
void keep_mode_monitor(char *iface) ;
|
||||
#endif // USE_PTHREAD
|
||||
int capture(void) ;
|
||||
void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||
const u_char *packet) ;
|
||||
void get_mac_addr(char *eth, unsigned char mac_bytes[6]) ;
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
void autocalibrate_hello(void) ;
|
||||
#endif // USE_PTHREAD
|
||||
|
||||
void print_usage(void) ;
|
||||
|
||||
|
||||
|
@ -100,6 +106,16 @@ void print_usage(void) ;
|
|||
#define GET_RTAP_IFACE() (cfg_getstr(cfg, "rtap_iface"))
|
||||
#define SET_WIFI_IFACE(IFACE) (cfg_setstr(cfg, "wifi_iface", (IFACE)))
|
||||
#define GET_WIFI_IFACE() (cfg_getstr(cfg, "wifi_iface"))
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#define SET_AUTOCALIBRATION() (cfg_setbool(cfg, "autocalibration", cfg_true))
|
||||
#define GET_AUTOCALIBRATION() (cfg_getbool(cfg, "autocalibration"))
|
||||
#define SET_AUTOCALIBRATION_PORT(PORT) (cfg_setint(cfg, "autocalibration_port", (PORT)))
|
||||
#define GET_AUTOCALIBRATION_PORT() (cfg_getint(cfg, "autocalibration_port"))
|
||||
#define SET_AUTOCALIBRATION_HELLO_DELAY(DELAY) (cfg_setint(cfg, "autocalibration_hello_delay", (DELAY)))
|
||||
#define GET_AUTOCALIBRATION_HELLO_DELAY() (cfg_getint(cfg, "autocalibration_hello_delay"))
|
||||
#endif // USE_PTHREAD
|
||||
|
||||
#define SET_VERBOSE() (cfg_setbool(cfg, "verbose", cfg_true))
|
||||
#define UNSET_VERBOSE() (cfg_setbool(cfg, "verbose", cfg_false))
|
||||
#define GET_VERBOSE() (cfg_getbool(cfg, "verbose"))
|
||||
|
@ -122,6 +138,16 @@ void print_usage(void) ;
|
|||
#define GET_RTAP_IFACE() (options.rtap_iface)
|
||||
#define SET_WIFI_IFACE(IFACE) (strncpy(options.wifi_iface, (IFACE), IFNAMSIZ+1))
|
||||
#define GET_WIFI_IFACE() (options.wifi_iface)
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
#define SET_AUTOCALIBRATION() (options.autocalibration = TRUE)
|
||||
#define GET_AUTOCALIBRATION() (options.autocalibration)
|
||||
#define SET_AUTOCALIBRATION_PORT(PORT) (options.autocalibration_port = (PORT))
|
||||
#define GET_AUTOCALIBRATION_PORT() (options.autocalibration_port)
|
||||
#define SET_AUTOCALIBRATION_HELLO_DELAY(DELAY) (options.autocalibration_hello_delay = (DELAY))
|
||||
#define GET_AUTOCALIBRATION_HELLO_DELAY() (options.autocalibration_hello_delay)
|
||||
#endif // USE_PTHREAD
|
||||
|
||||
#define SET_VERBOSE() (options.verbose = TRUE)
|
||||
#define UNSET_VERBOSE() (options.verbose = FALSE)
|
||||
#define GET_VERBOSE() (options.verbose)
|
||||
|
|
|
@ -30,6 +30,11 @@ struct {
|
|||
#endif // USE_PTHREAD
|
||||
char rtap_iface[IFNAMSIZ + 1] ;
|
||||
char wifi_iface[IFNAMSIZ + 1] ;
|
||||
#ifdef USE_PTHREAD
|
||||
BOOL autocalibration ;
|
||||
long autocalibration_port ;
|
||||
long autocalibration_hello_delay ;
|
||||
#endif // USE_PTHREAD
|
||||
BOOL verbose ;
|
||||
} options = { // Initalise default options:
|
||||
MODE_ACTIVE,
|
||||
|
@ -41,6 +46,11 @@ struct {
|
|||
#endif // USE_PTHREAD
|
||||
"",
|
||||
"",
|
||||
#ifdef USE_PTHREAD
|
||||
FALSE,
|
||||
AUTOCALIBRATION_DEFAULT_PORT,
|
||||
AUTOCALIBRATION_DEFAULT_HELLO_DELAY,
|
||||
#endif // USE_PTHREAD
|
||||
FALSE
|
||||
} ;
|
||||
#endif // USE_CONFIG_FILE
|
||||
|
@ -53,7 +63,9 @@ int main(int argc, char *argv[])
|
|||
char *mac_string ; // AP MAC (string value)
|
||||
int ret ; // Program return value
|
||||
#ifdef USE_PTHREAD
|
||||
pthread_t thread ; // Thread pour le repassage en mode monitor
|
||||
pthread_t
|
||||
keep_monitor_thread,
|
||||
autocalibration_hello_thread ;
|
||||
#endif // USE_PTHREAD
|
||||
|
||||
program_name = argv[0] ;
|
||||
|
@ -69,10 +81,15 @@ int main(int argc, char *argv[])
|
|||
sigaction(SIGTERM, &action, NULL) ;
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
/* Set up thread */
|
||||
/* Set up threads */
|
||||
if (GET_KEEP_MONITOR())
|
||||
pthread_create(&thread, NULL,
|
||||
pthread_create(&keep_monitor_thread, NULL,
|
||||
(void *) &keep_mode_monitor, GET_WIFI_IFACE()) ;
|
||||
if (GET_AUTOCALIBRATION())
|
||||
{
|
||||
pthread_create(&autocalibration_hello_thread, NULL,
|
||||
(void *) &autocalibrate_hello, NULL) ;
|
||||
}
|
||||
#endif // USE_PTHREAD
|
||||
|
||||
get_mac_addr(GET_WIFI_IFACE(), mac) ;
|
||||
|
@ -130,6 +147,17 @@ void 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
|
||||
// Autocalibration activated?
|
||||
CFG_BOOL("autocalibration", cfg_false, CFGF_NONE),
|
||||
// Port on which autocalibration data are exchanged:
|
||||
CFG_INT("autocalibration_port", AUTOCALIBRATION_DEFAULT_PORT,
|
||||
CFGF_NONE),
|
||||
// Delay between two hello messages:
|
||||
CFG_INT("autocalibration_hello_delay",
|
||||
AUTOCALIBRATION_DEFAULT_HELLO_DELAY,
|
||||
CFGF_NONE),
|
||||
#endif // USE_PTHREAD
|
||||
// Display capture packets, or not:
|
||||
CFG_BOOL("verbose", cfg_false, CFGF_NONE),
|
||||
CFG_END()
|
||||
|
@ -195,6 +223,22 @@ void parse_command_line(int argc, char **argv)
|
|||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'A' :
|
||||
#ifdef USE_PTHREAD
|
||||
SET_AUTOCALIBRATION() ;
|
||||
#else // USE_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
|
||||
break ;
|
||||
case 'a' :
|
||||
#ifdef USE_PTHREAD
|
||||
SET_AUTOCALIBRATION_PORT(strtol(optarg, NULL, 0)) ;
|
||||
#endif // USE_PTHREAD
|
||||
break ;
|
||||
case 'd' :
|
||||
SET_AGGREGATION_IP(optarg) ;
|
||||
break ;
|
||||
|
@ -203,6 +247,9 @@ void parse_command_line(int argc, char **argv)
|
|||
case 'h' :
|
||||
print_usage() ;
|
||||
exit(0) ;
|
||||
case 'H' :
|
||||
SET_AUTOCALIBRATION_HELLO_DELAY(strtol(optarg, NULL, 0)) ;
|
||||
break ;
|
||||
case 'k' :
|
||||
#ifdef USE_PTHREAD
|
||||
SET_KEEP_MONITOR() ;
|
||||
|
@ -312,15 +359,17 @@ void print_configuration()
|
|||
* Thread function. Switches interface 'iface' to monitor mode every
|
||||
* second.
|
||||
*/
|
||||
void* keep_mode_monitor(char *iface)
|
||||
void keep_mode_monitor(char *iface)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Thread for keeping monitor mode launched.\n") ;
|
||||
#endif // DEBUG
|
||||
|
||||
while (run)
|
||||
{
|
||||
iface_mode_monitor(iface) ; // Switch the interface to monitor mode
|
||||
sleep(1) ; // Wait for 1 second
|
||||
}
|
||||
|
||||
pthread_exit(NULL) ;
|
||||
}
|
||||
#endif // USE_PTHREAD
|
||||
|
||||
|
@ -339,8 +388,7 @@ int capture()
|
|||
handle = pcap_open_live(GET_RTAP_IFACE(), BUFSIZ, 1, 1000, errbuf) ;
|
||||
if (handle == NULL) // Capture starting failed
|
||||
{
|
||||
fprintf(stderr, "Cannot open interface « %s »: %s\n",
|
||||
GET_RTAP_IFACE(), errbuf) ;
|
||||
fprintf(stderr, "Cannot open capture interface %s\n", errbuf) ;
|
||||
return ERR_OPENING_IFACE ;
|
||||
}
|
||||
|
||||
|
@ -707,12 +755,43 @@ void get_mac_addr(char *eth, unsigned char mac_bytes[6])
|
|||
|
||||
|
||||
|
||||
/* *** Autocalibration functions *** */
|
||||
#ifdef USE_PTHREAD
|
||||
|
||||
void autocalibrate_hello()
|
||||
{
|
||||
int send_sockfd ;
|
||||
struct sockaddr_in serv;
|
||||
struct sockaddr_in client ;
|
||||
socklen_t serv_len = sizeof(serv);
|
||||
|
||||
send_sockfd = create_udp_sending_socket(GET_AGGREGATION_IP(),
|
||||
GET_AUTOCALIBRATION_PORT(),
|
||||
&serv, &client) ;
|
||||
|
||||
while (run)
|
||||
{
|
||||
sendto(send_sockfd, AUTOCALIBRATION_HELLO_STRING,
|
||||
sizeof(AUTOCALIBRATION_HELLO_STRING), 0,
|
||||
(struct sockaddr *)&serv, serv_len) ;
|
||||
sleep(GET_AUTOCALIBRATION_HELLO_DELAY()) ;
|
||||
}
|
||||
|
||||
(void) close(send_sockfd) ;
|
||||
}
|
||||
|
||||
#endif // USE_PTHREAD
|
||||
/* *** End of autocalibration functions *** */
|
||||
|
||||
|
||||
|
||||
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]\n"
|
||||
" [-w wifi_iface] [-k] [-v | -q] [-A] [-a autocalibration_port]"
|
||||
" [-H autocalibration_hello_delay]\n"
|
||||
|
||||
"Main options:\n"
|
||||
"\t-h\t\tPrint this help.\n"
|
||||
|
@ -723,14 +802,25 @@ void print_usage()
|
|||
"Capture options:\n"
|
||||
"\t-m mode\t\t\tCapture mode: a(ctive), p(assive), m(ixed)"
|
||||
" (default: a).\n"
|
||||
"\t-l listening_port\tPort on which explicit positioning"
|
||||
" requests are sent by mobiles (default: %d).\n"
|
||||
"\t-d aggregation_ip\tIP address of the aggregation server"
|
||||
" (default: 127.0.0.1)\n"
|
||||
"\t-l aggregation_port\tListening port on the aggregation server"
|
||||
" (default: %d).\n"
|
||||
"\t-p aggregation_port\tRequests are transmitted to the"
|
||||
" aggregation server on this port (default: %d).\n"
|
||||
"\t-r rtap_iface\t\tRadiotap capture interface.\n"
|
||||
"\t-w wifi_iface\t\tPhysical interface behind rtap_iface"
|
||||
" (default: rtap_iface).\n"
|
||||
|
||||
"Autocalibration options:\n"
|
||||
"(These options are available only if the program was compiled"
|
||||
" with support of POSIX threads.)\n"
|
||||
"\t-A\t\tEnable autocalibration (default: disabled).\n"
|
||||
"\t-a port\t\tPort on which autocalibration data"
|
||||
" are exchanged with the aggregation server (default: %d).\n"
|
||||
"\t-H hello_delay\tTime between each hello"
|
||||
" message sent to the aggregation server (default: %d s).\n"
|
||||
|
||||
"Other options:\n"
|
||||
"\t-k\tKeep the monitor mode up on wifi_iface. Use it with buggy"
|
||||
" drivers that disable monitor mode periodically. Available"
|
||||
|
@ -741,6 +831,9 @@ void print_usage()
|
|||
,
|
||||
program_name,
|
||||
DEFAULT_CONFIG_FILE,
|
||||
AGGREGATE_DEFAULT_PORT
|
||||
LOC_REQUEST_DEFAULT_PORT,
|
||||
AGGREGATE_DEFAULT_PORT,
|
||||
AUTOCALIBRATION_DEFAULT_PORT,
|
||||
AUTOCALIBRATION_DEFAULT_HELLO_DELAY
|
||||
) ;
|
||||
}
|
||||
|
|
|
@ -42,9 +42,16 @@
|
|||
#define AGGREGATE_DEFAULT_PORT 9901
|
||||
// Port on which aggregator and positioning server communicate:
|
||||
#define POSITIONER_DEFAULT_PORT 9902
|
||||
// Port on which listener listens for order from aggregator:
|
||||
#define LISTENER_DEFAULT_PORT 9903
|
||||
#define AUTOCALIBRATION_DEFAULT_PORT 9904
|
||||
// Port on which the mobile listens for its position:
|
||||
#define MOBILE_DEFAULT_PORT 9910
|
||||
|
||||
// Other parameters:
|
||||
#define AUTOCALIBRATION_HELLO_STRING "Ay oop aggregator!"
|
||||
|
||||
|
||||
/* Type booléen */
|
||||
typedef enum {FALSE, TRUE} BOOL ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue