mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
component/bt: Add Secure Simple Pairing
This commit is contained in:
@@ -42,7 +42,7 @@
|
||||
|
||||
static const esp_spp_mode_t esp_spp_mode = ESP_SPP_MODE_VFS;
|
||||
|
||||
static const esp_spp_sec_t sec_mask = ESP_SPP_SEC_NONE;
|
||||
static const esp_spp_sec_t sec_mask = ESP_SPP_SEC_AUTHENTICATE;
|
||||
static const esp_spp_role_t role_slave = ESP_SPP_ROLE_SLAVE;
|
||||
|
||||
#define SPP_DATA_LEN 100
|
||||
@@ -105,6 +105,38 @@ static void esp_spp_stack_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param
|
||||
spp_task_work_dispatch((spp_task_cb_t)esp_spp_cb, event, param, sizeof(esp_spp_cb_param_t), NULL);
|
||||
}
|
||||
|
||||
void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
|
||||
{
|
||||
switch (event) {
|
||||
#if (BT_SPP_INCLUDED)
|
||||
case ESP_BT_GAP_AUTH_CMPL_EVT:{
|
||||
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGI(SPP_TAG, "authentication success: %s", param->auth_cmpl.device_name);
|
||||
esp_log_buffer_hex(SPP_TAG, param->auth_cmpl.bda, ESP_BD_ADDR_LEN);
|
||||
} else {
|
||||
ESP_LOGE(SPP_TAG, "authentication failed, status:%d", param->auth_cmpl.stat);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ESP_BT_GAP_CFM_REQ_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %d", 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(SPP_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%d", param->key_notif.passkey);
|
||||
break;
|
||||
case ESP_BT_GAP_KEY_REQ_EVT:
|
||||
ESP_LOGI(SPP_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
|
||||
break;
|
||||
#endif ///BT_SPP_INCLUDED
|
||||
default: {
|
||||
ESP_LOGI(SPP_TAG, "event: %d", event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
@@ -135,6 +167,11 @@ void app_main()
|
||||
return;
|
||||
}
|
||||
|
||||
if (esp_bt_gap_register_callback(esp_bt_gap_cb) != ESP_OK) {
|
||||
ESP_LOGE(SPP_TAG, "%s gap register failed: %s\n", __func__, esp_err_to_name(ret));
|
||||
return;
|
||||
}
|
||||
|
||||
if (esp_spp_register_callback(esp_spp_stack_cb) != ESP_OK) {
|
||||
ESP_LOGE(SPP_TAG, "%s spp register failed", __func__);
|
||||
return;
|
||||
@@ -146,5 +183,11 @@ void app_main()
|
||||
ESP_LOGE(SPP_TAG, "%s spp init failed", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
#if (BT_SPP_INCLUDED)
|
||||
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 ///BT_SPP_INCLUDED
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user