[lib] Prefix all functions with owl_
This commit is contained in:
parent
686ab87a1c
commit
940c5f74df
2
TODO
2
TODO
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
* libowlps
|
* libowlps
|
||||||
|
|
||||||
- Prefix all function with "owlps_".
|
- Rename types? Prefix them?
|
||||||
|
|
||||||
|
|
||||||
* Aggregator
|
* Aggregator
|
||||||
|
|
|
@ -18,8 +18,8 @@ int owlclient_create_trx_socket(char *dest_ip, uint_fast16_t dest_port,
|
||||||
{
|
{
|
||||||
struct sockaddr_in client ;
|
struct sockaddr_in client ;
|
||||||
|
|
||||||
int sockfd = create_udp_sending_socket(dest_ip, dest_port,
|
int sockfd = owl_create_udp_sending_socket(dest_ip, dest_port,
|
||||||
server, &client) ;
|
server, &client) ;
|
||||||
if (sockfd < 0)
|
if (sockfd < 0)
|
||||||
{
|
{
|
||||||
perror("Error! Cannot create UDP sending socket to the aggregation"
|
perror("Error! Cannot create UDP sending socket to the aggregation"
|
||||||
|
|
|
@ -33,14 +33,14 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* Set up signal handlers */
|
/* Set up signal handlers */
|
||||||
sigemptyset(&action.sa_mask) ;
|
sigemptyset(&action.sa_mask) ;
|
||||||
action.sa_handler = sigint_handler ;
|
action.sa_handler = owl_sigint_handler ;
|
||||||
sigaction(SIGINT, &action, NULL) ;
|
sigaction(SIGINT, &action, NULL) ;
|
||||||
action.sa_handler = sigterm_handler ;
|
action.sa_handler = owl_sigterm_handler ;
|
||||||
sigaction(SIGTERM, &action, NULL) ;
|
sigaction(SIGTERM, &action, NULL) ;
|
||||||
|
|
||||||
/* Create UDP socket */
|
/* Create UDP socket */
|
||||||
listening_port = cfg_getint(cfg, "listening_port") ;
|
listening_port = cfg_getint(cfg, "listening_port") ;
|
||||||
if ((sockfd = create_udp_listening_socket(listening_port)) < 0)
|
if ((sockfd = owl_create_udp_listening_socket(listening_port)) < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Error! Cannot listen on port %"PRIuFAST16".\n",
|
"Error! Cannot listen on port %"PRIuFAST16".\n",
|
||||||
|
@ -328,9 +328,9 @@ int read_loop(int sockfd)
|
||||||
if (cfg_getbool(cfg, "verbose"))
|
if (cfg_getbool(cfg, "verbose"))
|
||||||
{
|
{
|
||||||
ap_mac_string =
|
ap_mac_string =
|
||||||
mac_bytes_to_string(message.ap_mac_addr_bytes) ;
|
owl_mac_bytes_to_string(message.ap_mac_addr_bytes) ;
|
||||||
mobile_mac_string =
|
mobile_mac_string =
|
||||||
mac_bytes_to_string(message.mobile_mac_addr_bytes) ;
|
owl_mac_bytes_to_string(message.mobile_mac_addr_bytes) ;
|
||||||
mobile_ip_string =
|
mobile_ip_string =
|
||||||
ip_bytes_to_string(message.mobile_ip_addr_bytes) ;
|
ip_bytes_to_string(message.mobile_ip_addr_bytes) ;
|
||||||
printf("\n"
|
printf("\n"
|
||||||
|
@ -349,8 +349,8 @@ int read_loop(int sockfd)
|
||||||
ap_mac_string,
|
ap_mac_string,
|
||||||
mobile_mac_string,
|
mobile_mac_string,
|
||||||
mobile_ip_string,
|
mobile_ip_string,
|
||||||
timestamp_to_ms(message.request_time),
|
owl_timestamp_to_ms(message.request_time),
|
||||||
timestamp_to_ms(message.start_time),
|
owl_timestamp_to_ms(message.start_time),
|
||||||
message.antenna_signal_dbm - 0x100,
|
message.antenna_signal_dbm - 0x100,
|
||||||
message.x_position,
|
message.x_position,
|
||||||
message.y_position,
|
message.y_position,
|
||||||
|
@ -365,7 +365,7 @@ int read_loop(int sockfd)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ap_mac_string =
|
ap_mac_string =
|
||||||
mac_bytes_to_string(message.ap_mac_addr_bytes) ;
|
owl_mac_bytes_to_string(message.ap_mac_addr_bytes) ;
|
||||||
fprintf(stderr, "Request received from AP « %s ».\n",
|
fprintf(stderr, "Request received from AP « %s ».\n",
|
||||||
ap_mac_string) ;
|
ap_mac_string) ;
|
||||||
free(ap_mac_string) ;
|
free(ap_mac_string) ;
|
||||||
|
@ -408,9 +408,10 @@ void* monitor_couples()
|
||||||
fprintf(stderr, "Monitor couples thread launched.\n") ;
|
fprintf(stderr, "Monitor couples thread launched.\n") ;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
sockfd = create_udp_sending_socket(cfg_getstr(cfg, "positioner_ip"),
|
sockfd =
|
||||||
cfg_getint(cfg, "positioner_port"),
|
owl_create_udp_sending_socket(cfg_getstr(cfg, "positioner_ip"),
|
||||||
&serv, &client) ;
|
cfg_getint(cfg, "positioner_port"),
|
||||||
|
&serv, &client) ;
|
||||||
|
|
||||||
/* Open output file */
|
/* Open output file */
|
||||||
fd = fopen(cfg_getstr(cfg, "output_file"), "a") ; // We use add mode
|
fd = fopen(cfg_getstr(cfg, "output_file"), "a") ; // We use add mode
|
||||||
|
@ -426,11 +427,11 @@ void* monitor_couples()
|
||||||
couple_ptr = couples ;
|
couple_ptr = couples ;
|
||||||
couple_prev = NULL ;
|
couple_prev = NULL ;
|
||||||
couple_info_ptr = NULL ;
|
couple_info_ptr = NULL ;
|
||||||
timestamp_now(¤t_time) ;
|
owl_timestamp_now(¤t_time) ;
|
||||||
|
|
||||||
while (couple_ptr != NULL) // Parsing list
|
while (couple_ptr != NULL) // Parsing list
|
||||||
{
|
{
|
||||||
sub = time_elapsed(couple_ptr->start_time, current_time) ;
|
sub = owl_time_elapsed(couple_ptr->start_time, current_time) ;
|
||||||
|
|
||||||
// If the couple was not treated already
|
// If the couple was not treated already
|
||||||
if (couple_ptr->info != NULL)
|
if (couple_ptr->info != NULL)
|
||||||
|
@ -450,13 +451,13 @@ void* monitor_couples()
|
||||||
#ifdef USE_TIMESTAMP
|
#ifdef USE_TIMESTAMP
|
||||||
// Print request mobile timestamp to the output file
|
// Print request mobile timestamp to the output file
|
||||||
fprintf(fd, "%"PRIu64";",
|
fprintf(fd, "%"PRIu64";",
|
||||||
timestamp_to_ms(couple_ptr->request_time)) ;
|
owl_timestamp_to_ms(couple_ptr->request_time)) ;
|
||||||
#endif // USE_TIMESTAMP
|
#endif // USE_TIMESTAMP
|
||||||
|
|
||||||
// Print mobile MAC address to the output file
|
// Print mobile MAC address to the output file
|
||||||
mac_string =
|
mac_string =
|
||||||
mac_bytes_to_string(couple_ptr
|
owl_mac_bytes_to_string(couple_ptr
|
||||||
->mobile_mac_addr_bytes) ;
|
->mobile_mac_addr_bytes) ;
|
||||||
fprintf(fd, "%s;", mac_string) ;
|
fprintf(fd, "%s;", mac_string) ;
|
||||||
free(mac_string) ;
|
free(mac_string) ;
|
||||||
|
|
||||||
|
@ -493,8 +494,8 @@ void* monitor_couples()
|
||||||
|
|
||||||
// Print AP info to the output file
|
// Print AP info to the output file
|
||||||
mac_string =
|
mac_string =
|
||||||
mac_bytes_to_string(couple_info_ptr
|
owl_mac_bytes_to_string(couple_info_ptr
|
||||||
->ap_mac_addr_bytes) ;
|
->ap_mac_addr_bytes) ;
|
||||||
fprintf(fd, ";%s;%d", mac_string,
|
fprintf(fd, ";%s;%d", mac_string,
|
||||||
couple_info_ptr->antenna_signal_dbm - 0x100) ;
|
couple_info_ptr->antenna_signal_dbm - 0x100) ;
|
||||||
free(mac_string) ;
|
free(mac_string) ;
|
||||||
|
@ -564,7 +565,7 @@ void got_couple_info(couple_message message)
|
||||||
couple_info_list *tmp_info = NULL ;
|
couple_info_list *tmp_info = NULL ;
|
||||||
TIMESTAMP start_time ; // Reception time on the aggregator
|
TIMESTAMP start_time ; // Reception time on the aggregator
|
||||||
|
|
||||||
timestamp_now(&start_time) ;
|
owl_timestamp_now(&start_time) ;
|
||||||
|
|
||||||
/* Create a new couple */
|
/* Create a new couple */
|
||||||
tmp_info = malloc(sizeof(couple_info_list)) ;
|
tmp_info = malloc(sizeof(couple_info_list)) ;
|
||||||
|
@ -580,10 +581,12 @@ void got_couple_info(couple_message message)
|
||||||
tmp_couple = malloc(sizeof(couple_list)) ; // create it.
|
tmp_couple = malloc(sizeof(couple_list)) ; // create it.
|
||||||
memcpy(tmp_couple->mobile_mac_addr_bytes,
|
memcpy(tmp_couple->mobile_mac_addr_bytes,
|
||||||
message.mobile_mac_addr_bytes, 6) ;
|
message.mobile_mac_addr_bytes, 6) ;
|
||||||
if (timestamp_to_ms(message.request_time) != 0) // Explicit packet
|
// Explicit packet:
|
||||||
|
if (owl_timestamp_to_ms(message.request_time) != 0)
|
||||||
// Transmission time on the mobile:
|
// Transmission time on the mobile:
|
||||||
tmp_couple->request_time = message.request_time ;
|
tmp_couple->request_time = message.request_time ;
|
||||||
else // Implicit packet
|
// Implicit packet:
|
||||||
|
else
|
||||||
// Reception time on the AP:
|
// Reception time on the AP:
|
||||||
tmp_couple->request_time = message.start_time ;
|
tmp_couple->request_time = message.start_time ;
|
||||||
// Save locale time on the aggregator (not the reception time
|
// Save locale time on the aggregator (not the reception time
|
||||||
|
@ -600,28 +603,30 @@ void got_couple_info(couple_message message)
|
||||||
|
|
||||||
else // If the couple list exists already
|
else // If the couple list exists already
|
||||||
{ // we search the list for the couple
|
{ // we search the list for the couple
|
||||||
if (timestamp_to_ms(message.request_time) != 0) // Explicit packet
|
// Explicit packet:
|
||||||
|
if (owl_timestamp_to_ms(message.request_time) != 0)
|
||||||
{
|
{
|
||||||
while (tmp_couple != NULL)
|
while (tmp_couple != NULL)
|
||||||
{ // Research criterion: MAC and transmission time
|
{ // Research criterion: MAC and transmission time
|
||||||
if (mac_equals(message.mobile_mac_addr_bytes,
|
if (owl_mac_equals(message.mobile_mac_addr_bytes,
|
||||||
tmp_couple->mobile_mac_addr_bytes) == 1
|
tmp_couple->mobile_mac_addr_bytes) == 1
|
||||||
&& time_elapsed(message.request_time,
|
&& owl_time_elapsed(message.request_time,
|
||||||
tmp_couple->request_time) == 0)
|
tmp_couple->request_time) == 0)
|
||||||
break ; // If the couple exists, we stop on it
|
break ; // If the couple exists, we stop on it
|
||||||
tmp_couple = tmp_couple->next ;
|
tmp_couple = tmp_couple->next ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Implicit packet
|
// Implicit packet:
|
||||||
|
else
|
||||||
{
|
{
|
||||||
while (tmp_couple != NULL)
|
while (tmp_couple != NULL)
|
||||||
{ // Research criterion: MAC addresses equals and reception
|
{ // Research criterion: MAC addresses equals and reception
|
||||||
// times on the APs less than 10 ms
|
// times on the APs less than 10 ms
|
||||||
// TODO : define an option for the maximal difference time.
|
// TODO : define an option for the maximal difference time.
|
||||||
if (mac_equals(message.mobile_mac_addr_bytes,
|
if (owl_mac_equals(message.mobile_mac_addr_bytes,
|
||||||
tmp_couple->mobile_mac_addr_bytes) == 1
|
tmp_couple->mobile_mac_addr_bytes) == 1
|
||||||
&& time_elapsed(message.start_time,
|
&& owl_time_elapsed(message.start_time,
|
||||||
tmp_couple->request_time) <= 10)
|
tmp_couple->request_time) <= 10)
|
||||||
break ; // If the couple exists, we stop on it
|
break ; // If the couple exists, we stop on it
|
||||||
tmp_couple = tmp_couple->next ;
|
tmp_couple = tmp_couple->next ;
|
||||||
}
|
}
|
||||||
|
@ -633,10 +638,12 @@ void got_couple_info(couple_message message)
|
||||||
tmp_couple = malloc(sizeof(couple_list)) ; // create it.
|
tmp_couple = malloc(sizeof(couple_list)) ; // create it.
|
||||||
memcpy(tmp_couple->mobile_mac_addr_bytes,
|
memcpy(tmp_couple->mobile_mac_addr_bytes,
|
||||||
message.mobile_mac_addr_bytes, 6) ;
|
message.mobile_mac_addr_bytes, 6) ;
|
||||||
if (timestamp_to_ms(message.request_time) != 0) // Explicit packet
|
// Explicit packet:
|
||||||
|
if (owl_timestamp_to_ms(message.request_time) != 0)
|
||||||
// Transmission time on the mobile:
|
// Transmission time on the mobile:
|
||||||
tmp_couple->request_time = message.request_time ;
|
tmp_couple->request_time = message.request_time ;
|
||||||
else // Implicit packet
|
// Implicit packet:
|
||||||
|
else
|
||||||
// Reception time on the AP:
|
// Reception time on the AP:
|
||||||
tmp_couple->request_time = message.start_time ;
|
tmp_couple->request_time = message.start_time ;
|
||||||
// Save locale time on the aggregator (not the reception time
|
// Save locale time on the aggregator (not the reception time
|
||||||
|
@ -710,8 +717,8 @@ void listen_for_aps(void)
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
listen_sockfd =
|
listen_sockfd =
|
||||||
create_udp_listening_socket(cfg_getint(cfg,
|
owl_create_udp_listening_socket(cfg_getint(cfg,
|
||||||
"autocalibration_port")) ;
|
"autocalibration_port")) ;
|
||||||
if (listen_sockfd < 0)
|
if (listen_sockfd < 0)
|
||||||
{
|
{
|
||||||
perror("Error! Cannot create UDP listening socket from the"
|
perror("Error! Cannot create UDP listening socket from the"
|
||||||
|
@ -779,7 +786,7 @@ ap_list* find_ap(uint8_t mac_addr_bytes[6])
|
||||||
found = token_aps ;
|
found = token_aps ;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (mac_equals(found->mac_addr_bytes, mac_addr_bytes))
|
if (owl_mac_equals(found->mac_addr_bytes, mac_addr_bytes))
|
||||||
return found ;
|
return found ;
|
||||||
found = found->next ;
|
found = found->next ;
|
||||||
}
|
}
|
||||||
|
@ -795,7 +802,7 @@ ap_list* find_ap(uint8_t mac_addr_bytes[6])
|
||||||
ap_list* add_ap_front(uint8_t mac_addr_bytes[6])
|
ap_list* add_ap_front(uint8_t mac_addr_bytes[6])
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
char *mac = mac_bytes_to_string(mac_addr_bytes) ;
|
char *mac = owl_mac_bytes_to_string(mac_addr_bytes) ;
|
||||||
fprintf(stderr, "Creating AP with MAC address « %s »...\n", mac) ;
|
fprintf(stderr, "Creating AP with MAC address « %s »...\n", mac) ;
|
||||||
free(mac) ;
|
free(mac) ;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
@ -823,7 +830,7 @@ void update_ap_ip_addr(ap_list *ap, char ip_addr[16])
|
||||||
void update_ap_seen(ap_list *ap)
|
void update_ap_seen(ap_list *ap)
|
||||||
{
|
{
|
||||||
assert(ap) ;
|
assert(ap) ;
|
||||||
timestamp_now(&ap->last_seen) ;
|
owl_timestamp_now(&ap->last_seen) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -887,10 +894,10 @@ void delete_old_aps()
|
||||||
{
|
{
|
||||||
TIMESTAMP now ;
|
TIMESTAMP now ;
|
||||||
|
|
||||||
timestamp_now(&now) ;
|
owl_timestamp_now(&now) ;
|
||||||
|
|
||||||
while (token_aps != NULL)
|
while (token_aps != NULL)
|
||||||
if (time_elapsed(token_aps->last_seen, now) >
|
if (owl_time_elapsed(token_aps->last_seen, now) >
|
||||||
(uint_fast32_t) cfg_getint(cfg, "ap_keep_timeout") * 1000)
|
(uint_fast32_t) cfg_getint(cfg, "ap_keep_timeout") * 1000)
|
||||||
delete_ap(token_aps) ;
|
delete_ap(token_aps) ;
|
||||||
else
|
else
|
||||||
|
@ -905,7 +912,7 @@ void delete_ap(ap_list *ap)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
assert(ap) ;
|
assert(ap) ;
|
||||||
char *mac = mac_bytes_to_string(token_aps->mac_addr_bytes) ;
|
char *mac = owl_mac_bytes_to_string(token_aps->mac_addr_bytes) ;
|
||||||
fprintf(stderr, "Deleting AP « %s »...\n", mac) ;
|
fprintf(stderr, "Deleting AP « %s »...\n", mac) ;
|
||||||
free(mac) ;
|
free(mac) ;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
@ -963,9 +970,9 @@ void order_send(ap_list *ap)
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
sockfd =
|
sockfd =
|
||||||
create_udp_sending_socket(ap->ip_addr,
|
owl_create_udp_sending_socket(ap->ip_addr,
|
||||||
cfg_getint(cfg, "autocalibration_port"),
|
cfg_getint(cfg, "autocalibration_port"),
|
||||||
&serv, &client) ;
|
&serv, &client) ;
|
||||||
|
|
||||||
message.order = htonl(AUTOCALIBRATION_ORDER_SEND) ;
|
message.order = htonl(AUTOCALIBRATION_ORDER_SEND) ;
|
||||||
nsent = sendto(sockfd, (void *)&message, sizeof(message), 0,
|
nsent = sendto(sockfd, (void *)&message, sizeof(message), 0,
|
||||||
|
@ -1027,14 +1034,14 @@ void print_couple_list()
|
||||||
info_ptr = couple_ptr->info ; // Get the sub-list pointer
|
info_ptr = couple_ptr->info ; // Get the sub-list pointer
|
||||||
|
|
||||||
mobile_mac_string =
|
mobile_mac_string =
|
||||||
mac_bytes_to_string(couple_ptr->mobile_mac_addr_bytes) ;
|
owl_mac_bytes_to_string(couple_ptr->mobile_mac_addr_bytes) ;
|
||||||
printf("Mobile MAC: %s\n"
|
printf("Mobile MAC: %s\n"
|
||||||
"Sequence number: %"PRIu64"\n"
|
"Sequence number: %"PRIu64"\n"
|
||||||
"Reception timestamp: %"PRIu64"\n"
|
"Reception timestamp: %"PRIu64"\n"
|
||||||
"\n",
|
"\n",
|
||||||
mobile_mac_string,
|
mobile_mac_string,
|
||||||
timestamp_to_ms(couple_ptr->request_time),
|
owl_timestamp_to_ms(couple_ptr->request_time),
|
||||||
timestamp_to_ms(couple_ptr->start_time)
|
owl_timestamp_to_ms(couple_ptr->start_time)
|
||||||
) ;
|
) ;
|
||||||
free(mobile_mac_string) ;
|
free(mobile_mac_string) ;
|
||||||
|
|
||||||
|
@ -1063,7 +1070,7 @@ void print_couple_info(couple_info_list *info)
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
ap_mac_string = mac_bytes_to_string(info->ap_mac_addr_bytes) ;
|
ap_mac_string = owl_mac_bytes_to_string(info->ap_mac_addr_bytes) ;
|
||||||
printf("\tAP MAC: %s\n"
|
printf("\tAP MAC: %s\n"
|
||||||
"\tSignal strength: %d dBm\n",
|
"\tSignal strength: %d dBm\n",
|
||||||
ap_mac_string,
|
ap_mac_string,
|
||||||
|
|
|
@ -287,12 +287,12 @@ void make_packet()
|
||||||
uint_fast16_t offset ; // Index used to create the packet
|
uint_fast16_t offset ; // Index used to create the packet
|
||||||
TIMESTAMP request_time ;
|
TIMESTAMP request_time ;
|
||||||
|
|
||||||
timestamp_now(&request_time) ;
|
owl_timestamp_now(&request_time) ;
|
||||||
|
|
||||||
if (is_calibration_request) // Calibration packet
|
if (is_calibration_request) // Calibration packet
|
||||||
{
|
{
|
||||||
printf("Calibration time: %"PRIu64"\n",
|
printf("Calibration time: %"PRIu64"\n",
|
||||||
timestamp_to_ms(request_time)) ;
|
owl_timestamp_to_ms(request_time)) ;
|
||||||
|
|
||||||
offset = 0 ;
|
offset = 0 ;
|
||||||
packet_size =
|
packet_size =
|
||||||
|
@ -318,7 +318,7 @@ void make_packet()
|
||||||
else // Standard packet
|
else // Standard packet
|
||||||
{
|
{
|
||||||
printf("Request time: %"PRIu64"\n",
|
printf("Request time: %"PRIu64"\n",
|
||||||
timestamp_to_ms(request_time)) ;
|
owl_timestamp_to_ms(request_time)) ;
|
||||||
packet_size = sizeof(uint8_t) + sizeof(TIMESTAMP) ;
|
packet_size = sizeof(uint8_t) + sizeof(TIMESTAMP) ;
|
||||||
packet = malloc(packet_size) ;
|
packet = malloc(packet_size) ;
|
||||||
memset(&packet[0], PACKET_TYPE_NORMAL, 1) ; // Packet type
|
memset(&packet[0], PACKET_TYPE_NORMAL, 1) ; // Packet type
|
||||||
|
@ -341,7 +341,7 @@ void receive_position()
|
||||||
// Position of the mobile as computed by the infrastructure:
|
// Position of the mobile as computed by the infrastructure:
|
||||||
float x, y, z ;
|
float x, y, z ;
|
||||||
|
|
||||||
sockfd = create_udp_listening_socket(options.listening_port) ;
|
sockfd = owl_create_udp_listening_socket(options.listening_port) ;
|
||||||
recvfrom(sockfd, &x, sizeof(float), 0, NULL, NULL) ;
|
recvfrom(sockfd, &x, sizeof(float), 0, NULL, NULL) ;
|
||||||
recvfrom(sockfd, &y, sizeof(float), 0, NULL, NULL) ;
|
recvfrom(sockfd, &y, sizeof(float), 0, NULL, NULL) ;
|
||||||
recvfrom(sockfd, &z, sizeof(float), 0, NULL, NULL) ;
|
recvfrom(sockfd, &z, sizeof(float), 0, NULL, NULL) ;
|
||||||
|
|
|
@ -89,13 +89,13 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
/* Set up signal handlers */
|
/* Set up signal handlers */
|
||||||
sigemptyset(&action.sa_mask) ;
|
sigemptyset(&action.sa_mask) ;
|
||||||
action.sa_handler = sigint_handler ;
|
action.sa_handler = owl_sigint_handler ;
|
||||||
sigaction(SIGINT, &action, NULL) ;
|
sigaction(SIGINT, &action, NULL) ;
|
||||||
action.sa_handler = sigterm_handler ;
|
action.sa_handler = owl_sigterm_handler ;
|
||||||
sigaction(SIGTERM, &action, NULL) ;
|
sigaction(SIGTERM, &action, NULL) ;
|
||||||
|
|
||||||
get_mac_addr(GET_WIFI_IFACE(), my_mac_bytes) ;
|
get_mac_addr(GET_WIFI_IFACE(), my_mac_bytes) ;
|
||||||
mac_string = mac_bytes_to_string(my_mac_bytes) ;
|
mac_string = owl_mac_bytes_to_string(my_mac_bytes) ;
|
||||||
printf("My MAC address is: %s\n", mac_string) ;
|
printf("My MAC address is: %s\n", mac_string) ;
|
||||||
free(mac_string) ;
|
free(mac_string) ;
|
||||||
get_ip_addr(GET_WIFI_IFACE(), my_ip) ;
|
get_ip_addr(GET_WIFI_IFACE(), my_ip) ;
|
||||||
|
@ -465,7 +465,8 @@ void keep_mode_monitor(char *iface)
|
||||||
|
|
||||||
while (run)
|
while (run)
|
||||||
{
|
{
|
||||||
iface_mode_monitor(iface) ; // Switch the interface to monitor mode
|
// Switch the interface to monitor mode:
|
||||||
|
owl_iface_mode_monitor(iface) ;
|
||||||
sleep(1) ; // Wait for 1 second
|
sleep(1) ; // Wait for 1 second
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -622,12 +623,12 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||||
memcpy(couple.mobile_mac_addr_bytes, &packet[rtap_bytes+10], 6) ;
|
memcpy(couple.mobile_mac_addr_bytes, &packet[rtap_bytes+10], 6) ;
|
||||||
|
|
||||||
// Drop the packet if it comes from the AP itself:
|
// Drop the packet if it comes from the AP itself:
|
||||||
if (mac_equals(my_mac_bytes, couple.mobile_mac_addr_bytes))
|
if (owl_mac_equals(my_mac_bytes, couple.mobile_mac_addr_bytes))
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
memcpy(couple.ap_mac_addr_bytes, my_mac_bytes, 6) ; // Copy AP MAC
|
memcpy(couple.ap_mac_addr_bytes, my_mac_bytes, 6) ; // Copy AP MAC
|
||||||
// Capture time is in the pcap header:
|
// Capture time is in the pcap header:
|
||||||
couple.start_time = timeval_to_timestamp(header->ts) ;
|
couple.start_time = owl_timeval_to_timestamp(header->ts) ;
|
||||||
// Transmission time on the mobile is unknown (unless the packet is
|
// Transmission time on the mobile is unknown (unless the packet is
|
||||||
// an explicit request):
|
// an explicit request):
|
||||||
memset(&couple.request_time, 0, sizeof(TIMESTAMP)) ;
|
memset(&couple.request_time, 0, sizeof(TIMESTAMP)) ;
|
||||||
|
@ -811,9 +812,9 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||||
if (GET_DISPLAY_CAPTURED())
|
if (GET_DISPLAY_CAPTURED())
|
||||||
{
|
{
|
||||||
char *ap_mac_string =
|
char *ap_mac_string =
|
||||||
mac_bytes_to_string(couple.ap_mac_addr_bytes) ;
|
owl_mac_bytes_to_string(couple.ap_mac_addr_bytes) ;
|
||||||
char *mobile_mac_string =
|
char *mobile_mac_string =
|
||||||
mac_bytes_to_string(couple.mobile_mac_addr_bytes) ;
|
owl_mac_bytes_to_string(couple.mobile_mac_addr_bytes) ;
|
||||||
printf("*** Couple to send ***\n"
|
printf("*** Couple to send ***\n"
|
||||||
"\tMAC AP: %s\n"
|
"\tMAC AP: %s\n"
|
||||||
"\tMobile MAC: %s\n"
|
"\tMobile MAC: %s\n"
|
||||||
|
@ -827,8 +828,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||||
,
|
,
|
||||||
ap_mac_string,
|
ap_mac_string,
|
||||||
mobile_mac_string,
|
mobile_mac_string,
|
||||||
timestamp_to_ms(couple.request_time),
|
owl_timestamp_to_ms(couple.request_time),
|
||||||
timestamp_to_ms(couple.start_time),
|
owl_timestamp_to_ms(couple.start_time),
|
||||||
couple.antenna_signal_dbm - 0x100,
|
couple.antenna_signal_dbm - 0x100,
|
||||||
couple.x_position,
|
couple.x_position,
|
||||||
couple.y_position,
|
couple.y_position,
|
||||||
|
@ -960,7 +961,7 @@ void autocalibrate()
|
||||||
|
|
||||||
// Socket to receive orders from the aggregator
|
// Socket to receive orders from the aggregator
|
||||||
listen_sockfd =
|
listen_sockfd =
|
||||||
create_udp_listening_socket(GET_AUTOCALIBRATION_PORT()) ;
|
owl_create_udp_listening_socket(GET_AUTOCALIBRATION_PORT()) ;
|
||||||
if (listen_sockfd < 0)
|
if (listen_sockfd < 0)
|
||||||
{
|
{
|
||||||
perror("Error! Cannot create UDP listening socket from the"
|
perror("Error! Cannot create UDP listening socket from the"
|
||||||
|
@ -1024,11 +1025,11 @@ uint_fast16_t make_packet(uint8_t **packet)
|
||||||
uint_fast16_t size ; // Packet size
|
uint_fast16_t size ; // Packet size
|
||||||
TIMESTAMP request_time ;
|
TIMESTAMP request_time ;
|
||||||
|
|
||||||
timestamp_now(&request_time) ;
|
owl_timestamp_now(&request_time) ;
|
||||||
|
|
||||||
if (GET_VERBOSE())
|
if (GET_VERBOSE())
|
||||||
printf("Autocalibration time: %"PRIu64"\n",
|
printf("Autocalibration time: %"PRIu64"\n",
|
||||||
timestamp_to_ms(request_time)) ;
|
owl_timestamp_to_ms(request_time)) ;
|
||||||
|
|
||||||
size = sizeof(char) + sizeof(TIMESTAMP) ;
|
size = sizeof(char) + sizeof(TIMESTAMP) ;
|
||||||
pkt = malloc(size) ;
|
pkt = malloc(size) ;
|
||||||
|
|
|
@ -17,7 +17,7 @@ BOOL run = TRUE ;
|
||||||
* Converts a MAC address from bytes to string.
|
* Converts a MAC address from bytes to string.
|
||||||
* /!\ You *must* manually free the returned string /!\
|
* /!\ You *must* manually free the returned string /!\
|
||||||
*/
|
*/
|
||||||
char* mac_bytes_to_string(uint8_t *mac_binary)
|
char* owl_mac_bytes_to_string(uint8_t *mac_binary)
|
||||||
{
|
{
|
||||||
char *ret = malloc(sizeof(char) * 18) ;
|
char *ret = malloc(sizeof(char) * 18) ;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ char* mac_bytes_to_string(uint8_t *mac_binary)
|
||||||
* Converts a IEEE 802.11 frequency into a channel number.
|
* Converts a IEEE 802.11 frequency into a channel number.
|
||||||
* Returns 0 if the frequency does not correspond to an official channel.
|
* Returns 0 if the frequency does not correspond to an official channel.
|
||||||
*/
|
*/
|
||||||
uint_fast8_t frequency_to_channel(uint_fast16_t channel)
|
uint_fast8_t owl_frequency_to_channel(uint_fast16_t channel)
|
||||||
{
|
{
|
||||||
uint_fast8_t c = 0 ; // Result
|
uint_fast8_t c = 0 ; // Result
|
||||||
|
|
||||||
|
@ -93,10 +93,10 @@ uint_fast8_t frequency_to_channel(uint_fast16_t channel)
|
||||||
/*
|
/*
|
||||||
* Set the TIMESTAMP 'now' at the current time (millisecond-precision).
|
* Set the TIMESTAMP 'now' at the current time (millisecond-precision).
|
||||||
*/
|
*/
|
||||||
void timestamp_now(TIMESTAMP *now)
|
void owl_timestamp_now(TIMESTAMP *now)
|
||||||
{
|
{
|
||||||
if (! timestamp_now_ns(now))
|
if (! owl_timestamp_now_ns(now))
|
||||||
timestamp_round_to_ms(now) ;
|
owl_timestamp_round_to_ms(now) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ void timestamp_now(TIMESTAMP *now)
|
||||||
/*
|
/*
|
||||||
* Set the TIMESTAMP 'now' at the current time (nanosecond-precision).
|
* Set the TIMESTAMP 'now' at the current time (nanosecond-precision).
|
||||||
*/
|
*/
|
||||||
int timestamp_now_ns(TIMESTAMP *now)
|
int owl_timestamp_now_ns(TIMESTAMP *now)
|
||||||
{
|
{
|
||||||
int ret ;
|
int ret ;
|
||||||
if ((ret = clock_gettime(CLOCK_REALTIME, now)))
|
if ((ret = clock_gettime(CLOCK_REALTIME, now)))
|
||||||
|
@ -120,7 +120,7 @@ int timestamp_now_ns(TIMESTAMP *now)
|
||||||
/*
|
/*
|
||||||
* Lower the precision of 'now' to milliseconds.
|
* Lower the precision of 'now' to milliseconds.
|
||||||
*/
|
*/
|
||||||
void timestamp_round_to_ms(TIMESTAMP *now)
|
void owl_timestamp_round_to_ms(TIMESTAMP *now)
|
||||||
{
|
{
|
||||||
now->tv_nsec = now->tv_nsec / 1000000 * 1000000 ;
|
now->tv_nsec = now->tv_nsec / 1000000 * 1000000 ;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ void timestamp_round_to_ms(TIMESTAMP *now)
|
||||||
/*
|
/*
|
||||||
* Returns a TIMESTAMP from a struct timeval.
|
* Returns a TIMESTAMP from a struct timeval.
|
||||||
*/
|
*/
|
||||||
TIMESTAMP timeval_to_timestamp(const struct timeval d)
|
TIMESTAMP owl_timeval_to_timestamp(const struct timeval d)
|
||||||
{
|
{
|
||||||
TIMESTAMP res ;
|
TIMESTAMP res ;
|
||||||
res.tv_sec = d.tv_sec ;
|
res.tv_sec = d.tv_sec ;
|
||||||
|
@ -143,7 +143,7 @@ TIMESTAMP timeval_to_timestamp(const struct timeval d)
|
||||||
/*
|
/*
|
||||||
* Converts a TIMESTAMP date value into milliseconds.
|
* Converts a TIMESTAMP date value into milliseconds.
|
||||||
*/
|
*/
|
||||||
uint64_t timestamp_to_ms(TIMESTAMP d)
|
uint64_t owl_timestamp_to_ms(TIMESTAMP d)
|
||||||
{
|
{
|
||||||
return d.tv_sec * 1000 + d.tv_nsec / 1000000 ;
|
return d.tv_sec * 1000 + d.tv_nsec / 1000000 ;
|
||||||
}
|
}
|
||||||
|
@ -153,13 +153,14 @@ uint64_t timestamp_to_ms(TIMESTAMP d)
|
||||||
/*
|
/*
|
||||||
* Returns the time (in milliseconds) between two dates.
|
* Returns the time (in milliseconds) between two dates.
|
||||||
*/
|
*/
|
||||||
uint_fast32_t time_elapsed(TIMESTAMP sup, TIMESTAMP inf)
|
uint_fast32_t owl_time_elapsed(TIMESTAMP sup, TIMESTAMP inf)
|
||||||
{
|
{
|
||||||
uint_fast32_t sub = abs(timestamp_to_ms(sup) - timestamp_to_ms(inf)) ;
|
uint_fast32_t elapsed_ms =
|
||||||
|
abs(owl_timestamp_to_ms(sup) - owl_timestamp_to_ms(inf)) ;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("time_elapsed(): %"PRIuFAST32"\n", sub) ;
|
printf("time_elapsed(): %"PRIuFAST32"ms\n", elapsed_ms) ;
|
||||||
#endif
|
#endif
|
||||||
return sub ;
|
return elapsed_ms ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,7 +169,7 @@ uint_fast32_t time_elapsed(TIMESTAMP sup, TIMESTAMP inf)
|
||||||
* Compares two MAC addresses.
|
* Compares two MAC addresses.
|
||||||
* Returns TRUE if they are identical, FALSE otherwise.
|
* Returns TRUE if they are identical, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
BOOL mac_equals(uint8_t *mac1, uint8_t *mac2)
|
BOOL owl_mac_equals(uint8_t *mac1, uint8_t *mac2)
|
||||||
{
|
{
|
||||||
int i ;
|
int i ;
|
||||||
for(i=0 ; i < 6 ; i++)
|
for(i=0 ; i < 6 ; i++)
|
||||||
|
@ -189,10 +190,10 @@ BOOL mac_equals(uint8_t *mac1, uint8_t *mac2)
|
||||||
* - client_description (in/out): the structure in which the client
|
* - client_description (in/out): the structure in which the client
|
||||||
* description will be saved.
|
* description will be saved.
|
||||||
*/
|
*/
|
||||||
int create_udp_sending_socket(char *server_address,
|
int owl_create_udp_sending_socket(char *server_address,
|
||||||
uint_fast16_t server_port,
|
uint_fast16_t server_port,
|
||||||
struct sockaddr_in *server_description,
|
struct sockaddr_in *server_description,
|
||||||
struct sockaddr_in * client_description)
|
struct sockaddr_in *client_description)
|
||||||
{
|
{
|
||||||
int sockfd ; // Socket descriptor
|
int sockfd ; // Socket descriptor
|
||||||
|
|
||||||
|
@ -227,7 +228,7 @@ int create_udp_sending_socket(char *server_address,
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* - port: port on which the socket listens.
|
* - port: port on which the socket listens.
|
||||||
*/
|
*/
|
||||||
int create_udp_listening_socket(uint_fast16_t port)
|
int owl_create_udp_listening_socket(uint_fast16_t port)
|
||||||
{
|
{
|
||||||
int sockfd ; // Socket descriptor
|
int sockfd ; // Socket descriptor
|
||||||
struct sockaddr_in server_description ; // Server structure
|
struct sockaddr_in server_description ; // Server structure
|
||||||
|
@ -266,7 +267,7 @@ int create_udp_listening_socket(uint_fast16_t port)
|
||||||
/*
|
/*
|
||||||
* Switches the IEEE 802.11 interface 'iface' to Monitor mode.
|
* Switches the IEEE 802.11 interface 'iface' to Monitor mode.
|
||||||
*/
|
*/
|
||||||
int iface_mode_monitor(char *iface)
|
int owl_iface_mode_monitor(char *iface)
|
||||||
{
|
{
|
||||||
struct iwreq wrq ;
|
struct iwreq wrq ;
|
||||||
int sockfd = iw_sockets_open() ;
|
int sockfd = iw_sockets_open() ;
|
||||||
|
@ -301,7 +302,7 @@ int iface_mode_monitor(char *iface)
|
||||||
* Sets the IEEE 802.11 channel of the interface 'iface'.
|
* Sets the IEEE 802.11 channel of the interface 'iface'.
|
||||||
* 'channel' must be an integer between 1 and 14.
|
* 'channel' must be an integer between 1 and 14.
|
||||||
*/
|
*/
|
||||||
int iface_set_channel(char *iface, uint_fast8_t channel)
|
int owl_iface_set_channel(char *iface, uint_fast8_t channel)
|
||||||
{
|
{
|
||||||
struct iwreq wrq ;
|
struct iwreq wrq ;
|
||||||
int sockfd = iw_sockets_open() ;
|
int sockfd = iw_sockets_open() ;
|
||||||
|
@ -327,7 +328,7 @@ int iface_set_channel(char *iface, uint_fast8_t channel)
|
||||||
* Switches alternatively the Wi-Fi channel of the IEEE 802.11 interface
|
* Switches alternatively the Wi-Fi channel of the IEEE 802.11 interface
|
||||||
* 'iface' to 4 or 11.
|
* 'iface' to 4 or 11.
|
||||||
*/
|
*/
|
||||||
int iface_channel_hop(char *iface)
|
int owl_iface_channel_hop(char *iface)
|
||||||
{
|
{
|
||||||
uint_fast16_t channel ;
|
uint_fast16_t channel ;
|
||||||
struct iwreq wrq ;
|
struct iwreq wrq ;
|
||||||
|
@ -345,16 +346,16 @@ int iface_channel_hop(char *iface)
|
||||||
channel = wrq.u.freq.m / 100000 ;
|
channel = wrq.u.freq.m / 100000 ;
|
||||||
|
|
||||||
if (channel > 1000) // If the value is in Hz, we convert it to a
|
if (channel > 1000) // If the value is in Hz, we convert it to a
|
||||||
channel = frequency_to_channel(channel) ; // channel number
|
channel = owl_frequency_to_channel(channel) ; // channel number
|
||||||
// (with our own function, still not very clean).
|
// (with our own function, still not very clean).
|
||||||
|
|
||||||
close(sockfd) ;
|
close(sockfd) ;
|
||||||
|
|
||||||
/* Switch the canal */
|
/* Switch the canal */
|
||||||
if (channel == 4) // If channel is 4
|
if (channel == 4) // If channel is 4
|
||||||
return iface_set_channel(iface, 11) ; // switch to 11 ;
|
return owl_iface_set_channel(iface, 11) ; // switch to 11 ;
|
||||||
else
|
else
|
||||||
return iface_set_channel(iface, 4) ; // else, set it to 4.
|
return owl_iface_set_channel(iface, 4) ; // else, set it to 4.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -362,7 +363,7 @@ int iface_channel_hop(char *iface)
|
||||||
/*
|
/*
|
||||||
* Generic signal handler for SIGINT.
|
* Generic signal handler for SIGINT.
|
||||||
*/
|
*/
|
||||||
void sigint_handler(int num)
|
void owl_sigint_handler(int num)
|
||||||
{
|
{
|
||||||
if (num != SIGINT)
|
if (num != SIGINT)
|
||||||
{
|
{
|
||||||
|
@ -382,7 +383,7 @@ void sigint_handler(int num)
|
||||||
|
|
||||||
|
|
||||||
/* Gestionnaire de signal générique pour SIGTERM */
|
/* Gestionnaire de signal générique pour SIGTERM */
|
||||||
void sigterm_handler(int num)
|
void owl_sigterm_handler(int num)
|
||||||
{
|
{
|
||||||
if (num != SIGTERM)
|
if (num != SIGTERM)
|
||||||
{
|
{
|
||||||
|
@ -391,5 +392,5 @@ void sigterm_handler(int num)
|
||||||
exit(ERR_BAD_SIGNAL) ;
|
exit(ERR_BAD_SIGNAL) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
sigint_handler(SIGINT) ;
|
owl_sigint_handler(SIGINT) ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,31 +218,31 @@ BOOL run ;
|
||||||
|
|
||||||
/* Function headers */
|
/* Function headers */
|
||||||
// Misc
|
// Misc
|
||||||
char* mac_bytes_to_string(uint8_t *mac_binary) ;
|
char* owl_mac_bytes_to_string(uint8_t *mac_binary) ;
|
||||||
BOOL mac_equals(uint8_t *mac1, uint8_t *mac2) ;
|
BOOL owl_mac_equals(uint8_t *mac1, uint8_t *mac2) ;
|
||||||
uint_fast8_t frequency_to_channel(uint_fast16_t channel) ;
|
uint_fast8_t owl_frequency_to_channel(uint_fast16_t channel) ;
|
||||||
|
|
||||||
// Time
|
// Time
|
||||||
void timestamp_now(TIMESTAMP *now) ;
|
void owl_timestamp_now(TIMESTAMP *now) ;
|
||||||
int timestamp_now_ns(TIMESTAMP *now) ;
|
int owl_timestamp_now_ns(TIMESTAMP *now) ;
|
||||||
void timestamp_round_to_ms(TIMESTAMP *now) ;
|
void owl_timestamp_round_to_ms(TIMESTAMP *now) ;
|
||||||
TIMESTAMP timeval_to_timestamp(const struct timeval d) ;
|
TIMESTAMP owl_timeval_to_timestamp(const struct timeval d) ;
|
||||||
uint64_t timestamp_to_ms(TIMESTAMP date) ;
|
uint64_t owl_timestamp_to_ms(TIMESTAMP date) ;
|
||||||
uint_fast32_t time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;
|
uint_fast32_t owl_time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;
|
||||||
|
|
||||||
// Network
|
// Network
|
||||||
int create_udp_sending_socket(char *server_address,
|
int owl_create_udp_sending_socket(char *server_address,
|
||||||
uint_fast16_t server_port,
|
uint_fast16_t server_port,
|
||||||
struct sockaddr_in *server_description,
|
struct sockaddr_in *server_description,
|
||||||
struct sockaddr_in * client_description) ;
|
struct sockaddr_in *client_description) ;
|
||||||
int create_udp_listening_socket(uint_fast16_t port) ;
|
int owl_create_udp_listening_socket(uint_fast16_t port) ;
|
||||||
int iface_mode_monitor(char *iface) ;
|
int owl_iface_mode_monitor(char *iface) ;
|
||||||
int iface_set_channel(char *iface, uint_fast8_t channel) ;
|
int owl_iface_set_channel(char *iface, uint_fast8_t channel) ;
|
||||||
int iface_channel_hop(char *iface) ;
|
int owl_iface_channel_hop(char *iface) ;
|
||||||
|
|
||||||
// Signals
|
// Signals
|
||||||
void sigint_handler(int num) ;
|
void owl_sigint_handler(int num) ;
|
||||||
void sigterm_handler(int num) ;
|
void owl_sigterm_handler(int num) ;
|
||||||
|
|
||||||
|
|
||||||
/* Macros */
|
/* Macros */
|
||||||
|
|
Loading…
Reference in New Issue