Skip to content

Commit 80e0f79

Browse files
carlescufiAnas Nashif
authored andcommitted
Bluetooth: controller: Add DTM HCI commands
Signed-off-by: Carles Cufi <[email protected]>
1 parent 37c7551 commit 80e0f79

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

samples/bluetooth/hci_uart/nrf5.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
1111
CONFIG_BT=y
1212
CONFIG_BT_HCI_RAW=y
1313
CONFIG_BT_MAX_CONN=16
14-
CONFIG_BT_CTLR_ASSERT_HANDLER=y
1514
CONFIG_BT_TINYCRYPT_ECC=n
15+
CONFIG_BT_CTLR_DTM_HCI=y
16+
CONFIG_BT_CTLR_ASSERT_HANDLER=y

subsys/bluetooth/controller/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ config BT_CTLR_ADV_EXT
206206
Enable support for Bluetooth 5.0 LE Advertising Extensions in the
207207
Controller.
208208

209+
config BT_CTLR_DTM
210+
bool
211+
help
212+
Enable support for Direct Test Mode in the Controller.
213+
214+
config BT_CTLR_DTM_HCI
215+
bool "Direct Test Mode over HCI"
216+
select BT_CTLR_DTM
217+
help
218+
Enable support for Direct Test Mode over the HCI transport.
219+
209220
config BT_CTLR_ADVANCED_FEATURES
210221
bool "Show advanced features"
211222
help

subsys/bluetooth/controller/hci/hci.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include "ll.h"
2828
#include "hci_internal.h"
2929

30+
#if defined(CONFIG_BT_CTLR_DTM_HCI)
31+
#include "ll_sw/ll_test.h"
32+
#endif /* CONFIG_BT_CTLR_DTM_HCI */
33+
3034
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
3135
#include "common/log.h"
3236
#include "hal/debug.h"
@@ -503,6 +507,14 @@ static void read_supported_commands(struct net_buf *buf, struct net_buf **evt)
503507
rp->commands[28] |= BIT(1) | BIT(2);
504508
#endif /* CONFIG_BT_CTLR_LE_ENC */
505509
#endif
510+
#if defined(CONFIG_BT_CTLR_DTM_HCI)
511+
/* LE RX Test, LE TX Test, LE Test End */
512+
rp->commands[28] |= BIT(4) | BIT(5) | BIT(6);
513+
/* LE Enhanced RX Test. */
514+
rp->commands[35] |= BIT(7);
515+
/* LE Enhanced TX Test. */
516+
rp->commands[36] |= BIT(0);
517+
#endif /* CONFIG_BT_CTLR_DTM_HCI */
506518
#if defined(CONFIG_BT_CONN)
507519
/* Disconnect. */
508520
rp->commands[0] |= BIT(5);
@@ -1343,6 +1355,70 @@ static void le_read_tx_power(struct net_buf *buf, struct net_buf **evt)
13431355
ll_tx_power_get(&rp->min_tx_power, &rp->max_tx_power);
13441356
}
13451357

1358+
#if defined(CONFIG_BT_CTLR_DTM_HCI)
1359+
static void le_rx_test(struct net_buf *buf, struct net_buf **evt)
1360+
{
1361+
struct bt_hci_cp_le_rx_test *cmd = (void *)buf->data;
1362+
struct bt_hci_evt_cc_status *ccst;
1363+
u32_t status;
1364+
1365+
status = ll_test_rx(cmd->rx_ch, 0x01, 0);
1366+
1367+
ccst = cmd_complete(evt, sizeof(*ccst));
1368+
ccst->status = status;
1369+
}
1370+
1371+
static void le_tx_test(struct net_buf *buf, struct net_buf **evt)
1372+
{
1373+
struct bt_hci_cp_le_tx_test *cmd = (void *)buf->data;
1374+
struct bt_hci_evt_cc_status *ccst;
1375+
u32_t status;
1376+
1377+
status = ll_test_tx(cmd->tx_ch, cmd->test_data_len, cmd->pkt_payload,
1378+
0x01);
1379+
1380+
ccst = cmd_complete(evt, sizeof(*ccst));
1381+
ccst->status = status;
1382+
}
1383+
1384+
static void le_test_end(struct net_buf *buf, struct net_buf **evt)
1385+
{
1386+
struct bt_hci_rp_le_test_end *rp;
1387+
u16_t rx_pkt_count;
1388+
1389+
ll_test_end(&rx_pkt_count);
1390+
1391+
rp = cmd_complete(evt, sizeof(*rp));
1392+
rp->status = 0x00;
1393+
rp->rx_pkt_count = sys_cpu_to_le16(rx_pkt_count);
1394+
}
1395+
1396+
static void le_enh_rx_test(struct net_buf *buf, struct net_buf **evt)
1397+
{
1398+
struct bt_hci_cp_le_enh_rx_test *cmd = (void *)buf->data;
1399+
struct bt_hci_evt_cc_status *ccst;
1400+
u32_t status;
1401+
1402+
status = ll_test_rx(cmd->rx_ch, cmd->phy, cmd->mod_index);
1403+
1404+
ccst = cmd_complete(evt, sizeof(*ccst));
1405+
ccst->status = status;
1406+
}
1407+
1408+
static void le_enh_tx_test(struct net_buf *buf, struct net_buf **evt)
1409+
{
1410+
struct bt_hci_cp_le_enh_tx_test *cmd = (void *)buf->data;
1411+
struct bt_hci_evt_cc_status *ccst;
1412+
u32_t status;
1413+
1414+
status = ll_test_tx(cmd->tx_ch, cmd->test_data_len, cmd->pkt_payload,
1415+
cmd->phy);
1416+
1417+
ccst = cmd_complete(evt, sizeof(*ccst));
1418+
ccst->status = status;
1419+
}
1420+
#endif /* CONFIG_BT_CTLR_DTM_HCI */
1421+
13461422
static int controller_cmd_handle(u16_t ocf, struct net_buf *cmd,
13471423
struct net_buf **evt)
13481424
{
@@ -1543,6 +1619,24 @@ static int controller_cmd_handle(u16_t ocf, struct net_buf *cmd,
15431619
le_read_tx_power(cmd, evt);
15441620
break;
15451621

1622+
#if defined(CONFIG_BT_CTLR_DTM_HCI)
1623+
case BT_OCF(BT_HCI_OP_LE_RX_TEST):
1624+
le_rx_test(cmd, evt);
1625+
break;
1626+
case BT_OCF(BT_HCI_OP_LE_TX_TEST):
1627+
le_tx_test(cmd, evt);
1628+
break;
1629+
case BT_OCF(BT_HCI_OP_LE_TEST_END):
1630+
le_test_end(cmd, evt);
1631+
break;
1632+
case BT_OCF(BT_HCI_OP_LE_ENH_RX_TEST):
1633+
le_enh_rx_test(cmd, evt);
1634+
break;
1635+
case BT_OCF(BT_HCI_OP_LE_ENH_TX_TEST):
1636+
le_enh_tx_test(cmd, evt);
1637+
break;
1638+
#endif /* CONFIG_BT_CTLR_DTM_HCI */
1639+
15461640
default:
15471641
return -EINVAL;
15481642
}

0 commit comments

Comments
 (0)