Page 2 of 2

Re: Activate BLE Bonding and security with Button and show special services

Posted: Mon Jul 08, 2019 5:22 pm
by Rx-365
Any updates on this issue? I believed that the Whitelisting was still broken, thus the path you ended up going down would not work.

I have tried several attempts to solve this problem and ended up with little to no success. At the moment I am trying to detect if a connection has a Long Term BLE Key stored on my device when a connection is opened. If the long term key exists I will let the device connect otherwise I will reject the connection. It isn't looking promising though.

Re: Activate BLE Bonding and security with Button and show special services

Posted: Wed Jul 10, 2019 4:02 pm
by Rx-365
Alright, this may not be a solution for you, but it worked for my problem.

What I believe you should do is change the security level when the button is pressed and then change it back for ten seconds. By default you should set the security level to:

Code: Select all

esp_ble_auth_req_t auth_req = ESP_LE_AUTH_REQ_SC_MITM_BOND;
    esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
This will allow previously bonded connections to bypass the GAP layer and stop all new connections. Once the button is pressed run the code:

Code: Select all

esp_ble_auth_req_t auth_req = ESP_LE_AUTH_BOND;     //bonding with peer device after authentication
esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
This will allow connections to create new bonds. Let me know if this works for you. Again, this solution does not handle GATT layer permissions. This simply controls the window in which new devices are able to access your BLE interface.