GNUnet  0.11.x
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
gnunet-helper-transport-wlan.c File Reference

mediator between the wlan interface and gnunet; must run as root (SUID will do) This code will work under GNU/Linux only. More...

#include "gnunet_config.h"
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <netpacket/packet.h>
#include <linux/if_ether.h>
#include <linux/if.h>
#include <linux/wireless.h>
#include <netinet/in.h>
#include <linux/if_tun.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#include <sys/param.h>
#include <stdint.h>
#include "gnunet_protocols.h"
#include "plugin_transport_wlan.h"
Include dependency graph for gnunet-helper-transport-wlan.c:

Go to the source code of this file.

Data Structures

struct  PrismValue
 Values in the 'struct PrismHeader'. More...
 
struct  PrismHeader
 Prism header format ('struct p80211msg' in Linux). More...
 
struct  Ieee80211RadiotapHeader
 Generic header for radiotap messages (receiving and sending). More...
 
struct  RadiotapTransmissionHeader
 Format of the header we need to prepend to messages to be sent to the Kernel. More...
 
struct  Ieee80211RadiotapHeaderIterator
 struct Ieee80211RadiotapHeaderIterator - tracks walk through present radiotap arguments in the radiotap header. More...
 
struct  HardwareInfos
 struct for storing the information of the hardware. More...
 
struct  SendBuffer
 IO buffer used for buffering data in transit (to wireless or to stdout). More...
 
struct  MessageStreamTokenizer
 Handle to a message stream tokenizer. More...
 

Macros

#define ARPHRD_ETHER   1
 Packet format type for the messages we receive from the kernel. More...
 
#define ARPHRD_IEEE80211   801
 Packet format type for the messages we receive from the kernel. More...
 
#define ARPHRD_IEEE80211_PRISM   802
 Packet format type for the messages we receive from the kernel. More...
 
#define ARPHRD_IEEE80211_FULL   803
 Packet format type for the messages we receive from the kernel. More...
 
#define MAXLINE   4096
 Maximum size of a message allowed in either direction (used for our receive and sent buffers). More...
 
#define PRISM_DEVICE_NAME_LENGTH   16
 Device name length in PRISM frames. More...
 
#define PRISM_MSGCODE_MONITOR   0x0041
 Monitor Frame (indicator that we have a 'struct PrismHeader'). More...
 
#define PRISM_DID_MACTIME   0x2041
 Mac time element. More...
 
#define PRISM_DID_CHANNEL   0x3041
 Channel element. More...
 
#define PRISM_DID_SIGNAL   0x6041
 Signal element. More...
 
#define PRISM_DID_NOISE   0x7041
 Noise element. More...
 
#define PRISM_DID_RATE   0x8041
 Rate element, in units/multiples of 500Khz. More...
 
#define PRISM_STATUS_OK   0
 Value is set (supplied) More...
 
#define PRISM_STATUS_NO_VALUE   1
 Value not supplied. More...
 
#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK   (1 << IEEE80211_RADIOTAP_EXT)
 Bitmask indicating an extension of the bitmask is used. More...
 
#define IEEE80211_RADIOTAP_F_CFP   0x01
 Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present'). More...
 
#define IEEE80211_RADIOTAP_F_SHORTPRE   0x02
 Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present'). More...
 
#define IEEE80211_RADIOTAP_F_WEP   0x04
 Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present'). More...
 
#define IEEE80211_RADIOTAP_F_FRAG   0x08
 Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present'). More...
 
#define IEEE80211_RADIOTAP_F_FCS   0x10
 Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present'). More...
 
#define IEEE80211_RADIOTAP_F_DATAPAD   0x20
 Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present'). More...
 
#define IEEE80211_RADIOTAP_F_RX_BADFCS   0x0001
 For IEEE80211_RADIOTAP_RX_FLAGS: frame failed crc check. More...
 
#define IEEE80211_RADIOTAP_F_TX_FAIL   0x0001
 For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): failed due to excessive retries. More...
 
#define IEEE80211_RADIOTAP_F_TX_CTS   0x0002
 For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): used cts 'protection'. More...
 
#define IEEE80211_RADIOTAP_F_TX_RTS   0x0004
 For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): used rts/cts handshake. More...
 
#define IEEE80211_RADIOTAP_F_TX_NOACK   0x0008
 For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): frame should not be ACKed. More...
 
#define IEEE80211_RADIOTAP_F_TX_NOSEQ   0x0010
 For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): sequence number handled by userspace. More...
 
#define IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK
 The above 'struct RadiotapTransmissionHeader' should have the following value for 'header.it_present' based on the presence of the 'rate' and 'txflags' in the overall struct. More...
 
#define ALIGN_FACTOR   8
 To what multiple do we align messages? 8 byte should suffice for everyone for now. More...
 
#define MIN_BUFFER_SIZE   sizeof(struct GNUNET_MessageHeader)
 Smallest supported message. More...
 

Typedefs

typedef void(* MessageTokenizerCallback) (void *cls, const struct GNUNET_MessageHeader *message)
 Functions with this signature are called whenever a complete message is received by the tokenizer. More...
 

Enumerations

enum  RadiotapType {
  IEEE80211_RADIOTAP_TSFT = 0, IEEE80211_RADIOTAP_FLAGS = 1, IEEE80211_RADIOTAP_RATE = 2, IEEE80211_RADIOTAP_CHANNEL = 3,
  IEEE80211_RADIOTAP_FHSS = 4, IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5, IEEE80211_RADIOTAP_DBM_ANTNOISE = 6, IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
  IEEE80211_RADIOTAP_TX_ATTENUATION = 8, IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9, IEEE80211_RADIOTAP_DBM_TX_POWER = 10, IEEE80211_RADIOTAP_ANTENNA = 11,
  IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12, IEEE80211_RADIOTAP_DB_ANTNOISE = 13, IEEE80211_RADIOTAP_RX_FLAGS = 14, IEEE80211_RADIOTAP_TX_FLAGS = 15,
  IEEE80211_RADIOTAP_RTS_RETRIES = 16, IEEE80211_RADIOTAP_DATA_RETRIES = 17, IEEE80211_RADIOTAP_EXT = 31
}
 Bits in the 'it_present' bitmask from the 'struct Ieee80211RadiotapHeader'. More...
 

Functions

struct PrismValue __attribute__ ((packed))
 
static struct MessageStreamTokenizermst_create (MessageTokenizerCallback cb, void *cb_cls)
 Create a message stream tokenizer. More...
 
static int mst_receive (struct MessageStreamTokenizer *mst, const char *buf, size_t size)
 Add incoming data to the receive buffer and call the callback for all complete messages. More...
 
static void mst_destroy (struct MessageStreamTokenizer *mst)
 Destroys a tokenizer. More...
 
static int ieee80211_radiotap_iterator_init (struct Ieee80211RadiotapHeaderIterator *iterator, const struct Ieee80211RadiotapHeader *radiotap_header, size_t max_length)
 Radiotap header iteration. More...
 
static int ieee80211_radiotap_iterator_next (struct Ieee80211RadiotapHeaderIterator *iterator)
 Returns the next radiotap parser iterator arg. More...
 
static unsigned long calc_crc_osdep (const unsigned char *buf, size_t len)
 Calculate crc32, the start of the calculation. More...
 
static int check_crc_buf_osdep (const unsigned char *buf, size_t len)
 Calculate and check crc of the wlan packet. More...
 
static int get_channel_from_frequency (int32_t frequency)
 Return the channel from the frequency (in Mhz) More...
 
static int linux_get_channel (const struct HardwareInfos *dev)
 Get the channel used by our WLAN interface. More...
 
static ssize_t linux_read (struct HardwareInfos *dev, unsigned char *buf, size_t buf_size, struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
 Read from the raw socket (the wlan card), parse the packet and put the result into the buffer for transmission to 'stdout'. More...
 
static int open_device_raw (struct HardwareInfos *dev)
 Open the wireless network interface for reading/writing. More...
 
static int test_wlan_interface (const char *iface)
 Test if the given interface name really corresponds to a wireless device. More...
 
static int mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, const struct HardwareInfos *dev)
 Test incoming packets mac for being our own. More...
 
static void mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, const struct HardwareInfos *dev)
 Set the wlan header to sane values to make attacks more difficult. More...
 
static void stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
 Process data from the stdin. More...
 
int main (int argc, char *argv[])
 Main function of the helper. More...
 

Variables

uint32_t did
 This has a different ID for each parameter, see PRISM_DID_* constants. More...
 
uint16_t status
 See PRISM_STATUS_*-constants. More...
 
uint16_t len
 length of data (which is always a uint32_t, but presumably this can be used to specify that fewer bytes are used (with values in 'len' from 0-4). More...
 
uint32_t data
 The data value. More...
 
uint32_t msgcode
 We expect this to be a PRISM_MSGCODE_*. More...
 
uint32_t msglen
 The length of the entire header. More...
 
char devname [16]
 Name of the device that captured the packet. More...
 
enum RadiotapType __attribute__
 
static struct SendBuffer write_pout
 Buffer for data read from stdin to be transmitted to the wirless card. More...
 
static struct SendBuffer write_std
 Buffer for data read from the wireless card to be transmitted to stdout. More...
 

Detailed Description

mediator between the wlan interface and gnunet; must run as root (SUID will do) This code will work under GNU/Linux only.

Author
David Brodski
Christian Grothoff

This program will allow receiving and sending traffic from the WLAN interface. It will force traffic to be in 'ad-hoc' mode, use the proper MAC address of the WLAN interface and use a GNUnet-specific SSID (and a GNUnet-specific SNAP header). It only takes a single argument, which is the name of the WLAN interface to use. The program detects if the interface is not a WLAN interface and exits with an error in that case.

Once initialized, the program will first send a 'struct GNUNET_TRANSPORT_WLAN_HelperControlMessage' to 'stdout'. That message contains the MAC address of the WLAN interface. It will then read messages from the WLAN interface and send them together with performance information as 'struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage' messages to 'stdout'. Furthermore, it will read a stream of messages from 'stdin' that have the format from 'struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage'. Those messages will then be sent via the WLAN interface; however, the sender MAC address will be forced to be the correct address from our WLAN card. If 'stdin' closes, receiving from the WLAN interface will continue. If 'stdout' causes a SIGPIPE, the process dies from the signal. Errors cause an error message to be reported to 'stderr', in most cases the process also exits (with status code '1'). The program never terminates normally; it is safe to kill the process with SIGTERM or SIGKILL at any time.

Since it uses RAW sockets, the binary must be installed SUID or run as 'root'. In order to keep the security risk of the resulting SUID binary minimal, the program ONLY opens the RAW socket with root privileges, then drops them and only then starts to process command line arguments. The code also does not link against any shared libraries (except libc) and is strictly minimal (except for checking for errors). The following list of people have reviewed this code and considered it safe since the last modification (if you reviewed it, please have your name added to the list):

Definition in file gnunet-helper-transport-wlan.c.

Macro Definition Documentation

◆ ARPHRD_ETHER

#define ARPHRD_ETHER   1

Packet format type for the messages we receive from the kernel.

This is for Ethernet 10Mbps format (no performance information included).

Definition at line 145 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read(), open_device_raw(), and stdin_send_hw().

◆ ARPHRD_IEEE80211

#define ARPHRD_IEEE80211   801

Packet format type for the messages we receive from the kernel.

This is for plain messages (with no performance information included).

Definition at line 153 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read(), open_device_raw(), and stdin_send_hw().

◆ ARPHRD_IEEE80211_PRISM

#define ARPHRD_IEEE80211_PRISM   802

Packet format type for the messages we receive from the kernel.

This is for the PRISM format.

Definition at line 160 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read(), open_device_raw(), and stdin_send_hw().

◆ ARPHRD_IEEE80211_FULL

#define ARPHRD_IEEE80211_FULL   803

Packet format type for the messages we receive from the kernel.

This is for messages with a 'struct Ieee80211RadiotapHeader' (see below).

Definition at line 167 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read(), open_device_raw(), and stdin_send_hw().

◆ MAXLINE

#define MAXLINE   4096

Maximum size of a message allowed in either direction (used for our receive and sent buffers).

Definition at line 174 of file gnunet-helper-transport-wlan.c.

Referenced by main(), and stdin_send_hw().

◆ PRISM_DEVICE_NAME_LENGTH

#define PRISM_DEVICE_NAME_LENGTH   16

Device name length in PRISM frames.

(In the kernel, this is "WLAN_DEVNAMELEN_MAX")

Definition at line 183 of file gnunet-helper-transport-wlan.c.

◆ PRISM_MSGCODE_MONITOR

#define PRISM_MSGCODE_MONITOR   0x0041

Monitor Frame (indicator that we have a 'struct PrismHeader').

Definition at line 188 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read().

◆ PRISM_DID_MACTIME

#define PRISM_DID_MACTIME   0x2041

Mac time element.

In micro-seconds. Drivers appear to use a 64bit counter to hold mactime internal the then fill the prism header with the lower 32 bits

Definition at line 195 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read().

◆ PRISM_DID_CHANNEL

#define PRISM_DID_CHANNEL   0x3041

Channel element.

Definition at line 200 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read().

◆ PRISM_DID_SIGNAL

#define PRISM_DID_SIGNAL   0x6041

Signal element.

Should be the signal strength in dbm, some people suggest that instead "100 - (strength in dbm)" is used (to make this a positive integer).

Definition at line 207 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read().

◆ PRISM_DID_NOISE

#define PRISM_DID_NOISE   0x7041

Noise element.

Definition at line 212 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read().

◆ PRISM_DID_RATE

#define PRISM_DID_RATE   0x8041

Rate element, in units/multiples of 500Khz.

Definition at line 217 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read().

◆ PRISM_STATUS_OK

#define PRISM_STATUS_OK   0

Value is set (supplied)

Definition at line 223 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read().

◆ PRISM_STATUS_NO_VALUE

#define PRISM_STATUS_NO_VALUE   1

Value not supplied.

Definition at line 228 of file gnunet-helper-transport-wlan.c.

◆ IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK

#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK   (1 << IEEE80211_RADIOTAP_EXT)

Bitmask indicating an extension of the bitmask is used.

(Mask corresponding to IEEE80211_RADIOTAP_EXT).

Definition at line 462 of file gnunet-helper-transport-wlan.c.

Referenced by ieee80211_radiotap_iterator_init().

◆ IEEE80211_RADIOTAP_F_CFP

#define IEEE80211_RADIOTAP_F_CFP   0x01

Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present').

The radiotap flags are an 8-bit field.

Frame was sent/received during CFP (Contention Free Period)

Definition at line 473 of file gnunet-helper-transport-wlan.c.

◆ IEEE80211_RADIOTAP_F_SHORTPRE

#define IEEE80211_RADIOTAP_F_SHORTPRE   0x02

Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present').

The radiotap flags are an 8-bit field.

Frame was sent/received with short preamble

Definition at line 483 of file gnunet-helper-transport-wlan.c.

◆ IEEE80211_RADIOTAP_F_WEP

#define IEEE80211_RADIOTAP_F_WEP   0x04

Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present').

The radiotap flags are an 8-bit field.

Frame was sent/received with WEP encryption

Definition at line 493 of file gnunet-helper-transport-wlan.c.

◆ IEEE80211_RADIOTAP_F_FRAG

#define IEEE80211_RADIOTAP_F_FRAG   0x08

Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present').

The radiotap flags are an 8-bit field.

Frame was sent/received with fragmentation

Definition at line 503 of file gnunet-helper-transport-wlan.c.

◆ IEEE80211_RADIOTAP_F_FCS

#define IEEE80211_RADIOTAP_F_FCS   0x10

Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present').

The radiotap flags are an 8-bit field.

Frame includes FCS (CRC at the end that needs to be removeD).

Definition at line 513 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read().

◆ IEEE80211_RADIOTAP_F_DATAPAD

#define IEEE80211_RADIOTAP_F_DATAPAD   0x20

Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a 'struct Ieee80211RadiotapHeader' extension if the IEEE80211_RADIOTAP_FLAGS bit is set in 'it_present').

The radiotap flags are an 8-bit field.

Frame has padding between 802.11 header and payload (to 32-bit boundary)

Definition at line 524 of file gnunet-helper-transport-wlan.c.

◆ IEEE80211_RADIOTAP_F_RX_BADFCS

#define IEEE80211_RADIOTAP_F_RX_BADFCS   0x0001

For IEEE80211_RADIOTAP_RX_FLAGS: frame failed crc check.

Definition at line 531 of file gnunet-helper-transport-wlan.c.

Referenced by linux_read().

◆ IEEE80211_RADIOTAP_F_TX_FAIL

#define IEEE80211_RADIOTAP_F_TX_FAIL   0x0001

For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): failed due to excessive retries.

Definition at line 537 of file gnunet-helper-transport-wlan.c.

◆ IEEE80211_RADIOTAP_F_TX_CTS

#define IEEE80211_RADIOTAP_F_TX_CTS   0x0002

For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): used cts 'protection'.

Definition at line 543 of file gnunet-helper-transport-wlan.c.

◆ IEEE80211_RADIOTAP_F_TX_RTS

#define IEEE80211_RADIOTAP_F_TX_RTS   0x0004

For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): used rts/cts handshake.

Definition at line 549 of file gnunet-helper-transport-wlan.c.

◆ IEEE80211_RADIOTAP_F_TX_NOACK

#define IEEE80211_RADIOTAP_F_TX_NOACK   0x0008

For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): frame should not be ACKed.

Definition at line 555 of file gnunet-helper-transport-wlan.c.

Referenced by stdin_send_hw().

◆ IEEE80211_RADIOTAP_F_TX_NOSEQ

#define IEEE80211_RADIOTAP_F_TX_NOSEQ   0x0010

For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): sequence number handled by userspace.

Definition at line 561 of file gnunet-helper-transport-wlan.c.

Referenced by stdin_send_hw().

◆ IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK

#define IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK
Value:
((1 \
<< \
IEEE80211_RADIOTAP_RATE) \
| (1 \
<< \
IEEE80211_RADIOTAP_TX_FLAGS __le16 bitmap.

The above 'struct RadiotapTransmissionHeader' should have the following value for 'header.it_present' based on the presence of the 'rate' and 'txflags' in the overall struct.

Definition at line 642 of file gnunet-helper-transport-wlan.c.

Referenced by stdin_send_hw().

◆ ALIGN_FACTOR

#define ALIGN_FACTOR   8

To what multiple do we align messages? 8 byte should suffice for everyone for now.

Definition at line 774 of file gnunet-helper-transport-wlan.c.

Referenced by mst_receive().

◆ MIN_BUFFER_SIZE

#define MIN_BUFFER_SIZE   sizeof(struct GNUNET_MessageHeader)

Smallest supported message.

Definition at line 779 of file gnunet-helper-transport-wlan.c.

Referenced by mst_create().

Typedef Documentation

◆ MessageTokenizerCallback

typedef void(* MessageTokenizerCallback) (void *cls, const struct GNUNET_MessageHeader *message)

Functions with this signature are called whenever a complete message is received by the tokenizer.

Parameters
clsclosure
messagethe actual message

Definition at line 789 of file gnunet-helper-transport-wlan.c.

Enumeration Type Documentation

◆ RadiotapType

Bits in the 'it_present' bitmask from the 'struct Ieee80211RadiotapHeader'.

For each value, we give the name, data type, unit and then a description below. Note that the actual size of the extension can be bigger as arguments must be padded so that args of a given length must begin at a boundary of that length. However, note that compound args are allowed (eg, 2 x uint16_t for IEEE80211_RADIOTAP_CHANNEL) so total argument length is not a reliable indicator of alignment requirement. See also 'man 9 ieee80211_radiotap'.

Enumerator
IEEE80211_RADIOTAP_TSFT 

IEEE80211_RADIOTAP_TSFT __le64 microseconds.

Value in microseconds of the MAC's 64-bit 802.11 Time Synchronization Function timer when the first bit of the MPDU arrived at the MAC. For received frames, only.

IEEE80211_RADIOTAP_FLAGS 

IEEE80211_RADIOTAP_FLAGS uint8_t bitmap.

Properties of transmitted and received frames. See flags defined below.

IEEE80211_RADIOTAP_RATE 

IEEE80211_RADIOTAP_RATE uint8_t 500kb/s.

Tx/Rx data rate

IEEE80211_RADIOTAP_CHANNEL 

IEEE80211_RADIOTAP_CHANNEL 2 x __le16 MHz, bitmap.

Tx/Rx frequency in MHz, followed by flags (see below).

IEEE80211_RADIOTAP_FHSS 

IEEE80211_RADIOTAP_FHSS __le16 see below.

For frequency-hopping radios, the hop set (first byte) and pattern (second byte).

IEEE80211_RADIOTAP_DBM_ANTSIGNAL 

IEEE80211_RADIOTAP_DBM_ANTSIGNAL s8 decibels from one milliwatt (dBm)

RF signal power at the antenna, decibel difference from one milliwatt.

IEEE80211_RADIOTAP_DBM_ANTNOISE 

IEEE80211_RADIOTAP_DBM_ANTNOISE s8 decibels from one milliwatt (dBm)

RF noise power at the antenna, decibel difference from one milliwatt.

IEEE80211_RADIOTAP_LOCK_QUALITY 

IEEE80211_RADIOTAP_LOCK_QUALITY __le16 unitless.

Quality of Barker code lock. Unitless. Monotonically nondecreasing with "better" lock strength. Called "Signal Quality" in datasheets. (Is there a standard way to measure this?)

IEEE80211_RADIOTAP_TX_ATTENUATION 

IEEE80211_RADIOTAP_TX_ATTENUATION __le16 unitless.

Transmit power expressed as unitless distance from max power set at factory calibration. 0 is max power. Monotonically nondecreasing with lower power levels.

IEEE80211_RADIOTAP_DB_TX_ATTENUATION 

IEEE80211_RADIOTAP_DB_TX_ATTENUATION __le16 decibels (dB)

Transmit power expressed as decibel distance from max power set at factory calibration. 0 is max power. Monotonically nondecreasing with lower power levels.

IEEE80211_RADIOTAP_DBM_TX_POWER 

IEEE80211_RADIOTAP_DBM_TX_POWER s8 decibels from one milliwatt (dBm)

Transmit power expressed as dBm (decibels from a 1 milliwatt reference). This is the absolute power level measured at the antenna port.

IEEE80211_RADIOTAP_ANTENNA 

IEEE80211_RADIOTAP_ANTENNA uint8_t antenna index.

Unitless indication of the Rx/Tx antenna for this packet. The first antenna is antenna 0.

IEEE80211_RADIOTAP_DB_ANTSIGNAL 

IEEE80211_RADIOTAP_DB_ANTSIGNAL uint8_t decibel (dB)

RF signal power at the antenna, decibel difference from an arbitrary, fixed reference.

IEEE80211_RADIOTAP_DB_ANTNOISE 

IEEE80211_RADIOTAP_DB_ANTNOISE uint8_t decibel (dB)

RF noise power at the antenna, decibel difference from an arbitrary, fixed reference point.

IEEE80211_RADIOTAP_RX_FLAGS 

IEEE80211_RADIOTAP_RX_FLAGS __le16 bitmap.

Properties of received frames. See flags defined below.

IEEE80211_RADIOTAP_TX_FLAGS 

IEEE80211_RADIOTAP_TX_FLAGS __le16 bitmap.

Properties of transmitted frames. See flags defined below.

IEEE80211_RADIOTAP_RTS_RETRIES 

IEEE80211_RADIOTAP_RTS_RETRIES uint8_t data.

Number of rts retries a transmitted frame used.

IEEE80211_RADIOTAP_DATA_RETRIES 

IEEE80211_RADIOTAP_DATA_RETRIES uint8_t data.

Number of unicast retries a transmitted frame used.

IEEE80211_RADIOTAP_EXT 

Extension bit, used to indicate that more bits are needed for the bitmask.

Definition at line 303 of file gnunet-helper-transport-wlan.c.

304 {
313 
321 
328 
342 
351 
360 
370 
379 
388 
398 
406 
414 
422 
429 
436 
443 
450 
456 };
Extension bit, used to indicate that more bits are needed for the bitmask.
IEEE80211_RADIOTAP_TX_FLAGS __le16 bitmap.
IEEE80211_RADIOTAP_RTS_RETRIES uint8_t data.
IEEE80211_RADIOTAP_DB_TX_ATTENUATION __le16 decibels (dB)
IEEE80211_RADIOTAP_RX_FLAGS __le16 bitmap.
IEEE80211_RADIOTAP_LOCK_QUALITY __le16 unitless.
IEEE80211_RADIOTAP_DBM_ANTSIGNAL s8 decibels from one milliwatt (dBm)
IEEE80211_RADIOTAP_TSFT __le64 microseconds.
IEEE80211_RADIOTAP_TX_ATTENUATION __le16 unitless.
IEEE80211_RADIOTAP_DBM_TX_POWER s8 decibels from one milliwatt (dBm)
IEEE80211_RADIOTAP_FLAGS uint8_t bitmap.
IEEE80211_RADIOTAP_CHANNEL 2 x __le16 MHz, bitmap.
IEEE80211_RADIOTAP_DATA_RETRIES uint8_t data.
IEEE80211_RADIOTAP_DBM_ANTNOISE s8 decibels from one milliwatt (dBm)
IEEE80211_RADIOTAP_ANTENNA uint8_t antenna index.
IEEE80211_RADIOTAP_DB_ANTNOISE uint8_t decibel (dB)
IEEE80211_RADIOTAP_DB_ANTSIGNAL uint8_t decibel (dB)
IEEE80211_RADIOTAP_FHSS __le16 see below.
IEEE80211_RADIOTAP_RATE uint8_t 500kb/s.

Function Documentation

◆ __attribute__()

struct PrismValue __attribute__ ( (packed)  )

◆ mst_create()

static struct MessageStreamTokenizer* mst_create ( MessageTokenizerCallback  cb,
void *  cb_cls 
)
static

Create a message stream tokenizer.

Parameters
cbfunction to call on completed messages
cb_clsclosure for cb
Returns
handle to tokenizer

Definition at line 839 of file gnunet-helper-transport-wlan.c.

References MessageStreamTokenizer::cb, MessageStreamTokenizer::cb_cls, MessageStreamTokenizer::curr_buf, MessageStreamTokenizer::hdr, MIN_BUFFER_SIZE, and ret.

Referenced by main().

841 {
842  struct MessageStreamTokenizer *ret;
843 
844  ret = malloc (sizeof(struct MessageStreamTokenizer));
845  if (NULL == ret)
846  {
847  fprintf (stderr, "Failed to allocate buffer for tokenizer\n");
848  exit (1);
849  }
850  ret->hdr = malloc (MIN_BUFFER_SIZE);
851  if (NULL == ret->hdr)
852  {
853  fprintf (stderr, "Failed to allocate buffer for alignment\n");
854  exit (1);
855  }
856  ret->curr_buf = MIN_BUFFER_SIZE;
857  ret->cb = cb;
858  ret->cb_cls = cb_cls;
859  return ret;
860 }
#define MIN_BUFFER_SIZE
Smallest supported message.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
MessageTokenizerCallback cb
Function to call on completed messages.
Handle to a message stream tokenizer.
size_t curr_buf
Size of the buffer (starting at &#39;hdr&#39;).
struct GNUNET_MessageHeader * hdr
Beginning of the buffer.
Here is the caller graph for this function:

◆ mst_receive()

static int mst_receive ( struct MessageStreamTokenizer mst,
const char *  buf,
size_t  size 
)
static

Add incoming data to the receive buffer and call the callback for all complete messages.

Parameters
msttokenizer to use
bufinput data to add
sizenumber of bytes in buf
Returns
GNUNET_OK if we are done processing (need more data) GNUNET_SYSERR if the data stream is corrupt

Definition at line 874 of file gnunet-helper-transport-wlan.c.

References ALIGN_FACTOR, MessageStreamTokenizer::cb, MessageStreamTokenizer::cb_cls, MessageStreamTokenizer::curr_buf, delta, do_align(), GNUNET_memcpy, GNUNET_MIN, GNUNET_NO, GNUNET_OK, GNUNET_YES, MessageStreamTokenizer::hdr, MessageStreamTokenizer::off, MessageStreamTokenizer::pos, ret, size, and GNUNET_MessageHeader::size.

Referenced by main().

876 {
877  const struct GNUNET_MessageHeader *hdr;
878  size_t delta;
879  uint16_t want;
880  char *ibuf;
881  int need_align;
882  unsigned long offset;
883  int ret;
884 
885  ret = GNUNET_OK;
886  ibuf = (char *) mst->hdr;
887  while (mst->pos > 0)
888  {
889 do_align:
890  if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
891  (0 != (mst->off % ALIGN_FACTOR)))
892  {
893  /* need to align or need more space */
894  mst->pos -= mst->off;
895  memmove (ibuf, &ibuf[mst->off], mst->pos);
896  mst->off = 0;
897  }
898  if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
899  {
900  delta =
901  GNUNET_MIN (sizeof(struct GNUNET_MessageHeader)
902  - (mst->pos - mst->off), size);
903  GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
904  mst->pos += delta;
905  buf += delta;
906  size -= delta;
907  }
908  if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
909  {
910  return GNUNET_OK;
911  }
912  hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
913  want = ntohs (hdr->size);
914  if (want < sizeof(struct GNUNET_MessageHeader))
915  {
916  fprintf (stderr,
917  "Received invalid message from stdin\n");
918  exit (1);
919  }
920  if (mst->curr_buf - mst->off < want)
921  {
922  /* need more space */
923  mst->pos -= mst->off;
924  memmove (ibuf, &ibuf[mst->off], mst->pos);
925  mst->off = 0;
926  }
927  if (want > mst->curr_buf)
928  {
929  mst->hdr = realloc (mst->hdr, want);
930  if (NULL == mst->hdr)
931  {
932  fprintf (stderr, "Failed to allocate buffer for alignment\n");
933  exit (1);
934  }
935  ibuf = (char *) mst->hdr;
936  mst->curr_buf = want;
937  }
938  hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
939  if (mst->pos - mst->off < want)
940  {
941  delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
942  GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
943  mst->pos += delta;
944  buf += delta;
945  size -= delta;
946  }
947  if (mst->pos - mst->off < want)
948  {
949  return GNUNET_OK;
950  }
951  mst->cb (mst->cb_cls, hdr);
952  mst->off += want;
953  if (mst->off == mst->pos)
954  {
955  /* reset to beginning of buffer, it's free right now! */
956  mst->off = 0;
957  mst->pos = 0;
958  }
959  }
960  while (size > 0)
961  {
962  if (size < sizeof(struct GNUNET_MessageHeader))
963  break;
964  offset = (unsigned long) buf;
965  need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
966  if (GNUNET_NO == need_align)
967  {
968  /* can try to do zero-copy and process directly from original buffer */
969  hdr = (const struct GNUNET_MessageHeader *) buf;
970  want = ntohs (hdr->size);
971  if (want < sizeof(struct GNUNET_MessageHeader))
972  {
973  fprintf (stderr,
974  "Received invalid message from stdin\n");
975  exit (1);
976  }
977  if (size < want)
978  break; /* or not, buffer incomplete, so copy to private buffer... */
979  mst->cb (mst->cb_cls, hdr);
980  buf += want;
981  size -= want;
982  }
983  else
984  {
985  /* need to copy to private buffer to align;
986  * yes, we go a bit more spagetti than usual here */
987  goto do_align;
988  }
989  }
990  if (size > 0)
991  {
992  if (size + mst->pos > mst->curr_buf)
993  {
994  mst->hdr = realloc (mst->hdr, size + mst->pos);
995  if (NULL == mst->hdr)
996  {
997  fprintf (stderr, "Failed to allocate buffer for alignment\n");
998  exit (1);
999  }
1000  ibuf = (char *) mst->hdr;
1001  mst->curr_buf = size + mst->pos;
1002  }
1003  if (mst->pos + size > mst->curr_buf)
1004  {
1005  fprintf (stderr,
1006  "Assertion failed\n");
1007  exit (1);
1008  }
1009  GNUNET_memcpy (&ibuf[mst->pos], buf, size);
1010  mst->pos += size;
1011  }
1012  return ret;
1013 }
size_t off
How many bytes in buffer have we already processed?
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
static size_t do_align(size_t start_position, size_t end_position)
Given the start and end position of a block of data, return the end position of that data after align...
Definition: fs_directory.c:487
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
size_t pos
How many bytes in buffer are valid right now?
#define ALIGN_FACTOR
To what multiple do we align messages? 8 byte should suffice for everyone for now.
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:80
static char buf[2048]
static unsigned int size
Size of the "table".
Definition: peer.c:67
MessageTokenizerCallback cb
Function to call on completed messages.
size_t curr_buf
Size of the buffer (starting at &#39;hdr&#39;).
struct GNUNET_MessageHeader * hdr
Beginning of the buffer.
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mst_destroy()

static void mst_destroy ( struct MessageStreamTokenizer mst)
static

Destroys a tokenizer.

Parameters
msttokenizer to destroy

Definition at line 1022 of file gnunet-helper-transport-wlan.c.

References MessageStreamTokenizer::hdr.

Referenced by main().

1023 {
1024  free (mst->hdr);
1025  free (mst);
1026 }
struct GNUNET_MessageHeader * hdr
Beginning of the buffer.
Here is the caller graph for this function:

◆ ieee80211_radiotap_iterator_init()

static int ieee80211_radiotap_iterator_init ( struct Ieee80211RadiotapHeaderIterator iterator,
const struct Ieee80211RadiotapHeader radiotap_header,
size_t  max_length 
)
static

Radiotap header iteration.

call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator struct Ieee80211RadiotapHeaderIterator (no need to init the struct beforehand) then loop calling __ieee80211_radiotap_iterator_next()... it returns -1 if there are no more args in the header, or the next argument type index that is present. The iterator's this_arg member points to the start of the argument associated with the current argument index that is present, which can be found in the iterator's this_arg_index member. This arg index corresponds to the IEEE80211_RADIOTAP_... defines.

Parameters
iteratoriterator to initialize
radiotap_headermessage to parse
max_lengthnumber of valid bytes in radiotap_header
Returns
0 on success, -1 on error

Definition at line 1052 of file gnunet-helper-transport-wlan.c.

References Ieee80211RadiotapHeaderIterator::arg, Ieee80211RadiotapHeaderIterator::bitmap_shifter, GNUNET_le16toh, GNUNET_le32toh, IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK, Ieee80211RadiotapHeader::it_len, Ieee80211RadiotapHeader::it_present, Ieee80211RadiotapHeader::it_version, Ieee80211RadiotapHeaderIterator::max_length, and Ieee80211RadiotapHeaderIterator::rtheader.

Referenced by linux_read().

1057 {
1058  if ((iterator == NULL) ||
1059  (radiotap_header == NULL))
1060  return -1;
1061 
1062  /* Linux only supports version 0 radiotap format */
1063  if (0 != radiotap_header->it_version)
1064  return -1;
1065 
1066  /* sanity check for allowed length and radiotap length field */
1067  if ((max_length < sizeof(struct Ieee80211RadiotapHeader)) ||
1068  (max_length < (GNUNET_le16toh (radiotap_header->it_len))))
1069  return -1;
1070 
1071  memset (iterator, 0, sizeof(struct Ieee80211RadiotapHeaderIterator));
1072  iterator->rtheader = radiotap_header;
1073  iterator->max_length = GNUNET_le16toh (radiotap_header->it_len);
1074  iterator->bitmap_shifter = GNUNET_le32toh (radiotap_header->it_present);
1075  iterator->arg = ((uint8_t *) radiotap_header) + sizeof(struct
1077 
1078  /* find payload start allowing for extended bitmap(s) */
1080  {
1081  while (GNUNET_le32toh (*((uint32_t *) iterator->arg))
1083  {
1084  iterator->arg += sizeof(uint32_t);
1085  /*
1086  * check for insanity where the present bitmaps
1087  * keep claiming to extend up to or even beyond the
1088  * stated radiotap header length
1089  */if (iterator->arg - ((uint8_t*) iterator->rtheader) >
1090  iterator->max_length)
1091  return -1;
1092  }
1093  iterator->arg += sizeof(uint32_t);
1094  /*
1095  * no need to check again for blowing past stated radiotap
1096  * header length, becuase ieee80211_radiotap_iterator_next
1097  * checks it before it is dereferenced
1098  */}
1099  /* we are all initialized happily */
1100  return 0;
1101 }
const struct Ieee80211RadiotapHeader * rtheader
pointer to the radiotap header we are walking through
#define GNUNET_le32toh(x)
size_t max_length
length of radiotap header in host byte ordering
#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK
Bitmask indicating an extension of the bitmask is used.
uint32_t bitmap_shifter
internal shifter for current uint32_t bitmap, (it_present in host byte order), If bit 0 is set...
uint32_t it_present
A bitmap telling which fields are present.
Generic header for radiotap messages (receiving and sending).
struct Ieee80211RadiotapHeaderIterator - tracks walk through present radiotap arguments in the radiot...
#define GNUNET_le16toh(x)
const uint8_t * arg
internal next argument pointer
uint16_t it_len
length of the whole header in bytes, including it_version, it_pad, it_len, and data fields...
Here is the caller graph for this function:

◆ ieee80211_radiotap_iterator_next()

static int ieee80211_radiotap_iterator_next ( struct Ieee80211RadiotapHeaderIterator iterator)
static

Returns the next radiotap parser iterator arg.

This function returns the next radiotap arg index (IEEE80211_RADIOTAP_...) and sets iterator->this_arg to point to the payload for the arg. It takes care of alignment handling and extended present fields. interator->this_arg can be changed by the caller. The args pointed to are in little-endian format.

Parameters
iteratorradiotap_iterator to move to next arg (if any)
Returns
next present arg index on success or -1 if no more or error

Definition at line 1117 of file gnunet-helper-transport-wlan.c.

References Ieee80211RadiotapHeaderIterator::arg, Ieee80211RadiotapHeaderIterator::arg_index, Ieee80211RadiotapHeaderIterator::bitmap_shifter, GNUNET_le32toh, IEEE80211_RADIOTAP_ANTENNA, IEEE80211_RADIOTAP_CHANNEL, IEEE80211_RADIOTAP_DATA_RETRIES, IEEE80211_RADIOTAP_DB_ANTNOISE, IEEE80211_RADIOTAP_DB_ANTSIGNAL, IEEE80211_RADIOTAP_DB_TX_ATTENUATION, IEEE80211_RADIOTAP_DBM_ANTNOISE, IEEE80211_RADIOTAP_DBM_ANTSIGNAL, IEEE80211_RADIOTAP_DBM_TX_POWER, IEEE80211_RADIOTAP_FHSS, IEEE80211_RADIOTAP_FLAGS, IEEE80211_RADIOTAP_LOCK_QUALITY, IEEE80211_RADIOTAP_RATE, IEEE80211_RADIOTAP_RTS_RETRIES, IEEE80211_RADIOTAP_RX_FLAGS, IEEE80211_RADIOTAP_TSFT, IEEE80211_RADIOTAP_TX_ATTENUATION, IEEE80211_RADIOTAP_TX_FLAGS, Ieee80211RadiotapHeaderIterator::max_length, Ieee80211RadiotapHeaderIterator::next_bitmap, Ieee80211RadiotapHeaderIterator::rtheader, Ieee80211RadiotapHeaderIterator::this_arg, and Ieee80211RadiotapHeaderIterator::this_arg_index.

Referenced by linux_read().

1119 {
1120  /*
1121  * small length lookup table for all radiotap types we heard of
1122  * starting from b0 in the bitmap, so we can walk the payload
1123  * area of the radiotap header
1124  *
1125  * There is a requirement to pad args, so that args
1126  * of a given length must begin at a boundary of that length
1127  * -- but note that compound args are allowed (eg, 2 x uint16_t
1128  * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
1129  * a reliable indicator of alignment requirement.
1130  *
1131  * upper nybble: content alignment for arg
1132  * lower nybble: content length for arg
1133  */static const uint8_t rt_sizes[] = {
1134  [IEEE80211_RADIOTAP_TSFT] = 0x88,
1135  [IEEE80211_RADIOTAP_FLAGS] = 0x11,
1136  [IEEE80211_RADIOTAP_RATE] = 0x11,
1137  [IEEE80211_RADIOTAP_CHANNEL] = 0x24,
1138  [IEEE80211_RADIOTAP_FHSS] = 0x22,
1145  [IEEE80211_RADIOTAP_ANTENNA] = 0x11,
1148  [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
1149  [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
1152  /*
1153  * add more here as they are defined in
1154  * include/net/ieee80211_radiotap.h
1155  */
1156  };
1157 
1158  /*
1159  * for every radiotap entry we can at
1160  * least skip (by knowing the length)...
1161  */
1162  while (iterator->arg_index < sizeof(rt_sizes))
1163  {
1164  int hit = (0 != (iterator->bitmap_shifter & 1));
1165 
1166  if (hit)
1167  {
1168  unsigned int wanted_alignment;
1169  unsigned int unalignment;
1170  /*
1171  * arg is present, account for alignment padding
1172  * 8-bit args can be at any alignment
1173  * 16-bit args must start on 16-bit boundary
1174  * 32-bit args must start on 32-bit boundary
1175  * 64-bit args must start on 64-bit boundary
1176  *
1177  * note that total arg size can differ from alignment of
1178  * elements inside arg, so we use upper nybble of length table
1179  * to base alignment on. First, 'wanted_alignment' is set to be
1180  * 1 for 8-bit, 2 for 16-bit, 4 for 32-bit and 8 for 64-bit
1181  * arguments. Then, we calculate the 'unalignment' (how many
1182  * bytes we are over by taking the difference of 'arg' and the
1183  * overall starting point modulo the desired alignment. As
1184  * desired alignments are powers of two, we can do modulo with
1185  * binary "&" (and also avoid the possibility of a division by
1186  * zero if the 'rt_sizes' table contains bogus entries).
1187  *
1188  * also note: these alignments are relative to the start of the
1189  * radiotap header. There is no guarantee that the radiotap
1190  * header itself is aligned on any kind of boundary, thus we
1191  * need to really look at the delta here.
1192  */wanted_alignment = rt_sizes[iterator->arg_index] >> 4;
1193  unalignment = (((void *) iterator->arg) - ((void *) iterator->rtheader))
1194  & (wanted_alignment - 1);
1195  if (0 != unalignment)
1196  {
1197  /* need padding (by 'wanted_alignment - unalignment') */
1198  iterator->arg_index += wanted_alignment - unalignment;
1199  }
1200 
1201  /*
1202  * this is what we will return to user, but we need to
1203  * move on first so next call has something fresh to test
1204  */
1205  iterator->this_arg_index = iterator->arg_index;
1206  iterator->this_arg = iterator->arg;
1207 
1208  /* internally move on the size of this arg (using lower nybble from
1209  the table) */
1210  iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
1211 
1212  /*
1213  * check for insanity where we are given a bitmap that
1214  * claims to have more arg content than the length of the
1215  * radiotap section. We will normally end up equalling this
1216  * max_length on the last arg, never exceeding it.
1217  */if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) >
1218  iterator->max_length)
1219  return -1;
1220  }
1221 
1222  /* Now, move on to next bit / next entry */
1223  iterator->arg_index++;
1224 
1225  if (0 == (iterator->arg_index % 32))
1226  {
1227  /* completed current uint32_t bitmap */
1228  if (0 != (iterator->bitmap_shifter & 1))
1229  {
1230  /* bit 31 was set, there is more; move to next uint32_t bitmap */
1231  iterator->bitmap_shifter = GNUNET_le32toh (*iterator->next_bitmap);
1232  iterator->next_bitmap++;
1233  }
1234  else
1235  {
1236  /* no more bitmaps: end (by setting arg_index to high, unsupported value) */
1237  iterator->arg_index = sizeof(rt_sizes);
1238  }
1239  }
1240  else
1241  {
1242  /* just try the next bit (while loop will move on) */
1243  iterator->bitmap_shifter >>= 1;
1244  }
1245 
1246  /* if we found a valid arg earlier, return it now */
1247  if (hit)
1248  return iterator->this_arg_index;
1249  }
1250 
1251  /* we don't know how to handle any more args (or there are no more),
1252  so we're done (this is not an error) */
1253  return -1;
1254 }
const struct Ieee80211RadiotapHeader * rtheader
pointer to the radiotap header we are walking through
#define GNUNET_le32toh(x)
size_t max_length
length of radiotap header in host byte ordering
IEEE80211_RADIOTAP_TX_FLAGS __le16 bitmap.
IEEE80211_RADIOTAP_RTS_RETRIES uint8_t data.
IEEE80211_RADIOTAP_DB_TX_ATTENUATION __le16 decibels (dB)
uint32_t bitmap_shifter
internal shifter for current uint32_t bitmap, (it_present in host byte order), If bit 0 is set...
unsigned int this_arg_index
IEEE80211_RADIOTAP_...
IEEE80211_RADIOTAP_RX_FLAGS __le16 bitmap.
IEEE80211_RADIOTAP_LOCK_QUALITY __le16 unitless.
IEEE80211_RADIOTAP_DBM_ANTSIGNAL s8 decibels from one milliwatt (dBm)
IEEE80211_RADIOTAP_TSFT __le64 microseconds.
IEEE80211_RADIOTAP_TX_ATTENUATION __le16 unitless.
IEEE80211_RADIOTAP_DBM_TX_POWER s8 decibels from one milliwatt (dBm)
const uint8_t * this_arg
pointer to current radiotap arg
IEEE80211_RADIOTAP_FLAGS uint8_t bitmap.
const uint32_t * next_bitmap
internal pointer to next present uint32_t (if IEEE80211_RADIOTAP_EXT is used).
IEEE80211_RADIOTAP_CHANNEL 2 x __le16 MHz, bitmap.
const uint8_t * arg
internal next argument pointer
IEEE80211_RADIOTAP_DATA_RETRIES uint8_t data.
IEEE80211_RADIOTAP_DBM_ANTNOISE s8 decibels from one milliwatt (dBm)
IEEE80211_RADIOTAP_ANTENNA uint8_t antenna index.
IEEE80211_RADIOTAP_DB_ANTNOISE uint8_t decibel (dB)
unsigned int arg_index
internal next argument index
IEEE80211_RADIOTAP_DB_ANTSIGNAL uint8_t decibel (dB)
IEEE80211_RADIOTAP_FHSS __le16 see below.
IEEE80211_RADIOTAP_RATE uint8_t 500kb/s.
Here is the caller graph for this function:

◆ calc_crc_osdep()

static unsigned long calc_crc_osdep ( const unsigned char *  buf,
size_t  len 
)
static

Calculate crc32, the start of the calculation.

Parameters
bufbuffer to calc the crc
lenlen of the buffer
Returns
crc sum

Definition at line 1265 of file gnunet-helper-transport-wlan.c.

Referenced by check_crc_buf_osdep().

1266 {
1267  static const unsigned long int crc_tbl_osdep[256] = {
1268  0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
1269  0xE963A535, 0x9E6495A3,
1270  0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD,
1271  0xE7B82D07, 0x90BF1D91,
1272  0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB,
1273  0xF4D4B551, 0x83D385C7,
1274  0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
1275  0xFA0F3D63, 0x8D080DF5,
1276  0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447,
1277  0xD20D85FD, 0xA50AB56B,
1278  0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75,
1279  0xDCD60DCF, 0xABD13D59,
1280  0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,
1281  0xCFBA9599, 0xB8BDA50F,
1282  0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11,
1283  0xC1611DAB, 0xB6662D3D,
1284  0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
1285  0x9FBFE4A5, 0xE8B8D433,
1286  0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D,
1287  0x91646C97, 0xE6635C01,
1288  0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B,
1289  0x8208F4C1, 0xF50FC457,
1290  0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49,
1291  0x8CD37CF3, 0xFBD44C65,
1292  0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7,
1293  0xA4D1C46D, 0xD3D6F4FB,
1294  0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5,
1295  0xAA0A4C5F, 0xDD0D7CC9,
1296  0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3,
1297  0xB966D409, 0xCE61E49F,
1298  0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
1299  0xB7BD5C3B, 0xC0BA6CAD,
1300  0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF,
1301  0x04DB2615, 0x73DC1683,
1302  0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D,
1303  0x0A00AE27, 0x7D079EB1,
1304  0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
1305  0x196C3671, 0x6E6B06E7,
1306  0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9,
1307  0x17B7BE43, 0x60B08ED5,
1308  0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767,
1309  0x3FB506DD, 0x48B2364B,
1310  0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55,
1311  0x316E8EEF, 0x4669BE79,
1312  0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703,
1313  0x220216B9, 0x5505262F,
1314  0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31,
1315  0x2CD99E8B, 0x5BDEAE1D,
1316  0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
1317  0x72076785, 0x05005713,
1318  0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D,
1319  0x7CDCEFB7, 0x0BDBDF21,
1320  0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B,
1321  0x6FB077E1, 0x18B74777,
1322  0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69,
1323  0x616BFFD3, 0x166CCF45,
1324  0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7,
1325  0x4969474D, 0x3E6E77DB,
1326  0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5,
1327  0x47B2CF7F, 0x30B5FFE9,
1328  0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,
1329  0x54DE5729, 0x23D967BF,
1330  0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1,
1331  0x5A05DF1B, 0x2D02EF8D
1332  };
1333 
1334  unsigned long crc = 0xFFFFFFFF;
1335 
1336  for (; len > 0; len--, buf++)
1337  crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8);
1338  return(~crc);
1339 }
static char buf[2048]
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ check_crc_buf_osdep()

static int check_crc_buf_osdep ( const unsigned char *  buf,
size_t  len 
)
static

Calculate and check crc of the wlan packet.

Parameters
bufbuffer of the packet, with len + 4 bytes of data, the last 4 bytes being the checksum
lenlength of the payload in data
Returns
0 on success (checksum matches), 1 on error

Definition at line 1351 of file gnunet-helper-transport-wlan.c.

References calc_crc_osdep(), and PrismValue::len.

Referenced by linux_read().

1352 {
1353  unsigned long crc;
1354 
1355  crc = calc_crc_osdep (buf, len);
1356  buf += len;
1357  if ((((crc) & 0xFF) == buf[0]) && (((crc >> 8) & 0xFF) == buf[1]) &&
1358  ( ((crc >> 16) & 0xFF) == buf[2]) && ( ((crc >> 24) & 0xFF) == buf[3]) )
1359  return 0;
1360  return 1;
1361 }
static char buf[2048]
static unsigned long calc_crc_osdep(const unsigned char *buf, size_t len)
Calculate crc32, the start of the calculation.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_channel_from_frequency()

static int get_channel_from_frequency ( int32_t  frequency)
static

Return the channel from the frequency (in Mhz)

Parameters
frequencyof the channel
Returns
number of the channel

Definition at line 1376 of file gnunet-helper-transport-wlan.c.

Referenced by linux_get_channel().

1377 {
1378  if ((frequency >= 2412) && (frequency <= 2472))
1379  return (frequency - 2407) / 5;
1380  if (frequency == 2484)
1381  return 14;
1382  if ((frequency >= 5000) && (frequency <= 6100))
1383  return (frequency - 5000) / 5;
1384  return -1;
1385 }
Here is the caller graph for this function:

◆ linux_get_channel()

static int linux_get_channel ( const struct HardwareInfos dev)
static

Get the channel used by our WLAN interface.

Parameters
devpointer to the dev struct of the card
Returns
channel number, -1 on error

Definition at line 1395 of file gnunet-helper-transport-wlan.c.

References HardwareInfos::fd_raw, get_channel_from_frequency(), and HardwareInfos::iface.

Referenced by linux_read().

1396 {
1397  struct iwreq wrq;
1398  int32_t frequency;
1399 
1400  memset (&wrq, 0, sizeof(struct iwreq));
1401  strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
1402  if (0 > ioctl (dev->fd_raw, SIOCGIWFREQ, &wrq))
1403  return -1;
1404  frequency = wrq.u.freq.m; /* 'iw_freq' defines 'm' as '__s32', so we keep it signed */
1405  if (100000000 < frequency)
1406  frequency /= 100000;
1407  else if (1000000 < frequency)
1408  frequency /= 1000;
1409  if (1000 < frequency)
1410  return get_channel_from_frequency (frequency);
1411  return frequency;
1412 }
static int get_channel_from_frequency(int32_t frequency)
Return the channel from the frequency (in Mhz)
int fd_raw
file descriptor for the raw socket
char iface[IFNAMSIZ]
Name of the interface, not necessarily 0-terminated (!).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ linux_read()

static ssize_t linux_read ( struct HardwareInfos dev,
unsigned char *  buf,
size_t  buf_size,
struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage ri 
)
static

Read from the raw socket (the wlan card), parse the packet and put the result into the buffer for transmission to 'stdout'.

Parameters
devpointer to the struct of the wlan card
bufbuffer to read to; first bytes will be the 'struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame', followed by the actual payload
buf_sizesize of the buffer
riwhere to write radiotap_rx info
Returns
number of bytes written to 'buf'

Definition at line 1427 of file gnunet-helper-transport-wlan.c.

References ARPHRD_ETHER, ARPHRD_IEEE80211, ARPHRD_IEEE80211_FULL, ARPHRD_IEEE80211_PRISM, HardwareInfos::arptype_in, check_crc_buf_osdep(), PrismValue::data, PrismValue::did, HardwareInfos::fd_raw, GNUNET_le16toh, GNUNET_le64toh, GNUNET_memcpy, IEEE80211_RADIOTAP_ANTENNA, IEEE80211_RADIOTAP_CHANNEL, IEEE80211_RADIOTAP_DB_ANTNOISE, IEEE80211_RADIOTAP_DB_ANTSIGNAL, IEEE80211_RADIOTAP_DBM_ANTNOISE, IEEE80211_RADIOTAP_DBM_ANTSIGNAL, IEEE80211_RADIOTAP_F_FCS, IEEE80211_RADIOTAP_F_RX_BADFCS, IEEE80211_RADIOTAP_FLAGS, ieee80211_radiotap_iterator_init(), ieee80211_radiotap_iterator_next(), IEEE80211_RADIOTAP_RATE, IEEE80211_RADIOTAP_RX_FLAGS, IEEE80211_RADIOTAP_TSFT, Ieee80211RadiotapHeader::it_len, linux_get_channel(), PrismHeader::msgcode, PrismHeader::msglen, ph, PRISM_DID_CHANNEL, PRISM_DID_MACTIME, PRISM_DID_NOISE, PRISM_DID_RATE, PRISM_DID_SIGNAL, PRISM_MSGCODE_MONITOR, PRISM_STATUS_OK, GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage::ri_antenna, GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage::ri_channel, GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage::ri_mactime, GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage::ri_noise, GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage::ri_power, GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage::ri_rate, PrismValue::status, Ieee80211RadiotapHeaderIterator::this_arg, and Ieee80211RadiotapHeaderIterator::this_arg_index.

Referenced by main().

1430 {
1431  unsigned char tmpbuf[buf_size];
1432  ssize_t caplen;
1433  size_t n;
1434  int got_signal = 0;
1435  int got_noise = 0;
1436  int got_channel = 0;
1437  int fcs_removed = 0;
1438 
1439  caplen = read (dev->fd_raw, tmpbuf, buf_size);
1440  if (0 > caplen)
1441  {
1442  if (EAGAIN == errno)
1443  return 0;
1444  fprintf (stderr, "Failed to read from RAW socket: %s\n", strerror (errno));
1445  return -1;
1446  }
1447 
1448  memset (ri, 0, sizeof(*ri));
1449  switch (dev->arptype_in)
1450  {
1452  {
1453  const struct PrismHeader *ph;
1454 
1455  ph = (const struct PrismHeader*) tmpbuf;
1456  n = ph->msglen;
1457  if ((n < 8) || (n >= caplen))
1458  return 0; /* invalid format */
1459  if ((PRISM_MSGCODE_MONITOR == ph->msgcode) &&
1460  (n >= sizeof(struct PrismHeader)))
1461  {
1462  const char *pos;
1463  size_t left;
1464  struct PrismValue pv;
1465 
1466  left = n - sizeof(struct PrismHeader);
1467  pos = (const char *) &ph[1];
1468  while (left > sizeof(struct PrismValue))
1469  {
1470  left -= sizeof(struct PrismValue);
1471  GNUNET_memcpy (&pv, pos, sizeof(struct PrismValue));
1472  pos += sizeof(struct PrismValue);
1473 
1474  switch (pv.did)
1475  {
1476  case PRISM_DID_NOISE:
1477  if (PRISM_STATUS_OK == pv.status)
1478  {
1479  ri->ri_noise = pv.data;
1480  /* got_noise = 1; */
1481  }
1482  break;
1483 
1484  case PRISM_DID_RATE:
1485  if (PRISM_STATUS_OK == pv.status)
1486  ri->ri_rate = pv.data * 500000;
1487  break;
1488 
1489  case PRISM_DID_CHANNEL:
1490  if (PRISM_STATUS_OK == pv.status)
1491  {
1492  ri->ri_channel = pv.data;
1493  got_channel = 1;
1494  }
1495  break;
1496 
1497  case PRISM_DID_MACTIME:
1498  if (PRISM_STATUS_OK == pv.status)
1499  ri->ri_mactime = pv.data;
1500  break;
1501 
1502  case PRISM_DID_SIGNAL:
1503  if (PRISM_STATUS_OK == pv.status)
1504  {
1505  ri->ri_power = pv.data;
1506  /* got_signal = 1; */
1507  }
1508  break;
1509  }
1510  }
1511  }
1512  if ((n < 8) || (n >= caplen))
1513  return 0; /* invalid format */
1514  }
1515  break;
1516 
1517  case ARPHRD_IEEE80211_FULL:
1518  {
1520  struct Ieee80211RadiotapHeader *rthdr;
1521 
1522  memset (&iterator, 0, sizeof(iterator));
1523  rthdr = (struct Ieee80211RadiotapHeader *) tmpbuf;
1524  n = GNUNET_le16toh (rthdr->it_len);
1525  if ((n < sizeof(struct Ieee80211RadiotapHeader)) || (n >= caplen))
1526  return 0; /* invalid 'it_len' */
1527  if (0 != ieee80211_radiotap_iterator_init (&iterator, rthdr, caplen))
1528  return 0;
1529  /* go through the radiotap arguments we have been given by the driver */
1531  {
1532  switch (iterator.this_arg_index)
1533  {
1535  ri->ri_mactime = GNUNET_le64toh (*((uint64_t *) iterator.this_arg));
1536  break;
1537 
1539  if (! got_signal)
1540  {
1541  ri->ri_power = *((int8_t*) iterator.this_arg);
1542  got_signal = 1;
1543  }
1544  break;
1545 
1547  if (! got_signal)
1548  {
1549  ri->ri_power = *((int8_t*) iterator.this_arg);
1550  got_signal = 1;
1551  }
1552  break;
1553 
1555  if (! got_noise)
1556  {
1557  ri->ri_noise = *((int8_t*) iterator.this_arg);
1558  got_noise = 1;
1559  }
1560  break;
1561 
1563  if (! got_noise)
1564  {
1565  ri->ri_noise = *((int8_t*) iterator.this_arg);
1566  got_noise = 1;
1567  }
1568  break;
1569 
1571  ri->ri_antenna = *iterator.this_arg;
1572  break;
1573 
1575  ri->ri_channel = *iterator.this_arg;
1576  got_channel = 1;
1577  break;
1578 
1580  ri->ri_rate = (*iterator.this_arg) * 500000;
1581  break;
1582 
1584  {
1585  uint8_t flags = *iterator.this_arg;
1586  /* is the CRC visible at the end? if so, remove */
1587  if (0 != (flags & IEEE80211_RADIOTAP_F_FCS))
1588  {
1589  fcs_removed = 1;
1590  caplen -= sizeof(uint32_t);
1591  }
1592  break;
1593  }
1594 
1596  {
1597  uint16_t flags = ntohs (*((uint16_t *) iterator.this_arg));
1598  if (0 != (flags & IEEE80211_RADIOTAP_F_RX_BADFCS))
1599  return 0;
1600  }
1601  break;
1602  } /* end of 'switch' */
1603  } /* end of the 'while' loop */
1604  }
1605  break;
1606 
1607  case ARPHRD_IEEE80211:
1608  n = 0; /* no header */
1609  break;
1610 
1611  case ARPHRD_ETHER:
1612  {
1613  if (sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) > caplen)
1614  return 0; /* invalid */
1616  tmpbuf + sizeof(struct
1618  caplen - sizeof(struct
1620  - 4 /* 4 byte FCS */);
1621  return caplen - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4;
1622  }
1623 
1624  default:
1625  errno = ENOTSUP; /* unsupported format */
1626  return -1;
1627  }
1628  caplen -= n;
1629  if (! got_channel)
1630  ri->ri_channel = linux_get_channel (dev);
1631 
1632  /* detect CRC32 at the end, even if the flag wasn't set and remove it */
1633  if ((0 == fcs_removed) &&
1634  (0 == check_crc_buf_osdep (tmpbuf + n, caplen - sizeof(uint32_t))))
1635  {
1636  /* NOTE: this heuristic can of course fail if there happens to
1637  be a matching checksum at the end. Would be good to have
1638  some data to see how often this heuristic actually works. */
1639  caplen -= sizeof(uint32_t);
1640  }
1641  /* copy payload to target buffer */
1642  GNUNET_memcpy (buf, tmpbuf + n, caplen);
1643  return caplen;
1644 }
static int iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries.
uint64_t ri_mactime
IEEE80211_RADIOTAP_TSFT, 0 if unknown.
int32_t ri_noise
either IEEE80211_RADIOTAP_DBM_ANTNOISE or IEEE80211_RADIOTAP_DB_ANTNOISE, 0 if unknown.
#define ARPHRD_IEEE80211_PRISM
Packet format type for the messages we receive from the kernel.
Prism header format (&#39;struct p80211msg&#39; in Linux).
#define PRISM_DID_CHANNEL
Channel element.
uint32_t ri_rate
IEEE80211_RADIOTAP_RATE * 50000, 0 if unknown.
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
#define PRISM_DID_NOISE
Noise element.
#define ARPHRD_IEEE80211_FULL
Packet format type for the messages we receive from the kernel.
static int ieee80211_radiotap_iterator_init(struct Ieee80211RadiotapHeaderIterator *iterator, const struct Ieee80211RadiotapHeader *radiotap_header, size_t max_length)
Radiotap header iteration.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define PRISM_MSGCODE_MONITOR
Monitor Frame (indicator that we have a &#39;struct PrismHeader&#39;).
uint32_t ri_antenna
IEEE80211_RADIOTAP_ANTENNA, 0 if unknown.
generic definitions for IEEE 802.3 frames
static int linux_get_channel(const struct HardwareInfos *dev)
Get the channel used by our WLAN interface.
#define PRISM_STATUS_OK
Value is set (supplied)
IEEE80211_RADIOTAP_RX_FLAGS __le16 bitmap.
uint32_t msgcode
We expect this to be a PRISM_MSGCODE_*.
static int check_crc_buf_osdep(const unsigned char *buf, size_t len)
Calculate and check crc of the wlan packet.
Values in the &#39;struct PrismHeader&#39;.
IEEE80211_RADIOTAP_DBM_ANTSIGNAL s8 decibels from one milliwatt (dBm)
#define IEEE80211_RADIOTAP_F_RX_BADFCS
For IEEE80211_RADIOTAP_RX_FLAGS: frame failed crc check.
uint32_t msglen
The length of the entire header.
IEEE80211_RADIOTAP_TSFT __le64 microseconds.
static char buf[2048]
#define ARPHRD_ETHER
Packet format type for the messages we receive from the kernel.
Generic header for radiotap messages (receiving and sending).
#define PRISM_DID_SIGNAL
Signal element.
struct Ieee80211RadiotapHeaderIterator - tracks walk through present radiotap arguments in the radiot...
IEEE80211_RADIOTAP_FLAGS uint8_t bitmap.
int fd_raw
file descriptor for the raw socket
#define GNUNET_le16toh(x)
IEEE80211_RADIOTAP_CHANNEL 2 x __le16 MHz, bitmap.
static int ieee80211_radiotap_iterator_next(struct Ieee80211RadiotapHeaderIterator *iterator)
Returns the next radiotap parser iterator arg.
#define IEEE80211_RADIOTAP_F_FCS
Bit in IEEE80211_RADIOTAP_FLAGS (which we might get as part of a &#39;struct Ieee80211RadiotapHeader&#39; ext...
uint32_t ri_channel
IEEE80211_RADIOTAP_CHANNEL, 0 if unknown.
IEEE80211_RADIOTAP_DBM_ANTNOISE s8 decibels from one milliwatt (dBm)
generic definitions for IEEE 802.11 frames
#define PRISM_DID_MACTIME
Mac time element.
int arptype_in
Which format has the header that we&#39;re getting when receiving packets? Some ARPHRD_IEEE80211_XXX-valu...
int32_t ri_power
from radiotap either IEEE80211_RADIOTAP_DBM_ANTSIGNAL or IEEE80211_RADIOTAP_DB_ANTSIGNAL, 0 if unknown.
#define ARPHRD_IEEE80211
Packet format type for the messages we receive from the kernel.
IEEE80211_RADIOTAP_ANTENNA uint8_t antenna index.
uint16_t it_len
length of the whole header in bytes, including it_version, it_pad, it_len, and data fields...
IEEE80211_RADIOTAP_DB_ANTNOISE uint8_t decibel (dB)
IEEE80211_RADIOTAP_DB_ANTSIGNAL uint8_t decibel (dB)
#define GNUNET_le64toh(x)
#define PRISM_DID_RATE
Rate element, in units/multiples of 500Khz.
IEEE80211_RADIOTAP_RATE uint8_t 500kb/s.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_device_raw()

static int open_device_raw ( struct HardwareInfos dev)
static

Open the wireless network interface for reading/writing.

Parameters
devpointer to the device struct
Returns
0 on success

Definition at line 1659 of file gnunet-helper-transport-wlan.c.

References ARPHRD_ETHER, ARPHRD_IEEE80211, ARPHRD_IEEE80211_FULL, ARPHRD_IEEE80211_PRISM, HardwareInfos::arptype_in, HardwareInfos::fd_raw, GNUNET_memcpy, HardwareInfos::iface, MAC_ADDR_SIZE, and HardwareInfos::pl_mac.

Referenced by main().

1660 {
1661  struct ifreq ifr;
1662  struct iwreq wrq;
1663  struct packet_mreq mr;
1664  struct sockaddr_ll sll;
1665 
1666  /* find the interface index */
1667  memset (&ifr, 0, sizeof(ifr));
1668  strncpy (ifr.ifr_name, dev->iface, IFNAMSIZ);
1669  if (-1 == ioctl (dev->fd_raw, SIOCGIFINDEX, &ifr))
1670  {
1671  fprintf (stderr, "ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n",
1672  IFNAMSIZ, dev->iface, strerror (errno));
1673  return 1;
1674  }
1675 
1676  /* lookup the hardware type */
1677  memset (&sll, 0, sizeof(sll));
1678  sll.sll_family = AF_PACKET;
1679  sll.sll_ifindex = ifr.ifr_ifindex;
1680  sll.sll_protocol = htons (ETH_P_ALL);
1681  if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
1682  {
1683  fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
1684  IFNAMSIZ, dev->iface, strerror (errno));
1685  return 1;
1686  }
1687  if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
1688  (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) &&
1689  (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
1690  (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)))
1691  {
1692  fprintf (stderr,
1693  "Error: interface `%.*s' is not using a supported hardware address family (got %d)\n",
1694  IFNAMSIZ, dev->iface,
1695  ifr.ifr_hwaddr.sa_family);
1696  return 1;
1697  }
1698 
1699  /* lookup iw mode */
1700  memset (&wrq, 0, sizeof(struct iwreq));
1701  strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
1702  if (-1 == ioctl (dev->fd_raw, SIOCGIWMODE, &wrq))
1703  {
1704  /* most probably not supported (ie for rtap ipw interface) *
1705  * so just assume its correctly set... */
1706  wrq.u.mode = IW_MODE_MONITOR;
1707  }
1708 
1709  if ((wrq.u.mode != IW_MODE_MONITOR) &&
1710  (wrq.u.mode != IW_MODE_ADHOC))
1711  {
1712  fprintf (stderr,
1713  "Error: interface `%.*s' is not in monitor or ad-hoc mode (got %d)\n",
1714  IFNAMSIZ, dev->iface,
1715  wrq.u.mode);
1716  return 1;
1717  }
1718 
1719  /* Is interface st to up, broadcast & running ? */
1720  if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags)
1721  {
1722  /* Bring interface up */
1723  ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
1724 
1725  if (-1 == ioctl (dev->fd_raw, SIOCSIFFLAGS, &ifr))
1726  {
1727  fprintf (stderr, "ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n",
1728  IFNAMSIZ, dev->iface, strerror (errno));
1729  return 1;
1730  }
1731  }
1732 
1733  /* bind the raw socket to the interface */
1734  if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof(sll)))
1735  {
1736  fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ,
1737  dev->iface, strerror (errno));
1738  return 1;
1739  }
1740 
1741  /* lookup the hardware type */
1742  if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
1743  {
1744  fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
1745  IFNAMSIZ, dev->iface, strerror (errno));
1746  return 1;
1747  }
1748 
1749  GNUNET_memcpy (&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE);
1750  dev->arptype_in = ifr.ifr_hwaddr.sa_family;
1751  if ((ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) &&
1752  (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
1753  (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
1754  (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL))
1755  {
1756  fprintf (stderr, "Unsupported hardware link type %d on interface `%.*s'\n",
1757  ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface);
1758  return 1;
1759  }
1760 
1761  /* enable promiscuous mode */
1762  memset (&mr, 0, sizeof(mr));
1763  mr.mr_ifindex = sll.sll_ifindex;
1764  mr.mr_type = PACKET_MR_PROMISC;
1765  if (0 !=
1766  setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,
1767  sizeof(mr)))
1768  {
1769  fprintf (stderr,
1770  "Failed to enable promiscuous mode on interface `%.*s'\n",
1771  IFNAMSIZ,
1772  dev->iface);
1773  return 1;
1774  }
1775  return 0;
1776 }
#define MAC_ADDR_SIZE
Number fo bytes in a mac address.
#define ARPHRD_IEEE80211_PRISM
Packet format type for the messages we receive from the kernel.
struct GNUNET_TRANSPORT_WLAN_MacAddress pl_mac
MAC address of our own bluetooth interface.
#define ARPHRD_IEEE80211_FULL
Packet format type for the messages we receive from the kernel.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define ARPHRD_ETHER
Packet format type for the messages we receive from the kernel.
int fd_raw
file descriptor for the raw socket
int arptype_in
Which format has the header that we&#39;re getting when receiving packets? Some ARPHRD_IEEE80211_XXX-valu...
char iface[IFNAMSIZ]
Name of the interface, not necessarily 0-terminated (!).
#define ARPHRD_IEEE80211
Packet format type for the messages we receive from the kernel.
Here is the caller graph for this function:

◆ test_wlan_interface()

static int test_wlan_interface ( const char *  iface)
static

Test if the given interface name really corresponds to a wireless device.

Parameters
ifacename of the interface
Returns
0 on success, 1 on error

Definition at line 1787 of file gnunet-helper-transport-wlan.c.

References ret.

Referenced by main().

1788 {
1789  char strbuf[512];
1790  struct stat sbuf;
1791  int ret;
1792 
1793  ret = snprintf (strbuf, sizeof(strbuf),
1794  "/sys/class/net/%s/phy80211/subsystem",
1795  iface);
1796  if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat (strbuf, &sbuf)))
1797  {
1798  fprintf (stderr,
1799  "Did not find 802.11 interface `%s'. Exiting.\n",
1800  iface);
1801  exit (1);
1802  }
1803  return 0;
1804 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Here is the caller graph for this function:

◆ mac_test()

static int mac_test ( const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame taIeeeHeader,
const struct HardwareInfos dev 
)
static

Test incoming packets mac for being our own.

Parameters
taIeeeHeaderbuffer of the packet
devthe Hardware_Infos struct
Returns
0 if mac belongs to us, 1 if mac is for another target

Definition at line 1815 of file gnunet-helper-transport-wlan.c.

References GNUNET_TRANSPORT_WLAN_Ieee80211Frame::addr1, GNUNET_TRANSPORT_WLAN_Ieee80211Frame::addr3, bc_all_mac, MAC_ADDR_SIZE, mac_bssid_gnunet, and HardwareInfos::pl_mac.

Referenced by main().

1817 {
1819 
1820  if ((0 == memcmp (&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) ||
1821  (0 == memcmp (&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE)))
1822  return 0; /* some drivers set no Macs, then assume it is all for us! */
1823 
1824  if (0 != memcmp (&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE))
1825  return 1; /* not a GNUnet ad-hoc package */
1826  if ((0 == memcmp (&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) ||
1827  (0 == memcmp (&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE)))
1828  return 0; /* for us, or broadcast */
1829  return 1; /* not for us */
1830 }
#define MAC_ADDR_SIZE
Number fo bytes in a mac address.
struct GNUNET_TRANSPORT_WLAN_MacAddress pl_mac
MAC address of our own bluetooth interface.
static GNUNET_NETWORK_STRUCT_END const struct GNUNET_TRANSPORT_WLAN_MacAddress mac_bssid_gnunet
GNUnet bssid.
static struct GNUNET_PeerIdentity all_zeros
Peer identity that is all zeros, used as a way to indicate "all peers".
struct GNUNET_TRANSPORT_WLAN_MacAddress addr3
Address 3: BSSID in ad-hoc mode, Destination if station, source if AP.
static const struct GNUNET_TRANSPORT_WLAN_MacAddress bc_all_mac
Broadcast MAC.
struct GNUNET_TRANSPORT_WLAN_MacAddress addr1
Address 1: destination address in ad-hoc mode or AP, BSSID if station,.
Here is the caller graph for this function:

◆ mac_set()

static void mac_set ( struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame taIeeeHeader,
const struct HardwareInfos dev 
)
static

Set the wlan header to sane values to make attacks more difficult.

Parameters
taIeeeHeaderpointer to the header of the packet
devpointer to the Hardware_Infos struct

Definition at line 1840 of file gnunet-helper-transport-wlan.c.

References GNUNET_TRANSPORT_WLAN_Ieee80211Frame::addr2, GNUNET_TRANSPORT_WLAN_Ieee80211Frame::addr3, GNUNET_TRANSPORT_WLAN_Ieee80211Frame::frame_control, IEEE80211_FC0_TYPE_DATA, mac_bssid_gnunet, and HardwareInfos::pl_mac.

Referenced by stdin_send_hw().

1842 {
1843  taIeeeHeader->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
1844  taIeeeHeader->addr2 = dev->pl_mac;
1845  taIeeeHeader->addr3 = mac_bssid_gnunet;
1846 }
struct GNUNET_TRANSPORT_WLAN_MacAddress pl_mac
MAC address of our own bluetooth interface.
#define IEEE80211_FC0_TYPE_DATA
static GNUNET_NETWORK_STRUCT_END const struct GNUNET_TRANSPORT_WLAN_MacAddress mac_bssid_gnunet
GNUnet bssid.
uint16_t frame_control
802.11 Frame Control field.
struct GNUNET_TRANSPORT_WLAN_MacAddress addr3
Address 3: BSSID in ad-hoc mode, Destination if station, source if AP.
struct GNUNET_TRANSPORT_WLAN_MacAddress addr2
Address 2: source address if in ad-hoc-mode or station, BSSID if AP.
Here is the caller graph for this function:

◆ stdin_send_hw()

static void stdin_send_hw ( void *  cls,
const struct GNUNET_MessageHeader hdr 
)
static

Process data from the stdin.

Takes the message, prepends the radiotap transmission header, forces the sender MAC to be correct and puts it into our buffer for transmission to the kernel.

Parameters
clspointer to the device struct ('struct HardwareInfos*')
hdrpointer to the start of the packet

Definition at line 1858 of file gnunet-helper-transport-wlan.c.

References GNUNET_TRANSPORT_WLAN_Ieee80211Frame::addr1, ARPHRD_ETHER, ARPHRD_IEEE80211, ARPHRD_IEEE80211_FULL, ARPHRD_IEEE80211_PRISM, HardwareInfos::arptype_in, SendBuffer::buf, GNUNET_TRANSPORT_WLAN_Ieee8023Frame::dst, GNUNET_TRANSPORT_WLAN_RadiotapSendMessage::frame, GNUNET_htole16, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER, GNUNET_TRANSPORT_WLAN_RadiotapSendMessage::header, RadiotapTransmissionHeader::header, IEEE80211_RADIOTAP_F_TX_NOACK, IEEE80211_RADIOTAP_F_TX_NOSEQ, IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK, Ieee80211RadiotapHeader::it_len, Ieee80211RadiotapHeader::it_pad, Ieee80211RadiotapHeader::it_present, Ieee80211RadiotapHeader::it_version, mac_set(), MAXLINE, RadiotapTransmissionHeader::pad1, HardwareInfos::pl_mac, GNUNET_TRANSPORT_WLAN_RadiotapSendMessage::rate, RadiotapTransmissionHeader::rate, SendBuffer::size, GNUNET_MessageHeader::size, GNUNET_TRANSPORT_WLAN_Ieee8023Frame::src, RadiotapTransmissionHeader::txflags, GNUNET_TRANSPORT_WLAN_Ieee8023Frame::type, GNUNET_MessageHeader::type, and write_pout.

Referenced by main().

1859 {
1860  struct HardwareInfos *dev = cls;
1862  struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *wlanheader;
1863  size_t sendsize;
1864  struct RadiotapTransmissionHeader rtheader;
1865  struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame etheader;
1866 
1867  sendsize = ntohs (hdr->size);
1868  if ((sendsize <
1871  {
1872  fprintf (stderr, "Received malformed message\n");
1873  exit (1);
1874  }
1875  sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)
1876  - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
1877  if (MAXLINE < sendsize)
1878  {
1879  fprintf (stderr, "Packet too big for buffer\n");
1880  exit (1);
1881  }
1882  header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr;
1883  switch (dev->arptype_in)
1884  {
1886  case ARPHRD_IEEE80211_FULL:
1887  case ARPHRD_IEEE80211:
1888  rtheader.header.it_version = 0;
1889  rtheader.header.it_pad = 0;
1890  rtheader.header.it_len = GNUNET_htole16 (sizeof(rtheader));
1891  rtheader.header.it_present = GNUNET_htole16 (
1893  rtheader.rate = header->rate;
1894  rtheader.pad1 = 0;
1895  rtheader.txflags = GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK
1897  GNUNET_memcpy (write_pout.buf, &rtheader, sizeof(rtheader));
1898  GNUNET_memcpy (&write_pout.buf[sizeof(rtheader)], &header->frame, sendsize);
1899  wlanheader = (struct
1901  rtheader)
1902  ];
1903 
1904  /* payload contains MAC address, but we don't trust it, so we'll
1905  * overwrite it with OUR MAC address to prevent mischief */
1906  mac_set (wlanheader, dev);
1907  write_pout.size = sendsize + sizeof(rtheader);
1908  break;
1909 
1910  case ARPHRD_ETHER:
1911  etheader.dst = header->frame.addr1;
1912  /* etheader.src = header->frame.addr2; --- untrusted input */
1913  etheader.src = dev->pl_mac;
1914  etheader.type = htons (ETH_P_IP);
1915  GNUNET_memcpy (write_pout.buf, &etheader, sizeof(etheader));
1916  GNUNET_memcpy (&write_pout.buf[sizeof(etheader)], &header[1], sendsize
1917  - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
1918  write_pout.size = sendsize - sizeof(struct
1920  + sizeof(etheader);
1921  break;
1922 
1923  default:
1924  fprintf (stderr,
1925  "Unsupported ARPTYPE!\n");
1926  break;
1927  }
1928 }
#define ARPHRD_IEEE80211_PRISM
Packet format type for the messages we receive from the kernel.
struct for storing the information of the hardware.
struct GNUNET_TRANSPORT_WLAN_MacAddress pl_mac
MAC address of our own bluetooth interface.
#define ARPHRD_IEEE80211_FULL
Packet format type for the messages we receive from the kernel.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static void mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, const struct HardwareInfos *dev)
Set the wlan header to sane values to make attacks more difficult.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
generic definitions for IEEE 802.3 frames
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
size_t size
How many bytes of data are stored in &#39;buf&#39; for transmission right now? Data always starts at offset 0...
struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame
IEEE Frame to transmit (the sender MAC address will be overwritten by the helper as it does not trust...
#define GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER
Type of data messages from the plugin to the gnunet-wlan-helper.
Format of the header we need to prepend to messages to be sent to the Kernel.
#define ARPHRD_ETHER
Packet format type for the messages we receive from the kernel.
#define IEEE80211_RADIOTAP_F_TX_NOSEQ
For IEEE80211_RADIOTAP_TX_FLAGS (&#39;txflags&#39; in &#39;struct RadiotapTransmissionHeader&#39;): sequence number h...
#define GNUNET_htole16(x)
struct GNUNET_MessageHeader header
Type is &#39;GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER&#39;.
#define IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK
The above &#39;struct RadiotapTransmissionHeader&#39; should have the following value for &#39;header...
#define IEEE80211_RADIOTAP_F_TX_NOACK
For IEEE80211_RADIOTAP_TX_FLAGS (&#39;txflags&#39; in &#39;struct RadiotapTransmissionHeader&#39;): frame should not ...
char buf[4096 *2]
Buffered data; twice the maximum allowed message size as we add some headers.
generic definitions for IEEE 802.11 frames
#define MAXLINE
Maximum size of a message allowed in either direction (used for our receive and sent buffers)...
int arptype_in
Which format has the header that we&#39;re getting when receiving packets? Some ARPHRD_IEEE80211_XXX-valu...
static struct SendBuffer write_pout
Buffer for data read from stdin to be transmitted to the wirless card.
#define ARPHRD_IEEE80211
Packet format type for the messages we receive from the kernel.
Message from the plugin to the WLAN helper: send the given message with the given connection paramete...
struct GNUNET_TRANSPORT_WLAN_MacAddress addr1
Address 1: destination address in ad-hoc mode or AP, BSSID if station,.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main function of the helper.

This code accesses a WLAN interface in monitoring mode (layer 2) and then forwards traffic in both directions between the WLAN interface and stdin/stdout of this process. Error messages are written to stdout.

Parameters
argcnumber of arguments, must be 2
argvarguments only argument is the name of the interface (i.e. 'mon0')
Returns
0 on success (never happens, as we don't return unless aborted), 1 on error

Definition at line 1942 of file gnunet-helper-transport-wlan.c.

References SendBuffer::buf, HardwareInfos::fd_raw, GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage::frame, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER, GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL, GNUNET_TRANSPORT_WLAN_HelperControlMessage::hdr, HardwareInfos::iface, linux_read(), GNUNET_TRANSPORT_WLAN_HelperControlMessage::mac, mac_test(), MAXLINE, mst_create(), mst_destroy(), mst_receive(), open_device_raw(), HardwareInfos::pl_mac, SendBuffer::pos, ret, SendBuffer::size, GNUNET_MessageHeader::size, stdin_mst, stdin_send_hw(), test_wlan_interface(), GNUNET_MessageHeader::type, write_pout, and write_std.

1943 {
1944  struct HardwareInfos dev;
1945  char readbuf[MAXLINE];
1946  int maxfd;
1947  fd_set rfds;
1948  fd_set wfds;
1949  int stdin_open;
1951  int raw_eno;
1952 
1953  /* assert privs so we can modify the firewall rules! */
1954  {
1955 #ifdef HAVE_SETRESUID
1956  uid_t uid = getuid ();
1957 
1958  if (0 != setresuid (uid, 0, 0))
1959  {
1960  fprintf (stderr,
1961  "Failed to setresuid to root: %s\n",
1962  strerror (errno));
1963  return 254;
1964  }
1965 #else
1966  if (0 != seteuid (0))
1967  {
1968  fprintf (stderr,
1969  "Failed to seteuid back to root: %s\n", strerror (errno));
1970  return 254;
1971  }
1972 #endif
1973  }
1974 
1975  /* make use of SGID capabilities on POSIX */
1976  memset (&dev, 0, sizeof(dev));
1977  dev.fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL));
1978  raw_eno = errno; /* remember for later */
1979 
1980  /* now that we've dropped root rights, we can do error checking */
1981  if (2 != argc)
1982  {
1983  fprintf (stderr,
1984  "You must specify the name of the interface as the first and only argument to this program.\n");
1985  if (-1 != dev.fd_raw)
1986  (void) close (dev.fd_raw);
1987  return 1;
1988  }
1989 
1990  if (-1 == dev.fd_raw)
1991  {
1992  fprintf (stderr, "Failed to create raw socket: %s\n", strerror (raw_eno));
1993  return 1;
1994  }
1995  if (dev.fd_raw >= FD_SETSIZE)
1996  {
1997  fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
1998  dev.fd_raw, FD_SETSIZE);
1999  (void) close (dev.fd_raw);
2000  return 1;
2001  }
2002  if (0 != test_wlan_interface (argv[1]))
2003  {
2004  (void) close (dev.fd_raw);
2005  return 1;
2006  }
2007  strncpy (dev.iface, argv[1], IFNAMSIZ);
2008  if (0 != open_device_raw (&dev))
2009  {
2010  (void) close (dev.fd_raw);
2011  return 1;
2012  }
2013 
2014  /* drop privs */
2015  {
2016  uid_t uid = getuid ();
2017 #ifdef HAVE_SETRESUID
2018  if (0 != setresuid (uid, uid, uid))
2019  {
2020  fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
2021  if (-1 != dev.fd_raw)
2022  (void) close (dev.fd_raw);
2023  return 1;
2024  }
2025 #else
2026  if (0 != (setuid (uid) | seteuid (uid)))
2027  {
2028  fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
2029  if (-1 != dev.fd_raw)
2030  (void) close (dev.fd_raw);
2031  return 1;
2032  }
2033 #endif
2034  }
2035 
2036 
2037  /* send MAC address of the WLAN interface to STDOUT first */
2038  {
2040 
2041  macmsg.hdr.size = htons (sizeof(macmsg));
2042  macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
2043  GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof(struct
2045  GNUNET_memcpy (write_std.buf, &macmsg, sizeof(macmsg));
2046  write_std.size = sizeof(macmsg);
2047  }
2048 
2049  stdin_mst = mst_create (&stdin_send_hw, &dev);
2050  stdin_open = 1;
2051  while (1)
2052  {
2053  maxfd = -1;
2054  FD_ZERO (&rfds);
2055  if ((0 == write_pout.size) && (1 == stdin_open))
2056  {
2057  FD_SET (STDIN_FILENO, &rfds);
2058  maxfd = MAX (maxfd, STDIN_FILENO);
2059  }
2060  if (0 == write_std.size)
2061  {
2062  FD_SET (dev.fd_raw, &rfds);
2063  maxfd = MAX (maxfd, dev.fd_raw);
2064  }
2065  FD_ZERO (&wfds);
2066  if (0 < write_std.size)
2067  {
2068  FD_SET (STDOUT_FILENO, &wfds);
2069  maxfd = MAX (maxfd, STDOUT_FILENO);
2070  }
2071  if (0 < write_pout.size)
2072  {
2073  FD_SET (dev.fd_raw, &wfds);
2074  maxfd = MAX (maxfd, dev.fd_raw);
2075  }
2076  {
2077  int retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
2078  if ((-1 == retval) && (EINTR == errno))
2079  continue;
2080  if (0 > retval)
2081  {
2082  fprintf (stderr, "select failed: %s\n", strerror (errno));
2083  break;
2084  }
2085  }
2086  if (FD_ISSET (STDOUT_FILENO, &wfds))
2087  {
2088  ssize_t ret =
2089  write (STDOUT_FILENO, write_std.buf + write_std.pos,
2091  if (0 > ret)
2092  {
2093  fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno));
2094  break;
2095  }
2096  write_std.pos += ret;
2097  if (write_std.pos == write_std.size)
2098  {
2099  write_std.pos = 0;
2100  write_std.size = 0;
2101  }
2102  }
2103  if (FD_ISSET (dev.fd_raw, &wfds))
2104  {
2105  ssize_t ret =
2106  write (dev.fd_raw, write_pout.buf + write_pout.pos,
2108  if (0 > ret)
2109  {
2110  fprintf (stderr, "Failed to write to WLAN device: %s\n",
2111  strerror (errno));
2112  break;
2113  }
2114  write_pout.pos += ret;
2115  if ((write_pout.pos != write_pout.size) && (0 != ret))
2116  {
2117  /* we should not get partial sends with packet-oriented devices... */
2118  fprintf (stderr, "Write error, partial send: %u/%u\n",
2119  (unsigned int) write_pout.pos,
2120  (unsigned int) write_pout.size);
2121  break;
2122  }
2123  if (write_pout.pos == write_pout.size)
2124  {
2125  write_pout.pos = 0;
2126  write_pout.size = 0;
2127  }
2128  }
2129 
2130  if (FD_ISSET (STDIN_FILENO, &rfds))
2131  {
2132  ssize_t ret =
2133  read (STDIN_FILENO, readbuf, sizeof(readbuf));
2134  if (0 > ret)
2135  {
2136  fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno));
2137  break;
2138  }
2139  if (0 == ret)
2140  {
2141  /* stop reading... */
2142  stdin_open = 0;
2143  }
2144  mst_receive (stdin_mst, readbuf, ret);
2145  }
2146 
2147  if (FD_ISSET (dev.fd_raw, &rfds))
2148  {
2150  ssize_t ret;
2151 
2152  rrm = (struct
2154  ret =
2155  linux_read (&dev, (unsigned char *) &rrm->frame,
2156  sizeof(write_std.buf)
2157  - sizeof(struct
2159  + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
2160  rrm);
2161  if (0 > ret)
2162  {
2163  fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno));
2164  break;
2165  }
2166  if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
2167  {
2168  write_std.size = ret
2169  + sizeof(struct
2171  - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
2172  rrm->header.size = htons (write_std.size);
2174  }
2175  }
2176  }
2177  /* Error handling, try to clean up a bit at least */
2178  mst_destroy (stdin_mst);
2179  (void) close (dev.fd_raw);
2180  return 1; /* we never exit 'normally' */
2181 }
#define GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL
Control message between the gnunet-wlan-helper and the daemon (with the MAC).
static struct MessageStreamTokenizer * mst_create(MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
struct GNUNET_MessageHeader hdr
Message header.
struct for storing the information of the hardware.
static void stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr)
Process data from the stdin.
struct GNUNET_MessageHeader header
Type is &#39;GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER&#39;.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_MessageStreamTokenizer * stdin_mst
Tokenizer for the data we get from stdin.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static struct SendBuffer write_std
Buffer for data read from the wireless card to be transmitted to stdout.
Format of a WLAN Control Message.
Message from the WLAN helper to the plugin: we have received the given message with the given perform...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
size_t size
How many bytes of data are stored in &#39;buf&#39; for transmission right now? Data always starts at offset 0...
static int mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, const struct HardwareInfos *dev)
Test incoming packets mac for being our own.
struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame
IEEE Frame.
static int open_device_raw(struct HardwareInfos *dev)
Open the wireless network interface for reading/writing.
static ssize_t linux_read(struct HardwareInfos *dev, unsigned char *buf, size_t buf_size, struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
Read from the raw socket (the wlan card), parse the packet and put the result into the buffer for tra...
static void mst_destroy(struct MessageStreamTokenizer *mst)
Destroys a tokenizer.
char buf[4096 *2]
Buffered data; twice the maximum allowed message size as we add some headers.
static int test_wlan_interface(const char *iface)
Test if the given interface name really corresponds to a wireless device.
Handle to a message stream tokenizer.
generic definitions for IEEE 802.11 frames
#define MAXLINE
Maximum size of a message allowed in either direction (used for our receive and sent buffers)...
static struct SendBuffer write_pout
Buffer for data read from stdin to be transmitted to the wirless card.
#define GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER
Type of data messages from the gnunet-wlan-helper to the plugin.
static int mst_receive(struct MessageStreamTokenizer *mst, const char *buf, size_t size)
Add incoming data to the receive buffer and call the callback for all complete messages.
size_t pos
How many bytes that were stored in &#39;buf&#39; did we already write to the destination? Always smaller than...
Here is the call graph for this function:

Variable Documentation

◆ did

uint32_t did

This has a different ID for each parameter, see PRISM_DID_* constants.

Definition at line 73 of file gnunet-helper-transport-wlan.c.

◆ status

uint16_t status

◆ len

uint16_t len

length of data (which is always a uint32_t, but presumably this can be used to specify that fewer bytes are used (with values in 'len' from 0-4).

We ignore this field.

Definition at line 85 of file gnunet-helper-transport-wlan.c.

Referenced by gnunet-chk.AESKey::__init__(), gnunet-chk.Chk::__init__(), address_notification(), aes_128_cbc_decrypt(), aes_128_cbc_encrypt(), gnunet-chk::aes_pad_(), check_crc_buf_osdep(), check_union_p2p_strata_estimator(), clear_from_s5r_rbuf(), client_receive(), client_send_cb(), gnunet-chk::compute_rootchk(), connect_probe_continuation(), create_keys(), create_string_array(), curl_upload_cb(), dht_get_string_handler(), dns_value_to_string(), do_accept(), do_dns_read(), do_write(), gnunet-chk::encode_data_to_string(), encrypt_existing_match(), exchange(), expand_dollar(), gnunet_pyexpect.pexpect::expect(), extract_fixed_blob(), extract_rsa_public_key(), extract_rsa_signature(), extract_string(), extract_varsize_blob(), find_typedefs::find_typedefs(), GCP_path_entry_add(), get_cb(), gnunet_janitor::get_process_list(), find_typedefs::get_td_from_function_signature(), find_typedefs::get_td_from_simple_type(), GNUNET_ABE_cpabe_serialize_key(), GNUNET_ABE_cpabe_serialize_master_key(), GNUNET_CONFIGURATION_expand_dollar(), GNUNET_CONFIGURATION_serialize(), GNUNET_CONTAINER_multihashmap32_create(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_CONTAINER_multishortmap_create(), GNUNET_CONTAINER_multiuuidmap_create(), GNUNET_CRYPTO_cpabe_serialize_key(), GNUNET_CRYPTO_cpabe_serialize_master_key(), GNUNET_CRYPTO_hkdf_v(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_create_for_file(), GNUNET_DISK_file_copy(), GNUNET_DISK_file_map(), GNUNET_DNSPARSER_builder_add_name(), GNUNET_FS_search_start_probe_(), GNUNET_NAT_register(), GNUNET_NETWORK_socket_close(), GNUNET_OS_init(), GNUNET_OS_start_process_s(), GNUNET_PQ_exec_prepared(), GNUNET_RECLAIM_ATTRIBUTE_list_serialize(), GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size(), GNUNET_REST_create_response(), GNUNET_STRINGS_base64_decode(), GNUNET_STRINGS_base64_encode(), GNUNET_STRINGS_conv(), GNUNET_STRINGS_data_to_string_alloc(), GNUNET_STRINGS_filename_expand(), GNUNET_STRINGS_parse_ipv4_policy(), GNUNET_STRINGS_parse_ipv6_policy(), GNUNET_STRINGS_parse_uri(), GNUNET_STRINGS_utf8_tolower(), GNUNET_STRINGS_utf8_toupper(), GST_stats_init(), handle_connection_broken(), handle_connection_create_ack(), handle_connection_destroy(), handle_data(), handle_tunnel_encrypted(), handle_tunnel_kx(), handle_tunnel_kx_auth(), handle_union_p2p_strata_estimator(), http_common_address_from_socket(), initialize_key_to_element(), libgnunet_plugin_transport_tcp_init(), libgnunet_plugin_transport_unix_done(), main(), modify_request(), needs_parens(), neighbours_connect_notification(), on_appsink_new_sample(), packetizer(), parse_fixed_data(), parse_name(), parse_rsa_public_key(), prepare_ipv4_packet(), prepare_ipv6_packet(), print_peer_list(), process_sblock(), put_cb(), read_cpabe(), read_from_the_socket(), regex_add(), REGEX_BLOCK_create(), REGEX_BLOCK_get_key(), REGEX_BLOCK_iterate(), regex_combine(), regex_edge_iterator(), REGEX_INTERNAL_search(), REGEX_TEST_generate_random_string(), REGEX_TEST_read_from_file(), reply_to_dns(), resolver_lookup_get_next_label(), run(), s2i_full(), find_typedefs::scan_dir(), select_write_cb(), send_icmp_packet_via_tun(), send_lookup_response(), send_tcp_packet_via_tun(), send_udp_packet_via_tun(), setup_data_transfer(), start_insert(), transmit_ready(), try_old_ax_keys(), try_top_down_reconstruction(), union_accept(), unix_real_send(), View_change_len(), View_create(), write_cpabe(), and write_pid_file().

◆ data

uint32_t data

The data value.

Definition at line 90 of file gnunet-helper-transport-wlan.c.

Referenced by abd_value_to_string(), add_to_meta_counter(), bind_abstime(), bind_nbotime(), bind_rsa_pub(), bind_rsa_sig(), bind_u16(), bind_u32(), bind_u64(), cadet_reply_proc(), check_pkey(), client_schedule(), configuration_receiver(), conversation_value_to_string(), copy_from_reader(), count_and_separate_strings(), data_to_ecdsa_value(), data_to_eddsa_value(), dht_get_id_handler(), dht_get_string_accept_handler(), dht_get_string_handler(), display_records_from_block(), dns_value_to_string(), do_read(), do_udp_read(), extract_result_cb(), filter_tickets_cb(), forward_resolution(), GDS_CLIENTS_handle_reply(), GDS_ROUTING_process(), gen_topo_from_file(), get_records_and_call_iterator(), gns_value_to_string(), GNUNET_ATS_TEST_logging_write_to_file(), GNUNET_CONTAINER_bloomfilter_or(), GNUNET_CRYPTO_crc8_n(), GNUNET_CRYPTO_ecdsa_sign(), GNUNET_CRYPTO_ecdsa_verify(), GNUNET_CRYPTO_eddsa_sign(), GNUNET_CRYPTO_eddsa_verify(), GNUNET_CRYPTO_rsa_blind(), GNUNET_CRYPTO_rsa_public_key_decode(), GNUNET_CRYPTO_rsa_signature_decode(), GNUNET_CRYPTO_rsa_verify(), GNUNET_DNSPARSER_bin_to_hex(), GNUNET_DNSPARSER_hex_to_bin(), GNUNET_FRIENDS_parse(), GNUNET_FS_data_reader_copy_(), GNUNET_GNSRECORD_records_deserialize(), GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_JSON_from_gnsrecord(), GNUNET_NAT_stun_handle_packet_(), GNUNET_RECLAIM_ATTRIBUTE_list_deserialize(), GNUNET_SECRETSHARING_share_read(), GNUNET_SQ_bind(), GNUNET_STRINGS_base64_encode(), GNUNET_STRINGS_data_to_string(), GNUNET_TESTBED_controller_link(), GNUNET_TESTBED_extract_config_(), GNUNET_TESTBED_forward_operation_msg_(), GNUNET_TESTBED_get_slave_config_(), GNUNET_TESTBED_hosts_load_from_file(), GNUNET_TESTBED_overlay_connect(), GNUNET_TESTBED_peer_create(), GNUNET_TESTBED_peer_get_information(), GNUNET_TESTBED_peer_manage_service(), GNUNET_TESTBED_peer_start(), GNUNET_TESTBED_peer_stop(), GNUNET_TESTBED_peer_update_configuration(), GNUNET_TESTBED_service_connect(), GNUNET_TESTBED_shutdown_peers(), handle_delegate_collection_cb(), handle_dht_p2p_result(), handle_dht_reply(), handle_dht_response(), handle_dht_result(), handle_gns_resolution_result(), handle_link_controllers_result(), handle_op_fail_event(), handle_opsuccess(), handle_peer_conevent(), handle_peer_config(), handle_peer_create_success(), handle_peer_event(), handle_results(), heap_plugin_put(), iter_finished(), load_search_strings(), lookup_authz_cb(), lookup_redirect_uri_result(), main(), make_file(), merge_with_nick_records(), message_sent_cont(), mpi_to_sexp(), namestore_postgres_store_records(), namestore_sqlite_store_records(), no_more_local_results(), normalize_metadata(), oprelease_link_controllers(), oprelease_manage_service(), oprelease_overlay_connect(), oprelease_peer_getinfo(), oprelease_peer_reconfigure(), oprelease_service_connect(), opstart_get_slave_config(), opstart_link_controllers(), opstart_manage_service(), opstart_overlay_connect(), opstart_peer_create(), opstart_peer_getinfo(), opstart_peer_reconfigure(), opstart_peer_start(), opstart_peer_stop(), opstart_service_connect(), parse_attr(), parse_gnsrecordobject(), parse_result_call_iterator(), parse_variable_data(), policy_filename_cb(), postgres_plugin_get_random(), process_client_result(), process_kblock_for_unindex(), process_local_reply(), process_lookup_result(), process_result(), process_tickets(), put_cb(), qconv_abs_time(), qconv_rsa_public_key(), qconv_rsa_signature(), qconv_uint16(), qconv_uint32(), qconv_uint64(), recursive_gns2dns_resolution(), reply_to_dns(), result_processor(), revoke_attrs_cb(), rsa_sign_mpi(), run(), run_zbar(), rvk_ticket_update(), sqlite_plugin_del(), stdin_receiver(), store_and_free_entries(), stream_read_callback(), ticket_iter(), try_reconnect(), try_send_tcp(), unindex_process(), update_tickets(), write_bw_gnuplot_script(), write_rtt_gnuplot_script(), and write_throughput_gnuplot_script().

◆ msgcode

uint32_t msgcode

We expect this to be a PRISM_MSGCODE_*.

Definition at line 72 of file gnunet-helper-transport-wlan.c.

◆ msglen

uint32_t msglen

The length of the entire header.

Definition at line 77 of file gnunet-helper-transport-wlan.c.

◆ devname

char devname[16]

Name of the device that captured the packet.

Definition at line 82 of file gnunet-helper-transport-wlan.c.

◆ __attribute__

struct PrismHeader __attribute__

◆ write_pout

struct SendBuffer write_pout
static

Buffer for data read from stdin to be transmitted to the wirless card.

Definition at line 760 of file gnunet-helper-transport-wlan.c.

Referenced by main(), and stdin_send_hw().

◆ write_std

struct SendBuffer write_std
static

Buffer for data read from the wireless card to be transmitted to stdout.

Definition at line 765 of file gnunet-helper-transport-wlan.c.

Referenced by main().