mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-07-27 13:27:47 +00:00
mesh: shell: Add command for printing mesh credentials
For testing purposes. X-Original-Commit: 77b78775f138c5aaffa9d8c8e0c17fb7e9604820
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "mesh/mesh.h"
|
||||
#include "mesh/main.h"
|
||||
#include "mesh/glue.h"
|
||||
#include "mesh/testing.h"
|
||||
|
||||
/* Private includes for raw Network & Transport layer access */
|
||||
#include "net.h"
|
||||
@@ -28,6 +29,7 @@
|
||||
#include "lpn.h"
|
||||
#include "transport.h"
|
||||
#include "foundation.h"
|
||||
#include "testing.h"
|
||||
|
||||
#define CID_NVAL 0xffff
|
||||
#define CID_LOCAL 0x0002
|
||||
@@ -2092,6 +2094,12 @@ struct shell_cmd_help cmd_del_fault_help = {
|
||||
NULL, "[Fault ID]", NULL
|
||||
};
|
||||
|
||||
static int cmd_print_credentials(int argc, char *argv[])
|
||||
{
|
||||
bt_test_print_credentials();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct shell_cmd mesh_commands[] = {
|
||||
{ "init", cmd_init, NULL },
|
||||
{ "timeout", cmd_timeout, &cmd_timeout_help },
|
||||
@@ -2127,6 +2135,7 @@ static const struct shell_cmd mesh_commands[] = {
|
||||
{ "lpn-subscribe", cmd_lpn_subscribe, &cmd_lpn_subscribe_help },
|
||||
{ "lpn-unsubscribe", cmd_lpn_unsubscribe, &cmd_lpn_unsubscribe_help },
|
||||
#endif
|
||||
{ "print-credentials", cmd_print_credentials, NULL },
|
||||
|
||||
/* Configuration Client Model operations */
|
||||
{ "get-comp", cmd_get_comp, &cmd_get_comp_help },
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "console/console.h"
|
||||
#include "mesh/testing.h"
|
||||
#include "mesh/slist.h"
|
||||
#include "mesh/glue.h"
|
||||
@@ -84,3 +85,70 @@ void bt_test_mesh_trans_incomp_timer_exp(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bt_test_print_credentials(void)
|
||||
{
|
||||
int i;
|
||||
u8_t nid;
|
||||
const u8_t *enc;
|
||||
const u8_t *priv;
|
||||
struct bt_mesh_subnet *sub;
|
||||
struct bt_mesh_app_key *app_key;
|
||||
|
||||
console_printf("IV Index: %08lx\n", bt_mesh.iv_index);
|
||||
console_printf("Dev key: %s\n", bt_hex(bt_mesh.dev_key, 16));
|
||||
|
||||
for (i = 0; i < MYNEWT_VAL(BLE_MESH_SUBNET_COUNT); ++i)
|
||||
{
|
||||
if (bt_mesh.app_keys[i].net_idx == BT_MESH_KEY_UNUSED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sub = &bt_mesh.sub[i];
|
||||
|
||||
console_printf("Subnet: %d\n", i);
|
||||
console_printf("\tNetKeyIdx: %04x\n",
|
||||
sub->net_idx);
|
||||
console_printf("\tNetKey: %s\n",
|
||||
bt_hex(sub->keys[sub->kr_flag].net, 16));
|
||||
}
|
||||
|
||||
for (i = 0; i < MYNEWT_VAL(BLE_MESH_APP_KEY_COUNT); ++i)
|
||||
{
|
||||
if (bt_mesh.app_keys[i].net_idx == BT_MESH_KEY_UNUSED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sub = &bt_mesh.sub[i];
|
||||
app_key = &bt_mesh.app_keys[i];
|
||||
|
||||
console_printf("AppKey: %d\n", i);
|
||||
console_printf("\tNetKeyIdx: %04x\n",
|
||||
app_key->net_idx);
|
||||
console_printf("\tAppKeyIdx: %04x\n",
|
||||
app_key->app_idx);
|
||||
console_printf("\tAppKey: %s\n",
|
||||
bt_hex(app_key->keys[sub->kr_flag].val, 16));
|
||||
}
|
||||
|
||||
for (i = 0; i < MYNEWT_VAL(BLE_MESH_SUBNET_COUNT); ++i)
|
||||
{
|
||||
if (bt_mesh.app_keys[i].net_idx == BT_MESH_KEY_UNUSED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (friend_cred_get(&bt_mesh.sub[i], BT_MESH_ADDR_UNASSIGNED,
|
||||
&nid, &enc, &priv)) {
|
||||
return;
|
||||
}
|
||||
|
||||
console_printf("Friend cred: %d\n", i);
|
||||
console_printf("\tNetKeyIdx: %04x\n",
|
||||
bt_mesh.sub[i].net_idx);
|
||||
console_printf("\tNID: %02x\n", nid);
|
||||
console_printf("\tEncKey: %s\n",
|
||||
bt_hex(enc, 16));
|
||||
console_printf("\tPrivKey: %s\n",
|
||||
bt_hex(priv, 16));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,3 +20,4 @@ void bt_test_mesh_prov_invalid_bearer(u8_t opcode);
|
||||
void bt_test_mesh_net_recv(u8_t ttl, u8_t ctl, u16_t src, u16_t dst,
|
||||
const void *payload, size_t payload_len);
|
||||
void bt_test_mesh_trans_incomp_timer_exp(void);
|
||||
void bt_test_print_credentials(void);
|
||||
|
||||
Reference in New Issue
Block a user