[shell] Clean OTA commands & remove base64 commands (#32396)

* [shell] Clean OTA commands

1. Remove obsolete "apply" and "notify" commands. These
   actions are invoked automatically by OTA requestor.
2. Do not post tasks onto CHIP thread - shell commands
   are already run on CHIP thread.
3. Do not print error codes. They are already printed
   by shell core.

* [shell] Remove base64 commands

Base64 encoding/decoding is not specific to Matter so base64
shell commands are not useful on actual Matter devices.
diff --git a/docs/guides/silabs_cli_guide.md b/docs/guides/silabs_cli_guide.md
index 8a368f0..5a79539 100644
--- a/docs/guides/silabs_cli_guide.md
+++ b/docs/guides/silabs_cli_guide.md
@@ -197,8 +197,6 @@
 ```bash
 matterCli> ota
   query           Query for a new image. Usage: ota query
-  apply           Apply the current update. Usage: ota apply
-  notify          Notify the new image has been applied. Usage: ota notify <version>
   state           Gets state of a current image update process. Usage: ota state
   progress        Gets progress of a current image update process. Usage: ota progress
 ```
diff --git a/src/lib/shell/Commands.h b/src/lib/shell/Commands.h
index 59fb07c..9cd4c88 100644
--- a/src/lib/shell/Commands.h
+++ b/src/lib/shell/Commands.h
@@ -21,12 +21,6 @@
 namespace Shell {
 
 /**
- * This function registers the base64 encode/decode commands.
- *
- */
-void RegisterBase64Commands();
-
-/**
  * This function registers the BLE commands.
  *
  */
diff --git a/src/lib/shell/Engine.cpp b/src/lib/shell/Engine.cpp
index b83b6ca..809d44c 100644
--- a/src/lib/shell/Engine.cpp
+++ b/src/lib/shell/Engine.cpp
@@ -105,7 +105,6 @@
 
 void Engine::RegisterDefaultCommands()
 {
-    RegisterBase64Commands();
     RegisterMetaCommands();
 #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
     RegisterBLECommands();
diff --git a/src/lib/shell/commands/BUILD.gn b/src/lib/shell/commands/BUILD.gn
index d6190fe..d4dd582 100644
--- a/src/lib/shell/commands/BUILD.gn
+++ b/src/lib/shell/commands/BUILD.gn
@@ -20,7 +20,6 @@
 
 source_set("commands") {
   sources = [
-    "Base64.cpp",
     "Help.cpp",
     "Help.h",
     "Meta.cpp",
diff --git a/src/lib/shell/commands/Base64.cpp b/src/lib/shell/commands/Base64.cpp
deleted file mode 100644
index 0e64bd5..0000000
--- a/src/lib/shell/commands/Base64.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- *
- *    Copyright (c) 2021 Project CHIP Authors
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-
-#include <cstdint>
-#include <inttypes.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <lib/core/CHIPCore.h>
-#include <lib/shell/Commands.h>
-#include <lib/shell/Engine.h>
-#include <lib/shell/commands/Help.h>
-#include <lib/support/Base64.h>
-#include <lib/support/CHIPArgParser.hpp>
-#include <lib/support/CodeUtils.h>
-#include <lib/support/SafeInt.h>
-
-chip::Shell::Engine sShellBase64Commands;
-
-namespace chip {
-namespace Shell {
-
-static CHIP_ERROR Base64HelpHandler(int argc, char ** argv)
-{
-    sShellBase64Commands.ForEachCommand(PrintCommandHelp, nullptr);
-    return CHIP_NO_ERROR;
-}
-
-static CHIP_ERROR Base64DecodeHandler(int argc, char ** argv)
-{
-    streamer_t * sout = streamer_get();
-    uint32_t binarySize;
-    uint8_t binary[256];
-
-    VerifyOrReturnError(argc > 0, CHIP_ERROR_INVALID_ARGUMENT);
-    auto argLen = strlen(argv[0]);
-    VerifyOrReturnError(CanCastTo<uint16_t>(argLen), CHIP_ERROR_INVALID_ARGUMENT);
-    VerifyOrReturnError(BASE64_MAX_DECODED_LEN(argLen) <= sizeof(binary), CHIP_ERROR_INVALID_ARGUMENT);
-
-    binarySize = Base64Decode(argv[0], static_cast<uint16_t>(argLen), binary);
-    VerifyOrReturnError(binarySize != UINT16_MAX, CHIP_ERROR_INVALID_ARGUMENT);
-    streamer_print_hex(sout, binary, static_cast<int>(binarySize));
-    streamer_printf(sout, "\r\n");
-    return CHIP_NO_ERROR;
-}
-
-static CHIP_ERROR Base64EncodeHandler(int argc, char ** argv)
-{
-    streamer_t * sout = streamer_get();
-    char base64[256];
-    uint8_t binary[256];
-    uint32_t binarySize, base64Size;
-
-    VerifyOrReturnError(argc > 0, CHIP_ERROR_INVALID_ARGUMENT);
-
-    auto argLen = strlen(argv[0]);
-    VerifyOrReturnError(CanCastTo<uint32_t>(argLen), CHIP_ERROR_INVALID_ARGUMENT);
-
-    ArgParser::ParseHexString(argv[0], static_cast<uint32_t>(argLen), binary, sizeof(binary), binarySize);
-    if (!CanCastTo<uint16_t>(binarySize))
-    {
-        return CHIP_ERROR_INVALID_ARGUMENT;
-    }
-    base64Size = Base64Encode(binary, static_cast<uint16_t>(binarySize), base64);
-    streamer_printf(sout, "%.*s\r\n", base64Size, base64);
-    return CHIP_NO_ERROR;
-}
-
-static CHIP_ERROR Base64Dispatch(int argc, char ** argv)
-{
-    if (argc == 0)
-    {
-        return Base64HelpHandler(argc, argv);
-    }
-    return sShellBase64Commands.ExecCommand(argc, argv);
-}
-
-void RegisterBase64Commands()
-{
-    /// Subcommands for root command: `base64 <subcommand>`
-    static const shell_command_t sBase64SubCommands[] = {
-        { &Base64HelpHandler, "help", "Usage: base64 <subcommand>" },
-        { &Base64EncodeHandler, "encode", "Encode a hex sting as base64. Usage: base64 encode <hex_string>" },
-        { &Base64DecodeHandler, "decode", "Decode a base64 sting as hex. Usage: base64 decode <base64_string>" },
-    };
-
-    static const shell_command_t sBase64Command = { &Base64Dispatch, "base64", "Base64 encode / decode utilities" };
-
-    // Register `base64` subcommands with the local shell dispatcher.
-    sShellBase64Commands.RegisterCommands(sBase64SubCommands, ArraySize(sBase64SubCommands));
-
-    // Register the root `base64` command with the top-level shell.
-    Engine::Root().RegisterCommands(&sBase64Command, 1);
-}
-
-} // namespace Shell
-} // namespace chip
diff --git a/src/lib/shell/commands/Ota.cpp b/src/lib/shell/commands/Ota.cpp
index 4cc005c..729d1b9 100644
--- a/src/lib/shell/commands/Ota.cpp
+++ b/src/lib/shell/commands/Ota.cpp
@@ -16,12 +16,11 @@
  */
 
 #include <app/clusters/ota-requestor/OTARequestorInterface.h>
+#include <lib/core/DataModelTypes.h>
 #include <lib/shell/Commands.h>
 #include <lib/shell/Engine.h>
 #include <lib/shell/commands/Help.h>
 #include <lib/support/logging/CHIPLogging.h>
-#include <platform/CHIPDeviceLayer.h>
-#include <platform/OTAImageProcessor.h>
 
 using namespace chip::DeviceLayer;
 
@@ -35,95 +34,32 @@
 {
     VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
     VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);
-    PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); });
-    return CHIP_NO_ERROR;
+
+    return GetRequestorInstance()->TriggerImmediateQuery();
 }
 
-CHIP_ERROR ApplyImageHandler(int argc, char ** argv)
+const char * UpdateStateToString(app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum state)
 {
-    VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
-    VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);
-    PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); });
-    return CHIP_NO_ERROR;
-}
-
-CHIP_ERROR NotifyImageHandler(int argc, char ** argv)
-{
-    VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
-    VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);
-
-    PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->NotifyUpdateApplied(); });
-    return CHIP_NO_ERROR;
-}
-
-static void HandleState(intptr_t context)
-{
-    app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum state;
-    CHIP_ERROR err = GetRequestorInstance()->GetUpdateStateAttribute(0, state);
-
-    if (err == CHIP_NO_ERROR)
+    switch (state)
     {
-        streamer_printf(streamer_get(), "Update state: ");
-        switch (state)
-        {
-        case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kUnknown:
-            streamer_printf(streamer_get(), "unknown");
-            break;
-        case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kIdle:
-            streamer_printf(streamer_get(), "idle");
-            break;
-        case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kQuerying:
-            streamer_printf(streamer_get(), "querying");
-            break;
-        case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnQuery:
-            streamer_printf(streamer_get(), "delayed on query");
-            break;
-        case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDownloading:
-            streamer_printf(streamer_get(), "downloading");
-            break;
-        case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kApplying:
-            streamer_printf(streamer_get(), "applying");
-            break;
-        case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnApply:
-            streamer_printf(streamer_get(), "delayed on apply");
-            break;
-        case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kRollingBack:
-            streamer_printf(streamer_get(), "rolling back");
-            break;
-        case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnUserConsent:
-            streamer_printf(streamer_get(), "delayed on user consent");
-            break;
-        default:
-            streamer_printf(streamer_get(), "invalid");
-            break;
-        }
-        streamer_printf(streamer_get(), "\r\n");
-    }
-    else
-    {
-        streamer_printf(streamer_get(), "Error: %" CHIP_ERROR_FORMAT "\r\n", err.Format());
-    }
-}
-
-static void HandleProgress(intptr_t context)
-{
-    chip::app::DataModel::Nullable<uint8_t> progress;
-    CHIP_ERROR err = GetRequestorInstance()->GetUpdateStateProgressAttribute(0, progress);
-
-    if (err == CHIP_NO_ERROR)
-    {
-        if (progress.IsNull())
-        {
-            streamer_printf(streamer_get(), "Update progress: NULL\r\n");
-        }
-        else
-        {
-            streamer_printf(streamer_get(), "Update progress: %d %%\r\n", progress.Value());
-        }
-    }
-    else
-    {
-        streamer_printf(streamer_get(), "Error: %" CHIP_ERROR_FORMAT "\r\n", err.Format());
+    case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kIdle:
+        return "idle";
+    case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kQuerying:
+        return "querying";
+    case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnQuery:
+        return "delayed on query";
+    case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDownloading:
+        return "downloading";
+    case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kApplying:
+        return "applying";
+    case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnApply:
+        return "delayed on apply";
+    case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kRollingBack:
+        return "rolling back";
+    case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnUserConsent:
+        return "delayed on user consent";
+    default:
+        return "unknown";
     }
 }
 
@@ -132,7 +68,10 @@
     VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
     VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);
 
-    PlatformMgr().ScheduleWork(HandleState, reinterpret_cast<intptr_t>(nullptr));
+    app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum state;
+    ReturnErrorOnFailure(GetRequestorInstance()->GetUpdateStateAttribute(kRootEndpointId, state));
+
+    streamer_printf(streamer_get(), "Update state: %s\r\n", UpdateStateToString(state));
 
     return CHIP_NO_ERROR;
 }
@@ -142,7 +81,17 @@
     VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
     VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);
 
-    PlatformMgr().ScheduleWork(HandleProgress, reinterpret_cast<intptr_t>(nullptr));
+    app::DataModel::Nullable<uint8_t> progress;
+    ReturnErrorOnFailure(GetRequestorInstance()->GetUpdateStateProgressAttribute(kRootEndpointId, progress));
+
+    if (progress.IsNull())
+    {
+        streamer_printf(streamer_get(), "Update progress: unknown\r\n");
+    }
+    else
+    {
+        streamer_printf(streamer_get(), "Update progress: %d %%\r\n", progress.Value());
+    }
 
     return CHIP_NO_ERROR;
 }
@@ -155,14 +104,7 @@
         return CHIP_NO_ERROR;
     }
 
-    CHIP_ERROR error = sSubShell.ExecCommand(argc, argv);
-
-    if (error != CHIP_NO_ERROR)
-    {
-        streamer_printf(streamer_get(), "Error: %" CHIP_ERROR_FORMAT "\r\n", error.Format());
-    }
-
-    return error;
+    return sSubShell.ExecCommand(argc, argv);
 }
 } // namespace
 
@@ -171,8 +113,6 @@
     // Register subcommands of the `ota` commands.
     static const shell_command_t subCommands[] = {
         { &QueryImageHandler, "query", "Query for a new image. Usage: ota query" },
-        { &ApplyImageHandler, "apply", "Apply the current update. Usage: ota apply" },
-        { &NotifyImageHandler, "notify", "Notify the new image has been applied. Usage: ota notify <version>" },
         { &StateHandler, "state", "Gets state of a current image update process. Usage: ota state" },
         { &ProgressHandler, "progress", "Gets progress of a current image update process. Usage: ota progress" }
     };