From e80881d0b9c830c27fd61f6ebd81477687c4f004 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 24 Nov 2017 11:37:23 +0200 Subject: [PATCH] Bluetooth: Mesh: shell: Add raw network PDU sending support Signed-off-by: Johan Hedberg --- subsys/bluetooth/host/mesh/shell.c | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/subsys/bluetooth/host/mesh/shell.c b/subsys/bluetooth/host/mesh/shell.c index 155d6530e98..04eafa3c88c 100644 --- a/subsys/bluetooth/host/mesh/shell.c +++ b/subsys/bluetooth/host/mesh/shell.c @@ -17,6 +17,12 @@ #include #include +/* Private includes for raw Network & Transport layer access */ +#include "mesh.h" +#include "net.h" +#include "transport.h" +#include "foundation.h" + #define CID_NVAL 0xffff #define CID_LOCAL 0x0002 @@ -613,6 +619,47 @@ static int cmd_appidx(int argc, char *argv[]) return 0; } +static int cmd_net_send(int argc, char *argv[]) +{ + struct net_buf_simple *msg = NET_BUF_SIMPLE(32); + struct bt_mesh_msg_ctx ctx = { + .send_ttl = BT_MESH_TTL_DEFAULT, + .net_idx = net.net_idx, + .addr = net.dst, + .app_idx = net.app_idx, + + }; + struct bt_mesh_net_tx tx = { + .ctx = &ctx, + .src = net.local, + .xmit = bt_mesh_net_transmit_get(), + .sub = bt_mesh_subnet_get(net.net_idx), + }; + size_t len; + int err; + + if (argc < 2) { + return -EINVAL; + } + + if (!tx.sub) { + printk("No matching subnet for NetKey Index 0x%04x\n", + net.net_idx); + return 0; + } + + net_buf_simple_init(msg, 0); + len = hex2bin(argv[1], msg->data, net_buf_simple_tailroom(msg) - 4); + net_buf_simple_add(msg, len); + + err = bt_mesh_trans_send(&tx, msg, NULL, NULL); + if (err) { + printk("Failed to send (err %d)\n", err); + } + + return 0; +} + static int cmd_beacon(int argc, char *argv[]) { u8_t status; @@ -1620,6 +1667,8 @@ static const struct shell_cmd mesh_commands[] = { { "netidx", cmd_netidx, "[NetIdx]" }, { "appidx", cmd_appidx, "[AppIdx]" }, + { "net-send", cmd_net_send, "" }, + /* Configuration Client Model operations */ { "get-comp", cmd_get_comp, "[page]" }, { "beacon", cmd_beacon, "[val: off, on]" },