Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for now, add tx without pcap option #26

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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