Skip to content

Commit

Permalink
add cb that is called on fatal error (no device)
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Mar 21, 2024
1 parent 14ec2bd commit 5b6bc23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 13 additions & 2 deletions wifibroadcast/src/WBTxRx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,10 @@ void WBTxRx::tx_inject_packet(const uint8_t stream_index, const uint8_t* data,
m_tx_stats.n_injected_bytes_excluding_overhead += data_len;
m_tx_stats.n_injected_bytes_including_overhead += packet_size;
m_tx_stats.n_injected_packets++;
}else{
} else {
m_console->debug("inject error, sleeping ...");
//m_tx_mutex.unlock(); for now, don't unlock ... therefore we block all threads calling inject
// m_tx_mutex.unlock(); for now, don't unlock ... therefore we block all
// threads calling inject
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
Expand Down Expand Up @@ -250,16 +251,26 @@ bool WBTxRx::inject_radiotap_packet(int card_index, const uint8_t* packet_buff,
if (len_injected != (int)packet_size) {
// This basically should never fail - if the tx queue is full, pcap seems to
// wait ?!
bool has_fatal_error = false;
if (m_options.tx_without_pcap) {
m_console->warn(
"raw sock - unable to inject packet size:{} ret:{} err:[{}]",
packet_size, len_injected, strerror(errno));
if (errno == ENODEV) {
m_console->warn("Fatal error, no device");
has_fatal_error = true;
}
} else {
m_console->warn("pcap -unable to inject packet size:{} ret:{} err:[{}]",
packet_size, len_injected,
pcap_geterr(m_pcap_handles[card_index].tx));
}
m_tx_stats.count_tx_dropped_packets++;
if (has_fatal_error) {
if (m_fatal_error_cb != nullptr) {
m_fatal_error_cb(errno);
}
}
return false;
}
return true;
Expand Down
5 changes: 4 additions & 1 deletion wifibroadcast/src/WBTxRx.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ class WBTxRx {
// register callback that is called each time a valid packet is received (any
// multiplexed stream)
void rx_register_callback(OUTPUT_DATA_CALLBACK cb);

// register callback that is called when the wifi card (probably)
// disconneccted
typedef std::function<void(int error)> DEVICE_FATAL_ERROR_CALLBACK;
DEVICE_FATAL_ERROR_CALLBACK m_fatal_error_cb = nullptr;
/**
* Receiving packets happens in the background in another thread.
*/
Expand Down

0 comments on commit 5b6bc23

Please sign in to comment.