diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 61831113f0..0377caebc0 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -108,7 +108,8 @@ if(CONFIG_BT_ENABLED) host/bluedroid/stack/a2dp/include host/bluedroid/stack/rfcomm/include host/bluedroid/stack/include - host/bluedroid/common/include) + host/bluedroid/common/include + host/bluedroid/config/include) list(APPEND include_dirs host/bluedroid/api/include/api) @@ -364,7 +365,8 @@ if(CONFIG_BT_ENABLED) "host/bluedroid/stack/smp/smp_keys.c" "host/bluedroid/stack/smp/smp_l2c.c" "host/bluedroid/stack/smp/smp_main.c" - "host/bluedroid/stack/smp/smp_utils.c") + "host/bluedroid/stack/smp/smp_utils.c" + "host/bluedroid/config/stack_config.c") list(APPEND srcs "common/btc/profile/esp/blufi/bluedroid_host/esp_blufi.c") diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index bc4051e4d7..8499f54472 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -135,14 +135,6 @@ choice BT_HID_ROLE This enables the BT HID Device endchoice -config BT_SSP_ENABLED - bool "Secure Simple Pairing" - depends on BT_CLASSIC_ENABLED - default y - help - This enables the Secure Simple Pairing. If disable this option, - Bluedroid will only support Legacy Pairing - config BT_BLE_ENABLED bool "Bluetooth Low Energy" depends on BT_BLUEDROID_ENABLED diff --git a/components/bt/host/bluedroid/api/esp_bt_main.c b/components/bt/host/bluedroid/api/esp_bt_main.c index 911897a89b..d4b93fbb33 100644 --- a/components/bt/host/bluedroid/api/esp_bt_main.c +++ b/components/bt/host/bluedroid/api/esp_bt_main.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 */ @@ -11,6 +11,7 @@ #include "esp_bt.h" #include "osi/future.h" #include "osi/allocator.h" +#include "config/stack_config.h" static bool bd_already_enable = false; static bool bd_already_init = false; @@ -106,11 +107,22 @@ esp_err_t esp_bluedroid_disable(void) } esp_err_t esp_bluedroid_init(void) +{ + esp_bluedroid_config_t cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + return esp_bluedroid_init_with_cfg(&cfg); +} + +esp_err_t esp_bluedroid_init_with_cfg(esp_bluedroid_config_t *cfg) { btc_msg_t msg; future_t **future_p; bt_status_t ret; + if (!cfg) { + LOG_ERROR("%s cfg is NULL", __func__); + return ESP_ERR_INVALID_ARG; + } + if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) { LOG_ERROR("Controller not initialised\n"); return ESP_ERR_INVALID_STATE; @@ -125,9 +137,15 @@ esp_err_t esp_bluedroid_init(void) osi_mem_dbg_init(); #endif + ret = bluedriod_config_init(cfg); + if (ret != BT_STATUS_SUCCESS) { + LOG_ERROR("Bluedroid stack initialize fail, ret:%d", ret); + return ESP_FAIL; + } + /* - * BTC Init - */ + * BTC Init + */ ret = btc_init(); if (ret != BT_STATUS_SUCCESS) { LOG_ERROR("Bluedroid Initialize Fail"); @@ -199,6 +217,8 @@ esp_err_t esp_bluedroid_deinit(void) btc_deinit(); + bluedriod_config_deinit(); + bd_already_init = false; return ESP_OK; diff --git a/components/bt/host/bluedroid/api/esp_gap_bt_api.c b/components/bt/host/bluedroid/api/esp_gap_bt_api.c index 1993438230..07b503cf16 100644 --- a/components/bt/host/bluedroid/api/esp_gap_bt_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_bt_api.c @@ -8,14 +8,18 @@ #include #include "esp_bt_main.h" #include "esp_gap_bt_api.h" +#include "esp_log.h" #include "common/bt_trace.h" #include "bta/bta_api.h" #include "btc/btc_manage.h" #include "btc_gap_bt.h" #include "btc/btc_storage.h" +#include "config/stack_config.h" #if (BTC_GAP_BT_INCLUDED == TRUE) +#define TAG "BT_GAP" + esp_err_t esp_bt_gap_register_callback(esp_bt_gap_cb_t callback) { if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { @@ -318,6 +322,11 @@ esp_err_t esp_bt_gap_set_security_param(esp_bt_sp_param_t param_type, return ESP_ERR_INVALID_STATE; } + if (!(bluedriod_config_get()->get_ssp_enabled())) { + ESP_LOGE(TAG, "%s is not supported when `ssp_en` in `esp_bluedroid_config_t` is disabled!", __func__); + return ESP_ERR_NOT_SUPPORTED; + } + msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_GAP_BT; msg.act = BTC_GAP_BT_ACT_SET_SECURITY_PARAM; @@ -338,6 +347,11 @@ esp_err_t esp_bt_gap_ssp_passkey_reply(esp_bd_addr_t bd_addr, bool accept, uint3 return ESP_ERR_INVALID_STATE; } + if (!(bluedriod_config_get()->get_ssp_enabled())) { + ESP_LOGE(TAG, "%s is not supported when `ssp_en` in `esp_bluedroid_config_t` is disabled!", __func__); + return ESP_ERR_NOT_SUPPORTED; + } + msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_GAP_BT; msg.act = BTC_GAP_BT_ACT_PASSKEY_REPLY; @@ -357,6 +371,11 @@ esp_err_t esp_bt_gap_ssp_confirm_reply(esp_bd_addr_t bd_addr, bool accept) return ESP_ERR_INVALID_STATE; } + if (!(bluedriod_config_get()->get_ssp_enabled())) { + ESP_LOGE(TAG, "%s is not supported when `ssp_en` in `esp_bluedroid_config_t` is disabled!", __func__); + return ESP_ERR_NOT_SUPPORTED; + } + msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_GAP_BT; msg.act = BTC_GAP_BT_ACT_CONFIRM_REPLY; diff --git a/components/bt/host/bluedroid/api/include/api/esp_bt_main.h b/components/bt/host/bluedroid/api/include/api/esp_bt_main.h index 74d9440aad..db6826e306 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_bt_main.h +++ b/components/bt/host/bluedroid/api/include/api/esp_bt_main.h @@ -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 */ @@ -7,6 +7,9 @@ #ifndef __ESP_BT_MAIN_H__ #define __ESP_BT_MAIN_H__ +#include +#include + #include "esp_err.h" #ifdef __cplusplus @@ -22,6 +25,18 @@ typedef enum { ESP_BLUEDROID_STATUS_ENABLED /*!< Bluetooth initialized and enabled */ } esp_bluedroid_status_t; +/** + * @brief Bluetooth stack configuration + */ +typedef struct { + bool ssp_en; /*!< Whether SSP(secure simple pairing) or legacy pairing is used for Classic Bluetooth */ +} esp_bluedroid_config_t; + +#define BT_BLUEDROID_INIT_CONFIG_DEFAULT() \ + { \ + .ssp_en = true, \ + } + /** * @brief Get bluetooth stack status * @@ -31,7 +46,7 @@ typedef enum { esp_bluedroid_status_t esp_bluedroid_get_status(void); /** - * @brief Enable bluetooth, must after esp_bluedroid_init(). + * @brief Enable bluetooth, must after esp_bluedroid_init()/esp_bluedroid_init_with_cfg(). * * @return * - ESP_OK : Succeed @@ -55,7 +70,18 @@ esp_err_t esp_bluedroid_disable(void); * - ESP_OK : Succeed * - Other : Failed */ -esp_err_t esp_bluedroid_init(void); +esp_err_t esp_bluedroid_init(void) __attribute__((deprecated("Please use esp_bluedroid_init_with_cfg"))); + +/** + * @brief Init and alloc the resource for bluetooth, must be prior to every bluetooth stuff. + * + * @param cfg Initial configuration of ESP Bluedroid stack. + * + * @return + * - ESP_OK : Succeed + * - Other : Failed + */ +esp_err_t esp_bluedroid_init_with_cfg(esp_bluedroid_config_t *cfg); /** * @brief Deinit and free the resource for bluetooth, must be after every bluetooth stuff. diff --git a/components/bt/host/bluedroid/api/include/api/esp_hidd_api.h b/components/bt/host/bluedroid/api/include/api/esp_hidd_api.h index 53e92a08d9..a2af1659dc 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_hidd_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_hidd_api.h @@ -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 * @@ -277,9 +277,10 @@ typedef void (*esp_hd_cb_t)(esp_hidd_cb_event_t event, esp_hidd_cb_param_t *para esp_err_t esp_bt_hid_device_register_callback(esp_hd_cb_t callback); /** - * @brief Initializes HIDD interface. This function should be called after esp_bluedroid_init() and - * esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_register_callback. - * When the operation is complete, the callback function will be called with ESP_HIDD_INIT_EVT. + * @brief Initializes HIDD interface. This function should be called after + * esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be + * called after esp_bt_hid_device_register_callback. When the operation is complete, the callback + * function will be called with ESP_HIDD_INIT_EVT. * * @return * - ESP_OK: success @@ -288,9 +289,10 @@ esp_err_t esp_bt_hid_device_register_callback(esp_hd_cb_t callback); esp_err_t esp_bt_hid_device_init(void); /** - * @brief De-initializes HIDD interface. This function should be called after esp_bluedroid_init() and - * esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). When the - * operation is complete, the callback function will be called with ESP_HIDD_DEINIT_EVT. + * @brief De-initializes HIDD interface. This function should be called after + * esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be + * called after esp_bt_hid_device_init(). When the operation is complete, the callback function will be + * called with ESP_HIDD_DEINIT_EVT. * * @return * - ESP_OK: success @@ -300,9 +302,9 @@ esp_err_t esp_bt_hid_device_deinit(void); /** * @brief Registers HIDD parameters with SDP and sets l2cap Quality of Service. This function should be - * called after esp_bluedroid_init() and esp_bluedroid_enable() success, and should be called after - * esp_bt_hid_device_init(). When the operation is complete, the callback function will be called - * with ESP_HIDD_REGISTER_APP_EVT. + * called after esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, + * and should be called after esp_bt_hid_device_init(). When the operation is complete, the callback + * function will be called with ESP_HIDD_REGISTER_APP_EVT. * * @param[in] app_param: HIDD parameters * @param[in] in_qos: incoming QoS parameters @@ -317,9 +319,9 @@ esp_err_t esp_bt_hid_device_register_app(esp_hidd_app_param_t *app_param, esp_hi /** * @brief Removes HIDD parameters from SDP and resets l2cap Quality of Service. This function should be - * called after esp_bluedroid_init() and esp_bluedroid_enable() success, and should be called after - * esp_bt_hid_device_init(). When the operation is complete, the callback function will be called - * with ESP_HIDD_UNREGISTER_APP_EVT. + * called after esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, + * and should be called after esp_bt_hid_device_init(). When the operation is complete, the callback + * function will be called with ESP_HIDD_UNREGISTER_APP_EVT. * * @return * - ESP_OK: success @@ -329,8 +331,9 @@ esp_err_t esp_bt_hid_device_unregister_app(void); /** * @brief Connects to the peer HID Host with virtual cable. This function should be called after - * esp_bluedroid_init() and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). - * When the operation is complete, the callback function will be called with ESP_HIDD_OPEN_EVT. + * esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be + * called after esp_bt_hid_device_init(). When the operation is complete, the callback function will + * be called with ESP_HIDD_OPEN_EVT. * * @param[in] bd_addr: Remote host bluetooth device address. * @@ -342,8 +345,9 @@ esp_err_t esp_bt_hid_device_connect(esp_bd_addr_t bd_addr); /** * @brief Disconnects from the currently connected HID Host. This function should be called after - * esp_bluedroid_init() and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). - * When the operation is complete, the callback function will be called with ESP_HIDD_CLOSE_EVT. + * esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be + * called after esp_bt_hid_device_init(). When the operation is complete, the callback function will + * be called with ESP_HIDD_CLOSE_EVT. * * @note The disconnect operation will not remove the virtually cabled device. If the connect request from the * different HID Host, it will reject the request. @@ -356,8 +360,9 @@ esp_err_t esp_bt_hid_device_disconnect(void); /** * @brief Sends HID report to the currently connected HID Host. This function should be called after - * esp_bluedroid_init() and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). - * When the operation is complete, the callback function will be called with ESP_HIDD_SEND_REPORT_EVT. + * esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be + * called after esp_bt_hid_device_init(). When the operation is complete, the callback function will + * be called with ESP_HIDD_SEND_REPORT_EVT. * * @param[in] type: type of report * @param[in] id: report id as defined by descriptor @@ -372,9 +377,9 @@ esp_err_t esp_bt_hid_device_send_report(esp_hidd_report_type_t type, uint8_t id, /** * @brief Sends HID Handshake with error info for invalid set_report to the currently connected HID Host. - * This function should be called after esp_bluedroid_init() and esp_bluedroid_enable() success, and - * should be called after esp_bt_hid_device_init(). When the operation is complete, the callback - * function will be called with ESP_HIDD_REPORT_ERR_EVT. + * This function should be called after esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and + * esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). When the + * operation is complete, the callback function will be called with ESP_HIDD_REPORT_ERR_EVT. * * @param[in] error: type of error * @@ -385,9 +390,10 @@ esp_err_t esp_bt_hid_device_send_report(esp_hidd_report_type_t type, uint8_t id, esp_err_t esp_bt_hid_device_report_error(esp_hidd_handshake_error_t error); /** - * @brief Remove the virtually cabled device. This function should be called after esp_bluedroid_init() - * and esp_bluedroid_enable() success, and should be called after esp_bt_hid_device_init(). When the - * operation is complete, the callback function will be called with ESP_HIDD_VC_UNPLUG_EVT. + * @brief Remove the virtually cabled device. This function should be called after + * esp_bluedroid_init()/esp_bluedroid_init_with_cfg() and esp_bluedroid_enable() success, and should be + * called after esp_bt_hid_device_init(). When the operation is complete, the callback function will be + * called with ESP_HIDD_VC_UNPLUG_EVT. * * @note If the connection exists, then HID Device will send a `VIRTUAL_CABLE_UNPLUG` control command to * the peer HID Host, and the connection will be destroyed. If the connection does not exist, then HID diff --git a/components/bt/host/bluedroid/api/include/api/esp_hidh_api.h b/components/bt/host/bluedroid/api/include/api/esp_hidh_api.h index 5d3924d8ba..46f8a15ba9 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_hidh_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_hidh_api.h @@ -318,8 +318,9 @@ esp_err_t esp_bt_hid_host_register_callback(esp_hh_cb_t callback); /** * @brief This function initializes HID host. This function should be called after esp_bluedroid_enable() and - * esp_bluedroid_init() success, and should be called after esp_bt_hid_host_register_callback(). - * When the operation is complete the callback function will be called with ESP_HIDH_INIT_EVT. + * esp_bluedroid_init()/esp_bluedroid_init_with_cfg() success, and should be called after + * esp_bt_hid_host_register_callback(). When the operation is complete the callback function will be called + * with ESP_HIDH_INIT_EVT. * * @return * - ESP_OK: success @@ -329,7 +330,7 @@ esp_err_t esp_bt_hid_host_init(void); /** * @brief Closes the interface. This function should be called after esp_bluedroid_enable() and - * esp_bluedroid_init() success, and should be called after esp_bt_hid_host_init(). + * esp_bluedroid_init()/esp_bluedroid_init_with_cfg() success, and should be called after esp_bt_hid_host_init(). * When the operation is complete the callback function will be called with ESP_HIDH_DEINIT_EVT. * * @return - ESP_OK: success diff --git a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h index bf655540a3..59022dd603 100644 --- a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h +++ b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h @@ -88,13 +88,6 @@ #define UC_BT_HID_DEVICE_ENABLED FALSE #endif -//SSP -#ifdef CONFIG_BT_SSP_ENABLED -#define UC_BT_SSP_ENABLED CONFIG_BT_SSP_ENABLED -#else -#define UC_BT_SSP_ENABLED FALSE -#endif - //BQB(BT) #ifdef CONFIG_BT_CLASSIC_BQB_ENABLED #define UC_BT_CLASSIC_BQB_ENABLED CONFIG_BT_CLASSIC_BQB_ENABLED diff --git a/components/bt/host/bluedroid/common/include/common/bt_target.h b/components/bt/host/bluedroid/common/include/common/bt_target.h index d1d44dc382..7e48557e0f 100644 --- a/components/bt/host/bluedroid/common/include/common/bt_target.h +++ b/components/bt/host/bluedroid/common/include/common/bt_target.h @@ -52,6 +52,7 @@ ******************************************************************************/ #if (UC_BT_CLASSIC_ENABLED == TRUE) #define CLASSIC_BT_INCLUDED TRUE +#define BT_SSP_INCLUDED TRUE #define BTC_SM_INCLUDED TRUE #define BTC_PRF_QUEUE_INCLUDED TRUE #define BTC_GAP_BT_INCLUDED TRUE @@ -134,10 +135,6 @@ #endif #endif /* UC_BT_HFP_CLIENT_ENABLED */ -#if UC_BT_SSP_ENABLED -#define BT_SSP_INCLUDED TRUE -#endif /* UC_BT_SSP_ENABLED */ - #if UC_BT_HID_ENABLED #define BT_HID_INCLUDED TRUE #endif /* UC_BT_HID_ENABLED */ diff --git a/components/bt/host/bluedroid/config/include/config/stack_config.h b/components/bt/host/bluedroid/config/include/config/stack_config.h new file mode 100644 index 0000000000..8b7777234e --- /dev/null +++ b/components/bt/host/bluedroid/config/include/config/stack_config.h @@ -0,0 +1,21 @@ +/* + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include "bt_common.h" + +struct bluedroid_config { + bool (*get_ssp_enabled)(void); +}; + +bt_status_t bluedriod_config_init(esp_bluedroid_config_t *cfg); + +void bluedriod_config_deinit(void); + +const struct bluedroid_config *bluedriod_config_get(void); diff --git a/components/bt/host/bluedroid/config/stack_config.c b/components/bt/host/bluedroid/config/stack_config.c new file mode 100644 index 0000000000..66d04a6396 --- /dev/null +++ b/components/bt/host/bluedroid/config/stack_config.c @@ -0,0 +1,55 @@ +/* + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include "osi/allocator.h" +#include "esp_bt_main.h" + +#include "config/stack_config.h" + +struct stack_config_env_tag { + esp_bluedroid_config_t cfg; + struct bluedroid_config interface; +}; + +static struct stack_config_env_tag *s_stack_config_env = NULL; + +static bool get_ssp_enabled(void) +{ + assert(s_stack_config_env); + esp_bluedroid_config_t *cfg = &s_stack_config_env->cfg; + return cfg->ssp_en; +} + +bt_status_t bluedriod_config_init(esp_bluedroid_config_t *cfg) +{ + s_stack_config_env = osi_calloc(sizeof(struct stack_config_env_tag)); + if (!s_stack_config_env) { + return BT_STATUS_NOMEM; + } + + memcpy(&s_stack_config_env->cfg, cfg, sizeof(esp_bluedroid_config_t)); + + struct bluedroid_config *interface = &s_stack_config_env->interface; + interface->get_ssp_enabled = get_ssp_enabled; + + return BT_STATUS_SUCCESS; +} + +void bluedriod_config_deinit(void) +{ + if (s_stack_config_env) { + osi_free(s_stack_config_env); + s_stack_config_env = NULL; + } +} + +const struct bluedroid_config *bluedriod_config_get(void) +{ + assert(s_stack_config_env); + return &s_stack_config_env->interface; +} diff --git a/components/bt/host/bluedroid/device/controller.c b/components/bt/host/bluedroid/device/controller.c index 8d2349b4cd..2f03d57132 100644 --- a/components/bt/host/bluedroid/device/controller.c +++ b/components/bt/host/bluedroid/device/controller.c @@ -29,6 +29,7 @@ #include "stack/btm_ble_api.h" #include "device/version.h" #include "osi/future.h" +#include "config/stack_config.h" #if (BLE_50_FEATURE_SUPPORT == TRUE) const bt_event_mask_t BLE_EVENT_MASK = { "\x00\x00\x00\x00\x00\xff\xff\xff" }; #else @@ -172,9 +173,11 @@ static void start_up(void) // Inform the controller what page 0 features we support, based on what // it told us it supports. We need to do this first before we request the // next page, because the controller's response for page 1 may be - // dependent on what we configure from page 0 + // dependent on what we configure from page 0 and host SSP configuration #if (BT_SSP_INCLUDED == TRUE) - controller_param.simple_pairing_supported = HCI_SIMPLE_PAIRING_SUPPORTED(controller_param.features_classic[0].as_array); + controller_param.simple_pairing_supported = HCI_SIMPLE_PAIRING_SUPPORTED( + controller_param.features_classic[0].as_array) && + (bluedriod_config_get()->get_ssp_enabled()); #else controller_param.simple_pairing_supported = false; #endif diff --git a/components/protocomm/src/simple_ble/simple_ble.c b/components/protocomm/src/simple_ble/simple_ble.c index ec210408d2..2cc49c6eef 100644 --- a/components/protocomm/src/simple_ble/simple_ble.c +++ b/components/protocomm/src/simple_ble/simple_ble.c @@ -233,7 +233,8 @@ esp_err_t simple_ble_start(simple_ble_cfg_t *cfg) return ret; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(TAG, "%s init bluetooth failed %d", __func__, ret); return ret; diff --git a/examples/bluetooth/bluedroid/ble/ble_ancs/main/ble_ancs_demo.c b/examples/bluetooth/bluedroid/ble/ble_ancs/main/ble_ancs_demo.c index 6a3def567b..0098cc9938 100644 --- a/examples/bluetooth/bluedroid/ble/ble_ancs/main/ble_ancs_demo.c +++ b/examples/bluetooth/bluedroid/ble/ble_ancs/main/ble_ancs_demo.c @@ -638,7 +638,8 @@ void app_main(void) } ESP_LOGI(BLE_ANCS_TAG, "%s init bluetooth", __func__); - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(BLE_ANCS_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble/ble_compatibility_test/main/ble_compatibility_test.c b/examples/bluetooth/bluedroid/ble/ble_compatibility_test/main/ble_compatibility_test.c index d875471a81..5b6d092c73 100644 --- a/examples/bluetooth/bluedroid/ble/ble_compatibility_test/main/ble_compatibility_test.c +++ b/examples/bluetooth/bluedroid/ble/ble_compatibility_test/main/ble_compatibility_test.c @@ -649,7 +649,8 @@ void app_main(void) return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(EXAMPLE_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble/ble_eddystone/main/esp_eddystone_demo.c b/examples/bluetooth/bluedroid/ble/ble_eddystone/main/esp_eddystone_demo.c index 71ce556515..7bda9f093d 100644 --- a/examples/bluetooth/bluedroid/ble/ble_eddystone/main/esp_eddystone_demo.c +++ b/examples/bluetooth/bluedroid/ble/ble_eddystone/main/esp_eddystone_demo.c @@ -154,7 +154,8 @@ void esp_eddystone_appRegister(void) void esp_eddystone_init(void) { - esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + esp_bluedroid_init_with_cfg(&bluedroid_cfg); esp_bluedroid_enable(); esp_eddystone_appRegister(); } diff --git a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c index 9b0df3e094..c0e77c08a0 100644 --- a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c +++ b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c @@ -216,7 +216,8 @@ void app_main(void) return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(HID_DEMO_TAG, "%s init bluedroid failed", __func__); return; diff --git a/examples/bluetooth/bluedroid/ble/ble_ibeacon/main/ibeacon_demo.c b/examples/bluetooth/bluedroid/ble/ble_ibeacon/main/ibeacon_demo.c index 3c3fd4dd1c..de1d1f36c9 100644 --- a/examples/bluetooth/bluedroid/ble/ble_ibeacon/main/ibeacon_demo.c +++ b/examples/bluetooth/bluedroid/ble/ble_ibeacon/main/ibeacon_demo.c @@ -156,7 +156,8 @@ void ble_ibeacon_appRegister(void) void ble_ibeacon_init(void) { - esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + esp_bluedroid_init_with_cfg(&bluedroid_cfg); esp_bluedroid_enable(); ble_ibeacon_appRegister(); } diff --git a/examples/bluetooth/bluedroid/ble/ble_spp_client/main/spp_client_demo.c b/examples/bluetooth/bluedroid/ble/ble_spp_client/main/spp_client_demo.c index 7aae9e7304..b7af64f05d 100644 --- a/examples/bluetooth/bluedroid/ble/ble_spp_client/main/spp_client_demo.c +++ b/examples/bluetooth/bluedroid/ble/ble_spp_client/main/spp_client_demo.c @@ -625,7 +625,8 @@ void app_main(void) } ESP_LOGI(GATTC_TAG, "%s init bluetooth", __func__); - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTC_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c b/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c index 72950bf033..ac90e4eb2f 100644 --- a/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c +++ b/examples/bluetooth/bluedroid/ble/ble_spp_server/main/ble_spp_server_demo.c @@ -686,7 +686,8 @@ void app_main(void) } ESP_LOGI(GATTS_TABLE_TAG, "%s init bluetooth", __func__); - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_client/main/example_ble_client_throughput.c b/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_client/main/example_ble_client_throughput.c index e64f4a6f40..226a82f744 100644 --- a/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_client/main/example_ble_client_throughput.c +++ b/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_client/main/example_ble_client_throughput.c @@ -568,7 +568,8 @@ void app_main(void) return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTC_TAG, "%s init bluetooth failed, error code = %x", __func__, ret); return; diff --git a/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_server/main/example_ble_server_throughput.c b/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_server/main/example_ble_server_throughput.c index 8ce8d26573..8747c5b316 100644 --- a/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_server/main/example_ble_server_throughput.c +++ b/examples/bluetooth/bluedroid/ble/ble_throughput/throughput_server/main/example_ble_server_throughput.c @@ -672,7 +672,8 @@ void app_main(void) ESP_LOGE(GATTS_TAG, "%s enable controller failed", __func__); return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTS_TAG, "%s init bluetooth failed", __func__); return; diff --git a/examples/bluetooth/bluedroid/ble/gatt_client/main/gattc_demo.c b/examples/bluetooth/bluedroid/ble/gatt_client/main/gattc_demo.c index 5f1d10f1f7..dd4b1b50e3 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_client/main/gattc_demo.c +++ b/examples/bluetooth/bluedroid/ble/gatt_client/main/gattc_demo.c @@ -469,7 +469,8 @@ void app_main(void) return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTC_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md index af778dbd12..6e5b8930b4 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md @@ -60,7 +60,8 @@ void app_main() return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTC_TAG, "%s init bluetooth failed, error code = %x", __func__, ret); return; @@ -119,13 +120,13 @@ esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); ret = esp_bt_controller_init(&bt_cfg); ``` -Next, the controller is enabled in BLE Mode. +Next, the controller is enabled in BLE Mode. ```c ret = esp_bt_controller_enable(ESP_BT_MODE_BLE); ``` >The controller should be enabled in `ESP_BT_MODE_BTDM`, if you want to use the dual mode (BLE + BT). - + There are four Bluetooth modes supported: 1. `ESP_BT_MODE_IDLE`: Bluetooth not running @@ -136,7 +137,8 @@ There are four Bluetooth modes supported: After the initialization of the BT controller, the Bluedroid stack, which includes the common definitions and APIs for both BT Classic and BLE, is initialized and enabled by using: ```c -ret = esp_bluedroid_init(); +esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); ret = esp_bluedroid_enable(); ``` The main function ends by registering the GAP and GATT event handlers, as well as the Application Profile and set the maximum supported MTU size. @@ -209,7 +211,7 @@ static struct gattc_profile_inst gl_profile_tab[PROFILE_NUM] = { }; ``` -The initialization of the Application Profile table array includes defining the callback function for Profile. It is `gattc_profile_event_handler()`. In addition, the GATT interface is initialized to the default value of `ESP_GATT_IF_NONE`. Later on, when the Application Profile is registered, the BLE stack returns a GATT interface instance to use with that Application Profile. +The initialization of the Application Profile table array includes defining the callback function for Profile. It is `gattc_profile_event_handler()`. In addition, the GATT interface is initialized to the default value of `ESP_GATT_IF_NONE`. Later on, when the Application Profile is registered, the BLE stack returns a GATT interface instance to use with that Application Profile. The profile registration triggers an `ESP_GATTC_REG_EVT` event, which is handled by the `esp_gattc_cb()` event handler. The handler takes the GATT interface returned by the event and stores it in the profile table: @@ -261,8 +263,8 @@ typedef struct { esp_ble_scan_type_t scan_type; /*!< Scan type */ esp_ble_addr_type_t own_addr_type; /*!< Owner address type */ esp_ble_scan_filter_t scan_filter_policy; /*!< Scan filter policy */ - uint16_t scan_interval; /*!< Scan interval. This is defined as the time interval from when the Controller started its last LE scan until it begins the subsequent LE scan.*/ - //Range: 0x0004 to 0x4000 + uint16_t scan_interval; /*!< Scan interval. This is defined as the time interval from when the Controller started its last LE scan until it begins the subsequent LE scan.*/ + //Range: 0x0004 to 0x4000 //Default: 0x0010 (10 ms) //Time = N * 0.625 msec //Time Range: 2.5 msec to 10.24 seconds @@ -430,10 +432,10 @@ The connection ID and the address of the remote device (server) are stored in th ```c conn_id = p_data->connect.conn_id; gl_profile_tab[PROFILE_A_APP_ID].conn_id = p_data->connect.conn_id; -memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->connect.remote_bda, +memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->connect.remote_bda, sizeof(esp_bd_addr_t)); ESP_LOGI(GATTC_TAG, "REMOTE BDA:"); -esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, +esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, sizeof(esp_bd_addr_t)); ``` @@ -484,7 +486,7 @@ Where, ```c #define REMOTE_SERVICE_UUID 0x00FF ``` -If UUID of the service application the user is interested in is 128-bit, then there is one note below for the user which is relevant with the little-endian storage mode of the processor architecture. +If UUID of the service application the user is interested in is 128-bit, then there is one note below for the user which is relevant with the little-endian storage mode of the processor architecture. The struct of UUID is defined as: ```c @@ -516,7 +518,7 @@ The resulting service found, if there is any, will be returned from an `ESP_GATT case ESP_GATTC_SEARCH_RES_EVT: { esp_gatt_srvc_id_t *srvc_id = &p_data->search_res.srvc_id; conn_id = p_data->search_res.conn_id; - if (srvc_id->id.uuid.len == ESP_UUID_LEN_16 && srvc_id->id.uuid.uuid.uuid16 == + if (srvc_id->id.uuid.len == ESP_UUID_LEN_16 && srvc_id->id.uuid.uuid.uuid16 == REMOTE_SERVICE_UUID) { get_server = true; gl_profile_tab[PROFILE_A_APP_ID].service_start_handle = p_data->search_res.start_handle; @@ -574,8 +576,8 @@ case ESP_GATTC_SEARCH_CMPL_EVT: if (get_server){ uint16_t count = 0; esp_gatt_status_t status = esp_ble_gattc_get_attr_count( gattc_if, - p_data->search_cmpl.conn_id,ESP_GATT_DB_CHARACTERISTIC, gl_profile_tab[PROFILE_A_APP_ID].service_start_handle, gl_profile_tab[PROFILE_A_APP_ID].service_end_handle, - INVALID_HANDLE, + p_data->search_cmpl.conn_id,ESP_GATT_DB_CHARACTERISTIC, gl_profile_tab[PROFILE_A_APP_ID].service_start_handle, gl_profile_tab[PROFILE_A_APP_ID].service_end_handle, + INVALID_HANDLE, &count); if (status != ESP_GATT_OK){ ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_attr_count error"); @@ -588,8 +590,8 @@ case ESP_GATTC_SEARCH_CMPL_EVT: ESP_LOGE(GATTC_TAG, "gattc no mem"); }else{ status = esp_ble_gattc_get_char_by_uuid( gattc_if, - p_data->search_cmpl.conn_id, - gl_profile_tab[PROFILE_A_APP_ID].service_start_handle, + p_data->search_cmpl.conn_id, + gl_profile_tab[PROFILE_A_APP_ID].service_start_handle, gl_profile_tab[PROFILE_A_APP_ID].service_end_handle, remote_filter_char_uuid, char_elem_result, @@ -598,14 +600,14 @@ case ESP_GATTC_SEARCH_CMPL_EVT: ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_char_by_uuid error"); } - /* Every service have only one char in our 'ESP_GATTS_DEMO' demo, + /* Every service have only one char in our 'ESP_GATTS_DEMO' demo, so we used first 'char_elem_result' */ - if (count > 0 && (char_elem_result[0].properties + if (count > 0 && (char_elem_result[0].properties &ESP_GATT_CHAR_PROP_BIT_NOTIFY)){ - gl_profile_tab[PROFILE_A_APP_ID].char_handle = + gl_profile_tab[PROFILE_A_APP_ID].char_handle = char_elem_result[0].char_handle; - esp_ble_gattc_register_for_notify (gattc_if, - gl_profile_tab[PROFILE_A_APP_ID].remote_bda, + esp_ble_gattc_register_for_notify (gattc_if, + gl_profile_tab[PROFILE_A_APP_ID].remote_bda, char_elem_result[0].char_handle); } } @@ -657,21 +659,21 @@ This procedure registers notifications to the BLE stack, and triggers an `ESP_GA if (!descr_elem_result){ ESP_LOGE(GATTC_TAG, "malloc error, gattc no mem"); }else{ - ret_status = esp_ble_gattc_get_descr_by_char_handle( - gattc_if, - gl_profile_tab[PROFILE_A_APP_ID].conn_id, - p_data->reg_for_notify.handle, - notify_descr_uuid, + ret_status = esp_ble_gattc_get_descr_by_char_handle( + gattc_if, + gl_profile_tab[PROFILE_A_APP_ID].conn_id, + p_data->reg_for_notify.handle, + notify_descr_uuid, descr_elem_result,&count); - + if (ret_status != ESP_GATT_OK){ - ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_descr_by_char_handle + ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_descr_by_char_handle error"); } /* Every char has only one descriptor in our 'ESP_GATTS_DEMO' demo, so we used first 'descr_elem_result' */ if (count > 0 && descr_elem_result[0].uuid.len == ESP_UUID_LEN_16 && descr_elem_result[0].uuid.uuid.uuid16 == ESP_GATT_UUID_CHAR_CLIENT_CONFIG){ - ret_status = esp_ble_gattc_write_char_descr( gattc_if, + ret_status = esp_ble_gattc_write_char_descr( gattc_if, gl_profile_tab[PROFILE_A_APP_ID].conn_id, descr_elem_result[0].handle, sizeof(notify_en), diff --git a/examples/bluetooth/bluedroid/ble/gatt_security_client/main/example_ble_sec_gattc_demo.c b/examples/bluetooth/bluedroid/ble/gatt_security_client/main/example_ble_sec_gattc_demo.c index f5e60c0939..1dc0fe95bc 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_security_client/main/example_ble_sec_gattc_demo.c +++ b/examples/bluetooth/bluedroid/ble/gatt_security_client/main/example_ble_sec_gattc_demo.c @@ -545,7 +545,8 @@ void app_main(void) return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTC_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c b/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c index 8324d170ea..f1ff6099cb 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c +++ b/examples/bluetooth/bluedroid/ble/gatt_security_server/main/example_ble_sec_gatts_demo.c @@ -531,7 +531,8 @@ void app_main(void) } ESP_LOGI(GATTS_TABLE_TAG, "%s init bluetooth", __func__); - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c b/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c index 91e495de8d..366cc6b429 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c +++ b/examples/bluetooth/bluedroid/ble/gatt_server/main/gatts_demo.c @@ -701,7 +701,8 @@ void app_main(void) ESP_LOGE(GATTS_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret)); return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTS_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble/gatt_server/tutorial/Gatt_Server_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble/gatt_server/tutorial/Gatt_Server_Example_Walkthrough.md index 9aba4bb43a..2f6aa348b6 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server/tutorial/Gatt_Server_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble/gatt_server/tutorial/Gatt_Server_Example_Walkthrough.md @@ -62,7 +62,8 @@ The entry point to this example is the app_main() function: ESP_LOGE(GATTS_TAG, "%s enable controller failed", __func__); return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTS_TAG, "%s init bluetooth failed", __func__); return; @@ -114,7 +115,7 @@ esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); ret = esp_bt_controller_init(&bt_cfg); ``` -Next, the controller is enabled in BLE Mode. +Next, the controller is enabled in BLE Mode. ```c ret = esp_bt_controller_enable(ESP_BT_MODE_BLE); @@ -131,7 +132,8 @@ There are four Bluetooth modes supported: After the initialization of the BT controller, the Bluedroid stack, which includes the common definitions and APIs for both BT Classic and BLE, is initialized and enabled by using: ```c -ret = esp_bluedroid_init(); +esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); ret = esp_bluedroid_enable(); ``` The Bluetooth stack is up and running at this point in the program flow, however the functionality of the application has not been defined yet. The functionality is defined by reacting to events such as what happens when another device tries to read or write parameters and establish a connection. The two main managers of events are the GAP and GATT event handlers. The application needs to register a callback function for each event handler in order to let the application know which functions are going to handle the GAP and GATT events: @@ -297,7 +299,7 @@ Once the advertising data have been set, the GAP event `ESP_GAP_BLE_ADV_DATA_SET ```c static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) -{ +{ switch (event) { #ifdef CONFIG_SET_RAW_ADV_DATA case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT: @@ -482,16 +484,16 @@ case ESP_GATTS_CREATE_EVT: ESP_LOGI(GATTS_TAG, "CREATE_SERVICE_EVT, status %d, service_handle %d", param->create.status, param->create.service_handle); gl_profile_tab[PROFILE_A_APP_ID].service_handle = param->create.service_handle; gl_profile_tab[PROFILE_A_APP_ID].char_uuid.len = ESP_UUID_LEN_16; - gl_profile_tab[PROFILE_A_APP_ID].char_uuid.uuid.uuid16 = GATTS_CHAR_UUID_TEST_A; + gl_profile_tab[PROFILE_A_APP_ID].char_uuid.uuid.uuid16 = GATTS_CHAR_UUID_TEST_A; esp_ble_gatts_start_service(gl_profile_tab[PROFILE_A_APP_ID].service_handle); a_property = ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_NOTIFY; - esp_err_t add_char_ret = - esp_ble_gatts_add_char(gl_profile_tab[PROFILE_A_APP_ID].service_handle, - &gl_profile_tab[PROFILE_A_APP_ID].char_uuid, - ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, - a_property, - &gatts_demo_char1_val, + esp_err_t add_char_ret = + esp_ble_gatts_add_char(gl_profile_tab[PROFILE_A_APP_ID].service_handle, + &gl_profile_tab[PROFILE_A_APP_ID].char_uuid, + ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, + a_property, + &gatts_demo_char1_val, NULL); if (add_char_ret){ ESP_LOGE(GATTS_TAG, "add char failed, error code =%x",add_char_ret); @@ -559,22 +561,22 @@ The attribute handle returned by the event is stored in the profile table and th const uint8_t *prf_char; ESP_LOGI(GATTS_TAG, "ADD_CHAR_EVT, status %d, attr_handle %d, service_handle %d", - param->add_char.status, param->add_char.attr_handle, param->add_char.service_handle); + param->add_char.status, param->add_char.attr_handle, param->add_char.service_handle); gl_profile_tab[PROFILE_A_APP_ID].char_handle = param->add_char.attr_handle; - gl_profile_tab[PROFILE_A_APP_ID].descr_uuid.len = ESP_UUID_LEN_16; - gl_profile_tab[PROFILE_A_APP_ID].descr_uuid.uuid.uuid16 = ESP_GATT_UUID_CHAR_CLIENT_CONFIG; - esp_err_t get_attr_ret = esp_ble_gatts_get_attr_value(param->add_char.attr_handle, &length, &prf_char); - if (get_attr_ret == ESP_FAIL){ + gl_profile_tab[PROFILE_A_APP_ID].descr_uuid.len = ESP_UUID_LEN_16; + gl_profile_tab[PROFILE_A_APP_ID].descr_uuid.uuid.uuid16 = ESP_GATT_UUID_CHAR_CLIENT_CONFIG; + esp_err_t get_attr_ret = esp_ble_gatts_get_attr_value(param->add_char.attr_handle, &length, &prf_char); + if (get_attr_ret == ESP_FAIL){ ESP_LOGE(GATTS_TAG, "ILLEGAL HANDLE"); } ESP_LOGI(GATTS_TAG, "the gatts demo char length = %x", length); for(int i = 0; i < length; i++){ ESP_LOGI(GATTS_TAG, "prf_char[%x] = %x",i,prf_char[i]); - } - esp_err_t add_descr_ret = esp_ble_gatts_add_char_descr( - gl_profile_tab[PROFILE_A_APP_ID].service_handle, - &gl_profile_tab[PROFILE_A_APP_ID].descr_uuid, - ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, + } + esp_err_t add_descr_ret = esp_ble_gatts_add_char_descr( + gl_profile_tab[PROFILE_A_APP_ID].service_handle, + &gl_profile_tab[PROFILE_A_APP_ID].descr_uuid, + ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, NULL,NULL); if (add_descr_ret){ ESP_LOGE(GATTS_TAG, "add char descr failed, error code = %x", add_descr_ret); @@ -588,7 +590,7 @@ Once the descriptor is added, the `ESP_GATTS_ADD_CHAR_DESCR_EVT` event is trigge ```c case ESP_GATTS_ADD_CHAR_DESCR_EVT: ESP_LOGI(GATTS_TAG, "ADD_DESCR_EVT, status %d, attr_handle %d, service_handle %d", - param->add_char.status, param->add_char.attr_handle, + param->add_char.status, param->add_char.attr_handle, param->add_char.service_handle); break; ``` @@ -601,22 +603,22 @@ An `ESP_GATTS_CONNECT_EVT` is triggered when a client has connected to the GATT Profile A connection event: ```c -case ESP_GATTS_CONNECT_EVT: { - esp_ble_conn_update_params_t conn_params = {0}; +case ESP_GATTS_CONNECT_EVT: { + esp_ble_conn_update_params_t conn_params = {0}; memcpy(conn_params.bda, param->connect.remote_bda, sizeof(esp_bd_addr_t)); /* For the IOS system, please reference the apple official documents about the ble connection parameters restrictions. */ - conn_params.latency = 0; - conn_params.max_int = 0x30; // max_int = 0x30*1.25ms = 40ms - conn_params.min_int = 0x10; // min_int = 0x10*1.25ms = 20ms - conn_params.timeout = 400; // timeout = 400*10ms = 4000ms - ESP_LOGI(GATTS_TAG, "ESP_GATTS_CONNECT_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:, is_conn %d", - param->connect.conn_id, - param->connect.remote_bda[0], - param->connect.remote_bda[1], - param->connect.remote_bda[2], - param->connect.remote_bda[3], - param->connect.remote_bda[4], - param->connect.remote_bda[5], + conn_params.latency = 0; + conn_params.max_int = 0x30; // max_int = 0x30*1.25ms = 40ms + conn_params.min_int = 0x10; // min_int = 0x10*1.25ms = 20ms + conn_params.timeout = 400; // timeout = 400*10ms = 4000ms + ESP_LOGI(GATTS_TAG, "ESP_GATTS_CONNECT_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:, is_conn %d", + param->connect.conn_id, + param->connect.remote_bda[0], + param->connect.remote_bda[1], + param->connect.remote_bda[2], + param->connect.remote_bda[3], + param->connect.remote_bda[4], + param->connect.remote_bda[5], param->connect.is_connected); gl_profile_tab[PROFILE_A_APP_ID].conn_id = param->connect.conn_id; //start sent the update connection parameters to the peer device. @@ -628,15 +630,15 @@ case ESP_GATTS_CONNECT_EVT: { Profile B connection event: ```c -case ESP_GATTS_CONNECT_EVT: - ESP_LOGI(GATTS_TAG, "CONNECT_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:, is_conn %d", - param->connect.conn_id, - param->connect.remote_bda[0], - param->connect.remote_bda[1], - param->connect.remote_bda[2], - param->connect.remote_bda[3], - param->connect.remote_bda[4], - param->connect.remote_bda[5], +case ESP_GATTS_CONNECT_EVT: + ESP_LOGI(GATTS_TAG, "CONNECT_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:, is_conn %d", + param->connect.conn_id, + param->connect.remote_bda[0], + param->connect.remote_bda[1], + param->connect.remote_bda[2], + param->connect.remote_bda[3], + param->connect.remote_bda[4], + param->connect.remote_bda[5], param->connect.is_connected); gl_profile_tab[PROFILE_B_APP_ID].conn_id = param->connect.conn_id; break; @@ -675,19 +677,19 @@ In this example, a response is constructed with dummy data and sent back to the ```c case ESP_GATTS_READ_EVT: { - ESP_LOGI(GATTS_TAG, "GATT_READ_EVT, conn_id %d, trans_id %d, handle %d", - param->read.conn_id, param->read.trans_id, param->read.handle); - esp_gatt_rsp_t rsp; - memset(&rsp, 0, sizeof(esp_gatt_rsp_t)); - rsp.attr_value.handle = param->read.handle; - rsp.attr_value.len = 4; - rsp.attr_value.value[0] = 0xde; - rsp.attr_value.value[1] = 0xed; - rsp.attr_value.value[2] = 0xbe; - rsp.attr_value.value[3] = 0xef; - esp_ble_gatts_send_response(gatts_if, - param->read.conn_id, - param->read.trans_id, + ESP_LOGI(GATTS_TAG, "GATT_READ_EVT, conn_id %d, trans_id %d, handle %d", + param->read.conn_id, param->read.trans_id, param->read.handle); + esp_gatt_rsp_t rsp; + memset(&rsp, 0, sizeof(esp_gatt_rsp_t)); + rsp.attr_value.handle = param->read.handle; + rsp.attr_value.len = 4; + rsp.attr_value.value[0] = 0xde; + rsp.attr_value.value[1] = 0xed; + rsp.attr_value.value[2] = 0xbe; + rsp.attr_value.value[3] = 0xef; + esp_ble_gatts_send_response(gatts_if, + param->read.conn_id, + param->read.trans_id, ESP_GATT_OK, &rsp); break; } @@ -714,7 +716,7 @@ There are two types of write events implemented in this example, write character When a write event is triggered, this example prints logging messages, and then executes the `example_write_event_env()` function. ```c -case ESP_GATTS_WRITE_EVT: { +case ESP_GATTS_WRITE_EVT: { ESP_LOGI(GATTS_TAG, "GATT_WRITE_EVT, conn_id %d, trans_id %d, handle %d", param->write.conn_id, param->write.trans_id, param->write.handle); if (!param->write.is_prep){ ESP_LOGI(GATTS_TAG, "GATT_WRITE_EVT, value len %d, value :", param->write.len); @@ -727,12 +729,12 @@ case ESP_GATTS_WRITE_EVT: { uint8_t notify_data[15]; for (int i = 0; i < sizeof(notify_data); ++i) { - notify_data[i] = i%0xff; + notify_data[i] = i%0xff; } //the size of notify_data[] need less than MTU size - esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, - gl_profile_tab[PROFILE_B_APP_ID].char_handle, - sizeof(notify_data), + esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, + gl_profile_tab[PROFILE_B_APP_ID].char_handle, + sizeof(notify_data), notify_data, false); } }else if (descr_value == 0x0002){ @@ -744,9 +746,9 @@ case ESP_GATTS_WRITE_EVT: { indicate_data[i] = i % 0xff; } //the size of indicate_data[] need less than MTU size - esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, - gl_profile_tab[PROFILE_B_APP_ID].char_handle, - sizeof(indicate_data), + esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, + gl_profile_tab[PROFILE_B_APP_ID].char_handle, + sizeof(indicate_data), indicate_data, true); } } @@ -762,7 +764,7 @@ case ESP_GATTS_WRITE_EVT: { } ``` -
Message flow for Write Long Characteristic
+
Message flow for Write Long Characteristic
The `example_write_event_env()` function contains the logic for the write long characteristic procedure: @@ -793,7 +795,7 @@ void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare gatt_rsp->attr_value.offset = param->write.offset; gatt_rsp->attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE; memcpy(gatt_rsp->attr_value.value, param->write.value, param->write.len); - esp_err_t response_err = esp_ble_gatts_send_response(gatts_if, param->write.conn_id, + esp_err_t response_err = esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, status, gatt_rsp); if (response_err != ESP_OK){ ESP_LOGE(GATTS_TAG, "Send response error"); @@ -817,7 +819,7 @@ void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare When the client sends a Write Request or a Prepare Write Request, the server shall respond. However, if the client sends a Write Without Response command, the server does not need to reply back a response. This is checked in the write procedure by examining the value of the `write.need_rsp parameter`. If a response is needed, the procedure continues doing the response preparation, if not present, the client does not need a response and therefore the procedure is ended. ```c -void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare_write_env, +void example_write_event_env(esp_gatt_if_t gatts_if, prepare_type_env_t *prepare_write_env, esp_ble_gatts_cb_param_t *param){ esp_gatt_status_t status = ESP_GATT_OK; if (param->write.need_rsp){ @@ -851,10 +853,10 @@ In order to use the prepare buffer, some memory space is allocated for it. In ca ```c if (prepare_write_env->prepare_buf == NULL) { - prepare_write_env->prepare_buf = - (uint8_t*)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t)); + prepare_write_env->prepare_buf = + (uint8_t*)malloc(PREPARE_BUF_MAX_SIZE*sizeof(uint8_t)); prepare_write_env->prepare_len = 0; - if (prepare_write_env->prepare_buf == NULL) { + if (prepare_write_env->prepare_buf == NULL) { ESP_LOGE(GATTS_TAG, "Gatt_server prep no mem"); status = ESP_GATT_NO_RESOURCES; } @@ -883,7 +885,7 @@ gatt_rsp->attr_value.handle = param->write.handle; gatt_rsp->attr_value.offset = param->write.offset; gatt_rsp->attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE; memcpy(gatt_rsp->attr_value.value, param->write.value, param->write.len); -esp_err_t response_err = esp_ble_gatts_send_response(gatts_if, param->write.conn_id, +esp_err_t response_err = esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, status, gatt_rsp); if (response_err != ESP_OK){ ESP_LOGE(GATTS_TAG, "Send response error"); @@ -897,17 +899,17 @@ Finally, the incoming data is copied to the buffer created and its length is inc ```c memcpy(prepare_write_env->prepare_buf + param->write.offset, - param->write.value, + param->write.value, param->write.len); prepare_write_env->prepare_len += param->write.len; ``` The client finishes the long write sequence by sending an Executive Write Request. This command triggers an `ESP_GATTS_EXEC_WRITE_EVT` event. The server handles this event by sending a response and executing the `example_exec_write_event_env()` function: ```c -case ESP_GATTS_EXEC_WRITE_EVT: - ESP_LOGI(GATTS_TAG,"ESP_GATTS_EXEC_WRITE_EVT"); - esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, ESP_GATT_OK, NULL); - example_exec_write_event_env(&a_prepare_write_env, param); +case ESP_GATTS_EXEC_WRITE_EVT: + ESP_LOGI(GATTS_TAG,"ESP_GATTS_EXEC_WRITE_EVT"); + esp_ble_gatts_send_response(gatts_if, param->write.conn_id, param->write.trans_id, ESP_GATT_OK, NULL); + example_exec_write_event_env(&a_prepare_write_env, param); break; ``` Let’s take a look at the Executive Write function: @@ -931,9 +933,9 @@ void example_exec_write_event_env(prepare_type_env_t *prepare_write_env, esp_ble The executive write is used to either confirm or cancel the write procedure done before, by the Long Characteristic Write procedure. In order to do this, the function checks for the `exec_write_flag` in the parameters received with the event. If the flag equals the execute flag represented by `exec_write_flag`, the write is confirmed and the buffer is printed in the log; if not, then it means the write is canceled and all the data that has been written is deleted. ```c -if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC){ - esp_log_buffer_hex(GATTS_TAG, - prepare_write_env->prepare_buf, +if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC){ + esp_log_buffer_hex(GATTS_TAG, + prepare_write_env->prepare_buf, prepare_write_env->prepare_len); } else{ diff --git a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c index 270153901d..982927ef3b 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c +++ b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c @@ -538,7 +538,8 @@ void app_main(void) return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md index 1cb9d2694a..7db332db2a 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md @@ -2,7 +2,7 @@ ## Introduction -This document presents a walkthrough of the GATT Server Service Table example code for the ESP32. This example implements a Bluetooth Low Energy (BLE) Generic Attribute (GATT) Server using a table-like data structure to define the server services and characteristics such as the one shown in the figure below Therefore, it demonstrates a practical way to define the server functionality in one place instead of adding services and characteristics one by one. +This document presents a walkthrough of the GATT Server Service Table example code for the ESP32. This example implements a Bluetooth Low Energy (BLE) Generic Attribute (GATT) Server using a table-like data structure to define the server services and characteristics such as the one shown in the figure below Therefore, it demonstrates a practical way to define the server functionality in one place instead of adding services and characteristics one by one. This example implements the *Heart Rate Profile* as defined by the [Traditional Profile Specifications](https://www.bluetooth.com/specifications/profiles-overview). @@ -101,7 +101,8 @@ void app_main() } ESP_LOGI(GATTS_TABLE_TAG, "%s init bluetooth", __func__); - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed", __func__); return; @@ -132,7 +133,7 @@ See this section in [GATT Server Example Walkthrough](../../gatt_server/tutorial ## Application Profiles -This example implements one Application Profile for the Heart Rate Service. An Application Profile is a way to group functionality which is designed to be used by one client application, for example one smartphone mobile app. In this way, different types of profiles can be accommodated in one server. The Application Profile ID, which is an user-assigned number to identify each profile, is used to register the profile in the stack, in this example the ID is 0x55. +This example implements one Application Profile for the Heart Rate Service. An Application Profile is a way to group functionality which is designed to be used by one client application, for example one smartphone mobile app. In this way, different types of profiles can be accommodated in one server. The Application Profile ID, which is an user-assigned number to identify each profile, is used to register the profile in the stack, in this example the ID is 0x55. ```c #define HEART_PROFILE_NUM 1 @@ -211,7 +212,7 @@ The minimum and maximum slave preferred connection intervals are set in units of An advertising payload can be up to 31 bytes of data. It is possible that some of the parameters surpass the 31-byte advertisement packet limit which causes the stack to cut the message and leave some of the parameters out. To solve this, usually the longer parameters are stored in the scan response, which can be configured using the same ``esp_ble_gap_config_adv_data()`` function and an additional esp_ble_adv_data_t type structure with the .set_scan_rsp parameter is set to true. Finally, to set the device name the ``esp_ble_gap_set_device_name()`` function is used. The registering event handler is shown as follows: ```c -static void gatts_profile_event_handler(esp_gatts_cb_event_t event, +static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) { ESP_LOGE(GATTS_TABLE_TAG, "event = %x",event); @@ -231,9 +232,9 @@ Once the advertising data have been set, the ``ESP_GAP_BLE_ADV_DATA_SET_COMPLETE ```c static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) -{ +{ ESP_LOGE(GATTS_TABLE_TAG, "GAP_EVT, event %d", event); - + switch (event) { case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: esp_ble_gap_start_advertising(&heart_rate_adv_params); @@ -364,12 +365,12 @@ The attr_control is the auto-respond parameter which can be set as ``ESP_GATT_AU The ``att_desc`` is the attribute description which is made of: ```c -uint16_t uuid_length; /*!< UUID length */ -uint8_t *uuid_p; /*!< UUID value */ -uint16_t perm; /*!< Attribute permission */ -uint16_t max_length; /*!< Maximum length of the element*/ -uint16_t length; /*!< Current length of the element*/ -uint8_t *value; /*!< Element value array*/ +uint16_t uuid_length; /*!< UUID length */ +uint8_t *uuid_p; /*!< UUID value */ +uint16_t perm; /*!< Attribute permission */ +uint16_t max_length; /*!< Maximum length of the element*/ +uint16_t length; /*!< Current length of the element*/ +uint8_t *value; /*!< Element value array*/ ``` For example, the first element of the table in this example is the service attribute: @@ -468,7 +469,7 @@ case ESP_GATTS_CREAT_ATTR_TAB_EVT:{ break; ``` -The handles stored in the handles pointer of the event parameters are numbers that identify each attribute. The handles can be used to know which characteristic is being read or written to, therefore they can be passed around and to upper layers of the application to handle different actions. +The handles stored in the handles pointer of the event parameters are numbers that identify each attribute. The handles can be used to know which characteristic is being read or written to, therefore they can be passed around and to upper layers of the application to handle different actions. Finally, the heart_rate_handle_table contains the Application Profile in the form of a structure with information about the attribute parameters as well as GATT interface, connection ID, permissions and application ID. The profile structure is shown as follows, note that not all members are used in this example: diff --git a/examples/bluetooth/bluedroid/ble/gattc_multi_connect/main/gattc_multi_connect.c b/examples/bluetooth/bluedroid/ble/gattc_multi_connect/main/gattc_multi_connect.c index e09ca88cbb..86ce49477f 100644 --- a/examples/bluetooth/bluedroid/ble/gattc_multi_connect/main/gattc_multi_connect.c +++ b/examples/bluetooth/bluedroid/ble/gattc_multi_connect/main/gattc_multi_connect.c @@ -930,7 +930,8 @@ void app_main(void) return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTC_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble_50/ble50_security_client/main/ble50_sec_gattc_demo.c b/examples/bluetooth/bluedroid/ble_50/ble50_security_client/main/ble50_sec_gattc_demo.c index f4a66878a5..8ef8dffc72 100644 --- a/examples/bluetooth/bluedroid/ble_50/ble50_security_client/main/ble50_sec_gattc_demo.c +++ b/examples/bluetooth/bluedroid/ble_50/ble50_security_client/main/ble50_sec_gattc_demo.c @@ -582,7 +582,8 @@ void app_main(void) return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTC_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble_50/ble50_security_server/main/ble50_sec_gatts_demo.c b/examples/bluetooth/bluedroid/ble_50/ble50_security_server/main/ble50_sec_gatts_demo.c index 32264b0234..ecba57764b 100644 --- a/examples/bluetooth/bluedroid/ble_50/ble50_security_server/main/ble50_sec_gatts_demo.c +++ b/examples/bluetooth/bluedroid/ble_50/ble50_security_server/main/ble50_sec_gatts_demo.c @@ -486,7 +486,8 @@ void app_main(void) } ESP_LOGI(GATTS_TABLE_TAG, "%s init bluetooth", __func__); - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble_50/multi-adv/main/multi_adv_demo.c b/examples/bluetooth/bluedroid/ble_50/multi-adv/main/multi_adv_demo.c index e30c6a8961..2b0cdb1e45 100644 --- a/examples/bluetooth/bluedroid/ble_50/multi-adv/main/multi_adv_demo.c +++ b/examples/bluetooth/bluedroid/ble_50/multi-adv/main/multi_adv_demo.c @@ -213,7 +213,8 @@ void app_main(void) ESP_LOGE(LOG_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret)); return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(LOG_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble_50/multi-adv/tutorial/Mulit_Adv_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble_50/multi-adv/tutorial/Mulit_Adv_Example_Walkthrough.md index bad6d70d12..39c778d989 100644 --- a/examples/bluetooth/bluedroid/ble_50/multi-adv/tutorial/Mulit_Adv_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble_50/multi-adv/tutorial/Mulit_Adv_Example_Walkthrough.md @@ -1,6 +1,6 @@ # Multi Adv Example Walkthrough -## introduction +## introduction In this document, we review the Multi Adv example code which implements a Bluetooth Low Energy (BLE5.0) Multi adv profile on the ESP32C3. This example is designed around two Application Profiles and a series of events that are handled in order to execute a sequence of configuration steps, such as defining extended advertising parameters with all phy 1M,2M and coded and Ext adv data. @@ -24,7 +24,7 @@ First, let’s take a look at the include #include "esp_bt_defs.h" #include "esp_bt_main.h" #include "esp_gatt_common_api.h" -#include "sdkconfig.h" +#include "sdkconfig.h" ``` These includes are required for the FreeRTOS and underlaying system components to run, including the logging functionality and a library to store data in non-volatile flash memory. We are interested in `"esp_bt.h"`, `"esp_bt_main.h"`, `"esp_gap_ble_api.h"` and `"esp_gatts_api.h"`, which expose the BLE APIs required to implement this example. @@ -35,9 +35,9 @@ These includes are required for the FreeRTOS and underlaying system components t * `esp_gatts_api.h`: implements GATT configuration, such as creating services and characteristics. ## Main Entry Point - + The entry point to this example is the app_main() function: - + ```c void app_main(void) { @@ -65,7 +65,8 @@ void app_main(void) ESP_LOGE(LOG_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret)); return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(LOG_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; @@ -79,7 +80,7 @@ void app_main(void) if (ret){ ESP_LOGE(LOG_TAG, "gap register error, error code = %x", ret); return; - + } vTaskDelay(200 / portTICK_PERIOD_MS); @@ -111,7 +112,7 @@ void app_main(void) return; -} +} ``` The main function starts by initializing the non-volatile storage library. This library allows tosave key-value pairs in flash memory and is used by some components such as the Wi-Fi library to save the SSID and password: @@ -144,7 +145,8 @@ There are four Bluetooth modes supported: After the initialization of the BT controller, the Bluedroid stack, which includes the common definitions and APIs for both BT Classic and BLE, is initialized and enabled by using: ```c -ret = esp_bluedroid_init(); +esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); ret = esp_bluedroid_enable(); ``` The Bluetooth stack is up and running at this point in the program flow, however the functionality of the application has not been defined yet. The functionality is defined by reacting to events @@ -158,7 +160,7 @@ The functions `gap_event_handler()` handle all the events that are pu shed to the application from the BLE stack. ## Setting GAP Parameters - + The register application event is the first one that is triggered during the lifetime of the program, this example uses the Profile A GATT event handle to configure the advertising parameters upon registration. This example has the option to use both standard Bluetooth Core Specification advertising parameters or a customized raw buffer. The option can be selected with the `CONFIG_SET_RAW_ADV_DATA` define. The raw advertising data can be used to implement iBeacons, Eddystone or other proprietary, and custom frame types such as the ones used for Indoor Location Services that are different from the standard specifications. The function is used to configure different types of extended advertisement types and legacy adv with 1M,2M and coded phy in esp_ble_gap_ext_adv_set_params , esp_ble_gap_ext_adv_set_rand_addr and esp_ble_gap_config_ext_adv_data_raw. Respective structure of each one of them mentioned below with one example: @@ -229,7 +231,7 @@ Once the Extended advertising data have been set, the GAP event `ESP_GAP_BLE_EXT ```c static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) -{ +{ switch (event) { case ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT: xSemaphoreGive(test_sem); @@ -269,7 +271,7 @@ rt.status); ``` ## Default config -This example by default configured with +This example by default configured with 1M phy extend adv, Connectable advertising 2M phy extend adv, Scannable advertising 1M phy legacy adv, ADV_IND diff --git a/examples/bluetooth/bluedroid/ble_50/peroidic_adv/main/periodic_adv_demo.c b/examples/bluetooth/bluedroid/ble_50/peroidic_adv/main/periodic_adv_demo.c index 35f594c78b..6924e512c7 100644 --- a/examples/bluetooth/bluedroid/ble_50/peroidic_adv/main/periodic_adv_demo.c +++ b/examples/bluetooth/bluedroid/ble_50/peroidic_adv/main/periodic_adv_demo.c @@ -164,7 +164,8 @@ void app_main(void) ESP_LOGE(LOG_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret)); return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(LOG_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble_50/peroidic_adv/tutorial/Periodic_adv_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble_50/peroidic_adv/tutorial/Periodic_adv_Example_Walkthrough.md index a45c3398d0..95166190a6 100644 --- a/examples/bluetooth/bluedroid/ble_50/peroidic_adv/tutorial/Periodic_adv_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble_50/peroidic_adv/tutorial/Periodic_adv_Example_Walkthrough.md @@ -1,6 +1,6 @@ # Periodic Adv Example Walkthrough -## introduction +## introduction In this document, We review the Periodic Adv example code which implements a Bluetooth Low Energy (BLE5.0) Multi adv profile on the ESP32C3. This example is designed the periodic advertisement which allow the scanner to sync with the advertiser so that scanner and advertiser wake up same time. @@ -28,16 +28,16 @@ First, let’s take a look at the include ``` These includes are required for the FreeRTOS and underlying system components to run, including the logging functionality and a library to store data in non-volatile flash memory. We are interested in `"esp_bt.h"`, `"esp_bt_main.h"`, `"esp_gap_ble_api.h"` and `"esp_gatts_api.h"`, which expose the BLE APIs required to implement this example. - + * `esp_bt.h`: implements BT controller and VHCI configuration procedures from the host side. * `esp_bt_main.h`: implements initialization and enabling of the Bluedroid stack. * `esp_gap_ble_api.h`: implements GAP configuration, such as advertising and connection parameters. * `esp_gatts_api.h`: implements GATT configuration, such as creating services and characteristics. - + ## Main Entry Point - + The entry point to this example is the app_main() function: - + ```c void app_main(void) { @@ -66,7 +66,8 @@ void app_main(void) ESP_LOGE(LOG_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret)); return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(LOG_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; @@ -107,39 +108,40 @@ dv_raw_data), &periodic_adv_raw_data[0]), test_sem); ``` The main function starts by initializing the non-volatile storage library. This library allows to save key-value pairs in flash memory and is used by some components such as the Wi-Fi library to save the SSID and password: - + ```c ret = nvs_flash_init(); ``` ## BT Controller and Stack Initialization - + The main function also initializes the BT controller by first creating a BT controller configuration structure named `esp_bt_controller_config_t` with default settings generated by the `BT_CONTROLLER_INIT_CONFIG_DEFAULT()` macro. The BT controller implements the Host Controller Interface (HCI) on the controller side, the Link Layer (LL) and the Physical Layer (PHY). The BT Controller is invisible to the user applications and deals with the lower layers of the BLE stack. The controller configuration includes setting the BT controller stack size, priority and HCI baud rate. With the settings created, the BT controller is initialized and enabled with the `esp_bt_controller_init()` function: - + ```c esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); ret = esp_bt_controller_init(&bt_cfg); ``` - + Next, the controller is enabled in BLE Mode. - + ```c ret = esp_bt_controller_enable(ESP_BT_MODE_BLE); ``` > The controller should be enabled in `ESP_BT_MODE_BTDM`, if you want to use the dual mode (BLE + BT). - + There are four Bluetooth modes supported: - + 1. `ESP_BT_MODE_IDLE`: Bluetooth not running 2. `ESP_BT_MODE_BLE`: BLE mode 3. `ESP_BT_MODE_CLASSIC_BT`: BT Classic mode 4. `ESP_BT_MODE_BTDM`: Dual mode (BLE + BT Classic) - + After the initialization of the BT controller, the Bluedroid stack, which includes the common definitions and APIs for both BT Classic and BLE, is initialized and enabled by using: - + ```c - ret = esp_bluedroid_init(); - ret = esp_bluedroid_enable(); +esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); +ret = esp_bluedroid_enable(); ``` The Bluetooth stack is up and running at this point in the program flow, however the functionality of the application has not been defined yet. The functionality is defined by reacting to events such as what happens when another device tries to read or write parameters and establish a connection. The two main managers of events are the GAP and GATT event handlers. The application needs to register a callback function for each event handler in order to let the application know which functions are going to handle the GAP and GATT events: @@ -186,7 +188,7 @@ esp_ble_gap_ext_adv_params_t ext_adv_params_2M = { .channel_map = ADV_CHNL_ALL, .filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, .primary_phy = ESP_BLE_GAP_PHY_1M, - .max_skip = 0, + .max_skip = 0, .secondary_phy = ESP_BLE_GAP_PHY_2M, .sid = 0, .scan_req_notif = false, @@ -223,7 +225,7 @@ static esp_ble_gap_periodic_adv_params_t periodic_adv_params = { ```c static uint8_t periodic_adv_raw_data[] = { 0x02, 0x01, 0x06, - 0x02, 0x0a, 0xeb, + 0x02, 0x0a, 0xeb, 0x03, 0x03, 0xab, 0xcd, 0x11, 0x09, 'E', 'S', 'P', '_', 'P', 'E', 'R', 'I', 'O', 'D', 'I', 'C', '_', 'A', 'D', 'V' @@ -240,10 +242,10 @@ Once we config the all the adv instances, We can start advertising using the fun ## GAP Event Handler Once the Extended advertising data have been set, the GAP event `ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT, ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT,ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT, ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT and ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT` is triggered. - + ```c -static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param){ +static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param){ switch (event) { case ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT: xSemaphoreGive(test_sem); diff --git a/examples/bluetooth/bluedroid/ble_50/peroidic_sync/main/periodic_sync_demo.c b/examples/bluetooth/bluedroid/ble_50/peroidic_sync/main/periodic_sync_demo.c index 1752a49788..fb3650529c 100644 --- a/examples/bluetooth/bluedroid/ble_50/peroidic_sync/main/periodic_sync_demo.c +++ b/examples/bluetooth/bluedroid/ble_50/peroidic_sync/main/periodic_sync_demo.c @@ -159,7 +159,8 @@ void app_main(void) ESP_LOGE(LOG_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret)); return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(LOG_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/bluedroid/ble_50/peroidic_sync/tutorial/Periodic_Sync_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble_50/peroidic_sync/tutorial/Periodic_Sync_Example_Walkthrough.md index 3635c9e2ed..bba00bb45a 100644 --- a/examples/bluetooth/bluedroid/ble_50/peroidic_sync/tutorial/Periodic_Sync_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble_50/peroidic_sync/tutorial/Periodic_Sync_Example_Walkthrough.md @@ -11,7 +11,7 @@ Little info about the EXT_ADV_IND , AUX_ADV_IND and AUX_SYNC_IND with scanner su ADV_EXT_IND is over primary advertising channels and is used to indicate that an advertisement will be sent on a secondary advertisement channel. The information in ADV_EXT_IND will inform the scanner: * Which secondary advertising channel will be used by AUX_ADV_IND -* Which PHY will be used by AUX_ADV_IND, 1M PHY, 2M PHY, or 1M Coded PHY +* Which PHY will be used by AUX_ADV_IND, 1M PHY, 2M PHY, or 1M Coded PHY * When AUX_ADV_IND will be presented on that specified secondary advertising channel If the scanner is capable of periodic advertising, it will enable its receiver at a specific channel and PHY at a specific time slot. @@ -50,7 +50,7 @@ With this information, the scanner can synchronize with the advertiser and they ``` These `includes` are required for the FreeRTOS and underlaying system components to run, including the logging functionality and a library to store data in non-volatile flash memory. We are interested in `“bt.h”`, `“esp_bt_main.h”`, `"esp_gap_ble_api.h"` and `“esp_gattc_api.h”`, which expose the BLE APIs required to implement this example. - + * `esp_bt.h`: configures the BT controller and VHCI from the host side. * `esp_bt_main.h`: initializes and enables the Bluedroid stack. * `esp_gap_ble_api.h`: implements the GAP configuration, such as advertising and connection parameters. @@ -86,7 +86,8 @@ void app_main(void) ESP_LOGE(LOG_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret)); return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(LOG_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; @@ -138,7 +139,7 @@ Next, the controller is enabled in BLE Mode. ```c ret = esp_bt_controller_enable(ESP_BT_MODE_BLE); ``` -> The controller should be enabled in `ESP_BT_MODE_BTDM`, if you want to use the dual mode (BLE + +> The controller should be enabled in `ESP_BT_MODE_BTDM`, if you want to use the dual mode (BLE + BT). There are four Bluetooth modes supported: @@ -151,7 +152,8 @@ There are four Bluetooth modes supported: After the initialization of the BT controller, the Bluedroid stack, which includes the common definitions and APIs for both BT Classic and BLE, is initialized and enabled by using: ```c -ret = esp_bluedroid_init(); +esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); ret = esp_bluedroid_enable(); ``` The main function ends by registering the GAP and GATT event handlers, as well as the Application Profile and set the maximum supported MTU size. @@ -195,7 +197,7 @@ typedef struct { esp_ble_ext_scan_cfg_t uncoded_cfg; /*!< ext scan uncoded config parameters */ esp_ble_ext_scan_cfg_t coded_cfg; /*!< ext scan coded config parameters */ } esp_ble_ext_scan_params_t; - + /** * @brief ext scan config */ @@ -217,7 +219,7 @@ t: 0x0010 (10 ms) //Time Range: 2.5 msec to 10240 msec } esp_ble_ext_scan_cfg_t; - + ``` An it is initialized as : @@ -247,7 +249,7 @@ typedef struct { hat can be skipped */ uint16_t sync_timeout; /*!< synchronization timeout */ } esp_ble_gap_periodic_adv_sync_params_t; - + ``` An it is initialized as: ```c @@ -257,7 +259,7 @@ static esp_ble_gap_periodic_adv_sync_params_t periodic_adv_sync_params = { .addr_type = BLE_ADDR_TYPE_RANDOM, .skip = 10, .sync_timeout = 1000, - }; + }; ``` The BLE scan parameters are configured so that the type of scanning is active (includes reading he scanning response), it is of public type, allows any advertising device to be read and has a scanning interval of 80 ms (1.25 ms * 0x40) and a scanning window of 80 ms (1.25 ms * 0x40). @@ -334,9 +336,9 @@ dv_sync_estab.status); ESP_LOGI(LOG_TAG, "periodic adv report, sync handle %d data status %d data len %d rssi %d ", param->period_adv_report.params.sync_handle, param->period_adv_report.params.data_status, - + param->period_adv_report.params.data_length, - + param->period_adv_report.params.rssi); break; diff --git a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/Kconfig.projbuild b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/Kconfig.projbuild index 67f53d5ded..468ad311d6 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/Kconfig.projbuild +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/Kconfig.projbuild @@ -1,4 +1,11 @@ menu "A2DP Example Configuration" + config EXAMPLE_A2DP_SINK_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing choice EXAMPLE_A2DP_SINK_OUTPUT prompt "A2DP Sink Output" diff --git a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c index 63bc0022fb..a140507146 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -62,7 +62,7 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_A2DP_SINK_SSP_ENABLED == true) /* when Security Simple Pairing user confirmation requested, this event comes */ case ESP_BT_GAP_CFM_REQ_EVT: ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); @@ -168,16 +168,22 @@ void app_main(void) ESP_LOGE(BT_AV_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(err)); return; } - if ((err = esp_bluedroid_init()) != ESP_OK) { + + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_A2DP_SINK_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((err = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(err)); return; } + if ((err = esp_bluedroid_enable()) != ESP_OK) { ESP_LOGE(BT_AV_TAG, "%s enable bluedroid failed: %s", __func__, esp_err_to_name(err)); return; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_A2DP_SINK_SSP_ENABLED == true) /* set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; diff --git a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/tutorial/Example_A2DP_Sink.md b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/tutorial/Example_A2DP_Sink.md index ddb06a557e..510077b9aa 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/tutorial/Example_A2DP_Sink.md +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/tutorial/Example_A2DP_Sink.md @@ -66,16 +66,20 @@ if (esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT) != OK) { After the initialization of the Bluetooth Controller, the Bluedroid Stack, which includes the common definitions and APIs for Classic Bluetooth is initialized and enabled by using: ```c -/* initialize Bluedroid Host */ -if (esp_bluedroid_init() != ESP_OK) { - ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed", __func__); - return; -} -/* enable Bluedroid Host */ -if (esp_bluedroid_enable() != ESP_OK) { - ESP_LOGE(BT_AV_TAG, "%s enable bluedroid failed", __func__); - return; -} + /* initialize Bluedroid Host */ + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_A2DP_SINK_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((err = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { + ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(err)); + return; + } + /* enable Bluedroid Host */ + if (esp_bluedroid_enable() != ESP_OK) { + ESP_LOGE(BT_AV_TAG, "%s enable bluedroid failed", __func__); + return; + } ``` The Classic Bluetooth uses an asynchronous programming paradigm. The entire Bluedroid stack sees the use of events, event handlers, callbacks and state machines. Most APIs are implemented by posting specific type of events to the work queue of Bluedroid Stack. Threads(FreeRTOS) tasks inside Bluedroid then process the events with specific handlers, according to the internal state. When the operations are completed, Bluedroid stack invokes the callback function which is registered by application, to report some other events and information. @@ -136,7 +140,7 @@ The main function installs I2S to play the audio. A loudspeaker, additional ADC The main function continues to set up paring parameters including Secure Simple Pairing and Legacy Pairing. ```c -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_A2DP_SINK_SSP_ENABLED == true) /* set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; diff --git a/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/Kconfig.projbuild b/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/Kconfig.projbuild new file mode 100644 index 0000000000..ece773895f --- /dev/null +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "A2DP Example Configuration" + config EXAMPLE_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing +endmenu diff --git a/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c b/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c index b4a370c7df..18f0de815d 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_source/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -267,7 +267,7 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* when Security Simple Pairing user confirmation requested, this event comes */ case ESP_BT_GAP_CFM_REQ_EVT: ESP_LOGI(BT_AV_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); @@ -750,16 +750,22 @@ void app_main(void) ESP_LOGE(BT_AV_TAG, "%s enable controller failed", __func__); return; } - if (esp_bluedroid_init() != ESP_OK) { - ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed", __func__); + + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { + ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } + if (esp_bluedroid_enable() != ESP_OK) { ESP_LOGE(BT_AV_TAG, "%s enable bluedroid failed", __func__); return; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; diff --git a/examples/bluetooth/bluedroid/classic_bt/a2dp_source/tutorial/Example_A2DP_Source.md b/examples/bluetooth/bluedroid/classic_bt/a2dp_source/tutorial/Example_A2DP_Source.md index bf1767a978..84b19c5436 100644 --- a/examples/bluetooth/bluedroid/classic_bt/a2dp_source/tutorial/Example_A2DP_Source.md +++ b/examples/bluetooth/bluedroid/classic_bt/a2dp_source/tutorial/Example_A2DP_Source.md @@ -63,16 +63,20 @@ if (esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT) != OK) { After the initialization of the Bluetooth Controller, the Bluedroid stack, which includes the common definitions and APIs for Classic Bluetooth is initialized and enabled by using: ```c -/* initialize Bluedroid Host */ -if (esp_bluedroid_init() != ESP_OK) { - ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed", __func__); - return; -} -/* Enable Bluedroid Host */ -if (esp_bluedroid_enable() != ESP_OK) { - ESP_LOGE(BT_AV_TAG, "%s enable bluedroid failed", __func__); - return; -} + /* initialize Bluedroid Host */ + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { + ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); + return; + } + /* Enable Bluedroid Host */ + if (esp_bluedroid_enable() != ESP_OK) { + ESP_LOGE(BT_AV_TAG, "%s enable bluedroid failed", __func__); + return; + } ``` The Classic Bluetooth uses an asynchronous programming paradigm. The entire Bluedroid stack sees the use of events, event handlers, callbacks and state machines. Most APIs are implemented by posting specific type of events to the work queue of Bluedroid Stack. Threads(FreeRTOS) tasks inside Bluedroid then process the events with specific handlers, according to the internal state. When the operations are completed, Bluedroid stack invokes the callback function which is registered by application, to report some other events and information. @@ -84,7 +88,7 @@ For example, after executing `esp_bt_gap_start_discovery()`, an event of `ESP_BT The main function continues to set up paring parameters including Secure Simple Pairing and Legacy Pairing. ```c -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; @@ -111,7 +115,7 @@ bt_app_task_start_up(); ### Profile Set up -The main function ends up dispatching event "BT_APP_STACK_UP_EVT" to the application task. +The main function ends up dispatching event "BT_APP_STACK_UP_EVT" to the application task. ```c /* Bluetooth device name, connection mode and profile set up */ diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_discovery/README.md b/examples/bluetooth/bluedroid/classic_bt/bt_discovery/README.md index dfe1a372a2..d9f0cd621c 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_discovery/README.md +++ b/examples/bluetooth/bluedroid/classic_bt/bt_discovery/README.md @@ -118,7 +118,8 @@ There are four Bluetooth modes supported: After the initialization of the Bluetooth controller, the Bluedroid stack, which includes the common definitions and APIs for both Bluetooth Classic and BLE, is initialized and enabled by using: ```c -if ((ret = esp_bluedroid_init()) != ESP_OK) { +esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { ESP_LOGE(GAP_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_discovery/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_discovery/main/main.c index 475c0180e6..cf451a18ed 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_discovery/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_discovery/main/main.c @@ -293,7 +293,8 @@ void app_main(void) return; } - if ((ret = esp_bluedroid_init()) != ESP_OK) { + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { ESP_LOGE(GAP_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/Kconfig.projbuild b/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/Kconfig.projbuild new file mode 100644 index 0000000000..568ef5ae62 --- /dev/null +++ b/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "HID Example Configuration" + config EXAMPLE_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing +endmenu diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c index 50bab9fa33..f6e5906470 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -199,7 +199,7 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) break; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) case ESP_BT_GAP_CFM_REQ_EVT: ESP_LOGI(TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true); @@ -411,8 +411,12 @@ void app_main(void) return; } - if ((ret = esp_bluedroid_init()) != ESP_OK) { - ESP_LOGE(TAG, "initialize bluedroid failed: %s", esp_err_to_name(ret)); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { + ESP_LOGE(TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } @@ -458,7 +462,7 @@ void app_main(void) ESP_LOGI(TAG, "starting hid device"); esp_bt_hid_device_init(); -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* Set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_NONE; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/Kconfig.projbuild b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/Kconfig.projbuild new file mode 100644 index 0000000000..abc0e748ce --- /dev/null +++ b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "L2CAP Example Configuration" + config EXAMPLE_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing +endmenu diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/main.c index 538673f044..610a3b3bba 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -176,7 +176,7 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* when Security Simple Pairing user confirmation requested, this event comes */ case ESP_BT_GAP_CFM_REQ_EVT: ESP_LOGI(L2CAP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); @@ -402,7 +402,11 @@ void app_main(void) return; } - if ((ret = esp_bluedroid_init()) != ESP_OK) { + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { ESP_LOGE(L2CAP_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } @@ -439,7 +443,7 @@ void app_main(void) return; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* Set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/tutorial/example_workflow.md b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/tutorial/example_workflow.md index c8fbfaa367..93e91742cf 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/tutorial/example_workflow.md +++ b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_client/tutorial/example_workflow.md @@ -5,28 +5,28 @@ This document describes the process of L2CAP initialization, connection, and dat ## Initialization Process -
+
-The `BT_Profile_StackA` and `BT_Profile_StackB` in the above diagram represent the same Bluetooth protocol stacks (GAP, SDP, L2CAP in this example). StackA and StackB are to distinguish which device is interacting with the protocol stack. -Both projects `BT_L2CAP_Server`([bt_l2cap_server](../../bt_l2cap_server)) and `BT_L2CAP_Client` have the same initialization process but are independent of each other. The entry point to the example is the `app_main()` function, and the main function starts by initializing the non-volatile storage library. Then, the L2CAP initialization both the `Server` and `Client` can be divided into the following steps: -- Step1: esp_bt_controller_init() +The `BT_Profile_StackA` and `BT_Profile_StackB` in the above diagram represent the same Bluetooth protocol stacks (GAP, SDP, L2CAP in this example). StackA and StackB are to distinguish which device is interacting with the protocol stack. +Both projects `BT_L2CAP_Server`([bt_l2cap_server](../../bt_l2cap_server)) and `BT_L2CAP_Client` have the same initialization process but are independent of each other. The entry point to the example is the `app_main()` function, and the main function starts by initializing the non-volatile storage library. Then, the L2CAP initialization both the `Server` and `Client` can be divided into the following steps: +- Step1: esp_bt_controller_init() - Step2: esp_bt_controller_enable() -- Step3: esp_bluedroid_init() +- Step3: esp_bluedroid_init_with_cfg() - Step4: esp_bluedroid_enable() -- Step5: esp_bt_gap_register_callback() +- Step5: esp_bt_gap_register_callback() ## Connection Process
-Step `6` is the setting phase of L2CAP. There are two alternative paths: one for the server's L2CAP setup and the other for the client's L2CAP setup. +Step `6` is the setting phase of L2CAP. There are two alternative paths: one for the server's L2CAP setup and the other for the client's L2CAP setup. - In the server path: - The L2CAP callback is registered by calling `esp_bt_l2cap_register_callback()`. - The `Server` performs the L2CAP initialization by calling the `esp_bt_l2cap_init()` function, and an asynchronous callback event `ESP_BT_L2CAP_INIT_EVT` is returned to indicate the initialization completion. - Then the `Server` proceeds to register the virtual file system using `esp_bt_l2cap_vfs_register()` and starts the server using function `esp_bt_l2cap_start_srv()`. The asynchronous callback event `ESP_BT_L2CAP_START_EVT` is also returned to indicate the server's start completion. -- In the client path: +- In the client path: - Compared with the server's path, the client path also calls functions `esp_bt_l2cap_register_callback()`, `esp_bt_l2cap_init()` and `esp_bt_l2cap_vfs_register()` to register L2CAP callback, initiate the L2CAP and register the the virtual file system. But the client does not need to start the service. Step `7` in sequence diagram is the setting of SDP and process of service discovery. Similar to the L2CAP setup, there are separate paths for `Server` and `Client`. @@ -34,10 +34,10 @@ Step `7` in sequence diagram is the setting of SDP and process of service discov - The SDP callback is registered by calling `esp_sdp_register_callback()`. - The `Server` initiates SDP by calling `esp_sdp_init()`, and the asynchronous callback event `ESP_SDP_INIT_EVT` is returned to indicate the initialization completion. - Then the `Server` creates an SDP record by calling `esp_sdp_create_record()`, and an asynchronous callback event `ESP_SDP_CREATE_RECORD_COMP_EVT` is returned to indicate the completion of the record creation. - - The `Server` can also set the device name by calling `esp_bt_dev_set_device_name()` and make itself connectable and discoverable by calling `esp_bt_gap_set_scan_mode()`. + - The `Server` can also set the device name by calling `esp_bt_dev_set_device_name()` and make itself connectable and discoverable by calling `esp_bt_gap_set_scan_mode()`. - In the client path: - The `Client` also calls functions `esp_sdp_register_callback()`, `esp_sdp_init()`, `esp_sdp_create_record()`, `esp_bt_dev_set_device_name()` and `esp_bt_gap_set_scan_mode()` to register SDP callback, initiate the SDP, create sdp record, set device name and set the scan mode. - - Additionally, the `Client` calls `esp_bt_gap_start_discovery()` to start `Inquiry`. When the `Inquiry` process is completed, the asynchronous callback event `ESP_BT_GAP_DISC_RES_EVT` will be returned. + - Additionally, the `Client` calls `esp_bt_gap_start_discovery()` to start `Inquiry`. When the `Inquiry` process is completed, the asynchronous callback event `ESP_BT_GAP_DISC_RES_EVT` will be returned. Once the event `ESP_BT_GAP_DISC_RES_EVT` is returned, the `Client` will try to make a L2CAP connection to the `BD Address` of `Server` by calling function `esp_bt_connect()` in step `8`. diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/Kconfig.projbuild b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/Kconfig.projbuild new file mode 100644 index 0000000000..abc0e748ce --- /dev/null +++ b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "L2CAP Example Configuration" + config EXAMPLE_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing +endmenu diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/main.c index fc03fb76d4..86d4dc020e 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_l2cap_server/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -90,7 +90,7 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* when Security Simple Pairing user confirmation requested, this event comes */ case ESP_BT_GAP_CFM_REQ_EVT: ESP_LOGI(L2CAP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); @@ -305,7 +305,11 @@ void app_main(void) return; } - if ((ret = esp_bluedroid_init()) != ESP_OK) { + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { ESP_LOGE(L2CAP_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } @@ -342,7 +346,7 @@ void app_main(void) return; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* Set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/README.md b/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/README.md index 340ed259c9..c291f8469f 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/README.md +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/README.md @@ -30,9 +30,9 @@ and `Component config --> Bluetooth --> Bluetooth --> Bluetooth controller --> BR/EDR ACL Max Connections` -4. SSP is enabled as default in this example. If you prefer the legacy pairing, you can disable it in the following path. +4. SSP is enabled as default in this example. If you prefer the legacy pairing, you shall disable it in the following path. -`Component config --> Bluetooth--> Bluedroid Options --> Secure Simple Pair`. +`SPP Example Configuration --> Secure Simple Pair`. ### Build and Flash diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/Kconfig.projbuild b/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/Kconfig.projbuild new file mode 100644 index 0000000000..971b124cfc --- /dev/null +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "SPP Example Configuration" + config EXAMPLE_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing +endmenu diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/main.c index 617e67f569..c56b82b985 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -174,7 +174,7 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) break; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) case ESP_BT_GAP_CFM_REQ_EVT: ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true); @@ -223,16 +223,15 @@ void app_main(void) return; } - if ((ret = esp_bluedroid_init()) != ESP_OK) { + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { ESP_LOGE(SPP_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } - if ((ret = esp_bluedroid_enable()) != ESP_OK) { - ESP_LOGE(SPP_TAG, "%s enable bluedroid failed: %s", __func__, esp_err_to_name(ret)); - return; - } - if ((ret = esp_bt_gap_register_callback(esp_bt_gap_cb)) != ESP_OK) { ESP_LOGE(SPP_TAG, "%s gap register failed: %s", __func__, esp_err_to_name(ret)); return; @@ -253,7 +252,7 @@ void app_main(void) return; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* Set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/README.md b/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/README.md index 544c2a1dfc..f6c15b3a06 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/README.md +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/README.md @@ -21,9 +21,9 @@ idf.py menuconfig `Component config --> Bluetooth --> Bluedroid Options --> SPP`. -3. SSP is enabled as default in this example. If you prefer the legacy pairing, you can disable it in the following path. +3. SSP is enabled as default in this example. If you prefer the legacy pairing, you shall disable it in the following path. -`Component config --> Bluetooth--> Bluedroid Options --> Secure Simple Pair`. +`SPP Example Configuration --> Secure Simple Pair`. ### Build and Flash @@ -76,7 +76,7 @@ The log in terminal will indicate you to input the passkey to initiate the conne ``` I (2244) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT -I (2244) SPP_INITIATOR_DEMO: ...... +I (2244) SPP_INITIATOR_DEMO: ...... I (2394) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT I (2404) SPP_INITIATOR_DEMO: ...... I (2404) SPP_INITIATOR_DEMO: ESP_SPP_ACCEPTOR @@ -93,7 +93,7 @@ The log in terminal will indicate you to confirm the number to initiate the conn ``` I (2342) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_RES_EVT -I (2342) SPP_INITIATOR_DEMO: 30 ae a4 80 18 32 +I (2342) SPP_INITIATOR_DEMO: 30 ae a4 80 18 32 I (2342) SPP_INITIATOR_DEMO: ESP_SPP_ACCEPTOR I (2352) SPP_INITIATOR_DEMO: ESP_BT_GAP_DISC_STATE_CHANGED_EVT I (3212) SPP_INITIATOR_DEMO: ESP_SPP_DISCOVERY_COMP_EVT status=0 scn_num=1 diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/Kconfig.projbuild b/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/Kconfig.projbuild new file mode 100644 index 0000000000..971b124cfc --- /dev/null +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "SPP Example Configuration" + config EXAMPLE_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing +endmenu diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/main.c index 137847f68b..c7e4c6f30b 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -302,7 +302,7 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) case ESP_BT_GAP_CFM_REQ_EVT: ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); ESP_LOGW(SPP_TAG, "To confirm the value, type `spp ok;`"); @@ -355,7 +355,11 @@ void app_main(void) return; } - if ((ret = esp_bluedroid_init()) != ESP_OK) { + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { ESP_LOGE(SPP_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } @@ -370,7 +374,7 @@ void app_main(void) return; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* Set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IN; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/README.md b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/README.md index 615f557c72..d13d4ce63e 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/README.md +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/README.md @@ -30,9 +30,9 @@ and `Component config --> Bluetooth --> Bluetooth --> Bluetooth controller --> BR/EDR ACL Max Connections` -4. SSP is enabled as default in this example. If you prefer the legacy pairing, you can disable it in the following path. +4. SSP is enabled as default in this example. If you prefer the legacy pairing, you shall disable it in the following path. -`Component config --> Bluetooth--> Bluedroid Options --> Secure Simple Pair`. +`SPP Example Configuration --> Secure Simple Pair`. ### Build and Flash diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/Kconfig.projbuild b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/Kconfig.projbuild new file mode 100644 index 0000000000..971b124cfc --- /dev/null +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "SPP Example Configuration" + config EXAMPLE_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing +endmenu diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/main.c index 3c124d1bef..4aee8ee354 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_acceptor/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -186,7 +186,7 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) break; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) case ESP_BT_GAP_CFM_REQ_EVT: ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true); @@ -234,8 +234,12 @@ void app_main(void) return; } - if (esp_bluedroid_init() != ESP_OK) { - ESP_LOGE(SPP_TAG, "%s initialize bluedroid failed", __func__); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { + ESP_LOGE(SPP_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } @@ -244,7 +248,7 @@ void app_main(void) return; } - if (esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) { + if ((ret = esp_bt_gap_register_callback(esp_bt_gap_cb)) != ESP_OK) { ESP_LOGE(SPP_TAG, "%s gap register failed: %s", __func__, esp_err_to_name(ret)); return; } @@ -262,7 +266,7 @@ void app_main(void) return; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* Set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/README.md b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/README.md index 67f30933e5..c8b1dc8274 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/README.md +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/README.md @@ -21,10 +21,9 @@ idf.py menuconfig `Component config --> Bluetooth --> Bluedroid Options --> SPP`. -3. SSP is enabled as default in this example. If you prefer the legacy pairing, you can disable it in the following path. - -`Component config --> Bluetooth--> Bluedroid Options --> Secure Simple Pair`. +3. SSP is enabled as default in this example. If you prefer the legacy pairing, you shall disable it in the following path. +`SPP Example Configuration --> Secure Simple Pair`. ### Build and Flash diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/Kconfig.projbuild b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/Kconfig.projbuild new file mode 100644 index 0000000000..971b124cfc --- /dev/null +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "SPP Example Configuration" + config EXAMPLE_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing +endmenu diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/main.c index 491bfeecb6..71947b8870 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_spp_vfs_initiator/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -264,7 +264,7 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) case ESP_BT_GAP_CFM_REQ_EVT: ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true); @@ -317,8 +317,12 @@ void app_main(void) return; } - if (esp_bluedroid_init() != ESP_OK) { - ESP_LOGE(SPP_TAG, "%s initialize bluedroid failed", __func__); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { + ESP_LOGE(SPP_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } @@ -345,7 +349,7 @@ void app_main(void) return; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) /* Set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/main.c b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/main.c index 4d6cc06462..38e4d0632c 100644 --- a/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -82,21 +82,21 @@ void app_main(void) ESP_ERROR_CHECK(ret); ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_BLE)); - esp_err_t err; esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); - if ((err = esp_bt_controller_init(&bt_cfg)) != ESP_OK) { + if ((ret = esp_bt_controller_init(&bt_cfg)) != ESP_OK) { ESP_LOGE(BT_HF_TAG, "%s initialize controller failed: %s", __func__, esp_err_to_name(ret)); return; } - if ((err = esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT)) != ESP_OK) { + if ((ret = esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT)) != ESP_OK) { ESP_LOGE(BT_HF_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret)); return; } - if ((err = esp_bluedroid_init()) != ESP_OK) { + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { ESP_LOGE(BT_HF_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } - if ((err = esp_bluedroid_enable()) != ESP_OK) { + if ((ret = esp_bluedroid_enable()) != ESP_OK) { ESP_LOGE(BT_HF_TAG, "%s enable bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/Kconfig.projbuild b/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/Kconfig.projbuild new file mode 100644 index 0000000000..0b1569390f --- /dev/null +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "HFP Example Configuration" + config EXAMPLE_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing +endmenu diff --git a/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/main.c b/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/main.c index 6842b5bbe6..ffb3d6d63b 100644 --- a/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/hfp_hf/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -116,7 +116,7 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param) break; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) case ESP_BT_GAP_CFM_REQ_EVT: ESP_LOGI(BT_HF_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true); @@ -161,24 +161,27 @@ void app_main(void) ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_BLE)); - esp_err_t err; esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); - if ((err = esp_bt_controller_init(&bt_cfg)) != ESP_OK) { + if ((ret = esp_bt_controller_init(&bt_cfg)) != ESP_OK) { ESP_LOGE(BT_HF_TAG, "%s initialize controller failed: %s", __func__, esp_err_to_name(ret)); return; } - if ((err = esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT)) != ESP_OK) { + if ((ret = esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT)) != ESP_OK) { ESP_LOGE(BT_HF_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret)); return; } - if ((err = esp_bluedroid_init()) != ESP_OK) { + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { ESP_LOGE(BT_HF_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } - if ((err = esp_bluedroid_enable()) != ESP_OK) { + if ((ret = esp_bluedroid_enable()) != ESP_OK) { ESP_LOGE(BT_HF_TAG, "%s enable bluedroid failed: %s", __func__, esp_err_to_name(ret)); return; } @@ -236,6 +239,13 @@ static void bt_hf_client_hdl_stack_evt(uint16_t event, void *p_param) esp_hf_client_register_callback(bt_app_hf_client_cb); esp_hf_client_init(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) + /* Set default parameters for Secure Simple Pairing */ + esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; + esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; + esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t)); +#endif + esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_FIXED; esp_bt_pin_code_t pin_code; pin_code[0] = '0'; diff --git a/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/Kconfig.projbuild b/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/Kconfig.projbuild index 67f53d5ded..ce29dd6c03 100644 --- a/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/Kconfig.projbuild +++ b/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/Kconfig.projbuild @@ -1,4 +1,11 @@ menu "A2DP Example Configuration" + config EXAMPLE_A2DP_SINK_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing choice EXAMPLE_A2DP_SINK_OUTPUT prompt "A2DP Sink Output" diff --git a/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c b/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c index 166435aecb..87f5a82f4a 100644 --- a/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c +++ b/examples/bluetooth/bluedroid/coex/a2dp_gatts_coex/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -634,7 +634,7 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa break; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_A2DP_SINK_SSP_ENABLED == true) /* when Security Simple Pairing user confirmation requested, this event comes */ case ESP_BT_GAP_CFM_REQ_EVT: ESP_LOGI(BT_BLE_COEX_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); @@ -718,20 +718,27 @@ void app_main(void) ESP_LOGE(BT_BLE_COEX_TAG, "%s initialize controller failed: %s", __func__, esp_err_to_name(err)); return; } + if ((err = esp_bt_controller_enable(ESP_BT_MODE_BTDM)) != ESP_OK) { ESP_LOGE(BT_BLE_COEX_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(err)); return; } - if ((err = esp_bluedroid_init()) != ESP_OK) { + + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_A2DP_SINK_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + if ((err = esp_bluedroid_init_with_cfg(&bluedroid_cfg)) != ESP_OK) { ESP_LOGE(BT_BLE_COEX_TAG, "%s initialize bluedroid failed: %s", __func__, esp_err_to_name(err)); return; } + if ((err = esp_bluedroid_enable()) != ESP_OK) { ESP_LOGE(BT_BLE_COEX_TAG, "%s enable bluedroid failed: %s", __func__, esp_err_to_name(err)); return; } -#if (CONFIG_BT_SSP_ENABLED == true) +#if (CONFIG_EXAMPLE_A2DP_SINK_SSP_ENABLED == true) /* set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; diff --git a/examples/bluetooth/bluedroid/coex/gattc_gatts_coex/main/gattc_gatts_coex.c b/examples/bluetooth/bluedroid/coex/gattc_gatts_coex/main/gattc_gatts_coex.c index 724b2a242c..89e0136baa 100644 --- a/examples/bluetooth/bluedroid/coex/gattc_gatts_coex/main/gattc_gatts_coex.c +++ b/examples/bluetooth/bluedroid/coex/gattc_gatts_coex/main/gattc_gatts_coex.c @@ -983,7 +983,8 @@ void app_main(void) return; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(COEX_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret)); return; diff --git a/examples/bluetooth/blufi/main/blufi_init.c b/examples/bluetooth/blufi/main/blufi_init.c index 378344e422..147876ea39 100644 --- a/examples/bluetooth/blufi/main/blufi_init.c +++ b/examples/bluetooth/blufi/main/blufi_init.c @@ -30,7 +30,8 @@ esp_err_t esp_blufi_host_init(void) { int ret; - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { BLUFI_ERROR("%s init bluedroid failed: %s\n", __func__, esp_err_to_name(ret)); return ESP_FAIL; diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_coex_test/components/case/ble_unit.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_coex_test/components/case/ble_unit.c index 38479d33f4..eb2ff48068 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_coex_test/components/case/ble_unit.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_coex_test/components/case/ble_unit.c @@ -241,7 +241,8 @@ void bt_test_init(void) esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg)); ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE)); - ESP_ERROR_CHECK(esp_bluedroid_init()); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ESP_ERROR_CHECK(esp_bluedroid_init_with_cfg(&bluedroid_cfg)); ESP_ERROR_CHECK(esp_bluedroid_enable()); } diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/tutorial/BLE_Mesh_WiFi_Coexist_Example_Walkthrough.md b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/tutorial/BLE_Mesh_WiFi_Coexist_Example_Walkthrough.md index 6d1671c4da..ea61c88493 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/tutorial/BLE_Mesh_WiFi_Coexist_Example_Walkthrough.md +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/tutorial/BLE_Mesh_WiFi_Coexist_Example_Walkthrough.md @@ -172,8 +172,9 @@ This demo calls the `bluetooth_init` function to: After the initialization of the BT controller, the Bluedroid stack, which includes the common definitions and APIs for both BT Classic and BLE, is initialized and enabled by using: - ```c - ret = esp_bluedroid_init(); + ``` + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); ret = esp_bluedroid_enable(); ``` diff --git a/examples/bluetooth/esp_ble_mesh/common_components/example_init/ble_mesh_example_init.c b/examples/bluetooth/esp_ble_mesh/common_components/example_init/ble_mesh_example_init.c index 93155523e1..bcb6e348f2 100644 --- a/examples/bluetooth/esp_ble_mesh/common_components/example_init/ble_mesh_example_init.c +++ b/examples/bluetooth/esp_ble_mesh/common_components/example_init/ble_mesh_example_init.c @@ -61,7 +61,8 @@ esp_err_t bluetooth_init(void) ESP_LOGE(TAG, "%s enable controller failed", __func__); return ret; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(TAG, "%s init bluetooth failed", __func__); return ret; diff --git a/examples/bluetooth/esp_hid_device/main/Kconfig.projbuild b/examples/bluetooth/esp_hid_device/main/Kconfig.projbuild new file mode 100644 index 0000000000..568ef5ae62 --- /dev/null +++ b/examples/bluetooth/esp_hid_device/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "HID Example Configuration" + config EXAMPLE_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing +endmenu diff --git a/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c b/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c index da553932b2..f47933be25 100644 --- a/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c +++ b/examples/bluetooth/esp_hid_device/main/esp_hid_gap.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -397,9 +397,37 @@ static void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_para handle_bt_device_result(¶m->disc_res); break; } - case ESP_BT_GAP_KEY_NOTIF_EVT: - ESP_LOGI(TAG, "BT GAP KEY_NOTIF passkey:%"PRIu32, param->key_notif.passkey); + case ESP_BT_GAP_PIN_REQ_EVT: { + ESP_LOGI(TAG, "BT GAP PIN_REQ_EVT min_16_digit:%d", param->pin_req.min_16_digit); + if (param->pin_req.min_16_digit) { + ESP_LOGI(TAG, "Input pin code: 0000 0000 0000 0000"); + esp_bt_pin_code_t pin_code = {0}; + esp_bt_gap_pin_reply(param->pin_req.bda, true, 16, pin_code); + } else { + ESP_LOGI(TAG, "Input pin code: 1234"); + esp_bt_pin_code_t pin_code; + pin_code[0] = '1'; + pin_code[1] = '2'; + pin_code[2] = '3'; + pin_code[3] = '4'; + esp_bt_gap_pin_reply(param->pin_req.bda, true, 4, pin_code); + } break; + } + +#if (CONFIG_EXAMPLE_SSP_ENABLED == true) + case ESP_BT_GAP_CFM_REQ_EVT: + ESP_LOGI(TAG, "BT GAP CFM_REQ_EVT Please compare the numeric value: %" PRIu32, + param->cfm_req.num_val); + esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true); + break; + case ESP_BT_GAP_KEY_NOTIF_EVT: + ESP_LOGI(TAG, "BT GAP KEY_NOTIF_EVT passkey:%" PRIu32, param->key_notif.passkey); + break; + case ESP_BT_GAP_KEY_REQ_EVT: + ESP_LOGI(TAG, "BT GAP KEY_REQ_EVT Please enter passkey!"); + break; +#endif case ESP_BT_GAP_MODE_CHG_EVT: ESP_LOGI(TAG, "BT GAP MODE_CHG_EVT mode:%d", param->mode_chg.mode); break; @@ -412,7 +440,7 @@ static void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_para static esp_err_t init_bt_gap(void) { esp_err_t ret; -#if (CONFIG_BT_SSP_ENABLED) +#if (CONFIG_EXAMPLE_SSP_ENABLED) /* Set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_NONE; @@ -714,7 +742,11 @@ static esp_err_t init_low_level(uint8_t mode) return ret; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(TAG, "esp_bluedroid_init failed: %d", ret); return ret; diff --git a/examples/bluetooth/esp_hid_host/main/Kconfig.projbuild b/examples/bluetooth/esp_hid_host/main/Kconfig.projbuild new file mode 100644 index 0000000000..568ef5ae62 --- /dev/null +++ b/examples/bluetooth/esp_hid_host/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "HID Example Configuration" + config EXAMPLE_SSP_ENABLED + bool "Secure Simple Pairing" + depends on BT_CLASSIC_ENABLED + default y + help + This enables the Secure Simple Pairing. If disable this option, + Bluedroid will only support Legacy Pairing +endmenu diff --git a/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c b/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c index c9804ef787..ca16f6191f 100644 --- a/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c +++ b/examples/bluetooth/esp_hid_host/main/esp_hid_gap.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -400,21 +400,24 @@ static void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_para handle_bt_device_result(¶m->disc_res); break; } -#if (CONFIG_BT_SSP_ENABLED) +#if (CONFIG_EXAMPLE_SSP_ENABLED) case ESP_BT_GAP_KEY_NOTIF_EVT: ESP_LOGI(TAG, "BT GAP KEY_NOTIF passkey:%"PRIu32, param->key_notif.passkey); break; case ESP_BT_GAP_CFM_REQ_EVT: { - ESP_LOGI(TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); + ESP_LOGI(TAG, "BT GAP CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val); esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true); break; } + case ESP_BT_GAP_KEY_REQ_EVT: + ESP_LOGI(TAG, "BT GAP KEY_REQ_EVT Please enter passkey!"); + break; #endif case ESP_BT_GAP_MODE_CHG_EVT: ESP_LOGI(TAG, "BT GAP MODE_CHG_EVT mode:%d", param->mode_chg.mode); break; case ESP_BT_GAP_PIN_REQ_EVT: { - ESP_LOGI(TAG, "ESP_BT_GAP_PIN_REQ_EVT min_16_digit:%d", param->pin_req.min_16_digit); + ESP_LOGI(TAG, "BT GAP PIN_REQ_EVT min_16_digit:%d", param->pin_req.min_16_digit); if (param->pin_req.min_16_digit) { ESP_LOGI(TAG, "Input pin code: 0000 0000 0000 0000"); esp_bt_pin_code_t pin_code = {0}; @@ -439,7 +442,7 @@ static void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_para static esp_err_t init_bt_gap(void) { esp_err_t ret; -#if (CONFIG_BT_SSP_ENABLED) +#if (CONFIG_EXAMPLE_SSP_ENABLED) /* Set default parameters for Secure Simple Pairing */ esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE; esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO; @@ -737,7 +740,11 @@ static esp_err_t init_low_level(uint8_t mode) return ret; } - ret = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); +#if (CONFIG_EXAMPLE_SSP_ENABLED == false) + bluedroid_cfg.ssp_en = false; +#endif + ret = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (ret) { ESP_LOGE(TAG, "esp_bluedroid_init failed: %d", ret); return ret; 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 af9ee1f876..02b0375f84 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 @@ -36,7 +36,8 @@ esp_err_t esp_ble_helper_init(void) ESP_LOGE(TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(err)); return err; } - err = esp_bluedroid_init(); + esp_bluedroid_config_t bluedroid_cfg = BT_BLUEDROID_INIT_CONFIG_DEFAULT(); + err = esp_bluedroid_init_with_cfg(&bluedroid_cfg); if (err) { ESP_LOGE(TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(err)); return err;