|
|
@@ -240,6 +240,9 @@ static char *esp_auth_req_to_str(esp_ble_auth_req_t auth_req)
|
|
|
case ESP_LE_AUTH_REQ_MITM:
|
|
|
auth_str = "ESP_LE_AUTH_REQ_MITM";
|
|
|
break;
|
|
|
+ case ESP_LE_AUTH_REQ_BOND_MITM:
|
|
|
+ auth_str = "ESP_LE_AUTH_REQ_BOND_MITM";
|
|
|
+ break;
|
|
|
case ESP_LE_AUTH_REQ_SC_ONLY:
|
|
|
auth_str = "ESP_LE_AUTH_REQ_SC_ONLY";
|
|
|
break;
|
|
|
@@ -318,9 +321,12 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
|
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_PASSKEY_REQ_EVT");
|
|
|
//esp_ble_passkey_reply(heart_rate_profile_tab[HEART_PROFILE_APP_IDX].remote_bda, true, 0x00);
|
|
|
break;
|
|
|
- case ESP_GAP_BLE_OOB_REQ_EVT: /* OOB request event */
|
|
|
+ case ESP_GAP_BLE_OOB_REQ_EVT: {
|
|
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_OOB_REQ_EVT");
|
|
|
+ uint8_t tk[16] = {1}; //If you paired with OOB, both devices need to use the same tk
|
|
|
+ esp_ble_oob_req_reply(param->ble_security.ble_req.bd_addr, tk, sizeof(tk));
|
|
|
break;
|
|
|
+ }
|
|
|
case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */
|
|
|
ESP_LOGI(GATTS_TABLE_TAG, "ESP_GAP_BLE_LOCAL_IR_EVT");
|
|
|
break;
|
|
|
@@ -553,7 +559,7 @@ void app_main()
|
|
|
}
|
|
|
|
|
|
/* set the security iocap & auth_req & key size & init key response key parameters to the stack*/
|
|
|
- esp_ble_auth_req_t auth_req = ESP_LE_AUTH_BOND; //bonding with peer device after authentication
|
|
|
+ esp_ble_auth_req_t auth_req = ESP_LE_AUTH_REQ_SC_MITM_BOND; //bonding with peer device after authentication
|
|
|
esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE; //set the IO capability to No output No input
|
|
|
uint8_t key_size = 16; //the key size should be 7~16 bytes
|
|
|
uint8_t init_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
|
|
|
@@ -561,11 +567,13 @@ void app_main()
|
|
|
//set static passkey
|
|
|
uint32_t passkey = 123456;
|
|
|
uint8_t auth_option = ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_DISABLE;
|
|
|
+ uint8_t oob_support = ESP_BLE_OOB_DISABLE;
|
|
|
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));
|
|
|
esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
|
|
|
esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
|
|
|
esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &key_size, sizeof(uint8_t));
|
|
|
esp_ble_gap_set_security_param(ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH, &auth_option, sizeof(uint8_t));
|
|
|
+ esp_ble_gap_set_security_param(ESP_BLE_SM_OOB_SUPPORT, &oob_support, sizeof(uint8_t));
|
|
|
/* If your BLE device act as a Slave, the init_key means you hope which types of key of the master should distribut to you,
|
|
|
and the response key means which key you can distribut to the Master;
|
|
|
If your BLE device act as a master, the response key means you hope which types of key of the slave should distribut to you,
|