Esp32-snippets: BLESecurity how to.handle auth not complete

Created on 14 Mar 2019  路  7Comments  路  Source: nkolban/esp32-snippets

onAuthenticationComplete(esp_ble_auth_cmpl_t)

ESP_GAP_BLE_AUTH_CMPL_EVT

I am using this event but having issues if pin fails. Is there an auth fail event?

Most helpful comment

Using the BLESecurity callback as mentioned here, where could i decode meaning of esp_ble_auth_cmpl_t?
It seems fail_reason in the GAP API documentation has no explanation. The library only mentions The HCI reason/error code for when success=FALSE

Currently I always need to pair twice as the first pair results with fail_reason = 81 (i think 0x51) . Is this a bit mask for something?

All 7 comments

You have to use the same callback. Here is how parameter structure looks like:

typedef struct
{
    esp_bd_addr_t         bd_addr;               /*!< BD address peer device. */
    bool                  key_present;           /*!< Valid link key value in key element */
    esp_link_key          key;                   /*!< Link key associated with peer device. */
    uint8_t               key_type;              /*!< The type of Link Key */
    bool                  success;               /*!< TRUE of authentication succeeded, FALSE if failed. */
    uint8_t               fail_reason;           /*!< The HCI reason/error code for when success=FALSE */
    esp_ble_addr_type_t   addr_type;             /*!< Peer device address type */
    esp_bt_dev_type_t     dev_type;              /*!< Device type */
    esp_ble_auth_req_t    auth_mode;             /*!< authentication mode */
} esp_ble_auth_cmpl_t;                           /*!< The ble authentication complete cb type */

Look at success value.

Using the BLESecurity callback as mentioned here, where could i decode meaning of esp_ble_auth_cmpl_t?
It seems fail_reason in the GAP API documentation has no explanation. The library only mentions The HCI reason/error code for when success=FALSE

Currently I always need to pair twice as the first pair results with fail_reason = 81 (i think 0x51) . Is this a bit mask for something?

@axa88 I鈥檝e ran into this as well. Can you please show me what you mean when pairing twice? I鈥檝e been having trouble just getting them to pair.

@axa88 I鈥檝e ran into this as well. Can you please show me what you mean when pairing twice? I鈥檝e been having trouble just getting them to pair.

literally i would need to pair my esp32 device to my host, an Android phone, once to which it would fail not pairing, and then the second time to which it would pair.

here I was hoping to get a better description of the actual error.

I dont know that error description, but you could open issue on esp-idf or even try to find old issue.

@axa88 I鈥檝e ran into this as well. Can you please show me what you mean when pairing twice? I鈥檝e been having trouble just getting them to pair.

literally i would need to pair my esp32 device to my host, an Android phone, once to which it would fail not pairing, and then the second time to which it would pair.

here I was hoping to get a better description of the actual error.

HCI Codes are here: https://github.com/NordicSemiconductor/ble-sdk-arduino/blob/master/libraries/BLE/aci.h
I have same issue - ESP32 only pairs device for second time. And I also have fail_reason = 81 (ACI_STATUS_ERROR_INTERNAL). Did you find any solution to this?

EDIT:
I guess I found some hacky solution. Erasing flash (I made this by running "erase flash" task in PlatformIO) seems to fix this problem... but only for a while. I think that esp32 is bugging when I'm playing with different security options. Then erasing flash is needed. Unfortunately I haven't found out clear way to reproduce this buggy behaviour.

It is good practice to erase flash every time when you work with ble security, also you should clear pairing on smartphone each time. If you wont do that it may lead to many problems with testing/debugging.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

frankipl picture frankipl  路  8Comments

d3cline picture d3cline  路  4Comments

hellowtisch picture hellowtisch  路  7Comments

minwinmin picture minwinmin  路  9Comments

Lakoja picture Lakoja  路  8Comments