Class: PacketGen::Header::Dot11 Abstract

Inherits:
Base show all
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 class is abstract.

This is a base class to demultiplex different IEEE 802.11 frames when parsing.

IEEE 802.11 header A IEEE 802.11 header may consists of at least:

Depending on frame type and subtype, it may also contains:

header accessors

As Dot11 header types are defined under Dot11 namespace, Dot11 header accessors have a specific name. By example, to access to a Beacon header, accessor is #dot11_beacon.

Author:

  • Sylvain Daubert

Direct Known Subclasses

Control, Data, Management

Defined Under Namespace

Classes: ATIM, 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

Instance Attribute Summary collapse

Attributes inherited from Base

#packet

Instance Method Summary collapse

Methods inherited from Base

bind_header, #header_id, inherited, #ip_header, known_headers, #method_name, #parse?, protocol_name, #protocol_name

Methods inherited from Types::Fields

#[], #[]=, define_bit_fields_on, define_field, define_field_after, define_field_before, delete_field, #force_binary, inherited, #is_optional?, #is_present?, #optional_fields, #sz, #to_h

Constructor Details

#initialize(options = {}) ⇒ Dot11

Returns a new instance of Dot11.

Parameters:

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

See Also:



220
221
222
223
# File 'lib/packetgen/header/dot11.rb', line 220

def initialize(options={})
  super
  @applicable_fields = old_fields
end

Class Attribute Details

.has_fcsBoolean

Set a flag for parsing Dot11 packets. If set to true, parse FCS field, else don’t. Default is true.

Returns:

  • (Boolean)


151
152
153
# File 'lib/packetgen/header/dot11.rb', line 151

def has_fcs
  @has_fcs
end

Instance Attribute Details

#bodyTypes::String

Returns:



184
# File 'lib/packetgen/header/dot11.rb', line 184

define_field :body, Types::String

#fcsTypes::Int32le

Returns:



187
# File 'lib/packetgen/header/dot11.rb', line 187

define_field :fcs, Types::Int32le

#frame_ctrlInteger

Returns 16-bit frame control word.

Returns:

  • (Integer)

    16-bit frame control word



157
# File 'lib/packetgen/header/dot11.rb', line 157

define_field :frame_ctrl, Types::Int16, default: 0

#from_dsBoolean

Returns from_ds flag from #frame_ctrl.

Returns:



211
212
# File 'lib/packetgen/header/dot11.rb', line 211

define_bit_fields_on :frame_ctrl,  :subtype, 4, :type, 2, :proto_version, 2,
:order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds

#ht_ctrlInteger

Returns 16-bit HT control word.

Returns:

  • (Integer)

    16-bit HT control word



181
# File 'lib/packetgen/header/dot11.rb', line 181

define_field :ht_ctrl, Types::Int32

#idInteger Also known as: duration

Returns 16-bit ID/Duration word.

Returns:

  • (Integer)

    16-bit ID/Duration word



160
# File 'lib/packetgen/header/dot11.rb', line 160

define_field :id, Types::Int16le, default: 0

#mac1Eth::MacAddr

Returns:



163
# File 'lib/packetgen/header/dot11.rb', line 163

define_field :mac1, Eth::MacAddr

#mac2Eth::MacAddr

Returns:



166
# File 'lib/packetgen/header/dot11.rb', line 166

define_field :mac2, Eth::MacAddr

#mac3Eth::MacAddr

Returns:



169
# File 'lib/packetgen/header/dot11.rb', line 169

define_field :mac3, Eth::MacAddr

#mac4Eth::MacAddr

Returns:



175
# File 'lib/packetgen/header/dot11.rb', line 175

define_field :mac4, Eth::MacAddr

#mdBoolean

Returns md flag from #frame_ctrl.

Returns:



211
212
# File 'lib/packetgen/header/dot11.rb', line 211

define_bit_fields_on :frame_ctrl,  :subtype, 4, :type, 2, :proto_version, 2,
:order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds

#mfBoolean

Returns mf flag from #frame_ctrl.

Returns:



211
212
# File 'lib/packetgen/header/dot11.rb', line 211

define_bit_fields_on :frame_ctrl,  :subtype, 4, :type, 2, :proto_version, 2,
:order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds

#orderBoolean

Returns order flag from #frame_ctrl.

Returns:



211
212
# File 'lib/packetgen/header/dot11.rb', line 211

define_bit_fields_on :frame_ctrl,  :subtype, 4, :type, 2, :proto_version, 2,
:order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds

#proto_versionInteger

Returns 2-bit protocol version from #frame_ctrl.

Returns:

  • (Integer)

    2-bit protocol version from #frame_ctrl



211
212
# File 'lib/packetgen/header/dot11.rb', line 211

define_bit_fields_on :frame_ctrl,  :subtype, 4, :type, 2, :proto_version, 2,
:order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds

#pwmngtBoolean

Returns pwmngt flag from #frame_ctrl.

Returns:



211
212
# File 'lib/packetgen/header/dot11.rb', line 211

define_bit_fields_on :frame_ctrl,  :subtype, 4, :type, 2, :proto_version, 2,
:order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds

#qos_ctrlInteger

Returns 16-bit QoS control word.

Returns:

  • (Integer)

    16-bit QoS control word



178
# File 'lib/packetgen/header/dot11.rb', line 178

define_field :qos_ctrl, Types::Int16

#retryBoolean

Returns retry flag from #frame_ctrl.

Returns:



211
212
# File 'lib/packetgen/header/dot11.rb', line 211

define_bit_fields_on :frame_ctrl,  :subtype, 4, :type, 2, :proto_version, 2,
:order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds

#sequence_ctrlInteger

Returns 16-bit sequence control word.

Returns:

  • (Integer)

    16-bit sequence control word



172
# File 'lib/packetgen/header/dot11.rb', line 172

define_field :sequence_ctrl, Types::Int16le, default: 0

#subtypeInteger

Returns 4-bit frame subtype from #frame_ctrl.

Returns:



211
212
# File 'lib/packetgen/header/dot11.rb', line 211

define_bit_fields_on :frame_ctrl,  :subtype, 4, :type, 2, :proto_version, 2,
:order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds

#to_dsBoolean

Returns to_ds flag from #frame_ctrl.

Returns:



211
212
# File 'lib/packetgen/header/dot11.rb', line 211

define_bit_fields_on :frame_ctrl,  :subtype, 4, :type, 2, :proto_version, 2,
:order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds

#typeInteger

Returns 2-bit frame type from #frame_ctrl.

Returns:



211
212
# File 'lib/packetgen/header/dot11.rb', line 211

define_bit_fields_on :frame_ctrl,  :subtype, 4, :type, 2, :proto_version, 2,
:order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds

#wepBoolean

Returns wep flag from #frame_ctrl.

Returns:



211
212
# File 'lib/packetgen/header/dot11.rb', line 211

define_bit_fields_on :frame_ctrl,  :subtype, 4, :type, 2, :proto_version, 2,
:order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds

Instance Method Details

#calc_checksumInteger

Compute checksum and set fcs field

Returns:

  • (Integer)


263
264
265
266
267
# File 'lib/packetgen/header/dot11.rb', line 263

def calc_checksum
  fcs = Zlib.crc32(to_s[0...-4])
  self.fcs = fcs
  fcs
end

#fieldsArray<Symbol>

Get all used field names

Returns:

  • (Array<Symbol>)


227
228
229
# File 'lib/packetgen/header/dot11.rb', line 227

def fields
  @applicable_fields
end

#human_typeString

Get human readable type

Returns:

  • (String)


277
278
279
# File 'lib/packetgen/header/dot11.rb', line 277

def human_type
  TYPES[type]
end

#inspectString

Returns:

  • (String)


282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/packetgen/header/dot11.rb', line 282

def inspect
  str = if self.class == Dot11
          Inspect.dashed_line("#{self.class} #{human_type}", 2)
        elsif self.respond_to? :human_subtype
          Inspect.dashed_line("#{self.class} #{human_subtype}", 2)
        else
          Inspect.dashed_line("#{self.class}", 2)
        end
  define_applicable_fields
  @applicable_fields.each do |attr|
    next if attr == :body
    str << Inspect.inspect_attribute(attr, @fields[attr], 2)
  end
  str
end

#old_fieldsObject



216
# File 'lib/packetgen/header/dot11.rb', line 216

alias old_fields fields

#old_readObject



232
# File 'lib/packetgen/header/dot11.rb', line 232

alias old_read read

#read(str) ⇒ Dot11

Populate object from a binary string

Parameters:

  • str (String)

Returns:

  • (Dot11)

    may return a subclass object if a more specific class may be determined



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/packetgen/header/dot11.rb', line 238

def read(str)
  has_fcs = Dot11.has_fcs

  if self.class == Dot11
    return self if str.nil?
    force_binary str
    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, has_fcs
    end
  else
    private_read str, has_fcs
  end
end

#to_sString

Returns:

  • (String)


270
271
272
273
# File 'lib/packetgen/header/dot11.rb', line 270

def to_s
  define_applicable_fields
  @applicable_fields.map { |f| force_binary @fields[f].to_s }.join
end

#to_w(iface) ⇒ void

This method returns an undefined value.

send Dot11 packet on wire.

Parameters:

  • iface (String)

    interface name



301
302
303
304
305
306
# File 'lib/packetgen/header/dot11.rb', line 301

def to_w(iface)
  pcap = PCAPRUB::Pcap.open_live(iface, PCAP_SNAPLEN, PCAP_PROMISC,
                                 PCAP_TIMEOUT)
  str = self.to_s
  pcap.inject str << [crc32].pack('V')
end