Skip to content

Fixed handling cancelled bonding for read/write operations#597

Merged
philips77 merged 1 commit intomainfrom
bugfix/bonding-cancelled
Oct 11, 2024
Merged

Fixed handling cancelled bonding for read/write operations#597
philips77 merged 1 commit intomainfrom
bugfix/bonding-cancelled

Conversation

@philips77
Copy link
Copy Markdown
Contributor

This PR fixes #552, again.

Write and read requests trigger bonding when sent using an unsecured link to a protected attribute. If bonding fails, e.g. it's cancelled, there are 2 things happening:

  1. Read characteristic and Read descriptor requests get status 137 in onCharacteristicRead callback. This will be ignored.
  2. Write characteristic and Write descriptor requests don't get such callback. They don't get any callback, actually.

In both cases, the bond state broadcast receiver gets transition BOND-BONDING -> BOND_NONE. This PR adds a code to fail awaiting request of write/read type.

If no GATT operation is performed withing 3 seconds after bonding fails, the device gets disconnected (Android disconnects, not the library). However, if there is any GATT operation enqueued and will be executed, the phone continues as if nothing happened. It can trigger bonding again and again. At some point, if bonding state changed to BOND_NONE, call to a protected attribute will generate status 5 (BluetoothGatt.GATT_INSUFFICIENT_AUTHENTICATION). This means, that Android will not try to bond again, and the request is getting failed immediately.

@philips77
Copy link
Copy Markdown
Contributor Author

I didn't manage to get error 8 during tests, but I will threat it just as state 5. I think it may be called when the security is insufficient (bonded without MITM, but MIMT required, etc.). This could be checked in the future.

@philips77 philips77 merged commit 3c9300a into main Oct 11, 2024
@philips77 philips77 deleted the bugfix/bonding-cancelled branch October 11, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No response from writeCharacteristic

1 participant