From 87e364a633f6d7ca7312fa9c144eed194631baf4 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 24 Jan 2011 12:02:35 +0100 Subject: [PATCH] [Listener] Accept all data frames The listener dropped all non-bare Data frames. It now accepts Data subtypes as well (QoS Data, etc.). --- .../owlps-listener/owlps-listenerd.c | 19 +++++++++++++++---- libowlps/owlps.h | 5 ++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/infrastructure-centred/owlps-listener/owlps-listenerd.c b/infrastructure-centred/owlps-listener/owlps-listenerd.c index 370304e..8361097 100644 --- a/infrastructure-centred/owlps-listener/owlps-listenerd.c +++ b/infrastructure-centred/owlps-listener/owlps-listenerd.c @@ -481,7 +481,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, couple_message couple ; // Message to send to the aggregator ssize_t nsent ; // sendto return value BOOL check[15] ; // Present flags - unsigned char raw_packet_type ; // Received packet type (beacon, data…) + unsigned char raw_packet_fc1 ; // First byte of the received frame's FC + unsigned char raw_packet_fc2 ; // Second byte of the received frame's FC unsigned char raw_packet_flags ; // IEEE 802.11 header flags unsigned short llc_packet_type = 0 ; // Pointer to the (possible) IP header of the packet: @@ -504,10 +505,20 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header, rtap_bytes = le16toh(rtap_bytes) ; // After the rtap header, there is the 802.11 header; the first byte - // is the packet type (beacon or not): - raw_packet_type = data[rtap_bytes] ; + // is the first byte of the Frame Control (FC) field, which contains + // the type of the packet (Management, Control or Data) and its subtype + // (QoS, etc.): + raw_packet_fc1 = data[rtap_bytes] ; + if (! IS_DATA_FRAME(raw_packet_fc1)) // Data packet? + goto not_explicit_packet ; - if (raw_packet_type != RAW_PACKET_TYPE_DATA) // Data packet? + // The second byte of the FC field contains the frame flags. The two + // first bits indicate the frame source and destination types: the + // first bit is "To DS" and the second is "From DS", so if the second + // bit is 0 the frame comes from a STA. That's what we want for an + // explicit packet: + raw_packet_fc2 = data[rtap_bytes+1] ; + if (! IS_FRAME_FROM_STA(raw_packet_fc2)) goto not_explicit_packet ; // Get the packet type (protocol, 2 bytes) from the LLC header: diff --git a/libowlps/owlps.h b/libowlps/owlps.h index 30ec9a7..786e7b2 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -127,7 +127,10 @@ typedef struct _autocalibration_order /* Types des paquets capturés (en-tête IEEE 802.11) */ #define RAW_PACKET_TYPE_BEACON 0x80 -#define RAW_PACKET_TYPE_DATA 0x08 +#define FRAME_TYPE_DATA_MASK 0x08 +#define IS_DATA_FRAME(FCS1) (((FCS1) & FRAME_TYPE_DATA_MASK) == FRAME_TYPE_DATA_MASK) +#define FRAME_FROM_STA_MASK 0x02 +#define IS_FRAME_FROM_STA(FCS2) (((FCS2) & FRAME_FROM_STA_MASK) != FRAME_FROM_STA_MASK) /* Position des champs fixes de l'en-tête radiotap (octets) */