Bluetooth: Mesh: shell: Add provision command for self-provisioning
This is for testing purposes, in case an external provisioner is not available or not wanted. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
e6aa6a0784
commit
d35061357a
@ -17,6 +17,12 @@
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/mesh.h>
|
||||
|
||||
/* Default net, app & dev key values, unless otherwise specified */
|
||||
static const u8_t default_key[16] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||
};
|
||||
|
||||
static struct {
|
||||
u16_t local;
|
||||
u16_t dst;
|
||||
@ -550,7 +556,6 @@ static int cmd_relay(int argc, char *argv[])
|
||||
|
||||
static int cmd_app_key_add(int argc, char *argv[])
|
||||
{
|
||||
u8_t val[16] = { [0 ... 15] = 0xcc, };
|
||||
u16_t key_net_idx, key_app_idx;
|
||||
u8_t status;
|
||||
int err;
|
||||
@ -565,7 +570,7 @@ static int cmd_app_key_add(int argc, char *argv[])
|
||||
/* TODO: decode key value that's given in hex */
|
||||
|
||||
err = bt_mesh_cfg_app_key_add(net.net_idx, net.dst, key_net_idx,
|
||||
key_app_idx, val, &status);
|
||||
key_app_idx, default_key, &status);
|
||||
if (err) {
|
||||
printk("Unable to send App Key Add (err %d)\n", err);
|
||||
return 0;
|
||||
@ -768,6 +773,34 @@ static int cmd_pb_gatt(int argc, char *argv[])
|
||||
}
|
||||
#endif /* CONFIG_BT_MESH_PB_GATT */
|
||||
|
||||
static int cmd_provision(int argc, char *argv[])
|
||||
{
|
||||
u16_t net_idx, addr;
|
||||
u32_t iv_index;
|
||||
int err;
|
||||
|
||||
if (argc < 3) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
net_idx = strtoul(argv[1], NULL, 0);
|
||||
addr = strtoul(argv[2], NULL, 0);
|
||||
|
||||
if (argc > 3) {
|
||||
iv_index = strtoul(argv[1], NULL, 0);
|
||||
} else {
|
||||
iv_index = 0;
|
||||
}
|
||||
|
||||
err = bt_mesh_provision(default_key, net_idx, 0, iv_index, 0, addr,
|
||||
default_key);
|
||||
if (err) {
|
||||
printk("Provisioning failed (err %d)\n", err);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct shell_cmd mesh_commands[] = {
|
||||
{ "init", cmd_init, NULL },
|
||||
#if defined(CONFIG_BT_MESH_PB_ADV)
|
||||
@ -779,6 +812,7 @@ static const struct shell_cmd mesh_commands[] = {
|
||||
{ "reset", cmd_reset, NULL },
|
||||
{ "input-num", cmd_input_num, "<number>" },
|
||||
{ "input-str", cmd_input_str, "<string>" },
|
||||
{ "provision", cmd_provision, "<NetKeyIndex> <addr> [IVIndex]" },
|
||||
#if defined(CONFIG_BT_MESH_LOW_POWER)
|
||||
{ "lpn", cmd_lpn, "<value: off, on>" },
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user