From 4f74524f05f86e4b5a492ad896640b8dc00d891f Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Fri, 25 Mar 2011 17:20:18 +0100 Subject: [PATCH] Handle request type in Listener & Aggregator The listener now sends the request type to the aggregator. The aggregator writes it to the CSV file and transmit it to the positioning server. --- TODO | 9 +++++++++ libowlps/owlps.h | 3 +++ owlps-aggregator/owlps-aggregator.h | 2 ++ owlps-aggregator/owlps-aggregatord.c | 16 +++++++++++++--- owlps-listener/owlps-listenerd.c | 20 +++++++++++++------- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index f1bdeae..bb79957 100644 --- a/TODO +++ b/TODO @@ -15,6 +15,12 @@ owl_mac_bytes_to_string(). See ether_aton(3). +* libowlps + +- Delete timestamp_is_null()? + This function is currently not used. + + * Aggregator - inet_ntoa() is not secure with threads @@ -22,6 +28,9 @@ - Use locks to read/write the AP list Currently, several threads can access the list simultaneously, and that's not cool! +- Refactor got_request(). +- Use the type of a request to identify it? + (along with the mobile MAC address and the request time) - got_request(): option for the maximal difference time For implicit packet, we consider that packet from the same MAC and received within an interval of 10ms are part of the same diff --git a/libowlps/owlps.h b/libowlps/owlps.h index 635dc23..32518da 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -80,6 +80,7 @@ typedef struct _owl_timestamp /* Message sent by the listener to the aggregator */ typedef struct _owl_captured_request { + uint8_t type ; // Type of the captured request uint8_t ap_mac_addr_bytes[ETHER_ADDR_LEN] ; // MAC of the listener uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; // MAC of the mobile uint8_t mobile_ip_addr_bytes[4] ; // IP of the mobile @@ -98,6 +99,7 @@ typedef struct _owl_captured_request * the main data of a request */ typedef struct _owl_request { + uint8_t type ; // Type of the request uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; // MAC of the mobile owl_timestamp request_time ; // Request ID (timestamp on the mobile) uint16_t nb_info ; // Number of (listener MAC;signal strength) couples @@ -133,6 +135,7 @@ typedef struct _owl_autocalibration_order #define OWL_REQUEST_NORMAL 0 #define OWL_REQUEST_CALIBRATION 1 #define OWL_REQUEST_AUTOCALIBRATION 2 +#define OWL_REQUEST_IMPLICIT 10 /* Wi-Fi channel frequencies in Hz */ diff --git a/owlps-aggregator/owlps-aggregator.h b/owlps-aggregator/owlps-aggregator.h index 69ab985..cbe0292 100644 --- a/owlps-aggregator/owlps-aggregator.h +++ b/owlps-aggregator/owlps-aggregator.h @@ -49,6 +49,8 @@ typedef struct _request_info_list /* Linked list of the requests */ typedef struct _request_list { + uint8_t type ; + /* Request identifier */ // Mobile MAC address (in bytes): uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; diff --git a/owlps-aggregator/owlps-aggregatord.c b/owlps-aggregator/owlps-aggregatord.c index 057e950..f62fff8 100644 --- a/owlps-aggregator/owlps-aggregatord.c +++ b/owlps-aggregator/owlps-aggregatord.c @@ -416,6 +416,7 @@ int read_loop(int sockfd) fprintf(stderr, "\n" "*** Request received from AP ***\n" + "\tType: %"PRIu8"\n" "\tAP MAC: %s\n" "\tMobile MAC: %s\n" "\tMobile IP: %s\n" @@ -427,6 +428,7 @@ int read_loop(int sockfd) "\tPosition Z: %f\n" "\tDirection: %hhd\n" , + request.type, owl_mac_bytes_to_string(request.ap_mac_addr_bytes), owl_mac_bytes_to_string(request.mobile_mac_addr_bytes), mobile_ip_str, @@ -538,6 +540,9 @@ void* monitor_requests(void *NULL_value) mac_str) ; fprintf(fd, "%s;", mac_str) ; + // Print request type to the output file + fprintf(fd, "%"PRIu8";", request_ptr->type) ; + #ifdef USE_TIMESTAMP // Print request mobile timestamp to the output file owl_timestamp_to_string(request_time_str, @@ -552,6 +557,7 @@ void* monitor_requests(void *NULL_value) request_ptr->z_position, request_ptr->direction) ; + request.type = request_ptr->type ; memcpy(request.mobile_mac_addr_bytes, request_ptr->mobile_mac_addr_bytes, ETHER_ADDR_LEN) ; @@ -673,10 +679,11 @@ void got_request(owl_captured_request request) { fprintf(stderr, "Creating request list.\n") ; tmp_request = malloc(sizeof(request_list)) ; // create it. + tmp_request->type = request.type ; memcpy(tmp_request->mobile_mac_addr_bytes, request.mobile_mac_addr_bytes, ETHER_ADDR_LEN) ; // Explicit packet: - if (! owl_timestamp_is_null(request.request_time)) + if (request.type != OWL_REQUEST_IMPLICIT) // Transmission time on the mobile: tmp_request->request_time = request.request_time ; // Implicit packet: @@ -698,7 +705,7 @@ void got_request(owl_captured_request request) else // If the request list exists already { // we search the list for the request // Explicit packet: - if (! owl_timestamp_is_null(request.request_time)) + if (request.type != OWL_REQUEST_IMPLICIT) { while (tmp_request != NULL) { // Research criterion: MAC and transmission time @@ -730,10 +737,11 @@ void got_request(owl_captured_request request) { fprintf(stderr, "Create new request.\n") ; tmp_request = malloc(sizeof(request_list)) ; // create it + tmp_request->type = request.type ; memcpy(tmp_request->mobile_mac_addr_bytes, request.mobile_mac_addr_bytes, ETHER_ADDR_LEN) ; // Explicit packet: - if (! owl_timestamp_is_null(request.request_time)) + if (request.type != OWL_REQUEST_IMPLICIT) // Transmission time on the mobile: tmp_request->request_time = request.request_time ; // Implicit packet: @@ -1144,10 +1152,12 @@ void print_request_list() owl_timestamp_to_string(start_time_str, request_ptr->start_time) ; fprintf(stderr, + "Type: %"PRIu8"\n" "Mobile MAC: %s\n" "Sequence number: %s\n" "Reception timestamp: %s\n" "\n", + request_ptr->type, mobile_mac_str, request_time_str, start_time_str diff --git a/owlps-listener/owlps-listenerd.c b/owlps-listener/owlps-listenerd.c index c9030da..8693839 100644 --- a/owlps-listener/owlps-listenerd.c +++ b/owlps-listener/owlps-listenerd.c @@ -636,7 +636,6 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, // Pointer to the (possible) UDP header of the packet: struct udphdr *packet_udp_header = NULL ; // Localisation request type (request, calibration, autocalibration): - uint8_t packet_type ; owl_bool is_explicit_packet = TRUE ; // Is the packet an explicit request? // Is the packet an autocalibration positioning request? owl_bool uses_autocalibration_request_port = FALSE ; @@ -753,10 +752,10 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, // FIXME: should we really ignore Retries? && ! IS_RETRY(raw_packet_flags)) { - packet_type = + request.type = packet[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE + sizeof(struct iphdr) + sizeof(struct udphdr)] ; - switch(packet_type) + switch(request.type) { case OWL_REQUEST_NORMAL : if (GET_VERBOSE()) @@ -797,7 +796,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, if (GET_VERBOSE()) printf("\nStrange explicit packet received\n") ; fprintf(stderr, - "Error! Unknown packet type (%d).\n", packet_type) ; + "Error! Unknown request type (%d).\n", request.type) ; is_explicit_packet = FALSE ; } @@ -805,9 +804,13 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, { if (GET_MODE() == MODE_ACTIVE) return ; - else if (GET_VERBOSE()) - printf("\nThis strange explicit packet will be handled as" - " an implicit one.\n") ; + else + { + if (GET_VERBOSE()) + printf("\nThis strange explicit packet will be handled" + " as an implicit one.\n") ; + request.type = OWL_REQUEST_IMPLICIT ; + } } else // Copy the timestamp "as is" (i.e. without changing endianess) @@ -823,6 +826,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, { if (GET_VERBOSE()) printf("\nImplicit packet received.\n") ; + request.type = OWL_REQUEST_IMPLICIT ; } else // Active mode, packet was not an explicit request @@ -930,6 +934,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, owl_timestamp_to_string(start_time_str, owl_ntoh_timestamp(request.start_time)) ; printf("*** Request to send ***\n" + "\tType: %"PRIu8"\n" "\tMAC AP: %s\n" "\tMobile MAC: %s\n" "\tSequence number (request time): %s\n" @@ -940,6 +945,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, "\tPosition Z: %f\n" "\tDirection: %hhd\n" , + request.type, owl_mac_bytes_to_string(request.ap_mac_addr_bytes), owl_mac_bytes_to_string(request.mobile_mac_addr_bytes), request_time_str,