diff --git a/include/bluetooth/hci.h b/include/bluetooth/hci.h index 3534dc16485..1fc488cccf3 100644 --- a/include/bluetooth/hci.h +++ b/include/bluetooth/hci.h @@ -337,6 +337,9 @@ struct bt_hci_cmd_hdr { /* Construct OpCode from OGF and OCF */ #define BT_OP(ogf, ocf) ((ocf) | ((ogf) << 10)) +/* Invalid opcode */ +#define BT_OP_NOP 0x0000 + /* Obtain OGF from OpCode */ #define BT_OGF(opcode) (((opcode) >> 10) & BIT_MASK(6)) /* Obtain OCF from OpCode */ diff --git a/samples/bluetooth/hci_uart/src/main.c b/samples/bluetooth/hci_uart/src/main.c index a8bd1b853e8..77a6bf099e9 100644 --- a/samples/bluetooth/hci_uart/src/main.c +++ b/samples/bluetooth/hci_uart/src/main.c @@ -357,6 +357,33 @@ void main(void) /* Enable the raw interface, this will in turn open the HCI driver */ bt_enable_raw(&rx_queue); + + if (IS_ENABLED(CONFIG_BT_WAIT_NOP)) { + /* Issue a Command Complete with NOP */ + int i; + + const struct { + const u8_t h4; + const struct bt_hci_evt_hdr hdr; + const struct bt_hci_evt_cmd_complete cc; + } __packed cc_evt = { + .h4 = H4_EVT, + .hdr = { + .evt = BT_HCI_EVT_CMD_COMPLETE, + .len = sizeof(struct bt_hci_evt_cmd_complete), + }, + .cc = { + .ncmd = 1, + .opcode = sys_cpu_to_le16(BT_OP_NOP), + }, + }; + + for (i = 0; i < sizeof(cc_evt); i++) { + uart_poll_out(hci_uart_dev, + *(((const u8_t *)&cc_evt)+i)); + } + } + /* Spawn the TX thread and start feeding commands and data to the * controller */ diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index c51b9a69f99..eda7df21685 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -46,6 +46,13 @@ config BT_HCI_MESH_EXT help Enable support for the Bluetooth Mesh HCI Commands. +config BT_WAIT_NOP + bool "Wait for \"NOP\" Command Complete event during init" + help + Emit a Command Complete event from the Controller (and wait for it + from the Host) for the NOP opcode to indicate that the Controller is + ready to receive commands. + config BT_RPA # Virtual/hidden option bool diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index 2e058f16562..5a0190a2dae 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -70,14 +70,6 @@ config BT_HCI_TX_PRIO int default 7 -config BT_WAIT_NOP - bool "Wait for \"NOP\" Command Complete event during init" - help - Some controllers emit a Command Complete event for the NOP - opcode to indicate that they're ready to receive commands. - This option should be selected if the controller used - exhibits such behavior. - config BT_HCI_RESERVE int default 0 if BT_H4