Skip to content

Commit

Permalink
Properly handle events in response to "PONG" (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgwohlbold committed Mar 21, 2023
1 parent e15a25a commit 52fa01a
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/ipc/Subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../metrics/MetricsManager.h"
#include "AssocEvent.h"

const std::string HOSTAPD_PONG = "PONG\n";
const std::string HOSTAPD_ASSOC_STRING = "<3>EAPOL-4WAY-HS-COMPLETED ";
const std::string HOSTAPD_AUTH_STRING = "<3>AP-STA-CONNECTED ";
const std::string HOSTAPD_DISASSOC_STRING = "<3>AP-STA-DISCONNECTED ";
Expand All @@ -32,20 +33,17 @@ void ipc::Subscriber::loop(const std::future<void>& future) {
event = socket.receive();
} catch (const TimeoutException& e) {
try {
std::string ping_result = socket.send_and_receive({"PING"});
if (ping_result != "PONG\n") {
WMLOG(FATAL) << "timeout in Subscriber::loop_ipc_queue(), hostapd did not respond pong: "
<< ping_result;
break;
} else {
continue;
}
event = socket.send_and_receive({"PING"});
} catch (const TimeoutException& e) {
WMLOG(FATAL)
<< "timeout in Subscriber::loop_ipc_queue(), hostapd timed out while responding to ping";
WMLOG(FATAL) << "timeout in Subscriber::loop_ipc_queue(), hostapd timed out while responding to ping";
break;
}
}
// This is a PONG in response to a previous PING where another event came first, ignore.
if (event == HOSTAPD_PONG) {
continue;
}

if (event.rfind(HOSTAPD_ASSOC_STRING) == 0) {
std::string station_mac =
event.substr(HOSTAPD_ASSOC_STRING.size(), HOSTAPD_ASSOC_STRING.size() + MAC_ADDRESS_LENGTH);
Expand Down

0 comments on commit 52fa01a

Please sign in to comment.