Class: PWN::SDR::Decoder::WiFi::DSSSIQ
- Inherits:
-
Object
- Object
- PWN::SDR::Decoder::WiFi::DSSSIQ
- Defined in:
- lib/pwn/sdr/decoder/wifi.rb
Overview
IEEE 802.11b 18.2/18.4 long-preamble DBPSK/Barker 1 Mbps only. https://www.ieee802.org/11/Documents/DocumentArchives/1999_docs/90845b_p80211b-draft3.1.pdf Integer 11 MHz chip-rate multiples; frequency-centred IQ. No OFDM/CCK, DQPSK, short preamble, resampling, equalizer or clock-drift tracking.
Constant Summary collapse
- BARKER =
[1, -1, 1, 1, -1, 1, 1, 1, -1, -1, -1].freeze
- SYNC =
(([1] * 96) + [0xf3a0].pack('v').unpack1('b*').chars.map(&:to_i)).freeze
Instance Method Summary collapse
- #feed_iq(samples, rate: nil) ⇒ Object
- #flush ⇒ Object
-
#initialize(rate:) ⇒ DSSSIQ
constructor
A new instance of DSSSIQ.
Constructor Details
#initialize(rate:) ⇒ DSSSIQ
Returns a new instance of DSSSIQ.
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/pwn/sdr/decoder/wifi.rb', line 151 def initialize(rate:) @rate = Integer(rate) raise ArgumentError, 'DSSS requires 11, 22 or 44 MHz IQ' unless [11_000_000, 22_000_000, 44_000_000].include?(@rate) @chips = BARKER.flat_map { |chip| [chip] * (@rate / 11_000_000) } @width = @chips.length @window = [] @lanes = Array.new(@width) { {} } @count = 0 @last_frame = -@width @reassembler = MACReassembler.new end |
Instance Method Details
#feed_iq(samples, rate: nil) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/pwn/sdr/decoder/wifi.rb', line 164 def feed_iq(samples, rate: nil) raise ArgumentError, 'sample rate changed midstream' if rate && (rate.to_f - @rate).abs.positive? raise ArgumentError, 'interleaved IQ pairs required' unless samples.length.even? samples.each_slice(2) do |i, q| @count += 1 @window << [i, q] @window.shift if @window.length > @width next unless @window.length == @width real = 0.0 imag = 0.0 power = 0.0 @window.each_with_index do |(wi, wq), index| real += wi * @chips[index] imag += wq * @chips[index] power += (wi * wi) + (wq * wq) end lane = @lanes[@count % @width] if power < 1e-8 || ((real * real) + (imag * imag)) < 0.65 * power * @width lane.clear next end previous = lane[:previous] lane[:previous] = [real, imag] next unless previous scrambled = ((real * previous[0]) + (imag * previous[1])).negative? ? 1 : 0 history = lane.fetch(:history, 0) bit = scrambled ^ ((history >> 3) & 1) ^ ((history >> 6) & 1) lane[:history] = ((history << 1) | scrambled) & 127 frame = consume(lane, bit) next unless frame && @count - @last_frame >= @width @last_frame = @count frame = @reassembler.feed(frame, sample_time: @count.to_f / @rate) yield frame if block_given? end end |
#flush ⇒ Object
204 205 206 207 208 |
# File 'lib/pwn/sdr/decoder/wifi.rb', line 204 def flush @window.clear @lanes.each(&:clear) @reassembler.clear end |