Class: PacketGen::Header::Dot11 Abstract
- Inherits:
-
Base
- Object
- Types::Fields
- Base
- PacketGen::Header::Dot11
- 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 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:
-
a #frame_ctrl (Types::Int16),
-
a #id/duration (Types::Int16le),
-
and a #mac1 (Eth::MacAddr).
Depending on frame type and subtype, it may also contains:
-
a #mac2 (Eth::MacAddr),
-
a #mac3 (Eth::MacAddr),
-
a #mac4 (Eth::MacAddr),
-
a #qos_ctrl (Types::Int16),
-
a #ht_ctrl (Types::Int32),
-
a #body (a Types::String or another Base class),
-
a Frame check sequence (#fcs, of type Types::Int32le)
Direct Known Subclasses
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
-
.has_fcs ⇒ Boolean
Set a flag for parsing Dot11 packets.
Instance Attribute Summary collapse
- #body ⇒ Types::String
- #fcs ⇒ Types::Int32le
-
#frame_ctrl ⇒ Integer
16-bit frame control word.
-
#from_ds ⇒ Boolean
From_ds flag from #frame_ctrl.
-
#ht_ctrl ⇒ Integer
16-bit HT control word.
-
#id ⇒ Integer
(also: #duration)
16-bit ID/Duration word.
- #mac1 ⇒ Eth::MacAddr
- #mac2 ⇒ Eth::MacAddr
- #mac3 ⇒ Eth::MacAddr
- #mac4 ⇒ Eth::MacAddr
-
#md ⇒ Boolean
Md flag from #frame_ctrl.
-
#mf ⇒ Boolean
Mf flag from #frame_ctrl.
-
#order ⇒ Boolean
Order flag from #frame_ctrl.
-
#proto_version ⇒ Integer
2-bit protocol version from #frame_ctrl.
-
#pwmngt ⇒ Boolean
Pwmngt flag from #frame_ctrl.
-
#qos_ctrl ⇒ Integer
16-bit QoS control word.
-
#retry ⇒ Boolean
Retry flag from #frame_ctrl.
-
#sequence_ctrl ⇒ Integer
16-bit sequence control word.
-
#subtype ⇒ Integer
4-bit frame subtype from #frame_ctrl.
-
#to_ds ⇒ Boolean
To_ds flag from #frame_ctrl.
-
#type ⇒ Integer
2-bit frame type from #frame_ctrl.
-
#wep ⇒ Boolean
Wep flag from #frame_ctrl.
Attributes inherited from Base
Instance Method Summary collapse
-
#calc_checksum ⇒ Integer
Compute checksum and set
fcsfield. -
#fields ⇒ Array<Symbol>
Get all used field names.
-
#human_type ⇒ String
Get human readable type.
-
#initialize(options = {}) ⇒ Dot11
constructor
A new instance of Dot11.
- #inspect ⇒ String
- #old_fields ⇒ Object
- #old_read ⇒ Object
-
#read(str) ⇒ Dot11
Populate object from a binary string.
- #to_s ⇒ String
-
#to_w(iface) ⇒ void
send Dot11 packet on wire.
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.
215 216 217 218 |
# File 'lib/packetgen/header/dot11.rb', line 215 def initialize(={}) super @applicable_fields = old_fields end |
Class Attribute Details
.has_fcs ⇒ Boolean
Set a flag for parsing Dot11 packets. If set to true, parse FCS field, else don’t. Default is true.
146 147 148 |
# File 'lib/packetgen/header/dot11.rb', line 146 def has_fcs @has_fcs end |
Instance Attribute Details
#body ⇒ Types::String
179 |
# File 'lib/packetgen/header/dot11.rb', line 179 define_field :body, Types::String |
#fcs ⇒ Types::Int32le
182 |
# File 'lib/packetgen/header/dot11.rb', line 182 define_field :fcs, Types::Int32le |
#frame_ctrl ⇒ Integer
Returns 16-bit frame control word.
152 |
# File 'lib/packetgen/header/dot11.rb', line 152 define_field :frame_ctrl, Types::Int16, default: 0 |
#from_ds ⇒ Boolean
Returns from_ds flag 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 |
#ht_ctrl ⇒ Integer
Returns 16-bit HT control word.
176 |
# File 'lib/packetgen/header/dot11.rb', line 176 define_field :ht_ctrl, Types::Int32 |
#id ⇒ Integer Also known as: duration
Returns 16-bit ID/Duration word.
155 |
# File 'lib/packetgen/header/dot11.rb', line 155 define_field :id, Types::Int16le, default: 0 |
#mac1 ⇒ Eth::MacAddr
158 |
# File 'lib/packetgen/header/dot11.rb', line 158 define_field :mac1, Eth::MacAddr |
#mac2 ⇒ Eth::MacAddr
161 |
# File 'lib/packetgen/header/dot11.rb', line 161 define_field :mac2, Eth::MacAddr |
#mac3 ⇒ Eth::MacAddr
164 |
# File 'lib/packetgen/header/dot11.rb', line 164 define_field :mac3, Eth::MacAddr |
#mac4 ⇒ Eth::MacAddr
170 |
# File 'lib/packetgen/header/dot11.rb', line 170 define_field :mac4, Eth::MacAddr |
#md ⇒ Boolean
Returns md flag 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 |
#mf ⇒ Boolean
Returns mf flag 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 |
#order ⇒ Boolean
Returns order flag 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 |
#proto_version ⇒ Integer
Returns 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 |
#pwmngt ⇒ Boolean
Returns pwmngt flag 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 |
#qos_ctrl ⇒ Integer
Returns 16-bit QoS control word.
173 |
# File 'lib/packetgen/header/dot11.rb', line 173 define_field :qos_ctrl, Types::Int16 |
#retry ⇒ Boolean
Returns retry flag 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 |
#sequence_ctrl ⇒ Integer
Returns 16-bit sequence control word.
167 |
# File 'lib/packetgen/header/dot11.rb', line 167 define_field :sequence_ctrl, Types::Int16le, default: 0 |
#subtype ⇒ Integer
Returns 4-bit frame subtype 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 |
#to_ds ⇒ Boolean
Returns to_ds flag 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 |
#type ⇒ Integer
Returns 2-bit frame type 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 |
#wep ⇒ Boolean
Returns wep flag 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 |
Instance Method Details
#calc_checksum ⇒ Integer
Compute checksum and set fcs field
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 |
#fields ⇒ Array<Symbol>
Get all used field names
222 223 224 |
# File 'lib/packetgen/header/dot11.rb', line 222 def fields @applicable_fields end |
#human_type ⇒ String
Get human readable type
272 273 274 |
# File 'lib/packetgen/header/dot11.rb', line 272 def human_type TYPES[type] end |
#inspect ⇒ 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_fields ⇒ Object
211 |
# File 'lib/packetgen/header/dot11.rb', line 211 alias old_fields fields |
#old_read ⇒ Object
227 |
# File 'lib/packetgen/header/dot11.rb', line 227 alias old_read read |
#read(str) ⇒ Dot11
Populate object from a binary string
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_s ⇒ 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.
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 |