Skip to content

Commit fc6f5cf

Browse files
committed
feat(bt): Initialize the SC during the bluedroid initialization
1 parent 081de6d commit fc6f5cf

File tree

8 files changed

+47
-19
lines changed

8 files changed

+47
-19
lines changed

components/bt/controller/lib_esp32

components/bt/host/bluedroid/api/esp_bt_main.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -128,6 +128,21 @@ esp_err_t esp_bluedroid_init_with_cfg(esp_bluedroid_config_t *cfg)
128128
return ESP_ERR_INVALID_ARG;
129129
}
130130

131+
if (cfg->sc_en) {
132+
#if (SC_MODE_INCLUDED == FALSE)
133+
LOG_ERROR("Secure Connections should not be enabled when target controller is ESP32.\n");
134+
LOG_ERROR("It may trigger unresolved bugs in the controller.\n");
135+
return ESP_ERR_INVALID_ARG;
136+
#endif // SC_MODE_INCLUDED
137+
138+
if (!cfg->ssp_en) {
139+
LOG_ERROR("secure simple pairing should be enabled when secure connection host support is enabled\n");
140+
return ESP_ERR_INVALID_ARG;
141+
}
142+
143+
LOG_WARN("Please make sure to clear the bond list before enabling the secure connection host support\n");
144+
}
145+
131146
#if (BT_CONTROLLER_INCLUDED == TRUE)
132147
if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) {
133148
LOG_ERROR("Controller not initialised\n");
@@ -144,7 +159,7 @@ esp_err_t esp_bluedroid_init_with_cfg(esp_bluedroid_config_t *cfg)
144159
osi_mem_dbg_init();
145160
#endif
146161

147-
ret = bluedriod_config_init(cfg);
162+
ret = bluedroid_config_init(cfg);
148163
if (ret != BT_STATUS_SUCCESS) {
149164
LOG_ERROR("Bluedroid stack initialize fail, ret:%d", ret);
150165
return ESP_FAIL;
@@ -228,7 +243,7 @@ esp_err_t esp_bluedroid_deinit(void)
228243

229244
btc_deinit();
230245

231-
bluedriod_config_deinit();
246+
bluedroid_config_deinit();
232247

233248
#if (BT_HCI_LOG_INCLUDED == TRUE)
234249
bt_hci_log_deinit();

components/bt/host/bluedroid/api/esp_gap_bt_api.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ esp_err_t esp_bt_gap_set_security_param(esp_bt_sp_param_t param_type,
322322
return ESP_ERR_INVALID_STATE;
323323
}
324324

325-
if (!(bluedriod_config_get()->get_ssp_enabled())) {
325+
if (!(bluedroid_config_get()->get_ssp_enabled())) {
326326
ESP_LOGE(TAG, "%s is not supported when `ssp_en` in `esp_bluedroid_config_t` is disabled!", __func__);
327327
return ESP_ERR_NOT_SUPPORTED;
328328
}
@@ -347,7 +347,7 @@ esp_err_t esp_bt_gap_ssp_passkey_reply(esp_bd_addr_t bd_addr, bool accept, uint3
347347
return ESP_ERR_INVALID_STATE;
348348
}
349349

350-
if (!(bluedriod_config_get()->get_ssp_enabled())) {
350+
if (!(bluedroid_config_get()->get_ssp_enabled())) {
351351
ESP_LOGE(TAG, "%s is not supported when `ssp_en` in `esp_bluedroid_config_t` is disabled!", __func__);
352352
return ESP_ERR_NOT_SUPPORTED;
353353
}
@@ -371,7 +371,7 @@ esp_err_t esp_bt_gap_ssp_confirm_reply(esp_bd_addr_t bd_addr, bool accept)
371371
return ESP_ERR_INVALID_STATE;
372372
}
373373

374-
if (!(bluedriod_config_get()->get_ssp_enabled())) {
374+
if (!(bluedroid_config_get()->get_ssp_enabled())) {
375375
ESP_LOGE(TAG, "%s is not supported when `ssp_en` in `esp_bluedroid_config_t` is disabled!", __func__);
376376
return ESP_ERR_NOT_SUPPORTED;
377377
}

components/bt/host/bluedroid/api/include/api/esp_bt_main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ typedef enum {
3030
*/
3131
typedef struct {
3232
bool ssp_en; /*!< Whether SSP(secure simple pairing) or legacy pairing is used for Classic Bluetooth */
33+
bool sc_en; /*!< Whether secure connection host support is enabled or disabled for Classic Bluetooth */
3334
} esp_bluedroid_config_t;
3435

3536
#define BT_BLUEDROID_INIT_CONFIG_DEFAULT() \
3637
{ \
3738
.ssp_en = true, \
39+
.sc_en = false, \
3840
}
3941

4042
/**

components/bt/host/bluedroid/common/include/common/bt_target.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,10 +1339,12 @@
13391339
**************************/
13401340

13411341
/* 4.1/4.2 secure connections feature */
1342-
#ifndef SC_MODE_INCLUDED
1343-
// Disable AES-CCM (BT 4.1) for BT Classic to workaround controller AES issue. E0 encryption (BT 4.0) will be used.
1342+
#if defined(CONFIG_IDF_TARGET_ESP32) && (BT_CONTROLLER_INCLUDED == TRUE)
1343+
// Disable AES-CCM (BT 4.1) for BT Classic to workaround controller AES issue on ESP32 controller. E0 encryption (BT 4.0) will be used.
13441344
#define SC_MODE_INCLUDED FALSE
1345-
#endif
1345+
#else
1346+
#define SC_MODE_INCLUDED TRUE
1347+
#endif // CONFIG_IDF_TARGET_ESP32
13461348

13471349
/* Used for conformance testing ONLY */
13481350
#ifndef BTM_BLE_CONFORMANCE_TESTING

components/bt/host/bluedroid/config/include/config/stack_config.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212

1313
struct bluedroid_config {
1414
bool (*get_ssp_enabled)(void);
15+
bool (*get_sc_enabled) (void);
1516
};
1617

17-
bt_status_t bluedriod_config_init(esp_bluedroid_config_t *cfg);
18+
bt_status_t bluedroid_config_init(esp_bluedroid_config_t *cfg);
1819

19-
void bluedriod_config_deinit(void);
20+
void bluedroid_config_deinit(void);
2021

21-
const struct bluedroid_config *bluedriod_config_get(void);
22+
const struct bluedroid_config *bluedroid_config_get(void);

components/bt/host/bluedroid/config/stack_config.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ static bool get_ssp_enabled(void)
2525
return cfg->ssp_en;
2626
}
2727

28-
bt_status_t bluedriod_config_init(esp_bluedroid_config_t *cfg)
28+
static bool get_sc_enabled(void)
29+
{
30+
assert(s_stack_config_env);
31+
esp_bluedroid_config_t *cfg = &s_stack_config_env->cfg;
32+
return cfg->sc_en;
33+
}
34+
35+
bt_status_t bluedroid_config_init(esp_bluedroid_config_t *cfg)
2936
{
3037
s_stack_config_env = osi_calloc(sizeof(struct stack_config_env_tag));
3138
if (!s_stack_config_env) {
@@ -36,19 +43,20 @@ bt_status_t bluedriod_config_init(esp_bluedroid_config_t *cfg)
3643

3744
struct bluedroid_config *interface = &s_stack_config_env->interface;
3845
interface->get_ssp_enabled = get_ssp_enabled;
46+
interface->get_sc_enabled = get_sc_enabled;
3947

4048
return BT_STATUS_SUCCESS;
4149
}
4250

43-
void bluedriod_config_deinit(void)
51+
void bluedroid_config_deinit(void)
4452
{
4553
if (s_stack_config_env) {
4654
osi_free(s_stack_config_env);
4755
s_stack_config_env = NULL;
4856
}
4957
}
5058

51-
const struct bluedroid_config *bluedriod_config_get(void)
59+
const struct bluedroid_config *bluedroid_config_get(void)
5260
{
5361
assert(s_stack_config_env);
5462
return &s_stack_config_env->interface;

components/bt/host/bluedroid/device/controller.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static void start_up(void)
188188
// dependent on what we configure from page 0 and host SSP configuration
189189
controller_param.simple_pairing_supported = HCI_SIMPLE_PAIRING_SUPPORTED(
190190
controller_param.features_classic[0].as_array) &&
191-
(bluedriod_config_get()->get_ssp_enabled());
191+
(bluedroid_config_get()->get_ssp_enabled());
192192
if (controller_param.simple_pairing_supported) {
193193
response = AWAIT_COMMAND(controller_param.packet_factory->make_write_simple_pairing_mode(HCI_SP_MODE_ENABLED));
194194
controller_param.packet_parser->parse_generic_command_complete(response);
@@ -223,13 +223,13 @@ static void start_up(void)
223223
}
224224
#endif
225225

226-
#if (SC_MODE_INCLUDED == TRUE)
226+
if ((bluedroid_config_get()->get_sc_enabled())) {
227227
controller_param.secure_connections_supported = HCI_SC_CTRLR_SUPPORTED(controller_param.features_classic[2].as_array);
228228
if (controller_param.secure_connections_supported) {
229229
response = AWAIT_COMMAND(controller_param.packet_factory->make_write_secure_connections_host_support(HCI_SC_MODE_ENABLED));
230230
controller_param.packet_parser->parse_generic_command_complete(response);
231231
}
232-
#endif
232+
}
233233

234234
#if (BLE_INCLUDED == TRUE)
235235
#if (CLASSIC_BT_INCLUDED)

0 commit comments

Comments
 (0)