hostapd: work with monitor interface
PATCH 1/1 hostapd: work with monitor interface
So here it is. hostapd using monitor interfaces instead of the management interface. It now uses the AP mode ethernet interface to get at EAPOL frames instead of the management interface.
Thanks goes to Andy for letting me use his radiotap iterator code from the kernel under GPL2/BSD :)
The code requires libnl from SVN and there's are two TODO (marked XXX) items related to error checking when creating the monitor interface. There are also a few more TODO items but those are not regressions except the channel/phytype one although I'm not sure hostapd actually uses that info.
---
Andy, feel free to lift the BPF code into your stuff. I've extended the radiotap parser to understand two more items, not sure if we want those in the kernel (the only thing we'd do with them is ignore). Actually, the two types I added are IEEE80211_RADIOTAP_TX_FLAGS and IEEE80211_RADIOTAP_DATA_RETRIES both of which we'll probably need for injection.
Too bad, this inserts more code than I've removed from the kernel, but at least much of the inserted code is the radiotap stuff which I just copied from the kernel.
I spent about two days working on this. Not too bad, so also thanks to Andy and everybody else who was involved with the injection for that.
hostapd/Makefile | 3 hostapd/defconfig | 5 hostapd/driver_devicescape.c | 564 ++++++++++++++++++++++++++----------------- hostapd/ieee802_11.c | 3 hostapd/radiotap.c | 281 +++++++++++++++++++++ hostapd/radiotap.h | 242 ++++++++++++++++++ hostapd/radiotap_iter.h | 41 +++ 7 files changed, 927 insertions(+), 212 deletions(-)
hostapd/Makefile +2 -1
@@ -117,7 +117,8 @@ endif ifdef CONFIG_DRIVER_DEVICESCAPE CFLAGS += -DCONFIG_DRIVER_DEVICESCAPE -OBJS += driver_devicescape.o +LIBS += -lnl +OBJS += driver_devicescape.o radiotap.o endif ifdef CONFIG_DRIVER_BSD
hostapd/driver_devicescape.c +353 -211
766 lines not on this page · raw message
hostapd/defconfig +5 -0
@@ -30,6 +30,11 @@ CONFIG_DRIVER_HOSTAP=y # wireless-dev.git tree). #WIRELESS_DEV=/usr/src/wireless-dev #CFLAGS += -I$(WIRELESS_DEV)/net/mac80211 +# driver_devicescape.c requires a rather new libnl, probably not +# shipped with your distribution yet +#LIBNL=/usr/src/libnl +#CFLAGS += -I$(LIBNL)/include +#LIBS += -L$(LIBNL)/lib # Driver interface for FreeBSD net80211 layer (e.g., Atheros driver) #CONFIG_DRIVER_BSD=y
hostapd/radiotap.c new file +281 -0
281 lines not on this page · raw message
hostapd/radiotap.h new file +242 -0
242 lines not on this page · raw message
hostapd/radiotap_iter.h new file +41 -0
41 lines not on this page · raw message
hostapd/ieee802_11.c +3 -0
@@ -1672,6 +1672,9 @@ void ieee802_11_mgmt_cb(struct hostapd_dcase WLAN_FC_STYPE_PROBE_RESP :HOSTAPD_DEBUG (HOSTAPD_DEBUG_MINIMAL ,"mgmt::proberesp cb\n" );break ; +case WLAN_FC_STYPE_DEAUTH : +/* ignore */ +break ;default :printf ("unknown mgmt cb frame subtype %d\n" , stype);break ;
Quoted 6 lines · Somebody in the thread at some point
Andy, feel free to lift the BPF code into your stuff. I've extended the radiotap parser to understand two more items, not sure if we want those in the kernel (the only thing we'd do with them is ignore). Actually, the two types I added are
IEEE80211_RADIOTAP_TX_FLAGSandIEEE80211_RADIOTAP_DATA_RETRIESboth of which we'll probably need for injection.
Wow impressive amount of ioctl calls going into the bit bucket there...
I will try to use your direct BPF programming and also dispense with libpcap tonight, thanks for that.
Quoted 2 lines
I spent about two days working on this. Not too bad, so also thanks to Andy and everybody else who was involved with the injection for that.
Good work done!
-Andy
Quoted 1 line · Andy Green
Wow impressive amount of ioctl calls going into the bit bucket there...
I think there's only a single ioctl being killed, but all the stuff from ieee80211_common.h which is good too. Less crappy userspace interface :)
Quoted 2 lines
I will try to use your direct BPF programming and also dispense with libpcap tonight, thanks for that.
There's one gotcha with BPF: the program counter is always increasing so you can't have loops, and if you say "jump by 1 instruction" then another one is added too. But if you just copy the post-processing code you won't have to deal with that :)
If you need any help writing a filter for the MAC address you use as the special one or something let me know. I'd probably use a 4-byte and a 2-byte word load and compare to constants; just remember that multi-byte word loads do network/host byte order swapping so you'll have to use the LE32/LE16 macros for the constants.
This was, incidentally, the reason I didn't use pcap, I couldn't figure out if it could handle little-endian loads like my first few instructions do.
johannes
Quoted 3 lines · Johannes Berg
So here it is. hostapd using monitor interfaces instead of the management interface. It now uses the AP mode ethernet interface to get at EAPOL frames instead of the management interface.
So there are a few more todo items now:
1) adjust wpa_supplicant accordingly; I don't quite understand the structure. Why is there src/drivers/* (for wpa_supplicant) and src/hostapd/drivers* for hostapd?
2) make sure that we don't copy each packet before stuffing it into a monitor interface. we now throw away packets with BPF but we've already copied them, that's rather wasteful. We should be able to get by using clones.
johannes
Quoted 4 lines · Johannes Berg
2) make sure that we don't copy each packet before stuffing it into a monitor interface. we now throw away packets with BPF but we've already copied them, that's rather wasteful. We should be able to get by using clones.
at least until we need to actually change anything in the packet, which is hopefully rare enough
johannes
PATCH v2 1/1 hostapd: work with monitor interface
In reply to Johannes BergSo here it is. hostapd using monitor interfaces instead of the management interface. It now uses the AP mode ethernet interface to get at EAPOL frames instead of the management interface.
Thanks goes to Andy for letting me use his radiotap iterator code from the kernel under GPL2/BSD :)
The code requires libnl from SVN.
There are few TODO items but those are not regressions except the channel/phytype one and I'm not sure hostapd actually uses that info.
--- hostapd/Makefile | 3 hostapd/defconfig | 5 hostapd/driver_devicescape.c | 563 ++++++++++++++++++++++++++----------------- hostapd/ieee802_11.c | 3 hostapd/radiotap.c | 281 +++++++++++++++++++++ hostapd/radiotap.h | 242 ++++++++++++++++++ hostapd/radiotap_iter.h | 41 +++ 7 files changed, 926 insertions(+), 212 deletions(-)
hostapd/Makefile +2 -1
@@ -117,7 +117,8 @@ endif ifdef CONFIG_DRIVER_DEVICESCAPE CFLAGS += -DCONFIG_DRIVER_DEVICESCAPE -OBJS += driver_devicescape.o +LIBS += -lnl +OBJS += driver_devicescape.o radiotap.o endif ifdef CONFIG_DRIVER_BSD
hostapd/driver_devicescape.c +352 -211
771 lines not on this page · raw message
hostapd/defconfig +5 -0
@@ -30,6 +30,11 @@ CONFIG_DRIVER_HOSTAP=y # wireless-dev.git tree). #WIRELESS_DEV=/usr/src/wireless-dev #CFLAGS += -I$(WIRELESS_DEV)/net/mac80211 +# driver_devicescape.c requires a rather new libnl, probably not +# shipped with your distribution yet +#LIBNL=/usr/src/libnl +#CFLAGS += -I$(LIBNL)/include +#LIBS += -L$(LIBNL)/lib # Driver interface for FreeBSD net80211 layer (e.g., Atheros driver) #CONFIG_DRIVER_BSD=y
hostapd/radiotap.c new file +281 -0
281 lines not on this page · raw message
hostapd/radiotap.h new file +242 -0
242 lines not on this page · raw message
hostapd/radiotap_iter.h new file +41 -0
41 lines not on this page · raw message
hostapd/ieee802_11.c +3 -0
@@ -1672,6 +1672,9 @@ void ieee802_11_mgmt_cb(struct hostapd_dcase WLAN_FC_STYPE_PROBE_RESP :HOSTAPD_DEBUG (HOSTAPD_DEBUG_MINIMAL ,"mgmt::proberesp cb\n" );break ; +case WLAN_FC_STYPE_DEAUTH : +/* ignore */ +break ;default :printf ("unknown mgmt cb frame subtype %d\n" , stype);break ;
PATCH 1/1 hostapd: also get outgoing EAPOL frames from monitor iface
Hostapd doesn't really seem to care much at the moment, but it really should be notified about EAPOL frame transmit callbacks as well.
--- hostapd/driver_devicescape.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
hostapd/driver_devicescape.c +48 -0
@@ -1518,6 +1518,54 @@ struct sock_filter msock_filter_insns[]/* do we need any other frames? */ +/* +* do the rest of the test only on frames we sent ourselves +*/ +BPF_STMT (BPF_LD |BPF_W |BPF_ABS ,4 ), +BPF_STMT (BPF_ALU |BPF_AND |BPF_K , +LE32 (1 <<IEEE80211_RADIOTAP_TX_FLAGS )), +BPF_JUMP (BPF_JMP |BPF_JEQ ,0 ,FAIL ,0 ), + +/* +* drop non-data frames, WDS frames +*/ +/* load the lower byte of the frame control field */ +BPF_STMT (BPF_LD |BPF_B |BPF_IND ,0 ), +/* mask off QoS bit */ +BPF_STMT (BPF_ALU |BPF_AND |BPF_K ,0x0c ), +/* drop non-data frames */ +BPF_JUMP (BPF_JMP |BPF_JEQ ,8 ,0 ,FAIL ), +/* load the upper byte of the frame control field */ +BPF_STMT (BPF_LD |BPF_B |BPF_IND ,0 ), +/* mask off toDS/fromDS */ +BPF_STMT (BPF_ALU |BPF_AND |BPF_K ,0x03 ), +/* drop WDS frames */ +BPF_JUMP (BPF_JMP |BPF_JEQ ,3 ,FAIL ,0 ), + +/* +* add header length to index +*/ +/* load the lower byte of the frame control field */ +BPF_STMT (BPF_LD |BPF_B |BPF_IND ,0 ), +/* mask off QoS bit */ +BPF_STMT (BPF_ALU |BPF_AND |BPF_K ,0x80 ), +/* right shift it by 6 to give 0 or 2 */ +BPF_STMT (BPF_ALU |BPF_RSH |BPF_K ,6 ), +/* add data frame header length */ +BPF_STMT (BPF_ALU |BPF_ADD |BPF_K ,24 ), +/* add index, was start of 802.11 header */ +BPF_STMT (BPF_ALU |BPF_ADD |BPF_X ,0 ), +/* move to index, now start of LL header */ +BPF_STMT (BPF_MISC |BPF_TAX ,0 ), + +/* +* Accept EAPOL frames +*/ +BPF_STMT (BPF_LD |BPF_W |BPF_IND ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ ,0xAAAA0300 ,0 ,FAIL ), +BPF_STMT (BPF_LD |BPF_W |BPF_IND ,4 ), +BPF_JUMP (BPF_JMP |BPF_JEQ ,0x0000888E ,PASS ,FAIL ), +/* keep these last two statements or change the code below */ /* return 0 == "DROP" */ BPF_STMT(BPF_RET | BPF_K, 0),
Re: [PATCH] hostapd: also get outgoing EAPOL frames from monitor iface
hostapd/driver_devicescape.c struct sock_filter msock_filter_insns[] · line 1567
Quoted 7 lines · Johannes Berg
hostapd/driver_devicescape.c +7
-0+/* +* Accept EAPOL frames +*/ +BPF_STMT (BPF_LD |BPF_W |BPF_IND ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ ,0xAAAA0300 ,0 ,FAIL ), +BPF_STMT (BPF_LD |BPF_W |BPF_IND ,4 ), + BPF_JUMP(BPF_JMP | BPF_JEQ, 0x0000888E, PASS, FAIL),
Hmm... This isn't going to work without hardware crypto. Ideas anyone?
johannes