Commit 450a432
committed
Refactor: Enhance BLESecure::removeBonding for specific device bond removal
This commit significantly refactors the `BLESecureClass::removeBonding(BLEDevice *device)` method to provide a functional implementation for deleting the bonding information of a specific, currently or recently connected LE device.
Previously, this method was a placeholder that only disconnected the device and noted the need for a full implementation.
The updated method now performs the following steps:
1. **Input Validation**: Checks if the provided `BLEDevice` object is valid and if it has a valid `hci_con_handle_t`.
2. **Device DB Index Lookup**: Uses `sm_le_device_index(handle)` to retrieve the internal index of the device within BTstack's LE Device Database. This requires the device's security context to be known to the Security Manager (SM).
3. **Address Information Retrieval**: If a valid DB index is found, `le_device_db_info()` is called to fetch the `bd_addr_t` (Bluetooth address) and `bd_addr_type_t` (address type) of the device from the LE Device Database (which, in the `arduino-pico` context, is typically a TLV store on flash).
4. **GAP-Level Bond Deletion**: Calls `gap_delete_bonding(addr_type, addr)` with the retrieved address and type. This is the appropriate high-level BTstack API function to request the deletion of an LE bond. It is expected to interact with both the LE Device Database and the Security Manager.
5. **Verification and Logging**:
* Includes extensive `Serial.println()` messages to log the steps taken, including the device's DB index, address, and address type.
* Calls `le_device_db_dump()` after `gap_delete_bonding` to allow observation of the LE Device DB state (though immediate changes to flash might not always be reflected without a re-scan or if the dump relies on a RAM cache).
* Checks `le_device_db_count()` after the deletion attempt to log if the count of bonded devices has changed.
6. **Disconnection**: Calls `gap_disconnect(handle)` to disconnect the device after the bond removal attempt, maintaining a similar behavior to the original placeholder in this regard.
7. **Error Handling**: Provides log messages if the device is not found in the LE Device DB or if a valid LE address type cannot be retrieved.
This enhancement aims to provide a more robust mechanism for managing individual device bonds within the `BLESecure` library, complementing the `clearAllBondings` function which targets all stored bonds. The effectiveness in completely preventing re-encryption still depends on the underlying behavior of BTstack's TLV flash backend and Security Manager regarding persistent key storage.1 parent 688f8ac commit 450a432
1 file changed
+44
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
190 | | - | |
191 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
192 | 192 | | |
| 193 | + | |
193 | 194 | | |
194 | 195 | | |
195 | | - | |
| 196 | + | |
| 197 | + | |
196 | 198 | | |
| 199 | + | |
197 | 200 | | |
| 201 | + | |
198 | 202 | | |
199 | 203 | | |
200 | | - | |
201 | 204 | | |
202 | | - | |
203 | | - | |
204 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
205 | 210 | | |
206 | 211 | | |
207 | 212 | | |
208 | | - | |
209 | | - | |
210 | | - | |
| 213 | + | |
211 | 214 | | |
212 | | - | |
213 | 215 | | |
214 | | - | |
215 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
216 | 220 | | |
217 | | - | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
218 | 247 | | |
219 | 248 | | |
220 | 249 | | |
| |||
0 commit comments