wltrace.dot11 module

IEEE802.11 protocol definitions and utilities.

class wltrace.dot11.Beacon(pkt)[source]

Bases: object

Payload for 802.11 Beacon packet.

exception wltrace.dot11.Dot11Exception[source]

Bases: exceptions.Exception

class wltrace.dot11.Dot11Packet(fh=None, phy=None, counter=1, *args, **kwargs)[source]

Bases: wltrace.common.GenericHeader

IEEE802.11 packet.

This class parse as much as possible depending on the packet type and subtype.

Parameters:
  • fh (file object) – the file’s read pointer points to the beginning of a 802.11 packet.
  • phy (pyparser.capture.common.PhyInfo) – PHY information.
  • counter (int) – packet index in trace file, starting from 1.
FIELDS = ['fc', 'duration', 'addr1']
PACK_PATTERN = '<HH6s'
air_time()[source]

Duration of the packet in air.

Returns:duration in seconds.
Return type:float
crc_ok
dest

Shortcut to pkt.addr1.

end_epoch_ts
end_ts
epoch_ts
hash
parse_control()[source]
parse_data()[source]
parse_mgmt()[source]
src

Shortcut to pkt.addr2.

ts

Shortcut to pkt.phy.timestamp.

wltrace.dot11.MAX_ACK_LATENCY_US = 100

Maximum allowed gap between a packet and its ack in the packet trace.

wltrace.dot11.is_ack(pkt)[source]

Whether or not the packet is an ack packet.

Parameters:pkt (wltrace.dot11.Dot11Packet) – the packet.
Returns:True if it is an ack packet, otherwise False.
Return type:bool
wltrace.dot11.is_beacon(pkt)[source]

Whether a packet is a Beacon packet.

wltrace.dot11.is_block_ack(pkt)[source]

Whether a packet is a Block Ack packet.

wltrace.dot11.is_broadcast(mac)[source]

Whether or not a mac is broadcast MAC address.

Parameters:mac (str) – MAC address in string format (xx:xx:xx:xx:xx:xx). Case insensitive.
Returns:bool.
wltrace.dot11.is_highest_rate(rate)[source]

Whether or not the rate is the highest rate (single spatial stream) in rate table.

Parameters:rate (int) – rate in Mbps. Can be 802.11g/n rate.
Returns:True if the rate is highest, otherwise False. Note that if rate is not valid, this function returns False, instead of raising an exception.
Return type:bool
wltrace.dot11.is_lowest_rate(rate)[source]

Whether or not the rate is the lowest rate in rate table.

Parameters:rate (int) – rate in Mbps . Can be 802.11g/n rate.
Returns:True if the rate is lowest, otherwise False. Note that if rate is not valid, this function returns False, instead of raising an exception.
Return type:bool
wltrace.dot11.is_multicast(mac)[source]

Whether a MAC address is IPV4/V6 multicast address.

See https://en.wikipedia.org/wiki/Multicast_address#Ethernet

Parameters:mac (str) – MAC address
Returns:bool
>>> is_multicast('01:80:C2:00:00:08')
True
wltrace.dot11.is_qos_data(pkt)[source]

Whether a packet is a QoS Data packet.

wltrace.dot11.mcs_to_rate(mcs, bw=20, long_gi=True)[source]

Convert MCS index to rate in Mbps.

See http://mcsindex.com/

Parameters:
  • mcs (int) – MCS index
  • bw (int) – bandwidth, 20, 40, 80, ...
  • long_gi (bool) – True if long GI is used.
Returns:

rate – bitrate in Mbps

Return type:

float

>>> mcs_to_rate(5, bw=20, long_gi=False)
57.8
>>> mcs_to_rate(4, bw=40, long_gi=True)
81
>>> mcs_to_rate(3, bw=80, long_gi=False)
130
>>> mcs_to_rate(13, bw=160, long_gi=True)
936
wltrace.dot11.next_seq(seq)[source]

Next sequence number.

Parameters:seq (int) – current sequence number
Returns:next sequence number, may wrap around
Return type:int
>>> next_seq(3)
4
>>> next_seq(4095)
0
wltrace.dot11.rate_to_mcs(rate, bw=20, long_gi=True)[source]

Convert bit rate to MCS index.

Parameters:
  • rate (float) – bit rate in Mbps
  • bw (int) – bandwidth, 20, 40, 80, ...
  • long_gi (bool) – True if long GI is used.
Returns:

mcs – MCS index

Return type:

int

>>> rate_to_mcs(120, bw=40, long_gi=False)
5