avinabmalla / ESP32_BleSerial

A BLE Serial library for Arduino ESP32
MIT License
62 stars 17 forks source link

ESP32C3 - GATT_INSUF_AUTHENTICATION using android phone when connecting #9

Open CFTechno opened 1 year ago

CFTechno commented 1 year ago

Tried to build the bridge example for a Seeed studio XIAO-ESP32C3.

Did not liked the disableCore1WDT(); , commented it out but then got an exit status 1

error message pointed to the two rtc functions rtc_wdt_protect_off(); rtc_wdt_disable();

commented them both out. build, flash all no problem

Used "Serial Bluetooth Terminal" to connect to the device, device is visible, pairing however fails. ` E (172628) BT_GATT: gatts_write_attr_perm_check - GATT_INSUF_AUTHENTICATION E (177430) BT_SMP: smp_calculate_link_key_from_long_term_key failed to update link_key. Sec Mode = 2, sm4 = 0x00 E (177431) BT_SMP: smp_derive_link_key_from_long_term_key failed

E (177437) BT_BTM: btm_proc_smp_cback received for unknown device`

lemio commented 5 months ago

Similair issue here; I try to connect with an Android phone to the esp32-s3, and when reading from the esp32 through nrf connect I get.


E (94155) BT_BTM: Device not found

E (308791) BT_GATT: GATT_INSUF_AUTHENTICATION

When I try to write to the device I get this:

E (324766) BT_GATT: gatts_write_attr_perm_check - GATT_INSUF_AUTHENTICATION
E (324856) BT_GATT: gatts_write_attr_perm_check - GATT_INSUF_AUTHENTICATION

In general I never set any PIN code for the device, so in theory pairing should not happen I assumed.

thegoodhen commented 1 month ago

Same happens with esp32s3 and iPhone (BLESerialNRF app). Will investigate further.

thegoodhen commented 1 month ago

The problem is related to:

https://github.com/nkolban/esp32-snippets/issues/806

Adding the following code to the setup makes it prompt for a pin, but then works as expected:

  BLESecurity *pSecurity = new BLESecurity();
  pSecurity->setStaticPIN(123456);
  pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_BOND);

I will try to see if there is a better solution.

thegoodhen commented 1 month ago

A workaround is to change the access permissions to the characteristics to ESP_GATT_PERM_READ and ESP_GATT_PERM_WRITE from their respective encrypted variants inside BleSerial::SetupSerialService.

I would post a pull request, but I am not sure if this is the correct fix, since this, well... disables the encryption.