diff --git a/owlps-listener/owlps-listener.h b/owlps-listener/owlps-listener.h index 0efed76..b0b1e60 100644 --- a/owlps-listener/owlps-listener.h +++ b/owlps-listener/owlps-listener.h @@ -188,6 +188,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) ; void extract_calibration_data(const u_char *packet, owl_captured_request *request) ; +void extract_packet_numbers(const u_char *packet, + owl_captured_request *request) ; void extract_radiotap_data(const u_char *packet, owl_captured_request *request, owl_bool rtap_fields[15]) ; diff --git a/owlps-listener/owlps-listenerd.c b/owlps-listener/owlps-listenerd.c index c39a315..f75fd53 100644 --- a/owlps-listener/owlps-listenerd.c +++ b/owlps-listener/owlps-listenerd.c @@ -987,6 +987,12 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, case OWL_REQUEST_NORMAL : if (VERBOSE_INFO) printf("\nExplicit packet received.\n") ; + extract_packet_numbers(&packet[rtap_bytes + + ieee80211_header_size + + LLC_HEADER_SIZE + + sizeof(struct iphdr) + + sizeof(struct udphdr) + 9], + &request) ; break ; case OWL_REQUEST_CALIBRATION : @@ -994,10 +1000,17 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, printf("\nExplicit calibration packet received.\n") ; extract_calibration_data(&packet[rtap_bytes + ieee80211_header_size + - LLC_HEADER_SIZE - + sizeof(struct iphdr) + + LLC_HEADER_SIZE + + sizeof(struct iphdr) + sizeof(struct udphdr) + 9], &request) ; + extract_packet_numbers(&packet[rtap_bytes + + ieee80211_header_size + + LLC_HEADER_SIZE + + sizeof(struct iphdr) + + sizeof(struct udphdr) + 10 + + 3 * sizeof(float)], + &request) ; break ; case OWL_REQUEST_AUTOCALIBRATION : @@ -1010,10 +1023,17 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, } extract_calibration_data(&packet[rtap_bytes + ieee80211_header_size + - LLC_HEADER_SIZE - + sizeof(struct iphdr) + + LLC_HEADER_SIZE + + sizeof(struct iphdr) + sizeof(struct udphdr) + 9], &request) ; + extract_packet_numbers(&packet[rtap_bytes + + ieee80211_header_size + + LLC_HEADER_SIZE + + sizeof(struct iphdr) + + sizeof(struct udphdr) + 10 + + 3 * sizeof(float)], + &request) ; break ; default : @@ -1088,13 +1108,14 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, "\tMAC AP: %s\n" "\tMobile MAC: %s\n" "\tMobile IP: %s\n" - "\tSequence number (request time): %s\n" + "\tRequest timestamp: %s\n" "\tRequest arrival time on the AP: %s\n" "\tSignal: %d dBm\n" "\tPosition X: %f\n" "\tPosition Y: %f\n" "\tPosition Z: %f\n" "\tDirection: %hhd\n" + "\tPacket number: %"PRIu16"/%"PRIu16"\n" , request.type, ap_mac_addr_str, @@ -1107,7 +1128,9 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, owl_ntohf(request.x_position), owl_ntohf(request.y_position), owl_ntohf(request.z_position), - request.direction + request.direction, + ntohs(request.packet_id), + ntohs(request.nb_packets) ) ; } @@ -1142,6 +1165,26 @@ void extract_calibration_data(const u_char *packet, +/* + * Fills 'request' with the number of packets and packet ID extracted + * from 'packet'. + * Note: 'packet' is read from its first byte, therefore you must not + * pass the whole received packet to this function. + */ +void extract_packet_numbers(const u_char *packet, + owl_captured_request *request) +{ + // Number of packets: + memcpy(&request->nb_packets, packet, sizeof(uint16_t)) ; + request->nb_packets = request->nb_packets ; + // Current packet's ID: + memcpy(&request->packet_id, &packet[sizeof(uint16_t)], + sizeof(uint16_t)) ; + request->packet_id = request->packet_id ; +} + + + /* * Fills 'request' with the required data extracted from the Radiotap * header of 'packet'. The elements of 'rtap_fields' are set to owl_true @@ -1430,6 +1473,7 @@ uint_fast16_t make_packet(uint8_t **packet) my_position_x = owl_htonf(GET_MY_POSITION_X()), my_position_y = owl_htonf(GET_MY_POSITION_Y()), my_position_z = owl_htonf(GET_MY_POSITION_Z()) ; + uint16_t npkt ; owl_timestamp_now(&request_time) ; @@ -1444,25 +1488,32 @@ uint_fast16_t make_packet(uint8_t **packet) offset = 0 ; size = - sizeof(uint8_t) * 2 + sizeof(owl_timestamp) + sizeof(float) * 3 ; + sizeof(uint8_t) * 2 + sizeof(owl_timestamp) + sizeof(float) * 3 + + sizeof(uint16_t) * 2 ; pkt = malloc(size) ; // Request type: - memset(&pkt[offset], OWL_REQUEST_AUTOCALIBRATION, 1) ; - ++offset ; + memset(&pkt[offset++], OWL_REQUEST_AUTOCALIBRATION, 1) ; // Timestamp: memcpy(&pkt[offset], &request_time, sizeof(request_time)) ; offset += sizeof(request_time) ; // Coordinates: - pkt[offset] = GET_MY_DIRECTION() ; - ++offset ; + pkt[offset++] = GET_MY_DIRECTION() ; memcpy(&pkt[offset], &my_position_x, sizeof(float)) ; offset += sizeof(float) ; memcpy(&pkt[offset], &my_position_y, sizeof(float)) ; offset += sizeof(float) ; memcpy(&pkt[offset], &my_position_z, sizeof(float)) ; -#ifndef NDEBUG offset += sizeof(float) ; + // Number of packets: + npkt = htons(GET_AUTOCALIBRATION_NBPKT()) ; + memcpy(&pkt[offset], &npkt, sizeof(uint16_t)) ; + offset += sizeof(uint16_t) ; + // Number of the current packet (1 for the first): + npkt = htons(1u) ; + memcpy(&pkt[offset], &npkt, sizeof(uint16_t)) ; +#ifndef NDEBUG + offset += sizeof(uint16_t) ; assert(offset == size) ; #endif // NDEBUG