class PacketGen::Header::Dot11::Management

IEEE 802.11 management frame header

This class make a {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

Public Class Methods

new(options={}) click to toggle source

@param [Hash] options @see Base#initialize

Calls superclass method PacketGen::Header::Dot11::new
# 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

Public Instance Methods

add_element(type:, value:) click to toggle source

Add an {Element} @param [Integer,String] type element type @param [Object] value element value @return [self] @since 2.1.3

# File lib/packetgen/header/dot11/management.rb, line 55
def add_element(type:, value:)
  if self[:body].is_a? SubMngt
    self[:body].elements << { type: type, value: value }
  else
    raise FormatError, 'Before adding an Element, you have to add a Dot11::SubMngt subclass instance'
  end

  self
end
reply!() click to toggle source

Invert mac1 and mac2 (resp. destination address and source address). @return [self]

# File lib/packetgen/header/dot11/management.rb, line 67
def reply!
  self[:mac1], self[:mac2] = self[:mac2], self[:mac1]
end