Class: PacketGen::Header::Dot11::Data

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

Overview

IEEE 802.11 data frame header

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

A IEEE 802.11 data header consists of:

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 = {}) ⇒ Data

Returns a new instance of Data.

Parameters:

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

See Also:

Since:

  • 1.4.0



32
33
34
35
36
# File 'lib/packetgen/header/dot11/data.rb', line 32

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

Instance Method Details

#dstString

Get destination MAC address

Returns:

  • (String)

Since:

  • 1.4.0



70
71
72
73
# File 'lib/packetgen/header/dot11/data.rb', line 70

def dst
  _src_mac, dst_mac = src_dst_from_mac
  self.send(dst_mac)
end

#dst=(mac) ⇒ String

Set destination MAC address

Parameters:

  • mac (String)

    MAC address to set

Returns:

  • (String)

Since:

  • 1.4.0



78
79
80
81
# File 'lib/packetgen/header/dot11/data.rb', line 78

def dst=(mac)
  _src_mac, dst_mac = src_dst_from_mac
  self.send(:"#{dst_mac}=", mac)
end

#reply!Object

Invert source and destination addresses (see Table 8-19 from IEEE 802.11-2012 document to known which MAC is SA, and which one is DA). Also invert Receiver and Transmitter address in case ToDS and FromDS are true.

Since:

  • 1.4.0



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/packetgen/header/dot11/data.rb', line 43

def reply!
  ds = frame_ctrl & 3
  case ds
  when 0
    # MAC1: RA/DA, MAC2: TA/SA
    invert_mac :mac1, :mac2
  when 1
    # MAC1: RA/BSSID, MAC2: TA/SA, MAC3: DA
    invert_mac :mac1, :mac2
    self.to_ds = false
    self.from_ds = true
  when 2
    # MAC1: RA/DA, MAC2: BSSID, MAC3: SA or BSSID
    invert_mac :mac1, :mac2
    self.to_ds = true
    self.from_ds = false
  when 3
    # MAC1: RA, MAC2: TA
    invert_mac :mac1, :mac2
    # MAC3: DA, MAC4: SA
    invert_mac :mac3, :mac4
  end
  self
end

#srcString

Get source MAC address

Returns:

  • (String)

Since:

  • 1.4.0



85
86
87
88
# File 'lib/packetgen/header/dot11/data.rb', line 85

def src
  src_mac, = src_dst_from_mac
  self.send(src_mac)
end

#src=(mac) ⇒ String

Set source MAC address

Parameters:

  • mac (String)

    MAC address to set

Returns:

  • (String)

Since:

  • 1.4.0



93
94
95
96
# File 'lib/packetgen/header/dot11/data.rb', line 93

def src=(mac)
  src_mac, = src_dst_from_mac
  self.send(:"#{src_mac}=", mac)
end