1 /*
2 * Copyright (c) 2022 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <stdlib.h>
8 #include <zephyr/shell/shell.h>
9 #include <zephyr/bluetooth/mesh.h>
10 #include <zephyr/bluetooth/mesh/shell.h>
11
12 #include "utils.h"
13
cmd_srpl_clear(const struct shell * sh,size_t argc,char * argv[])14 static int cmd_srpl_clear(const struct shell *sh, size_t argc,
15 char *argv[])
16 {
17 int err = 0;
18 uint8_t len;
19
20 struct bt_mesh_msg_ctx ctx = BT_MESH_MSG_CTX_INIT_APP(bt_mesh_shell_target_ctx.app_idx,
21 bt_mesh_shell_target_ctx.dst);
22
23 uint16_t range_start = shell_strtoul(argv[1], 0, &err);
24 bool acked = shell_strtobool(argv[2], 0, &err);
25
26 if (argc > 3) {
27 len = shell_strtoul(argv[3], 0, &err);
28 } else {
29 len = 0;
30 }
31
32 if (err < 0) {
33 shell_error(sh, "Invalid command parameter (err %d)", err);
34 return err;
35 }
36
37 if (acked) {
38 uint16_t start_rsp;
39 uint8_t len_rsp;
40
41 err = bt_mesh_sol_pdu_rpl_clear(&ctx, range_start, len,
42 &start_rsp, &len_rsp);
43
44 if (err) {
45 shell_error(sh, "Failed to clear Solicitation PDU RPL (err %d)", err);
46 } else {
47 shell_print(sh, "Cleared Solicitation PDU RPL with range start=%u len=%u",
48 start_rsp, len_rsp);
49 }
50
51 return err;
52 }
53
54 err = bt_mesh_sol_pdu_rpl_clear_unack(&ctx, range_start, len);
55 if (err) {
56 shell_error(sh, "Failed to clear Solicitation PDU RPL (err %d)", err);
57 }
58
59 return err;
60 }
61
62 SHELL_STATIC_SUBCMD_SET_CREATE(
63 sol_pdu_rpl_cmds,
64 SHELL_CMD_ARG(clear, NULL, "<RngStart> <Ackd> [RngLen]",
65 cmd_srpl_clear, 3, 1),
66 SHELL_SUBCMD_SET_END);
67
68 SHELL_SUBCMD_ADD((mesh, models), sol_pdu_rpl, &sol_pdu_rpl_cmds,
69 "Solicitation PDU RPL Cli commands",
70 bt_mesh_shell_mdl_cmds_help, 1, 1);
71