Skip to content

Commit

Permalink
Support non-directed address generation offload
Browse files Browse the repository at this point in the history
  • Loading branch information
zxzxwu committed Dec 26, 2023
1 parent 6139ca8 commit 1a333eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 10 additions & 0 deletions bumble/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,16 @@ async def refresh_resolving_list(self) -> None:
if self.address_resolution_offload:
await self.send_command(HCI_LE_Clear_Resolving_List_Command())

# Add an empty entry for non-directed address generation.
await self.send_command(
HCI_LE_Add_Device_To_Resolving_List_Command(
peer_identity_address_type=Address.ANY.address_type,
peer_identity_address=Address.ANY,
peer_irk=bytes(16),
local_irk=self.irk,
)
)

for irk, address in resolving_keys:
await self.send_command(
HCI_LE_Add_Device_To_Resolving_List_Command(
Expand Down
13 changes: 10 additions & 3 deletions bumble/smp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1991,12 +1991,19 @@ async def on_pairing(
) -> None:
# Store the keys in the key store
if self.device.keystore and identity_address is not None:
# Make sure on_pairing emits after key update.
self.device.abort_on(
'flush', self.device.update_keys(str(identity_address), keys)
).add_done_callback(
lambda *_: self.device.on_pairing(
session.connection, identity_address, keys, session.sc
)
)
else:
# Notify the device
self.device.on_pairing(
session.connection, identity_address, keys, session.sc
)

# Notify the device
self.device.on_pairing(session.connection, identity_address, keys, session.sc)

def on_pairing_failure(self, session: Session, reason: int) -> None:
self.device.on_pairing_failure(session.connection, reason)
Expand Down
2 changes: 1 addition & 1 deletion bumble/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def close(self) -> None:


class AbortableEventEmitter(EventEmitter):
def abort_on(self, event: str, awaitable: Awaitable[_T]) -> Awaitable[_T]:
def abort_on(self, event: str, awaitable: Awaitable[_T]) -> asyncio.Future[_T]:
"""
Set a coroutine or future to abort when an event occur.
"""
Expand Down

0 comments on commit 1a333eb

Please sign in to comment.