Class: PacketGen::Header::Dot11::Management

Inherits:
PacketGen::Header::Dot11 show all
Defined in:
lib/packetgen/header/dot11/management.rb

Overview

IEEE 802.11 management frame header

This class make a PacketGen::Header::Dot11 header with #type set to 0 (management frame).

A IEEE 802.11 management header consists of:

Management frames should be constructed with more headers from SubMngt subclasses.

By example, build a DeAuth frame:

PacketGen.gen('Dot11::Management').add('Dot11::DeAuth')

Some frames need to have Element. By example a Beacon frame:

pkt = PacketGen.gen('Dot11::Management', mac1: broadcast, mac2: bssid, mac3: bssid).
                add('Dot11::Beacon')
pkt.dot11_beacon.add_elements(type: 'SSID', value: ssid)
pkt.dot11_beacon.add_elements(type: 'Rates', value: "\x82\x84\x8b\x96\x12\x24\x48\x6c")
pkt.dot11_beacon.add_elements(type: 'DSset', value: "\x06")
pkt.dot11_beacon.add_elements(type: 'TIM', value: "\x00\x01\x00\x00")

Author:

  • Sylvain Daubert

Since:

  • 1.4.0

Constant Summary

Constants inherited from PacketGen::Header::Dot11

TYPES

Instance Attribute Summary

Attributes inherited from PacketGen::Header::Dot11

#body, #fcs, #fragment_number, #frame_ctrl, #from_ds, #ht_ctrl, #id, #mac1, #mac2, #mac3, #mac4, #md, #mf, #order, #proto_version, #pwmngt, #qos_ctrl, #retry, #sequence_ctrl, #sequence_number, #subtype, #to_ds, #type, #wep

Instance Method Summary collapse

Methods inherited from PacketGen::Header::Dot11

#added_to_packet, #calc_checksum, #fields, #human_type, #inspect, #old_fields, #old_read, #read, #to_s, #to_w

Methods inherited from Base

bind, calculate_and_set_length, #header_id, inherited, #ip_header, #ll_header

Methods included from PacketGen::Headerable

#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

#initialize(options = {}) ⇒ Management

Returns a new instance of Management.

Parameters:

  • options (Hash) (defaults to: {})

See Also:

Since:

  • 1.4.0



44
45
46
47
48
# File 'lib/packetgen/header/dot11/management.rb', line 44

def initialize(options={})
  super({ type: 0 }.merge!(options))
  @applicable_fields -= %i[mac4 qos_ctrl ht_ctrl]
  define_applicable_fields
end

Instance Method Details

#add_element(type:, value:) ⇒ self

Add an Element

Parameters:

  • type (Integer, String)

    element type

  • value (Object)

    element value

Returns:

  • (self)

Raises:

Since:

  • 2.1.3



55
56
57
58
59
60
# File 'lib/packetgen/header/dot11/management.rb', line 55

def add_element(type:, value:)
  raise FormatError, 'Before adding an Element, you have to add a Dot11::SubMngt subclass instance' unless self[:body].is_a? SubMngt

  self[:body].elements << { type: type, value: value }
  self
end

#reply!self

Invert mac1 and mac2 (resp. destination address and source address).

Returns:

  • (self)

Since:

  • 1.4.0



64
65
66
# File 'lib/packetgen/header/dot11/management.rb', line 64

def reply!
  self[:mac1], self[:mac2] = self[:mac2], self[:mac1]
end