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:

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, #parse?, #protocol_name

Methods inherited from Types::Fields

#[], #[]=, define_bit_fields_on, define_field, define_field_after, define_field_before, #force_binary, inherited, #sz, #to_h

Constructor Details

#initialize(options = {}) ⇒ Dot11

Returns a new instance of Dot11.

Parameters:

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

See Also:



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

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)


146
147
148
# File 'lib/packetgen/header/dot11.rb', line 146

def has_fcs
  @has_fcs
end

Instance Attribute Details

#bodyTypes::String

Returns:



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

define_field :body, Types::String

#fcsTypes::Int32le

Returns:



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

define_field :fcs, Types::Int32le

#frame_ctrlInteger

Returns 16-bit frame control word.

Returns:

  • (Integer)

    16-bit frame control word



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

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

#from_dsBoolean

Returns from_ds flag from #frame_ctrl.

Returns:



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

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



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

define_field :ht_ctrl, Types::Int32

#idInteger Also known as: duration

Returns 16-bit ID/Duration word.

Returns:

  • (Integer)

    16-bit ID/Duration word



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

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

#mac1Eth::MacAddr

Returns:



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

define_field :mac1, Eth::MacAddr

#mac2Eth::MacAddr

Returns:



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

define_field :mac2, Eth::MacAddr

#mac3Eth::MacAddr

Returns:



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

define_field :mac3, Eth::MacAddr

#mac4Eth::MacAddr

Returns:



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

define_field :mac4, Eth::MacAddr

#mdBoolean

Returns md flag from #frame_ctrl.

Returns:



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

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:



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

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:



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

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



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

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:



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

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



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

define_field :qos_ctrl, Types::Int16

#retryBoolean

Returns retry flag from #frame_ctrl.

Returns:



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

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



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

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

#subtypeInteger

Returns 4-bit frame subtype from #frame_ctrl.

Returns:



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

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:



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

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:



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

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:



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

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)


258
259
260
261
262
# File 'lib/packetgen/header/dot11.rb', line 258

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>)


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

def fields
  @applicable_fields
end

#human_typeString

Get human readable type

Returns:

  • (String)


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

def human_type
  TYPES[type]
end

#inspectString

Returns:

  • (String)


277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/packetgen/header/dot11.rb', line 277

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



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

alias old_fields fields

#old_readObject



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

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



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/packetgen/header/dot11.rb', line 233

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)


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

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



296
297
298
299
300
301
# File 'lib/packetgen/header/dot11.rb', line 296

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