From 525f53aaa9f77386f0b46513cf351a34d1a3ce34 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Thu, 19 Oct 2023 16:51:15 -0700 Subject: [PATCH] https://telecominfraproject.atlassian.net/browse/WIFI-12692 Signed-off-by: stephb9959 --- src/CommandManager.cpp | 12 ++++++++++++ src/CommandManager.h | 2 ++ src/RESTAPI/RESTAPI_device_commandHandler.cpp | 15 +++++++++++---- test_scripts/curl/cli | 3 ++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/CommandManager.cpp b/src/CommandManager.cpp index 391da35bf..c9ee370a8 100644 --- a/src/CommandManager.cpp +++ b/src/CommandManager.cpp @@ -467,4 +467,16 @@ namespace OpenWifi { poco_warning(Logger(), fmt::format("{}: Failed to send command. ID: {}", UUID, RPC_ID)); return nullptr; } + + bool CommandManager::FireAndForget(const std::string &SerialNumber, const std::string &Method, const Poco::JSON::Object &Params) { + Poco::JSON::Object CompleteRPC; + CompleteRPC.set(uCentralProtocol::JSONRPC, uCentralProtocol::JSONRPC_VERSION); + CompleteRPC.set(uCentralProtocol::ID, 0); + CompleteRPC.set(uCentralProtocol::METHOD, Method); + CompleteRPC.set(uCentralProtocol::PARAMS, Params); + std::stringstream ToSend; + CompleteRPC.stringify(ToSend); + poco_debug(Logger(), fmt::format("{}: Fire and forget command {}.", SerialNumber, Method)); + return AP_WS_Server()->SendFrame(SerialNumber, ToSend.str())>0; + } } // namespace OpenWifi \ No newline at end of file diff --git a/src/CommandManager.h b/src/CommandManager.h index 296cc06ab..ef71cc196 100644 --- a/src/CommandManager.h +++ b/src/CommandManager.h @@ -162,6 +162,8 @@ namespace OpenWifi { inline auto CommandTimeout() const { return commandTimeOut_; } inline auto CommandRetry() const { return commandRetry_; } + bool FireAndForget(const std::string &SerialNumber, const std::string &Method, + const Poco::JSON::Object &Params); private: mutable std::recursive_mutex LocalMutex_; std::atomic_bool Running_ = false; diff --git a/src/RESTAPI/RESTAPI_device_commandHandler.cpp b/src/RESTAPI/RESTAPI_device_commandHandler.cpp index a9557454d..a6001dbdc 100644 --- a/src/RESTAPI/RESTAPI_device_commandHandler.cpp +++ b/src/RESTAPI/RESTAPI_device_commandHandler.cpp @@ -1398,10 +1398,17 @@ namespace OpenWifi { Cmd.RunAt = 0; Cmd.ErrorCode = 0; Cmd.WaitingForFile = 0; - - return RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::rrm, false, Cmd, - Params, *Request, *Response, timeout, nullptr, this, - Logger_); + Cmd.Status= "completed"; + if(CommandManager()->FireAndForget(SerialNumber_, uCentralProtocol::RRM, Params)) { + StorageService()->AddCommand(SerialNumber_, Cmd, + Storage::CommandExecutionType::COMMAND_COMPLETED); + Cmd.Status= "completed"; + return OK(); + } + Cmd.Status= "failed"; // should never happen + StorageService()->AddCommand(SerialNumber_, Cmd, + Storage::CommandExecutionType::COMMAND_COMPLETED); + return BadRequest(RESTAPI::Errors::CouldNotPerformCommand); } void RESTAPI_device_commandHandler::Transfer( diff --git a/test_scripts/curl/cli b/test_scripts/curl/cli index 8e153635b..ca99eb686 100755 --- a/test_scripts/curl/cli +++ b/test_scripts/curl/cli @@ -940,7 +940,8 @@ certupdate() { } rrm_kick() { - payload="$(printf '[{ "action": "kick", "addr": "%s", "reason": %s, "ban_time": %s}' "$2" "$3" "$4")" + payload="$(printf '{ "actions" : [{ "action": "kick", "addr": "%s", "reason": %s, "ban_time": %s}] }' "$2" "$3" "$4")" + echo "$payload" curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/rrm" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \