From ff81d43cb16c22338540d4dd78280b3a6694937f Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Thu, 10 Mar 2011 14:26:02 +0100 Subject: [PATCH] [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(). --- .../owlps-aggregator/owlps-aggregator.h | 6 ++--- .../owlps-aggregator/owlps-aggregatord.c | 22 +++++++++---------- .../owlps-client/owlps-client.c | 10 ++++----- .../owlps-listener/owlps-listenerd.c | 13 ++++++----- libowlps/libowlps.c | 14 ++++++------ libowlps/owlps.h | 14 +++++++----- .../librtapscanmob/librtapscanmob.c | 2 +- 7 files changed, 43 insertions(+), 38 deletions(-) diff --git a/infrastructure-centred/owlps-aggregator/owlps-aggregator.h b/infrastructure-centred/owlps-aggregator/owlps-aggregator.h index c4cb28c..3d9c30a 100644 --- a/infrastructure-centred/owlps-aggregator/owlps-aggregator.h +++ b/infrastructure-centred/owlps-aggregator/owlps-aggregator.h @@ -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 ; diff --git a/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c b/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c index 4d4b4f8..fdf630c 100644 --- a/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c +++ b/infrastructure-centred/owlps-aggregator/owlps-aggregatord.c @@ -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) ; diff --git a/infrastructure-centred/owlps-client/owlps-client.c b/infrastructure-centred/owlps-client/owlps-client.c index bdddd44..1106f3c 100644 --- a/infrastructure-centred/owlps-client/owlps-client.c +++ b/infrastructure-centred/owlps-client/owlps-client.c @@ -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)) ; diff --git a/infrastructure-centred/owlps-listener/owlps-listenerd.c b/infrastructure-centred/owlps-listener/owlps-listenerd.c index 63731c4..43dbdea 100644 --- a/infrastructure-centred/owlps-listener/owlps-listenerd.c +++ b/infrastructure-centred/owlps-listener/owlps-listenerd.c @@ -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 diff --git a/libowlps/libowlps.c b/libowlps/libowlps.c index b6e4227..6f2d69f 100644 --- a/libowlps/libowlps.c +++ b/libowlps/libowlps.c @@ -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 diff --git a/libowlps/owlps.h b/libowlps/owlps.h index ce20899..b239bd2 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -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, diff --git a/mobile-centred/librtapscanmob/librtapscanmob.c b/mobile-centred/librtapscanmob/librtapscanmob.c index 9a85b2d..539d8de 100644 --- a/mobile-centred/librtapscanmob/librtapscanmob.c +++ b/mobile-centred/librtapscanmob/librtapscanmob.c @@ -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 */