Skip to content

Commit

Permalink
Merge pull request #352 from Telecominfraproject/WIFI-13535
Browse files Browse the repository at this point in the history
  • Loading branch information
stephb9959 committed Jun 3, 2024
2 parents e133a9c + 909b4c8 commit 03dabed
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
95
97
22 changes: 22 additions & 0 deletions src/AP_WS_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,28 @@ namespace OpenWifi {
return 0;
}

bool AP_WS_Server::Disconnect(uint64_t SerialNumber) {
std::shared_ptr<AP_WS_Connection> 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_) {
Expand Down
1 change: 1 addition & 0 deletions src/AP_WS_Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/RESTAPI/RESTAPI_device_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 03dabed

Please sign in to comment.