From 14ec2bd65e01d1542230648de43be0e21f63cdb8 Mon Sep 17 00:00:00 2001 From: Consti10 Date: Wed, 20 Mar 2024 16:06:09 +0100 Subject: [PATCH 1/6] 'just sleep' for now on tx error(s) --- wifibroadcast/src/WBTxRx.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wifibroadcast/src/WBTxRx.cpp b/wifibroadcast/src/WBTxRx.cpp index 880636a9..9dfd0c80 100644 --- a/wifibroadcast/src/WBTxRx.cpp +++ b/wifibroadcast/src/WBTxRx.cpp @@ -205,6 +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{ + m_console->debug("inject error, sleeping ..."); + //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)); } } From 5b6bc2388bdeea2aa48d7a86911eea8869f622ab Mon Sep 17 00:00:00 2001 From: Consti10 Date: Thu, 21 Mar 2024 11:58:56 +0100 Subject: [PATCH 2/6] add cb that is called on fatal error (no device) --- wifibroadcast/src/WBTxRx.cpp | 15 +++++++++++++-- wifibroadcast/src/WBTxRx.h | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/wifibroadcast/src/WBTxRx.cpp b/wifibroadcast/src/WBTxRx.cpp index 9dfd0c80..3f52bd47 100644 --- a/wifibroadcast/src/WBTxRx.cpp +++ b/wifibroadcast/src/WBTxRx.cpp @@ -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)); } } @@ -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; diff --git a/wifibroadcast/src/WBTxRx.h b/wifibroadcast/src/WBTxRx.h index 43ba1cae..c3bac2b1 100644 --- a/wifibroadcast/src/WBTxRx.h +++ b/wifibroadcast/src/WBTxRx.h @@ -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 DEVICE_FATAL_ERROR_CALLBACK; + DEVICE_FATAL_ERROR_CALLBACK m_fatal_error_cb = nullptr; /** * Receiving packets happens in the background in another thread. */ From a3893b9fbb34554c61ce4b568f1f32d10f1a24e8 Mon Sep 17 00:00:00 2001 From: Consti10 Date: Thu, 21 Mar 2024 12:08:20 +0100 Subject: [PATCH 3/6] add cb that is called on fatal error (no device) --- wifibroadcast/src/WBTxRx.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wifibroadcast/src/WBTxRx.cpp b/wifibroadcast/src/WBTxRx.cpp index 3f52bd47..4f99f187 100644 --- a/wifibroadcast/src/WBTxRx.cpp +++ b/wifibroadcast/src/WBTxRx.cpp @@ -256,7 +256,8 @@ bool WBTxRx::inject_radiotap_packet(int card_index, const uint8_t* packet_buff, m_console->warn( "raw sock - unable to inject packet size:{} ret:{} err:[{}]", packet_size, len_injected, strerror(errno)); - if (errno == ENODEV) { + if (errno == ENXIO) { + // See https://man7.org/linux/man-pages/man3/errno.3.html m_console->warn("Fatal error, no device"); has_fatal_error = true; } From 6e5a894d8e91214f4d34d28c624cb9bf332050f5 Mon Sep 17 00:00:00 2001 From: Consti10 Date: Wed, 10 Apr 2024 09:29:23 +0200 Subject: [PATCH 4/6] add a few priority stubs for use in openhd --- wifibroadcast/src/HelperSources/SchedulingHelper.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wifibroadcast/src/HelperSources/SchedulingHelper.hpp b/wifibroadcast/src/HelperSources/SchedulingHelper.hpp index 9e7600bd..898a90a5 100644 --- a/wifibroadcast/src/HelperSources/SchedulingHelper.hpp +++ b/wifibroadcast/src/HelperSources/SchedulingHelper.hpp @@ -15,6 +15,11 @@ namespace SchedulingHelper { +// Only 'low' in comparison to other realtime tasks +static constexpr int PRIORITY_REALTIME_LOW=30; +static constexpr int PRIORITY_REALTIME_MID=40; +static constexpr int PRIORITY_REALTIME_HIGH=50; + // this thread should run as close to realtime as possible // https://youtu.be/NrjXEaTSyrw?t=647 // COMMENT: Please don't ever use 99 for your application, there are some kernel From 35dde9ed7e4be72c253f4cf38c19e2b1828fc038 Mon Sep 17 00:00:00 2001 From: consti10 Date: Sun, 14 Apr 2024 11:23:33 +0200 Subject: [PATCH 5/6] compilation on enterprise --- wifibroadcast/src/pcap_helper.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/wifibroadcast/src/pcap_helper.hpp b/wifibroadcast/src/pcap_helper.hpp index 3769df79..879f1aa2 100644 --- a/wifibroadcast/src/pcap_helper.hpp +++ b/wifibroadcast/src/pcap_helper.hpp @@ -5,6 +5,7 @@ #ifndef WIFIBROADCAST_SRC_PCAP_HELPER_H_ #define WIFIBROADCAST_SRC_PCAP_HELPER_H_ +#include #include #include From a64e5467a0ddebef8c6206fb5e9d51eb6eeafa0b Mon Sep 17 00:00:00 2001 From: consti10 Date: Sun, 14 Apr 2024 20:38:25 +0200 Subject: [PATCH 6/6] fix clang tidy --- wifibroadcast/src/HelperSources/SchedulingHelper.hpp | 6 +++--- wifibroadcast/src/pcap_helper.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wifibroadcast/src/HelperSources/SchedulingHelper.hpp b/wifibroadcast/src/HelperSources/SchedulingHelper.hpp index 898a90a5..1dabf1c7 100644 --- a/wifibroadcast/src/HelperSources/SchedulingHelper.hpp +++ b/wifibroadcast/src/HelperSources/SchedulingHelper.hpp @@ -16,9 +16,9 @@ namespace SchedulingHelper { // Only 'low' in comparison to other realtime tasks -static constexpr int PRIORITY_REALTIME_LOW=30; -static constexpr int PRIORITY_REALTIME_MID=40; -static constexpr int PRIORITY_REALTIME_HIGH=50; +static constexpr int PRIORITY_REALTIME_LOW = 30; +static constexpr int PRIORITY_REALTIME_MID = 40; +static constexpr int PRIORITY_REALTIME_HIGH = 50; // this thread should run as close to realtime as possible // https://youtu.be/NrjXEaTSyrw?t=647 diff --git a/wifibroadcast/src/pcap_helper.hpp b/wifibroadcast/src/pcap_helper.hpp index 879f1aa2..83b06334 100644 --- a/wifibroadcast/src/pcap_helper.hpp +++ b/wifibroadcast/src/pcap_helper.hpp @@ -5,9 +5,9 @@ #ifndef WIFIBROADCAST_SRC_PCAP_HELPER_H_ #define WIFIBROADCAST_SRC_PCAP_HELPER_H_ -#include #include #include +#include #include