Skip to content

Commit 93e6f73

Browse files
PavelVPVcarlescufi
authored andcommitted
Bluetooth: Mesh: Change linkage for ctx_shell and default_key in shell
Change linkage for ctx_shell and default_key in shell.c to external to share their usage in other places. Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent 73c5568 commit 93e6f73

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

subsys/bluetooth/mesh/shell/cfg.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
#define CID_NVAL 0xffff
1717

1818
/* Default net & app key values, unless otherwise specified */
19-
static const uint8_t default_key[16] = {
20-
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
21-
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
22-
};
19+
extern const uint8_t bt_mesh_shell_default_key[16];
2320

2421
static int cmd_reset(const struct shell *sh, size_t argc, char *argv[])
2522
{
@@ -413,7 +410,7 @@ static int cmd_net_key_add(const struct shell *sh, size_t argc, char *argv[])
413410
len = hex2bin(argv[3], strlen(argv[3]), key_val, sizeof(key_val));
414411
(void)memset(key_val, 0, sizeof(key_val) - len);
415412
} else {
416-
memcpy(key_val, default_key, sizeof(key_val));
413+
memcpy(key_val, bt_mesh_shell_default_key, sizeof(key_val));
417414
}
418415

419416
if (IS_ENABLED(CONFIG_BT_MESH_CDB)) {
@@ -475,7 +472,7 @@ static int cmd_net_key_update(const struct shell *sh, size_t argc, char *argv[])
475472
len = hex2bin(argv[2], strlen(argv[2]), key_val, sizeof(key_val));
476473
(void)memset(key_val, 0, sizeof(key_val) - len);
477474
} else {
478-
memcpy(key_val, default_key, sizeof(key_val));
475+
memcpy(key_val, bt_mesh_shell_default_key, sizeof(key_val));
479476
}
480477

481478
err = bt_mesh_cfg_cli_net_key_update(bt_mesh_shell_target_ctx.net_idx,
@@ -567,7 +564,7 @@ static int cmd_app_key_add(const struct shell *sh, size_t argc, char *argv[])
567564
len = hex2bin(argv[3], strlen(argv[3]), key_val, sizeof(key_val));
568565
(void)memset(key_val + len, 0, sizeof(key_val) - len);
569566
} else {
570-
memcpy(key_val, default_key, sizeof(key_val));
567+
memcpy(key_val, bt_mesh_shell_default_key, sizeof(key_val));
571568
}
572569

573570
if (IS_ENABLED(CONFIG_BT_MESH_CDB)) {
@@ -632,7 +629,7 @@ static int cmd_app_key_upd(const struct shell *sh, size_t argc, char *argv[])
632629
len = hex2bin(argv[3], strlen(argv[3]), key_val, sizeof(key_val));
633630
(void)memset(key_val, 0, sizeof(key_val) - len);
634631
} else {
635-
memcpy(key_val, default_key, sizeof(key_val));
632+
memcpy(key_val, bt_mesh_shell_default_key, sizeof(key_val));
636633
}
637634

638635
err = bt_mesh_cfg_cli_app_key_update(bt_mesh_shell_target_ctx.net_idx,

subsys/bluetooth/mesh/shell/shell.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@
2929

3030
#define CID_NVAL 0xffff
3131

32-
static const struct shell *ctx_shell;
32+
const struct shell *bt_mesh_shell_ctx_shell;
3333

3434
struct bt_mesh_shell_target bt_mesh_shell_target_ctx = {
3535
.dst = BT_MESH_ADDR_UNASSIGNED,
3636
};
3737

38-
#define shell_print_ctx(_ft, ...) \
39-
do { \
40-
if (ctx_shell != NULL) { \
41-
shell_print(ctx_shell, _ft, ##__VA_ARGS__); \
42-
} \
38+
#define shell_print_ctx(_ft, ...) \
39+
do { \
40+
if (bt_mesh_shell_ctx_shell != NULL) { \
41+
shell_print(bt_mesh_shell_ctx_shell, _ft, ##__VA_ARGS__); \
42+
} \
4343
} while (0)
4444

4545
/* Default net, app & dev key values, unless otherwise specified */
46-
static const uint8_t default_key[16] = {
46+
const uint8_t bt_mesh_shell_default_key[16] = {
4747
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
4848
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
4949
};
@@ -204,7 +204,7 @@ struct bt_mesh_health_cli bt_mesh_shell_health_cli = {
204204
static int cmd_init(const struct shell *sh, size_t argc, char *argv[])
205205
{
206206

207-
ctx_shell = sh;
207+
bt_mesh_shell_ctx_shell = sh;
208208
shell_print(sh, "Mesh shell initialized");
209209

210210
return 0;
@@ -452,8 +452,9 @@ static int output_number(bt_mesh_output_action_t action, uint32_t number)
452452
shell_print_ctx("OOB display Number: %u", number);
453453
break;
454454
default:
455-
if (ctx_shell != NULL) {
456-
shell_error(ctx_shell, "Unknown Output action %u (number %u) requested!",
455+
if (bt_mesh_shell_ctx_shell != NULL) {
456+
shell_error(bt_mesh_shell_ctx_shell,
457+
"Unknown Output action %u (number %u) requested!",
457458
action, number);
458459
}
459460
return -EINVAL;
@@ -485,9 +486,9 @@ static int input(bt_mesh_input_action_t act, uint8_t size)
485486
shell_print_ctx("\"Push\" a number (max %u digits) with: Input-num <num>", size);
486487
break;
487488
default:
488-
if (ctx_shell != NULL) {
489-
shell_error(ctx_shell, "Unknown Input action %u (size %u) requested!", act,
490-
size);
489+
if (bt_mesh_shell_ctx_shell != NULL) {
490+
shell_error(bt_mesh_shell_ctx_shell,
491+
"Unknown Input action %u (size %u) requested!", act, size);
491492
}
492493
return -EINVAL;
493494
}
@@ -834,7 +835,7 @@ static int cmd_provision_adv(const struct shell *sh, size_t argc,
834835

835836
static int cmd_provision_local(const struct shell *sh, size_t argc, char *argv[])
836837
{
837-
const uint8_t *net_key = default_key;
838+
const uint8_t *net_key = bt_mesh_shell_default_key;
838839
uint16_t net_idx, addr;
839840
uint32_t iv_index;
840841
int err = 0;
@@ -867,7 +868,7 @@ static int cmd_provision_local(const struct shell *sh, size_t argc, char *argv[]
867868
}
868869

869870
err = bt_mesh_provision(net_key, net_idx, 0, iv_index, addr,
870-
default_key);
871+
bt_mesh_shell_default_key);
871872
if (err) {
872873
shell_error(sh, "Provisioning failed (err %d)", err);
873874
}

0 commit comments

Comments
 (0)