[Listener] Remove unused radiotap fields

From the radiotap header, we only use the antenna signal field,
therefore we don't need to handle the fields that are after it. We do
need to take into account the fields preceding the antenna signal field
though, in order to know where it is.
This commit is contained in:
Matteo Cypriani 2013-05-16 11:37:18 -04:00
parent 4a3e1e1091
commit 7a5ed8ec51
2 changed files with 22 additions and 80 deletions

View File

@ -152,12 +152,23 @@ enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ;
#define RTAP_P_HLENGTH 2 // Header length
#define RTAP_P_PRESENTFLAGS 4 // Present flags
/* Radiotap field lengths (in bytes) */
/* Lengths of the radiotap fixed fields (in bytes) */
#define RTAP_L_HREVISION 1 // Header revision
#define RTAP_L_HPAD 1 // Header pad
#define RTAP_L_HLENGTH 2 // Header length
#define RTAP_L_PRESENTFLAGS 4 // Present flags
/* Bits of the radiotap "Present flags" field */
#define RTAP_TSFT 0
#define RTAP_FLAGS 1
#define RTAP_RATE 2
#define RTAP_CHANNEL 3 // Channel frequency and flags
#define RTAP_FHSS 4 // FHSS hop set and hop pattern
#define RTAP_ANTENNASIGNAL 5
// ... (we use only the antenna signal field, so we don't need to handle
// the bits greater than RTAP_ANTENNASIGNAL)
/* Lengths of the radiotap optional fields (in bytes) */
#define RTAP_L_TSFT 8 // MAC timestamp (Time Synchronization Function Timer)
#define RTAP_L_FLAGS 1 // Flags
#define RTAP_L_RATE 1 // Data rate
@ -166,34 +177,6 @@ enum {MODE_ACTIVE = 'a', MODE_PASSIVE = 'p', MODE_MIXED = 'm'} ;
#define RTAP_L_FHSSHOPSET 1 // FHSS hop set
#define RTAP_L_FHSSHOPPATTERN 1 // FHSS hop pattern
#define RTAP_L_ANTENNASIGNAL 1 // Signal power at the antenna (dBm)
#define RTAP_L_ANTENNANOISE 1 // Noise power at the antenna (dBm)
#define RTAP_L_LOCKQUALITY 2 // Signal quality (quality of Barker code lock)
#define RTAP_L_TXATTENUATION 2 // Transmit power (distance from max power)
#define RTAP_L_DBTXATTENUATION 2 // Ditto (dB)
#define RTAP_L_DBMTXPOWER 1 // Absolute transmit power (dBm)
#define RTAP_L_ANTENNA 1 // Antenna number
#define RTAP_L_DBANTENNASIGNAL 1 // Relative signal power at the antenna (dB)
#define RTAP_L_DBANTENNANOISE 1 // Relative noise power at the antenna (dB)
#define RTAP_L_RXFLAGS 2 // Properties of the received flags
/* Positions in 'Present flags' (and present fields 'check' array) */
#define RTAP_TSFT 0
#define RTAP_FLAGS 1
#define RTAP_RATE 2
#define RTAP_CHANNEL 3 // Channel frequency and flags
#define RTAP_FHSS 4 // FHSS hop set and hop pattern
#define RTAP_ANTENNASIGNAL 5
#define RTAP_ANTENNANOISE 6
#define RTAP_LOCKQUALITY 7
#define RTAP_TXATTENUATION 8
#define RTAP_DBTXATTENUATION 9
#define RTAP_DBMTXPOWER 10
#define RTAP_ANTENNA 11
#define RTAP_DBANTENNASIGNAL 12
#define RTAP_DBANTENNANOISE 13
#define RTAP_RXFLAGS 14
/*
* Returns the number of bytes needed to jump after a (radiotap) field of
@ -231,7 +214,7 @@ void extract_packet_numbers(const u_char *pkt_data,
owl_captured_request *request) ;
void extract_radiotap_data(const u_char *pkt_data,
owl_captured_request *request,
bool rtap_fields[15]) ;
bool rtap_fields[RTAP_ANTENNASIGNAL + 1]) ;
uint_fast16_t nat_align(uint_fast16_t offset, uint_fast8_t field_len) ;
void get_mac_addr(char *eth, uint8_t mac_bytes[ETHER_ADDR_LEN]) ;
void get_ip_addr(char *eth, char *ip_bytes) ;

View File

@ -977,7 +977,7 @@ void read_packet(const struct pcap_pkthdr *pkt_header,
owl_captured_request request ; // Message to send to the aggregator
uint16_t rtap_bytes ; // Radiotap header size
uint_fast16_t offset ; // Offset to read the packet
bool rtap_fields[15] ; // Present flags
bool rtap_fields[RTAP_ANTENNASIGNAL + 1] ; // Present flags
uint8_t raw_packet_fc1 ; // First byte of the received frame's FC
uint8_t raw_packet_fc2 ; // Second byte of the received frame's FC
// Size of the IEEE 802.11 header:
@ -1285,7 +1285,7 @@ void extract_packet_numbers(const u_char *pkt_data,
*/
void extract_radiotap_data(const u_char *pkt_data,
owl_captured_request *request,
bool rtap_fields[15])
bool rtap_fields[RTAP_ANTENNASIGNAL + 1])
{
uint32_t rtap_presentflags ;
uint_fast16_t rtap_position ;
@ -1297,13 +1297,15 @@ void extract_radiotap_data(const u_char *pkt_data,
// The Radiotap header is little-endian
rtap_presentflags = le32toh(rtap_presentflags) ;
for (i = 0 ; i < 15 ; ++i) // Initialise present flags structure
// Initialise the present flags array
for (i = 0 ; i <= RTAP_ANTENNASIGNAL ; ++i)
rtap_fields[i] = false ;
rtap_position = 8 ; // Begining of the present flags determined fields
// Test the first 15 bits of the flag field in order to check their
// presence and to copy them:
for (i = 0 ; i < 15 ; ++i)
// Test the first bits of the flag field in order to check their
// presence, up to the antenna signal field which is the only one
// we need:
for (i = 0 ; i <= RTAP_ANTENNASIGNAL ; ++i)
{
if ((rtap_presentflags % 2) == 1)
{
@ -1346,49 +1348,6 @@ void extract_radiotap_data(const u_char *pkt_data,
printf("Antenna signal: %"PRId8" dBm\n", request->ss_dbm) ;
rtap_position += RTAP_L_ANTENNASIGNAL ;
break ;
case RTAP_ANTENNANOISE:
rtap_fields[RTAP_ANTENNANOISE] = true;
rtap_position += SKIP_FIELD(rtap_position,
RTAP_L_ANTENNANOISE) ;
break ;
case RTAP_LOCKQUALITY:
rtap_fields[RTAP_LOCKQUALITY] = true;
rtap_position += SKIP_FIELD(rtap_position,
RTAP_L_LOCKQUALITY) ;
break ;
case RTAP_TXATTENUATION:
rtap_fields[RTAP_TXATTENUATION] = true;
rtap_position += SKIP_FIELD(rtap_position,
RTAP_L_TXATTENUATION) ;
break ;
case RTAP_DBTXATTENUATION:
rtap_fields[RTAP_DBTXATTENUATION] = true;
rtap_position += SKIP_FIELD(rtap_position,
RTAP_L_DBTXATTENUATION) ;
break ;
case RTAP_DBMTXPOWER:
rtap_fields[RTAP_DBMTXPOWER] = true;
rtap_position += SKIP_FIELD(rtap_position,
RTAP_L_DBMTXPOWER) ;
break ;
case RTAP_ANTENNA:
rtap_fields[RTAP_ANTENNA] = true;
rtap_position += SKIP_FIELD(rtap_position, RTAP_L_ANTENNA) ;
break ;
case RTAP_DBANTENNASIGNAL:
rtap_fields[RTAP_DBANTENNASIGNAL] = true;
rtap_position += SKIP_FIELD(rtap_position,
RTAP_L_DBANTENNASIGNAL) ;
break ;
case RTAP_DBANTENNANOISE:
rtap_fields[RTAP_DBANTENNANOISE] = true;
rtap_position += SKIP_FIELD(rtap_position,
RTAP_L_DBANTENNANOISE) ;
break ;
case RTAP_RXFLAGS:
rtap_fields[RTAP_RXFLAGS] = true;
rtap_position += SKIP_FIELD(rtap_position, RTAP_L_RXFLAGS) ;
break ;
default:
fprintf(stderr, "Warning! Radiotap field not handled: bit"
" %d. This should be investigated.", i) ;