[Listener] Add extract_radiotap_data()
Another refactoring step for read_packet().
This commit is contained in:
parent
4bae0c9b4e
commit
fb9d093d5a
|
@ -178,6 +178,9 @@ 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_radiotap_data(const u_char *packet,
|
||||||
|
owl_captured_request *request,
|
||||||
|
owl_bool rtap_fields[15]) ;
|
||||||
void get_mac_addr(char *eth, uint8_t mac_bytes[ETHER_ADDR_LEN]) ;
|
void get_mac_addr(char *eth, uint8_t mac_bytes[ETHER_ADDR_LEN]) ;
|
||||||
void get_ip_addr(char *eth, char *ip_bytes) ;
|
void get_ip_addr(char *eth, char *ip_bytes) ;
|
||||||
|
|
||||||
|
|
|
@ -770,12 +770,9 @@ int capture()
|
||||||
void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||||
const u_char *packet)
|
const u_char *packet)
|
||||||
{
|
{
|
||||||
uint16_t rtap_bytes ; // Received data size
|
|
||||||
uint32_t rtap_presentflags ;
|
|
||||||
uint_fast16_t rtap_position ;
|
|
||||||
owl_captured_request request ; // Message to send to the aggregator
|
owl_captured_request request ; // Message to send to the aggregator
|
||||||
ssize_t nsent ; // sendto return value
|
uint16_t rtap_bytes ; // Radiotap header size
|
||||||
owl_bool check[15] ; // Present flags
|
owl_bool rtap_fields[15] ; // Present flags
|
||||||
uint8_t raw_packet_fc1 ; // First byte of the received frame's FC
|
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
|
uint8_t raw_packet_fc2 ; // Second byte of the received frame's FC
|
||||||
uint8_t raw_packet_flags ; // IEEE 802.11 header flags
|
uint8_t raw_packet_flags ; // IEEE 802.11 header flags
|
||||||
|
@ -790,7 +787,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||||
owl_bool is_explicit_packet = TRUE ; // Is the packet an explicit request?
|
owl_bool is_explicit_packet = TRUE ; // Is the packet an explicit request?
|
||||||
// Is the packet an autocalibration positioning request?
|
// Is the packet an autocalibration positioning request?
|
||||||
owl_bool uses_autocalibration_request_port = FALSE ;
|
owl_bool uses_autocalibration_request_port = FALSE ;
|
||||||
int i ; // Iterator
|
ssize_t nsent ; // sendto return value
|
||||||
|
|
||||||
// Blank the request:
|
// Blank the request:
|
||||||
memset(&request, 0, sizeof(request)) ;
|
memset(&request, 0, sizeof(request)) ;
|
||||||
|
@ -973,96 +970,8 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||||
else // Active mode, packet was not an explicit request
|
else // Active mode, packet was not an explicit request
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
|
|
||||||
/* Radiotap header handling */
|
/* Radiotap header handling */
|
||||||
|
extract_radiotap_data(packet, &request, rtap_fields) ;
|
||||||
// Get rtap flags:
|
|
||||||
memcpy(&rtap_presentflags,
|
|
||||||
&packet[RTAP_P_PRESENTFLAGS], RTAP_L_PRESENTFLAGS) ;
|
|
||||||
// Radiotap header is little-endian
|
|
||||||
rtap_presentflags = le32toh(rtap_presentflags) ;
|
|
||||||
|
|
||||||
for (i = 0 ; i < 15 ; i++) // Initialise present flags structure
|
|
||||||
check[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++)
|
|
||||||
{
|
|
||||||
if ((rtap_presentflags % 2) == 1)
|
|
||||||
{
|
|
||||||
switch(i)
|
|
||||||
{
|
|
||||||
case RTAP_MACTS:
|
|
||||||
check[RTAP_MACTS] = TRUE ;
|
|
||||||
rtap_position += RTAP_L_MACTS ;
|
|
||||||
break ;
|
|
||||||
case RTAP_FLAGS:
|
|
||||||
check[RTAP_FLAGS] = TRUE;
|
|
||||||
rtap_position += RTAP_L_FLAGS ;
|
|
||||||
break ;
|
|
||||||
case RTAP_RATE:
|
|
||||||
check[RTAP_RATE] = TRUE;
|
|
||||||
rtap_position += RTAP_L_RATE ;
|
|
||||||
break ;
|
|
||||||
case RTAP_CHANNEL:
|
|
||||||
rtap_position += RTAP_L_CHANNEL ;
|
|
||||||
rtap_position += RTAP_L_CHANNELTYPE ;
|
|
||||||
break ;
|
|
||||||
case RTAP_FHSS:
|
|
||||||
check[RTAP_FHSS] = TRUE;
|
|
||||||
rtap_position += RTAP_L_FHSS ;
|
|
||||||
break ;
|
|
||||||
case RTAP_ANTENNASIGNALDBM:
|
|
||||||
memcpy(&(request.antenna_signal_dbm),
|
|
||||||
&packet[rtap_position], RTAP_L_ANTENNASIGNALDBM) ;
|
|
||||||
check[RTAP_ANTENNASIGNALDBM] = TRUE;
|
|
||||||
if (VERBOSE_INFO)
|
|
||||||
printf("Antenna signal: %d dBm\n",
|
|
||||||
request.antenna_signal_dbm - 0x100);
|
|
||||||
rtap_position += RTAP_L_ANTENNASIGNALDBM ;
|
|
||||||
break ;
|
|
||||||
case RTAP_ANTENNANOISEDBM:
|
|
||||||
check[RTAP_ANTENNANOISEDBM] = TRUE;
|
|
||||||
rtap_position += RTAP_L_ANTENNANOISEDBM ;
|
|
||||||
break ;
|
|
||||||
case RTAP_LOCKQUALITY:
|
|
||||||
check[RTAP_LOCKQUALITY] = TRUE;
|
|
||||||
rtap_position += RTAP_L_LOCKQUALITY ;
|
|
||||||
break ;
|
|
||||||
case RTAP_TXATTENUATION:
|
|
||||||
check[RTAP_TXATTENUATION] = TRUE;
|
|
||||||
rtap_position += RTAP_L_TXATTENUATION ;
|
|
||||||
break ;
|
|
||||||
case RTAP_TXATTENUATIONDB:
|
|
||||||
check[RTAP_TXATTENUATIONDB] = TRUE;
|
|
||||||
rtap_position += RTAP_L_TXATTENUATIONDB ;
|
|
||||||
break ;
|
|
||||||
case RTAP_TXATTENUATIONDBM:
|
|
||||||
check[RTAP_TXATTENUATIONDBM] = TRUE;
|
|
||||||
rtap_position += RTAP_L_TXATTENUATIONDBM ;
|
|
||||||
break ;
|
|
||||||
case RTAP_ANTENNA:
|
|
||||||
check[RTAP_ANTENNA] = TRUE;
|
|
||||||
rtap_position += RTAP_L_ANTENNA ;
|
|
||||||
break ;
|
|
||||||
case RTAP_ANTENNASIGNALDB:
|
|
||||||
check[RTAP_ANTENNASIGNALDB] = TRUE;
|
|
||||||
rtap_position += RTAP_L_ANTENNASIGNALDB ;
|
|
||||||
break ;
|
|
||||||
case RTAP_ANTENNANOISEDB:
|
|
||||||
check[RTAP_ANTENNANOISEDB] = TRUE;
|
|
||||||
rtap_position += RTAP_L_ANTENNANOISEDB ;
|
|
||||||
break ;
|
|
||||||
case RTAP_FCS:
|
|
||||||
check[RTAP_FCS] = TRUE;
|
|
||||||
rtap_position += RTAP_L_FCS ;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rtap_presentflags /= 2 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Display the packet details */
|
/* Display the packet details */
|
||||||
if (GET_DISPLAY_CAPTURED())
|
if (GET_DISPLAY_CAPTURED())
|
||||||
|
@ -1091,7 +1000,7 @@ void read_packet(u_char *args, const struct pcap_pkthdr *header,
|
||||||
owl_mac_bytes_to_string(request.mobile_mac_addr_bytes),
|
owl_mac_bytes_to_string(request.mobile_mac_addr_bytes),
|
||||||
request_time_str,
|
request_time_str,
|
||||||
start_time_str,
|
start_time_str,
|
||||||
check[RTAP_ANTENNASIGNALDBM] ?
|
rtap_fields[RTAP_ANTENNASIGNALDBM] ?
|
||||||
request.antenna_signal_dbm - 0x100 : 0,
|
request.antenna_signal_dbm - 0x100 : 0,
|
||||||
owl_ntohf(request.x_position),
|
owl_ntohf(request.x_position),
|
||||||
owl_ntohf(request.y_position),
|
owl_ntohf(request.y_position),
|
||||||
|
@ -1130,6 +1039,110 @@ void extract_calibration_data(const u_char *packet,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fills 'request' with the required data extracted from the Radiotap
|
||||||
|
* header of 'packet'. The elements of 'rtap_fields' are set to TRUE
|
||||||
|
* when the corresponding Radiotap flag is found in the packet.
|
||||||
|
*/
|
||||||
|
void extract_radiotap_data(const u_char *packet,
|
||||||
|
owl_captured_request *request,
|
||||||
|
owl_bool rtap_fields[15])
|
||||||
|
{
|
||||||
|
uint32_t rtap_presentflags ;
|
||||||
|
uint_fast16_t rtap_position ;
|
||||||
|
int i ; // Iterator
|
||||||
|
|
||||||
|
// Get rtap flags:
|
||||||
|
memcpy(&rtap_presentflags,
|
||||||
|
&packet[RTAP_P_PRESENTFLAGS], RTAP_L_PRESENTFLAGS) ;
|
||||||
|
// The Radiotap header is little-endian
|
||||||
|
rtap_presentflags = le32toh(rtap_presentflags) ;
|
||||||
|
|
||||||
|
for (i = 0 ; i < 15 ; i++) // Initialise present flags structure
|
||||||
|
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++)
|
||||||
|
{
|
||||||
|
if ((rtap_presentflags % 2) == 1)
|
||||||
|
{
|
||||||
|
switch(i)
|
||||||
|
{
|
||||||
|
case RTAP_MACTS:
|
||||||
|
rtap_fields[RTAP_MACTS] = TRUE ;
|
||||||
|
rtap_position += RTAP_L_MACTS ;
|
||||||
|
break ;
|
||||||
|
case RTAP_FLAGS:
|
||||||
|
rtap_fields[RTAP_FLAGS] = TRUE;
|
||||||
|
rtap_position += RTAP_L_FLAGS ;
|
||||||
|
break ;
|
||||||
|
case RTAP_RATE:
|
||||||
|
rtap_fields[RTAP_RATE] = TRUE;
|
||||||
|
rtap_position += RTAP_L_RATE ;
|
||||||
|
break ;
|
||||||
|
case RTAP_CHANNEL:
|
||||||
|
rtap_position += RTAP_L_CHANNEL ;
|
||||||
|
rtap_position += RTAP_L_CHANNELTYPE ;
|
||||||
|
break ;
|
||||||
|
case RTAP_FHSS:
|
||||||
|
rtap_fields[RTAP_FHSS] = TRUE;
|
||||||
|
rtap_position += RTAP_L_FHSS ;
|
||||||
|
break ;
|
||||||
|
case RTAP_ANTENNASIGNALDBM:
|
||||||
|
memcpy(&request->antenna_signal_dbm,
|
||||||
|
&packet[rtap_position], RTAP_L_ANTENNASIGNALDBM) ;
|
||||||
|
rtap_fields[RTAP_ANTENNASIGNALDBM] = TRUE;
|
||||||
|
if (VERBOSE_INFO)
|
||||||
|
printf("Antenna signal: %d dBm\n",
|
||||||
|
request->antenna_signal_dbm - 0x100);
|
||||||
|
rtap_position += RTAP_L_ANTENNASIGNALDBM ;
|
||||||
|
break ;
|
||||||
|
case RTAP_ANTENNANOISEDBM:
|
||||||
|
rtap_fields[RTAP_ANTENNANOISEDBM] = TRUE;
|
||||||
|
rtap_position += RTAP_L_ANTENNANOISEDBM ;
|
||||||
|
break ;
|
||||||
|
case RTAP_LOCKQUALITY:
|
||||||
|
rtap_fields[RTAP_LOCKQUALITY] = TRUE;
|
||||||
|
rtap_position += RTAP_L_LOCKQUALITY ;
|
||||||
|
break ;
|
||||||
|
case RTAP_TXATTENUATION:
|
||||||
|
rtap_fields[RTAP_TXATTENUATION] = TRUE;
|
||||||
|
rtap_position += RTAP_L_TXATTENUATION ;
|
||||||
|
break ;
|
||||||
|
case RTAP_TXATTENUATIONDB:
|
||||||
|
rtap_fields[RTAP_TXATTENUATIONDB] = TRUE;
|
||||||
|
rtap_position += RTAP_L_TXATTENUATIONDB ;
|
||||||
|
break ;
|
||||||
|
case RTAP_TXATTENUATIONDBM:
|
||||||
|
rtap_fields[RTAP_TXATTENUATIONDBM] = TRUE;
|
||||||
|
rtap_position += RTAP_L_TXATTENUATIONDBM ;
|
||||||
|
break ;
|
||||||
|
case RTAP_ANTENNA:
|
||||||
|
rtap_fields[RTAP_ANTENNA] = TRUE;
|
||||||
|
rtap_position += RTAP_L_ANTENNA ;
|
||||||
|
break ;
|
||||||
|
case RTAP_ANTENNASIGNALDB:
|
||||||
|
rtap_fields[RTAP_ANTENNASIGNALDB] = TRUE;
|
||||||
|
rtap_position += RTAP_L_ANTENNASIGNALDB ;
|
||||||
|
break ;
|
||||||
|
case RTAP_ANTENNANOISEDB:
|
||||||
|
rtap_fields[RTAP_ANTENNANOISEDB] = TRUE;
|
||||||
|
rtap_position += RTAP_L_ANTENNANOISEDB ;
|
||||||
|
break ;
|
||||||
|
case RTAP_FCS:
|
||||||
|
rtap_fields[RTAP_FCS] = TRUE;
|
||||||
|
rtap_position += RTAP_L_FCS ;
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rtap_presentflags /= 2 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get our own MAC address and copy it to 'mac_bytes'.
|
* Get our own MAC address and copy it to 'mac_bytes'.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue