[lib] Introduce type TIMESTAMP
The type TIMESTAMP is a wrapper to the currently-used time structure (we currently use struct timeval). The function timeval_to_ms() is now timestamp_to_ms().
This commit is contained in:
parent
3331a6685f
commit
ff81d43cb1
|
@ -49,7 +49,7 @@ typedef struct _couple_list
|
||||||
{
|
{
|
||||||
/* Numéro de séquence de la demande de localisation du mobile */
|
/* Numéro de séquence de la demande de localisation du mobile */
|
||||||
unsigned char mobile_mac_addr_bytes[6] ; // Mobile MAC address (in bytes)
|
unsigned char mobile_mac_addr_bytes[6] ; // Mobile MAC address (in bytes)
|
||||||
struct timeval request_time ; // Request time on the mobile
|
TIMESTAMP request_time ; // Request time on the mobile
|
||||||
|
|
||||||
/* Calibration data */
|
/* Calibration data */
|
||||||
float x_position ;
|
float x_position ;
|
||||||
|
@ -59,7 +59,7 @@ typedef struct _couple_list
|
||||||
|
|
||||||
/* Other data */
|
/* Other data */
|
||||||
// Arrival time of the first packet of the couple on the aggregator:
|
// Arrival time of the first packet of the couple on the aggregator:
|
||||||
struct timeval start_time ;
|
TIMESTAMP start_time ;
|
||||||
couple_info_list *info ; // Data for this couple
|
couple_info_list *info ; // Data for this couple
|
||||||
|
|
||||||
struct _couple_list *next ;
|
struct _couple_list *next ;
|
||||||
|
@ -72,7 +72,7 @@ typedef struct _ap_list
|
||||||
unsigned char mac_addr_bytes[6] ;
|
unsigned char mac_addr_bytes[6] ;
|
||||||
char ip_addr[16] ;
|
char ip_addr[16] ;
|
||||||
|
|
||||||
struct timeval last_seen ;
|
TIMESTAMP last_seen ;
|
||||||
|
|
||||||
struct _ap_list *previous ;
|
struct _ap_list *previous ;
|
||||||
struct _ap_list *next ;
|
struct _ap_list *next ;
|
||||||
|
|
|
@ -348,8 +348,8 @@ int read_loop(int sockfd)
|
||||||
ap_mac_string,
|
ap_mac_string,
|
||||||
mobile_mac_string,
|
mobile_mac_string,
|
||||||
mobile_ip_string,
|
mobile_ip_string,
|
||||||
timeval_to_ms(message.request_time),
|
timestamp_to_ms(message.request_time),
|
||||||
timeval_to_ms(message.start_time),
|
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,
|
||||||
|
@ -387,7 +387,7 @@ void* monitor_couples()
|
||||||
{
|
{
|
||||||
couple_list *couple_ptr, *couple_prev ;
|
couple_list *couple_ptr, *couple_prev ;
|
||||||
couple_info_list *couple_info_ptr ;
|
couple_info_list *couple_info_ptr ;
|
||||||
struct timeval current_time ;
|
TIMESTAMP current_time ;
|
||||||
FILE *fd = NULL ;
|
FILE *fd = NULL ;
|
||||||
char *mac_string ;
|
char *mac_string ;
|
||||||
unsigned long sub ; // time_elapsed() result
|
unsigned long sub ; // time_elapsed() result
|
||||||
|
@ -449,7 +449,7 @@ 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, "%llu;",
|
fprintf(fd, "%llu;",
|
||||||
timeval_to_ms(couple_ptr->request_time)) ;
|
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
|
||||||
|
@ -560,7 +560,7 @@ void got_couple_info(couple_message message)
|
||||||
{
|
{
|
||||||
couple_list *tmp_couple = NULL ;
|
couple_list *tmp_couple = NULL ;
|
||||||
couple_info_list *tmp_info = NULL ;
|
couple_info_list *tmp_info = NULL ;
|
||||||
struct timeval start_time ; // Reception time on the aggregator
|
TIMESTAMP start_time ; // Reception time on the aggregator
|
||||||
|
|
||||||
gettimeofday(&start_time, NULL) ;
|
gettimeofday(&start_time, NULL) ;
|
||||||
|
|
||||||
|
@ -578,7 +578,7 @@ 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 (timeval_to_ms(message.request_time) != 0) // Explicit packet
|
if (timestamp_to_ms(message.request_time) != 0) // Explicit packet
|
||||||
// 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
|
else // Implicit packet
|
||||||
|
@ -598,7 +598,7 @@ 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 (timeval_to_ms(message.request_time) != 0) // Explicit packet
|
if (timestamp_to_ms(message.request_time) != 0) // Explicit packet
|
||||||
{
|
{
|
||||||
while (tmp_couple != NULL)
|
while (tmp_couple != NULL)
|
||||||
{ // Research criterion: MAC and transmission time
|
{ // Research criterion: MAC and transmission time
|
||||||
|
@ -631,7 +631,7 @@ 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 (timeval_to_ms(message.request_time) != 0) // Explicit packet
|
if (timestamp_to_ms(message.request_time) != 0) // Explicit packet
|
||||||
// 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
|
else // Implicit packet
|
||||||
|
@ -883,7 +883,7 @@ void monitor_aps()
|
||||||
*/
|
*/
|
||||||
void delete_old_aps()
|
void delete_old_aps()
|
||||||
{
|
{
|
||||||
struct timeval now ;
|
TIMESTAMP now ;
|
||||||
|
|
||||||
gettimeofday(&now, NULL) ;
|
gettimeofday(&now, NULL) ;
|
||||||
|
|
||||||
|
@ -1031,8 +1031,8 @@ void print_couple_list()
|
||||||
"Reception timestamp: %llu\n"
|
"Reception timestamp: %llu\n"
|
||||||
"\n",
|
"\n",
|
||||||
mobile_mac_string,
|
mobile_mac_string,
|
||||||
timeval_to_ms(couple_ptr->request_time),
|
timestamp_to_ms(couple_ptr->request_time),
|
||||||
timeval_to_ms(couple_ptr->start_time)
|
timestamp_to_ms(couple_ptr->start_time)
|
||||||
) ;
|
) ;
|
||||||
free(mobile_mac_string) ;
|
free(mobile_mac_string) ;
|
||||||
|
|
||||||
|
|
|
@ -284,17 +284,17 @@ void create_socket()
|
||||||
void make_packet()
|
void make_packet()
|
||||||
{
|
{
|
||||||
int offset ; // Index used to create the packet
|
int offset ; // Index used to create the packet
|
||||||
struct timeval request_time ;
|
TIMESTAMP request_time ;
|
||||||
|
|
||||||
gettimeofday(&request_time, NULL) ;
|
gettimeofday(&request_time, NULL) ;
|
||||||
|
|
||||||
if (is_calibration_request) // Calibration packet
|
if (is_calibration_request) // Calibration packet
|
||||||
{
|
{
|
||||||
printf("Calibration time: %llu\n", timeval_to_ms(request_time)) ;
|
printf("Calibration time: %llu\n", timestamp_to_ms(request_time)) ;
|
||||||
|
|
||||||
offset = 0 ;
|
offset = 0 ;
|
||||||
packet_size =
|
packet_size =
|
||||||
sizeof(char) * 2 + sizeof(struct timeval) + sizeof(float) * 3 ;
|
sizeof(char) * 2 + sizeof(TIMESTAMP) + sizeof(float) * 3 ;
|
||||||
packet = malloc(packet_size) ;
|
packet = malloc(packet_size) ;
|
||||||
|
|
||||||
packet[offset++] = PACKET_TYPE_CALIBRATION ; // Packet type
|
packet[offset++] = PACKET_TYPE_CALIBRATION ; // Packet type
|
||||||
|
@ -314,8 +314,8 @@ void make_packet()
|
||||||
|
|
||||||
else // Standard packet
|
else // Standard packet
|
||||||
{
|
{
|
||||||
printf("Request time: %llu\n", timeval_to_ms(request_time)) ;
|
printf("Request time: %llu\n", timestamp_to_ms(request_time)) ;
|
||||||
packet_size = sizeof(char) + sizeof(struct timeval) ;
|
packet_size = sizeof(char) + sizeof(TIMESTAMP) ;
|
||||||
packet = malloc(packet_size) ;
|
packet = malloc(packet_size) ;
|
||||||
packet[0] = PACKET_TYPE_NORMAL ; // Packet type
|
packet[0] = PACKET_TYPE_NORMAL ; // Packet type
|
||||||
memcpy(&packet[1], &request_time, sizeof(request_time)) ;
|
memcpy(&packet[1], &request_time, sizeof(request_time)) ;
|
||||||
|
|
|
@ -706,7 +706,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||||
memcpy(&couple.request_time,
|
memcpy(&couple.request_time,
|
||||||
&data[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE
|
&data[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE
|
||||||
+ sizeof(struct iphdr) + sizeof(struct udphdr) + 1],
|
+ sizeof(struct iphdr) + sizeof(struct udphdr) + 1],
|
||||||
sizeof(struct timeval)) ;
|
sizeof(TIMESTAMP)) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (GET_MODE() == MODE_PASSIVE || GET_MODE() == MODE_MIXED)
|
else if (GET_MODE() == MODE_PASSIVE || GET_MODE() == MODE_MIXED)
|
||||||
|
@ -829,8 +829,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||||
,
|
,
|
||||||
ap_mac_string,
|
ap_mac_string,
|
||||||
mobile_mac_string,
|
mobile_mac_string,
|
||||||
timeval_to_ms(couple.request_time),
|
timestamp_to_ms(couple.request_time),
|
||||||
timeval_to_ms(couple.start_time),
|
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,
|
||||||
|
@ -1023,14 +1023,15 @@ int make_packet(char **packet)
|
||||||
{
|
{
|
||||||
char *pkt ;
|
char *pkt ;
|
||||||
int size ; // Packet size
|
int size ; // Packet size
|
||||||
struct timeval request_time ;
|
TIMESTAMP request_time ;
|
||||||
|
|
||||||
gettimeofday(&request_time, NULL) ;
|
gettimeofday(&request_time, NULL) ;
|
||||||
|
|
||||||
if (GET_VERBOSE())
|
if (GET_VERBOSE())
|
||||||
printf("Autocalibration time: %llu\n", timeval_to_ms(request_time)) ;
|
printf("Autocalibration time: %llu\n",
|
||||||
|
timestamp_to_ms(request_time)) ;
|
||||||
|
|
||||||
size = sizeof(char) + sizeof(struct timeval) ;
|
size = sizeof(char) + sizeof(TIMESTAMP) ;
|
||||||
pkt = malloc(size) ;
|
pkt = malloc(size) ;
|
||||||
|
|
||||||
pkt[0] = PACKET_TYPE_AUTOCALIBRATION ; // Packet type
|
pkt[0] = PACKET_TYPE_AUTOCALIBRATION ; // Packet type
|
||||||
|
|
|
@ -91,9 +91,9 @@ char frequency_to_channel(unsigned short channel)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Converts a struct timeval date value into milliseconds.
|
* Converts a TIMESTAMP date value into milliseconds.
|
||||||
*/
|
*/
|
||||||
unsigned long long timeval_to_ms(struct timeval d)
|
unsigned long long timestamp_to_ms(TIMESTAMP d)
|
||||||
{
|
{
|
||||||
return d.tv_sec * 1000 + d.tv_usec / 1000 ;
|
return d.tv_sec * 1000 + d.tv_usec / 1000 ;
|
||||||
}
|
}
|
||||||
|
@ -101,11 +101,11 @@ unsigned long long timeval_to_ms(struct timeval d)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Converts a date value in milliseconds into a struct timeval.
|
* Converts a date value in milliseconds into a TIMESTAMP.
|
||||||
*
|
*
|
||||||
struct timeval ms_to_timeval(unsigned long long tms)
|
TIMESTAMP ms_to_timestamp(unsigned long long tms)
|
||||||
{
|
{
|
||||||
struct timeval d ;
|
TIMESTAMP d ;
|
||||||
d.tv_sec = tms / 1000 ;
|
d.tv_sec = tms / 1000 ;
|
||||||
d.tv_usec = (tms - d.tv_sec * 1000) * 1000 ;
|
d.tv_usec = (tms - d.tv_sec * 1000) * 1000 ;
|
||||||
return d ;
|
return d ;
|
||||||
|
@ -117,9 +117,9 @@ struct timeval ms_to_timeval(unsigned long long tms)
|
||||||
/*
|
/*
|
||||||
* Returns the time (in milliseconds) between two dates.
|
* Returns the time (in milliseconds) between two dates.
|
||||||
*/
|
*/
|
||||||
unsigned long time_elapsed(struct timeval sup, struct timeval inf)
|
unsigned long time_elapsed(TIMESTAMP sup, TIMESTAMP inf)
|
||||||
{
|
{
|
||||||
unsigned long sub = abs(timeval_to_ms(sup) - timeval_to_ms(inf)) ;
|
unsigned long sub = abs(timestamp_to_ms(sup) - timestamp_to_ms(inf)) ;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("time_elapsed(): %lu\n", sub) ;
|
printf("time_elapsed(): %lu\n", sub) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -60,14 +60,18 @@ typedef enum {FALSE, TRUE} BOOL ;
|
||||||
typedef enum {NORTH = 1, EAST, SOUTH, WEST} DIRECTION ;
|
typedef enum {NORTH = 1, EAST, SOUTH, WEST} DIRECTION ;
|
||||||
|
|
||||||
|
|
||||||
|
/* Timestamp type */
|
||||||
|
typedef struct timeval TIMESTAMP ;
|
||||||
|
|
||||||
|
|
||||||
/* Message sent by the listener to the aggregator */
|
/* Message sent by the listener to the aggregator */
|
||||||
typedef struct _couple_message
|
typedef struct _couple_message
|
||||||
{
|
{
|
||||||
unsigned char ap_mac_addr_bytes[6] ; // MAC of the listener
|
unsigned char ap_mac_addr_bytes[6] ; // MAC of the listener
|
||||||
unsigned char mobile_mac_addr_bytes[6] ; // MAC of the mobile involved
|
unsigned char mobile_mac_addr_bytes[6] ; // MAC of the mobile involved
|
||||||
unsigned char mobile_ip_addr_bytes[4] ; // IP of the mobile
|
unsigned char mobile_ip_addr_bytes[4] ; // IP of the mobile
|
||||||
struct timeval request_time ; // Request ID (timestamp on the mobile)
|
TIMESTAMP request_time ; // Request ID (timestamp on the mobile)
|
||||||
struct timeval start_time ; // Timestamp of arrival on the listener
|
TIMESTAMP start_time ; // Timestamp of arrival on the listener
|
||||||
unsigned char antenna_signal_dbm ; // Signal strength measured by the listener
|
unsigned char antenna_signal_dbm ; // Signal strength measured by the listener
|
||||||
/* Calibration data */
|
/* Calibration data */
|
||||||
float x_position ;
|
float x_position ;
|
||||||
|
@ -85,7 +89,7 @@ typedef struct _couple_info
|
||||||
typedef struct _request
|
typedef struct _request
|
||||||
{
|
{
|
||||||
unsigned char mobile_mac_addr_bytes[6]; // MAC of the mobile
|
unsigned char mobile_mac_addr_bytes[6]; // MAC of the mobile
|
||||||
struct timeval request_time; // Request ID (timestamp on the mobile)
|
TIMESTAMP request_time ; // Request ID (timestamp on the mobile)
|
||||||
int nb_couples; // Number of (listener MAC;signal strength) couples
|
int nb_couples; // Number of (listener MAC;signal strength) couples
|
||||||
} request;
|
} request;
|
||||||
|
|
||||||
|
@ -219,8 +223,8 @@ BOOL mac_equals(unsigned char *mac1, unsigned char *mac2) ;
|
||||||
char frequency_to_channel(unsigned short channel) ;
|
char frequency_to_channel(unsigned short channel) ;
|
||||||
|
|
||||||
// Time
|
// Time
|
||||||
unsigned long long timeval_to_ms(struct timeval date) ;
|
unsigned long long timestamp_to_ms(TIMESTAMP date) ;
|
||||||
unsigned long time_elapsed(struct timeval sup, struct timeval inf) ;
|
unsigned long time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;
|
||||||
|
|
||||||
// Network
|
// Network
|
||||||
int create_udp_sending_socket(char *server_address, int server_port,
|
int create_udp_sending_socket(char *server_address, int server_port,
|
||||||
|
|
|
@ -19,7 +19,7 @@ int capture(char *capture_iface, unsigned long capture_time, mac_list **results,
|
||||||
{
|
{
|
||||||
pcap_t *handle ; // Descripteur de capture de paquets
|
pcap_t *handle ; // Descripteur de capture de paquets
|
||||||
char errbuf[PCAP_ERRBUF_SIZE] ; // Message d'erreur
|
char errbuf[PCAP_ERRBUF_SIZE] ; // Message d'erreur
|
||||||
struct timeval tbegin, tcurrent ;
|
TIMESTAMP tbegin, tcurrent ;
|
||||||
|
|
||||||
|
|
||||||
/* Sous-fonction de traitement des paquets capturés */
|
/* Sous-fonction de traitement des paquets capturés */
|
||||||
|
|
Loading…
Reference in New Issue