From aab4e316c1dcbf750fc499563028eca7a22fd99a Mon Sep 17 00:00:00 2001 From: consti10 Date: Wed, 16 Aug 2023 23:50:51 +0200 Subject: [PATCH] for now, add tx without pcap option --- src/WBTxRx.cpp | 36 ++++++++++++++++++++++++++---------- src/WBTxRx.h | 3 +++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/WBTxRx.cpp b/src/WBTxRx.cpp index d96d0185..bb3ab4cb 100644 --- a/src/WBTxRx.cpp +++ b/src/WBTxRx.cpp @@ -45,19 +45,24 @@ WBTxRx::WBTxRx(std::vector wifi_cards1,Options options1) for(int i=0;idebug("pcap_setdirection() returned {}",ret); } } - m_pcap_handles.push_back(pcapTxRx); - auto fd = pcap_get_selectable_fd(pcapTxRx.rx); - m_receive_pollfds[i].fd = fd; + auto rx_pollfd = pcap_get_selectable_fd(pcapTxRx.rx); + m_receive_pollfds[i].fd = rx_pollfd; m_receive_pollfds[i].events = POLLIN; + // TX part - using raw socket or pcap + if(m_options.tx_without_pcap){ + pcapTxRx.tx_sockfd= openWifiInterfaceAsTxRawSocket(wifi_card.name); + }else{ + pcapTxRx.tx=wifibroadcast::pcap_helper::open_pcap_tx(wifi_card.name); + } + m_pcap_handles.push_back(pcapTxRx); } wb::KeyPairTxRx keypair{}; if(m_options.secure_keypair.has_value()){ @@ -86,8 +91,15 @@ WBTxRx::~WBTxRx() { pcapTxRx.rx= nullptr; pcapTxRx.tx= nullptr; }else{ - pcap_close(pcapTxRx.rx); - pcap_close(pcapTxRx.tx); + if(pcapTxRx.rx!= nullptr){ + pcap_close(pcapTxRx.rx); + } + if(pcapTxRx.tx!= nullptr){ + pcap_close(pcapTxRx.tx); + } + if(pcapTxRx.tx_sockfd!=-1){ + close(pcapTxRx.tx_sockfd); + } } //pcap_close(pcapTxRx.rx); //pcap_close(pcapTxRx.tx); @@ -171,10 +183,14 @@ void WBTxRx::tx_inject_packet(const uint8_t stream_index,const uint8_t* data, in int WBTxRx::inject_radiotap_packet(int card_index,const uint8_t* packet_buff, int packet_size) { // inject via pcap + int len_injected=0; // we inject the packet on whatever card has the highest rx rssi right now - //pcap_t *tx= m_pcap_handles[card_index].tx; - //const auto len_injected=pcap_inject(tx, packet_buff, packet_size); - const auto len_injected=write(m_receive_pollfds[card_index].fd,packet_buff,packet_size); + if(m_options.tx_without_pcap){ + len_injected=(int)write(m_pcap_handles[card_index].tx_sockfd,packet_buff,packet_size); + }else{ + len_injected=pcap_inject(m_pcap_handles[card_index].tx, packet_buff, packet_size); + //const auto len_injected=write(m_receive_pollfds[card_index].fd,packet_buff,packet_size); + } if (len_injected != (int) packet_size) { // This basically should never fail - if the tx queue is full, pcap seems to wait ?! //m_console->warn("pcap -unable to inject packet size:{} ret:{} err:[{}]",packet_size, len_injected, pcap_geterr(tx)); diff --git a/src/WBTxRx.h b/src/WBTxRx.h index 05239200..e5ec8087 100644 --- a/src/WBTxRx.h +++ b/src/WBTxRx.h @@ -91,6 +91,8 @@ class WBTxRx { bool debug_multi_rx_packets_variance= false; // This is only for debugging / testing, inject packets with a fixed MAC - won't be received as valid packets by another rx instance bool enable_non_openhd_mode= false; + // tmp + bool tx_without_pcap=false; }; // RTL8812AU driver requires a quirk regarding rssi static constexpr auto WIFI_CARD_TYPE_UNKNOWN=0; @@ -290,6 +292,7 @@ class WBTxRx { struct PcapTxRx{ pcap_t *tx= nullptr; pcap_t *rx= nullptr; + int tx_sockfd=-1; }; std::vector m_pcap_handles; // temporary