From fd0f9b50ac629abb138e4a7bb115ad4321900051 Mon Sep 17 00:00:00 2001 From: consti10 Date: Mon, 7 Aug 2023 01:57:16 +0200 Subject: [PATCH] rssi testing --- src/WBTxRx.cpp | 8 ++++---- src/pcap_helper.hpp | 29 ++++++++++++----------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/WBTxRx.cpp b/src/WBTxRx.cpp index 7f598458..91c1becc 100644 --- a/src/WBTxRx.cpp +++ b/src/WBTxRx.cpp @@ -237,7 +237,7 @@ void WBTxRx::on_new_packet(const uint8_t wlan_idx, const pcap_pkthdr &hdr, if(m_options.log_all_received_packets){ m_console->debug("Got packet {} {}",wlan_idx,hdr.len); } - const auto parsedPacket = wifibroadcast::pcap_helper::processReceivedPcapPacket(hdr, pkt, m_options.rtl8812au_rssi_fixup); + const auto parsedPacket = wifibroadcast::pcap_helper::processReceivedPcapPacket(hdr, pkt); if (parsedPacket == std::nullopt) { if(m_options.advanced_debugging_rx){ m_console->warn("Discarding packet due to pcap parsing error!"); @@ -291,7 +291,7 @@ void WBTxRx::on_new_packet(const uint8_t wlan_idx, const pcap_pkthdr &hdr, // Rare case - when multiple RX-es are used, we might get a packet we sent on this air / gnd unit // And on AR9271, there is a bug where the card itself gives injected packets back to us if(unique_air_gnd_id==unique_tx_id){ - // Packet originated from this unit + // Packet (most likely) originated from this unit if(m_options.advanced_debugging_rx){ m_console->debug("Got packet back on rx {} that was injected (bug or multi rx) {}",wlan_idx,rx_iee80211_hdr_openhd.debug_unique_ids()); } @@ -361,8 +361,8 @@ void WBTxRx::on_new_packet(const uint8_t wlan_idx, const pcap_pkthdr &hdr, // We only use known "good" packets for those stats. auto &this_wifi_card_stats = m_rx_stats_per_card.at(wlan_idx); auto& rssi_for_this_card=this_wifi_card_stats.rssi_for_wifi_card; - //m_console->debug("{}",all_rssi_to_string(parsedPacket->allAntennaValues)); - const auto best_rssi=wifibroadcast::pcap_helper::get_best_rssi_of_card(parsedPacket->allAntennaValues); + m_console->debug("{}",all_rssi_to_string(parsedPacket->allAntennaValues)); + const auto best_rssi=wifibroadcast::pcap_helper::get_best_rssi_of_card(parsedPacket->allAntennaValues,m_options.rtl8812au_rssi_fixup); //m_console->debug("best_rssi:{}",(int)best_rssi); if(best_rssi.has_value()){ rssi_for_this_card.addRSSI(best_rssi.value()); diff --git a/src/pcap_helper.hpp b/src/pcap_helper.hpp index b3266632..50232360 100644 --- a/src/pcap_helper.hpp +++ b/src/pcap_helper.hpp @@ -93,8 +93,9 @@ static pcap_t *open_pcap_tx(const std::string &wlan) { } struct RssiForAntenna { - // which antenna the value refers to - const uint8_t antennaIdx; + // which antenna the value refers to, + // or -1 this dgm value came before a IEEE80211_RADIOTAP_ANTENNA field and the antenna idx is therefore unknown + const int8_t antennaIdx; // https://www.radiotap.org/fields/Antenna%20signal.html const int8_t rssi; }; @@ -114,9 +115,10 @@ struct ParsedRxPcapPacket { }; static std::string all_rssi_to_string(const std::vector& all_rssi){ std::stringstream ss; + ss<<"RSSI for antenna:"; int idx=0; for(const auto& rssiForAntenna:all_rssi){ - ss<<"RssiForAntenna"<& all_rss //RssiForAntenna1{10} //RssiForAntenna2{-18} //Now this doesn't make sense, so this helper should fix it -static std::optional get_best_rssi_of_card(const std::vector& all_rssi){ +static std::optional get_best_rssi_of_card(const std::vector& all_rssi,const bool fixup_rssi_rtl8812au){ if(all_rssi.empty())return std::nullopt; // best rssi == highest value int8_t highest_value=INT8_MIN; for(const auto& rssiForAntenna:all_rssi){ + if(rssiForAntenna.antennaIdx==-1){ + continue ; + } if(rssiForAntenna.rssi>highest_value){ highest_value=rssiForAntenna.rssi; } @@ -141,7 +146,7 @@ static std::optional get_best_rssi_of_card(const std::vector processReceivedPcapPacket(const pcap_pkthdr &hdr, const uint8_t *pkt,const bool fixup_rssi_rtl8812au) { +static std::optional processReceivedPcapPacket(const pcap_pkthdr &hdr, const uint8_t *pkt) { int pktlen = hdr.caplen; // //RadiotapHelper::debugRadiotapHeader(pkt,pktlen); @@ -165,7 +170,7 @@ static std::optional processReceivedPcapPacket(const pcap_pk std::optional channel_width=std::nullopt; std::optional signal_quality=std::nullopt; - uint8_t currentAntenna = 0; + int8_t currentAntenna = -1; // not confirmed yet, but one pcap packet might include stats for multiple antennas std::vector allAntennaValues; while (ret == 0) { @@ -183,17 +188,7 @@ static std::optional processReceivedPcapPacket(const pcap_pk case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:{ int8_t value; std::memcpy(&value,iterator.this_arg,1); - //const int8_t value=*(int8_t*)iterator.this_arg; - if(fixup_rssi_rtl8812au){ - // Dirty fixup for rtl8812au: Throw out the first reported value - if(is_first_reported_antenna_value){ - is_first_reported_antenna_value= false; - }else{ - allAntennaValues.push_back({currentAntenna,value}); - } - }else{ - allAntennaValues.push_back({currentAntenna,value}); - } + allAntennaValues.push_back({currentAntenna,value}); } break; case IEEE80211_RADIOTAP_FLAGS: