Commit 392f9570 authored by Krzysztof Kopyściński's avatar Krzysztof Kopyściński Committed by Carles Cufi
Browse files

tests: bluetooth: mesh: add Proxy Solicitation to shell

This adds commands to advertise Solicitation PDUs, configure
On-Demand Private Proxy and manage Solicitation PDU RPL.

Signed-off-by: default avatarKrzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
parent d0995541
Loading
Loading
Loading
Loading
+36 −0
Changes for doc/connectivity/bluetooth/api/mesh/shell.rst: 36 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -395,6 +395,14 @@ The Proxy Client module is an optional mesh subsystem that can be enabled throug

	* ``NetKeyIndex``: Index of the network key to disconnect.


``mesh proxy solicit <NetKeyIndex>``
------------------------------------

	Begin Proxy Solicitation of a subnet. Support of this feature can be enabled through the :kconfig:option:`CONFIG_BT_MESH_PROXY_SOLICITATION` configuration option.

	* ``NetKeyIndex``: Index of the network key to send Solicitation PDUs to.

.. _bluetooth_mesh_shell_cfg_cli:

Models
@@ -1545,3 +1553,31 @@ The Configuration database is an optional mesh subsystem that can be enabled thr
	Delete an application key from the Configuration database.

	* ``AppKeyIdx``: Key index of the application key to delete.


On-Demand Private GATT Proxy Client
-----------------------------------

The On-Demand Private GATT Proxy Client model is an optional mesh subsystem that can be enabled through the :kconfig:option:`CONFIG_BT_MESH_OD_PRIV_PROXY_CLI` configuration option.

``mesh models od_priv_proxy od-priv-gatt-proxy [duration]``
-----------------------------------------------------------

	Set the On-Demand Private GATT Proxy state on active target, or fetch the value of this state from it. This feature can be enabled through the :kconfig:option:`CONFIG_BT_MESH_OD_PRIV_PROXY_CLI` configuration option.

	* ``duration``: If given, set the state of On-Demand Private GATT Proxy to this value. Fetch this value otherwise.


Solicitation PDU RPL Client
---------------------------

The Solicitation PDU RPL Client model is an optional mesh subsystem that can be enabled through the :kconfig:option:`CONFIG_BT_MESH_SOL_PDU_RPL_CLI` configuration option.

``mesh models sol_pdu_rpl sol-pdu-rpl-clear <range_start> <acked> [range_len]``
-------------------------------------------------------------------------------

	Clear active target's solicitation replay protection list (SRPL) in given range of solicitation source (SSRC) addresses. This feature can be enabled through the :kconfig:option:`CONFIG_BT_MESH_SOL_PDU_RPL_CLI` configuration option.

	* ``range_start``: Start address of the SSRC range.
	* ``acked``: This argument decides on whether an acknowledged or unacknowledged message will be sent.
	* ``range_len``: Range length for the SSRC addresses to be cleared from the solicitiation RPL list. This parameter is optional; if absent, only a single SSRC address will be cleared.
+4 −0
Changes for subsys/bluetooth/mesh/shell/CMakeLists.txt: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -30,3 +30,7 @@ zephyr_library_sources(dfu.c)
endif()

zephyr_library_sources_ifdef(CONFIG_BT_MESH_SHELL_DFD_SRV dfd.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI od_priv_proxy.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_SOL_PDU_RPL_CLI sol_pdu_rpl.c)
+54 −0
Changes for subsys/bluetooth/mesh/shell/od_priv_proxy.c: 54 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
 * Copyright (c) 2022 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdlib.h>
#include <zephyr/shell/shell.h>
#include <zephyr/bluetooth/mesh.h>
#include <zephyr/bluetooth/mesh/shell.h>

#include "utils.h"

static int cmd_od_priv_gatt_proxy_set(const struct shell *sh, size_t argc,
				      char *argv[])
{
	uint8_t val, val_rsp;
	int err = 0;

	struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_DEV(bt_mesh_shell_target_ctx.net_idx,
							      bt_mesh_shell_target_ctx.dst);

	if (argc < 2) {
		err = bt_mesh_od_priv_proxy_cli_get(&ctx, &val_rsp);
	} else {
		val = shell_strtoul(argv[1], 0, &err);

		if (err) {
			shell_warn(sh, "Unable to parse input string argument");
			return err;
		}

		err = bt_mesh_od_priv_proxy_cli_set(&ctx, val, &val_rsp);
	}

	if (err) {
		shell_print(sh, "Unable to send On-Demand Private GATT Proxy Get/Set (err %d)",
			    err);
		return 0;
	}

	shell_print(sh, "On-Demand Private GATT Proxy is set to 0x%02x", val_rsp);

	return 0;
}

SHELL_STATIC_SUBCMD_SET_CREATE(
	od_priv_proxy_cmds,
	SHELL_CMD_ARG(gatt-proxy, NULL, "[duration]", cmd_od_priv_gatt_proxy_set, 1, 1),
	SHELL_SUBCMD_SET_END);

SHELL_SUBCMD_ADD((mesh, models), od_priv_proxy, &od_priv_proxy_cmds,
		 "On-Demand Private Proxy Cli commands",
		 bt_mesh_shell_mdl_cmds_help, 1, 1);
+28 −0
Changes for subsys/bluetooth/mesh/shell/shell.c: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -387,6 +387,29 @@ static int cmd_proxy_disconnect(const struct shell *sh, size_t argc,

	return 0;
}

#if defined(CONFIG_BT_MESH_PROXY_SOLICITATION)
static int cmd_proxy_solicit(const struct shell *sh, size_t argc,
			     char *argv[])
{
	uint16_t net_idx;
	int err = 0;

	net_idx = shell_strtoul(argv[1], 0, &err);
	if (err) {
		shell_warn(sh, "Unable to parse input string argument");
		return err;
	}

	err = bt_mesh_proxy_solicit(net_idx);
	if (err) {
		shell_error(sh, "Failed to advertise solicitation PDU (err %d)",
			    err);
	}

	return err;
}
#endif /* CONFIG_BT_MESH_PROXY_SOLICITATION */
#endif /* CONFIG_BT_MESH_PROXY_CLIENT */
#endif /* CONFIG_BT_MESH_SHELL_GATT_PROXY */

@@ -1653,6 +1676,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(proxy_cmds,
#if defined(CONFIG_BT_MESH_PROXY_CLIENT)
	SHELL_CMD_ARG(connect, NULL, "<NetKeyIndex>", cmd_proxy_connect, 2, 0),
	SHELL_CMD_ARG(disconnect, NULL, "<NetKeyIndex>", cmd_proxy_disconnect, 2, 0),

#if defined(CONFIG_BT_MESH_PROXY_SOLICITATION)
	SHELL_CMD_ARG(solicit, NULL, "<NetKeyIndex>",
		      cmd_proxy_solicit, 2, 0),
#endif
#endif
	SHELL_SUBCMD_SET_END);
#endif /* CONFIG_BT_MESH_SHELL_GATT_PROXY */
+70 −0
Changes for subsys/bluetooth/mesh/shell/sol_pdu_rpl.c: 70 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
 * Copyright (c) 2022 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdlib.h>
#include <zephyr/shell/shell.h>
#include <zephyr/bluetooth/mesh.h>
#include <zephyr/bluetooth/mesh/shell.h>

#include "utils.h"

static int cmd_srpl_clear(const struct shell *sh, size_t argc,
			  char *argv[])
{
	int err = 0;
	uint8_t len;

	struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(bt_mesh_shell_target_ctx.app_idx,
							      bt_mesh_shell_target_ctx.dst);

	uint16_t range_start = shell_strtoul(argv[1], 0, &err);
	bool acked = shell_strtobool(argv[2], 0, &err);

	if (argc > 3) {
		len = shell_strtoul(argv[3], 0, &err);
	} else {
		len = 0;
	}

	if (err < 0) {
		shell_error(sh, "Invalid command parameter (err %d)", err);
		return err;
	}

	if (acked) {
		uint16_t start_rsp;
		uint8_t len_rsp;

		err = bt_mesh_sol_pdu_rpl_clear(&ctx, range_start, len,
						&start_rsp, &len_rsp);

		if (err) {
			shell_error(sh, "Failed to clear Solicitation PDU RPL (err %d)", err);
		} else {
			shell_print(sh, "Cleared Solicitation PDU RPL with range start=%u len=%u",
				    start_rsp, len_rsp);
		}

		return err;
	}

	err = bt_mesh_sol_pdu_rpl_clear_unack(&ctx, range_start, len);
	if (err) {
		shell_error(sh, "Failed to clear Solicitation PDU RPL (err %d)", err);
	}

	return err;
}

SHELL_STATIC_SUBCMD_SET_CREATE(
	sol_pdu_rpl_cmds,
	SHELL_CMD_ARG(clear, NULL, "<range_start> <acked> [range_len]",
		      cmd_srpl_clear, 3, 1),
	SHELL_SUBCMD_SET_END);

SHELL_SUBCMD_ADD((mesh, models), sol_pdu_rpl, &sol_pdu_rpl_cmds,
		 "Solicitation PDU RPL Cli commands",
		 bt_mesh_shell_mdl_cmds_help, 1, 1);
Loading