802.11 Beacon Packet recovery failing
Hello Y’all,
I have a NI USRP coupled with a router’s antenna, and I receive 802.11 wifi signals in the 2.4G band. Then I convert that signal to .mat format and filter channel by channel to extract beacon frames and print their info such as ssid, bssid etc. I use Maltab’s WLAN Beacon Receiver Using Software-Defined Radio tutorial to do the beacon extraction, with config=’OFDM, band 2.4′ . I was able to see the router’s ssid from my phone and laptop, like how it is broadcasting in channel 1, 2.4 band (non-HT data) and its mode is 802.11n. I was also able to see regular spikes of energy every 100 ms when i plotted the spectrogram of channel_1 from the .mat file, indicating there is beacon transmission clearly. I am not able to figure out why the matlab code is not able to extract the beacon frames, i just used the standard matlab tutorial attached above, any help in figuring out the bottleneck in my approach would be really appreciated. Let me also attach the actual code in case if it helps (also my matlab version is R2022b)
fileName="C:WiFi_ProjectWiFi Dataextracted data20240626b_0.5seachData_0channel_1.mat";
rxsim.ReceiveOnSDR = false;
config=’OFDM, band 2.4′;
cbw="CBW20";
cfg = wlanNonHTConfig(ChannelBandwidth=cbw);
displayScope = true;
displayAdditionalInfo=false;
retrieveVendorInfo=true;
if rxsim.ReceiveOnSDR
[frequencyBand,bbSampleRate,chanNumber] = getSimParams(config);
rxsim.FrequencyBand = frequencyBand;
rxsim.RadioSampleRate = bbSampleRate;
rxsim.ChannelNumbers = chanNumber;
rxsim.SDRDeviceName = "Pluto"; % SDR for waveform reception
rxsim.RadioGain = 50;
rxsim.ReceiveAntenna = 1; % Configure to work with only a single antenna
rxsim.CaptureTime = milliseconds(102.4); % Value expected to be of type duration
% Derived Parameters
rxsim.CenterFrequencies = wlanChannelFrequency(rxsim.ChannelNumbers,rxsim.FrequencyBand);
else
rx = load(fileName);
[~,bbSampleRate,~] = getSimParams(config);
rxsim.ChannelNumbers = rx.channels;
rxsim.RadioSampleRate = rx.radioSampleRate;
rxsim.FrequencyBand = rx.band;
% Derived Parameters
rxsim.CaptureTime = seconds(size(rx.capturedWaveforms,1)/rxsim.RadioSampleRate);
end
overSampFac = rxsim.RadioSampleRate/bbSampleRate;
if rxsim.ReceiveOnSDR
sdrReceiver = hSDRReceiver(rxsim.SDRDeviceName);
sdrReceiver.SampleRate = rxsim.RadioSampleRate;
sdrReceiver.Gain = rxsim.RadioGain;
sdrReceiver.ChannelMapping = rxsim.ReceiveAntenna;
sdrReceiver.OutputDataType = "single";
end
APs = struct(…
"SSID",[],"BSSID",[],"Vendor",[],"SNR_dB",[],"Beacon_Channel",[], …
"Operating_Channel",[],"Channel_Width_MHz",[],"Band",[],"Mode",[], …
"MAC_Config",wlanMACFrameConfig,"Waveform",[],"Offset",[]);
indexAP = 1;
%Scan and decode for the specified channels.
tic
for i = 1:length(rxsim.ChannelNumbers)
fprintf("<strong>Scanning channel %d on band %.1f.</strong>n",rxsim.ChannelNumbers(i),rxsim.FrequencyBand);
if rxsim.ReceiveOnSDR
sdrReceiver.CenterFrequency = rxsim.CenterFrequencies(i);
capturedData = capture(sdrReceiver,rxsim.CaptureTime);
else
capturedData = double(rx.capturedWaveforms(:,i));
end
% Display spectrum and spectrogram
if displayScope %#ok<*UNRCH>
scope = spectrumAnalyzer(ViewType="spectrum-and-spectrogram",SampleRate=rxsim.RadioSampleRate,…
TimeSpanSource="property",TimeSpan=seconds(rxsim.CaptureTime));
scope.Title = "Band: " + rxsim.FrequencyBand + " Channel: " + rxsim.ChannelNumbers(i);
scope(capturedData);
end
% Resample the captured data to basesband sample rate for beacon processing
if overSampFac ~= 1
capturedData = resample(capturedData,bbSampleRate,rxsim.RadioSampleRate);
end
searchOffset = 0;
while searchOffset<length(capturedData)
capturedData = capturedData(searchOffset+1:end);
if(strcmp(config,’DSSS, band 2.4′))
[decParams, searchOffset, res, bitsData] = recoverDSSS(capturedData);
else
[decParams, searchOffset, res, bitsData] = recoverNonHTOFDM(capturedData,rxsim);
end
if ~isempty(bitsData)
[cfgMAC, ~, decodeStatus] = wlanMPDUDecode(bitsData,cfg …
,SuppressWarnings=false);
% Print additional information on all successfully recovered packets
if ~decodeStatus && displayAdditionalInfo
payloadSize = floor(length(bitsData)/8);
if(strcmp(config,’DSSS, band 2.4′))
fprintf("Payload Size: %d | Modulation: %s | Data Rate: %s n",payloadSize,decParams.modulation,decParams.dataRate);
else
fprintf("Payload Size: %d | Modulation: %s | Code Rate: %s n",payloadSize,decParams.modulation,decParams.coderate);
end
fprintf("Type: %s | Sub-Type: %s",cfgMAC.getType,cfgMAC.getSubtype);
end
% Extract information about channel from the beacon.
if ~decodeStatus && matches(cfgMAC.FrameType,"Beacon")
% Populate the table with information about the beacon.
if isempty(cfgMAC.ManagementConfig.SSID)
APs(indexAP).SSID = "Hidden";
else
APs(indexAP).SSID = string(cfgMAC.ManagementConfig.SSID);
end
APs(indexAP).BSSID = string(cfgMAC.Address3);
if retrieveVendorInfo
APs(indexAP).Vendor = determineVendor(cfgMAC.Address3);
else
APs(indexAP).Vendor = "Skipped";
end
[APs(indexAP).Mode, APs(indexAP).Channel_Width_MHz, operatingChannel,primaryChannel] = …
determineMode(cfgMAC.ManagementConfig.InformationElements);
if isempty(operatingChannel)
% Default to scanning channel if operating channel
% cannot be determined.
operatingChannel = rxsim.ChannelNumbers(i);
end
if(rxsim.ChannelNumbers(i)~=primaryChannel)
% Skip the iteration if the current search channel is
% not the primary channel.
APs = APs(1:indexAP-1);
continue;
end
fprintf("<strong>%s beacon detected on channel %d in band %.1f.</strong>n",APs(indexAP).SSID,rxsim.ChannelNumbers(i),rxsim.FrequencyBand);
APs(indexAP).Beacon_Channel = primaryChannel;
APs(indexAP).Operating_Channel = operatingChannel;
if(~strcmp(config,’DSSS, band 2.4′))
APs(indexAP).SNR_dB = res.LLTFSNR;
end
APs(indexAP).MAC_Config = cfgMAC;
APs(indexAP).Offset = res.PacketOffset;
APs(indexAP).Waveform = capturedData;
indexAP = indexAP + 1;
end
end
end
end
tocHello Y’all,
I have a NI USRP coupled with a router’s antenna, and I receive 802.11 wifi signals in the 2.4G band. Then I convert that signal to .mat format and filter channel by channel to extract beacon frames and print their info such as ssid, bssid etc. I use Maltab’s WLAN Beacon Receiver Using Software-Defined Radio tutorial to do the beacon extraction, with config=’OFDM, band 2.4′ . I was able to see the router’s ssid from my phone and laptop, like how it is broadcasting in channel 1, 2.4 band (non-HT data) and its mode is 802.11n. I was also able to see regular spikes of energy every 100 ms when i plotted the spectrogram of channel_1 from the .mat file, indicating there is beacon transmission clearly. I am not able to figure out why the matlab code is not able to extract the beacon frames, i just used the standard matlab tutorial attached above, any help in figuring out the bottleneck in my approach would be really appreciated. Let me also attach the actual code in case if it helps (also my matlab version is R2022b)
fileName="C:WiFi_ProjectWiFi Dataextracted data20240626b_0.5seachData_0channel_1.mat";
rxsim.ReceiveOnSDR = false;
config=’OFDM, band 2.4′;
cbw="CBW20";
cfg = wlanNonHTConfig(ChannelBandwidth=cbw);
displayScope = true;
displayAdditionalInfo=false;
retrieveVendorInfo=true;
if rxsim.ReceiveOnSDR
[frequencyBand,bbSampleRate,chanNumber] = getSimParams(config);
rxsim.FrequencyBand = frequencyBand;
rxsim.RadioSampleRate = bbSampleRate;
rxsim.ChannelNumbers = chanNumber;
rxsim.SDRDeviceName = "Pluto"; % SDR for waveform reception
rxsim.RadioGain = 50;
rxsim.ReceiveAntenna = 1; % Configure to work with only a single antenna
rxsim.CaptureTime = milliseconds(102.4); % Value expected to be of type duration
% Derived Parameters
rxsim.CenterFrequencies = wlanChannelFrequency(rxsim.ChannelNumbers,rxsim.FrequencyBand);
else
rx = load(fileName);
[~,bbSampleRate,~] = getSimParams(config);
rxsim.ChannelNumbers = rx.channels;
rxsim.RadioSampleRate = rx.radioSampleRate;
rxsim.FrequencyBand = rx.band;
% Derived Parameters
rxsim.CaptureTime = seconds(size(rx.capturedWaveforms,1)/rxsim.RadioSampleRate);
end
overSampFac = rxsim.RadioSampleRate/bbSampleRate;
if rxsim.ReceiveOnSDR
sdrReceiver = hSDRReceiver(rxsim.SDRDeviceName);
sdrReceiver.SampleRate = rxsim.RadioSampleRate;
sdrReceiver.Gain = rxsim.RadioGain;
sdrReceiver.ChannelMapping = rxsim.ReceiveAntenna;
sdrReceiver.OutputDataType = "single";
end
APs = struct(…
"SSID",[],"BSSID",[],"Vendor",[],"SNR_dB",[],"Beacon_Channel",[], …
"Operating_Channel",[],"Channel_Width_MHz",[],"Band",[],"Mode",[], …
"MAC_Config",wlanMACFrameConfig,"Waveform",[],"Offset",[]);
indexAP = 1;
%Scan and decode for the specified channels.
tic
for i = 1:length(rxsim.ChannelNumbers)
fprintf("<strong>Scanning channel %d on band %.1f.</strong>n",rxsim.ChannelNumbers(i),rxsim.FrequencyBand);
if rxsim.ReceiveOnSDR
sdrReceiver.CenterFrequency = rxsim.CenterFrequencies(i);
capturedData = capture(sdrReceiver,rxsim.CaptureTime);
else
capturedData = double(rx.capturedWaveforms(:,i));
end
% Display spectrum and spectrogram
if displayScope %#ok<*UNRCH>
scope = spectrumAnalyzer(ViewType="spectrum-and-spectrogram",SampleRate=rxsim.RadioSampleRate,…
TimeSpanSource="property",TimeSpan=seconds(rxsim.CaptureTime));
scope.Title = "Band: " + rxsim.FrequencyBand + " Channel: " + rxsim.ChannelNumbers(i);
scope(capturedData);
end
% Resample the captured data to basesband sample rate for beacon processing
if overSampFac ~= 1
capturedData = resample(capturedData,bbSampleRate,rxsim.RadioSampleRate);
end
searchOffset = 0;
while searchOffset<length(capturedData)
capturedData = capturedData(searchOffset+1:end);
if(strcmp(config,’DSSS, band 2.4′))
[decParams, searchOffset, res, bitsData] = recoverDSSS(capturedData);
else
[decParams, searchOffset, res, bitsData] = recoverNonHTOFDM(capturedData,rxsim);
end
if ~isempty(bitsData)
[cfgMAC, ~, decodeStatus] = wlanMPDUDecode(bitsData,cfg …
,SuppressWarnings=false);
% Print additional information on all successfully recovered packets
if ~decodeStatus && displayAdditionalInfo
payloadSize = floor(length(bitsData)/8);
if(strcmp(config,’DSSS, band 2.4′))
fprintf("Payload Size: %d | Modulation: %s | Data Rate: %s n",payloadSize,decParams.modulation,decParams.dataRate);
else
fprintf("Payload Size: %d | Modulation: %s | Code Rate: %s n",payloadSize,decParams.modulation,decParams.coderate);
end
fprintf("Type: %s | Sub-Type: %s",cfgMAC.getType,cfgMAC.getSubtype);
end
% Extract information about channel from the beacon.
if ~decodeStatus && matches(cfgMAC.FrameType,"Beacon")
% Populate the table with information about the beacon.
if isempty(cfgMAC.ManagementConfig.SSID)
APs(indexAP).SSID = "Hidden";
else
APs(indexAP).SSID = string(cfgMAC.ManagementConfig.SSID);
end
APs(indexAP).BSSID = string(cfgMAC.Address3);
if retrieveVendorInfo
APs(indexAP).Vendor = determineVendor(cfgMAC.Address3);
else
APs(indexAP).Vendor = "Skipped";
end
[APs(indexAP).Mode, APs(indexAP).Channel_Width_MHz, operatingChannel,primaryChannel] = …
determineMode(cfgMAC.ManagementConfig.InformationElements);
if isempty(operatingChannel)
% Default to scanning channel if operating channel
% cannot be determined.
operatingChannel = rxsim.ChannelNumbers(i);
end
if(rxsim.ChannelNumbers(i)~=primaryChannel)
% Skip the iteration if the current search channel is
% not the primary channel.
APs = APs(1:indexAP-1);
continue;
end
fprintf("<strong>%s beacon detected on channel %d in band %.1f.</strong>n",APs(indexAP).SSID,rxsim.ChannelNumbers(i),rxsim.FrequencyBand);
APs(indexAP).Beacon_Channel = primaryChannel;
APs(indexAP).Operating_Channel = operatingChannel;
if(~strcmp(config,’DSSS, band 2.4′))
APs(indexAP).SNR_dB = res.LLTFSNR;
end
APs(indexAP).MAC_Config = cfgMAC;
APs(indexAP).Offset = res.PacketOffset;
APs(indexAP).Waveform = capturedData;
indexAP = indexAP + 1;
end
end
end
end
toc Hello Y’all,
I have a NI USRP coupled with a router’s antenna, and I receive 802.11 wifi signals in the 2.4G band. Then I convert that signal to .mat format and filter channel by channel to extract beacon frames and print their info such as ssid, bssid etc. I use Maltab’s WLAN Beacon Receiver Using Software-Defined Radio tutorial to do the beacon extraction, with config=’OFDM, band 2.4′ . I was able to see the router’s ssid from my phone and laptop, like how it is broadcasting in channel 1, 2.4 band (non-HT data) and its mode is 802.11n. I was also able to see regular spikes of energy every 100 ms when i plotted the spectrogram of channel_1 from the .mat file, indicating there is beacon transmission clearly. I am not able to figure out why the matlab code is not able to extract the beacon frames, i just used the standard matlab tutorial attached above, any help in figuring out the bottleneck in my approach would be really appreciated. Let me also attach the actual code in case if it helps (also my matlab version is R2022b)
fileName="C:WiFi_ProjectWiFi Dataextracted data20240626b_0.5seachData_0channel_1.mat";
rxsim.ReceiveOnSDR = false;
config=’OFDM, band 2.4′;
cbw="CBW20";
cfg = wlanNonHTConfig(ChannelBandwidth=cbw);
displayScope = true;
displayAdditionalInfo=false;
retrieveVendorInfo=true;
if rxsim.ReceiveOnSDR
[frequencyBand,bbSampleRate,chanNumber] = getSimParams(config);
rxsim.FrequencyBand = frequencyBand;
rxsim.RadioSampleRate = bbSampleRate;
rxsim.ChannelNumbers = chanNumber;
rxsim.SDRDeviceName = "Pluto"; % SDR for waveform reception
rxsim.RadioGain = 50;
rxsim.ReceiveAntenna = 1; % Configure to work with only a single antenna
rxsim.CaptureTime = milliseconds(102.4); % Value expected to be of type duration
% Derived Parameters
rxsim.CenterFrequencies = wlanChannelFrequency(rxsim.ChannelNumbers,rxsim.FrequencyBand);
else
rx = load(fileName);
[~,bbSampleRate,~] = getSimParams(config);
rxsim.ChannelNumbers = rx.channels;
rxsim.RadioSampleRate = rx.radioSampleRate;
rxsim.FrequencyBand = rx.band;
% Derived Parameters
rxsim.CaptureTime = seconds(size(rx.capturedWaveforms,1)/rxsim.RadioSampleRate);
end
overSampFac = rxsim.RadioSampleRate/bbSampleRate;
if rxsim.ReceiveOnSDR
sdrReceiver = hSDRReceiver(rxsim.SDRDeviceName);
sdrReceiver.SampleRate = rxsim.RadioSampleRate;
sdrReceiver.Gain = rxsim.RadioGain;
sdrReceiver.ChannelMapping = rxsim.ReceiveAntenna;
sdrReceiver.OutputDataType = "single";
end
APs = struct(…
"SSID",[],"BSSID",[],"Vendor",[],"SNR_dB",[],"Beacon_Channel",[], …
"Operating_Channel",[],"Channel_Width_MHz",[],"Band",[],"Mode",[], …
"MAC_Config",wlanMACFrameConfig,"Waveform",[],"Offset",[]);
indexAP = 1;
%Scan and decode for the specified channels.
tic
for i = 1:length(rxsim.ChannelNumbers)
fprintf("<strong>Scanning channel %d on band %.1f.</strong>n",rxsim.ChannelNumbers(i),rxsim.FrequencyBand);
if rxsim.ReceiveOnSDR
sdrReceiver.CenterFrequency = rxsim.CenterFrequencies(i);
capturedData = capture(sdrReceiver,rxsim.CaptureTime);
else
capturedData = double(rx.capturedWaveforms(:,i));
end
% Display spectrum and spectrogram
if displayScope %#ok<*UNRCH>
scope = spectrumAnalyzer(ViewType="spectrum-and-spectrogram",SampleRate=rxsim.RadioSampleRate,…
TimeSpanSource="property",TimeSpan=seconds(rxsim.CaptureTime));
scope.Title = "Band: " + rxsim.FrequencyBand + " Channel: " + rxsim.ChannelNumbers(i);
scope(capturedData);
end
% Resample the captured data to basesband sample rate for beacon processing
if overSampFac ~= 1
capturedData = resample(capturedData,bbSampleRate,rxsim.RadioSampleRate);
end
searchOffset = 0;
while searchOffset<length(capturedData)
capturedData = capturedData(searchOffset+1:end);
if(strcmp(config,’DSSS, band 2.4′))
[decParams, searchOffset, res, bitsData] = recoverDSSS(capturedData);
else
[decParams, searchOffset, res, bitsData] = recoverNonHTOFDM(capturedData,rxsim);
end
if ~isempty(bitsData)
[cfgMAC, ~, decodeStatus] = wlanMPDUDecode(bitsData,cfg …
,SuppressWarnings=false);
% Print additional information on all successfully recovered packets
if ~decodeStatus && displayAdditionalInfo
payloadSize = floor(length(bitsData)/8);
if(strcmp(config,’DSSS, band 2.4′))
fprintf("Payload Size: %d | Modulation: %s | Data Rate: %s n",payloadSize,decParams.modulation,decParams.dataRate);
else
fprintf("Payload Size: %d | Modulation: %s | Code Rate: %s n",payloadSize,decParams.modulation,decParams.coderate);
end
fprintf("Type: %s | Sub-Type: %s",cfgMAC.getType,cfgMAC.getSubtype);
end
% Extract information about channel from the beacon.
if ~decodeStatus && matches(cfgMAC.FrameType,"Beacon")
% Populate the table with information about the beacon.
if isempty(cfgMAC.ManagementConfig.SSID)
APs(indexAP).SSID = "Hidden";
else
APs(indexAP).SSID = string(cfgMAC.ManagementConfig.SSID);
end
APs(indexAP).BSSID = string(cfgMAC.Address3);
if retrieveVendorInfo
APs(indexAP).Vendor = determineVendor(cfgMAC.Address3);
else
APs(indexAP).Vendor = "Skipped";
end
[APs(indexAP).Mode, APs(indexAP).Channel_Width_MHz, operatingChannel,primaryChannel] = …
determineMode(cfgMAC.ManagementConfig.InformationElements);
if isempty(operatingChannel)
% Default to scanning channel if operating channel
% cannot be determined.
operatingChannel = rxsim.ChannelNumbers(i);
end
if(rxsim.ChannelNumbers(i)~=primaryChannel)
% Skip the iteration if the current search channel is
% not the primary channel.
APs = APs(1:indexAP-1);
continue;
end
fprintf("<strong>%s beacon detected on channel %d in band %.1f.</strong>n",APs(indexAP).SSID,rxsim.ChannelNumbers(i),rxsim.FrequencyBand);
APs(indexAP).Beacon_Channel = primaryChannel;
APs(indexAP).Operating_Channel = operatingChannel;
if(~strcmp(config,’DSSS, band 2.4′))
APs(indexAP).SNR_dB = res.LLTFSNR;
end
APs(indexAP).MAC_Config = cfgMAC;
APs(indexAP).Offset = res.PacketOffset;
APs(indexAP).Waveform = capturedData;
indexAP = indexAP + 1;
end
end
end
end
toc 802.11 packet extraction, beacon frames extraction MATLAB Answers — New Questions