From 4bae0c9b4e689eae9ca2f55a3e5eb7064810a2b0 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Wed, 3 Aug 2011 23:52:25 +0200 Subject: [PATCH] [Listener] Add extract_calibration_data() A first step in the long way of read_packet() refactoring. --- owlps-listener/owlps-listener.h | 2 ++ owlps-listener/owlps-listenerd.c | 58 +++++++++++++++----------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/owlps-listener/owlps-listener.h b/owlps-listener/owlps-listener.h index f2559a8..5f08308 100644 --- a/owlps-listener/owlps-listener.h +++ b/owlps-listener/owlps-listener.h @@ -176,6 +176,8 @@ int iface_mode_monitor(const char *const iface) ; int capture(void) ; 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 get_mac_addr(char *eth, uint8_t mac_bytes[ETHER_ADDR_LEN]) ; void get_ip_addr(char *eth, char *ip_bytes) ; diff --git a/owlps-listener/owlps-listenerd.c b/owlps-listener/owlps-listenerd.c index 7a6ef97..16f6a72 100644 --- a/owlps-listener/owlps-listenerd.c +++ b/owlps-listener/owlps-listenerd.c @@ -909,21 +909,12 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, case OWL_REQUEST_CALIBRATION : if (VERBOSE_INFO) printf("\nExplicit calibration packet received.\n") ; - request.direction = - packet[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE - + sizeof(struct iphdr) + sizeof(struct udphdr) + 9]; - memcpy(&request.x_position, - &packet[rtap_bytes + ieee80211_header_size - + LLC_HEADER_SIZE + sizeof(struct iphdr) - + sizeof(struct udphdr) + 10], sizeof(float)) ; - memcpy(&request.y_position, - &packet[rtap_bytes + ieee80211_header_size - + LLC_HEADER_SIZE + sizeof(struct iphdr) - + sizeof(struct udphdr) + 14], sizeof(float)) ; - memcpy(&request.z_position, - &packet[rtap_bytes + ieee80211_header_size - + LLC_HEADER_SIZE + sizeof(struct iphdr) - + sizeof(struct udphdr) + 18], sizeof(float)) ; + extract_calibration_data(&packet[rtap_bytes + + ieee80211_header_size + + LLC_HEADER_SIZE + + sizeof(struct iphdr) + + sizeof(struct udphdr) + 9], + &request) ; break ; case OWL_REQUEST_AUTOCALIBRATION : @@ -934,21 +925,12 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, printf(".. on the wrong port!") ; putchar('\n') ; } - request.direction = - packet[rtap_bytes + ieee80211_header_size + LLC_HEADER_SIZE - + sizeof(struct iphdr) + sizeof(struct udphdr) + 9]; - memcpy(&request.x_position, - &packet[rtap_bytes + ieee80211_header_size - + LLC_HEADER_SIZE + sizeof(struct iphdr) - + sizeof(struct udphdr) + 10], sizeof(float)) ; - memcpy(&request.y_position, - &packet[rtap_bytes + ieee80211_header_size - + LLC_HEADER_SIZE + sizeof(struct iphdr) - + sizeof(struct udphdr) + 14], sizeof(float)) ; - memcpy(&request.z_position, - &packet[rtap_bytes + ieee80211_header_size - + LLC_HEADER_SIZE + sizeof(struct iphdr) - + sizeof(struct udphdr) + 18], sizeof(float)) ; + extract_calibration_data(&packet[rtap_bytes + + ieee80211_header_size + + LLC_HEADER_SIZE + + sizeof(struct iphdr) + + sizeof(struct udphdr) + 9], + &request) ; break ; default : @@ -1132,6 +1114,22 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, +/* + * Fills 'request' with the calibration data 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_calibration_data(const u_char *packet, + owl_captured_request *request) +{ + request->direction = packet[0] ; + memcpy(&request->x_position, &packet[1], sizeof(float)) ; + memcpy(&request->y_position, &packet[4], sizeof(float)) ; + memcpy(&request->z_position, &packet[8], sizeof(float)) ; +} + + + /* * Get our own MAC address and copy it to 'mac_bytes'. */