From e8fa8c79ab8ae7791c2bc42a4404d70c54e1f534 Mon Sep 17 00:00:00 2001 From: Nicola Baldo Date: Thu, 13 Aug 2009 13:39:14 +0200 Subject: [PATCH] bug 644: make sure we set standard and frequency correctly in radiotap output --- src/common/pcap-writer.cc | 52 ++++++++++++++++++++----------- src/common/pcap-writer.h | 4 ++- src/devices/wifi/wifi-phy.cc | 8 ++--- src/devices/wifi/wifi-phy.h | 8 ++--- src/devices/wifi/yans-wifi-phy.cc | 4 +-- src/helper/yans-wifi-helper.cc | 8 ++--- 6 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/common/pcap-writer.cc b/src/common/pcap-writer.cc index 273f1407f..c69cb223e 100644 --- a/src/common/pcap-writer.cc +++ b/src/common/pcap-writer.cc @@ -196,7 +196,7 @@ PcapWriter::WritePacket (Ptr packet) } -void PcapWriter::WriteWifiMonitorPacket(Ptr packet, uint16_t channelFreqMhz, +void PcapWriter::WriteWifiMonitorPacket(Ptr packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble, bool isTx, double signalDbm, double noiseDbm) { @@ -288,10 +288,8 @@ void PcapWriter::WriteWifiMonitorPacket(Ptr packet, uint16_t chann Write32(PRISM_DID_CHANNEL); Write16(PRISM_STATUS_PRESENT); - Write16(PRISM_ITEM_LENGTH); - // convert from frequency to channel number. This conversion is - // correct only for IEEE 802.11b/g channels 1-13. - Write32((2437 - 2407) / 5); + Write16(PRISM_ITEM_LENGTH); + Write32((uint32_t) channelNumber); Write32(PRISM_DID_RSSI); Write16(PRISM_STATUS_PRESENT); @@ -372,14 +370,18 @@ void PcapWriter::WriteWifiMonitorPacket(Ptr packet, uint16_t chann #define RADIOTAP_FLAG_DATAPAD 0x20 #define RADIOTAP_FLAG_BADFCS 0x40 -#define RADIOTAP_CHANNEL_TURBO 0x0010 -#define RADIOTAP_CHANNEL_CCK 0x0020 -#define RADIOTAP_CHANNEL_OFDM 0x0040 -#define RADIOTAP_CHANNEL_2GHZ 0x0080 -#define RADIOTAP_CHANNEL_5GHZ 0x0100 -#define RADIOTAP_CHANNEL_PASSIVE 0x0200 -#define RADIOTAP_CHANNEL_DYN 0x0400 -#define RADIOTAP_CHANNEL_GFSK 0x0800 +#define RADIOTAP_CHANNEL_TURBO 0x0010 +#define RADIOTAP_CHANNEL_CCK 0x0020 +#define RADIOTAP_CHANNEL_OFDM 0x0040 +#define RADIOTAP_CHANNEL_2GHZ 0x0080 +#define RADIOTAP_CHANNEL_5GHZ 0x0100 +#define RADIOTAP_CHANNEL_PASSIVE 0x0200 +#define RADIOTAP_CHANNEL_DYN_CCK_OFDM 0x0400 +#define RADIOTAP_CHANNEL_GFSK 0x0800 +#define RADIOTAP_CHANNEL_GSM 0x1000 +#define RADIOTAP_CHANNEL_STATIC_TURBO 0x2000 +#define RADIOTAP_CHANNEL_HALF_RATE 0x4000 +#define RADIOTAP_CHANNEL_QUARTER_RATE 0x8000 #define RADIOTAP_RX_PRESENT (RADIOTAP_TSFT | RADIOTAP_FLAGS | RADIOTAP_RATE | RADIOTAP_CHANNEL | RADIOTAP_DBM_ANTSIGNAL | RADIOTAP_DBM_ANTNOISE) #define RADIOTAP_RX_LENGTH (8+8+1+1+2+2+1+1) @@ -433,12 +435,24 @@ void PcapWriter::WriteWifiMonitorPacket(Ptr packet, uint16_t chann Write8(rate); - Write16((uint16_t) 2437); - - // we might want to make this setting depend on the WifiMode and - // on the ChannelFrequency at some time in the future. But for now - // I think a fixed setting is more than enough for most purposes. - Write16(RADIOTAP_CHANNEL_OFDM | RADIOTAP_CHANNEL_2GHZ); + Write16(channelFreqMhz); + + uint16_t channelFlags; + if (channelFreqMhz < 2500) + { + // TODO: when 802.11g WifiModes will be implemented + // we will need to check dinamically whether channelFlags + // needs to be set to RADIOTAP_CHANNEL_CCK, + // RADIOTAP_CHANNEL_DYN or RADIOTAP_CHANNEL_OFDM. + channelFlags = RADIOTAP_CHANNEL_2GHZ | RADIOTAP_CHANNEL_CCK; + } + else + { + // TODO: we should handle correctly the case of half rate + // (10 MHz channel) and quarter rate (5 Mhz channel). + channelFlags = RADIOTAP_CHANNEL_5GHZ | RADIOTAP_CHANNEL_OFDM; + } + Write16(channelFlags); if (!isTx) { diff --git a/src/common/pcap-writer.h b/src/common/pcap-writer.h index b688e6001..91a878cdc 100644 --- a/src/common/pcap-writer.h +++ b/src/common/pcap-writer.h @@ -117,6 +117,8 @@ public: * transmitted. This is because it is possible to have the receiver * tuned on a given channel and still to be able to receive packets * on a nearby channel. + * @param channelNumber the channel number, as defined by the + * IEEE 802.11 standard. * @param rate the PHY data rate in units of 500kbps (i.e., the same * units used both for the radiotap and for the prism header) * @param isShortPreamble true if short preamble is used, false otherwise @@ -125,7 +127,7 @@ public: * @param signalDbm signal power in dBm * @param noiseDbm noise power in dBm */ - void WriteWifiMonitorPacket(Ptr packet, uint16_t channelFreqMhz, + void WriteWifiMonitorPacket(Ptr packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble, bool isTx, double signalDbm, double noiseDbm); diff --git a/src/devices/wifi/wifi-phy.cc b/src/devices/wifi/wifi-phy.cc index 949708f8a..9de83f3c6 100644 --- a/src/devices/wifi/wifi-phy.cc +++ b/src/devices/wifi/wifi-phy.cc @@ -205,15 +205,15 @@ WifiPhy::NotifyRxDrop (Ptr packet) } void -WifiPhy::NotifyPromiscSniffRx (Ptr packet, uint16_t channelFreqMhz, uint32_t rate, bool isShortPreamble, double signalDbm, double noiseDbm) +WifiPhy::NotifyPromiscSniffRx (Ptr packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble, double signalDbm, double noiseDbm) { - m_phyPromiscSniffRxTrace (packet, channelFreqMhz, rate, isShortPreamble, signalDbm, noiseDbm); + m_phyPromiscSniffRxTrace (packet, channelFreqMhz, channelNumber, rate, isShortPreamble, signalDbm, noiseDbm); } void -WifiPhy::NotifyPromiscSniffTx (Ptr packet, uint16_t channelFreqMhz, uint32_t rate, bool isShortPreamble) +WifiPhy::NotifyPromiscSniffTx (Ptr packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble) { - m_phyPromiscSniffTxTrace (packet, channelFreqMhz, rate, isShortPreamble); + m_phyPromiscSniffTxTrace (packet, channelFreqMhz, channelNumber, rate, isShortPreamble); } WifiMode diff --git a/src/devices/wifi/wifi-phy.h b/src/devices/wifi/wifi-phy.h index f17adac2c..b9519a812 100644 --- a/src/devices/wifi/wifi-phy.h +++ b/src/devices/wifi/wifi-phy.h @@ -341,7 +341,7 @@ public: * @param signalDbm signal power in dBm * @param noiseDbm noise power in dBm */ - void NotifyPromiscSniffRx (Ptr packet, uint16_t channelFreqMhz, uint32_t rate, bool isShortPreamble, + void NotifyPromiscSniffRx (Ptr packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble, double signalDbm, double noiseDbm); /** @@ -361,7 +361,7 @@ public: * units used both for the radiotap and for the prism header) * @param isShortPreamble true if short preamble is used, false otherwise */ - void NotifyPromiscSniffTx (Ptr packet, uint16_t channelFreqMhz, uint32_t rate, bool isShortPreamble); + void NotifyPromiscSniffTx (Ptr packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble); private: @@ -422,7 +422,7 @@ private: * * \see class CallBackTraceSource */ - TracedCallback, uint16_t, uint32_t, bool, double, double> m_phyPromiscSniffRxTrace; + TracedCallback, uint16_t, uint16_t, uint32_t, bool, double, double> m_phyPromiscSniffRxTrace; /** * A trace source that emulates a wifi device in monitor mode @@ -434,7 +434,7 @@ private: * * \see class CallBackTraceSource */ - TracedCallback, uint16_t, uint32_t, bool> m_phyPromiscSniffTxTrace; + TracedCallback, uint16_t, uint16_t, uint32_t, bool> m_phyPromiscSniffTxTrace; }; diff --git a/src/devices/wifi/yans-wifi-phy.cc b/src/devices/wifi/yans-wifi-phy.cc index 75024b1c2..6d2a36867 100644 --- a/src/devices/wifi/yans-wifi-phy.cc +++ b/src/devices/wifi/yans-wifi-phy.cc @@ -451,7 +451,7 @@ YansWifiPhy::SendPacket (Ptr packet, WifiMode txMode, WifiPreamble NotifyTxBegin (packet); uint32_t dataRate500KbpsUnits = txMode.GetDataRate () / 500000; bool isShortPreamble = (WIFI_PREAMBLE_SHORT == preamble); - NotifyPromiscSniffTx (packet, (uint16_t)GetChannelFrequencyMhz(), dataRate500KbpsUnits, isShortPreamble); + NotifyPromiscSniffTx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, isShortPreamble); m_state->SwitchToTx (txDuration, packet, txMode, preamble, txPower); m_channel->Send (this, packet, GetPowerDbm (txPower) + m_txGainDb, txMode, preamble); } @@ -657,7 +657,7 @@ YansWifiPhy::EndSync (Ptr packet, Ptr event) bool isShortPreamble = (WIFI_PREAMBLE_SHORT == event->GetPreambleType ()); double signalDbm = RatioToDb (event->GetRxPowerW ()) + 30; double noiseDbm = RatioToDb(event->GetRxPowerW() / snrPer.snr) - GetRxNoiseFigure() + 30 ; - NotifyPromiscSniffRx (packet, (uint16_t)GetChannelFrequencyMhz(), dataRate500KbpsUnits, isShortPreamble, signalDbm, noiseDbm); + NotifyPromiscSniffRx (packet, (uint16_t)GetChannelFrequencyMhz (), GetChannelNumber (), dataRate500KbpsUnits, isShortPreamble, signalDbm, noiseDbm); m_state->SwitchFromSyncEndOk (packet, snrPer.snr, event->GetPayloadMode (), event->GetPreambleType ()); } else diff --git a/src/helper/yans-wifi-helper.cc b/src/helper/yans-wifi-helper.cc index 9af1ed6b2..5b5980986 100644 --- a/src/helper/yans-wifi-helper.cc +++ b/src/helper/yans-wifi-helper.cc @@ -32,18 +32,18 @@ namespace ns3 { -static void PcapSniffTxEvent (Ptr writer, Ptr packet, uint16_t channelFreqMhz, +static void PcapSniffTxEvent (Ptr writer, Ptr packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble) { const double unusedValue = 0; - writer->WriteWifiMonitorPacket(packet, channelFreqMhz, rate, isShortPreamble, true, unusedValue, unusedValue); + writer->WriteWifiMonitorPacket(packet, channelFreqMhz, channelNumber, rate, isShortPreamble, true, unusedValue, unusedValue); } -static void PcapSniffRxEvent (Ptr writer, Ptr packet, uint16_t channelFreqMhz, +static void PcapSniffRxEvent (Ptr writer, Ptr packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble, double signalDbm, double noiseDbm) { - writer->WriteWifiMonitorPacket(packet, channelFreqMhz, rate, isShortPreamble, false, signalDbm, noiseDbm); + writer->WriteWifiMonitorPacket(packet, channelFreqMhz, channelNumber, rate, isShortPreamble, false, signalDbm, noiseDbm); }