diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 9cad15b996..8e9faa22fd 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -3,33 +3,35 @@ if(CONFIG_BT_ENABLED) set(srcs "") set(include_dirs "") set(ldfragments "linker.lf") + if(CONFIG_BT_CONTROLLER_ENABLED) + if(CONFIG_IDF_TARGET_ESP32) + list(APPEND srcs "controller/esp32/bt.c" + "controller/esp32/hli_api.c" + "controller/esp32/hli_vectors.S") + list(APPEND include_dirs include/esp32/include) - if(CONFIG_IDF_TARGET_ESP32) - list(APPEND srcs "controller/esp32/bt.c" - "controller/esp32/hli_api.c" - "controller/esp32/hli_vectors.S") - list(APPEND include_dirs include/esp32/include) + elseif(CONFIG_IDF_TARGET_ESP32C3) + list(APPEND srcs "controller/esp32c3/bt.c") + list(APPEND include_dirs include/esp32c3/include) - elseif(CONFIG_IDF_TARGET_ESP32C3) - list(APPEND srcs "controller/esp32c3/bt.c") - list(APPEND include_dirs include/esp32c3/include) + elseif(CONFIG_IDF_TARGET_ESP32S3) + list(APPEND srcs "controller/esp32c3/bt.c") + list(APPEND include_dirs include/esp32c3/include) - elseif(CONFIG_IDF_TARGET_ESP32S3) - list(APPEND srcs "controller/esp32c3/bt.c") - list(APPEND include_dirs include/esp32c3/include) + elseif(CONFIG_IDF_TARGET_ESP32C2) + set(ldfragments "linker.lf.esp32c2") + list(APPEND srcs "controller/esp32c2/bt.c") + list(APPEND include_dirs include/esp32c2/include) - elseif(CONFIG_IDF_TARGET_ESP32C2) - set(ldfragments "linker.lf.esp32c2") - list(APPEND srcs "controller/esp32c2/bt.c") - list(APPEND include_dirs include/esp32c2/include) + elseif(CONFIG_IDF_TARGET_ESP32C6) + list(APPEND srcs "controller/esp32c6/bt.c") + list(APPEND include_dirs include/esp32c6/include) - elseif(CONFIG_IDF_TARGET_ESP32C6) - list(APPEND srcs "controller/esp32c6/bt.c") - list(APPEND include_dirs include/esp32c6/include) + elseif(CONFIG_IDF_TARGET_ESP32H2) + list(APPEND srcs "controller/esp32h2/bt.c") + list(APPEND include_dirs include/esp32h2/include) + endif() - elseif(CONFIG_IDF_TARGET_ESP32H2) - list(APPEND srcs "controller/esp32h2/bt.c") - list(APPEND include_dirs include/esp32h2/include) endif() @@ -483,6 +485,11 @@ if(CONFIG_BT_ENABLED) "porting/nimble/src/os_msys_init.c" ) + if(CONFIG_BT_CONTROLLER_DISABLED) + list(APPEND srcs + "host/nimble/nimble/porting/nimble/src/hal_uart.c" + ) + endif() list(APPEND include_dirs porting/include porting/nimble/include @@ -524,6 +531,7 @@ if(CONFIG_BT_ENABLED) list(APPEND include_dirs host/nimble/nimble/nimble/host/include + host/nimble/nimble/nimble/include host/nimble/nimble/nimble/host/services/ans/include host/nimble/nimble/nimble/host/services/bas/include host/nimble/nimble/nimble/host/services/dis/include @@ -613,6 +621,13 @@ if(CONFIG_BT_ENABLED) "host/nimble/nimble/nimble/host/src/ble_gattc_cache_conn.c" ) + if(CONFIG_BT_CONTROLLER_DISABLED AND CONFIG_BT_NIMBLE_TRANSPORT_UART) + list(APPEND srcs + "host/nimble/nimble/nimble/transport/uart_ll/src/hci_uart.c" + "host/nimble/nimble/nimble/transport/common/hci_h4/src/hci_h4.c" + ) + endif() + list(APPEND srcs "host/nimble/nimble/porting/nimble/src/nimble_port.c" "host/nimble/nimble/porting/npl/freertos/src/nimble_port_freertos.c" @@ -625,6 +640,12 @@ if(CONFIG_BT_ENABLED) host/nimble/nimble/nimble/transport/include ) + if(CONFIG_BT_CONTROLLER_DISABLED) + list(APPEND include_dirs + host/nimble/nimble/nimble/transport/common/hci_h4/include + ) + endif() + if(NOT CONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORT) list(APPEND srcs "host/nimble/nimble/porting/nimble/src/endian.c" @@ -634,6 +655,13 @@ if(CONFIG_BT_ENABLED) "host/nimble/nimble/porting/nimble/src/os_msys_init.c" "host/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c" ) + + if(CONFIG_BT_CONTROLLER_DISABLED AND CONFIG_BT_NIMBLE_TRANSPORT_UART) + list(APPEND srcs + "host/nimble/nimble/porting/nimble/src/hal_uart.c" + ) + endif() + list(APPEND include_dirs host/nimble/nimble/porting/npl/freertos/include host/nimble/nimble/porting/nimble/include @@ -641,7 +669,7 @@ if(CONFIG_BT_ENABLED) ) endif() - if(CONFIG_BT_NIMBLE_LEGACY_VHCI_ENABLE) + if(CONFIG_BT_NIMBLE_LEGACY_VHCI_ENABLE AND CONFIG_BT_CONTROLLER_ENABLED) list(APPEND srcs "host/nimble/esp-hci/src/esp_nimble_hci.c" ) diff --git a/components/bt/Kconfig b/components/bt/Kconfig index 152ce7b386..7df3de8276 100644 --- a/components/bt/Kconfig +++ b/components/bt/Kconfig @@ -1,9 +1,8 @@ menu "Bluetooth" - visible if SOC_BT_SUPPORTED config BT_ENABLED bool "Bluetooth" - depends on SOC_BT_SUPPORTED && !APP_NO_BLOBS + depends on !APP_NO_BLOBS help Select this option to enable Bluetooth and show the submenu with Bluetooth configuration choices. @@ -15,6 +14,7 @@ menu "Bluetooth" This helps to choose Bluetooth host stack config BT_BLUEDROID_ENABLED + depends on BT_CONTROLLER_ENABLED bool "Bluedroid - Dual-mode" help This option is recommended for classic Bluetooth or for dual-mode @@ -26,6 +26,7 @@ menu "Bluetooth" This option is recommended for BLE only usecases to save on memory config BT_CONTROLLER_ONLY + depends on SOC_BT_SUPPORTED bool "Disabled" help This option is recommended when you want to communicate directly with the @@ -42,6 +43,7 @@ menu "Bluetooth" This helps to choose Bluetooth controller stack config BT_CONTROLLER_ENABLED + depends on SOC_BT_SUPPORTED bool "Enabled" help This option is recommended for Bluetooth controller usecases diff --git a/components/bt/host/nimble/Kconfig.in b/components/bt/host/nimble/Kconfig.in index 09dfd663b6..b6e2f7ef17 100644 --- a/components/bt/host/nimble/Kconfig.in +++ b/components/bt/host/nimble/Kconfig.in @@ -201,6 +201,17 @@ config BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION help Enable encryption connection +config BT_NIMBLE_SM_SC_LVL + int "Security level" + depends on BT_NIMBLE_SECURITY_ENABLE + default 0 + help + LE Security Mode 1 Levels: + 1. No Security + 2. Unauthenticated pairing with encryption + 3. Authenticated pairing with encryption + 4. Authenticated LE Secure Connections pairing with encryption using a 128-bit strength encryption key. + config BT_NIMBLE_DEBUG bool "Enable extra runtime asserts and host debugging" default n @@ -756,3 +767,91 @@ config BT_NIMBLE_HOST_QUEUE_CONG_CHECK When scanning and scan duplicate is not enabled, if there are a lot of adv packets around or application layer handling adv packets is slow, it will cause the controller memory to run out. if enabled, adv packets will be lost when host queue is congested. + +menu "Host-controller Transport" + config BT_NIMBLE_TRANSPORT_UART + bool "Enable Uart Transport" + default y + depends on BT_CONTROLLER_DISABLED + help + Use UART transport + + config BT_NIMBLE_TRANSPORT_UART_PORT + int "Uart port" + depends on BT_CONTROLLER_DISABLED && BT_NIMBLE_TRANSPORT_UART + default 1 + help + Uart port + + choice BT_NIMBLE_USE_HCI_UART_PARITY + prompt "Uart PARITY" + default UART_PARITY_NONE + help + Uart Parity + + config UART_PARITY_NONE + bool "None" + config UART_PARITY_ODD + bool "Odd" + config UART_PARITY_EVEN + bool "Even" + endchoice + + config BT_NIMBLE_TRANSPORT_UART_PARITY_NONE + int + default 0 if !UART_PARITY_NONE + default 1 if UART_PARITY_NONE + + config BT_NIMBLE_TRANSPORT_UART_PARITY_ODD + int + default 0 if !UART_PARITY_ODD + default 1 if UART_PARITY_ODD + + config BT_NIMBLE_TRANSPORT_UART_PARITY_EVEN + int + default 0 if !UART_PARITY_EVEN + default 1 if UART_PARITY_EVEN + + config BT_NIMBLE_UART_RX_PIN + int "UART Rx pin" + depends on BT_CONTROLLER_DISABLED && BT_NIMBLE_TRANSPORT_UART + default 5 + help + Rx pin for Nimble Transport + + config BT_NIMBLE_UART_TX_PIN + int "UART Tx pin" + depends on BT_CONTROLLER_DISABLED && BT_NIMBLE_TRANSPORT_UART + default 4 + help + Tx pin for Nimble Transport + + choice BT_NIMBLE_USE_HCI_UART_FLOW_CTRL + prompt "Uart Flow Control" + default UART_HW_FLOWCTRL_DISABLE + help + Uart Flow Control + + config UART_HW_FLOWCTRL_DISABLE + bool "Disable" + config UART_HW_FLOWCTRL_CTS_RTS + bool "Enable hardware flow control" + endchoice + + config BT_NIMBLE_HCI_UART_FLOW_CTRL + int + default 0 if UART_HW_FLOWCTRL_DISABLE + default 1 if UART_HW_FLOWCTRL_CTS_RTS + + config BT_NIMBLE_HCI_UART_RTS_PIN + int "UART Rts Pin" + default 19 + help + UART HCI RTS pin + + config BT_NIMBLE_HCI_UART_CTS_PIN + int "UART Cts Pin" + default 23 + help + UART HCI CTS pin +endmenu diff --git a/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c b/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c index cf580d6509..f0897d31a9 100644 --- a/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c +++ b/components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c @@ -15,7 +15,9 @@ #include "esp_nimble_hci.h" #include "esp_nimble_mem.h" #include "bt_osi_mem.h" +#if CONFIG_BT_CONTROLLER_ENABLED #include "esp_bt.h" +#endif #include "freertos/semphr.h" #include "esp_compiler.h" #include "soc/soc_caps.h" diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 31335a5a4f..c89851043b 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 31335a5a4fd0e063edc086d3c268399404db3bfd +Subproject commit c89851043b079a691d7eec788de36c1bba780956 diff --git a/components/bt/host/nimble/port/include/esp_nimble_cfg.h b/components/bt/host/nimble/port/include/esp_nimble_cfg.h index fead96289a..1279fca68e 100644 --- a/components/bt/host/nimble/port/include/esp_nimble_cfg.h +++ b/components/bt/host/nimble/port/include/esp_nimble_cfg.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -844,7 +844,7 @@ #ifndef MYNEWT_VAL_BLE_SM_SC_LVL -#define MYNEWT_VAL_BLE_SM_SC_LVL (0) +#define MYNEWT_VAL_BLE_SM_SC_LVL CONFIG_BT_NIMBLE_SM_SC_LVL #endif #ifndef MYNEWT_VAL_BLE_SM_SC_ONLY @@ -1773,4 +1773,38 @@ #endif #endif +#if CONFIG_BT_CONTROLLER_DISABLED +#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_PORT +#define MYNEWT_VAL_BLE_TRANSPORT_UART_PORT CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT +#endif + +#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__none +#define MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__none CONFIG_BT_NIMBLE_TRANSPORT_UART_PARITY_NONE +#endif + +#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__odd +#define MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__odd CONFIG_BT_NIMBLE_TRANSPORT_UART_PARITY_ODD +#endif + +#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__even +#define MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__even CONFIG_BT_NIMBLE_TRANSPORT_UART_PARITY_EVEN +#endif + +#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_FLOW_CONTROL__rtscts +#define MYNEWT_VAL_BLE_TRANSPORT_UART_FLOW_CONTROL__rtscts CONFIG_BT_NIMBLE_HCI_UART_FLOW_CTRL +#endif + +#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_BAUDRATE +#define MYNEWT_VAL_BLE_TRANSPORT_UART_BAUDRATE (921600) +#endif + +#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_DATA_BITS +#define MYNEWT_VAL_BLE_TRANSPORT_UART_DATA_BITS (3) +#endif + +#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_STOP_BITS +#define MYNEWT_VAL_BLE_TRANSPORT_UART_STOP_BITS (1) +#endif +#endif + #endif diff --git a/components/bt/porting/include/mem_api.h b/components/bt/porting/include/mem_api.h index ea19f2cff4..854074613a 100644 --- a/components/bt/porting/include/mem_api.h +++ b/components/bt/porting/include/mem_api.h @@ -11,7 +11,7 @@ extern "C" { #endif -#if SOC_ESP_NIMBLE_CONTROLLER +#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED struct os_mempool; struct os_mbuf_pool; diff --git a/components/bt/porting/nimble/include/nimble/ble_hci_trans.h b/components/bt/porting/nimble/include/nimble/ble_hci_trans.h index 60281c676d..5bbf922460 100644 --- a/components/bt/porting/nimble/include/nimble/ble_hci_trans.h +++ b/components/bt/porting/nimble/include/nimble/ble_hci_trans.h @@ -63,7 +63,7 @@ extern "C" { typedef int ble_hci_trans_rx_cmd_fn(uint8_t *cmd, void *arg); typedef int ble_hci_trans_rx_acl_fn(struct os_mbuf *om, void *arg); -#if SOC_ESP_NIMBLE_CONTROLLER +#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED #define ble_transport_alloc_cmd() ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD) #define ble_transport_alloc_event(X) ble_hci_trans_buf_alloc(X ? BLE_HCI_TRANS_BUF_EVT_LO : BLE_HCI_TRANS_BUF_EVT_HI) #define ble_transport_free ble_hci_trans_buf_free diff --git a/components/bt/porting/nimble/include/nimble/hci_common.h b/components/bt/porting/nimble/include/nimble/hci_common.h deleted file mode 100644 index 4cda1c731c..0000000000 --- a/components/bt/porting/nimble/include/nimble/hci_common.h +++ /dev/null @@ -1,2009 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2023 The Apache Software Foundation (ASF) - * - * SPDX-License-Identifier: Apache-2.0 - * - * SPDX-FileContributor: 2019-2022 Espressif Systems (Shanghai) CO LTD - */ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef H_BLE_HCI_COMMON_ -#define H_BLE_HCI_COMMON_ - -#include "ble.h" -#include "nimble/transport.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define BLE_HCI_MAX_DATA_LEN (MYNEWT_VAL(BLE_TRANSPORT_EVT_SIZE) - \ - sizeof(struct ble_hci_ev)) - -/* Generic command header */ -struct ble_hci_cmd { - uint16_t opcode; - uint8_t length; - uint8_t data[0]; -} __attribute__((packed)); - -/* Generic event header */ -struct ble_hci_ev { - uint8_t opcode; - uint8_t length; - uint8_t data[0]; -} __attribute__((packed)); - -#define BLE_HCI_OPCODE_NOP (0) - -/* Set opcode based on OCF and OGF */ -#define BLE_HCI_OP(ogf, ocf) ((ocf) | ((ogf) << 10)) - -/* Get the OGF and OCF from the opcode in the command */ -#define BLE_HCI_OGF(opcode) (((opcode) >> 10) & 0x003F) -#define BLE_HCI_OCF(opcode) ((opcode) & 0x03FF) - -/* Opcode Group definitions (note: 0x07 not defined in spec) */ -#define BLE_HCI_OGF_LINK_CTRL (0x01) -#define BLE_HCI_OGF_LINK_POLICY (0x02) -#define BLE_HCI_OGF_CTLR_BASEBAND (0x03) -#define BLE_HCI_OGF_INFO_PARAMS (0x04) -#define BLE_HCI_OGF_STATUS_PARAMS (0x05) -#define BLE_HCI_OGF_TESTING (0x06) -#define BLE_HCI_OGF_LE (0x08) -#define BLE_HCI_OGF_VENDOR (0x3F) - -/* - * Number of LE commands. NOTE: this is really just used to size the array - * containing the lengths of the LE commands. - */ -#define BLE_HCI_NUM_LE_CMDS (79) - -/* List of OCF for Link Control commands (OGF=0x01) */ -#define BLE_HCI_OCF_DISCONNECT_CMD (0x0006) -struct ble_hci_lc_disconnect_cp { - uint16_t conn_handle; - uint8_t reason; -} __attribute__((packed)); - -#define BLE_HCI_OCF_RD_REM_VER_INFO (0x001D) -struct ble_hci_rd_rem_ver_info_cp { - uint16_t conn_handle; -} __attribute__((packed)); - -/* List of OCF for Controller and Baseband commands (OGF=0x03) */ -#define BLE_HCI_OCF_CB_SET_EVENT_MASK (0x0001) -struct ble_hci_cb_set_event_mask_cp { - uint64_t event_mask; -} __attribute__((packed)); - -#define BLE_HCI_OCF_CB_RESET (0x0003) - -#define BLE_HCI_OCF_CB_READ_TX_PWR (0x002D) -struct ble_hci_cb_read_tx_pwr_cp { - uint16_t conn_handle; - uint8_t type; -} __attribute__((packed)); - -struct ble_hci_cb_read_tx_pwr_rp { - uint16_t conn_handle; - int8_t tx_level; -} __attribute__((packed)); - - -#define BLE_HCI_OCF_CB_SET_CTLR_TO_HOST_FC (0x0031) -struct ble_hci_cb_ctlr_to_host_fc_cp { - uint8_t enable; -} __attribute__((packed)); - -#define BLE_HCI_OCF_CB_HOST_BUF_SIZE (0x0033) -struct ble_hci_cb_host_buf_size_cp { - uint16_t acl_data_len; - uint8_t sco_data_len; - uint16_t acl_num; - uint16_t sco_num; -} __attribute__((packed)); - -#define BLE_HCI_OCF_CB_HOST_NUM_COMP_PKTS (0x0035) -struct ble_hci_cb_host_num_comp_pkts_entry { - uint16_t handle; - uint16_t count; -} __attribute__((packed)); -struct ble_hci_cb_host_num_comp_pkts_cp { - uint8_t handles; - struct ble_hci_cb_host_num_comp_pkts_entry h[0]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_CB_SET_EVENT_MASK2 (0x0063) -struct ble_hci_cb_set_event_mask2_cp { - uint64_t event_mask2; -} __attribute__((packed)); - -#define BLE_HCI_OCF_CB_RD_AUTH_PYLD_TMO (0x007B) -struct ble_hci_cb_rd_auth_pyld_tmo_cp { - uint16_t conn_handle; -} __attribute__((packed)); -struct ble_hci_cb_rd_auth_pyld_tmo_rp { - uint16_t conn_handle; - uint16_t tmo; -} __attribute__((packed)); - -#define BLE_HCI_OCF_CB_WR_AUTH_PYLD_TMO (0x007C) -struct ble_hci_cb_wr_auth_pyld_tmo_cp { - uint16_t conn_handle; - uint16_t tmo; -} __attribute__((packed)); -struct ble_hci_cb_wr_auth_pyld_tmo_rp { - uint16_t conn_handle; -} __attribute__((packed)); - -/* List of OCF for Info Param commands (OGF=0x04) */ -#define BLE_HCI_OCF_IP_RD_LOCAL_VER (0x0001) -struct ble_hci_ip_rd_local_ver_rp { - uint8_t hci_ver; - uint16_t hci_rev; - uint8_t lmp_ver; - uint16_t manufacturer; - uint16_t lmp_subver; -} __attribute__((packed)); - -#define BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD (0x0002) -struct ble_hci_ip_rd_loc_supp_cmd_rp { - uint8_t commands[64]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT (0x0003) -struct ble_hci_ip_rd_loc_supp_feat_rp { - uint64_t features; -} __attribute__((packed)); - -#define BLE_HCI_OCF_IP_RD_BUF_SIZE (0x0005) -struct ble_hci_ip_rd_buf_size_rp { - uint16_t acl_data_len; - uint8_t sco_data_len; - uint16_t acl_num; - uint16_t sco_num; -} __attribute__((packed)); - -#define BLE_HCI_OCF_IP_RD_BD_ADDR (0x0009) -struct ble_hci_ip_rd_bd_addr_rp { - uint8_t addr[6]; -} __attribute__((packed)); - -/* List of OCF for Status parameters commands (OGF = 0x05) */ -#define BLE_HCI_OCF_RD_RSSI (0x0005) -struct ble_hci_rd_rssi_cp { - uint16_t handle; -} __attribute__((packed)); -struct ble_hci_rd_rssi_rp { - uint16_t handle; - int8_t rssi; -} __attribute__((packed)); - -/* List of OCF for LE commands (OGF = 0x08) */ -#define BLE_HCI_OCF_LE_SET_EVENT_MASK (0x0001) -struct ble_hci_le_set_event_mask_cp { - uint64_t event_mask; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_BUF_SIZE (0x0002) -struct ble_hci_le_rd_buf_size_rp { - uint16_t data_len; - uint8_t data_packets; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_BUF_SIZE_V2 (0x0060) -struct ble_hci_le_rd_buf_size_v2_rp { - uint16_t data_len; - uint8_t data_packets; - uint16_t iso_data_len; - uint8_t iso_data_packets; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT (0x0003) -struct ble_hci_le_rd_loc_supp_feat_rp { - uint64_t features; -} __attribute__((packed)); - -/* NOTE: 0x0004 is intentionally left undefined */ -#define BLE_HCI_OCF_LE_SET_RAND_ADDR (0x0005) -struct ble_hci_le_set_rand_addr_cp { - uint8_t addr[6]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_ADV_PARAMS (0x0006) -struct ble_hci_le_set_adv_params_cp { - uint16_t min_interval; - uint16_t max_interval; - uint8_t type; - uint8_t own_addr_type; - uint8_t peer_addr_type; - uint8_t peer_addr[6]; - uint8_t chan_map; - uint8_t filter_policy; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR (0x0007) -struct ble_hci_le_rd_adv_chan_txpwr_rp { - int8_t power_level; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_ADV_DATA (0x0008) -#define BLE_HCI_MAX_ADV_DATA_LEN (31) -struct ble_hci_le_set_adv_data_cp { - uint8_t adv_data_len; - uint8_t adv_data[BLE_HCI_MAX_ADV_DATA_LEN]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_SCAN_RSP_DATA (0x0009) -#define BLE_HCI_MAX_SCAN_RSP_DATA_LEN (31) -struct ble_hci_le_set_scan_rsp_data_cp { - uint8_t scan_rsp_len; - uint8_t scan_rsp[BLE_HCI_MAX_SCAN_RSP_DATA_LEN]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_ADV_ENABLE (0x000A) -struct ble_hci_le_set_adv_enable_cp { - uint8_t enable; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_SCAN_PARAMS (0x000B) -struct ble_hci_le_set_scan_params_cp { - uint8_t scan_type; - uint16_t scan_itvl; - uint16_t scan_window; - uint8_t own_addr_type; - uint8_t filter_policy; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_SCAN_ENABLE (0x000C) -struct ble_hci_le_set_scan_enable_cp { - uint8_t enable; - uint8_t filter_duplicates; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_CREATE_CONN (0x000D) -struct ble_hci_le_create_conn_cp { - uint16_t scan_itvl; - uint16_t scan_window; - uint8_t filter_policy; - uint8_t peer_addr_type; - uint8_t peer_addr[6]; - uint8_t own_addr_type; - uint16_t min_conn_itvl; - uint16_t max_conn_itvl; - uint16_t conn_latency; - uint16_t tmo; - uint16_t min_ce; - uint16_t max_ce; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_CREATE_CONN_CANCEL (0x000E) - -#define BLE_HCI_OCF_LE_RD_WHITE_LIST_SIZE (0x000F) -struct ble_hci_le_rd_white_list_rp { - uint8_t size; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_CLEAR_WHITE_LIST (0x0010) - -#define BLE_HCI_OCF_LE_ADD_WHITE_LIST (0x0011) -struct ble_hci_le_add_whte_list_cp { - uint8_t addr_type; - uint8_t addr[6]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RMV_WHITE_LIST (0x0012) -struct ble_hci_le_rmv_white_list_cp { - uint8_t addr_type; - uint8_t addr[6]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_CONN_UPDATE (0x0013) -struct ble_hci_le_conn_update_cp { - uint16_t conn_handle; - uint16_t conn_itvl_min; - uint16_t conn_itvl_max; - uint16_t conn_latency; - uint16_t supervision_timeout; - uint16_t min_ce_len; - uint16_t max_ce_len; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_HOST_CHAN_CLASS (0x0014) -struct ble_hci_le_set_host_chan_class_cp { - uint8_t chan_map[5]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_CHAN_MAP (0x0015) -struct ble_hci_le_rd_chan_map_cp { - uint16_t conn_handle; -} __attribute__((packed)); -struct ble_hci_le_rd_chan_map_rp { - uint16_t conn_handle; - uint8_t chan_map[5]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_REM_FEAT (0x0016) -struct ble_hci_le_rd_rem_feat_cp { - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_ENCRYPT (0x0017) -struct ble_hci_le_encrypt_cp { - uint8_t key[16]; - uint8_t data[16]; -} __attribute__((packed)); -struct ble_hci_le_encrypt_rp { - uint8_t data[16]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RAND (0x0018) -struct ble_hci_le_rand_rp { - uint64_t random_number; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_START_ENCRYPT (0x0019) -struct ble_hci_le_start_encrypt_cp { - uint16_t conn_handle; - uint64_t rand; - uint16_t div; - uint8_t ltk[16]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY (0x001A) -struct ble_hci_le_lt_key_req_reply_cp { - uint16_t conn_handle; - uint8_t ltk[16]; -} __attribute__((packed)); -struct ble_hci_le_lt_key_req_reply_rp { - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY (0x001B) -struct ble_hci_le_lt_key_req_neg_reply_cp { - uint16_t conn_handle; -} __attribute__((packed)); -struct ble_hci_le_lt_key_req_neg_reply_rp { - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_SUPP_STATES (0x001C) -struct ble_hci_le_rd_supp_states_rp { - uint64_t states; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RX_TEST (0x001D) -struct ble_hci_le_rx_test_cp { - uint8_t rx_chan; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_TX_TEST (0x001E) -struct ble_hci_le_tx_test_cp { - uint8_t tx_chan; - uint8_t test_data_len; - uint8_t payload; -} __attribute__((packed)); -#if MYNEWT_VAL(BLE_LL_DTM_EXTENSIONS) -struct ble_hci_le_tx_test_ext_cp { - uint8_t tx_chan; - uint8_t test_data_len; - uint8_t payload; - uint16_t interval; - uint16_t pkt_count; -} __attribute__((packed)); -#endif - -#define BLE_HCI_OCF_LE_TEST_END (0x001F) -struct ble_hci_le_test_end_rp { - uint16_t num_packets; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_REM_CONN_PARAM_RR (0x0020) -struct ble_hci_le_rem_conn_param_rr_cp { - uint16_t conn_handle; - uint16_t conn_itvl_min; - uint16_t conn_itvl_max; - uint16_t conn_latency; - uint16_t supervision_timeout; - uint16_t min_ce; - uint16_t max_ce; -} __attribute__((packed)); -struct ble_hci_le_rem_conn_param_rr_rp { - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR (0x0021) -struct ble_hci_le_rem_conn_params_nrr_cp { - uint16_t conn_handle; - uint8_t reason; -} __attribute__((packed)); -struct ble_hci_le_rem_conn_params_nrr_rp { - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_DATA_LEN (0x0022) -struct ble_hci_le_set_data_len_cp { - uint16_t conn_handle; - uint16_t tx_octets; - uint16_t tx_time; -} __attribute__((packed)); -struct ble_hci_le_set_data_len_rp { - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN (0x0023) -struct ble_hci_le_rd_sugg_def_data_len_rp { - uint16_t max_tx_octets; - uint16_t max_tx_time; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN (0x0024) -struct ble_hci_le_wr_sugg_def_data_len_cp { - uint16_t max_tx_octets; - uint16_t max_tx_time; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_P256_PUBKEY (0x0025) - -#define BLE_HCI_OCF_LE_GEN_DHKEY (0x0026) -struct ble_hci_le_gen_dhkey_cp { - uint8_t pkey[64]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_ADD_RESOLV_LIST (0x0027) -struct ble_hci_le_add_resolv_list_cp { - uint8_t peer_addr_type; - uint8_t peer_id_addr[6]; - uint8_t peer_irk[16]; - uint8_t local_irk[16]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RMV_RESOLV_LIST (0x0028) -struct ble_hci_le_rmv_resolve_list_cp { - uint8_t peer_addr_type; - uint8_t peer_id_addr[6]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_CLR_RESOLV_LIST (0x0029) - -#define BLE_HCI_OCF_LE_RD_RESOLV_LIST_SIZE (0x002A) -struct ble_hci_le_rd_resolv_list_size_rp { - uint8_t size; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_PEER_RESOLV_ADDR (0x002B) -struct ble_hci_le_rd_peer_resolv_addr_cp { - uint8_t peer_addr_type; - uint8_t peer_id_addr[6]; -} __attribute__((packed)); -struct ble_hci_le_rd_peer_resolv_addr_rp { - uint8_t rpa[6]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_LOCAL_RESOLV_ADDR (0x002C) -struct ble_hci_le_rd_local_resolv_addr_cp { - uint8_t peer_addr_type; - uint8_t peer_id_addr[6]; -} __attribute__((packed)); -struct ble_hci_le_rd_local_resolv_addr_rp { - uint8_t rpa[6]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_ADDR_RES_EN (0x002D) -struct ble_hci_le_set_addr_res_en_cp { - uint8_t enable; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_RPA_TMO (0x002E) -struct ble_hci_le_set_rpa_tmo_cp { - uint16_t rpa_timeout; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_MAX_DATA_LEN (0x002F) -struct ble_hci_le_rd_max_data_len_rp { - uint16_t max_tx_octests; - uint16_t max_tx_time; - uint16_t max_rx_octests; - uint16_t max_rx_time; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_PHY (0x0030) -struct ble_hci_le_rd_phy_cp { - uint16_t conn_handle; -} __attribute__((packed)); -struct ble_hci_le_rd_phy_rp { - uint16_t conn_handle; - uint8_t tx_phy; - uint8_t rx_phy; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_DEFAULT_PHY (0x0031) -struct ble_hci_le_set_default_phy_cp { - uint8_t all_phys; - uint8_t tx_phys; - uint8_t rx_phys; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_PHY (0x0032) -struct ble_hci_le_set_phy_cp { - uint16_t conn_handle; - uint8_t all_phys; - uint8_t tx_phys; - uint8_t rx_phys; - uint16_t phy_options; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RX_TEST_V2 (0x0033) -struct ble_hci_le_rx_test_v2_cp { - uint8_t rx_chan; - uint8_t phy; - uint8_t index; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_TX_TEST_V2 (0x0034) -struct ble_hci_le_tx_test_v2_cp { - uint8_t tx_chan; - uint8_t test_data_len; - uint8_t payload; - uint8_t phy; -} __attribute__((packed)); -#if MYNEWT_VAL(BLE_LL_DTM_EXTENSIONS) -struct ble_hci_le_tx_test_v2_ext_cp { - uint8_t tx_chan; - uint8_t test_data_len; - uint8_t payload; - uint8_t phy; - uint16_t interval; - uint16_t pkt_count; -} __attribute__((packed)); -#endif - -#define BLE_HCI_OCF_LE_SET_ADV_SET_RND_ADDR (0x0035) -struct ble_hci_le_set_adv_set_rnd_addr_cp { - uint8_t adv_handle; - uint8_t addr[6]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_EXT_ADV_PARAM (0x0036) -struct ble_hci_le_set_ext_adv_params_cp { - uint8_t adv_handle; - uint16_t props; - uint8_t pri_itvl_min[3]; - uint8_t pri_itvl_max[3]; - uint8_t pri_chan_map; - uint8_t own_addr_type; - uint8_t peer_addr_type; - uint8_t peer_addr[6]; - uint8_t filter_policy; - int8_t tx_power; - uint8_t pri_phy; - uint8_t sec_max_skip; - uint8_t sec_phy; - uint8_t sid; - uint8_t scan_req_notif; -} __attribute__((packed)); -struct ble_hci_le_set_ext_adv_params_rp { - int8_t tx_power; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_EXT_ADV_DATA (0x0037) -struct ble_hci_le_set_ext_adv_data_cp { - uint8_t adv_handle; - uint8_t operation; - uint8_t fragment_pref; - uint8_t adv_data_len; - uint8_t adv_data[0]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_EXT_SCAN_RSP_DATA (0x0038) -struct ble_hci_le_set_ext_scan_rsp_data_cp { - uint8_t adv_handle; - uint8_t operation; - uint8_t fragment_pref; - uint8_t scan_rsp_len; - uint8_t scan_rsp[0]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_EXT_ADV_ENABLE (0x0039) -struct adv_set { - uint8_t adv_handle; - uint16_t duration; - uint8_t max_events; -} __attribute__((packed)); -struct ble_hci_le_set_ext_adv_enable_cp { - uint8_t enable; - uint8_t num_sets; - struct adv_set sets[0]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_MAX_ADV_DATA_LEN (0x003A) -struct ble_hci_le_rd_max_adv_data_len_rp { - uint16_t max_adv_data_len; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_NUM_OF_ADV_SETS (0x003B) -struct ble_hci_le_rd_num_of_adv_sets_rp { - uint8_t num_sets; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_REMOVE_ADV_SET (0x003C) -struct ble_hci_le_remove_adv_set_cp { - uint8_t adv_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_CLEAR_ADV_SETS (0x003D) - -#define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS (0x003E) -struct ble_hci_le_set_periodic_adv_params_cp { - uint8_t adv_handle; - uint16_t min_itvl; - uint16_t max_itvl; - uint16_t props; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_DATA (0x003F) -struct ble_hci_le_set_periodic_adv_data_cp { - uint8_t adv_handle; - uint8_t operation; - uint8_t adv_data_len; - uint8_t adv_data[0]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_ENABLE (0x0040) -struct ble_hci_le_set_periodic_adv_enable_cp { - uint8_t enable; - uint8_t adv_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_EXT_SCAN_PARAM (0x0041) -struct scan_params { - uint8_t type; - uint16_t itvl; - uint16_t window; -} __attribute__((packed)); -struct ble_hci_le_set_ext_scan_params_cp { - uint8_t own_addr_type; - uint8_t filter_policy; - uint8_t phys; - struct scan_params scans[0]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_EXT_SCAN_ENABLE (0x0042) -struct ble_hci_le_set_ext_scan_enable_cp { - uint8_t enable; - uint8_t filter_dup; - uint16_t duration; - uint16_t period; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_EXT_CREATE_CONN (0x0043) -struct conn_params { - uint16_t scan_itvl; - uint16_t scan_window; - uint16_t conn_min_itvl; - uint16_t conn_max_itvl; - uint16_t conn_latency; - uint16_t supervision_timeout; - uint16_t min_ce; - uint16_t max_ce; -} __attribute__((packed)); -struct ble_hci_le_ext_create_conn_cp { - uint8_t filter_policy; - uint8_t own_addr_type; - uint8_t peer_addr_type; - uint8_t peer_addr[6]; - uint8_t init_phy_mask; - struct conn_params conn_params[0]; -} __attribute__((packed)); - -#define BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_FILTER 0x01 -#define BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_DISABLED 0x02 - -#define BLE_HCI_OCF_LE_PERIODIC_ADV_CREATE_SYNC (0x0044) -struct ble_hci_le_periodic_adv_create_sync_cp { - uint8_t options; - uint8_t sid; - uint8_t peer_addr_type; - uint8_t peer_addr[6]; - uint16_t skip; - uint16_t sync_timeout; - uint8_t sync_cte_type; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL (0x0045) - -#define BLE_HCI_OCF_LE_PERIODIC_ADV_TERM_SYNC (0x0046) -struct ble_hci_le_periodic_adv_term_sync_cp { - uint16_t sync_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_ADD_DEV_TO_PERIODIC_ADV_LIST (0x0047) -struct ble_hci_le_add_dev_to_periodic_adv_list_cp { - uint8_t peer_addr_type; - uint8_t peer_addr[6]; - uint8_t sid; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_REM_DEV_FROM_PERIODIC_ADV_LIST (0x0048) -struct ble_hci_le_rem_dev_from_periodic_adv_list_cp { - uint8_t peer_addr_type; - uint8_t peer_addr[6]; - uint8_t sid; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_CLEAR_PERIODIC_ADV_LIST (0x0049) - -#define BLE_HCI_OCF_LE_RD_PERIODIC_ADV_LIST_SIZE (0x004A) -struct ble_hci_le_rd_periodic_adv_list_size_rp { - uint8_t list_size; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_TRANSMIT_POWER (0x004B) -struct ble_hci_le_rd_transmit_power_rp { - int8_t min_tx_power; - int8_t max_tx_power; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RD_RF_PATH_COMPENSATION (0x004C) -struct ble_hci_le_rd_rf_path_compensation_rp { - int16_t tx_path_compensation; - int16_t rx_path_compensation; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_WR_RF_PATH_COMPENSATION (0x004D) -struct ble_hci_le_wr_rf_path_compensation_cp { - int16_t tx_path_compensation; - int16_t rx_path_compensation; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_PRIVACY_MODE (0x004E) -struct ble_hci_le_set_privacy_mode_cp { - uint8_t peer_id_addr_type; - uint8_t peer_id_addr[6]; - uint8_t mode; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_RX_TEST_V3 (0x004F) -#define BLE_HCI_OCF_LE_TX_TEST_V3 (0x0050) -#define BLE_HCI_OCF_LE_SET_CONNLESS_CTE_TX_PARAMS (0x0051) -#define BLE_HCI_OCF_LE_SET_CONNLESS_CTE_TX_ENABLE (0x0052) -#define BLE_HCI_OCF_LE_SET_CONNLESS_IQ_SAMPLING_ENABLE (0x0053) -#define BLE_HCI_OCF_LE_SET_CONN_CTE_RX_PARAMS (0x0054) -#define BLE_HCI_OCF_LE_SET_CONN_CTE_TX_PARAMS (0x0055) -#define BLE_HCI_OCF_LE_SET_CONN_CTE_REQ_ENABLE (0x0056) -#define BLE_HCI_OCF_LE_SET_CONN_CTE_RESP_ENABLE (0x0057) -#define BLE_HCI_OCF_LE_RD_ANTENNA_INFO (0x0058) - -#define BLE_HCI_OCF_LE_PERIODIC_ADV_RECEIVE_ENABLE (0x0059) -struct ble_hci_le_periodic_adv_receive_enable_cp { - uint16_t sync_handle; - uint8_t enable; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_PERIODIC_ADV_SYNC_TRANSFER (0x005A) -struct ble_hci_le_periodic_adv_sync_transfer_cp { - uint16_t conn_handle; - uint16_t service_data; - uint16_t sync_handle; -} __attribute__((packed)); -struct ble_hci_le_periodic_adv_sync_transfer_rp { - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_PERIODIC_ADV_SET_INFO_TRANSFER (0x005B) -struct ble_hci_le_periodic_adv_set_info_transfer_cp { - uint16_t conn_handle; - uint16_t service_data; - uint8_t adv_handle; -} __attribute__((packed)); -struct ble_hci_le_periodic_adv_set_info_transfer_rp { - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_PERIODIC_ADV_SYNC_TRANSFER_PARAMS (0x005C) -struct ble_hci_le_periodic_adv_sync_transfer_params_cp { - uint16_t conn_handle; - uint8_t mode; - uint16_t skip; - uint16_t sync_timeout; - uint8_t sync_cte_type; -} __attribute__((packed)); -struct ble_hci_le_periodic_adv_sync_transfer_params_rp { - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_DEFAULT_SYNC_TRANSFER_PARAMS (0x005D) -struct ble_hci_le_set_default_periodic_sync_transfer_params_cp { - uint8_t mode; - uint16_t skip; - uint16_t sync_timeout; - uint8_t sync_cte_type; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_GENERATE_DHKEY_V2 (0x005E) -#define BLE_HCI_OCF_LE_MODIFY_SCA (0x005F) - -#if MYNEWT_VAL(BLE_ISO) -#define BLE_HCI_OCF_LE_READ_ISO_TX_SYNC (0x0061) -struct ble_hci_le_read_iso_tx_sync_cp { - uint16_t conn_handle; -} __attribute__((packed)); - -struct ble_hci_le_read_iso_tx_sync_rp { - uint16_t conn_handle; - uint16_t packet_seq_num; - uint32_t timestamp; - uint8_t timeoffset[3]; -} __attribute__((packed)); - -#define BLE_HCI_LE_SET_CIG_CIS_MAX_NUM (0x1F) -#define BLE_HCI_OCF_LE_SET_CIG_PARAM (0x0062) -struct ble_hci_le_cis_params { - uint8_t cis_id; - uint16_t max_sdu_mtos; - uint16_t max_sdu_stom; - uint8_t phy_mtos; - uint8_t phy_stom; - uint8_t rnt_mtos; - uint8_t rnt_stom; -} __attribute__((packed)); - -struct ble_hci_le_set_cig_params_cp { - uint8_t cig_id; - uint8_t sdu_interval_mtos[3]; - uint8_t sdu_interval_stom[3]; - uint8_t sca; - uint8_t packing; - uint8_t framing; - uint16_t max_latency_mtos; - uint16_t max_latency_stom; - uint8_t cis_cnt; - struct ble_hci_le_cis_params cis_params[0]; -} __attribute__((packed)); - -struct ble_hci_le_set_cig_params_rp { - uint8_t cig_id; - uint8_t cis_cnt; - uint16_t cis_handle[0]; -} __attribute__((packed)); - -#if MYNEWT_VAL(BLE_ISO_TEST) -#define BLE_HCI_OCF_LE_SET_CIG_PARAM_TEST (0x0063) -struct ble_hci_le_cis_params_test { - uint8_t cis_id; - uint8_t nse; - uint16_t max_sdu_mtos; - uint16_t max_sdu_stom; - uint16_t max_pdu_mtos; - uint16_t max_pdu_stom; - uint8_t phy_mtos; - uint8_t phy_stom; - uint8_t bn_mtos; - uint8_t bn_stom; -} __attribute__((packed)); - -struct ble_hci_le_set_cig_params_test_cp { - uint8_t cig_id; - uint8_t sdu_interval_mtos[3]; - uint8_t sdu_interval_stom[3]; - uint8_t ft_mtos; - uint8_t ft_stom; - uint16_t iso_interval; - uint8_t sca; - uint8_t packing; - uint8_t framing; - uint8_t cis_cnt; - struct ble_hci_le_cis_params_test cis_params[0]; -} __attribute__((packed)); -#endif - -#define BLE_HCI_LE_CREATE_CIS_MAX_CIS_NUM (0x1F) -#define BLE_HCI_OCF_LE_CREATE_CIS (0x0064) -struct ble_hci_le_create_cis_params { - uint16_t cis_handle; - uint16_t conn_handle; -} __attribute__((packed)); - -struct ble_hci_le_create_cis_cp { - uint8_t cis_cnt; - struct ble_hci_le_create_cis_params params[0]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_REMOVE_CIG (0x0065) -struct ble_hci_le_remove_cig_cp { - uint8_t cig_id; -} __attribute__((packed)); - -struct ble_hci_le_remove_cig_rp { - uint8_t cig_id; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_ACCEPT_CIS_REQ (0x0066) -struct ble_hci_le_accept_cis_request_cp { - uint16_t cis_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_REJECT_CIS_REQ (0x0067) -struct ble_hci_le_reject_cis_request_cp { - uint16_t cis_handle; - uint8_t reason; -} __attribute__((packed)); - -struct ble_hci_le_reject_cis_request_rp { - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_CREATE_BIG (0x0068) -struct ble_hci_le_create_big_cp { - uint8_t big_handle; - uint8_t adv_handle; - uint8_t bis_cnt; - uint8_t sdu_interval[3]; - uint16_t max_sdu; - uint16_t max_transport_latency; - uint8_t rnt; - uint8_t phy; - uint8_t packing; - uint8_t framing; - uint8_t encryption; - uint8_t broadcast_code[16]; -} __attribute__((packed)); - -#if MYNEWT_VAL(BLE_ISO_TEST) -#define BLE_HCI_OCF_LE_CREATE_BIG_TEST (0x0069) -struct ble_hci_le_create_big_test_cp { - uint8_t big_handle; - uint8_t adv_handle; - uint8_t bis_cnt; - uint8_t sdu_interval[3]; - uint16_t iso_interval; - uint8_t nse; - uint16_t max_sdu; - uint16_t max_pdu; - uint8_t phy; - uint8_t packing; - uint8_t framing; - uint8_t bn; - uint8_t irc; - uint8_t pto; - uint8_t encryption; - uint8_t broadcast_code[16]; -} __attribute__((packed)); -#endif - -#define BLE_HCI_OCF_LE_TERMINATE_BIG (0x006a) -struct ble_hci_le_terminate_big_cp { - uint8_t big_handle; - uint8_t reason; -} __attribute__((packed)); - -#define BLE_HCI_LE_BIG_CREATE_SYNC_LEN_MIN (25) -#define BLE_HCI_OCF_LE_BIG_CREATE_SYNC (0x006b) -struct ble_hci_le_big_create_sync_cp { - uint8_t big_handle; - uint16_t sync_handle; - uint8_t big_cnt; - uint8_t encryption; - uint8_t broadcast_code[16]; - uint8_t mse; - uint16_t timeout; - uint8_t bis[0]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_BIG_TERMINATE_SYNC (0x006c) -struct ble_hci_le_terminate_big_sync_cp { - uint8_t big_handle; -} __attribute__((packed)); -#endif - -#define BLE_HCI_OCF_LE_REQ_PEER_SCA (0x006d) -struct ble_hci_le_request_peer_sca_cp { - uint16_t conn_handle; -} __attribute__((packed)); - -#if MYNEWT_VAL(BLE_ISO) -#define BLE_HCI_OCF_LE_SETUP_ISO_DATA_PATH (0x006e) -struct ble_hci_le_iso_setup_data_path_cp { - uint16_t iso_handle; - uint8_t direction; - uint8_t id; - uint8_t codec_id[5]; - uint8_t controller_delay[3]; - uint8_t codec_conf_len; - uint8_t codec_conf[0]; -} __attribute__((packed)); - -#define BLE_HCI_LE_REMOVE_INPUT_DATA_PATH_BIT (0x01) -#define BLE_HCI_LE_REMOVE_OUTPUT_DATA_PATH_BIT (0x02) -#define BLE_HCI_OCF_LE_REMOVE_ISO_DATA_PATH (0x006f) -struct ble_hci_le_iso_remove_data_path_cp { - uint16_t iso_handle; - uint8_t direction; -} __attribute__((packed)); - -#if MYNEWT_VAL(BLE_ISO_TEST) -#define BLE_HCI_OCF_LE_ISO_TRANSMIT_TEST (0x0070) -struct ble_hci_le_iso_transmit_test_cp { - uint16_t iso_handle; - uint8_t payload_type; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_ISO_RECEIVE_TEST (0x0071) -struct ble_hci_le_iso_receive_test_cp { - uint16_t iso_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_ISO_READ_TEST_COUNTERS (0x0072) -struct ble_hci_le_iso_read_test_counters_cp { - uint16_t iso_handle; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_ISO_TEST_END (0x0073) -struct ble_hci_le_iso_test_end_cp { - uint16_t iso_handle; -} __attribute__((packed)); -#endif -#endif - -#define BLE_HCI_OCF_LE_SET_HOST_FEAT (0x0074) -struct ble_hci_le_set_host_feat_cp { - uint8_t bit_num; - uint8_t val; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_ENH_READ_TRANSMIT_POWER_LEVEL (0x0076) -struct ble_hci_le_enh_read_transmit_power_level_cp { - uint16_t conn_handle; - uint8_t phy; -} __attribute__((packed)); -struct ble_hci_le_enh_read_transmit_power_level_rp { - uint16_t conn_handle; - uint8_t phy; - uint8_t curr_tx_power_level; - uint8_t max_tx_power_level; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_READ_REMOTE_TRANSMIT_POWER_LEVEL (0x0077) -struct ble_hci_le_read_remote_transmit_power_level_cp { - uint16_t conn_handle; - uint8_t phy; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_PATH_LOSS_REPORT_PARAM (0x0078) -struct ble_hci_le_set_path_loss_report_param_cp { - uint16_t conn_handle; - uint8_t high_threshold; - uint8_t high_hysteresis; - uint8_t low_threshold; - uint8_t low_hysteresis; - uint16_t min_time_spent; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_PATH_LOSS_REPORT_ENABLE (0x0079) -struct ble_hci_le_set_path_loss_report_enable_cp { - uint16_t conn_handle; - uint8_t enable; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_TRANS_PWR_REPORT_ENABLE (0x007A) -struct ble_hci_le_set_transmit_power_report_enable_cp { - uint16_t conn_handle; - uint8_t local_enable; - uint8_t remote_enable; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_DATA_ADDR_CHANGE (0x007C) -struct ble_hci_le_set_data_addr_change_cp { - uint8_t adv_handle; - uint8_t change_reason; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SET_DEFAULT_SUBRATE (0x007D) -struct ble_hci_le_set_default_subrate_cp { - uint16_t subrate_min; - uint16_t subrate_max; - uint16_t max_latency; - uint16_t cont_num; - uint16_t supervision_tmo; -} __attribute__((packed)); - -#define BLE_HCI_OCF_LE_SUBRATE_REQ (0x007E) -struct ble_hci_le_subrate_req_cp { - uint16_t conn_handle; - uint16_t subrate_min; - uint16_t subrate_max; - uint16_t max_latency; - uint16_t cont_num; - uint16_t supervision_tmo; -} __attribute__((packed)); - -/* --- Vendor specific commands (OGF 0x003F) */ -/* Read Random Static Address */ -#define BLE_HCI_OCF_VS_RD_STATIC_ADDR (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0001)) -struct ble_hci_vs_rd_static_addr_rp { - uint8_t addr[6]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_VS_DUPLICATE_EXCEPTION_LIST (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0108)) -struct ble_hci_vs_duplicate_exception_list_cp { - uint8_t operation; - uint32_t type; - uint8_t device_info[6]; -} __attribute__((packed)); - -#define BLE_HCI_OCF_VS_LEGACY_ADV_CLEAR (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x010C)) - -#if SOC_BLE_POWER_CONTROL_SUPPORTED -#define BLE_HCI_OCF_VS_PCL_SET_RSSI (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0111)) -#endif - -#define BLE_HCI_OCF_VS_SET_CHAN_SELECT (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0112)) - -/* Command Specific Definitions */ -/* --- Set controller to host flow control (OGF 0x03, OCF 0x0031) --- */ -#define BLE_HCI_CTLR_TO_HOST_FC_OFF (0) -#define BLE_HCI_CTLR_TO_HOST_FC_ACL (1) -#define BLE_HCI_CTLR_TO_HOST_FC_SYNC (2) -#define BLE_HCI_CTLR_TO_HOST_FC_BOTH (3) - -/* --- LE set advertising parameters (OCF 0x0006) */ -/* Advertising types */ -#define BLE_HCI_ADV_TYPE_ADV_IND (0) -#define BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD (1) -#define BLE_HCI_ADV_TYPE_ADV_SCAN_IND (2) -#define BLE_HCI_ADV_TYPE_ADV_NONCONN_IND (3) -#define BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD (4) -#define BLE_HCI_ADV_TYPE_MAX (4) - -#define BLE_HCI_ADV_CONN_MASK (0x0001) -#define BLE_HCI_ADV_SCAN_MASK (0x0002) -#define BLE_HCI_ADV_DIRECT_MASK (0x0004) -#define BLE_HCI_ADV_SCAN_RSP_MASK (0x0008) -#define BLE_HCI_ADV_LEGACY_MASK (0x0010) - -#define BLE_HCI_ADV_DATA_STATUS_COMPLETE (0x0000) -#define BLE_HCI_ADV_DATA_STATUS_INCOMPLETE (0x0020) -#define BLE_HCI_ADV_DATA_STATUS_TRUNCATED (0x0040) -#define BLE_HCI_ADV_DATA_STATUS_MASK (0x0060) - -/* Own address types */ -#define BLE_HCI_ADV_OWN_ADDR_PUBLIC (0) -#define BLE_HCI_ADV_OWN_ADDR_RANDOM (1) -#define BLE_HCI_ADV_OWN_ADDR_PRIV_PUB (2) -#define BLE_HCI_ADV_OWN_ADDR_PRIV_RAND (3) -#define BLE_HCI_ADV_OWN_ADDR_MAX (3) - -/* Advertisement peer address Type */ -#define BLE_HCI_ADV_PEER_ADDR_PUBLIC (0) -#define BLE_HCI_ADV_PEER_ADDR_RANDOM (1) -#define BLE_HCI_ADV_PEER_ADDR_MAX (1) - -/* --- LE advertising channel tx power (OCF 0x0007) */ -#define BLE_HCI_ADV_CHAN_TXPWR_MIN (-20) -#define BLE_HCI_ADV_CHAN_TXPWR_MAX (10) - -/* --- LE set scan enable (OCF 0x000c) */ - -/* Connect peer address type */ -#define BLE_HCI_CONN_PEER_ADDR_PUBLIC (0) -#define BLE_HCI_CONN_PEER_ADDR_RANDOM (1) -#define BLE_HCI_CONN_PEER_ADDR_PUBLIC_IDENT (2) -#define BLE_HCI_CONN_PEER_ADDR_RANDOM_IDENT (3) -#define BLE_HCI_CONN_PEER_ADDR_MAX (3) - -/* - * Advertising filter policy - * - * Determines how an advertiser filters scan and connection requests. - * - * NONE: no filtering (default value). No whitelist used. - * SCAN: process all connection requests but only scans from white list. - * CONN: process all scan request but only connection requests from white list - * BOTH: ignore all scan and connection requests unless in white list. - */ -#define BLE_HCI_ADV_FILT_NONE (0) -#define BLE_HCI_ADV_FILT_SCAN (1) -#define BLE_HCI_ADV_FILT_CONN (2) -#define BLE_HCI_ADV_FILT_BOTH (3) -#define BLE_HCI_ADV_FILT_MAX (3) - -#define BLE_HCI_ADV_FILT_DEF (BLE_HCI_ADV_FILT_NONE) - -/* Advertising interval */ -#define BLE_HCI_ADV_ITVL (625) /* usecs */ -#define BLE_HCI_ADV_ITVL_MIN (32) /* units */ -#define BLE_HCI_ADV_ITVL_MAX (16384) /* units */ -#define BLE_HCI_ADV_ITVL_NONCONN_MIN (160) /* units */ - -#define BLE_HCI_ADV_ITVL_DEF (0x800) /* 1.28 seconds */ -#define BLE_HCI_ADV_CHANMASK_DEF (0x7) /* all channels */ - -#define BLE_HCI_PERIODIC_ADV_ITVL (1250) /* usecs */ - -/* Set scan parameters */ -#define BLE_HCI_SCAN_TYPE_PASSIVE (0) -#define BLE_HCI_SCAN_TYPE_ACTIVE (1) - -/* Scan interval and scan window timing */ -#define BLE_HCI_SCAN_ITVL (625) /* usecs */ -#define BLE_HCI_SCAN_ITVL_MIN (4) /* units */ -#define BLE_HCI_SCAN_ITVL_MAX (16384) /* units */ -#define BLE_HCI_SCAN_ITVL_DEF (16) /* units */ -#define BLE_HCI_SCAN_WINDOW_MIN (4) /* units */ -#define BLE_HCI_SCAN_WINDOW_MAX (16384) /* units */ -#define BLE_HCI_SCAN_WINDOW_DEF (16) /* units */ - -/* - * Scanning filter policy - * NO_WL: - * Scanner processes all advertising packets (white list not used) except - * directed, connectable advertising packets not sent to the scanner. - * USE_WL: - * Scanner processes advertisements from white list only. A connectable, - * directed advertisment is ignored unless it contains scanners address. - * NO_WL_INITA: - * Scanner process all advertising packets (white list not used). A - * connectable, directed advertisement shall not be ignored if the InitA - * is a resolvable private address. - * USE_WL_INITA: - * Scanner process advertisements from white list only. A connectable, - * directed advertisement shall not be ignored if the InitA is a - * resolvable private address. - */ -#define BLE_HCI_SCAN_FILT_NO_WL (0) -#define BLE_HCI_SCAN_FILT_USE_WL (1) -#define BLE_HCI_SCAN_FILT_NO_WL_INITA (2) -#define BLE_HCI_SCAN_FILT_USE_WL_INITA (3) -#define BLE_HCI_SCAN_FILT_MAX (3) - -/* Whitelist commands */ -#define BLE_HCI_ADD_WHITE_LIST_LEN (7) -#define BLE_HCI_RMV_WHITE_LIST_LEN (7) - -/* Create Connection */ -#define BLE_HCI_CREATE_CONN_LEN (25) -#define BLE_HCI_CONN_ITVL (1250) /* usecs */ -#define BLE_HCI_CONN_FILT_NO_WL (0) -#define BLE_HCI_CONN_FILT_USE_WL (1) -#define BLE_HCI_CONN_FILT_MAX (1) -#define BLE_HCI_CONN_ITVL_MIN (0x0006) -#define BLE_HCI_CONN_ITVL_MAX (0x0c80) -#define BLE_HCI_CONN_LATENCY_MIN (0x0000) -#define BLE_HCI_CONN_LATENCY_MAX (0x01f3) -#define BLE_HCI_CONN_SPVN_TIMEOUT_MIN (0x000a) -#define BLE_HCI_CONN_SPVN_TIMEOUT_MAX (0x0c80) -#define BLE_HCI_CONN_SPVN_TMO_UNITS (10) /* msecs */ -#define BLE_HCI_INITIATOR_FILT_POLICY_MAX (1) - -/* Peer Address Type */ -#define BLE_HCI_CONN_PEER_ADDR_PUBLIC (0) -#define BLE_HCI_CONN_PEER_ADDR_RANDOM (1) -#define BLE_HCI_CONN_PEER_ADDR_PUB_ID (2) -#define BLE_HCI_CONN_PEER_ADDR_RAND_ID (3) -#define BLE_HCI_CONN_PEER_ADDR_MAX (3) - - -/* --- LE set data length (OCF 0x0022) */ -#define BLE_HCI_SET_DATALEN_TX_OCTETS_MIN (0x001b) -#define BLE_HCI_SET_DATALEN_TX_OCTETS_MAX (0x00fb) -#define BLE_HCI_SET_DATALEN_TX_TIME_MIN (0x0148) -#define BLE_HCI_SET_DATALEN_TX_TIME_MAX (0x4290) - -/* --- LE read/write suggested default data length (OCF 0x0023 and 0x0024) */ -#define BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MIN (0x001b) -#define BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MAX (0x00fb) -#define BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MIN (0x0148) -#define BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MAX (0x4290) - -/* --- LE read maximum default PHY (OCF 0x0030) */ -#define BLE_HCI_LE_PHY_1M (1) -#define BLE_HCI_LE_PHY_2M (2) -#define BLE_HCI_LE_PHY_CODED (3) - -/* --- LE set default PHY (OCF 0x0031) */ -#define BLE_HCI_LE_PHY_NO_TX_PREF_MASK (0x01) -#define BLE_HCI_LE_PHY_NO_RX_PREF_MASK (0x02) -#define BLE_HCI_LE_PHY_1M_PREF_MASK (0x01) -#define BLE_HCI_LE_PHY_2M_PREF_MASK (0x02) -#define BLE_HCI_LE_PHY_CODED_PREF_MASK (0x04) - -#define BLE_HCI_LE_PHY_PREF_MASK_ALL \ - (BLE_HCI_LE_PHY_1M_PREF_MASK | BLE_HCI_LE_PHY_2M_PREF_MASK | \ - BLE_HCI_LE_PHY_CODED_PREF_MASK) - -/* --- LE set PHY (OCF 0x0032) */ -#define BLE_HCI_LE_PHY_CODED_ANY (0x0000) -#define BLE_HCI_LE_PHY_CODED_S2_PREF (0x0001) -#define BLE_HCI_LE_PHY_CODED_S8_PREF (0x0002) - -/* --- LE enhanced receiver test (OCF 0x0033) */ -#define BLE_HCI_LE_PHY_1M (1) -#define BLE_HCI_LE_PHY_2M (2) -#define BLE_HCI_LE_PHY_CODED (3) - -/* --- LE enhanced transmitter test (OCF 0x0034) */ -#define BLE_HCI_LE_PHY_CODED_S8 (3) -#define BLE_HCI_LE_PHY_CODED_S2 (4) - -/* --- LE set extended advertising parameters (OCF 0x0036) */ -#define BLE_HCI_LE_SET_EXT_ADV_PROP_CONNECTABLE (0x0001) -#define BLE_HCI_LE_SET_EXT_ADV_PROP_SCANNABLE (0x0002) -#define BLE_HCI_LE_SET_EXT_ADV_PROP_DIRECTED (0x0004) -#define BLE_HCI_LE_SET_EXT_ADV_PROP_HD_DIRECTED (0x0008) -#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY (0x0010) -#define BLE_HCI_LE_SET_EXT_ADV_PROP_ANON_ADV (0x0020) -#define BLE_HCI_LE_SET_EXT_ADV_PROP_INC_TX_PWR (0x0040) -#define BLE_HCI_LE_SET_EXT_ADV_PROP_MASK (0x7F) - -#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_IND (0x0013) -#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_LD_DIR (0x0015) -#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_HD_DIR (0x001d) -#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_SCAN (0x0012) -#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_NONCONN (0x0010) - -/* --- LE set extended advertising data (OCF 0x0037) */ -#define BLE_HCI_MAX_EXT_ADV_DATA_LEN (251) - -#define BLE_HCI_LE_SET_DATA_OPER_INT (0) -#define BLE_HCI_LE_SET_DATA_OPER_FIRST (1) -#define BLE_HCI_LE_SET_DATA_OPER_LAST (2) -#define BLE_HCI_LE_SET_DATA_OPER_COMPLETE (3) -#define BLE_HCI_LE_SET_DATA_OPER_UNCHANGED (4) - -/* --- LE set extended scan response data (OCF 0x0038) */ -#define BLE_HCI_MAX_EXT_SCAN_RSP_DATA_LEN (251) - -/* --- LE set periodic advertising parameters (OCF 0x003E) */ -#define BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR (0x0040) -#define BLE_HCI_LE_SET_PERIODIC_ADV_PROP_MASK (0x0040) - -/* --- LE set periodic advertising data (OCF 0x003F) */ -#define BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN (252) - -/* --- LE remove device from periodic advertising list (OCF 0x0048) */ -#define BLE_HCI_PERIODIC_DATA_STATUS_COMPLETE 0x00 -#define BLE_HCI_PERIODIC_DATA_STATUS_INCOMPLETE 0x01 -#define BLE_HCI_PERIODIC_DATA_STATUS_TRUNCATED 0x02 - -/* --- LE set privacy mode (OCF 0x004E) */ -#define BLE_HCI_PRIVACY_NETWORK (0) -#define BLE_HCI_PRIVACY_DEVICE (1) - -/* Event Codes */ -#define BLE_HCI_EVCODE_INQUIRY_CMP (0x01) -#define BLE_HCI_EVCODE_INQUIRY_RESULT (0x02) -#define BLE_HCI_EVCODE_CONN_DONE (0x03) -#define BLE_HCI_EVCODE_CONN_REQUEST (0x04) -#define BLE_HCI_EVCODE_DISCONN_CMP (0x05) -struct ble_hci_ev_disconn_cmp { - uint8_t status; - uint16_t conn_handle; - uint8_t reason; -} __attribute__((packed)); - -#define BLE_HCI_EVCODE_AUTH_CMP (0x06) -#define BLE_HCI_EVCODE_REM_NAME_REQ_CMP (0x07) - -#define BLE_HCI_EVCODE_ENCRYPT_CHG (0x08) -struct ble_hci_ev_enrypt_chg { - uint8_t status; - uint16_t connection_handle; - uint8_t enabled; -} __attribute__((packed)); - -#define BLE_HCI_EVCODE_CHG_LINK_KEY_CMP (0x09) -#define BLE_HCI_EVCODE_MASTER_LINK_KEY_CMP (0x0A) -#define BLE_HCI_EVCODE_RD_REM_SUPP_FEAT_CMP (0x0B) -#define BLE_HCI_EVCODE_RD_REM_VER_INFO_CMP (0x0C) -struct ble_hci_ev_rd_rem_ver_info_cmp { - uint8_t status; - uint16_t conn_handle; - uint8_t version; - uint16_t manufacturer; - uint16_t subversion; -} __attribute__((packed)); - -#define BLE_HCI_EVCODE_QOS_SETUP_CMP (0x0D) - -#define BLE_HCI_EVCODE_COMMAND_COMPLETE (0x0E) -struct ble_hci_ev_command_complete { - uint8_t num_packets; - uint16_t opcode; - uint8_t status; - uint8_t return_params[0]; -} __attribute__((packed)); -/* NOP is exception and has no return parameters */ -struct ble_hci_ev_command_complete_nop { - uint8_t num_packets; - uint16_t opcode; -} __attribute__((packed)); - -#define BLE_HCI_EVCODE_COMMAND_STATUS (0x0F) -struct ble_hci_ev_command_status { - uint8_t status; - uint8_t num_packets; - uint16_t opcode; -} __attribute__((packed)); - -#define BLE_HCI_EVCODE_HW_ERROR (0x10) -struct ble_hci_ev_hw_error { - uint8_t hw_code; -} __attribute__((packed)); - -#define BLE_HCI_EVCODE_NUM_COMP_PKTS (0x13) -struct comp_pkt { - uint16_t handle; - uint16_t packets; -} __attribute__((packed));; -struct ble_hci_ev_num_comp_pkts { - uint8_t count; - struct comp_pkt completed[0]; -} __attribute__((packed)); - -#define BLE_HCI_EVCODE_MODE_CHANGE (0x14) -#define BLE_HCI_EVCODE_RETURN_LINK_KEYS (0x15) -#define BLE_HCI_EVCODE_PIN_CODE_REQ (0x16) -#define BLE_HCI_EVCODE_LINK_KEY_REQ (0x17) -#define BLE_HCI_EVCODE_LINK_KEY_NOTIFY (0x18) -#define BLE_HCI_EVCODE_LOOPBACK_CMD (0x19) - -#define BLE_HCI_EVCODE_DATA_BUF_OVERFLOW (0x1A) -struct ble_hci_ev_data_buf_overflow { - uint8_t link_type; -} __attribute__((packed)); - -#define BLE_HCI_EVCODE_MAX_SLOTS_CHG (0x1B) -#define BLE_HCI_EVCODE_READ_CLK_OFF_COMP (0x1C) -#define BLE_HCI_EVCODE_CONN_PKT_TYPE_CHG (0x1D) -#define BLE_HCI_EVCODE_QOS_VIOLATION (0x1E) -/* NOTE: 0x1F not defined */ -#define BLE_HCI_EVCODE_PSR_MODE_CHG (0x20) -#define BLE_HCI_EVCODE_FLOW_SPEC_COMP (0x21) -#define BLE_HCI_EVCODE_INQ_RESULT_RSSI (0x22) -#define BLE_HCI_EVCODE_READ_REM_EXT_FEAT (0x23) -/* NOTE: 0x24 - 0x2B not defined */ -#define BLE_HCI_EVCODE_SYNCH_CONN_COMP (0x2C) -#define BLE_HCI_EVCODE_SYNCH_CONN_CHG (0x2D) -#define BLE_HCI_EVCODE_SNIFF_SUBRATING (0x2E) -#define BLE_HCI_EVCODE_EXT_INQ_RESULT (0x2F) - -#define BLE_HCI_EVCODE_ENC_KEY_REFRESH (0x30) -struct ble_hci_ev_enc_key_refresh { - uint8_t status; - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_EVOCDE_IO_CAP_REQ (0x31) -#define BLE_HCI_EVCODE_IO_CAP_RSP (0x32) -#define BLE_HCI_EVCODE_USER_CONFIRM_REQ (0x33) -#define BLE_HCI_EVCODE_PASSKEY_REQ (0x34) -#define BLE_HCI_EVCODE_REM_OOB_DATA_REQ (0x35) -#define BLE_HCI_EVCODE_SIMPLE_PAIR_COMP (0x36) -/* NOTE: 0x37 not defined */ -#define BLE_HCI_EVCODE_LNK_SPVN_TMO_CHG (0x38) -#define BLE_HCI_EVCODE_ENH_FLUSH_COMP (0x39) -#define BLE_HCI_EVCODE_USER_PASSKEY_NOTIFY (0x3B) -#define BLE_HCI_EVCODE_KEYPRESS_NOTIFY (0x3C) -#define BLE_HCI_EVCODE_REM_HOST_SUPP_FEAT (0x3D) - -#define BLE_HCI_EVCODE_LE_META (0x3E) -struct ble_hci_ev_le_meta { - uint8_t subevent; - uint8_t data[0]; -} __attribute__((packed)); - -/* NOTE: 0x3F not defined */ -#define BLE_HCI_EVCODE_PHYS_LINK_COMP (0x40) -#define BLE_HCI_EVCODE_CHAN_SELECTED (0x41) -#define BLE_HCI_EVCODE_DISCONN_PHYS_LINK (0x42) -#define BLE_HCI_EVCODE_PHYS_LINK_LOSS_EARLY (0x43) -#define BLE_HCI_EVCODE_PHYS_LINK_RECOVERY (0x44) -#define BLE_HCI_EVCODE_LOGICAL_LINK_COMP (0x45) -#define BLE_HCI_EVCODE_DISCONN_LOGICAL_LINK (0x46) -#define BLE_HCI_EVCODE_FLOW_SPEC_MODE_COMP (0x47) -#define BLE_HCI_EVCODE_NUM_COMP_DATA_BLKS (0x48) -#define BLE_HCI_EVCODE_AMP_START_TEST (0x49) -#define BLE_HCI_EVOCDE_AMP_TEST_END (0x4A) -#define BLE_HCI_EVOCDE_AMP_RCVR_REPORT (0x4B) -#define BLE_HCI_EVCODE_SHORT_RANGE_MODE_CHG (0x4C) -#define BLE_HCI_EVCODE_AMP_STATUS_CHG (0x4D) -#define BLE_HCI_EVCODE_TRIG_CLK_CAPTURE (0x4E) -#define BLE_HCI_EVCODE_SYNCH_TRAIN_COMP (0x4F) -#define BLE_HCI_EVCODE_SYNCH_TRAIN_RCVD (0x50) -#define BLE_HCI_EVCODE_SLAVE_BCAST_RX (0x51) -#define BLE_HCI_EVCODE_SLAVE_BCAST_TMO (0x52) -#define BLE_HCI_EVCODE_TRUNC_PAGE_COMP (0x53) -#define BLE_HCI_EVCODE_SLAVE_PAGE_RSP_TMO (0x54) -#define BLE_HCI_EVCODE_SLAVE_BCAST_CHAN_MAP (0x55) -#define BLE_HCI_EVCODE_INQ_RSP_NOTIFY (0x56) - -#define BLE_HCI_EVCODE_AUTH_PYLD_TMO (0x57) -struct ble_hci_ev_auth_pyld_tmo { - uint16_t conn_handle; -} __attribute__((packed)); - -#define BLE_HCI_EVCODE_SAM_STATUS_CHG (0x58) - -#define BLE_HCI_EVCODE_VS_DEBUG (0xFF) -struct ble_hci_ev_vs_debug { - uint8_t id; - uint8_t data[0]; -} __attribute__((packed)); - -/* LE sub-event codes */ -#define BLE_HCI_LE_SUBEV_CONN_COMPLETE (0x01) -struct ble_hci_ev_le_subev_conn_complete { - uint8_t subev_code; - uint8_t status; - uint16_t conn_handle; - uint8_t role; - uint8_t peer_addr_type; - uint8_t peer_addr[6]; - uint16_t conn_itvl; - uint16_t conn_latency; - uint16_t supervision_timeout; - uint8_t mca; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_ADV_RPT (0x02) -struct adv_report { - uint8_t type; - uint8_t addr_type; - uint8_t addr[6]; - uint8_t data_len; - uint8_t data[0]; -} __attribute__((packed)); -struct ble_hci_ev_le_subev_adv_rpt { - uint8_t subev_code; - uint8_t num_reports; - struct adv_report reports[0]; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE (0x03) -struct ble_hci_ev_le_subev_conn_upd_complete { - uint8_t subev_code; - uint8_t status; - uint16_t conn_handle; - uint16_t conn_itvl; - uint16_t conn_latency; - uint16_t supervision_timeout; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_RD_REM_USED_FEAT (0x04) -struct ble_hci_ev_le_subev_rd_rem_used_feat { - uint8_t subev_code; - uint8_t status; - uint16_t conn_handle; - uint8_t features[8]; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_LT_KEY_REQ (0x05) -struct ble_hci_ev_le_subev_lt_key_req { - uint8_t subev_code; - uint16_t conn_handle; - uint64_t rand; - uint16_t div; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ (0x06) -struct ble_hci_ev_le_subev_rem_conn_param_req { - uint8_t subev_code; - uint16_t conn_handle; - uint16_t min_interval; - uint16_t max_interval; - uint16_t latency; - uint16_t timeout; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_DATA_LEN_CHG (0x07) -struct ble_hci_ev_le_subev_data_len_chg { - uint8_t subev_code; - uint16_t conn_handle; - uint16_t max_tx_octets; - uint16_t max_tx_time; - uint16_t max_rx_octets; - uint16_t max_rx_time; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_RD_LOC_P256_PUBKEY (0x08) -struct ble_hci_ev_le_subev_rd_loc_p256_pubkey { - uint8_t subev_code; - uint8_t status; - uint8_t public_key[64]; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_GEN_DHKEY_COMPLETE (0x09) -struct ble_hci_ev_le_subev_gen_dhkey_complete { - uint8_t subev_code; - uint8_t status; - uint8_t dh_key[32]; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE (0x0A) -struct ble_hci_ev_le_subev_enh_conn_complete { - uint8_t subev_code; - uint8_t status; - uint16_t conn_handle; - uint8_t role; - uint8_t peer_addr_type; - uint8_t peer_addr[6]; - uint8_t local_rpa[6]; - uint8_t peer_rpa[6]; - uint16_t conn_itvl; - uint16_t conn_latency; - uint16_t supervision_timeout; - uint8_t mca; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT (0x0B) -struct dir_adv_report { - uint8_t type; - uint8_t addr_type; - uint8_t addr[6]; - uint8_t dir_addr_type; - uint8_t dir_addr[6]; - int8_t rssi; -} __attribute__((packed)); -struct ble_hci_ev_le_subev_direct_adv_rpt { - uint8_t subev_code; - uint8_t num_reports; - struct dir_adv_report reports[0]; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_PHY_UPDATE_COMPLETE (0x0C) -struct ble_hci_ev_le_subev_phy_update_complete { - uint8_t subev_code; - uint8_t status; - uint16_t conn_handle; - uint8_t tx_phy; - uint8_t rx_phy; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_EXT_ADV_RPT (0x0D) -struct ext_adv_report { - uint16_t evt_type; - uint8_t addr_type; - uint8_t addr[6]; - uint8_t pri_phy; - uint8_t sec_phy; - uint8_t sid; - int8_t tx_power; - int8_t rssi; - uint16_t periodic_itvl; - uint8_t dir_addr_type; - uint8_t dir_addr[6]; - uint8_t data_len; - uint8_t data[0]; -} __attribute__((packed)); -struct ble_hci_ev_le_subev_ext_adv_rpt { - uint8_t subev_code; - uint8_t num_reports; - struct ext_adv_report reports[0]; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_ESTAB (0x0E) -struct ble_hci_ev_le_subev_periodic_adv_sync_estab { - uint8_t subev_code; - uint8_t status; - uint16_t sync_handle; - uint8_t sid; - uint8_t peer_addr_type; - uint8_t peer_addr[6]; - uint8_t phy; - uint16_t interval; - uint8_t aca; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_RPT (0x0F) -struct ble_hci_ev_le_subev_periodic_adv_rpt { - uint8_t subev_code; - uint16_t sync_handle; - int8_t tx_power; - int8_t rssi; - uint8_t cte_type; - uint8_t data_status; - uint8_t data_len; - uint8_t data[0]; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_LOST (0x10) -struct ble_hci_ev_le_subev_periodic_adv_sync_lost { - uint8_t subev_code; - uint16_t sync_handle; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_SCAN_TIMEOUT (0x11) -struct ble_hci_ev_le_subev_scan_timeout { - uint8_t subev_code; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_ADV_SET_TERMINATED (0x12) -struct ble_hci_ev_le_subev_adv_set_terminated { - uint8_t subev_code; - uint8_t status; - uint8_t adv_handle; - uint16_t conn_handle; - uint8_t num_events; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_SCAN_REQ_RCVD (0x13) -struct ble_hci_ev_le_subev_scan_req_rcvd { - uint8_t subev_code; - uint8_t adv_handle; - uint8_t peer_addr_type; - uint8_t peer_addr[6]; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_CHAN_SEL_ALG (0x14) -struct ble_hci_ev_le_subev_chan_sel_alg { - uint8_t subev_code; - uint16_t conn_handle; - uint8_t csa; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_CONNLESS_IQ_RPT (0x15) -#define BLE_HCI_LE_SUBEV_CONN_IQ_RPT (0x16) -#define BLE_HCI_LE_SUBEV_CTE_REQ_FAILED (0x17) - -#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_TRANSFER (0x18) -struct ble_hci_ev_le_subev_periodic_adv_sync_transfer { - uint8_t subev_code; - uint8_t status; - uint16_t conn_handle; - uint16_t service_data; - uint16_t sync_handle; - uint8_t sid; - uint8_t peer_addr_type; - uint8_t peer_addr[6]; - uint8_t phy; - uint16_t interval; - uint8_t aca; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_CIS_ESTAB (0x19) -struct ble_hci_ev_le_subev_cis_established { - uint8_t subev_code; - uint8_t status; - uint16_t cis_handle; - uint8_t cig_sync_delay[3]; - uint8_t cis_sync_delay[3]; - uint8_t trans_latency_mtos[3]; - uint8_t trans_latency_stom[3]; - uint8_t phy_mtos; - uint8_t phy_stom; - uint8_t nse; - uint8_t bn_mtos; - uint8_t bn_stom; - uint8_t ft_mtos; - uint8_t ft_stom; - uint16_t max_pdu_mtos; - uint16_t max_pdu_stom; - uint16_t iso_interval; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_CIS_REQUEST (0x1A) -struct ble_hci_ev_le_subev_cis_request { - uint8_t subev_code; - uint16_t conn_handle; - uint16_t cis_handle; - uint8_t cig_id; - uint8_t cis_id; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_BIG_COMP (0x1B) -struct ble_hci_ev_le_subev_big_complete { - uint8_t subev_code; - uint8_t status; - uint8_t big_handle; - uint8_t big_sync_delay[3]; - uint8_t transport_latency[3]; - uint8_t phy; - uint8_t nse; - uint8_t bn; - uint8_t pto; - uint8_t irc; - uint16_t max_pdu; - uint16_t iso_interval; - uint8_t bis_cnt; - uint16_t bis[0]; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_BIG_TERMINATE_COMP (0x1C) -struct ble_hci_ev_le_subev_big_terminate_complete { - uint8_t subev_code; - uint8_t big_handle; - uint8_t reason; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_BIG_SYNC_ESTAB (0x1D) -struct ble_hci_ev_le_subev_big_sync_established { - uint8_t subev_code; - uint8_t status; - uint8_t big_handle; - uint8_t transport_latency[3]; - uint8_t nse; - uint8_t bn; - uint8_t pto; - uint8_t irc; - uint16_t max_pdu; - uint16_t iso_interval; - uint8_t bis_cnt; - uint16_t bis_handles[0]; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_BIG_SYNC_LOST (0x1E) -struct ble_hci_ev_le_subev_big_sync_lost { - uint8_t subev_code; - uint8_t big_handle; - uint8_t reason; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_REQ_PEER_SCA_COMP (0x1F) -struct ble_hci_ev_le_subev_peer_sca_complete { - uint8_t subev_code; - uint8_t status; - uint16_t conn_handle; - uint8_t sca; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_PATH_LOSS_THRESHOLD (0x20) -struct ble_hci_ev_le_subev_path_loss_threshold { - uint8_t subev_code; - uint16_t conn_handle; - uint8_t current_path_loss; - uint8_t zone_entered; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_TRANSMIT_POWER_REPORT (0x21) -struct ble_hci_ev_le_subev_transmit_power_report { - uint8_t subev_code; - uint8_t status; - uint16_t conn_handle; - uint8_t reason; - uint8_t phy; - int8_t transmit_power_level; - uint8_t transmit_power_level_flag; - int8_t delta; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_BIGINFO_ADV_REPORT (0x22) -struct ble_hci_ev_le_subev_biginfo_adv_report { - uint8_t subev_code; - uint16_t sync_handle; - uint8_t bis_cnt; - uint8_t nse; - uint16_t iso_interval; - uint8_t bn; - uint8_t pto; - uint8_t irc; - uint16_t max_pdu; - uint8_t sdu_interval[3]; - uint16_t max_sdu; - uint8_t phy; - uint8_t framing; - uint8_t encryption; -} __attribute__((packed)); - -#define BLE_HCI_LE_SUBEV_SUBRATE_CHANGE (0x23) -struct ble_hci_ev_le_subev_subrate_change { - uint8_t subev_code; - uint8_t status; - uint16_t conn_handle; - uint16_t subrate_factor; - uint16_t periph_latency; - uint16_t cont_num; - uint16_t supervision_tmo; -} __attribute__((packed)); - -/* Data buffer overflow event */ -#define BLE_HCI_EVENT_ACL_BUF_OVERFLOW (0x01) - -/* Advertising report */ -#define BLE_HCI_ADV_RPT_EVTYPE_ADV_IND (0) -#define BLE_HCI_ADV_RPT_EVTYPE_DIR_IND (1) -#define BLE_HCI_ADV_RPT_EVTYPE_SCAN_IND (2) -#define BLE_HCI_ADV_RPT_EVTYPE_NONCONN_IND (3) -#define BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP (4) - -/* Bluetooth 5, Vol 2, Part E, 7.7.65.13 */ -#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_IND (0x13) -#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_DIRECT_IND (0x15) -#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_SCAN_IND (0x12) -#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_NONCON_IND (0x10) -#define BLE_HCI_LEGACY_ADV_EVTYPE_SCAN_RSP_ADV_IND (0x1b) -#define BLE_HCI_LEGACY_ADV_EVTYPE_SCAN_RSP_ADV_SCAN_IND (0x1a) - -/* LE connection complete event (sub event 0x01) */ -#define BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER (0x00) -#define BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE (0x01) - -/* Maximum valid connection handle value */ -#define BLE_HCI_LE_CONN_HANDLE_MAX (0x0eff) - -/* LE advertising report event. (sub event 0x02) */ -#define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN (1) -#define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX (0x19) - -/* Bluetooth Assigned numbers for version information.*/ -#define BLE_HCI_VER_BCS_1_0b (0) -#define BLE_HCI_VER_BCS_1_1 (1) -#define BLE_HCI_VER_BCS_1_2 (2) -#define BLE_HCI_VER_BCS_2_0_EDR (3) -#define BLE_HCI_VER_BCS_2_1_EDR (4) -#define BLE_HCI_VER_BCS_3_0_HCS (5) -#define BLE_HCI_VER_BCS_4_0 (6) -#define BLE_HCI_VER_BCS_4_1 (7) -#define BLE_HCI_VER_BCS_4_2 (8) -#define BLE_HCI_VER_BCS_5_0 (9) -#define BLE_HCI_VER_BCS_5_1 (10) -#define BLE_HCI_VER_BCS_5_2 (11) -#define BLE_HCI_VER_BCS_5_3 (12) - -#define BLE_LMP_VER_BCS_1_0b (0) -#define BLE_LMP_VER_BCS_1_1 (1) -#define BLE_LMP_VER_BCS_1_2 (2) -#define BLE_LMP_VER_BCS_2_0_EDR (3) -#define BLE_LMP_VER_BCS_2_1_EDR (4) -#define BLE_LMP_VER_BCS_3_0_HCS (5) -#define BLE_LMP_VER_BCS_4_0 (6) -#define BLE_LMP_VER_BCS_4_1 (7) -#define BLE_LMP_VER_BCS_4_2 (8) -#define BLE_LMP_VER_BCS_5_0 (9) -#define BLE_LMP_VER_BCS_5_1 (10) -#define BLE_LMP_VER_BCS_5_2 (11) -#define BLE_LMP_VER_BCS_5_3 (12) - -/* selected HCI and LMP version */ -#if MYNEWT_VAL(BLE_VERSION) == 50 -#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_0 -#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_0 -#elif MYNEWT_VAL(BLE_VERSION) == 51 -#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_1 -#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_1 -#elif MYNEWT_VAL(BLE_VERSION) == 52 -#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_2 -#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_2 -#elif MYNEWT_VAL(BLE_VERSION) == 53 -#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_3 -#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_3 -#endif - -#define BLE_HCI_DATA_HDR_SZ 4 -#define BLE_HCI_DATA_HANDLE(handle_pb_bc) (((handle_pb_bc) & 0x0fff) >> 0) -#define BLE_HCI_DATA_PB(handle_pb_bc) (((handle_pb_bc) & 0x3000) >> 12) -#define BLE_HCI_DATA_BC(handle_pb_bc) (((handle_pb_bc) & 0xc000) >> 14) - -struct hci_data_hdr -{ - uint16_t hdh_handle_pb_bc; - uint16_t hdh_len; -}; - -#define BLE_HCI_PB_FIRST_NON_FLUSH 0 -#define BLE_HCI_PB_MIDDLE 1 -#define BLE_HCI_PB_FIRST_FLUSH 2 -#define BLE_HCI_PB_FULL 3 - -#ifdef __cplusplus -} -#endif - -#endif /* H_BLE_HCI_COMMON_ */ diff --git a/components/bt/porting/nimble/include/nimble/nimble_opt_auto.h b/components/bt/porting/nimble/include/nimble/nimble_opt_auto.h index 7aeafcc321..daf2153348 100644 --- a/components/bt/porting/nimble/include/nimble/nimble_opt_auto.h +++ b/components/bt/porting/nimble/include/nimble/nimble_opt_auto.h @@ -92,6 +92,10 @@ extern "C" { #define NIMBLE_BLE_ATT_CLT_WRITE \ (MYNEWT_VAL(BLE_GATT_WRITE)) +#undef NIMBLE_BLE_ATT_CLT_SIGNED_WRITE +#define NIMBLE_BLE_ATT_CLT_SIGNED_WRITE \ + (MYNEWT_VAL(BLE_GATT_SIGNED_WRITE)) + #undef NIMBLE_BLE_ATT_CLT_WRITE_NO_RSP #define NIMBLE_BLE_ATT_CLT_WRITE_NO_RSP \ (MYNEWT_VAL(BLE_GATT_WRITE_NO_RSP)) diff --git a/components/bt/porting/nimble/include/nimble/nimble_port.h b/components/bt/porting/nimble/include/nimble/nimble_port.h index 2b000081ea..f4a9854378 100644 --- a/components/bt/porting/nimble/include/nimble/nimble_port.h +++ b/components/bt/porting/nimble/include/nimble/nimble_port.h @@ -27,7 +27,7 @@ #define NIMBLE_HS_STACK_SIZE CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE -#if SOC_ESP_NIMBLE_CONTROLLER +#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED #define NIMBLE_LL_STACK_SIZE CONFIG_BT_LE_CONTROLLER_TASK_STACK_SIZE #endif diff --git a/components/bt/porting/nimble/include/os/endian.h b/components/bt/porting/nimble/include/os/endian.h index af474acc05..2e06a8b566 100644 --- a/components/bt/porting/nimble/include/os/endian.h +++ b/components/bt/porting/nimble/include/os/endian.h @@ -213,7 +213,7 @@ extern "C" { #endif -#if SOC_ESP_NIMBLE_CONTROLLER +#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED void r_put_le16(void *buf, uint16_t x); #define put_le16 r_put_le16 diff --git a/components/bt/porting/nimble/include/os/os_mbuf.h b/components/bt/porting/nimble/include/os/os_mbuf.h index bd2df864b4..e6fd6b907e 100644 --- a/components/bt/porting/nimble/include/os/os_mbuf.h +++ b/components/bt/porting/nimble/include/os/os_mbuf.h @@ -244,7 +244,7 @@ _os_mbuf_trailingspace(struct os_mbuf *om) #define OS_MBUF_TRAILINGSPACE(__om) _os_mbuf_trailingspace(__om) -#if SOC_ESP_NIMBLE_CONTROLLER +#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED /** * Initializes an mqueue. An mqueue is a queue of mbufs that ties to a * particular task's event queue. Mqueues form a helper API around a common diff --git a/components/bt/porting/nimble/include/os/os_mempool.h b/components/bt/porting/nimble/include/os/os_mempool.h index 4daead13a6..3ef8e6d579 100644 --- a/components/bt/porting/nimble/include/os/os_mempool.h +++ b/components/bt/porting/nimble/include/os/os_mempool.h @@ -163,7 +163,7 @@ typedef __uint128_t os_membuf_t; #define OS_MEMPOOL_BYTES(n,blksize) \ (sizeof (os_membuf_t) * OS_MEMPOOL_SIZE((n), (blksize))) -#if SOC_ESP_NIMBLE_CONTROLLER +#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED /** * Initialize a memory pool. * diff --git a/components/protocomm/src/simple_ble/simple_ble.c b/components/protocomm/src/simple_ble/simple_ble.c index 138e7c3ada..8a4ae0f3d9 100644 --- a/components/protocomm/src/simple_ble/simple_ble.c +++ b/components/protocomm/src/simple_ble/simple_ble.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,7 +8,9 @@ #include #include #include +#ifdef CONFIG_BT_CONTROLLER_ENABLED #include "esp_bt.h" +#endif #include #include #include @@ -213,6 +215,7 @@ esp_err_t simple_ble_start(simple_ble_cfg_t *cfg) ESP_LOGD(TAG, "Free mem at start of simple_ble_init %" PRIu32, esp_get_free_heap_size()); esp_err_t ret; +#ifdef CONFIG_BT_CONTROLLER_ENABLED esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); ret = esp_bt_controller_init(&bt_cfg); if (ret) { @@ -232,6 +235,7 @@ esp_err_t simple_ble_start(simple_ble_cfg_t *cfg) ESP_LOGE(TAG, "%s enable controller failed %d", __func__, ret); return ret; } +#endif ret = esp_bluedroid_init(); if (ret) { @@ -306,6 +310,7 @@ esp_err_t simple_ble_stop(void) return err; } ESP_LOGD(TAG, "esp_bluedroid_deinit called successfully"); +#ifdef CONFIG_BT_CONTROLLER_ENABLED err = esp_bt_controller_disable(); if (err != ESP_OK) { return ESP_FAIL; @@ -320,7 +325,7 @@ esp_err_t simple_ble_stop(void) return ESP_FAIL; } ESP_LOGD(TAG, "esp_bt_controller_deinit called successfully"); - +#endif ESP_LOGD(TAG, "Free mem at end of simple_ble_stop %" PRIu32, esp_get_free_heap_size()); return ESP_OK; } diff --git a/components/wifi_provisioning/src/scheme_ble.c b/components/wifi_provisioning/src/scheme_ble.c index 88e1724e08..d323fda21d 100644 --- a/components/wifi_provisioning/src/scheme_ble.c +++ b/components/wifi_provisioning/src/scheme_ble.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,7 +7,9 @@ #include #include #include +#ifdef CONFIG_BT_CONTROLLER_ENABLED #include "esp_bt.h" +#endif #include #include @@ -197,9 +199,12 @@ static esp_err_t set_config_endpoint(void *config, const char *endpoint_name, ui /* Used when both BT and BLE are not needed by application */ void wifi_prov_scheme_ble_event_cb_free_btdm(void *user_data, wifi_prov_cb_event_t event, void *event_data) { +#ifdef CONFIG_BT_CONTROLLER_ENABLED esp_err_t err; +#endif switch (event) { case WIFI_PROV_INIT: +#ifdef CONFIG_BT_CONTROLLER_ENABLED /* Release BT memory, as we need only BLE */ err = esp_bt_mem_release(ESP_BT_MODE_CLASSIC_BT); if (err != ESP_OK) { @@ -207,10 +212,12 @@ void wifi_prov_scheme_ble_event_cb_free_btdm(void *user_data, wifi_prov_cb_event } else { ESP_LOGI(TAG, "BT memory released"); } +#endif break; case WIFI_PROV_DEINIT: #ifndef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV +#ifdef CONFIG_BT_CONTROLLER_ENABLED /* Release memory used by BLE and Bluedroid host stack */ err = esp_bt_mem_release(ESP_BT_MODE_BTDM); if (err != ESP_OK) { @@ -218,6 +225,7 @@ void wifi_prov_scheme_ble_event_cb_free_btdm(void *user_data, wifi_prov_cb_event } else { ESP_LOGI(TAG, "BTDM memory released"); } +#endif #endif break; @@ -229,9 +237,12 @@ void wifi_prov_scheme_ble_event_cb_free_btdm(void *user_data, wifi_prov_cb_event /* Used when BT is not needed by application */ void wifi_prov_scheme_ble_event_cb_free_bt(void *user_data, wifi_prov_cb_event_t event, void *event_data) { +#ifdef CONFIG_BT_CONTROLLER_ENABLED esp_err_t err; +#endif switch (event) { case WIFI_PROV_INIT: +#ifdef CONFIG_BT_CONTROLLER_ENABLED /* Release BT memory, as we need only BLE */ err = esp_bt_mem_release(ESP_BT_MODE_CLASSIC_BT); if (err != ESP_OK) { @@ -239,6 +250,7 @@ void wifi_prov_scheme_ble_event_cb_free_bt(void *user_data, wifi_prov_cb_event_t } else { ESP_LOGI(TAG, "BT memory released"); } +#endif break; default: @@ -249,10 +261,13 @@ void wifi_prov_scheme_ble_event_cb_free_bt(void *user_data, wifi_prov_cb_event_t /* Used when BLE is not needed by application */ void wifi_prov_scheme_ble_event_cb_free_ble(void *user_data, wifi_prov_cb_event_t event, void *event_data) { +#ifdef CONFIG_BT_CONTROLLER_ENABLED esp_err_t err; +#endif switch (event) { case WIFI_PROV_DEINIT: #ifndef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV +#ifdef CONFIG_BT_CONTROLLER_ENABLED /* Release memory used by BLE stack */ err = esp_bt_mem_release(ESP_BT_MODE_BLE); if (err != ESP_OK) { @@ -260,6 +275,7 @@ void wifi_prov_scheme_ble_event_cb_free_ble(void *user_data, wifi_prov_cb_event_ } else { ESP_LOGI(TAG, "BLE memory released"); } +#endif #endif break; diff --git a/examples/bluetooth/.build-test-rules.yml b/examples/bluetooth/.build-test-rules.yml index aee1577c2a..d6daee8f4d 100644 --- a/examples/bluetooth/.build-test-rules.yml +++ b/examples/bluetooth/.build-test-rules.yml @@ -287,6 +287,16 @@ examples/bluetooth/nimble/bleprph: temporary: true reason: The runner doesn't support yet +examples/bluetooth/nimble/bleprph_host_only: + enable: + - if: IDF_TARGET in ["esp32", "esp32c2", "esp32c3", "esp32c6" , "esp32s3", "esp32h2" ] + temporary: true + reason: the other targets are not tested yet + disable_test: + - if: IDF_TARGET in ["esp32c2", "esp32c3", "esp32h2", "esp32s3", "esp32c6"] + temporary: true + reason: The runner doesn't support yet + examples/bluetooth/nimble/bleprph_wifi_coex: enable: - if: IDF_TARGET in ["esp32", "esp32c2", "esp32c3", "esp32s3"] diff --git a/examples/bluetooth/blufi/main/blufi_example_main.c b/examples/bluetooth/blufi/main/blufi_example_main.c index a4db69cc56..2db4cb2bf4 100644 --- a/examples/bluetooth/blufi/main/blufi_example_main.c +++ b/examples/bluetooth/blufi/main/blufi_example_main.c @@ -24,7 +24,9 @@ #include "esp_event.h" #include "esp_log.h" #include "nvs_flash.h" +#if CONFIG_BT_CONTROLLER_ENABLED || !CONFIG_BT_NIMBLE_ENABLED #include "esp_bt.h" +#endif #include "esp_blufi_api.h" #include "blufi_example.h" @@ -463,11 +465,13 @@ void app_main(void) initialise_wifi(); +#if CONFIG_BT_CONTROLLER_ENABLED || !CONFIG_BT_NIMBLE_ENABLED ret = esp_blufi_controller_init(); if (ret) { BLUFI_ERROR("%s BLUFI controller init failed: %s\n", __func__, esp_err_to_name(ret)); return; } +#endif ret = esp_blufi_host_and_cb_init(&example_callbacks); if (ret) { diff --git a/examples/bluetooth/blufi/main/blufi_init.c b/examples/bluetooth/blufi/main/blufi_init.c index 378344e422..7429cbd8f4 100644 --- a/examples/bluetooth/blufi/main/blufi_init.c +++ b/examples/bluetooth/blufi/main/blufi_init.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ diff --git a/examples/bluetooth/blufi/main/blufi_security.c b/examples/bluetooth/blufi/main/blufi_security.c index 5dd304b034..470e38ce16 100644 --- a/examples/bluetooth/blufi/main/blufi_security.c +++ b/examples/bluetooth/blufi/main/blufi_security.c @@ -16,7 +16,9 @@ #include "esp_log.h" #include "nvs_flash.h" #include "esp_random.h" +#if CONFIG_BT_CONTROLLER_ENABLED || !CONFIG_BT_NIMBLE_ENABLED #include "esp_bt.h" +#endif #include "esp_blufi_api.h" #include "blufi_example.h" diff --git a/examples/bluetooth/nimble/bleprph/main/main.c b/examples/bluetooth/nimble/bleprph/main/main.c index 479d37ba82..49951c6fc1 100644 --- a/examples/bluetooth/nimble/bleprph/main/main.c +++ b/examples/bluetooth/nimble/bleprph/main/main.c @@ -393,6 +393,16 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) } return 0; + case BLE_GAP_EVENT_AUTHORIZE: + MODLOG_DFLT(INFO, "authorize event: conn_handle=%d attr_handle=%d is_read=%d", + event->authorize.conn_handle, + event->authorize.attr_handle, + event->authorize.is_read); + + /* The default behaviour for the event is to reject authorize request */ + event->authorize.out_response = BLE_GAP_AUTHORIZE_REJECT; + return 0; + #if MYNEWT_VAL(BLE_POWER_CONTROL) case BLE_GAP_EVENT_TRANSMIT_POWER: MODLOG_DFLT(INFO, "Transmit power event : status=%d conn_handle=%d reason=%d " diff --git a/examples/bluetooth/nimble/bleprph_host_only/CMakeLists.txt b/examples/bluetooth/nimble/bleprph_host_only/CMakeLists.txt new file mode 100644 index 0000000000..07e8a161ad --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(bleprph_host_only) diff --git a/examples/bluetooth/nimble/bleprph_host_only/README.md b/examples/bluetooth/nimble/bleprph_host_only/README.md new file mode 100644 index 0000000000..14de6b7edf --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/README.md @@ -0,0 +1,114 @@ +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | + +# BLE Peripheral Example + +(See the README.md file in the upper level 'examples' directory for more information about examples.) + +This example uses the UART transport written by application itself. Refer the file [main/uart_driver.c](main/uart_driver.c). + +To write the custom transport in the application, the controller should be disabled and the default uart-transport should be disabled(When the controller is disabled, by default the uart-transport is selected). In order to compile the custom transport in the application, the default uart-transport should be disabled. Refer to the sdkconfig.defaults. + +For more information about the application refer to the bleprph [README file](../bleprph/README.md) +To test this demo, any BLE scanner app can be used. + +Note : + +* To install the dependency packages needed, please refer to the top level [README file](../../../README.md#running-test-python-script-pytest). +* Currently this Python utility is only supported on Linux (BLE communication is via BLuez + DBus). + +## How to Use Example + +Before project configuration and build, be sure to set the correct chip target using: + +```bash +idf.py set-target +``` + +### Configure the project + +Open the project configuration menu: + +```bash +idf.py menuconfig +``` + +In the `Component config-> Bluetooth` menu: + +* Select `controller` to Disabled. +* Disable `Nimble Options-> Host-controller Transport -> Enable Uart Transport`. + +### Build and Flash + +Run `idf.py -p PORT flash monitor` to build, flash and monitor the project. + +(To exit the serial monitor, type ``Ctrl-]``.) + +See the [Getting Started Guide](https://idf.espressif.com/) for full steps to configure and use ESP-IDF to build projects. + +## Example Output + +There is this console output when bleprph_host_only running on esp32 and using controller of esp32c6: + +``` +I (31) boot: ESP-IDF v5.3-dev-1570-gbc703f3508-dirty 2nd stage bootloader +I (31) boot: compile time Jan 18 2024 17:45:38 +I (33) boot: Multicore bootloader +I (37) boot: chip revision: v3.0 +I (41) boot.esp32: SPI Speed : 40MHz +I (46) boot.esp32: SPI Mode : DIO +I (50) boot.esp32: SPI Flash Size : 2MB +I (55) boot: Enabling RNG early entropy source... +I (60) boot: Partition Table: +I (64) boot: ## Label Usage Type ST Offset Length +I (71) boot: 0 nvs WiFi data 01 02 00009000 00006000 +I (79) boot: 1 phy_init RF data 01 01 0000f000 00001000 +I (86) boot: 2 factory factory app 00 00 00010000 00100000 +I (94) boot: End of partition table +I (98) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=19554h (103764) map +I (142) esp_image: segment 1: paddr=0002957c vaddr=3ffb0000 size=0278ch ( 10124) load +I (146) esp_image: segment 2: paddr=0002bd10 vaddr=40080000 size=04308h ( 17160) load +I (155) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=42800h (272384) map +I (250) esp_image: segment 4: paddr=00072828 vaddr=40084308 size=0a6ech ( 42732) load +I (274) boot: Loaded app from partition at offset 0x10000 +I (274) boot: Disabling RNG early entropy source... +I (285) cpu_start: Multicore app +I (294) cpu_start: Pro cpu start user code +I (294) cpu_start: cpu freq: 160000000 Hz +I (294) cpu_start: Application information: +I (297) cpu_start: Project name: bleprph +I (302) cpu_start: App version: v5.3-dev-1570-gbc703f3508-dirty +I (309) cpu_start: Compile time: Jan 18 2024 17:45:29 +I (315) cpu_start: ELF file SHA256: bd62addc6... +I (321) cpu_start: ESP-IDF: v5.3-dev-1570-gbc703f3508-dirty +I (328) cpu_start: Min chip rev: v0.0 +I (332) cpu_start: Max chip rev: v3.99 +I (337) cpu_start: Chip rev: v3.0 +I (342) heap_init: Initializing. RAM available for dynamic allocation: +I (349) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM +I (355) heap_init: At 3FFB4AA8 len 0002B558 (173 KiB): DRAM +I (362) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM +I (368) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM +I (374) heap_init: At 4008E9F4 len 0001160C (69 KiB): IRAM +I (382) spi_flash: detected chip: generic +I (385) spi_flash: flash io: dio +W (389) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header. +I (403) coexist: coex firmware version: c02915e +I (408) main_task: Started on CPU0 +I (418) main_task: Calling app_main() +I (428) NimBLE_BLE_PRPH: BLE Host Task Started +I (438) uart: queue free spaces: 8 +I (438) main_task: Returned from app_main() +I (478) NimBLE: Device Address: +I (478) NimBLE: 60:55:f9:f6:07:e2 +I (478) NimBLE: + +I (488) NimBLE: GAP procedure initiated: advertise; +I (488) NimBLE: disc_mode=2 +I (488) NimBLE: adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0 +I (498) NimBLE: +``` + +## Troubleshooting + +For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. diff --git a/examples/bluetooth/nimble/bleprph_host_only/main/CMakeLists.txt b/examples/bluetooth/nimble/bleprph_host_only/main/CMakeLists.txt new file mode 100644 index 0000000000..d730ef912a --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/main/CMakeLists.txt @@ -0,0 +1,6 @@ +set(srcs "main.c" + "gatt_svr.c" + "uart_driver.c") + +idf_component_register(SRCS "${srcs}" + INCLUDE_DIRS ".") diff --git a/examples/bluetooth/nimble/bleprph_host_only/main/Kconfig.projbuild b/examples/bluetooth/nimble/bleprph_host_only/main/Kconfig.projbuild new file mode 100644 index 0000000000..197519e903 --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/main/Kconfig.projbuild @@ -0,0 +1,140 @@ +menu "Example Configuration" + + menu "Uart Configuration" + + config EXAMPLE_HCI_UART_BAUDRATE + int "UART Baudrate for HCI" + range 115200 921600 + default 921600 + help + UART Baudrate for HCI. Please use standard baudrate. + + config EXAMPLE_HCI_UART_TX_PIN + int "UART Tx Pin" + default 4 + help + UART HCI Tx pin + + config EXAMPLE_HCI_UART_RX_PIN + int "UART Rx Pin" + default 5 + help + UART HCI Rx pin + + choice EXAMPLE_USE_HCI_UART_FLOW_CTRL + prompt "Uart Flow Control" + default EXAMPLE_UART_HW_FLOWCTRL_DISABLE + help + Uart Flow Control + + config EXAMPLE_UART_HW_FLOWCTRL_DISABLE + bool "Disable" + config EXAMPLE_UART_HW_FLOWCTRL_RTS + bool "Enable Rx hardware flow control" + config EXAMPLE_UART_HW_FLOWCTRL_CTS + bool "Enable Tx hardware flow control" + config EXAMPLE_UART_HW_FLOWCTRL_CTS_RTS + bool "Enable hardware flow control" + config EXAMPLE_UART_HW_FLOWCTRL_MAX + bool "Hardware Flow control max" + endchoice + + config EXAMPLE_HCI_UART_FLOW_CTRL + int + default 0 if EXAMPLE_UART_HW_FLOWCTRL_DISABLE + default 1 if EXAMPLE_UART_HW_FLOWCTRL_RTS + default 2 if EXAMPLE_UART_HW_FLOWCTRL_CTS + default 3 if EXAMPLE_UART_HW_FLOWCTRL_CTS_RTS + default 4 if EXAMPLE_UART_HW_FLOWCTRL_MAX + + config EXAMPLE_HCI_UART_RTS_PIN + int "UART Rts Pin" + default 19 + help + UART HCI RTS pin + + config EXAMPLE_HCI_UART_CTS_PIN + int "UART Cts Pin" + default 23 + help + UART HCI CTS pin + endmenu + + choice EXAMPLE_USE_IO_TYPE + prompt "I/O Capability" + default BLE_SM_IO_CAP_NO_IO + help + I/O capability of device. + + config BLE_SM_IO_CAP_DISP_ONLY + bool "DISPLAY ONLY" + config BLE_SM_IO_CAP_DISP_YES_NO + bool "DISPLAY YESNO" + config BLE_SM_IO_CAP_KEYBOARD_ONLY + bool "KEYBOARD ONLY" + config BLE_SM_IO_CAP_NO_IO + bool "Just works" + config BLE_SM_IO_CAP_KEYBOARD_DISP + bool "Both KEYBOARD & DISPLAY" + endchoice + + config EXAMPLE_IO_TYPE + int + default 0 if BLE_SM_IO_CAP_DISP_ONLY + default 1 if BLE_SM_IO_CAP_DISP_YES_NO + default 2 if BLE_SM_IO_CAP_KEYBOARD_ONLY + default 3 if BLE_SM_IO_CAP_NO_IO + default 4 if BLE_SM_IO_CAP_KEYBOARD_DISP + + config EXAMPLE_BONDING + bool + default n + prompt "Use Bonding" + help + Use this option to enable/disable bonding. + + config EXAMPLE_MITM + bool + default n + prompt "MITM security" + help + Use this option to enable/disable MITM security. + + config EXAMPLE_USE_SC + bool + depends on BT_NIMBLE_SM_SC + default n + prompt "Use Secure Connection feature" + help + Use this option to enable/disable Security Manager Secure Connection 4.2 feature. + + config EXAMPLE_EXTENDED_ADV + bool + depends on SOC_BLE_50_SUPPORTED + default y if SOC_ESP_NIMBLE_CONTROLLER + select BT_NIMBLE_EXT_ADV + prompt "Enable Extended Adv" + help + Use this option to enable extended advertising in the example. + If this option is disabled, ensure config BT_NIMBLE_EXT_ADV is + also disabled from Nimble stack menuconfig + + config EXAMPLE_RANDOM_ADDR + bool + prompt "Advertise RANDOM Address" + help + Use this option to advertise a random address instead of public address + + config EXAMPLE_ENCRYPTION + bool + prompt "Enable Link Encryption" + help + This adds Encrypted Read and Write permissions in the custom GATT server. + + config EXAMPLE_RESOLVE_PEER_ADDR + bool + prompt "Enable resolving peer address" + help + Use this option to enable resolving peer's address. + +endmenu diff --git a/examples/bluetooth/nimble/bleprph_host_only/main/bleprph.h b/examples/bluetooth/nimble/bleprph_host_only/main/bleprph.h new file mode 100644 index 0000000000..91912742bd --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/main/bleprph.h @@ -0,0 +1,35 @@ +/* + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef H_BLEPRPH_ +#define H_BLEPRPH_ + +#include +#include "nimble/ble.h" +#include "modlog/modlog.h" +#include "esp_peripheral.h" +#ifdef __cplusplus +extern "C" { +#endif + +struct ble_hs_cfg; +struct ble_gatt_register_ctxt; + +/** GATT server. */ +#define GATT_SVR_SVC_ALERT_UUID 0x1811 +#define GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47 +#define GATT_SVR_CHR_NEW_ALERT 0x2A46 +#define GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48 +#define GATT_SVR_CHR_UNR_ALERT_STAT_UUID 0x2A45 +#define GATT_SVR_CHR_ALERT_NOT_CTRL_PT 0x2A44 + +void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg); +int gatt_svr_init(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/examples/bluetooth/nimble/bleprph_host_only/main/gatt_svr.c b/examples/bluetooth/nimble/bleprph_host_only/main/gatt_svr.c new file mode 100644 index 0000000000..8a9d8b0e7c --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/main/gatt_svr.c @@ -0,0 +1,247 @@ +/* + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +#include "host/ble_hs.h" +#include "host/ble_uuid.h" +#include "services/gap/ble_svc_gap.h" +#include "services/gatt/ble_svc_gatt.h" +#include "bleprph.h" +#include "services/ans/ble_svc_ans.h" + +/*** Maximum number of characteristics with the notify flag ***/ +#define MAX_NOTIFY 5 + +static const ble_uuid128_t gatt_svr_svc_uuid = + BLE_UUID128_INIT(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12, + 0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59); + +/* A characteristic that can be subscribed to */ +static uint8_t gatt_svr_chr_val; +static uint16_t gatt_svr_chr_val_handle; +static const ble_uuid128_t gatt_svr_chr_uuid = + BLE_UUID128_INIT(0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, + 0x22, 0x22, 0x22, 0x22, 0x33, 0x33, 0x33, 0x33); + +/* A custom descriptor */ +static uint8_t gatt_svr_dsc_val; +static const ble_uuid128_t gatt_svr_dsc_uuid = + BLE_UUID128_INIT(0x01, 0x01, 0x01, 0x01, 0x12, 0x12, 0x12, 0x12, + 0x23, 0x23, 0x23, 0x23, 0x34, 0x34, 0x34, 0x34); + +static int +gatt_svc_access(uint16_t conn_handle, uint16_t attr_handle, + struct ble_gatt_access_ctxt *ctxt, + void *arg); + +static const struct ble_gatt_svc_def gatt_svr_svcs[] = { + { + /*** Service ***/ + .type = BLE_GATT_SVC_TYPE_PRIMARY, + .uuid = &gatt_svr_svc_uuid.u, + .characteristics = (struct ble_gatt_chr_def[]) + { { + /*** This characteristic can be subscribed to by writing 0x00 and 0x01 to the CCCD ***/ + .uuid = &gatt_svr_chr_uuid.u, + .access_cb = gatt_svc_access, +#if CONFIG_EXAMPLE_ENCRYPTION + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE | + BLE_GATT_CHR_F_READ_ENC | BLE_GATT_CHR_F_WRITE_ENC | + BLE_GATT_CHR_F_NOTIFY | BLE_GATT_CHR_F_INDICATE, +#else + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_NOTIFY | BLE_GATT_CHR_F_INDICATE, +#endif + .val_handle = &gatt_svr_chr_val_handle, + .descriptors = (struct ble_gatt_dsc_def[]) + { { + .uuid = &gatt_svr_dsc_uuid.u, +#if CONFIG_EXAMPLE_ENCRYPTION + .att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_ENC, +#else + .att_flags = BLE_ATT_F_READ, +#endif + .access_cb = gatt_svc_access, + }, { + 0, /* No more descriptors in this characteristic */ + } + }, + }, { + 0, /* No more characteristics in this service. */ + } + }, + }, + + { + 0, /* No more services. */ + }, +}; + +static int +gatt_svr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len, + void *dst, uint16_t *len) +{ + uint16_t om_len; + int rc; + + om_len = OS_MBUF_PKTLEN(om); + if (om_len < min_len || om_len > max_len) { + return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN; + } + + rc = ble_hs_mbuf_to_flat(om, dst, max_len, len); + if (rc != 0) { + return BLE_ATT_ERR_UNLIKELY; + } + + return 0; +} + +/** + * Access callback whenever a characteristic/descriptor is read or written to. + * Here reads and writes need to be handled. + * ctxt->op tells weather the operation is read or write and + * weather it is on a characteristic or descriptor, + * ctxt->dsc->uuid tells which characteristic/descriptor is accessed. + * attr_handle give the value handle of the attribute being accessed. + * Accordingly do: + * Append the value to ctxt->om if the operation is READ + * Write ctxt->om to the value if the operation is WRITE + **/ +static int +gatt_svc_access(uint16_t conn_handle, uint16_t attr_handle, + struct ble_gatt_access_ctxt *ctxt, void *arg) +{ + const ble_uuid_t *uuid; + int rc; + + switch (ctxt->op) { + case BLE_GATT_ACCESS_OP_READ_CHR: + if (conn_handle != BLE_HS_CONN_HANDLE_NONE) { + MODLOG_DFLT(INFO, "Characteristic read; conn_handle=%d attr_handle=%d\n", + conn_handle, attr_handle); + } else { + MODLOG_DFLT(INFO, "Characteristic read by NimBLE stack; attr_handle=%d\n", + attr_handle); + } + uuid = ctxt->chr->uuid; + if (attr_handle == gatt_svr_chr_val_handle) { + rc = os_mbuf_append(ctxt->om, + &gatt_svr_chr_val, + sizeof(gatt_svr_chr_val)); + return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; + } + goto unknown; + + case BLE_GATT_ACCESS_OP_WRITE_CHR: + if (conn_handle != BLE_HS_CONN_HANDLE_NONE) { + MODLOG_DFLT(INFO, "Characteristic write; conn_handle=%d attr_handle=%d", + conn_handle, attr_handle); + } else { + MODLOG_DFLT(INFO, "Characteristic write by NimBLE stack; attr_handle=%d", + attr_handle); + } + uuid = ctxt->chr->uuid; + if (attr_handle == gatt_svr_chr_val_handle) { + rc = gatt_svr_write(ctxt->om, + sizeof(gatt_svr_chr_val), + sizeof(gatt_svr_chr_val), + &gatt_svr_chr_val, NULL); + ble_gatts_chr_updated(attr_handle); + MODLOG_DFLT(INFO, "Notification/Indication scheduled for " + "all subscribed peers.\n"); + return rc; + } + goto unknown; + + case BLE_GATT_ACCESS_OP_READ_DSC: + if (conn_handle != BLE_HS_CONN_HANDLE_NONE) { + MODLOG_DFLT(INFO, "Descriptor read; conn_handle=%d attr_handle=%d\n", + conn_handle, attr_handle); + } else { + MODLOG_DFLT(INFO, "Descriptor read by NimBLE stack; attr_handle=%d\n", + attr_handle); + } + uuid = ctxt->dsc->uuid; + if (ble_uuid_cmp(uuid, &gatt_svr_dsc_uuid.u) == 0) { + rc = os_mbuf_append(ctxt->om, + &gatt_svr_dsc_val, + sizeof(gatt_svr_chr_val)); + return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; + } + goto unknown; + + case BLE_GATT_ACCESS_OP_WRITE_DSC: + goto unknown; + + default: + goto unknown; + } + +unknown: + /* Unknown characteristic/descriptor; + * The NimBLE host should not have called this function; + */ + assert(0); + return BLE_ATT_ERR_UNLIKELY; +} + +void +gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) +{ + char buf[BLE_UUID_STR_LEN]; + + switch (ctxt->op) { + case BLE_GATT_REGISTER_OP_SVC: + MODLOG_DFLT(DEBUG, "registered service %s with handle=%d\n", + ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf), + ctxt->svc.handle); + break; + + case BLE_GATT_REGISTER_OP_CHR: + MODLOG_DFLT(DEBUG, "registering characteristic %s with " + "def_handle=%d val_handle=%d\n", + ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf), + ctxt->chr.def_handle, + ctxt->chr.val_handle); + break; + + case BLE_GATT_REGISTER_OP_DSC: + MODLOG_DFLT(DEBUG, "registering descriptor %s with handle=%d\n", + ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf), + ctxt->dsc.handle); + break; + + default: + assert(0); + break; + } +} + +int +gatt_svr_init(void) +{ + int rc; + + ble_svc_gap_init(); + ble_svc_gatt_init(); + ble_svc_ans_init(); + + rc = ble_gatts_count_cfg(gatt_svr_svcs); + if (rc != 0) { + return rc; + } + + rc = ble_gatts_add_svcs(gatt_svr_svcs); + if (rc != 0) { + return rc; + } + + /* Setting a value for the read-only descriptor */ + gatt_svr_dsc_val = 0x99; + + return 0; +} diff --git a/examples/bluetooth/nimble/bleprph_host_only/main/idf_component.yml b/examples/bluetooth/nimble/bleprph_host_only/main/idf_component.yml new file mode 100644 index 0000000000..d6e735fe77 --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/main/idf_component.yml @@ -0,0 +1,3 @@ +dependencies: + nimble_peripheral_utils: + path: ${IDF_PATH}/examples/bluetooth/nimble/common/nimble_peripheral_utils diff --git a/examples/bluetooth/nimble/bleprph_host_only/main/main.c b/examples/bluetooth/nimble/bleprph_host_only/main/main.c new file mode 100644 index 0000000000..e34b0683fc --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/main/main.c @@ -0,0 +1,548 @@ +/* + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "esp_log.h" +#include "nvs_flash.h" +/* BLE */ +#include "nimble/nimble_port.h" +#include "nimble/nimble_port_freertos.h" +#include "host/ble_hs.h" +#include "host/util/util.h" +#include "console/console.h" +#include "services/gap/ble_svc_gap.h" +#include "bleprph.h" +#include "uart_driver.h" + +#if CONFIG_EXAMPLE_EXTENDED_ADV +static uint8_t ext_adv_pattern_1[] = { + 0x02, 0x01, 0x06, + 0x03, 0x03, 0xab, 0xcd, + 0x03, 0x03, 0x18, 0x11, + 0x11, 0X09, 'n', 'i', 'm', 'b', 'l', 'e', '-', 'b', 'l', 'e', 'p', 'r', 'p', 'h', '-', 'e', +}; +#endif + +static const char *tag = "NimBLE_BLE_PRPH"; +static int bleprph_gap_event(struct ble_gap_event *event, void *arg); +#if CONFIG_EXAMPLE_RANDOM_ADDR +static uint8_t own_addr_type = BLE_OWN_ADDR_RANDOM; +#else +static uint8_t own_addr_type; +#endif + +void ble_store_config_init(void); + +/** + * Logs information about a connection to the console. + */ +static void +bleprph_print_conn_desc(struct ble_gap_conn_desc *desc) +{ + MODLOG_DFLT(INFO, "handle=%d our_ota_addr_type=%d our_ota_addr=", + desc->conn_handle, desc->our_ota_addr.type); + print_addr(desc->our_ota_addr.val); + MODLOG_DFLT(INFO, " our_id_addr_type=%d our_id_addr=", + desc->our_id_addr.type); + print_addr(desc->our_id_addr.val); + MODLOG_DFLT(INFO, " peer_ota_addr_type=%d peer_ota_addr=", + desc->peer_ota_addr.type); + print_addr(desc->peer_ota_addr.val); + MODLOG_DFLT(INFO, " peer_id_addr_type=%d peer_id_addr=", + desc->peer_id_addr.type); + print_addr(desc->peer_id_addr.val); + MODLOG_DFLT(INFO, " conn_itvl=%d conn_latency=%d supervision_timeout=%d " + "encrypted=%d authenticated=%d bonded=%d\n", + desc->conn_itvl, desc->conn_latency, + desc->supervision_timeout, + desc->sec_state.encrypted, + desc->sec_state.authenticated, + desc->sec_state.bonded); +} + +#if CONFIG_EXAMPLE_EXTENDED_ADV +/** + * Enables advertising with the following parameters: + * o General discoverable mode. + * o Undirected connectable mode. + */ +static void +ext_bleprph_advertise(void) +{ + struct ble_gap_ext_adv_params params; + struct os_mbuf *data; + uint8_t instance = 0; + int rc; + + /* First check if any instance is already active */ + if(ble_gap_ext_adv_active(instance)) { + return; + } + + /* use defaults for non-set params */ + memset (¶ms, 0, sizeof(params)); + + /* enable connectable advertising */ + params.connectable = 1; + + /* advertise using random addr */ + params.own_addr_type = BLE_OWN_ADDR_PUBLIC; + + params.primary_phy = BLE_HCI_LE_PHY_1M; + params.secondary_phy = BLE_HCI_LE_PHY_2M; + //params.tx_power = 127; + params.sid = 1; + + params.itvl_min = BLE_GAP_ADV_FAST_INTERVAL1_MIN; + params.itvl_max = BLE_GAP_ADV_FAST_INTERVAL1_MIN; + + /* configure instance 0 */ + rc = ble_gap_ext_adv_configure(instance, ¶ms, NULL, + bleprph_gap_event, NULL); + assert (rc == 0); + + /* in this case only scan response is allowed */ + + /* get mbuf for scan rsp data */ + data = os_msys_get_pkthdr(sizeof(ext_adv_pattern_1), 0); + assert(data); + + /* fill mbuf with scan rsp data */ + rc = os_mbuf_append(data, ext_adv_pattern_1, sizeof(ext_adv_pattern_1)); + assert(rc == 0); + + rc = ble_gap_ext_adv_set_data(instance, data); + assert (rc == 0); + + /* start advertising */ + rc = ble_gap_ext_adv_start(instance, 0, 0); + assert (rc == 0); +} +#else +/** + * Enables advertising with the following parameters: + * o General discoverable mode. + * o Undirected connectable mode. + */ +static void +bleprph_advertise(void) +{ + struct ble_gap_adv_params adv_params; + struct ble_hs_adv_fields fields; + const char *name; + int rc; + + /** + * Set the advertisement data included in our advertisements: + * o Flags (indicates advertisement type and other general info). + * o Advertising tx power. + * o Device name. + * o 16-bit service UUIDs (alert notifications). + */ + + memset(&fields, 0, sizeof fields); + + /* Advertise two flags: + * o Discoverability in forthcoming advertisement (general) + * o BLE-only (BR/EDR unsupported). + */ + fields.flags = BLE_HS_ADV_F_DISC_GEN | + BLE_HS_ADV_F_BREDR_UNSUP; + + /* Indicate that the TX power level field should be included; have the + * stack fill this value automatically. This is done by assigning the + * special value BLE_HS_ADV_TX_PWR_LVL_AUTO. + */ + fields.tx_pwr_lvl_is_present = 1; + fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO; + + name = ble_svc_gap_device_name(); + fields.name = (uint8_t *)name; + fields.name_len = strlen(name); + fields.name_is_complete = 1; + + fields.uuids16 = (ble_uuid16_t[]) { + BLE_UUID16_INIT(GATT_SVR_SVC_ALERT_UUID) + }; + fields.num_uuids16 = 1; + fields.uuids16_is_complete = 1; + + rc = ble_gap_adv_set_fields(&fields); + if (rc != 0) { + MODLOG_DFLT(ERROR, "error setting advertisement data; rc=%d\n", rc); + return; + } + + /* Begin advertising. */ + memset(&adv_params, 0, sizeof adv_params); + adv_params.conn_mode = BLE_GAP_CONN_MODE_UND; + adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN; + rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER, + &adv_params, bleprph_gap_event, NULL); + if (rc != 0) { + MODLOG_DFLT(ERROR, "error enabling advertisement; rc=%d\n", rc); + return; + } +} +#endif + +#if MYNEWT_VAL(BLE_POWER_CONTROL) +static void bleprph_power_control(uint16_t conn_handle) +{ + int rc; + + rc = ble_gap_read_remote_transmit_power_level(conn_handle, 0x01 ); // Attempting on LE 1M phy + assert (rc == 0); + + rc = ble_gap_set_transmit_power_reporting_enable(conn_handle, 0x1, 0x1); + assert (rc == 0); +} +#endif + +/** + * The nimble host executes this callback when a GAP event occurs. The + * application associates a GAP event callback with each connection that forms. + * bleprph uses the same callback for all connections. + * + * @param event The type of event being signalled. + * @param ctxt Various information pertaining to the event. + * @param arg Application-specified argument; unused by + * bleprph. + * + * @return 0 if the application successfully handled the + * event; nonzero on failure. The semantics + * of the return code is specific to the + * particular GAP event being signalled. + */ +static int +bleprph_gap_event(struct ble_gap_event *event, void *arg) +{ + struct ble_gap_conn_desc desc; + int rc; + + switch (event->type) { + case BLE_GAP_EVENT_CONNECT: + /* A new connection was established or a connection attempt failed. */ + MODLOG_DFLT(INFO, "connection %s; status=%d ", + event->connect.status == 0 ? "established" : "failed", + event->connect.status); + if (event->connect.status == 0) { + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + assert(rc == 0); + bleprph_print_conn_desc(&desc); + } + MODLOG_DFLT(INFO, "\n"); + + if (event->connect.status != 0) { + /* Connection failed; resume advertising. */ +#if CONFIG_EXAMPLE_EXTENDED_ADV + ext_bleprph_advertise(); +#else + bleprph_advertise(); +#endif + } + +#if MYNEWT_VAL(BLE_POWER_CONTROL) + bleprph_power_control(event->connect.conn_handle); +#endif + return 0; + + case BLE_GAP_EVENT_DISCONNECT: + MODLOG_DFLT(INFO, "disconnect; reason=%d ", event->disconnect.reason); + bleprph_print_conn_desc(&event->disconnect.conn); + MODLOG_DFLT(INFO, "\n"); + + /* Connection terminated; resume advertising. */ +#if CONFIG_EXAMPLE_EXTENDED_ADV + ext_bleprph_advertise(); +#else + bleprph_advertise(); +#endif + return 0; + + case BLE_GAP_EVENT_CONN_UPDATE: + /* The central has updated the connection parameters. */ + MODLOG_DFLT(INFO, "connection updated; status=%d ", + event->conn_update.status); + rc = ble_gap_conn_find(event->conn_update.conn_handle, &desc); + assert(rc == 0); + bleprph_print_conn_desc(&desc); + MODLOG_DFLT(INFO, "\n"); + return 0; + + case BLE_GAP_EVENT_ADV_COMPLETE: + MODLOG_DFLT(INFO, "advertise complete; reason=%d", + event->adv_complete.reason); +#if CONFIG_EXAMPLE_EXTENDED_ADV + ext_bleprph_advertise(); +#else + bleprph_advertise(); +#endif + return 0; + + case BLE_GAP_EVENT_ENC_CHANGE: + /* Encryption has been enabled or disabled for this connection. */ + MODLOG_DFLT(INFO, "encryption change event; status=%d ", + event->enc_change.status); + rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc); + assert(rc == 0); + bleprph_print_conn_desc(&desc); + MODLOG_DFLT(INFO, "\n"); + return 0; + + case BLE_GAP_EVENT_NOTIFY_TX: + MODLOG_DFLT(INFO, "notify_tx event; conn_handle=%d attr_handle=%d " + "status=%d is_indication=%d", + event->notify_tx.conn_handle, + event->notify_tx.attr_handle, + event->notify_tx.status, + event->notify_tx.indication); + return 0; + + case BLE_GAP_EVENT_SUBSCRIBE: + MODLOG_DFLT(INFO, "subscribe event; conn_handle=%d attr_handle=%d " + "reason=%d prevn=%d curn=%d previ=%d curi=%d\n", + event->subscribe.conn_handle, + event->subscribe.attr_handle, + event->subscribe.reason, + event->subscribe.prev_notify, + event->subscribe.cur_notify, + event->subscribe.prev_indicate, + event->subscribe.cur_indicate); + return 0; + + case BLE_GAP_EVENT_MTU: + MODLOG_DFLT(INFO, "mtu update event; conn_handle=%d cid=%d mtu=%d\n", + event->mtu.conn_handle, + event->mtu.channel_id, + event->mtu.value); + return 0; + + case BLE_GAP_EVENT_REPEAT_PAIRING: + /* We already have a bond with the peer, but it is attempting to + * establish a new secure link. This app sacrifices security for + * convenience: just throw away the old bond and accept the new link. + */ + + /* Delete the old bond. */ + rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc); + assert(rc == 0); + ble_store_util_delete_peer(&desc.peer_id_addr); + + /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should + * continue with the pairing operation. + */ + return BLE_GAP_REPEAT_PAIRING_RETRY; + + case BLE_GAP_EVENT_PASSKEY_ACTION: + ESP_LOGI(tag, "PASSKEY_ACTION_EVENT started"); + struct ble_sm_io pkey = {0}; + int key = 0; + + if (event->passkey.params.action == BLE_SM_IOACT_DISP) { + pkey.action = event->passkey.params.action; + pkey.passkey = 123456; // This is the passkey to be entered on peer + ESP_LOGI(tag, "Enter passkey %" PRIu32 "on the peer side", pkey.passkey); + rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey); + ESP_LOGI(tag, "ble_sm_inject_io result: %d", rc); + } else if (event->passkey.params.action == BLE_SM_IOACT_NUMCMP) { + ESP_LOGI(tag, "Passkey on device's display: %" PRIu32 , event->passkey.params.numcmp); + ESP_LOGI(tag, "Accept or reject the passkey through console in this format -> key Y or key N"); + pkey.action = event->passkey.params.action; + if (scli_receive_key(&key)) { + pkey.numcmp_accept = key; + } else { + pkey.numcmp_accept = 0; + ESP_LOGE(tag, "Timeout! Rejecting the key"); + } + rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey); + ESP_LOGI(tag, "ble_sm_inject_io result: %d", rc); + } else if (event->passkey.params.action == BLE_SM_IOACT_OOB) { + static uint8_t tem_oob[16] = {0}; + pkey.action = event->passkey.params.action; + for (int i = 0; i < 16; i++) { + pkey.oob[i] = tem_oob[i]; + } + rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey); + ESP_LOGI(tag, "ble_sm_inject_io result: %d", rc); + } else if (event->passkey.params.action == BLE_SM_IOACT_INPUT) { + ESP_LOGI(tag, "Enter the passkey through console in this format-> key 123456"); + pkey.action = event->passkey.params.action; + if (scli_receive_key(&key)) { + pkey.passkey = key; + } else { + pkey.passkey = 0; + ESP_LOGE(tag, "Timeout! Passing 0 as the key"); + } + rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey); + ESP_LOGI(tag, "ble_sm_inject_io result: %d", rc); + } + return 0; + +#if MYNEWT_VAL(BLE_POWER_CONTROL) + case BLE_GAP_EVENT_TRANSMIT_POWER: + MODLOG_DFLT(INFO, "Transmit power event : status=%d conn_handle=%d reason=%d " + "phy=%d power_level=%x power_level_flag=%d delta=%d", + event->transmit_power.status, + event->transmit_power.conn_handle, + event->transmit_power.reason, + event->transmit_power.phy, + event->transmit_power.transmit_power_level, + event->transmit_power.transmit_power_level_flag, + event->transmit_power.delta); + return 0; + + case BLE_GAP_EVENT_PATHLOSS_THRESHOLD: + MODLOG_DFLT(INFO, "Pathloss threshold event : conn_handle=%d current path loss=%d " + "zone_entered =%d", + event->pathloss_threshold.conn_handle, + event->pathloss_threshold.current_path_loss, + event->pathloss_threshold.zone_entered); + return 0; +#endif + } + + return 0; +} + +static void +bleprph_on_reset(int reason) +{ + MODLOG_DFLT(ERROR, "Resetting state; reason=%d\n", reason); +} + +#if CONFIG_EXAMPLE_RANDOM_ADDR +static void +ble_app_set_addr(void) +{ + ble_addr_t addr; + int rc; + + /* generate new non-resolvable private address */ + rc = ble_hs_id_gen_rnd(0, &addr); + assert(rc == 0); + + /* set generated address */ + rc = ble_hs_id_set_rnd(addr.val); + + assert(rc == 0); +} +#endif + +static void +bleprph_on_sync(void) +{ + int rc; + +#if CONFIG_EXAMPLE_RANDOM_ADDR + /* Generate a non-resolvable private address. */ + ble_app_set_addr(); +#endif + + /* Make sure we have proper identity address set (public preferred) */ +#if CONFIG_EXAMPLE_RANDOM_ADDR + rc = ble_hs_util_ensure_addr(1); +#else + rc = ble_hs_util_ensure_addr(0); +#endif + assert(rc == 0); + + /* Figure out address to use while advertising (no privacy for now) */ + rc = ble_hs_id_infer_auto(0, &own_addr_type); + if (rc != 0) { + MODLOG_DFLT(ERROR, "error determining address type; rc=%d\n", rc); + return; + } + + /* Printing ADDR */ + uint8_t addr_val[6] = {0}; + rc = ble_hs_id_copy_addr(own_addr_type, addr_val, NULL); + + MODLOG_DFLT(INFO, "Device Address: "); + print_addr(addr_val); + MODLOG_DFLT(INFO, "\n"); + /* Begin advertising. */ +#if CONFIG_EXAMPLE_EXTENDED_ADV + ext_bleprph_advertise(); +#else + bleprph_advertise(); +#endif +} + +void bleprph_host_task(void *param) +{ + ESP_LOGI(tag, "BLE Host Task Started"); + /* This function will return only when nimble_port_stop() is executed */ + nimble_port_run(); + + nimble_port_freertos_deinit(); +} + +void +app_main(void) +{ + int rc; + + /* Initialize NVS — it is used to store PHY calibration data */ + esp_err_t ret = nvs_flash_init(); + if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { + ESP_ERROR_CHECK(nvs_flash_erase()); + ret = nvs_flash_init(); + } + ESP_ERROR_CHECK(ret); + + hci_uart_open(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + ESP_LOGE(tag, "Failed to init nimble %d ", ret); + return; + } + /* Initialize the NimBLE host configuration. */ + ble_hs_cfg.reset_cb = bleprph_on_reset; + ble_hs_cfg.sync_cb = bleprph_on_sync; + ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb; + ble_hs_cfg.store_status_cb = ble_store_util_status_rr; + + ble_hs_cfg.sm_io_cap = CONFIG_EXAMPLE_IO_TYPE; +#ifdef CONFIG_EXAMPLE_BONDING + ble_hs_cfg.sm_bonding = 1; + /* Enable the appropriate bit masks to make sure the keys + * that are needed are exchanged + */ + ble_hs_cfg.sm_our_key_dist |= BLE_SM_PAIR_KEY_DIST_ENC; + ble_hs_cfg.sm_their_key_dist |= BLE_SM_PAIR_KEY_DIST_ENC; +#endif +#ifdef CONFIG_EXAMPLE_MITM + ble_hs_cfg.sm_mitm = 1; +#endif +#ifdef CONFIG_EXAMPLE_USE_SC + ble_hs_cfg.sm_sc = 1; +#else + ble_hs_cfg.sm_sc = 0; +#endif +#ifdef CONFIG_EXAMPLE_RESOLVE_PEER_ADDR + /* Stores the IRK */ + ble_hs_cfg.sm_our_key_dist |= BLE_SM_PAIR_KEY_DIST_ID; + ble_hs_cfg.sm_their_key_dist |= BLE_SM_PAIR_KEY_DIST_ID; +#endif + + rc = gatt_svr_init(); + assert(rc == 0); + + /* Set the default device name. */ + rc = ble_svc_gap_device_name_set("nimble-bleprph"); + assert(rc == 0); + + /* XXX Need to have template for store */ + ble_store_config_init(); + + nimble_port_freertos_init(bleprph_host_task); + + /* Initialize command line interface to accept input from user */ + rc = scli_init(); + if (rc != ESP_OK) { + ESP_LOGE(tag, "scli_init() failed"); + } +} diff --git a/examples/bluetooth/nimble/bleprph_host_only/main/uart_driver.c b/examples/bluetooth/nimble/bleprph_host_only/main/uart_driver.c new file mode 100644 index 0000000000..07e82387f5 --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/main/uart_driver.c @@ -0,0 +1,231 @@ +/* + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "driver/uart.h" +#include "esp_log.h" +#include "esp_attr.h" +#include "uart_driver.h" +#include "nimble/hci_common.h" +#include "host/ble_hs_mbuf.h" + +#define TAG "UART_HCI" + +#define UART_NO (1) +#define UART_BUF_SZ (1024) + +#define UART_TX_PIN (CONFIG_EXAMPLE_HCI_UART_TX_PIN) +#define UART_RX_PIN (CONFIG_EXAMPLE_HCI_UART_RX_PIN) +#define UART_RTS_PIN (CONFIG_EXAMPLE_HCI_UART_RTS_PIN) +#define UART_CTS_PIN (CONFIG_EXAMPLE_HCI_UART_CTS_PIN) +#define HCI_H4_ACL (0x02) +#define HCI_H4_CMD (0x01) +#define HCI_H4_EVT (0x04) +#define BLE_HCI_EVENT_HDR_LEN (2) +#define BLE_HCI_CMD_HDR_LEN (3) + +enum { + UART_RX_TYPE = 0, + UART_RX_LEN, + UART_RX_DATA, +}; + +enum { + DATA_TYPE_COMMAND = 1, + DATA_TYPE_ACL = 2, + DATA_TYPE_EVENT = 4 +}; + +TaskHandle_t s_rx_task_hdl; + +static void IRAM_ATTR hci_uart_rx_task(void *arg) +{ + uint8_t buf[1026]; + int len_now_read = -1; + uint32_t len_to_read = 1; + uint32_t len_total_read = 0; + uint8_t rx_st = UART_RX_TYPE; + + while (1) { + len_now_read = uart_read_bytes(UART_NO, &buf[len_total_read], len_to_read, portMAX_DELAY); + assert(len_now_read == len_to_read); + len_total_read += len_now_read; + + switch (rx_st) { + case UART_RX_TYPE: { + assert(buf[0] >= DATA_TYPE_ACL && buf[0] <= DATA_TYPE_EVENT); + if (buf[0] == DATA_TYPE_ACL) { + len_to_read = 4; + } else if (buf[0] == DATA_TYPE_EVENT) { + len_to_read = 2; + } else { + assert(0); + } + rx_st = UART_RX_LEN; + } + break; + + case UART_RX_LEN: { + if (buf[0] == DATA_TYPE_ACL) { + len_to_read = buf[3] | (buf[4] << 8); + } else if (buf[0] == DATA_TYPE_EVENT) { + len_to_read = buf[2]; + } else { + assert(0); + } + rx_st = UART_RX_DATA; + } + break; + + case UART_RX_DATA: { + uint8_t *data = buf; + int rc; + + if (data[0] == HCI_H4_EVT) { + uint8_t *evbuf; + int totlen; + + totlen = BLE_HCI_EVENT_HDR_LEN + data[2]; + assert(totlen <= UINT8_MAX + BLE_HCI_EVENT_HDR_LEN); + + if (totlen > MYNEWT_VAL(BLE_TRANSPORT_EVT_SIZE)) { + ESP_LOGE(TAG, "Received HCI data length at host (%d)" + "exceeds maximum configured HCI event buffer size (%d).", + totlen, MYNEWT_VAL(BLE_TRANSPORT_EVT_SIZE)); + break; + } + + if (data[1] == BLE_HCI_EVCODE_HW_ERROR) { + assert(0); + } + + /* Allocate LE Advertising Report Event from lo pool only */ + if ((data[1] == BLE_HCI_EVCODE_LE_META) && + (data[3] == BLE_HCI_LE_SUBEV_ADV_RPT || data[3] == BLE_HCI_LE_SUBEV_EXT_ADV_RPT)) { + evbuf = ble_transport_alloc_evt(1); + /* Skip advertising report if we're out of memory */ + if (!evbuf) { + ESP_LOGE(TAG, "No buffers"); + break; + } + } else { + evbuf = ble_transport_alloc_evt(0); + assert(evbuf != NULL); + } + + memset(evbuf, 0, sizeof * evbuf); + memcpy(evbuf, &data[1], totlen); + + rc = ble_transport_to_hs_evt(evbuf); + assert(rc == 0); + } else if (data[0] == HCI_H4_ACL) { + struct os_mbuf *m = NULL; + m = ble_transport_alloc_acl_from_ll(); + if (!m) { + ESP_LOGE(TAG, "No buffers"); + } + + if ((rc = os_mbuf_append(m, &data[1], len_total_read - 1)) != 0) { + ESP_LOGE(TAG, "%s failed to os_mbuf_append; rc = %d", __func__, rc); + os_mbuf_free_chain(m); + return; + } + + ble_transport_to_hs_acl(m); + } + + rx_st = UART_RX_TYPE; + len_to_read = 1; + len_total_read = 0; + } + break; + + default: { + assert(0); + break; + } + } + + } + vTaskDelete(NULL); +} + +void hci_uart_send(uint8_t *buf, uint16_t len) +{ + uint8_t *p = buf; + int len_write = 0; + + while (len) { + len_write = uart_write_bytes(UART_NO, p, len); + assert(len_write > 0); + len -= len_write; + p += len_write; + } +} + +int +ble_transport_to_ll_acl_impl(struct os_mbuf *om) +{ + uint8_t buf[OS_MBUF_PKTLEN(om) + 1]; + int rc; + buf[0] = HCI_H4_ACL; + rc = ble_hs_mbuf_to_flat(om, buf + 1, OS_MBUF_PKTLEN(om), NULL); + if(rc) { + ESP_LOGE(TAG, "Error copying data %d", rc); + os_mbuf_free_chain(om); + return rc; + } + hci_uart_send(buf, OS_MBUF_PKTLEN(om) + 1); + os_mbuf_free_chain(om); + return 0; +} + +int +ble_transport_to_ll_cmd_impl(void *buf) +{ + int len = 3 + ((uint8_t *)buf)[2] + 1; + uint8_t data[258]; + data[0] = HCI_H4_CMD; + memcpy(data + 1, buf, len - 1); + hci_uart_send(data, len); + ble_transport_free(buf); + return 0; +} + +void hci_uart_open(void) +{ + uart_config_t uart_config = { + .baud_rate = CONFIG_EXAMPLE_HCI_UART_BAUDRATE, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = CONFIG_EXAMPLE_HCI_UART_FLOW_CTRL, + .source_clk = UART_SCLK_DEFAULT, + }; + + int intr_alloc_flags = 0; +#if CONFIG_UART_ISR_IN_IRAM + intr_alloc_flags = ESP_INTR_FLAG_IRAM; +#endif + + ESP_ERROR_CHECK(uart_driver_install(UART_NO, UART_BUF_SZ * 2, UART_BUF_SZ * 2, 0, NULL, intr_alloc_flags)); + ESP_ERROR_CHECK(uart_param_config(UART_NO, &uart_config)); + ESP_ERROR_CHECK(uart_set_pin(UART_NO, UART_TX_PIN, UART_RX_PIN, -1, -1)); + + xTaskCreate(hci_uart_rx_task, "hci_uart_rx_task", 2048, NULL, 12, &s_rx_task_hdl); +} + +void hci_uart_close(void) +{ + if (s_rx_task_hdl) { + vTaskDelete(s_rx_task_hdl); + } + uart_driver_delete(UART_NO); +} diff --git a/examples/bluetooth/nimble/bleprph_host_only/main/uart_driver.h b/examples/bluetooth/nimble/bleprph_host_only/main/uart_driver.h new file mode 100644 index 0000000000..89f2f5cb26 --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/main/uart_driver.h @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#ifndef __UART_DRIVER_H__ +#define __UART_DRIVER_H__ + +#include +#include + +/** + * @brief open HCI transport of uart + */ +void hci_uart_open(void); + +/** + * @brief close HCI transport of uart + */ +void hci_uart_close(void); + +/** + * @brief send data from host to HCI transport + * + * @param[in] data pointer to data buffer + * @param[in] len length of data + */ +void hci_uart_send(uint8_t *data, uint16_t len); + +#endif /* __UART_DRIVER_H__ */ diff --git a/examples/bluetooth/nimble/bleprph_host_only/sdkconfig.defaults b/examples/bluetooth/nimble/bleprph_host_only/sdkconfig.defaults new file mode 100644 index 0000000000..eb07a5c578 --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/sdkconfig.defaults @@ -0,0 +1,11 @@ +# Override some defaults so BT stack is enabled +# in this example + +# +# BT config +# +CONFIG_BT_ENABLED=y +CONFIG_BT_CONTROLLER_DISABLED=y +CONFIG_BT_BLUEDROID_ENABLED=n +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_TRANSPORT_UART=n diff --git a/examples/bluetooth/nimble/bleprph_host_only/tutorial/bleprph_host_only_walkthrough.md b/examples/bluetooth/nimble/bleprph_host_only/tutorial/bleprph_host_only_walkthrough.md new file mode 100644 index 0000000000..4bfba23bc4 --- /dev/null +++ b/examples/bluetooth/nimble/bleprph_host_only/tutorial/bleprph_host_only_walkthrough.md @@ -0,0 +1,56 @@ +# BLE Peripheral Example Walkthrough + +## Introduction + +The tutorial is focused on how to implement the custom transport in the application and register it with nimble-host. This example has the exact same working as bleprph except the transport used is custom UART transport written in `"main/uart_driver.c"` file. The controller is disabled for this example, the nimble-host tries to communicate with the external connected controller using UART transport. + +Note: This walkthrough only covers the transport used by the application, for detailed explanation see the [bleprph_walkthrough](../../bleprph/tutorial/bleprph_walkthrough.md) +## Hardware Setup + +This example uses esp32 chip to run the example `bleprph_host_only` that runs the nimble-host and sends and receives the commands and events using uart. The another chip used is esp32c6 that runs the esp-hosted `esp-hosted/esp_hosted_fg/esp/esp_driver/network_adapter` example that runs the controller and receives commands and sends events using UART. Below is the setup of esp32 and esp32c6. + +![Hardware Setup](hardware_setup.png) + +Note that the esp32s gpio pins tx=4 and rx=5 are defined in [uart_driver.c](../main/uart_driver.c) file. The tx pin of one chip connectes to the rx pin of the other and vice versa. + +```c +#define UART_TX_PIN (4) +#define UART_RX_PIN (5) +#define UART_RTS_PIN (19) +#define UART_CTS_PIN (23) +``` + +## Main Entry Point + +The program’s entry point is the app_main() function: + +```c +void +app_main(void) +{ + int rc; + + /* Initialize NVS — it is used to store PHY calibration data */ + esp_err_t ret = nvs_flash_init(); + if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { + ESP_ERROR_CHECK(nvs_flash_erase()); + ret = nvs_flash_init(); + } + ESP_ERROR_CHECK(ret); + + hci_uart_open(); + ret = nimble_port_init(); + if (ret != ESP_OK) { + ESP_LOGE(tag, "Failed to init nimble %d ", ret); + return; + } + .... + .... +} +``` +In the main function `hci_uart_open()` configures the uart with necessary parameters like baud_rate, parity, etc. The file [uart_driver.c](../main/uart_driver.c) has all the uart transport code along with the necessary apis mandated by nimble-host. `ble_transport_to_ll_acl_impl` is the api used to send the data to the controller. and `ble_transport_to_ll_cmd_impl` is used to send the command to the controller. These two apis are implemented as they are necessary. Along with these two apis, any data that is received in the rx direction is redirected to the host using `ble_transport_to_hs_evt` and `ble_transport_to_hs_acl` apis. + +## Conclusion +1. This example covered how to write the custom transport layer and use it with nimble-host. +2. The example used the esp-hosted network-adapter example flashed on esp32c6 connected through UART to test this demo. +3. In the similar fashion the external controller could be connected. diff --git a/examples/bluetooth/nimble/bleprph_host_only/tutorial/hardware_setup.png b/examples/bluetooth/nimble/bleprph_host_only/tutorial/hardware_setup.png new file mode 100644 index 0000000000..cbff4b7a7b Binary files /dev/null and b/examples/bluetooth/nimble/bleprph_host_only/tutorial/hardware_setup.png differ diff --git a/examples/bluetooth/nimble/common/nimble_central_utils/misc.c b/examples/bluetooth/nimble/common/nimble_central_utils/misc.c index e901adde92..44dfade97b 100644 --- a/examples/bluetooth/nimble/common/nimble_central_utils/misc.c +++ b/examples/bluetooth/nimble/common/nimble_central_utils/misc.c @@ -169,6 +169,43 @@ print_adv_fields(const struct ble_hs_adv_fields *fields) MODLOG_DFLT(DEBUG, "\n"); } + if (fields->sm_tk_value_is_present) { + MODLOG_DFLT(DEBUG, " sm_tk_value="); + print_bytes(fields->sm_tk_value, 16); + MODLOG_DFLT(DEBUG, "\n"); + } + + if (fields->sm_oob_flag_is_present) { + MODLOG_DFLT(DEBUG, " sm_oob_flag=%d\n", fields->sm_oob_flag); + } + + if (fields->sol_uuids16 != NULL) { + MODLOG_DFLT(DEBUG, " sol_uuids16="); + for (i = 0; i < fields->sol_num_uuids16; i++) { + print_uuid(&fields->sol_uuids16[i].u); + MODLOG_DFLT(DEBUG, " "); + } + MODLOG_DFLT(DEBUG, "\n"); + } + + if (fields->sol_uuids32 != NULL) { + MODLOG_DFLT(DEBUG, " sol_uuids32="); + for (i = 0; i < fields->sol_num_uuids32; i++) { + print_uuid(&fields->sol_uuids32[i].u); + MODLOG_DFLT(DEBUG, "\n"); + } + MODLOG_DFLT(DEBUG, "\n"); + } + + if (fields->sol_uuids128 != NULL) { + MODLOG_DFLT(DEBUG, " sol_uuids128="); + for (i = 0; i < fields->sol_num_uuids128; i++) { + print_uuid(&fields->sol_uuids128[i].u); + MODLOG_DFLT(DEBUG, " "); + } + MODLOG_DFLT(DEBUG, "\n"); + } + if (fields->svc_data_uuid16 != NULL) { MODLOG_DFLT(DEBUG, " svc_data_uuid16="); print_bytes(fields->svc_data_uuid16, fields->svc_data_uuid16_len); @@ -185,6 +222,16 @@ print_adv_fields(const struct ble_hs_adv_fields *fields) MODLOG_DFLT(DEBUG, "\n"); } + if (fields->random_tgt_addr != NULL) { + MODLOG_DFLT(DEBUG, " random_tgt_addr="); + u8p = fields->random_tgt_addr; + for (i = 0; i < fields->num_random_tgt_addrs; i++) { + MODLOG_DFLT(DEBUG, "random_tgt_addr=%s ", addr_str(u8p)); + u8p += BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN; + } + MODLOG_DFLT(DEBUG, "\n"); + } + if (fields->appearance_is_present) { MODLOG_DFLT(DEBUG, " appearance=0x%04x\n", fields->appearance); } @@ -193,6 +240,19 @@ print_adv_fields(const struct ble_hs_adv_fields *fields) MODLOG_DFLT(DEBUG, " adv_itvl=0x%04x\n", fields->adv_itvl); } + if (fields->device_addr_is_present) { + MODLOG_DFLT(DEBUG, " device_addr="); + u8p = fields->device_addr; + MODLOG_DFLT(DEBUG, "%s ", addr_str(u8p)); + + u8p += BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN; + MODLOG_DFLT(DEBUG, "addr_type %d ", *u8p); + } + + if (fields->le_role_is_present) { + MODLOG_DFLT(DEBUG, " le_role=%d\n", fields->le_role); + } + if (fields->svc_data_uuid32 != NULL) { MODLOG_DFLT(DEBUG, " svc_data_uuid32="); print_bytes(fields->svc_data_uuid32, fields->svc_data_uuid32_len); diff --git a/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c b/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c index 52b70bff0e..6cdb884551 100644 --- a/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c +++ b/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c @@ -272,7 +272,7 @@ void app_main(void) #endif // CONFIG_BT_ENABLED #endif // CONFIG_EXAMPLE_CONNECT_WIFI -#if CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED +#if CONFIG_BT_CONTROLLER_ENABLED && (CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED) ESP_ERROR_CHECK(esp_ble_helper_init()); #endif diff --git a/examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c b/examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c index ce78fe5dfb..26504f857c 100644 --- a/examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c +++ b/examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c @@ -6,7 +6,7 @@ #include "sdkconfig.h" -#if CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED +#if CONFIG_BT_CONTROLLER_ENABLED && (CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED) #include "ble_api.h" #include "esp_log.h" diff --git a/examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h b/examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h index 740355c1e2..2dc59f4c86 100644 --- a/examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h +++ b/examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h @@ -12,7 +12,7 @@ extern "C" { #endif -#if CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED +#if CONFIG_BT_CONTROLLER_ENABLED && (CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED) esp_err_t esp_ble_helper_init(void); #endif