Skip to content

Commit

Permalink
for now, add tx without pcap option
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Aug 16, 2023
1 parent 1b12caa commit aab4e31
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/WBTxRx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,24 @@ WBTxRx::WBTxRx(std::vector<WifiCard> wifi_cards1,Options options1)
for(int i=0;i<m_wifi_cards.size();i++){
auto wifi_card=m_wifi_cards[i];
PcapTxRx pcapTxRx{};
// RX part - using pcap
pcapTxRx.rx=wifibroadcast::pcap_helper::open_pcap_rx(wifi_card.name);
//pcapTxRx.tx=pcapTxRx.rx;
pcapTxRx.tx=wifibroadcast::pcap_helper::open_pcap_tx(wifi_card.name);
if(m_options.pcap_rx_set_direction){
const auto ret=pcap_setdirection(pcapTxRx.rx, PCAP_D_IN);
if(ret!=0){
m_console->debug("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()){
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions src/WBTxRx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -290,6 +292,7 @@ class WBTxRx {
struct PcapTxRx{
pcap_t *tx= nullptr;
pcap_t *rx= nullptr;
int tx_sockfd=-1;
};
std::vector<PcapTxRx> m_pcap_handles;
// temporary
Expand Down

0 comments on commit aab4e31

Please sign in to comment.