[Listener] Handle the packet numbering

This commit is contained in:
Matteo Cypriani 2011-10-24 15:22:23 +02:00
parent c53b8d61e7
commit 1cc1ce4302
2 changed files with 65 additions and 12 deletions

View File

@ -188,6 +188,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
const u_char *packet) ; const u_char *packet) ;
void extract_calibration_data(const u_char *packet, void extract_calibration_data(const u_char *packet,
owl_captured_request *request) ; owl_captured_request *request) ;
void extract_packet_numbers(const u_char *packet,
owl_captured_request *request) ;
void extract_radiotap_data(const u_char *packet, void extract_radiotap_data(const u_char *packet,
owl_captured_request *request, owl_captured_request *request,
owl_bool rtap_fields[15]) ; owl_bool rtap_fields[15]) ;

View File

@ -987,6 +987,12 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
case OWL_REQUEST_NORMAL : case OWL_REQUEST_NORMAL :
if (VERBOSE_INFO) if (VERBOSE_INFO)
printf("\nExplicit packet received.\n") ; 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 ; break ;
case OWL_REQUEST_CALIBRATION : 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") ; printf("\nExplicit calibration packet received.\n") ;
extract_calibration_data(&packet[rtap_bytes + extract_calibration_data(&packet[rtap_bytes +
ieee80211_header_size + ieee80211_header_size +
LLC_HEADER_SIZE LLC_HEADER_SIZE +
+ sizeof(struct iphdr) + sizeof(struct iphdr) +
sizeof(struct udphdr) + 9], sizeof(struct udphdr) + 9],
&request) ; &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 ; break ;
case OWL_REQUEST_AUTOCALIBRATION : 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 + extract_calibration_data(&packet[rtap_bytes +
ieee80211_header_size + ieee80211_header_size +
LLC_HEADER_SIZE LLC_HEADER_SIZE +
+ sizeof(struct iphdr) + sizeof(struct iphdr) +
sizeof(struct udphdr) + 9], sizeof(struct udphdr) + 9],
&request) ; &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 ; break ;
default : default :
@ -1088,13 +1108,14 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
"\tMAC AP: %s\n" "\tMAC AP: %s\n"
"\tMobile MAC: %s\n" "\tMobile MAC: %s\n"
"\tMobile IP: %s\n" "\tMobile IP: %s\n"
"\tSequence number (request time): %s\n" "\tRequest timestamp: %s\n"
"\tRequest arrival time on the AP: %s\n" "\tRequest arrival time on the AP: %s\n"
"\tSignal: %d dBm\n" "\tSignal: %d dBm\n"
"\tPosition X: %f\n" "\tPosition X: %f\n"
"\tPosition Y: %f\n" "\tPosition Y: %f\n"
"\tPosition Z: %f\n" "\tPosition Z: %f\n"
"\tDirection: %hhd\n" "\tDirection: %hhd\n"
"\tPacket number: %"PRIu16"/%"PRIu16"\n"
, ,
request.type, request.type,
ap_mac_addr_str, 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.x_position),
owl_ntohf(request.y_position), owl_ntohf(request.y_position),
owl_ntohf(request.z_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 * Fills 'request' with the required data extracted from the Radiotap
* header of 'packet'. The elements of 'rtap_fields' are set to owl_true * 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_x = owl_htonf(GET_MY_POSITION_X()),
my_position_y = owl_htonf(GET_MY_POSITION_Y()), my_position_y = owl_htonf(GET_MY_POSITION_Y()),
my_position_z = owl_htonf(GET_MY_POSITION_Z()) ; my_position_z = owl_htonf(GET_MY_POSITION_Z()) ;
uint16_t npkt ;
owl_timestamp_now(&request_time) ; owl_timestamp_now(&request_time) ;
@ -1444,25 +1488,32 @@ uint_fast16_t make_packet(uint8_t **packet)
offset = 0 ; offset = 0 ;
size = 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) ; pkt = malloc(size) ;
// Request type: // Request type:
memset(&pkt[offset], OWL_REQUEST_AUTOCALIBRATION, 1) ; memset(&pkt[offset++], OWL_REQUEST_AUTOCALIBRATION, 1) ;
++offset ;
// Timestamp: // Timestamp:
memcpy(&pkt[offset], &request_time, sizeof(request_time)) ; memcpy(&pkt[offset], &request_time, sizeof(request_time)) ;
offset += sizeof(request_time) ; offset += sizeof(request_time) ;
// Coordinates: // Coordinates:
pkt[offset] = GET_MY_DIRECTION() ; pkt[offset++] = GET_MY_DIRECTION() ;
++offset ;
memcpy(&pkt[offset], &my_position_x, sizeof(float)) ; memcpy(&pkt[offset], &my_position_x, sizeof(float)) ;
offset += sizeof(float) ; offset += sizeof(float) ;
memcpy(&pkt[offset], &my_position_y, sizeof(float)) ; memcpy(&pkt[offset], &my_position_y, sizeof(float)) ;
offset += sizeof(float) ; offset += sizeof(float) ;
memcpy(&pkt[offset], &my_position_z, sizeof(float)) ; memcpy(&pkt[offset], &my_position_z, sizeof(float)) ;
#ifndef NDEBUG
offset += sizeof(float) ; 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) ; assert(offset == size) ;
#endif // NDEBUG #endif // NDEBUG