lib/packetgen/header/dot11/sub_mngt.rb in packetgen-3.1.0 vs lib/packetgen/header/dot11/sub_mngt.rb in packetgen-3.1.1
- old
+ new
@@ -17,65 +17,35 @@
# All SubMngt subclasses have ability to have {Element}. These elements
# may be accessed through {#elements}.
# @author Sylvain Daubert
class SubMngt < Base
# @return [Array<Element>]
- attr_accessor :elements
+ define_field :elements, ArrayOfElements
- # @param [Hash] options
- # @see Base#initialize
- def initialize(options={})
- super
- @elements = []
- end
-
- # Populate object from binary string
- # @param [String] str
- # @return [SubMngt] self
- def read(str)
- super
- read_elements str[sz, str.size] || ''
- self
- end
-
# @return [String]
- def to_s
- super + @elements.map(&:to_s).join
- end
+ #def inspect
+ # str = super
+ # str << Inspect.dashed_line('Dot11 Elements', 2)
+ # @elements.each do |el|
+ # str << Inspect.shift_level(2) << el.to_human << "\n"
+ # end
+ # str
+ #end
- # @return [String]
- def inspect
- str = super
- str << Inspect.dashed_line('Dot11 Elements', 2)
- @elements.each do |el|
- str << Inspect.shift_level(2) << el.to_human << "\n"
- end
- str
- end
-
# Add an {Element} to header
# @param [Integer,String] type element type
# @param [Object] value element value
# @return [self]
# @since 2.1.3
+ # @since 3.1.1 #elements in no more an Array but an {ArrayOfElements}
+ # @deprecated Prefer use of +submngt.element << {type: type, value: value}+
def add_element(type:, value:)
+ Deprecation.deprecated(self.class, __method__, 'elements')
element = Element.new(type: type, value: value)
- @elements << element
+ self.elements << element
self
end
-
- private
-
- def read_elements(str)
- start = 0
- elsz = Element.new.sz
- while str.size - start >= elsz
- el = Element.new.read(str[start, str.size])
- @elements << el
- start += el.sz
- end
- end
end
# IEEE 802.11 Association Request frame
#
# Specialize {Dot11::Management} with +subtype+ set to 0.
@@ -85,14 +55,14 @@
# * {#listen_interval} ({Types::Int16le}).
# @author Sylvain Daubert
class AssoReq < SubMngt
# @!attribute cap
# @return [Integer] 16-bit capabillities word
- define_field :cap, Types::Int16le
+ define_field_before :elements, :cap, Types::Int16le
# @!attribute listen_interval
# @return [Integer] 16-bit listen interval value
- define_field :listen_interval, Types::Int16le, default: 0x00c8
+ define_field_before :elements, :listen_interval, Types::Int16le, default: 0x00c8
end
Header.add_class AssoReq
Management.bind AssoReq, type: 0, subtype: 0
# IEEE 802.11 Association Response frame
@@ -105,17 +75,17 @@
# * {#aid} ({Types::Int16le}).
# @author Sylvain Daubert
class AssoResp < SubMngt
# @!attribute cap
# @return [Integer] 16-bit capabillities word
- define_field :cap, Types::Int16le
+ define_field_before :elements, :cap, Types::Int16le
# @!attribute status
# @return [Integer] 16-bit status word
- define_field :status, Types::Int16le
+ define_field_before :elements, :status, Types::Int16le
# @!attribute aid
# @return [Integer] 16-bit AID word
- define_field :aid, Types::Int16le
+ define_field_before :elements, :aid, Types::Int16le
end
Header.add_class AssoResp
Management.bind AssoResp, type: 0, subtype: 1
# IEEE 802.11 ReAssociation Request frame
@@ -128,11 +98,11 @@
# * {#current_ap} ({Eth::MacAddr}).
# @author Sylvain Daubert
class ReAssoReq < AssoReq
# @!attribute current_ap
# @return [Eth::MAcAddr]
- define_field :current_ap, Eth::MacAddr
+ define_field_before :elements, :current_ap, Eth::MacAddr
end
Header.add_class ReAssoReq
Management.bind ReAssoReq, type: 0, subtype: 2
# IEEE 802.11 ReAssociation Response frame
@@ -170,17 +140,17 @@
# * {#cap} ({Types::Int16le}).
# @author Sylvain Daubert
class ProbeResp < SubMngt
# @!attribute timestamp
# @return [Integer] 64-bit timestamp
- define_field :timestamp, Types::Int64le
+ define_field_before :elements, :timestamp, Types::Int64le
# @!attribute beacon_interval
# @return [Integer] 16-bit beacon interval value
- define_field :beacon_interval, Types::Int16le, default: 0x0064
+ define_field_before :elements, :beacon_interval, Types::Int16le, default: 0x0064
# @!attribute cap
# @return [Integer] 16-bit capabillities word
- define_field :cap, Types::Int16le
+ define_field_before :elements, :cap, Types::Int16le
end
Header.add_class ProbeResp
Management.bind ProbeResp, type: 0, subtype: 5
# IEEE 802.11 Beacon frame
@@ -193,17 +163,17 @@
# * {#cap} ({Types::Int16le}).
# @author Sylvain Daubert
class Beacon < SubMngt
# @!attribute timestamp
# @return [Integer] 64-bit timestamp
- define_field :timestamp, Types::Int64le
+ define_field_before :elements, :timestamp, Types::Int64le
# @!attribute interval
# @return [Integer] 16-bit interval value
- define_field :interval, Types::Int16le, default: 0x64
+ define_field_before :elements, :interval, Types::Int16le, default: 0x64
# @!attribute cap
# @return [Integer] 16-bit capabillities word
- define_field :cap, Types::Int16le
+ define_field_before :elements, :cap, Types::Int16le
end
Header.add_class Beacon
Management.bind Beacon, type: 0, subtype: 8
# IEEE 802.11 ATIM frame
@@ -224,11 +194,11 @@
# * {#reason} ({Types::Int16le}).
# @author Sylvain Daubert
class Disas < SubMngt
# @!attribute reason
# @return [Integer] 16-bit reason value
- define_field :reason, Types::Int16le
+ define_field_before :elements, :reason, Types::Int16le
end
Header.add_class Disas
Management.bind Disas, type: 0, subtype: 10
# IEEE 802.11 Authentication frame
@@ -241,17 +211,17 @@
# * {#status} ({Types::Int16le}).
# @author Sylvain Daubert
class Auth < SubMngt
# @!attribute algo
# @return [Integer] 16-bit algo value
- define_field :algo, Types::Int16le
+ define_field_before :elements, :algo, Types::Int16le
# @!attribute seqnum
# @return [Integer] 16-bit seqnum value
- define_field :seqnum, Types::Int16le
+ define_field_before :elements, :seqnum, Types::Int16le
# @!attribute status
# @return [Integer] 16-bit status word
- define_field :status, Types::Int16le
+ define_field_before :elements, :status, Types::Int16le
end
Header.add_class Auth
Management.bind Auth, type: 0, subtype: 11
# IEEE 802.11 Deauthentication frame
@@ -262,10 +232,10 @@
# * {#reason} ({Types::Int16le}).
# @author Sylvain Daubert
class DeAuth < SubMngt
# @!attribute reason
# @return [Integer] 16-bit reason value
- define_field :reason, Types::Int16le
+ define_field_before :elements, :reason, Types::Int16le
end
Header.add_class DeAuth
Management.bind DeAuth, type: 0, subtype: 12
end
end