Integrated Zephyr shell with the CHIP lib shell (#7848)
Currently there was a standalone CHIP shell example using
CHIP lib shell and there was a Zephyr shell used only by
nrfconnect platform with some specific commands. The goal
is to use for Zephyr based platforms the CHIP lib shell
but with Zephyr shell backend integrated and be able to use it
in every example, not only standalone shell app.
For nrfconnect:
* Removed custom Zephyr-based ChipShell.cpp
and CONFIG_CHIP_ZEPHYR_SHELL option.
* Renamed CONFIG_CHIP_STANDALONE_SHELL to the CONFIG_CHIP_LIB_SHELL.
* Aligned console docs to the new commands.
For all:
* Extended existing shell commands by ble adv <state>,
onboardingcodes <qrcode|qrcodeurl|manualpairingcode>,
nfc <start|stop|state> and device factoryreset.
* Added MainLoopZephyr.cpp file for Zephyr-based platforms,
that enables Zephyr shell and is kind of integration layer
between CHIP shell and Zephyr shell.
* Removed from streamer_zephyr.cpp part not using Zephyr shell.
diff --git a/BUILD.gn b/BUILD.gn
index 496d109..a24dfee 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -73,7 +73,6 @@
"${chip_root}/src/lib",
"${chip_root}/src/lib/asn1",
"${chip_root}/src/lib/core",
- "${chip_root}/src/lib/shell",
"${chip_root}/src/lib/support",
"${chip_root}/src/messaging",
"${chip_root}/src/protocols",
diff --git a/config/nrfconnect/chip-gn/BUILD.gn b/config/nrfconnect/chip-gn/BUILD.gn
index d724320..b9a71c9 100644
--- a/config/nrfconnect/chip-gn/BUILD.gn
+++ b/config/nrfconnect/chip-gn/BUILD.gn
@@ -21,7 +21,6 @@
declare_args() {
chip_build_pw_rpc_lib = false
- chip_build_zephyr_shell = false
}
group("nrfconnect") {
@@ -31,10 +30,6 @@
deps += [ "${chip_root}/src:tests" ]
}
- if (chip_build_zephyr_shell) {
- deps += [ "${chip_root}/src/platform/nrfconnect/shell:chip-zephyr-shell" ]
- }
-
# Building PW_RPC lib with GN may go obsolete after getting full CMake
# support in Pigweed.
if (chip_build_pw_rpc_lib) {
diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt
index 2416859..89b21be 100644
--- a/config/nrfconnect/chip-module/CMakeLists.txt
+++ b/config/nrfconnect/chip-module/CMakeLists.txt
@@ -119,14 +119,6 @@
set(CHIP_LIBRARIES -lCHIP)
endif()
-if (CONFIG_CHIP_STANDALONE_SHELL)
- list(APPEND CHIP_LIBRARIES -lCHIPShell)
-endif()
-
-if (CONFIG_CHIP_ZEPHYR_SHELL)
- set(CHIP_ZEPHYR_SHELL_LIBRARY -lCHIPZephyrShell)
-endif()
-
if (CONFIG_CHIP_PW_RPC)
list(APPEND CHIP_LIBRARIES -lPwRpc)
endif()
@@ -206,8 +198,7 @@
chip_gn_arg_bool ("chip_inet_config_enable_raw_endpoint" CONFIG_CHIP_BUILD_TESTS)
chip_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS)
chip_gn_arg_bool ("chip_inet_config_enable_dns_resolver" CONFIG_CHIP_BUILD_TESTS)
-chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_STANDALONE_SHELL)
-chip_gn_arg_bool ("chip_build_zephyr_shell" CONFIG_CHIP_ZEPHYR_SHELL)
+chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_LIB_SHELL)
chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_PW_RPC)
if (CONFIG_CHIP_ENABLE_DNSSD_SRP)
@@ -266,7 +257,12 @@
${CMAKE_CURRENT_BINARY_DIR}/gen/include
)
target_link_directories(chip INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/lib)
-target_link_libraries(chip INTERFACE -Wl,--whole-archive ${CHIP_ZEPHYR_SHELL_LIBRARY} -Wl,--no-whole-archive,--start-group ${CHIP_LIBRARIES} -Wl,--end-group)
+if (CONFIG_CHIP_LIB_SHELL)
+ target_link_options(chip INTERFACE -Wl,--whole-archive -lCHIPShell -Wl,--no-whole-archive)
+endif()
+
+target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--end-group)
+
add_dependencies(chip chip-gn)
endif() # CONFIG_CHIP
diff --git a/config/zephyr/Kconfig b/config/zephyr/Kconfig
index 1dc5c8c..32f548f 100644
--- a/config/zephyr/Kconfig
+++ b/config/zephyr/Kconfig
@@ -47,17 +47,10 @@
This option can be used to replace Zephyr-supplied OpenThread
configuration file with a custom one.
-config CHIP_ZEPHYR_SHELL
- bool "Enable Zephyr-based CHIP shell"
- default n
- imply SHELL
- help
- Add CHIP commands to the Zephyr shell.
-
-config CHIP_STANDALONE_SHELL
+config CHIP_LIB_SHELL
bool "Enable CHIP shell library"
default n
- depends on !CHIP_ZEPHYR_SHELL
+ imply SHELL
help
Link the application with the library containing CHIP shell commands.
diff --git a/docs/guides/nrfconnect_examples_cli.md b/docs/guides/nrfconnect_examples_cli.md
index a0bf5dd..8d35aa1 100644
--- a/docs/guides/nrfconnect_examples_cli.md
+++ b/docs/guides/nrfconnect_examples_cli.md
@@ -90,114 +90,220 @@
The nRF Connect SDK examples let you use several CHIP-specific CLI commands.
-These commands are not available in the standard Zephyr shell.
+These commands are not available by default and to enable using them, set the
+`CONFIG_CHIP_LIB_SHELL=y` Kconfig option in the `prj.conf` file of the given
+example.
-They are currently used for testing purposes and allow only to get some
-information about CHIP stack state, but not to modify it.
-
-To enable using CHIP commands, set the `CONFIG_CHIP_ZEPHYR_SHELL=y` Kconfig
-option in the `prj.conf` file of the given example.
-
-### Listing CHIP-specific commands
-
-To list all available CHIP-specific commands, enter `chip` in the command line
-and press the Tab key. This will list the available commands:
-
-```shell
-uart:~$ chip
- qrcode qrcodeurl setuppincode discriminator
- vendorid productid manualpairingcode bleadvertising
- nfcemulation
-```
+Every invoked command must be preceded by the `matter` prefix.
See the following subsections for the description of each CHIP-specific command.
-#### `qrcode`
+### device
+
+Handles a group of commands that are used to manage the device. You must use
+this command together with one of the additional subcommands listed below.
+
+#### factoryreset
+
+Performs device factory reset that is hardware reset preceded by erasing of the
+whole CHIP settings stored in a non-volatile memory.
+
+```shell
+uart:~$ matter factoryreset
+Performing factory reset ...
+```
+
+### onboardingcodes
+
+Handles a group of commands that are used to view information about device
+onboarding codes. You can use this command without any subcommand to print all
+available onboarding codes or to add a specific subcommand.
+
+```shell
+uart:~$ matter onboardingcodes
+QRCode: MT:W0GU2OTB00KA0648G00
+QRCodeUrl: https://dhrishi.github.io/connectedhomeip/qrcode.html?data=MT%3AW0GU2OTB00KA0648G00
+ManualPairingCode: 34970112332
+```
+
+The `onboardingcodes` command can also take the subcommands listed below.
+
+#### qrcode
Prints the device
[onboarding QR code payload](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/nrfconnect_android_commissioning.md#preparing-accessory-device).
Takes no arguments.
```shell
-uart:~$ chip qrcode
+uart:~$ matter onboardingcodes qrcode
MT:W0GU2OTB00KA0648G00
```
-#### `qrcodeurl`
+#### qrcodeurl
Prints the URL to view the
[device onboarding QR code](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/nrfconnect_android_commissioning.md#preparing-accessory-device)
in a web browser. Takes no arguments.
```shell
-uart:~$ chip qrcodeurl
-https://dhrishi.github.io/connectedhomeip/qrcode.html?data=CH%3AH34.GHY00%200C9SS0
+uart:~$ matter onboardingcodes qrcodeurl
+https://dhrishi.github.io/connectedhomeip/qrcode.html?data=MT%3AW0GU2OTB00KA0648G00
```
-#### `setuppincode`
-
-Prints the PIN code for device setup. Takes no arguments.
-
-```shell
-uart:~$ chip setuppincode
-12345678
-```
-
-#### `discriminator`
-
-Prints the device setup discriminator. Takes no arguments.
-
-```shell
-uart:~$ chip discriminator
-3840
-```
-
-#### `vendorid`
-
-Prints the vendor ID of the device. Takes no arguments.
-
-```shell
-uart:~$ chip vendorid
-9050
-```
-
-#### `productid`
-
-Prints the product ID of the device. Takes no arguments.
-
-```shell
-uart:~$ chip productid
-20043
-```
-
-#### `manualpairingcode`
+#### manualpairingcode
Prints the pairing code for the manual onboarding of a device. Takes no
arguments.
```shell
-uart:~$ chip manualpairingcode
-35767807533
+uart:~$ matter onboardingcodes manualpairingcode
+34970112332
```
-#### `bleadvertising`
+### config
-Prints the information about the Bluetooth LE advertising status, either `0` if
-the advertising is disabled on the device or `1` if it is enabled. Takes no
-arguments.
+Handles a group of commands that are used to view device configuration
+information. You can use this command without any subcommand to print all
+available configuration data or to add a specific subcommand.
```shell
-uart:~$ chip bleadvertising
-0
+VendorId: 9050 (0x235A)
+ProductId: 20043 (0x4E4B)
+ProductRevision: 1 (0x1)
+FabricId:
+PinCode: 020202021
+Discriminator: f00
+DeviceId:
```
-#### `nfcemulation`
+The `config` command can also take the subcommands listed below.
-Prints the information about the NFC tag emulation status, either `0` if the
-emulation is disabled on the device or `1` if it is enabled (1). Takes no
-arguments.
+#### pincode
+
+Prints the PIN code for device setup. Takes no arguments.
```shell
-uart:~$ chip nfcemulation
-0
+uart:~$ matter config pincode
+020202021
+```
+
+#### discriminator
+
+Prints the device setup discriminator. Takes no arguments.
+
+```shell
+uart:~$ matter config discriminator
+f00
+```
+
+#### vendorid
+
+Prints the vendor ID of the device. Takes no arguments.
+
+```shell
+uart:~$ matter config vendorid
+9050 (0x235A)
+```
+
+#### productid
+
+Prints the product ID of the device. Takes no arguments.
+
+```shell
+uart:~$ matter config productid
+20043 (0x4E4B)
+```
+
+#### productrev
+
+Prints the product revision of the device. Takes no arguments.
+
+```shell
+uart:~$ matter config productrev
+1 (0x1)
+```
+
+#### deviceid
+
+Prints the device identifier. Takes no arguments.
+
+#### fabricid
+
+Prints the fabric identifier. Takes no arguments.
+
+### ble
+
+Handles a group of commands that are used to control the device Bluetooth LE
+transport state. You must use this command together with one of the additional
+subcommands listed below.
+
+#### help
+
+Prints help information about `ble` commands group.
+
+```shell
+uart:~$ matter ble help
+ help Usage: ble <subcommand>
+ adv Enable or disable advertisement. Usage: ble adv <start|stop|state>
+```
+
+#### adv start
+
+Enables Bluetooth LE advertising.
+
+```shell
+uart:~$ matter ble adv start
+Starting BLE advertising
+```
+
+#### adv stop
+
+Disables Bluetooth LE advertising.
+
+```shell
+uart:~$ matter ble adv stop
+Stopping BLE advertising
+```
+
+#### adv status
+
+Prints the information about the current Bluetooth LE advertising status.
+
+```shell
+uart:~$ matter ble adv state
+BLE advertising is disabled
+
+```
+
+### nfc
+
+Handles a group of commands that are used to control the device NFC tag
+emulation state. You must use this command together with one of the additional
+subcommands listed below.
+
+#### start
+
+Starts the NFC tag emulation.
+
+```shell
+uart:~$ matter nfc start
+NFC tag emulation started
+```
+
+#### stop
+
+Stops the NFC tag emulation.
+
+```shell
+uart:~$ matter nfc stop
+NFC tag emulation stopped
+```
+
+#### state
+
+Prints the information about the NFC tag emulation status.
+
+```shell
+uart:~$ matter nfc state
+NFC tag emulation is disabled
```
diff --git a/examples/shell/nrfconnect/prj.conf b/examples/shell/nrfconnect/prj.conf
index 3d74a32..351d450 100644
--- a/examples/shell/nrfconnect/prj.conf
+++ b/examples/shell/nrfconnect/prj.conf
@@ -22,10 +22,7 @@
CONFIG_DK_LIBRARY=y
# Configure CHIP shell
-CONFIG_CHIP_STANDALONE_SHELL=y
-CONFIG_CONSOLE_SUBSYS=y
-CONFIG_CONSOLE_GETCHAR=y
-CONFIG_SHELL=n
+CONFIG_CHIP_LIB_SHELL=y
CONFIG_OPENTHREAD_SHELL=n
# Some shell commands require OpenThread FTD configuration
diff --git a/src/lib/shell/BUILD.gn b/src/lib/shell/BUILD.gn
index d941042..c085639 100644
--- a/src/lib/shell/BUILD.gn
+++ b/src/lib/shell/BUILD.gn
@@ -58,6 +58,8 @@
"MainLoopDefault.cpp",
"streamer_k32w.cpp",
]
+ } else if (current_os == "zephyr") {
+ sources += [ "MainLoopZephyr.cpp" ]
} else {
sources += [ "MainLoopDefault.cpp" ]
}
diff --git a/src/lib/shell/Commands.h b/src/lib/shell/Commands.h
index 762df6a..84a325b 100644
--- a/src/lib/shell/Commands.h
+++ b/src/lib/shell/Commands.h
@@ -45,10 +45,28 @@
void RegisterConfigCommands();
/**
+ * This function registers the device management commands.
+ *
+ */
+void RegisterDeviceCommands();
+
+/**
+ * This function registers the device onboarding codes commands.
+ *
+ */
+void RegisterOnboardingCodesCommands();
+
+/**
* This function registers the wifi commands.
*
*/
void RegisterWiFiCommands();
+/**
+ * This function registers the NFC commands.
+ *
+ */
+void RegisterNFCCommands();
+
} // namespace Shell
} // namespace chip
diff --git a/src/lib/shell/Engine.cpp b/src/lib/shell/Engine.cpp
index 616cf52..2f2fcd5 100644
--- a/src/lib/shell/Engine.cpp
+++ b/src/lib/shell/Engine.cpp
@@ -105,6 +105,11 @@
#endif
#if CONFIG_DEVICE_LAYER
RegisterConfigCommands();
+ RegisterDeviceCommands();
+ RegisterOnboardingCodesCommands();
+#endif
+#if CHIP_DEVICE_CONFIG_ENABLE_NFC
+ RegisterNFCCommands();
#endif
}
diff --git a/src/lib/shell/MainLoopZephyr.cpp b/src/lib/shell/MainLoopZephyr.cpp
new file mode 100644
index 0000000..58bc4c2
--- /dev/null
+++ b/src/lib/shell/MainLoopZephyr.cpp
@@ -0,0 +1,49 @@
+/*
+ *
+ * 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 <init.h>
+#include <shell/shell.h>
+
+#include <lib/core/CHIPError.h>
+#include <lib/shell/Engine.h>
+
+using chip::Shell::Engine;
+
+static int cmd_matter(const struct shell * shell, size_t argc, char ** argv)
+{
+ return (Engine::Root().ExecCommand(argc - 1, argv + 1) == CHIP_NO_ERROR) ? 0 : -ENOEXEC;
+}
+
+static int RegisterCommands(const struct device * dev)
+{
+ Engine::Root().RegisterDefaultCommands();
+ return 0;
+}
+
+SYS_INIT(RegisterCommands, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
+
+SHELL_CMD_ARG_REGISTER(matter, NULL, "Matter commands", cmd_matter, 1, 4);
+
+namespace chip {
+namespace Shell {
+
+void Engine::RunMainLoop()
+{
+ // Intentionally empty as Zephyr has own thread handling shell
+}
+
+} // namespace Shell
+} // namespace chip
diff --git a/src/lib/shell/commands/BLE.cpp b/src/lib/shell/commands/BLE.cpp
index 0843c45..b652638 100644
--- a/src/lib/shell/commands/BLE.cpp
+++ b/src/lib/shell/commands/BLE.cpp
@@ -72,12 +72,23 @@
streamer_printf(sout, "BLE advertising already stopped\r\n");
}
}
+ else if (strcmp(argv[0], "state") == 0)
+ {
+ if (adv_enabled)
+ {
+ streamer_printf(sout, "BLE advertising is enabled\r\n");
+ }
+ else
+ {
+ streamer_printf(sout, "BLE advertising is disabled\r\n");
+ }
+ }
else
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
- return CHIP_NO_ERROR;
+ return error;
}
int BLEDispatch(int argc, char ** argv)
@@ -94,7 +105,7 @@
{
static const shell_command_t sBLESubCommands[] = {
{ &BLEHelpHandler, "help", "Usage: ble <subcommand>" },
- { &BLEAdvertiseHandler, "adv", "Enable or disable advertisement. Usage: ble adv <start|stop>" },
+ { &BLEAdvertiseHandler, "adv", "Enable or disable advertisement. Usage: ble adv <start|stop|state>" },
};
static const shell_command_t sBLECommand = { &BLEDispatch, "ble", "BLE transport commands" };
diff --git a/src/lib/shell/commands/BUILD.gn b/src/lib/shell/commands/BUILD.gn
index 3171714..b4ec8c1 100644
--- a/src/lib/shell/commands/BUILD.gn
+++ b/src/lib/shell/commands/BUILD.gn
@@ -26,7 +26,11 @@
]
if (chip_device_platform != "none") {
- sources += [ "Config.cpp" ]
+ sources += [
+ "Config.cpp",
+ "Device.cpp",
+ "OnboardingCodes.cpp",
+ ]
}
if (chip_enable_wifi) {
@@ -37,5 +41,13 @@
sources += [ "BLE.cpp" ]
}
+ if (chip_enable_nfc && chip_device_platform != "none") {
+ sources += [ "NFC.cpp" ]
+ }
+
public_deps = [ "${chip_root}/src/lib/shell:shell_core" ]
+
+ if (chip_device_platform != "none") {
+ public_deps += [ "${chip_root}/src/app/server" ]
+ }
}
diff --git a/src/lib/shell/commands/Device.cpp b/src/lib/shell/commands/Device.cpp
new file mode 100644
index 0000000..6b17629
--- /dev/null
+++ b/src/lib/shell/commands/Device.cpp
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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 <core/CHIPCore.h>
+#include <lib/shell/Commands.h>
+#if CONFIG_DEVICE_LAYER
+#include <platform/CHIPDeviceLayer.h>
+#endif
+#include <lib/shell/Engine.h>
+#include <lib/shell/commands/Help.h>
+#include <support/CHIPArgParser.hpp>
+#include <support/CHIPMem.h>
+#include <support/CodeUtils.h>
+
+using chip::DeviceLayer::ConnectivityMgr;
+
+namespace chip {
+namespace Shell {
+
+static chip::Shell::Engine sShellDeviceSubcommands;
+
+int DeviceHelpHandler(int argc, char ** argv)
+{
+ sShellDeviceSubcommands.ForEachCommand(PrintCommandHelp, nullptr);
+ return 0;
+}
+
+static int FactoryResetHandler(int argc, char ** argv)
+{
+ streamer_printf(streamer_get(), "Performing factory reset ... \r\n");
+ DeviceLayer::ConfigurationMgr().InitiateFactoryReset();
+ return 0;
+}
+
+static int DeviceHandler(int argc, char ** argv)
+{
+ if (argc == 0)
+ {
+ DeviceHelpHandler(argc, argv);
+ return CHIP_NO_ERROR;
+ }
+ return sShellDeviceSubcommands.ExecCommand(argc, argv);
+}
+
+void RegisterDeviceCommands()
+{
+ static const shell_command_t sDeviceSubCommands[] = {
+ { &FactoryResetHandler, "factoryreset", "Performs device factory reset" },
+ };
+
+ static const shell_command_t sDeviceComand = { &DeviceHandler, "device", "Device management commands" };
+
+ // Register `device` subcommands with the local shell dispatcher.
+ sShellDeviceSubcommands.RegisterCommands(sDeviceSubCommands, ArraySize(sDeviceSubCommands));
+
+ // Register the root `device` command with the top-level shell.
+ Engine::Root().RegisterCommands(&sDeviceComand, 1);
+}
+
+} // namespace Shell
+} // namespace chip
diff --git a/src/lib/shell/commands/NFC.cpp b/src/lib/shell/commands/NFC.cpp
new file mode 100644
index 0000000..ba101b0
--- /dev/null
+++ b/src/lib/shell/commands/NFC.cpp
@@ -0,0 +1,97 @@
+/*
+ *
+ * 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 <core/CHIPCore.h>
+#include <lib/shell/Commands.h>
+#if CONFIG_DEVICE_LAYER
+#include <platform/CHIPDeviceLayer.h>
+#endif
+#include <app/server/OnboardingCodesUtil.h>
+#include <lib/shell/Engine.h>
+#include <lib/shell/commands/Help.h>
+#include <support/CHIPArgParser.hpp>
+#include <support/CHIPMem.h>
+#include <support/CodeUtils.h>
+
+using chip::DeviceLayer::ConnectivityMgr;
+
+namespace chip {
+namespace Shell {
+
+static int NFCHandler(int argc, char ** argv)
+{
+ CHIP_ERROR error = CHIP_NO_ERROR;
+ streamer_t * sout = streamer_get();
+ bool nfcEnabled;
+
+ VerifyOrReturnError(argc == 1, error = CHIP_ERROR_INVALID_ARGUMENT);
+
+ nfcEnabled = chip::DeviceLayer::NFCMgr().IsTagEmulationStarted();
+
+ if (strcmp(argv[0], "start") == 0)
+ {
+ if (nfcEnabled)
+ {
+ streamer_printf(sout, "NFC tag emulation is already enabled\r\n");
+ }
+ else
+ {
+ ShareQRCodeOverNFC(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
+ streamer_printf(sout, "NFC tag emulation started\r\n");
+ }
+ }
+ else if (strcmp(argv[0], "stop") == 0)
+ {
+ if (nfcEnabled)
+ {
+ chip::DeviceLayer::NFCMgr().StopTagEmulation();
+ streamer_printf(sout, "NFC tag emulation stopped\r\n");
+ }
+ else
+ {
+ streamer_printf(sout, "NFC tag emulation is already disabled\r\n");
+ }
+ }
+ else if (strcmp(argv[0], "state") == 0)
+ {
+ if (nfcEnabled)
+ {
+ streamer_printf(sout, "NFC tag emulation is enabled\r\n");
+ }
+ else
+ {
+ streamer_printf(sout, "NFC tag emulation is disabled\r\n");
+ }
+ }
+ else
+ {
+ return CHIP_ERROR_INVALID_ARGUMENT;
+ }
+ return error;
+}
+
+void RegisterNFCCommands()
+{
+ static const shell_command_t sDeviceComand = { &NFCHandler, "nfc",
+ "Start, stop or get nfc emulation state. Usage: nfc <start|stop|state>" };
+
+ // Register the root `device` command with the top-level shell.
+ Engine::Root().RegisterCommands(&sDeviceComand, 1);
+}
+
+} // namespace Shell
+} // namespace chip
diff --git a/src/lib/shell/commands/OnboardingCodes.cpp b/src/lib/shell/commands/OnboardingCodes.cpp
new file mode 100644
index 0000000..2d7d82a
--- /dev/null
+++ b/src/lib/shell/commands/OnboardingCodes.cpp
@@ -0,0 +1,133 @@
+/*
+ *
+ * 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 <app/server/OnboardingCodesUtil.h>
+#include <inttypes.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/CHIPArgParser.hpp>
+#include <lib/support/CHIPMem.h>
+#include <lib/support/CodeUtils.h>
+#include <platform/CHIPDeviceLayer.h>
+
+#define CHIP_SHELL_MAX_BUFFER_SIZE 128
+
+using chip::DeviceLayer::ConfigurationMgr;
+
+namespace chip {
+namespace Shell {
+
+static CHIP_ERROR GetOnboardingQRCode(bool printHeader)
+{
+ streamer_t * sout = streamer_get();
+ std::string QRCode;
+
+ if (printHeader)
+ {
+ streamer_printf(sout, "QRCode: ");
+ }
+ ReturnErrorOnFailure(GetQRCode(QRCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)));
+ streamer_printf(sout, "%s\r\n", QRCode.c_str());
+ return CHIP_NO_ERROR;
+}
+
+static CHIP_ERROR GetOnboardingQRCodeUrl(bool printHeader)
+{
+ streamer_t * sout = streamer_get();
+ std::string QRCode;
+
+ if (printHeader)
+ {
+ streamer_printf(sout, "QRCodeUrl: ");
+ }
+ ReturnErrorOnFailure(GetQRCode(QRCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)));
+
+ char qrCodeBuffer[CHIP_SHELL_MAX_BUFFER_SIZE];
+
+ ReturnErrorOnFailure(GetQRCodeUrl(qrCodeBuffer, sizeof(qrCodeBuffer), QRCode));
+ streamer_printf(sout, "%s\r\n", qrCodeBuffer);
+ return CHIP_NO_ERROR;
+}
+
+static CHIP_ERROR GetOnboardingManualPairingCode(bool printHeader)
+{
+ streamer_t * sout = streamer_get();
+ std::string manualPairingCode;
+
+ if (printHeader)
+ {
+ streamer_printf(sout, "ManualPairingCode: ");
+ }
+ ReturnErrorOnFailure(
+ GetManualPairingCode(manualPairingCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)));
+ streamer_printf(sout, "%s\r\n", manualPairingCode.c_str());
+ return CHIP_NO_ERROR;
+}
+
+static int PrintAllOnboardingCodes()
+{
+ CHIP_ERROR error = CHIP_NO_ERROR;
+
+ error |= GetOnboardingQRCode(true);
+ error |= GetOnboardingQRCodeUrl(true);
+ error |= GetOnboardingManualPairingCode(true);
+
+ return error;
+}
+
+static int OnboardingHandler(int argc, char ** argv)
+{
+ CHIP_ERROR error = CHIP_NO_ERROR;
+
+ if (argc == 0)
+ {
+ return PrintAllOnboardingCodes();
+ }
+
+ if (strcmp(argv[0], "qrcode") == 0)
+ {
+ return GetOnboardingQRCode(false);
+ }
+ else if (strcmp(argv[0], "qrcodeurl") == 0)
+ {
+ return error = GetOnboardingQRCodeUrl(false);
+ }
+ else if (strcmp(argv[0], "manualpairingcode") == 0)
+ {
+ return error = GetOnboardingManualPairingCode(false);
+ }
+ else
+ {
+ return CHIP_ERROR_INVALID_ARGUMENT;
+ }
+}
+
+void RegisterOnboardingCodesCommands()
+{
+
+ static const shell_command_t sDeviceComand = { &OnboardingHandler, "onboardingcodes",
+ "Dump device onboarding codes. Usage: onboardingcodes [param_name]" };
+
+ // Register the root `device` command with the top-level shell.
+ Engine::Root().RegisterCommands(&sDeviceComand, 1);
+ return;
+}
+
+} // namespace Shell
+} // namespace chip
diff --git a/src/lib/shell/streamer_zephyr.cpp b/src/lib/shell/streamer_zephyr.cpp
index 00f8c46..8f93e82 100644
--- a/src/lib/shell/streamer_zephyr.cpp
+++ b/src/lib/shell/streamer_zephyr.cpp
@@ -24,24 +24,13 @@
#include <cassert>
-#if CONFIG_SHELL
#include <shell/shell.h>
#include <shell/shell_uart.h>
-#else
-#include <console/console.h>
-#endif
namespace chip {
namespace Shell {
namespace {
-#if CONFIG_SHELL
-
-// NOTE:
-// We assume that if Zephyr shell is enabled it will be responsible for reading and parsing
-// a command line. Therefore, we only have to provide implentation for streamer_write() and
-// may omit streamer_read() part.
-
int streamer_zephyr_init(streamer_t * streamer)
{
ARG_UNUSED(streamer);
@@ -63,39 +52,6 @@
return length;
}
-#else // CONFIG_SHELL
-
-int streamer_zephyr_init(streamer_t * streamer)
-{
- ARG_UNUSED(streamer);
- return console_init();
-}
-
-ssize_t streamer_zephyr_read(streamer_t * streamer, char * buffer, size_t length)
-{
- ARG_UNUSED(streamer);
- const ssize_t rc = console_read(nullptr, buffer, length);
- return rc >= 0 ? rc : 0;
-}
-
-ssize_t streamer_zephyr_write(streamer_t * streamer, const char * buffer, size_t length)
-{
- ARG_UNUSED(streamer);
- size_t written = 0;
-
- while (written < length)
- {
- const ssize_t rc = console_write(nullptr, buffer + written, length - written);
- if (rc <= 0) // error
- break;
- written += static_cast<size_t>(rc);
- }
-
- return written;
-}
-
-#endif // CONFIG_SHELL
-
static streamer_t streamer_zephyr = {
.init_cb = streamer_zephyr_init,
.read_cb = streamer_zephyr_read,
diff --git a/src/platform/nrfconnect/shell/BUILD.gn b/src/platform/nrfconnect/shell/BUILD.gn
deleted file mode 100644
index 04874cd..0000000
--- a/src/platform/nrfconnect/shell/BUILD.gn
+++ /dev/null
@@ -1,26 +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.
-
-import("//build_overrides/chip.gni")
-
-static_library("chip-zephyr-shell") {
- output_name = "libCHIPZephyrShell"
- output_dir = "${root_out_dir}/lib"
-
- sources = [ "ChipShell.cpp" ]
-
- cflags = [ "-Wconversion" ]
-
- public_deps = [ "${chip_root}/src/app/server" ]
-}
diff --git a/src/platform/nrfconnect/shell/ChipShell.cpp b/src/platform/nrfconnect/shell/ChipShell.cpp
deleted file mode 100644
index f81e714..0000000
--- a/src/platform/nrfconnect/shell/ChipShell.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- *
- * Copyright (c) 2021 Project CHIP Authors
- * All rights reserved.
- *
- * 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 <app/server/OnboardingCodesUtil.h>
-#include <platform/CHIPDeviceLayer.h>
-#include <support/CodeUtils.h>
-
-#include "shell/shell.h"
-
-#define CHIP_SHELL_MAX_BUFFER_SIZE 128
-
-using namespace chip::DeviceLayer;
-
-static int cmd_chip_qrcode(const struct shell * shell, size_t argc, char ** argv)
-{
- CHIP_ERROR error = CHIP_NO_ERROR;
- std::string QRCode;
-
- error = GetQRCode(QRCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
-
- if (error == CHIP_NO_ERROR)
- {
- shell_print(shell, "%s", QRCode.c_str());
- }
- else
- {
- shell_print(shell, "Getting QR code failed with error: %d", error);
- }
-
- return (error == CHIP_NO_ERROR) ? 0 : -ENOEXEC;
-}
-
-static int cmd_chip_qrcodeurl(const struct shell * shell, size_t argc, char ** argv)
-{
- CHIP_ERROR error = CHIP_NO_ERROR;
- std::string QRCode;
-
- error = GetQRCode(QRCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
- VerifyOrExit(error == CHIP_NO_ERROR, shell_print(shell, "Getting QR code failed with error: %d", error));
-
- char qrCodeBuffer[CHIP_SHELL_MAX_BUFFER_SIZE];
-
- error = GetQRCodeUrl(qrCodeBuffer, sizeof(qrCodeBuffer), QRCode);
- VerifyOrExit(error == CHIP_NO_ERROR, shell_print(shell, "Getting QR code url failed with error: %d", error));
-
- shell_print(shell, "%s", qrCodeBuffer);
-
-exit:
- return (error == CHIP_NO_ERROR) ? 0 : -ENOEXEC;
-}
-
-static int cmd_chip_setuppincode(const struct shell * shell, size_t argc, char ** argv)
-{
- CHIP_ERROR error = CHIP_NO_ERROR;
- uint32_t setupPinCode;
-
- error = ConfigurationMgr().GetSetupPinCode(setupPinCode);
- if (error == CHIP_NO_ERROR)
- {
- shell_print(shell, "%d", setupPinCode);
- }
- else
- {
- shell_print(shell, "Getting Setup Pin Code failed with error: %d", error);
- }
-
- return (error == CHIP_NO_ERROR) ? 0 : -ENOEXEC;
-}
-
-static int cmd_chip_discriminator(const struct shell * shell, size_t argc, char ** argv)
-{
- CHIP_ERROR error = CHIP_NO_ERROR;
- uint16_t discriminator;
-
- error = ConfigurationMgr().GetSetupDiscriminator(discriminator);
- if (error == CHIP_NO_ERROR)
- {
- shell_print(shell, "%d", discriminator);
- }
- else
- {
- shell_print(shell, "Getting Setup Discriminator failed with error: %d", error);
- }
-
- return (error == CHIP_NO_ERROR) ? 0 : -ENOEXEC;
-}
-
-static int cmd_chip_vendorid(const struct shell * shell, size_t argc, char ** argv)
-{
- CHIP_ERROR error = CHIP_NO_ERROR;
- uint16_t vendorId;
-
- error = ConfigurationMgr().GetVendorId(vendorId);
- if (error == CHIP_NO_ERROR)
- {
- shell_print(shell, "%d", vendorId);
- }
- else
- {
- shell_print(shell, "Getting Vendor ID failed with error: %d", error);
- }
-
- return (error == CHIP_NO_ERROR) ? 0 : -ENOEXEC;
-}
-
-static int cmd_chip_productid(const struct shell * shell, size_t argc, char ** argv)
-{
- CHIP_ERROR error = CHIP_NO_ERROR;
- uint16_t productId;
-
- error = ConfigurationMgr().GetProductId(productId);
- if (error == CHIP_NO_ERROR)
- {
- shell_print(shell, "%d", productId);
- }
- else
- {
- shell_print(shell, "Getting Product ID failed with error: %d", error);
- }
-
- return (error == CHIP_NO_ERROR) ? 0 : -ENOEXEC;
-}
-
-static int cmd_chip_manualpairingcode(const struct shell * shell, size_t argc, char ** argv)
-{
- CHIP_ERROR error = CHIP_NO_ERROR;
- std::string manualPairingCode;
-
- error = GetManualPairingCode(manualPairingCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
- if (error == CHIP_NO_ERROR)
- {
- shell_print(shell, "%s", manualPairingCode.c_str());
- }
- else
- {
- shell_print(shell, "Getting Manual Pairing Code failed with error: %d", error);
- }
-
- return (error == CHIP_NO_ERROR) ? 0 : -ENOEXEC;
-}
-
-static int cmd_chip_bleadvertising(const struct shell * shell, size_t argc, char ** argv)
-{
- if (ConnectivityMgr().IsBLEAdvertisingEnabled())
- {
- shell_print(shell, "1");
- }
- else
- {
- shell_print(shell, "0");
- }
-
- return 0;
-}
-
-static int cmd_chip_nfcemulation(const struct shell * shell, size_t argc, char ** argv)
-{
- if (NFCMgr().IsTagEmulationStarted())
- {
- shell_print(shell, "1");
- }
- else
- {
- shell_print(shell, "0");
- }
-
- return 0;
-}
-
-SHELL_STATIC_SUBCMD_SET_CREATE(chipCommands, SHELL_CMD_ARG(qrcode, NULL, "qrcode", cmd_chip_qrcode, 0, 0),
- SHELL_CMD_ARG(qrcodeurl, NULL, "qrcodeurl", cmd_chip_qrcodeurl, 0, 0),
- SHELL_CMD_ARG(setuppincode, NULL, "setuppincode", cmd_chip_setuppincode, 0, 0),
- SHELL_CMD_ARG(discriminator, NULL, "discriminator", cmd_chip_discriminator, 0, 0),
- SHELL_CMD_ARG(vendorid, NULL, "vendorid", cmd_chip_vendorid, 0, 0),
- SHELL_CMD_ARG(productid, NULL, "productid", cmd_chip_productid, 0, 0),
- SHELL_CMD_ARG(manualpairingcode, NULL, "manualpairingcode", cmd_chip_manualpairingcode, 0, 0),
- SHELL_CMD_ARG(bleadvertising, NULL, "bleadvertising", cmd_chip_bleadvertising, 0, 0),
- SHELL_CMD_ARG(nfcemulation, NULL, "nfcemulation", cmd_chip_nfcemulation, 0, 0),
- SHELL_SUBCMD_SET_END /* Array terminated. */
-);
-
-SHELL_CMD_REGISTER(chip, &chipCommands, "CHIP commands", NULL);