kopia lustrzana https://github.com/micropython/micropython-lib
aioble/security: Add DeviceConnection.pairing_in_progress flag.
Will be True if the pairing process has been started but is waiting for ack from remote device.pull/468/head
rodzic
5b496e944e
commit
93492e00b9
|
@ -163,7 +163,7 @@ class DeviceConnection:
|
||||||
_connected = {}
|
_connected = {}
|
||||||
|
|
||||||
def __init__(self, device):
|
def __init__(self, device):
|
||||||
self.device = device
|
self.device: Device = device
|
||||||
device._connection = self
|
device._connection = self
|
||||||
|
|
||||||
self.encrypted = False
|
self.encrypted = False
|
||||||
|
@ -171,6 +171,7 @@ class DeviceConnection:
|
||||||
self.bonded = False
|
self.bonded = False
|
||||||
self.key_size = False
|
self.key_size = False
|
||||||
self.mtu = None
|
self.mtu = None
|
||||||
|
self.pairing_in_progress = False
|
||||||
|
|
||||||
self._conn_handle = None
|
self._conn_handle = None
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import binascii
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from .core import log_info, log_warn, ble, register_irq_handler
|
from .core import log_info, log_warn, ble, register_irq_handler
|
||||||
from .device import DeviceConnection
|
from .device import DeviceConnection, Device
|
||||||
|
|
||||||
_IRQ_ENCRYPTION_UPDATE = const(28)
|
_IRQ_ENCRYPTION_UPDATE = const(28)
|
||||||
_IRQ_GET_SECRET = const(29)
|
_IRQ_GET_SECRET = const(29)
|
||||||
|
@ -51,6 +51,15 @@ def load_secrets(path=None):
|
||||||
log_warn("No secrets available")
|
log_warn("No secrets available")
|
||||||
|
|
||||||
|
|
||||||
|
def _get_connection(key) -> DeviceConnection:
|
||||||
|
if not key:
|
||||||
|
return None
|
||||||
|
addr = bytes(reversed(key[-6:]))
|
||||||
|
for connection in DeviceConnection._connected.values():
|
||||||
|
if connection.device.addr == addr:
|
||||||
|
return connection
|
||||||
|
|
||||||
|
|
||||||
# Call this whenever the secrets dict changes.
|
# Call this whenever the secrets dict changes.
|
||||||
def _save_secrets(arg=None):
|
def _save_secrets(arg=None):
|
||||||
global _modified, _path
|
global _modified, _path
|
||||||
|
@ -84,6 +93,7 @@ def _security_irq(event, data):
|
||||||
connection.authenticated = authenticated
|
connection.authenticated = authenticated
|
||||||
connection.bonded = bonded
|
connection.bonded = bonded
|
||||||
connection.key_size = key_size
|
connection.key_size = key_size
|
||||||
|
connection.pairing_in_progress = False
|
||||||
# TODO: Handle failure.
|
# TODO: Handle failure.
|
||||||
if encrypted and connection._pair_event:
|
if encrypted and connection._pair_event:
|
||||||
connection._pair_event.set()
|
connection._pair_event.set()
|
||||||
|
@ -126,6 +136,11 @@ def _security_irq(event, data):
|
||||||
i += 1
|
i += 1
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
if sec_type in SEC_TYPES_PEER:
|
||||||
|
if conn := _get_connection(key):
|
||||||
|
log_info("encryption / pairing started", conn)
|
||||||
|
conn.pairing_in_progress = True
|
||||||
|
|
||||||
# Return the secret for this key (or None).
|
# Return the secret for this key (or None).
|
||||||
key = sec_type, bytes(key)
|
key = sec_type, bytes(key)
|
||||||
return _secrets.get(key, None)
|
return _secrets.get(key, None)
|
||||||
|
|
Ładowanie…
Reference in New Issue