Skip to content

Commit

Permalink
rssi testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Aug 6, 2023
1 parent 45a73c5 commit fd0f9b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/WBTxRx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
Expand Down
29 changes: 12 additions & 17 deletions src/pcap_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -114,9 +115,10 @@ struct ParsedRxPcapPacket {
};
static std::string all_rssi_to_string(const std::vector<RssiForAntenna>& all_rssi){
std::stringstream ss;
ss<<"RSSI for antenna:";
int idx=0;
for(const auto& rssiForAntenna:all_rssi){
ss<<"RssiForAntenna"<<idx<<"{"<<(int)rssiForAntenna.rssi<<"}\n";
ss<<" {"<<(int)rssiForAntenna.antennaIdx<<":"<<(int)rssiForAntenna.rssi<<"}";
idx++;
}
return ss.str();
Expand All @@ -126,11 +128,14 @@ static std::string all_rssi_to_string(const std::vector<RssiForAntenna>& all_rss
//RssiForAntenna1{10}
//RssiForAntenna2{-18}
//Now this doesn't make sense, so this helper should fix it
static std::optional<int8_t> get_best_rssi_of_card(const std::vector<RssiForAntenna>& all_rssi){
static std::optional<int8_t> get_best_rssi_of_card(const std::vector<RssiForAntenna>& 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;
}
Expand All @@ -141,7 +146,7 @@ static std::optional<int8_t> get_best_rssi_of_card(const std::vector<RssiForAnte
// Returns std::nullopt if radiotap was unable to parse the header
// else return the *parsed information*
// To avoid confusion it might help to treat this method as a big black Box :)
static std::optional<ParsedRxPcapPacket> processReceivedPcapPacket(const pcap_pkthdr &hdr, const uint8_t *pkt,const bool fixup_rssi_rtl8812au) {
static std::optional<ParsedRxPcapPacket> processReceivedPcapPacket(const pcap_pkthdr &hdr, const uint8_t *pkt) {
int pktlen = hdr.caplen;
//
//RadiotapHelper::debugRadiotapHeader(pkt,pktlen);
Expand All @@ -165,7 +170,7 @@ static std::optional<ParsedRxPcapPacket> processReceivedPcapPacket(const pcap_pk
std::optional<uint16_t> channel_width=std::nullopt;
std::optional<int> 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<RssiForAntenna> allAntennaValues;
while (ret == 0) {
Expand All @@ -183,17 +188,7 @@ static std::optional<ParsedRxPcapPacket> 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:
Expand Down

0 comments on commit fd0f9b5

Please sign in to comment.