From 909b4c889e4d837c6bb020c0557a35b06168b0b3 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Wed, 29 May 2024 09:12:58 -0700 Subject: [PATCH] https://telecominfraproject.atlassian.net/browse/WIFI-13535 Signed-off-by: stephb9959 --- build | 2 +- src/AP_WS_Server.cpp | 22 ++++++++++++++++++++++ src/AP_WS_Server.h | 1 + src/RESTAPI/RESTAPI_device_handler.cpp | 5 +++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/build b/build index 90be1cdd8..c4fbb1cfa 100644 --- a/build +++ b/build @@ -1 +1 @@ -95 \ No newline at end of file +97 \ No newline at end of file diff --git a/src/AP_WS_Server.cpp b/src/AP_WS_Server.cpp index 3b4240199..d4fa73dcf 100644 --- a/src/AP_WS_Server.cpp +++ b/src/AP_WS_Server.cpp @@ -207,6 +207,28 @@ namespace OpenWifi { return 0; } + bool AP_WS_Server::Disconnect(uint64_t SerialNumber) { + std::shared_ptr Connection; + { + auto hashIndex = MACHash::Hash(SerialNumber); + std::lock_guard DeviceLock(SerialNumbersMutex_[hashIndex]); + auto DeviceHint = SerialNumbers_[hashIndex].find(SerialNumber); + if (DeviceHint == SerialNumbers_[hashIndex].end() || DeviceHint->second == nullptr) { + return false; + } + Connection = DeviceHint->second; + SerialNumbers_[hashIndex].erase(DeviceHint); + } + + { + auto H = SessionHash::Hash(Connection->State_.sessionId); + std::lock_guard SessionLock(SessionMutex_[H]); + Sessions_[H].erase(Connection->State_.sessionId); + } + + return true; + } + void AP_WS_Server::CleanupSessions() { while(Running_) { diff --git a/src/AP_WS_Server.h b/src/AP_WS_Server.h index af6a575c6..6b257b355 100644 --- a/src/AP_WS_Server.h +++ b/src/AP_WS_Server.h @@ -141,6 +141,7 @@ namespace OpenWifi { bool Connected(uint64_t SerialNumber, GWObjects::DeviceRestrictions &Restrictions) const; bool Connected(uint64_t SerialNumber) const; + bool Disconnect(uint64_t SerialNumber); bool SendFrame(uint64_t SerialNumber, const std::string &Payload) const; bool SendRadiusAuthenticationData(const std::string &SerialNumber, const unsigned char *buffer, std::size_t size); diff --git a/src/RESTAPI/RESTAPI_device_handler.cpp b/src/RESTAPI/RESTAPI_device_handler.cpp index 778a9027d..1b61e6183 100644 --- a/src/RESTAPI/RESTAPI_device_handler.cpp +++ b/src/RESTAPI/RESTAPI_device_handler.cpp @@ -17,6 +17,8 @@ #include "RESTAPI_device_helper.h" +#include "AP_WS_Server.h" + namespace OpenWifi { void RESTAPI_device_handler::DoGet() { std::string SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, ""); @@ -80,6 +82,9 @@ namespace OpenWifi { return OK(); } else if (StorageService()->DeleteDevice(SerialNumber)) { + if(AP_WS_Server()->Connected(Utils::SerialNumberToInt(SerialNumber))) { + AP_WS_Server()->Disconnect(Utils::SerialNumberToInt(SerialNumber)); + } return OK(); }