[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 */
|
||||
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 */
|
||||
float x_position ;
|
||||
|
@ -59,7 +59,7 @@ typedef struct _couple_list
|
|||
|
||||
/* Other data */
|
||||
// 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
|
||||
|
||||
struct _couple_list *next ;
|
||||
|
@ -72,7 +72,7 @@ typedef struct _ap_list
|
|||
unsigned char mac_addr_bytes[6] ;
|
||||
char ip_addr[16] ;
|
||||
|
||||
struct timeval last_seen ;
|
||||
TIMESTAMP last_seen ;
|
||||
|
||||
struct _ap_list *previous ;
|
||||
struct _ap_list *next ;
|
||||
|
|
|
@ -348,8 +348,8 @@ int read_loop(int sockfd)
|
|||
ap_mac_string,
|
||||
mobile_mac_string,
|
||||
mobile_ip_string,
|
||||
timeval_to_ms(message.request_time),
|
||||
timeval_to_ms(message.start_time),
|
||||
timestamp_to_ms(message.request_time),
|
||||
timestamp_to_ms(message.start_time),
|
||||
message.antenna_signal_dbm - 0x100,
|
||||
message.x_position,
|
||||
message.y_position,
|
||||
|
@ -387,7 +387,7 @@ void* monitor_couples()
|
|||
{
|
||||
couple_list *couple_ptr, *couple_prev ;
|
||||
couple_info_list *couple_info_ptr ;
|
||||
struct timeval current_time ;
|
||||
TIMESTAMP current_time ;
|
||||
FILE *fd = NULL ;
|
||||
char *mac_string ;
|
||||
unsigned long sub ; // time_elapsed() result
|
||||
|
@ -449,7 +449,7 @@ void* monitor_couples()
|
|||
#ifdef USE_TIMESTAMP
|
||||
// Print request mobile timestamp to the output file
|
||||
fprintf(fd, "%llu;",
|
||||
timeval_to_ms(couple_ptr->request_time)) ;
|
||||
timestamp_to_ms(couple_ptr->request_time)) ;
|
||||
#endif // USE_TIMESTAMP
|
||||
|
||||
// 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_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) ;
|
||||
|
||||
|
@ -578,7 +578,7 @@ void got_couple_info(couple_message message)
|
|||
tmp_couple = malloc(sizeof(couple_list)) ; // create it.
|
||||
memcpy(tmp_couple->mobile_mac_addr_bytes,
|
||||
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:
|
||||
tmp_couple->request_time = message.request_time ;
|
||||
else // Implicit packet
|
||||
|
@ -598,7 +598,7 @@ void got_couple_info(couple_message message)
|
|||
|
||||
else // If the couple list exists already
|
||||
{ // 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)
|
||||
{ // 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.
|
||||
memcpy(tmp_couple->mobile_mac_addr_bytes,
|
||||
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:
|
||||
tmp_couple->request_time = message.request_time ;
|
||||
else // Implicit packet
|
||||
|
@ -883,7 +883,7 @@ void monitor_aps()
|
|||
*/
|
||||
void delete_old_aps()
|
||||
{
|
||||
struct timeval now ;
|
||||
TIMESTAMP now ;
|
||||
|
||||
gettimeofday(&now, NULL) ;
|
||||
|
||||
|
@ -1031,8 +1031,8 @@ void print_couple_list()
|
|||
"Reception timestamp: %llu\n"
|
||||
"\n",
|
||||
mobile_mac_string,
|
||||
timeval_to_ms(couple_ptr->request_time),
|
||||
timeval_to_ms(couple_ptr->start_time)
|
||||
timestamp_to_ms(couple_ptr->request_time),
|
||||
timestamp_to_ms(couple_ptr->start_time)
|
||||
) ;
|
||||
free(mobile_mac_string) ;
|
||||
|
||||
|
|
|
@ -284,17 +284,17 @@ void create_socket()
|
|||
void make_packet()
|
||||
{
|
||||
int offset ; // Index used to create the packet
|
||||
struct timeval request_time ;
|
||||
TIMESTAMP request_time ;
|
||||
|
||||
gettimeofday(&request_time, NULL) ;
|
||||
|
||||
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 ;
|
||||
packet_size =
|
||||
sizeof(char) * 2 + sizeof(struct timeval) + sizeof(float) * 3 ;
|
||||
sizeof(char) * 2 + sizeof(TIMESTAMP) + sizeof(float) * 3 ;
|
||||
packet = malloc(packet_size) ;
|
||||
|
||||
packet[offset++] = PACKET_TYPE_CALIBRATION ; // Packet type
|
||||
|
@ -314,8 +314,8 @@ void make_packet()
|
|||
|
||||
else // Standard packet
|
||||
{
|
||||
printf("Request time: %llu\n", timeval_to_ms(request_time)) ;
|
||||
packet_size = sizeof(char) + sizeof(struct timeval) ;
|
||||
printf("Request time: %llu\n", timestamp_to_ms(request_time)) ;
|
||||
packet_size = sizeof(char) + sizeof(TIMESTAMP) ;
|
||||
packet = malloc(packet_size) ;
|
||||
packet[0] = PACKET_TYPE_NORMAL ; // Packet type
|
||||
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,
|
||||
&data[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE
|
||||
+ sizeof(struct iphdr) + sizeof(struct udphdr) + 1],
|
||||
sizeof(struct timeval)) ;
|
||||
sizeof(TIMESTAMP)) ;
|
||||
}
|
||||
|
||||
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,
|
||||
mobile_mac_string,
|
||||
timeval_to_ms(couple.request_time),
|
||||
timeval_to_ms(couple.start_time),
|
||||
timestamp_to_ms(couple.request_time),
|
||||
timestamp_to_ms(couple.start_time),
|
||||
couple.antenna_signal_dbm - 0x100,
|
||||
couple.x_position,
|
||||
couple.y_position,
|
||||
|
@ -1023,14 +1023,15 @@ int make_packet(char **packet)
|
|||
{
|
||||
char *pkt ;
|
||||
int size ; // Packet size
|
||||
struct timeval request_time ;
|
||||
TIMESTAMP request_time ;
|
||||
|
||||
gettimeofday(&request_time, NULL) ;
|
||||
|
||||
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[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 ;
|
||||
}
|
||||
|
@ -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_usec = (tms - d.tv_sec * 1000) * 1000 ;
|
||||
return d ;
|
||||
|
@ -117,9 +117,9 @@ struct timeval ms_to_timeval(unsigned long long tms)
|
|||
/*
|
||||
* 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
|
||||
printf("time_elapsed(): %lu\n", sub) ;
|
||||
#endif
|
||||
|
|
|
@ -60,14 +60,18 @@ typedef enum {FALSE, TRUE} BOOL ;
|
|||
typedef enum {NORTH = 1, EAST, SOUTH, WEST} DIRECTION ;
|
||||
|
||||
|
||||
/* Timestamp type */
|
||||
typedef struct timeval TIMESTAMP ;
|
||||
|
||||
|
||||
/* Message sent by the listener to the aggregator */
|
||||
typedef struct _couple_message
|
||||
{
|
||||
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_ip_addr_bytes[4] ; // IP of the mobile
|
||||
struct timeval request_time ; // Request ID (timestamp on the mobile)
|
||||
struct timeval start_time ; // Timestamp of arrival on the listener
|
||||
TIMESTAMP request_time ; // Request ID (timestamp on the mobile)
|
||||
TIMESTAMP start_time ; // Timestamp of arrival on the listener
|
||||
unsigned char antenna_signal_dbm ; // Signal strength measured by the listener
|
||||
/* Calibration data */
|
||||
float x_position ;
|
||||
|
@ -85,7 +89,7 @@ typedef struct _couple_info
|
|||
typedef struct _request
|
||||
{
|
||||
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
|
||||
} request;
|
||||
|
||||
|
@ -219,8 +223,8 @@ BOOL mac_equals(unsigned char *mac1, unsigned char *mac2) ;
|
|||
char frequency_to_channel(unsigned short channel) ;
|
||||
|
||||
// Time
|
||||
unsigned long long timeval_to_ms(struct timeval date) ;
|
||||
unsigned long time_elapsed(struct timeval sup, struct timeval inf) ;
|
||||
unsigned long long timestamp_to_ms(TIMESTAMP date) ;
|
||||
unsigned long time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;
|
||||
|
||||
// Network
|
||||
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
|
||||
char errbuf[PCAP_ERRBUF_SIZE] ; // Message d'erreur
|
||||
struct timeval tbegin, tcurrent ;
|
||||
TIMESTAMP tbegin, tcurrent ;
|
||||
|
||||
|
||||
/* Sous-fonction de traitement des paquets capturés */
|
||||
|
|
Loading…
Reference in New Issue