Skip to contentSkip to conversation

Radiotap injection for Monitor Mode

PATCH In review [email protected] 2 participants 7 messages Jun 11, 2007 – Jun 12, 2007

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Radiotap injection for Monitor Mode

These patches add the ability to inject packets down a monitor mode interface for transmission according to a prepended radiotap header.

For injecting packets, the you issue a packet using libpcap or a SOCK_PACKET socket down an interface to the wireless device that is in Monitor Mode. The packet has a normal radiotap header prepended to the IEEE80211 header. The radiotap header is variable length depending on what the user wants to specify, currently the transmit rate, power and antenna can be specified using normal radiotap semantics. Any other entries are skipped.

The radiotap parser is broken out into its own file under cfg80211.

A usermode app packetspammer is available from here

http://penumbra.warmcat.com/_twk/tiki-index.php?page=packetspammer

which allows easy injection of these packets from the commandline. At the moment it loops issuing packets at a variety of rates which can be seen from another machine's monitor mode interface on the same channel. There are instructions for build and using it on the page above.

Currently it has been tested for both rx and tx using zd1211rw-mac80211.

The patches are based against current wireless-dev.

I also added some documentation files which explains how to use the injection functionality and radiotap header notes.

#1 lore raw

PATCH 1/4 mac80211: Monitor mode radiotap injection docs

From: Andy Green <[email protected]>

---
 Documentation/networking/mac80211-injection.txt |   59 +++++++++++++++++
 Documentation/networking/radiotap-headers.txt   |   79 ++++++++++++++++++++++++
 2 files changed, 138 insertions(+)
Documentation/networking/mac80211-injection.txt new file +59 -0
Index: wireless-dev/Documentation/networking/mac80211-injection.txt
===================================================================
@@ -0,0 +1,59 @@
+How to use packet injection with mac80211
+=========================================
+
+mac80211 now allows arbitrary packets to be injected down any Monitor Mode
+interface from userland.  The packet you inject needs to be composed in the
+following format:
+
+ [ radiotap header  ]
+ [ ieee80211 header ]
+ [ payload ]
+
+The radiotap format is discussed in
+./Documentation/networking/radiotap-headers.txt.
+
+Despite 13 radiotap argument types are currently defined, most only make sense
+to appear on received packets.  Currently three kinds of argument are used by
+the injection code, although it knows to skip any other arguments that are
+present (facilitating replay of captured radiotap headers directly):
+
+ - IEEE80211_RADIOTAP_RATE - u8 arg in 500kbps units (0x02 --> 1Mbps)
+
+ - IEEE80211_RADIOTAP_ANTENNA - u8 arg, 0x00 = ant1, 0x01 = ant2
+
+ - IEEE80211_RADIOTAP_DBM_TX_POWER - u8 arg, dBm
+
+Here is an example valid radiotap header defining these three parameters
+
+	0x00, 0x00, // <-- radiotap version
+	0x0b, 0x00, // <- radiotap header length
+	0x04, 0x0c, 0x00, 0x00, // <-- bitmap
+	0x6c, // <-- rate
+	0x0c, //<-- tx power
+	0x01 //<-- antenna
+
+The ieee80211 header follows immediately afterwards, looking for example like
+this:
+
+	0x08, 0x01, 0x00, 0x00,
+	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+	0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
+	0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
+	0x10, 0x86
+
+Then lastly there is the payload.
+
+After composing the packet contents, it is sent by send()-ing it to a logical
+mac80211 interface that is in Monitor mode.  Libpcap can also be used,
+(which is easier than doing the work to bind the socket to the right
+interface), along the following lines:
+
+	ppcap = pcap_open_live(szInterfaceName, 800, 1, 20, szErrbuf);
+...
+	r = pcap_inject(ppcap, u8aSendBuffer, nLength);
+
+You can also find sources for a complete inject test applet here:
+
+http://penumbra.warmcat.com/_twk/tiki-index.php?page=packetspammer
+
+Andy Green <[email protected]>
Documentation/networking/radiotap-headers.txt new file +79 -0

79 lines not on this page · raw message

#2 lore raw

PATCH 2/4 mac80211: Define present bitmap extend bit mask

In reply to [email protected]

Used to detect if the field presence mask is extended

---
 include/net/ieee80211_radiotap.h |    2 ++
 1 file changed, 2 insertions(+)
include/net/ieee80211_radiotap.h +2 -0
Index: wireless-dev/include/net/ieee80211_radiotap.h
===================================================================
@@ -90,6 +90,8 @@ struct ieee80211_radiotap_header {
 				 */
 };
 
+#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000
+
 /* Name                                 Data type    Units
  * ----                                 ---------    -----
  *
#3 lore raw

PATCH 3/4 cfg80211: Radiotap parser

In reply to [email protected]

Generic code to walk through the fields in a radiotap header, accounting for nasties like extended "field present" bitfields and alignment rules

Try #9 (of the radiotap patchset) thanks to Johannes Berg's feedback
- Add docs to nano kernel docs
- Add docs to Documentation/networking/radiotap-headers.txt
- Fix typos

Try #2
- added sanity check to extended present bitmap u32 walking code - disallow possibility to walk past the end of the radiotap header length

Try #1
- Based on Johannes Berg's comments, broke out the radiotap parsing into its own file as part of cfg80211
- From same comments, added mask constant for b31 of arg presence bitfield to ieee80211_radiotap.h
- Fixed subtle but nasty bug with alignment: args in the radiotap area are aligned *relative to the start of the header* now. The header is not guaranteed to align to anything (it is randomly in an skb data area).

===================================================

---
 Documentation/networking/radiotap-headers.txt |   56 +++++
 include/net/cfg80211.h                        |   39 +++
 net/wireless/Makefile                         |    2 
 net/wireless/radiotap.c                       |  256 ++++++++++++++++++++++++++
 4 files changed, 352 insertions(+), 1 deletion(-)
include/net/cfg80211.h +39 -0
Index: wireless-dev/include/net/cfg80211.h
===================================================================
@@ -74,6 +74,45 @@ struct key_params {
 	u32 cipher;
 };
 
+
+/* Radiotap header iteration
+ *   implemented in net/wireless/radiotap.c
+ *   docs in Documentation/networking/radiotap-headers.txt
+ */
+/**
+ * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
+ * @rtheader: pointer to the radiotap header we are walking through
+ * @max_length: length of radiotap header in cpu byte ordering
+ * @this_arg_index: IEEE80211_RADIOTAP_... index of current arg
+ * @this_arg: pointer to current radiotap arg
+ * @arg_index: internal next argument index
+ * @arg: internal next argument pointer
+ * @next_bitmap: internal pointer to next present u32
+ * @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
+ */
+
+struct ieee80211_radiotap_iterator {
+	struct ieee80211_radiotap_header *rtheader;
+	int max_length;
+	int this_arg_index;
+	u8 * this_arg;
+
+	int arg_index;
+	u8 * arg;
+	__le32 *next_bitmap;
+	u32 bitmap_shifter;
+};
+
+extern int ieee80211_radiotap_iterator_init(
+   struct ieee80211_radiotap_iterator * iterator,
+   struct ieee80211_radiotap_header * radiotap_header,
+   int max_length
+);
+
+extern int ieee80211_radiotap_iterator_next(
+   struct ieee80211_radiotap_iterator * iterator);
+
+
 /* from net/wireless.h */
 struct wiphy;
 
net/wireless/Makefile +1 -1
Index: wireless-dev/net/wireless/Makefile
===================================================================
@@ -1,5 +1,5 @@
 obj-$(CONFIG_WIRELESS_EXT) += wext.o
 obj-$(CONFIG_CFG80211) += cfg80211.o
 
-cfg80211-y += core.o sysfs.o
+cfg80211-y += core.o sysfs.o radiotap.o
 cfg80211-$(CONFIG_NL80211) += nl80211.o
net/wireless/radiotap.c new file +256 -0

256 lines not on this page · raw message

Documentation/networking/radiotap-headers.txt +56 -0

60 lines not on this page · raw message

#4 lore raw

Re: [PATCH Try#9 3/4] cfg80211: Radiotap parser

include/net/cfg80211.h struct key_params { · line 98

Quoted 5 lines · On Monday 11 June 2007 08:21, [email protected] wrote:
include/net/cfg80211.h +5 -0
+struct ieee80211_radiotap_iterator {
+	struct ieee80211_radiotap_header *rtheader;
+	int max_length;
+	int this_arg_index;
+	u8 * this_arg;
            ^

Eliminate the space here between * and this_arg.

include/net/cfg80211.h struct key_params { · line 101

Quoted 3 lines
include/net/cfg80211.h +3 -0
+
+	int arg_index;
+	u8 * arg;

And here. ^

include/net/cfg80211.h struct key_params { · line 107

Quoted 6 lines
include/net/cfg80211.h +6 -0
+	__le32 *next_bitmap;
+	u32 bitmap_shifter;
+};
+
+extern int ieee80211_radiotap_iterator_init(
+   struct ieee80211_radiotap_iterator * iterator,

Here. ^

Quoted 1 line

+ struct ieee80211_radiotap_header * radiotap_header,

You get the idea. ^

net/wireless/radiotap.c line 7

Quoted 12 lines

Index: wireless-dev/net/wireless/radiotap.c
===================================================================

net/wireless/radiotap.c new file +7 -0
@@ -0,0 +1,256 @@
+/*
+ * Radiotap parser
+ *
+ * Copyright 2007		Andy Green <[email protected]>
+ */
+
+#include <linux/if.h>

Don't think anything from here is used.

net/wireless/radiotap.c line 9

Quoted 2 lines
net/wireless/radiotap.c new file +2 -0
+#include <linux/err.h>
+#include <linux/mutex.h>

We don't touch any mutexes in this file..

net/wireless/radiotap.c line 10

Quoted 1 line
net/wireless/radiotap.c new file +1 -0
+#include <linux/device.h>

Nor do we care about devices.

net/wireless/radiotap.c line 11

Quoted 1 line
net/wireless/radiotap.c new file +1 -0
+#include <net/genetlink.h>

Or netlink.

net/wireless/radiotap.c line 13

Quoted 2 lines
net/wireless/radiotap.c new file +2 -0
+#include <net/cfg80211.h>
+#include <net/wireless.h>

Or wiphys.

net/wireless/radiotap.c line 15

Quoted 2 lines
net/wireless/radiotap.c new file +2 -0
+#include "nl80211.h"
+#include "core.h"

nl80211.h and core.h seem unnecessary too.

All these includes might be pulling some other header that you do need, however. (linux/kernel.h probably covers it..)

net/wireless/radiotap.c line 58

Quoted 7 lines
net/wireless/radiotap.c new file +7 -0
+int ieee80211_radiotap_iterator_init(
+    struct ieee80211_radiotap_iterator * iterator,
+    struct ieee80211_radiotap_header * radiotap_header,
+    int max_length)
+{
+	/* Linux only supports version 0 radiotap format */
+

I think the code would look better without a blank line following the comment.

net/wireless/radiotap.c line 64

Quoted 6 lines
net/wireless/radiotap.c new file +6 -0
+	if (radiotap_header->it_version)
+		return -EINVAL;
+
+	/* sanity check for allowed length and radiotap length field */
+
+	if (max_length < (le16_to_cpu(radiotap_header->it_len)))

Unnecessary parenthesis. ^ ^

net/wireless/radiotap.c line 71

Quoted 7 lines
net/wireless/radiotap.c new file +7 -0
+		return -EINVAL;
+
+	iterator->rtheader = radiotap_header;
+	iterator->max_length = le16_to_cpu(radiotap_header->it_len);
+	iterator->arg_index = 0;
+	iterator->bitmap_shifter = le32_to_cpu(radiotap_header->it_present);
+	iterator->arg = ((u8 *)radiotap_header) +

Ditto. ^ ^

net/wireless/radiotap.c line 72

Quoted 1 line
net/wireless/radiotap.c new file +1 -0
+			sizeof(struct ieee80211_radiotap_header);

I usually like to use sizeof on a variable (eg., sizeof(*radiotap_header)) since it's shorter and doesn't need to be changed if the variable type changes.

net/wireless/radiotap.c line 78

Quoted 6 lines
net/wireless/radiotap.c new file +6 -0
+	iterator->this_arg = 0;
+
+	/* find payload start allowing for extended bitmap(s) */
+
+	if (unlikely(iterator->bitmap_shifter &
+	    IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) {
            +--------^

Indenting this a bit more to the right should look better.

net/wireless/radiotap.c line 80

Quoted 2 lines
net/wireless/radiotap.c new file +2 -0
+		while (le32_to_cpu(*((u32 *)iterator->arg)) &
+		    IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) {
                    +--------------^

Ditto.

net/wireless/radiotap.c line 90

Quoted 10 lines
net/wireless/radiotap.c new file +10 -0
+			iterator->arg += sizeof(u32);
+
+			/*
+			 * check for insanity where the present bitmaps
+			 * keep claiming to extend up to or even beyond the
+			 * stated radiotap header length
+			 */
+
+			if ((((int)iterator->arg) - ((int)iterator->rtheader)) >
+			    iterator->max_length)

For pointer arithmetic, you should use unsigned long. The parenthesis are a little too paranoid here too.

net/wireless/radiotap.c line 193

Quoted 1 line
net/wireless/radiotap.c new file +1 -0
+		if ((((int)iterator->arg)-((int)iterator->rtheader)) &

unsigned long for pointer arithmetic and reduce parenthesis, as before. Seems to be a lot of this, so I won't mention it again.

Quoted 23 lines
net/wireless/radiotap.c new file +23 -0
+		    ((rt_sizes[iterator->arg_index] >> 4) - 1))
+			iterator->arg_index +=
+				(rt_sizes[iterator->arg_index] >> 4) -
+				((((int)iterator->arg) -
+				 ((int)iterator->rtheader)) &
+				 ((rt_sizes[iterator->arg_index] >> 4) - 1));
+
+		/*
+		 * this is what we will return to user, but we need to
+		 * move on first so next call has something fresh to test
+		 */
+
+		iterator->this_arg_index = iterator->arg_index;
+		iterator->this_arg = iterator->arg;
+		hit = 1;
+
+		/* internally move on the size of this arg */
+
+		iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
+
+		/*
+		 * check for insanity where we are given a bitmap that
+		 * claims to have more arg content than the length of the

net/wireless/radiotap.c line 226

Quoted 10 lines
net/wireless/radiotap.c new file +10 -0
+		 * radiotap section.  We will normally end up equalling this
+		 * max_length on the last arg, never exceeding it.
+		 */
+
+		if ((((int)iterator->arg) - ((int)iterator->rtheader)) >
+		    iterator->max_length)
+			return -EINVAL;
+
+	next_entry:
+

A blank line after a label doesn't look right to me..

net/wireless/radiotap.c line 234

Quoted 8 lines
net/wireless/radiotap.c new file +8 -0
+		iterator->arg_index++;
+		if (unlikely((iterator->arg_index & 31) == 0)) {
+			/* completed current u32 bitmap */
+			if (iterator->bitmap_shifter & 1) {
+				/* b31 was set, there is more */
+				/* move to next u32 bitmap */
+				iterator->bitmap_shifter = le32_to_cpu(
+					*iterator->next_bitmap);

Move "le32_to_cpu(" down to the next line.

Quoted 4 lines
net/wireless/radiotap.c new file +4 -0
+				iterator->next_bitmap++;
+			} else {
+				/* no more bitmaps: end */
+				iterator->arg_index = sizeof(rt_sizes);

net/wireless/radiotap.c line 248

Quoted 10 lines
net/wireless/radiotap.c new file +10 -0
+			}
+		} else { /* just try the next bit */
+			iterator->bitmap_shifter >>= 1;
+		}
+
+		/* if we found a valid arg earlier, return it now */
+
+		if (hit)
+			return iterator->this_arg_index;
+

Another unnecessary blank line. ;)

Thanks,
-Michael Wu

#5 lore raw

PATCH 4/4 mac80211: Monitor mode radiotap-based packet injection

In reply to [email protected]

From: Andy Green <[email protected]>

Try #9
- Normalize multiline comment style

Try #6
- Accounted for various comments from Johannes Berg
- Radiotap parsing is moved to cfg80211 as requested in a separate patch

Try #5
- De-indent last few indented comments

Try #4
- All from Michael Wu's feedback: further style heresies removed
- took account of radiotap arg alignment requirement. n-byte arg must be placed on n-byte boundary using padding where necessary

Try #3
- moved to Michael Wu's method of tracking if we came in on a monitor interface by using ifindex
- removed older proposed monitor interface tracking method and flags
- style fixes
- removed duped #include that is present in Michael Wu's patch already

Try #2
- took Michael Wu's advice about better tools and basing on wireless-dev
- took Luis Rodriguez's advice about coding style makeover
- took Pavel Roskin's advice about little-endian radiotap

---
 net/mac80211/ieee80211.c |  212 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 202 insertions(+), 10 deletions(-)
net/mac80211/ieee80211.c +202 -10
Index: wireless-dev/net/mac80211/ieee80211.c
===================================================================
@@ -1118,7 +1118,113 @@ ieee80211_tx_h_ps_buf(struct ieee80211_t
 }
 
 
-static void inline
+/*
+ * deal with packet injection down monitor interface
+ * with Radiotap Header -- only called for monitor mode interface
+ */
+
+static ieee80211_txrx_result
+__ieee80211_convert_radiotap_to_control_and_remove(
+	struct ieee80211_txrx_data *tx,
+	struct sk_buff *skb, struct ieee80211_tx_control *control)
+{
+	/*
+	 * this is the moment to interpret and discard the radiotap header that
+	 * must be at the start of the packet injected in Monitor mode
+	 *
+	 * Need to take some care with endian-ness since radiotap
+	 * args are little-endian
+	 */
+
+	struct ieee80211_radiotap_iterator iterator;
+	struct ieee80211_radiotap_header *rthdr =
+		(struct ieee80211_radiotap_header *) skb->data;
+	struct ieee80211_hw_mode *hw_mode=tx->local->hw.conf.mode;
+
+	/* this can fail some sanity checks, drop packet if it does so */
+
+	if (ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len) < 0)
+		return TXRX_DROP;
+
+	/*
+	 * default control situation for all injected packets
+	 * FIXME: this does not suit all usage cases, expand to allow control
+	 */
+
+	control->retry_limit = 1; /* no retry */
+	control->key_idx = -1; /* no encryption key */
+	control->flags &= ~(IEEE80211_TXCTL_USE_RTS_CTS |
+			    IEEE80211_TXCTL_USE_CTS_PROTECT);
+	control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT |
+			  IEEE80211_TXCTL_NO_ACK;
+	control->antenna_sel_tx = 0; /* default to default antenna */
+
+	/*
+	 * for every radiotap entry that is present (returns -ve on end or
+	 * on error)
+	 */
+
+	while (ieee80211_radiotap_iterator_next(&iterator) >= 0) {
+		int i, target_rate;
+
+		/* see if this argument is something we can use */
+
+		switch (iterator.this_arg_index) {
+
+		case IEEE80211_RADIOTAP_RATE:
+			/*
+			 * radiotap rate u8 is in 500kbps units eg, 0x02=1Mbps
+			 * ieee80211 rate int is in 100kbps units eg, 0x0a=1Mbps
+			 */
+			target_rate = (*iterator.this_arg) * 5;
+			for (i = 0; i < hw_mode->num_rates; i++) {
+				struct ieee80211_rate *r = &hw_mode->rates[i];
+
+				if (r->rate > target_rate)
+					continue;
+
+				control->rate = r;
+
+				if (r->flags & IEEE80211_RATE_PREAMBLE2)
+					control->tx_rate = r->val2;
+				else
+					control->tx_rate = r->val;
+
+				/* end on exact match */
+				if (r->rate == target_rate)
+					i = hw_mode->num_rates;
+
+			}
+			break;
+
+		case IEEE80211_RADIOTAP_ANTENNA:
+			/*
+			 * radiotap uses 0 for 1st ant, mac80211 is 1 for
+			 * 1st ant
+			 */
+			control->antenna_sel_tx = (*iterator.this_arg) + 1;
+			break;
+
+		case IEEE80211_RADIOTAP_DBM_TX_POWER:
+			control->power_level = *iterator.this_arg;
+			break;
+
+		default:
+			break;
+		}
+	}
+
+	/*
+	 * remove the radiotap header
+	 * rthdr->it_len was sanity-checked against skb->len by iterator init
+	 */
+	skb_pull(skb, le16_to_cpu(rthdr->it_len));
+
+	return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result inline
 __ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
 		       struct sk_buff *skb,
 		       struct net_device *dev,
@@ -1126,6 +1232,9 @@ __ieee80211_tx_prepare(struct ieee80211_
 {
 	struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+	struct ieee80211_sub_if_data *sdata;
+	ieee80211_txrx_result res = TXRX_CONTINUE;
+
 	int hdrlen;
 
 	memset(tx, 0, sizeof(*tx));
@@ -1135,7 +1244,33 @@ __ieee80211_tx_prepare(struct ieee80211_
 	tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev);
 	tx->sta = sta_info_get(local, hdr->addr1);
 	tx->fc = le16_to_cpu(hdr->frame_control);
+
+	/* set defaults for things that can be set by
+	 * injected radiotap headers
+	 */
+
 	control->power_level = local->hw.conf.power_level;
+	control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
+	if (local->sta_antenna_sel != STA_ANTENNA_SEL_AUTO && tx->sta)
+		control->antenna_sel_tx = tx->sta->antenna_sel_tx;
+
+	/* process and remove the injection radiotap header */
+
+	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	if (unlikely(sdata->type == IEEE80211_IF_TYPE_MNTR)) {
+		if (__ieee80211_convert_radiotap_to_control_and_remove(
+		    tx, skb, control) == TXRX_DROP) {
+			return TXRX_DROP;
+		}
+		/*
+		 * we removed the radiotap header after this point,
+		 * we filled control with what we could use
+		 * set to the actual ieee header now
+		 */
+		hdr = (struct ieee80211_hdr *) skb->data;
+		res = TXRX_QUEUED; /* indication it was monitor packet */
+	}
+
 	tx->u.tx.control = control;
 	tx->u.tx.unicast = !is_multicast_ether_addr(hdr->addr1);
 	if (is_multicast_ether_addr(hdr->addr1))
@@ -1152,9 +1287,6 @@ __ieee80211_tx_prepare(struct ieee80211_
 		control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK;
 		tx->sta->clear_dst_mask = 0;
 	}
-	control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
-	if (local->sta_antenna_sel != STA_ANTENNA_SEL_AUTO && tx->sta)
-		control->antenna_sel_tx = tx->sta->antenna_sel_tx;
 	hdrlen = ieee80211_get_hdrlen(tx->fc);
 	if (skb->len > hdrlen + sizeof(rfc1042_header) + 2) {
 		u8 *pos = &skb->data[hdrlen + sizeof(rfc1042_header)];
@@ -1162,6 +1294,7 @@ __ieee80211_tx_prepare(struct ieee80211_
 	}
 	control->flags |= IEEE80211_TXCTL_FIRST_FRAGMENT;
 
+	return res;
 }
 
 static int inline is_ieee80211_device(struct net_device *dev,
@@ -1274,7 +1407,7 @@ static int ieee80211_tx(struct net_devic
 	struct sta_info *sta;
 	ieee80211_tx_handler *handler;
 	struct ieee80211_txrx_data tx;
-	ieee80211_txrx_result res = TXRX_DROP;
+	ieee80211_txrx_result res = TXRX_DROP, res_prepare;
 	int ret, i;
 
 	WARN_ON(__ieee80211_queue_pending(local, control->queue));
@@ -1284,15 +1417,26 @@ static int ieee80211_tx(struct net_devic
 		return 0;
 	}
 
-	__ieee80211_tx_prepare(&tx, skb, dev, control);
+	res_prepare = __ieee80211_tx_prepare(&tx, skb, dev, control);
+
+	if (res_prepare == TXRX_DROP) {
+		dev_kfree_skb(skb);
+		return 0;
+	}
+
 	sta = tx.sta;
 	tx.u.tx.mgmt_interface = mgmt;
 	tx.u.tx.mode = local->hw.conf.mode;
 
-	for (handler = local->tx_handlers; *handler != NULL; handler++) {
-		res = (*handler)(&tx);
-		if (res != TXRX_CONTINUE)
-			break;
+	if (res_prepare == TXRX_QUEUED) { /* if it was an injected packet */
+		res = TXRX_CONTINUE;
+	} else {
+		for (handler = local->tx_handlers; *handler != NULL;
+		     handler++) {
+			res = (*handler)(&tx);
+			if (res != TXRX_CONTINUE)
+				break;
+		}
 	}
 
 	skb = tx.skb; /* handlers are allowed to change skb */
@@ -1531,6 +1675,54 @@ static int ieee80211_subif_start_xmit(st
 		goto fail;
 	}
 
+	if (unlikely(sdata->type == IEEE80211_IF_TYPE_MNTR)) {
+		struct ieee80211_radiotap_header * prthdr =
+			(struct ieee80211_radiotap_header *)skb->data;
+
+		/*
+		 * there must be a radiotap header at the
+		 * start in this case
+		 */
+
+		if (unlikely(prthdr->it_version)) {
+			/* only version 0 is supported  */
+			ret = 0;
+			goto fail;
+		}
+
+		skb->dev = local->mdev;
+
+		pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
+		memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
+		pkt_data->ifindex = sdata->dev->ifindex;
+		pkt_data->mgmt_iface = 0;
+		pkt_data->do_not_encrypt = 1;
+
+		/* above needed because we set skb device to master */
+
+		/*
+		 * fix up the pointers accounting for the radiotap
+		 * header still being in there.  We are being given
+		 * a precooked IEEE80211 header so no need for
+		 * normal processing
+		 */
+
+		skb_set_mac_header(skb, prthdr->it_len);
+		skb_set_network_header(skb, prthdr->it_len +
+		    sizeof(struct ieee80211_hdr));
+		skb_set_transport_header(skb, prthdr->it_len +
+		    sizeof(struct ieee80211_hdr));
+
+		/*
+		 * pass the radiotap header up to
+		 * the next stage intact
+		 */
+
+		dev_queue_xmit(skb);
+
+		return 0;
+	}
+
 	nh_pos = skb_network_header(skb) - skb->data;
 	h_pos = skb_transport_header(skb) - skb->data;
 
#6 lore raw

Re: [PATCH Try#9 4/4] mac80211: Monitor mode radiotap-based packet injection

Quoted 1 line · On Monday 11 June 2007 08:21, [email protected] wrote:

+__ieee80211_convert_radiotap_to_control_and_remove(

This is kinda long.. how about ieee80211_parse_radiotap instead? Function names aren't a substitute for comments. ;)

net/mac80211/ieee80211.c ieee80211_tx_h_ps_buf(struct ieee80211_t · line 1142

Quoted 1 line
net/mac80211/ieee80211.c +1 -0
+	struct ieee80211_hw_mode *hw_mode=tx->local->hw.conf.mode;

Add a space before and after the '='. Also, mode is more common than hw_mode as a variable name for struct ieee80211_hw_mode.

Quoted 11 lines
net/mac80211/ieee80211.c +11 -0
+
+	/* this can fail some sanity checks, drop packet if it does so */
+
+	if (ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len) < 0)
+		return TXRX_DROP;
+
+	/*
+	 * default control situation for all injected packets
+	 * FIXME: this does not suit all usage cases, expand to allow control
+	 */
+

net/mac80211/ieee80211.c ieee80211_tx_h_ps_buf(struct ieee80211_t · line 1163

Quoted 10 lines
net/mac80211/ieee80211.c +10 -0
+	control->retry_limit = 1; /* no retry */
+	control->key_idx = -1; /* no encryption key */
+	control->flags &= ~(IEEE80211_TXCTL_USE_RTS_CTS |
+			    IEEE80211_TXCTL_USE_CTS_PROTECT);
+	control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT |
+			  IEEE80211_TXCTL_NO_ACK;
+	control->antenna_sel_tx = 0; /* default to default antenna */
+
+	/*
+	 * for every radiotap entry that is present (returns -ve on end or

-ve?

net/mac80211/ieee80211.c ieee80211_tx_h_ps_buf(struct ieee80211_t · line 1173

Quoted 10 lines
net/mac80211/ieee80211.c +10 -0
+	 * on error)
+	 */
+
+	while (ieee80211_radiotap_iterator_next(&iterator) >= 0) {
+		int i, target_rate;
+
+		/* see if this argument is something we can use */
+
+		switch (iterator.this_arg_index) {
+

An empty line after a switch statement doesn't seem right.

I think the rest of the patch is okay. Just keep in mind the other style comments I made in the other patch.

Thanks,
-Michael Wu