8K-ESP8266 Sniffer Introduction en v0.3
8K-ESP8266 Sniffer Introduction en v0.3
8K-ESP8266 Sniffer Introduction en v0.3
Espressif Systems
2/9
Espressif Systems
Table of Contents
1.
2.
2.
3.
3/9
Espressif Systems
1.
Sniffer Introduction
ESP8266 can enter promiscuous mode (sniffer) and capture IEEE 802.11 packets in the air.
The following HT20 packets are support:
802.11b
802.11g
HT40
LDPC
Although ESP8266 can not completely decipher these kinds of IEEE80211 packets completely, it can
still obtain the length of these special packets.
In summary, while in sniffer mode, ESP8266 can either capture completely the packets or obtain the
length of the packet:
Packets that ESP8266 can decipher completely; ESP8266 returns with the
MAC address of the both side of communication and encryption type and
Packets that ESP8266 can only partial decipher; ESP8266 returns with
Structure RxControl and sniffer_buf are used to represent these two kinds of packets. Structure
sniffer_buf contains structure RxControl.
struct RxControl {
signed rssi:8;
unsigned rate:4;
unsigned is_group:1;
unsigned:1;
unsigned sig_mode:2;
4/9
Espressif Systems
unsigned bssidmatch1:1;
unsigned MCS:7;
//length of packet
};
struct sniffer_buf2{
struct RxControl rx_ctrl;
u8 buf[112];
u16 cnt;
u16 len;
//length of packet
};
5/9
Espressif Systems
Callback wifi_promiscuous_rx has two parameters ( buf and len). len means the length of buf, it
can be: len = 128, len = X * 10, len = 12 :
Case of LEN == 128
buf contains structure sniffer_buf2: it is the management packet, it has 112 bytes data.
sniffer_buf2.cnt is 1.
Case of LEN == X * 10
buf contains structure sniffer_buf: this structure is reliable, data packets represented by it
sniffer_buf.cnt means the count of packets in buf. The value of len depends on
sniffer_buf.cnt.
If sniffer_buf.cnt > 1, it is a AMPDU packet, head of each MPDU packets are similar, so
we only provide the length of each packet (from head of MAC packet to FCS)
This structure contains: length of packet, MAC address of both sides of communication,
length of the head of packet.
Case of LEN == 12
buf contains structure RxControl; but this structure is not reliable, we can not get neither
MAC address of both sides of communication nor length of the head of packet.
For AMPDU packet, we can not get the count of packets or the length of packet.
RSSI and FEC_CODING are used to guess if the packets are sent from same device.
6/9
Espressif Systems
Summary
We should not take too long to process the packets. Otherwise, other packets may be lost.
The diagram below shows the format of a ieee80211 packet:
For WEP packets, MAC Header is followed by 4 bytes IV and before FCS there are 4 bytes
ICV.
For TKIP packet, MAC Header is followed by 4 bytes IV and 4 bytes EIV, and before FCS there
are 8 bytes MIC and 4 bytes ICV.
For CCMP packet, MAC Header is followed by 8 bytes CCMP header, and before FCS there
are 8 bytes MIC.
2.
Because some APs wont transmit UDP broadcast packets to WLAN, so only the UDP packets from
mobile phone can be listened. These UDP packets are from mobile phone to AP, and are encrypted.
Scenario 1: IOT_device can get all packets from mobile phone
This scenario requires:
The distance between mobile phone and AP is longer than the distance between mobile
phone and IOT_device
7/9
Espressif Systems
IOT-device firmware can set filter of MAC address or MAC-header ( include MAC-cryption-header ), it
can also set a filter for retransmission.
Meanwhile, for 802.11n AMPDU packets, IOT_device can also get the length of packet and MACheader ( include MAC-cryption-header )
Scenario 2: IOT_device can not get all packets from mobile phone, signal is strong, but packet
format is not supported.
Case 1
The distance between mobile phone and AP is much longer than the distance between mobile
phone and IOT_device. Then the high-frequency packets from mobile phone can be got by AP, but
can not be got by IOT_device.
For example, mobile phone sent MCS7 packets which can be got correctly by AP, but IOT_device can
only parse its packet header of physical layer (HT-SIG), because packet header of physical layer is
encoded on low-speed (6Mbps).
Case 2
Format of packets that mobile phone sent to AP is not supported by IOT_device, such as
HT40
LDPC
IOT_device can not get the whole packet, but can parse its packet header of physical layer (HT-SIG).
In both case 1 and case 2, IOT_device can get HT-SIG which include the length of packet in physical
layer. Please pay attention on following items when using it
When it isnt AMPDU packet or only one sub-frame in AMPDU packet, the length of UDP packet
can be speculated. If the time interval of UDP packets which sent from phone APP is long ( 20ms
~ 50ms ) , each UDP packet will in different packets in physical layer, may be a AMPDU packet
which only has one sub-frame.
Firmware of IOT_device can filter packets from other devices according to RSSI.
Packet of retransmission need to be filter according to the packets sequence, it means that length
of packets which sent consecutively need to be different. For example
Two useful packets can be separated by a specific packet. The specific packet works like
separative sign.
8/9
Espressif Systems
2.
Phone APP
Two data packets can be separated by a specific packet. The specific packet works like separative
sign.
Packet with redundant data so that packet can verify each other.
Set flag-packet at the beginning of sequence. Then phone APP can be cyclic sending the whole
sequence.
Only need to send the lowest 2 bytes of APs BSSID ( MAC address ), IOT-device can still get it. If
AP will broadcast its SSID, then phone APP need not to send APs SSID either. So AP beacon need
to be analyzed to check if the AP will broadcast its SSID.
Length of UDP packet need to be multiply by 4. Because when phone APP sent a AMPDU packet
which only has one sub-frame, packet length will be filled to be a multiple of 4.
3.
IOT-device Firmware
Search the channel which has strongest signal first, according to RSSI.
Filter useless packets according to RSSI. Considering 10~15db fluctuations in the air, some
packets may be decline 10db or more. We could search the strongest signal at first, then extend
the range since find the target sequence.
To design the length of packet that works as separative sign, different QoS, different encryption
algorithm and AMPDU packet will be a multiple of 4, all of these should be taken into
consideration.
Use relative value to transmit information, for example, the value that the length of data packet
minus the length of packet that works as separative sign.
9/9