Skip to content

Commit

Permalink
refactor out wifibroadcast::WifiCard
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Sep 13, 2023
1 parent 3b339cd commit b59d75c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 30 deletions.
4 changes: 2 additions & 2 deletions executables/example_hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ int main(int argc, char *const *argv) {
std::cout<<"Running as "<<(is_air ? "Air" : "Ground")<<" on card "<<card<<"\n";

// Create the Tx-RX
std::vector<WBTxRx::WifiCard> cards;
WBTxRx::WifiCard tmp_card{card,1};
std::vector<wifibroadcast::WifiCard> cards;
wifibroadcast::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.pcap_rx_set_direction = true;
Expand Down
4 changes: 2 additions & 2 deletions executables/example_pollute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ int main(int argc, char *const *argv) {
}

// Create the Tx-RX
std::vector<WBTxRx::WifiCard> cards;
WBTxRx::WifiCard tmp_card{card,1};
std::vector<wifibroadcast::WifiCard> cards;
wifibroadcast::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
options_txrx.pcap_rx_set_direction = true;
Expand Down
4 changes: 2 additions & 2 deletions executables/example_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ int main(int argc, char *const *argv) {
auto console=wifibroadcast::log::create_or_get("main");
console->info("Running as {} on card {}",(is_air ? "Air" : "Ground"),card);

std::vector<WBTxRx::WifiCard> cards;
WBTxRx::WifiCard tmp_card{card,1};
std::vector<wifibroadcast::WifiCard> cards;
wifibroadcast::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
//options_txrx.pcap_rx_set_direction= false;
Expand Down
4 changes: 2 additions & 2 deletions executables/injection_rate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ int main(int argc, char *const *argv) {
std::cout<<"Running on card "<<card<<"\n";

// Create the Tx-RX
std::vector<WBTxRx::WifiCard> cards;
WBTxRx::WifiCard tmp_card{card,1};
std::vector<wifibroadcast::WifiCard> cards;
wifibroadcast::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
//options_txrx.pcap_rx_set_direction= false;
Expand Down
4 changes: 2 additions & 2 deletions executables/test_txrx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ int main(int argc, char *const *argv) {
}
}

std::vector<WBTxRx::WifiCard> cards;
WBTxRx::WifiCard tmp_card{card,1};
std::vector<wifibroadcast::WifiCard> cards;
wifibroadcast::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
//options_txrx.pcap_rx_set_direction= false;
Expand Down
8 changes: 4 additions & 4 deletions src/WBTxRx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
#include "pcap_helper.hpp"
#include "raw_socket_helper.hpp"

WBTxRx::WBTxRx(std::vector<WifiCard> wifi_cards1,Options options1,std::shared_ptr<RadiotapHeaderHolder> session_key_radiotap_header)
WBTxRx::WBTxRx(std::vector<wifibroadcast::WifiCard> wifi_cards1,Options options1,std::shared_ptr<RadiotapHeaderHolder> session_key_radiotap_header)
: m_options(options1),
m_wifi_cards(std::move(wifi_cards1)),
m_session_key_radiotap_header(std::move(session_key_radiotap_header))
{
assert(!m_wifi_cards.empty());
m_console=wifibroadcast::log::create_or_get("WBTxRx");
m_console->debug("{}", options_to_string(get_wifi_card_names(),m_options));
m_console->debug("[{}]", options_to_string(wifibroadcast::get_wifi_card_names(m_wifi_cards),m_options));
// Common error - not run as root
if(!SchedulingHelper::check_root()){
std::cerr<<"wifibroadcast needs root"<<std::endl;
Expand Down Expand Up @@ -502,7 +502,7 @@ void WBTxRx::on_new_packet(const uint8_t wlan_idx,const uint8_t *pkt,const int p
auto opt_minmaxavg= this_wifi_card_calc.card_rssi.add_and_recalculate_if_needed(rssi);
if(opt_minmaxavg.has_value()){
// See below for how this value is calculated on rtl8812au
if(m_wifi_cards[wlan_idx].type!=WIFI_CARD_TYPE_RTL8812AU){
if(m_wifi_cards[wlan_idx].type!=wifibroadcast::WIFI_CARD_TYPE_RTL8812AU){
this_wifi_card_stats.card_dbm=opt_minmaxavg.value().avg;
}
if(m_options.debug_rssi>=1){
Expand Down Expand Up @@ -530,7 +530,7 @@ void WBTxRx::on_new_packet(const uint8_t wlan_idx,const uint8_t *pkt,const int p
}
}
}
if(m_wifi_cards[wlan_idx].type==WIFI_CARD_TYPE_RTL8812AU){
if(m_wifi_cards[wlan_idx].type==wifibroadcast::WIFI_CARD_TYPE_RTL8812AU){
// RTL8812AU BUG - general value cannot be used, use max of antennas instead
this_wifi_card_stats.card_dbm=std::max(this_wifi_card_stats.antenna1_dbm,this_wifi_card_stats.antenna2_dbm);
}
Expand Down
24 changes: 8 additions & 16 deletions src/WBTxRx.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "SignalQualityAccumulator.hpp"
#include "HelperSources/UINT16SeqNrHelper.hpp"
#include "HelperSources/UINT64SeqNrHelper.hpp"
#include "WiFiCard.h"

/**
* This class exists to provide a clean, working interface to create a
Expand Down Expand Up @@ -96,14 +97,12 @@ class WBTxRx {
// a tx error hint is thrown if injecting the packet takes longer than max_sane_injection_time
std::chrono::milliseconds max_sane_injection_time=std::chrono::milliseconds(5);
};
// RTL8812AU driver requires a quirk regarding rssi
static constexpr auto WIFI_CARD_TYPE_UNKNOWN=0;
static constexpr auto WIFI_CARD_TYPE_RTL8812AU=1;
struct WifiCard{
std::string name;
int type;
};
explicit WBTxRx(std::vector<WifiCard> wifi_cards,Options options1,std::shared_ptr<RadiotapHeaderHolder> session_key_radiotap_header);
/**
* @param wifi_cards card(s) used for tx / rx
* @param options1 see documentation in options string
* @param session_key_radiotap_header radiotap header used when injecting session key packets
*/
explicit WBTxRx(std::vector<wifibroadcast::WifiCard> wifi_cards,Options options1,std::shared_ptr<RadiotapHeaderHolder> session_key_radiotap_header);
WBTxRx(const WBTxRx &) = delete;
WBTxRx &operator=(const WBTxRx &) = delete;
~WBTxRx();
Expand Down Expand Up @@ -255,14 +254,7 @@ class WBTxRx {
const Options m_options;
std::shared_ptr<spdlog::logger> m_console;
std::shared_ptr<RadiotapHeaderHolder> m_session_key_radiotap_header;
const std::vector<WifiCard> m_wifi_cards;
std::vector<std::string> get_wifi_card_names(){
std::vector<std::string> ret;
for(const auto& card:m_wifi_cards){
ret.push_back(card.name);
}
return ret;
}
const std::vector<wifibroadcast::WifiCard> m_wifi_cards;
std::chrono::steady_clock::time_point m_session_key_next_announce_ts{};
Ieee80211HeaderOpenHD m_tx_ieee80211_hdr_openhd{};
std::array<uint8_t,PCAP_MAX_PACKET_SIZE> m_tx_packet_buff{};
Expand Down
32 changes: 32 additions & 0 deletions src/WiFiCard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by consti10 on 13.09.23.
//

#ifndef WIFIBROADCAST_WIFICARD_H
#define WIFIBROADCAST_WIFICARD_H

#include <string>
#include <sstream>
#include <vector>

namespace wifibroadcast{
// In OpenHD, we have a quite extensive WiFiCard abstraction -
// in wifibroadcast, we are a bit simpler
// (But we require info for quirks)
// RTL8812AU driver requires a quirk regarding rssi
static constexpr auto WIFI_CARD_TYPE_UNKNOWN=0;
static constexpr auto WIFI_CARD_TYPE_RTL8812AU=1;
struct WifiCard{
std::string name;
int type;
};
static std::vector<std::string> get_wifi_card_names(const std::vector<WifiCard>& cards){
std::vector<std::string> ret;
for(const auto& card:cards){
ret.push_back(card.name);
}
return ret;
}
}

#endif // WIFIBROADCAST_WIFICARD_H

0 comments on commit b59d75c

Please sign in to comment.