Class: PacketGen::Header::Dot11 Abstract
- Defined in:
- lib/packetgen/header/dot11.rb,
lib/packetgen/header/dot11/data.rb,
lib/packetgen/header/dot11/control.rb,
lib/packetgen/header/dot11/element.rb,
lib/packetgen/header/dot11/sub_mngt.rb,
lib/packetgen/header/dot11/management.rb
Overview
This is a base class to demultiplex different IEEE 802.11 frames when parsing.
A IEEE 802.11 header may consist of at least:
-
a #frame_ctrl (
BinStruct::Int16
), -
a #id/duration (
BinStruct::Int16le
), -
and a #mac1 (Eth::MacAddr).
Depending on frame type and subtype, it may also contains:
-
a #mac2 (Eth::MacAddr),
-
a #mac3 (Eth::MacAddr),
-
a #sequence_ctrl (
BinStruct::Int16
), -
a #mac4 (Eth::MacAddr),
-
a #qos_ctrl (
BinStruct::Int16
), -
a #ht_ctrl (
BinStruct::Int32
), -
a #body (a
BinStruct::String
or another PacketGen::Headerable class), -
a Frame check sequence (#fcs, of type
BinStruct::Int32le
)
Header accessors
As Dot11 header types are defined under Dot11 namespace, Dot11 header accessors have a specific name. For example, to access to a Beacon header, accessor is #dot11_beacon
.
Create Dot11 packets
As Dot11 is an abstract class, you have to use one of its subclasses to instanciate a IEEE802.11 header (see examples below).
Parse Dot11 packets
When parsing a Dot11 packet, Dot11 subclass is created from type
value. Dot11 header should then be accessed through Packet#dot11, whatever the frame type is. But, specialized methods also exist: by example, for a control frame, Packet#dot11_control may also be used.
Send Dot11 packets
To send a Dot11 packet, a RadioTap or PPI header is needed (depending on your hardware):
pkt = PacketGen.gen('RadioTap')
pkt.add('Dot11::Management', mac1: client, mac2: bssid, mac3: bssid)
pkt.add('Dot11::Beacon')
pkt.dot11_management.add_element(type: 'SSID', value: 'My SSID')
pkt.dot11_management.add_element(type: 'Rates', value: "\x85\x0c")
pkt.to_w('wlan0')
Direct Known Subclasses
Defined Under Namespace
Classes: ATIM, ArrayOfElements, AssoReq, AssoResp, Auth, Beacon, Control, Data, DeAuth, Disas, Element, Management, ProbeReq, ProbeResp, ReAssoReq, ReAssoResp, SubMngt
Constant Summary collapse
- TYPES =
Frame types
%w[Management Control Data Reserved].freeze
Class Attribute Summary collapse
-
.fcs ⇒ Boolean
(also: fcs?)
Set a flag for parsing Dot11 packets.
Instance Attribute Summary collapse
-
#body ⇒ BinStruct::String
Dot11 body, if any.
-
#fcs ⇒ BinStruct::Int32le
Checksum of the Dot11 frame.
-
#fragment_number ⇒ Integer
4-bit attribute from #sequence_ctrl.
-
#frame_ctrl ⇒ Integer
16-bit frame control word.
-
#from_ds ⇒ Boolean
From_ds flag from #frame_ctrl.
-
#ht_ctrl ⇒ Integer
16-bit HT control word.
-
#id ⇒ Integer
(also: #duration)
16-bit ID/Duration word.
- #mac1 ⇒ Eth::MacAddr
- #mac2 ⇒ Eth::MacAddr
- #mac3 ⇒ Eth::MacAddr
- #mac4 ⇒ Eth::MacAddr
-
#md ⇒ Boolean
Md flag from #frame_ctrl.
-
#mf ⇒ Boolean
Mf flag from #frame_ctrl.
-
#order ⇒ Boolean
Order flag from #frame_ctrl.
-
#proto_version ⇒ Integer
2-bit protocol version from #frame_ctrl.
-
#pwmngt ⇒ Boolean
Pwmngt flag from #frame_ctrl.
-
#qos_ctrl ⇒ Integer
16-bit QoS control word.
-
#retry ⇒ Boolean
Retry flag from #frame_ctrl.
-
#sequence_ctrl ⇒ Integer
16-bit sequence control word.
-
#sequence_number ⇒ Integer
12-bit field from #sequence_ctrl.
-
#subtype ⇒ Integer
4-bit frame subtype from #frame_ctrl.
-
#to_ds ⇒ Boolean
To_ds flag from #frame_ctrl.
-
#type ⇒ Integer
2-bit frame type from #frame_ctrl.
-
#wep ⇒ Boolean
Wep flag from #frame_ctrl.
Instance Method Summary collapse
-
#added_to_packet(packet) ⇒ void
Callback called when a Dot11 header is added to a packet.
-
#attributes ⇒ Array<Symbol>
Get all used attribute names.
-
#calc_checksum ⇒ Integer
Compute checksum and set
fcs
field. -
#human_type ⇒ String
Get human readable type.
-
#initialize(options = {}) ⇒ Dot11
constructor
A new instance of Dot11.
- #inspect ⇒ String
- #old_attributes ⇒ Object
- #old_read ⇒ Object
-
#read(str) ⇒ Dot11
Populate object from a binary string.
-
#to_s ⇒ String
Generate binary string.
-
#to_w(iface) ⇒ void
send Dot11 packet on wire.
Methods inherited from Base
bind, calculate_and_set_length, #header_id, inherited, #ip_header, #ll_header
Methods included from PacketGen::Headerable
included, #method_name, #packet, #packet=, #parse?, #protocol_name
Constructor Details
#initialize(options = {}) ⇒ Dot11
Returns a new instance of Dot11.
257 258 259 260 |
# File 'lib/packetgen/header/dot11.rb', line 257 def initialize(={}) super @applicable_attributes = old_attributes end |
Class Attribute Details
.fcs ⇒ Boolean Also known as: fcs?
Set a flag for parsing Dot11 packets. If set to true
, parse FCS field, else don’t. Default is true
.
179 180 181 |
# File 'lib/packetgen/header/dot11.rb', line 179 def fcs @fcs end |
Instance Attribute Details
#body ⇒ BinStruct::String
Dot11 body, if any
245 |
# File 'lib/packetgen/header/dot11.rb', line 245 define_attr :body, BinStruct::String |
#fcs ⇒ BinStruct::Int32le
Checksum of the Dot11 frame.
249 |
# File 'lib/packetgen/header/dot11.rb', line 249 define_attr :fcs, BinStruct::Int32le |
#fragment_number ⇒ Integer
4-bit attribute from #sequence_ctrl
232 |
# File 'lib/packetgen/header/dot11.rb', line 232 define_bit_attr :sequence_ctrl, sequence_number: 12, fragment_number: 4 |
#frame_ctrl ⇒ Integer
Returns 16-bit frame control word.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
#from_ds ⇒ Boolean
Returns from_ds flag from #frame_ctrl.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
#ht_ctrl ⇒ Integer
Returns 16-bit HT control word.
241 |
# File 'lib/packetgen/header/dot11.rb', line 241 define_attr :ht_ctrl, BinStruct::Int32 |
#id ⇒ Integer Also known as: duration
Returns 16-bit ID/Duration word.
212 |
# File 'lib/packetgen/header/dot11.rb', line 212 define_attr :id, BinStruct::Int16le, default: 0 |
#mac1 ⇒ Eth::MacAddr
215 |
# File 'lib/packetgen/header/dot11.rb', line 215 define_attr :mac1, Eth::MacAddr |
#mac2 ⇒ Eth::MacAddr
218 |
# File 'lib/packetgen/header/dot11.rb', line 218 define_attr :mac2, Eth::MacAddr |
#mac3 ⇒ Eth::MacAddr
221 |
# File 'lib/packetgen/header/dot11.rb', line 221 define_attr :mac3, Eth::MacAddr |
#mac4 ⇒ Eth::MacAddr
235 |
# File 'lib/packetgen/header/dot11.rb', line 235 define_attr :mac4, Eth::MacAddr |
#md ⇒ Boolean
Returns md flag from #frame_ctrl.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
#mf ⇒ Boolean
Returns mf flag from #frame_ctrl.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
#order ⇒ Boolean
Returns order flag from #frame_ctrl.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
#proto_version ⇒ Integer
Returns 2-bit protocol version from #frame_ctrl.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
#pwmngt ⇒ Boolean
Returns pwmngt flag from #frame_ctrl.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
#qos_ctrl ⇒ Integer
Returns 16-bit QoS control word.
238 |
# File 'lib/packetgen/header/dot11.rb', line 238 define_attr :qos_ctrl, BinStruct::Int16 |
#retry ⇒ Boolean
Returns retry flag from #frame_ctrl.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
#sequence_ctrl ⇒ Integer
Returns 16-bit sequence control word.
232 |
# File 'lib/packetgen/header/dot11.rb', line 232 define_bit_attr :sequence_ctrl, sequence_number: 12, fragment_number: 4 |
#sequence_number ⇒ Integer
12-bit field from #sequence_ctrl
232 |
# File 'lib/packetgen/header/dot11.rb', line 232 define_bit_attr :sequence_ctrl, sequence_number: 12, fragment_number: 4 |
#subtype ⇒ Integer
Returns 4-bit frame subtype from #frame_ctrl.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
#to_ds ⇒ Boolean
Returns to_ds flag from #frame_ctrl.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
#type ⇒ Integer
Returns 2-bit frame type from #frame_ctrl.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
#wep ⇒ Boolean
Returns wep flag from #frame_ctrl.
208 209 |
# File 'lib/packetgen/header/dot11.rb', line 208 define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1, wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1 |
Instance Method Details
#added_to_packet(packet) ⇒ void
This method returns an undefined value.
Callback called when a Dot11 header is added to a packet. Here, add #dot11
method as a shortcut to existing #dot11_(control|management|data).
351 352 353 354 355 |
# File 'lib/packetgen/header/dot11.rb', line 351 def added_to_packet(packet) return if packet.respond_to?(:dot11) packet.instance_eval("def dot11(arg=nil); header(#{self.class}, arg); end") # def dot11(arg=nil); header(Dot11, arg); end end |
#attributes ⇒ Array<Symbol>
Get all used attribute names
264 265 266 |
# File 'lib/packetgen/header/dot11.rb', line 264 def attributes @applicable_attributes end |
#calc_checksum ⇒ Integer
Compute checksum and set fcs
field
301 302 303 304 305 |
# File 'lib/packetgen/header/dot11.rb', line 301 def calc_checksum fcs = Zlib.crc32(to_s[0...-4]) self.fcs = fcs fcs end |
#human_type ⇒ String
Get human readable type
316 317 318 |
# File 'lib/packetgen/header/dot11.rb', line 316 def human_type TYPES[type] end |
#inspect ⇒ String
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/packetgen/header/dot11.rb', line 321 def inspect str = if self.instance_of?(Dot11) Inspect.dashed_line("#{self.class} #{human_type}", 1) elsif self.respond_to?(:human_subtype) Inspect.dashed_line("#{self.class} #{human_subtype}", 1) else Inspect.dashed_line(self.class.to_s, 1) end define_applicable_attributes @applicable_attributes.each do |attr| next if attr == :body str << Inspect.inspect_attribute(attr, @attributes[attr], 1) end str end |
#old_attributes ⇒ Object
253 |
# File 'lib/packetgen/header/dot11.rb', line 253 alias old_attributes attributes |
#old_read ⇒ Object
269 |
# File 'lib/packetgen/header/dot11.rb', line 269 alias old_read read |
#read(str) ⇒ Dot11
Populate object from a binary string
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/packetgen/header/dot11.rb', line 275 def read(str) fcs = Dot11.fcs? if self.instance_of?(Dot11) return self if str.nil? str = str.b unless str.encoding == Encoding::BINARY self[:frame_ctrl].read(str[0, 2]) case type when 0 Dot11::Management.new.read(str) when 1 Dot11::Control.new.read(str) when 2 Dot11::Data.new.read(str) else private_read(str, fcs) end else private_read(str, fcs) end end |
#to_s ⇒ String
Generate binary string
309 310 311 312 |
# File 'lib/packetgen/header/dot11.rb', line 309 def to_s define_applicable_attributes @applicable_attributes.map { |f| @attributes[f].to_s.b }.join end |
#to_w(iface) ⇒ void
This method returns an undefined value.
send Dot11 packet on wire.
342 343 344 |
# File 'lib/packetgen/header/dot11.rb', line 342 def to_w(iface) Inject.inject(iface: iface, data: self) end |