From 128a0613cd01771dcf8d25a3475f717140df15e2 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 6 Jun 2017 13:58:55 +0200 Subject: [PATCH] Bluetooth: shell: Add LE Adv. Ext. advx command Add Bluetooth Link Layer LE Advertising Extensions commands for manual testing the feature during development. First one being advx command to start non-connectable non-scannable extended advertising. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/shell/Makefile | 1 + subsys/bluetooth/shell/bt.c | 4 ++ subsys/bluetooth/shell/ll.c | 110 ++++++++++++++++++++++++++++++++ subsys/bluetooth/shell/ll.h | 18 ++++++ 4 files changed, 133 insertions(+) create mode 100644 subsys/bluetooth/shell/ll.c create mode 100644 subsys/bluetooth/shell/ll.h diff --git a/subsys/bluetooth/shell/Makefile b/subsys/bluetooth/shell/Makefile index 36e38215207..d4964a5583f 100644 --- a/subsys/bluetooth/shell/Makefile +++ b/subsys/bluetooth/shell/Makefile @@ -1,3 +1,4 @@ obj-y += bt.o obj-y += gatt.o +obj-$(CONFIG_BLUETOOTH_CONTROLLER) += ll.o obj-$(CONFIG_BLUETOOTH_CONTROLLER) += ticker.o diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index 8754386203d..30d7f5263b5 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -30,6 +30,7 @@ #include "bt.h" #include "gatt.h" +#include "ll.h" #define DEVICE_NAME CONFIG_BLUETOOTH_DEVICE_NAME #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) @@ -2040,6 +2041,9 @@ static const struct shell_cmd bt_commands[] = { { "br-rfcomm-disconnect", cmd_rfcomm_disconnect, HELP_NONE }, #endif /* CONFIG_BLUETOOTH_RFCOMM */ #endif +#if defined(CONFIG_BLUETOOTH_CONTROLLER_ADV_EXT) + { "advx", cmd_advx, " [coded] [anon] [txp]" }, +#endif /* CONFIG_BLUETOOTH_CONTROLLER_ADV_EXT */ { NULL, NULL, NULL } }; diff --git a/subsys/bluetooth/shell/ll.c b/subsys/bluetooth/shell/ll.c new file mode 100644 index 00000000000..0b266dd81ff --- /dev/null +++ b/subsys/bluetooth/shell/ll.c @@ -0,0 +1,110 @@ +/** @file + * @brief Bluetooth Link Layer functions + * + */ + +/* + * Copyright (c) 2017 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include "../controller/include/ll.h" + +#if defined(CONFIG_BLUETOOTH_CONTROLLER_ADV_EXT) +#define ADV_INTERVAL 0x000020 +#define ADV_TYPE 0x05 /* Adv. Ext. */ +#define OWN_ADDR_TYPE 1 +#define PEER_ADDR_TYPE 0 +#define PEER_ADDR NULL +#define ADV_CHAN_MAP 0x07 +#define FILTER_POLICY 0x00 +#define ADV_TX_PWR NULL +#define ADV_SEC_SKIP 0 +#define ADV_PHY_S 0x01 +#define ADV_SID 0 +#define SCAN_REQ_NOT 0 + +int cmd_advx(int argc, char *argv[]) +{ + u16_t evt_prop; + u8_t enable; + u8_t phy_p; + s32_t err; + + if (argc < 2) { + return -EINVAL; + } + + if (argc > 1) { + if (!strcmp(argv[1], "on")) { + evt_prop = 0; + enable = 1; + } else if (!strcmp(argv[1], "off")) { + enable = 0; + goto disable; + } else { + return -EINVAL; + } + } + + phy_p = BIT(0); + + if (argc > 2) { + if (!strcmp(argv[2], "coded")) { + phy_p = BIT(2); + } else if (!strcmp(argv[2], "anon")) { + evt_prop |= BIT(5); + } else if (!strcmp(argv[2], "txp")) { + evt_prop |= BIT(6); + } else { + return -EINVAL; + } + } + + if (argc > 3) { + if (!strcmp(argv[3], "anon")) { + evt_prop |= BIT(5); + } else if (!strcmp(argv[3], "txp")) { + evt_prop |= BIT(6); + } else { + return -EINVAL; + } + } + + if (argc > 4) { + if (!strcmp(argv[4], "txp")) { + evt_prop |= BIT(6); + } else { + return -EINVAL; + } + } + + printk("adv param set..."); + err = ll_adv_params_set(0x00, evt_prop, ADV_INTERVAL, ADV_TYPE, + OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, + ADV_CHAN_MAP, FILTER_POLICY, ADV_TX_PWR, + phy_p, ADV_SEC_SKIP, ADV_PHY_S, ADV_SID, + SCAN_REQ_NOT); + if (err) { + goto exit; + } + +disable: + printk("adv enable (%u)...", enable); + err = ll_adv_enable(enable); + if (err) { + goto exit; + } + +exit: + printk("done (err= %d).\n", err); + + return 0; +} +#endif /* CONFIG_BLUETOOTH_CONTROLLER_ADV_EXT */ diff --git a/subsys/bluetooth/shell/ll.h b/subsys/bluetooth/shell/ll.h new file mode 100644 index 00000000000..3d9eb255208 --- /dev/null +++ b/subsys/bluetooth/shell/ll.h @@ -0,0 +1,18 @@ +/** @file + * @brief Bluetooth Link Layer shell functions + * + * This is not to be included by the application. + */ + +/* + * Copyright (c) 2017 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __LL_H +#define __LL_H + +int cmd_advx(int argc, char *argv[]); + +#endif /* __LL_H */