Handle SSP Complete events

This commit is contained in:
Josh Wu
2023-08-09 19:19:34 +08:00
parent fe28473ba8
commit 2af3494d8c
3 changed files with 18 additions and 14 deletions

View File

@@ -2743,20 +2743,6 @@ class Device(CompositeEventEmitter):
) )
connection.emit('connection_authentication_failure', error) connection.emit('connection_authentication_failure', error)
@host_event_handler
@with_connection_from_address
def on_ssp_complete(self, connection):
# On Secure Simple Pairing complete, in case:
# - Connection isn't already authenticated
# - AND we are not the initiator of the authentication
# We must trigger authentication to know if we are truly authenticated
if not connection.authenticating and not connection.authenticated:
logger.debug(
f'*** Trigger Connection Authentication: [0x{connection.handle:04X}] '
f'{connection.peer_address}'
)
asyncio.create_task(connection.authenticate())
# [Classic only] # [Classic only]
@host_event_handler @host_event_handler
@with_connection_from_address @with_connection_from_address
@@ -3111,6 +3097,18 @@ class Device(CompositeEventEmitter):
connection.emit('role_change_failure', error) connection.emit('role_change_failure', error)
self.emit('role_change_failure', address, error) self.emit('role_change_failure', address, error)
# [Classic only]
@host_event_handler
@with_connection_from_address
def on_classic_pairing(self, connection: Connection) -> None:
connection.emit('classic_pairing')
# [Classic only]
@host_event_handler
@with_connection_from_address
def on_classic_pairing_failure(self, connection: Connection, status) -> None:
connection.emit('classic_pairing_failure', status)
def on_pairing_start(self, connection: Connection) -> None: def on_pairing_start(self, connection: Connection) -> None:
connection.emit('pairing_start') connection.emit('pairing_start')

View File

@@ -822,6 +822,10 @@ class Host(AbortableEventEmitter):
f'simple pairing complete for {event.bd_addr}: ' f'simple pairing complete for {event.bd_addr}: '
f'status={HCI_Constant.status_name(event.status)}' f'status={HCI_Constant.status_name(event.status)}'
) )
if event.status == HCI_SUCCESS:
self.emit('classic_pairing', event.bd_addr)
else:
self.emit('classic_pairing_failure', event.bd_addr, event.status)
def on_hci_pin_code_request_event(self, event): def on_hci_pin_code_request_event(self, event):
self.emit('pin_code_request', event.bd_addr) self.emit('pin_code_request', event.bd_addr)

View File

@@ -423,6 +423,8 @@ class SecurityService(SecurityServicer):
'pairing': try_set_success, 'pairing': try_set_success,
'connection_authentication': try_set_success, 'connection_authentication': try_set_success,
'connection_encryption_change': on_encryption_change, 'connection_encryption_change': on_encryption_change,
'classic_pairing': try_set_success,
'classic_pairing_failure': set_failure('pairing_failure'),
} }
# register event handlers # register event handlers