* Number of unicast retries a transmitted frame used.
*
*/
-enum ieee80211_radiotap_type
+enum RadiotapType
{
IEEE80211_RADIOTAP_TSFT = 0,
IEEE80211_RADIOTAP_FLAGS = 1,
/**
* FIXME.
*/
-struct sendbuf
+struct SendBuffer
{
unsigned int pos;
unsigned int size;
/**
* struct for storing the information of the hardware
*/
-struct Hardware_Infos
+struct HardwareInfos
{
/**
* send buffer
*/
- struct sendbuf write_pout;
+ struct SendBuffer write_pout;
/**
* file descriptor for the raw socket
*/
/**
* pointer to the radiotap header we are walking through
*/
- struct ieee80211_radiotap_header *rtheader;
+ const struct ieee80211_radiotap_header *rtheader;
/**
* length of radiotap header in cpu byte ordering
*/
- int max_length;
+ size_t max_length;
/**
* IEEE80211_RADIOTAP_... index of current arg
*/
- int this_arg_index;
+ unsigned int this_arg_index;
/**
* pointer to current radiotap arg
/**
* internal next argument index
*/
- int arg_index;
+ unsigned int arg_index;
/**
* internal next argument pointer
* @param message the actual message
*/
typedef void (*MessageTokenizerCallback) (void *cls,
- const struct
- GNUNET_MessageHeader *
- message);
+ const struct
+ GNUNET_MessageHeader *
+ message);
/**
* Handle to a message stream tokenizer.
*/
static struct MessageStreamTokenizer *
mst_create (MessageTokenizerCallback cb,
- void *cb_cls)
+ void *cb_cls)
{
struct MessageStreamTokenizer *ret;
*/
static int
mst_receive (struct MessageStreamTokenizer *mst,
- const char *buf, size_t size)
+ const char *buf, size_t size)
{
const struct GNUNET_MessageHeader *hdr;
size_t delta;
* 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.
+ *
+ * @param iterator iterator to initialize
+ * @param radiotap_header message to parse
+ * @param max_length number of valid bytes in radiotap_header
+ * @return 0 on success
*/
static int
ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator,
- struct ieee80211_radiotap_header
- *radiotap_header, int max_length)
+ const struct ieee80211_radiotap_header
+ *radiotap_header,
+ size_t max_length)
{
- if (iterator == NULL)
- return (-EINVAL);
+ if ( (iterator == NULL) ||
+ (radiotap_header == NULL) )
+ return -EINVAL;
- if (radiotap_header == NULL)
- return (-EINVAL);
/* Linux only supports version 0 radiotap format */
-
- if (radiotap_header->it_version)
- return (-EINVAL);
+ if (0 != radiotap_header->it_version)
+ return -EINVAL;
/* sanity check for allowed length and radiotap length field */
-
- if (max_length < (GNUNET_le16toh (radiotap_header->it_len)))
- return (-EINVAL);
+ if ( (max_length < sizeof (struct ieee80211_radiotap_header)) ||
+ (max_length < (GNUNET_le16toh (radiotap_header->it_len))) )
+ return -EINVAL;
iterator->rtheader = radiotap_header;
iterator->max_length = GNUNET_le16toh (radiotap_header->it_len);
iterator->this_arg = 0;
/* find payload start allowing for extended bitmap(s) */
-
if ((iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK))
{
while (GNUNET_le32toh (*((uint32_t *) iterator->arg)) &
* keep claiming to extend up to or even beyond the
* stated radiotap header length
*/
-
- if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) >
- iterator->max_length)
- return (-EINVAL);
-
+ if (iterator->arg - ((uint8_t*) iterator->rtheader) > iterator->max_length)
+ return -EINVAL;
}
-
iterator->arg += sizeof (uint32_t);
-
/*
* no need to check again for blowing past stated radiotap
* header length, becuase ieee80211_radiotap_iterator_next
* checks it before it is dereferenced
*/
-
}
-
/* we are all initialized happily */
return 0;
}
* least skip (by knowing the length)...
*/
- while (iterator->arg_index < (int) sizeof (rt_sizes))
+ while (iterator->arg_index < sizeof (rt_sizes))
{
int hit = 0;
if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) >
iterator->max_length)
- return (-EINVAL);
+ return -EINVAL;
next_entry:
/* if we found a valid arg earlier, return it now */
if (hit)
- return (iterator->this_arg_index);
+ return iterator->this_arg_index;
}
/* we don't know how to handle any more args, we're done */
-
- return (-1);
+ return -1;
}
static int
send_mac_to_plugin (char *buffer, struct MacAddress *mac)
{
-
struct Wlan_Helper_Control_Message macmsg;
memcpy (&macmsg.mac, (char *) mac, sizeof (struct MacAddress));
macmsg.hdr.size = htons (sizeof (struct Wlan_Helper_Control_Message));
macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
-
memcpy (buffer, &macmsg, sizeof (struct Wlan_Helper_Control_Message));
return sizeof (struct Wlan_Helper_Control_Message);
}
* @return number of the channel
*/
static int
-getChannelFromFrequency (int frequency)
+get_channel_from_frequency (int frequency)
{
if (frequency >= 2412 && frequency <= 2472)
return (frequency - 2407) / 5;
- else if (frequency == 2484)
+ if (frequency == 2484)
return 14;
- else if (frequency >= 5000 && frequency <= 6100)
+ if (frequency >= 5000 && frequency <= 6100)
return (frequency - 5000) / 5;
- else
- return -1;
+ return -1;
}
for (; len > 0; len--, buf++)
crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8);
-
return (~crc);
}
* @return channel number
*/
static int
-linux_get_channel (const struct Hardware_Infos *dev)
+linux_get_channel (const struct HardwareInfos *dev)
{
struct iwreq wrq;
int fd;
int chan;
memset (&wrq, 0, sizeof (struct iwreq));
-
strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
-
fd = dev->fd_raw;
if (0 > ioctl (fd, SIOCGIWFREQ, &wrq))
return (-1);
frequency /= 100000;
else if (1000000 < frequency)
frequency /= 1000;
-
if (1000 < frequency)
- chan = getChannelFromFrequency (frequency);
+ chan = get_channel_from_frequency (frequency);
else
chan = frequency;
-
return chan;
}
* @return size read from the buffer
*/
static ssize_t
-linux_read (struct Hardware_Infos *dev, unsigned char *buf, size_t buf_size,
+linux_read (struct HardwareInfos *dev, unsigned char *buf, size_t buf_size,
struct Radiotap_rx *ri)
{
unsigned char tmpbuf[buf_size];
* @return 0 on success
*/
static int
-openraw (struct Hardware_Infos *dev)
+open_device_raw (struct HardwareInfos *dev)
{
struct ifreq ifr;
struct iwreq wrq;
* @return 0 on success
*/
static int
-wlaninit (struct Hardware_Infos *dev, const char *iface)
+wlan_initialize (struct HardwareInfos *dev, const char *iface)
{
char strbuf[512];
struct stat sbuf;
return 1;
}
strncpy (dev->iface, iface, IFNAMSIZ);
- if (0 != openraw (dev))
+ if (0 != open_device_raw (dev))
{
close (dev->fd_raw);
return 1;
*/
static int
mac_test (const struct ieee80211_frame *uint8_taIeeeHeader,
- const struct Hardware_Infos *dev)
+ const struct HardwareInfos *dev)
{
if (0 != memcmp (uint8_taIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE))
return 1;
*/
static void
mac_set (struct ieee80211_frame *uint8_taIeeeHeader,
- const struct Hardware_Infos *dev)
+ const struct HardwareInfos *dev)
{
uint8_taIeeeHeader->i_fc[0] = 0x08;
uint8_taIeeeHeader->i_fc[1] = 0x00;
static void
stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
{
- struct Hardware_Infos *dev = cls;
- struct sendbuf *write_pout = &dev->write_pout;
+ struct HardwareInfos *dev = cls;
+ struct SendBuffer *write_pout = &dev->write_pout;
struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1];
struct ieee80211_frame *wlanheader;
size_t sendsize;
struct RadioTapheader rtheader;
- rtheader.header.it_version = 0;
- rtheader.header.it_len = GNUNET_htole16 (0x0c);
- rtheader.header.it_present = GNUNET_le16toh (0x00008004);
+ rtheader.header.it_version = 0; /* radiotap version */
+ rtheader.header.it_len = GNUNET_htole16 (0x0c); /* radiotap header length */
+ rtheader.header.it_present = GNUNET_le16toh (0x00008004); /* our bitmap */
rtheader.rate = 0x00;
rtheader.pad1 = 0x00;
rtheader.txflags =
GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
- /* { 0x00, 0x00, <-- radiotap version
- * 0x0c, 0x00, <- radiotap header length
- * 0x04, 0x80, 0x00, 0x00, <-- bitmap
- * 0x00, <-- rate
- * 0x00, <-- padding for natural alignment
- * 0x18, 0x00, <-- TX flags
- * }; */
-
sendsize = ntohs (hdr->size);
if (sendsize <
sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader))
}
if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type))
{
- fprintf (stderr, "Function stdin_send: wrong packet type\n");
+ fprintf (stderr, "Function stdin_send_hw: wrong packet type\n");
exit (1);
}
main (int argc, char *argv[])
{
uid_t uid;
- struct Hardware_Infos dev;
+ struct HardwareInfos dev;
char readbuf[MAXLINE];
- struct sendbuf write_std;
+ struct SendBuffer write_std;
ssize_t ret;
int maxfd;
fd_set rfds;
"You must specify the name of the interface as the first and only argument to this program.\n");
return 1;
}
- if (0 != wlaninit (&dev, argv[1]))
+ if (0 != wlan_initialize (&dev, argv[1]))
return 1;
uid = getuid ();
if (0 != setresuid (uid, uid, uid))
* @brief header for transport plugin and the helper for wlan
* @author David Brodski
*/
-
#ifndef PLUGIN_TRANSPORT_WLAN
#define PLUGIN_TRANSPORT_WLAN
*/
#define MAC_ADDR_SIZE 6
+/**
+ * A MAC Address.
+ */
struct MacAddress
{
uint8_t mac[MAC_ADDR_SIZE];
};
-struct Wlan_Helper_Control_Message
-{
- struct GNUNET_MessageHeader hdr;
- struct MacAddress mac;
-};
-
/**
- * Header for messages which need fragmentation
+ * Format of a WLAN Control Message.
*/
-struct WlanHeader
+struct Wlan_Helper_Control_Message
{
-
- struct GNUNET_MessageHeader header;
-
- /**
- * checksum/error correction
- */
- uint32_t crc GNUNET_PACKED;
-
/**
- * To whom are we talking to (set to our identity
- * if we are still waiting for the welcome message)
+ * Message header. FIXME: type?
*/
- struct GNUNET_PeerIdentity target;
+ struct GNUNET_MessageHeader hdr;
/**
- * Where the packet came from
+ * MAC Address. FIXME: of what?
*/
- struct GNUNET_PeerIdentity source;
-
-// followed by payload
-
+ struct MacAddress mac;
};
-/* Wlan IEEE80211 header default */
-//Informations (in German) http://www.umtslink.at/content/WLAN_macheader-196.html
-static const uint8_t u8aIeeeHeader[] = { 0x08, 0x01, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0;
- // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
- // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
- 0x00, 0x00, // Duration/ID
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver
- 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender
- 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
- 0x10, 0x86, //Sequence Control
-};
-// gnunet bssid
+/**
+ * GNUnet bssid
+ */
static const struct MacAddress mac_bssid = {
{0x13, 0x22, 0x33, 0x44, 0x55, 0x66}
};
-// broadcast mac
+
+/**
+ * Broadcast MAC
+ */
static const struct MacAddress bc_all_mac = {
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
};
-/* this is the template radiotap header we send packets out with */
-
-static const uint8_t u8aRadiotapHeader[] = { 0x00, 0x00, // <-- radiotap version
- 0x19, 0x00, // <- radiotap header length
- 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
- 0x00, // <-- flags (Offset +0x10)
- 0x6c, // <-- rate (0ffset +0x11)
- 0x71, 0x09, 0xc0, 0x00, // <-- channel
- 0xde, // <-- antsignal
- 0x00, // <-- antnoise
- 0x01, // <-- antenna
-};
struct Radiotap_Send
{
uint8_t rate;
/**
- * antenna
+ * Antenna; the first antenna is 0.
*/
uint8_t antenna;
* Transmit power expressed as unitless distance from max power set at factory calibration.
* 0 is max power. Monotonically nondecreasing with lower power levels.
*/
-
uint16_t tx_power;
};
-// bit field defines for ri_present
-
-#define has_noise 1
-#define has_power 2
-#define has_channel 4
/**
* struct to represent infos gathered form the radiotap fields, see RadiotapHeader for more Infos
*/
-
struct Radiotap_rx
{
+ /**
+ * FIXME: not initialized properly so far. (supposed to contain
+ * information about which of the fields below are actually valid).
+ */
uint32_t ri_present;
+
/**
* IEEE80211_RADIOTAP_TSFT
*/
uint64_t ri_mactime;
+
/**
* from radiotap
* either IEEE80211_RADIOTAP_DBM_ANTSIGNAL
* or IEEE80211_RADIOTAP_DB_ANTSIGNAL
*/
int32_t ri_power;
+
/**
* either IEEE80211_RADIOTAP_DBM_ANTNOISE
* or IEEE80211_RADIOTAP_DB_ANTNOISE
*/
int32_t ri_noise;
+
/**
* IEEE80211_RADIOTAP_CHANNEL
*/
uint32_t ri_channel;
+ /**
+ * Frequency we use. FIXME: not properly initialized so far!
+ */
uint32_t ri_freq;
+
/**
* IEEE80211_RADIOTAP_RATE * 50000
*/
uint32_t ri_rate;
+
/**
* IEEE80211_RADIOTAP_ANTENNA
*/
uint32_t ri_antenna;
};
-/**
- * Radiotap Header
- */
-struct RadiotapHeader
-{
- /**
- * radiotap version
- */
- u_int8_t version;
-
- u_int8_t pad_version;
-
- /**
- * radiotap header length
- */
- uint16_t length GNUNET_PACKED;
-
- /**
- * bitmap, fields present
- */
- uint32_t bitmap GNUNET_PACKED;
-
- /**
- * timestamp
- */
- uint64_t timestamp GNUNET_PACKED;
-
- /**
- * radiotap flags
- */
- uint8_t flags;
- /**
- * wlan send rate
- */
- uint8_t rate;
-
- // FIXME: unaligned here, is this OK?
- /**
- * Wlan channel
- */
- uint32_t channel GNUNET_PACKED;
-
- /**
- * antsignal
- */
- uint8_t antsignal;
-
- /**
- * antnoise
- */
- uint8_t antnoise;
-
- /**
- * antenna
- */
- uint8_t antenna;
-};
#endif