Skip to content

aioble/security: Add DeviceConnection.pairing_in_progress flag. #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion micropython/bluetooth/aioble/aioble/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,15 @@ class DeviceConnection:
_connected = {}

def __init__(self, device):
self.device = device
self.device: Device = device
device._connection = self

self.encrypted = False
self.authenticated = False
self.bonded = False
self.key_size = False
self.mtu = None
self.pairing_in_progress = False

self._conn_handle = None

Expand Down
17 changes: 16 additions & 1 deletion micropython/bluetooth/aioble/aioble/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import json

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_GET_SECRET = const(29)
Expand Down Expand Up @@ -51,6 +51,15 @@
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.
def _save_secrets(arg=None):
global _modified, _path
Expand Down Expand Up @@ -84,6 +93,7 @@
connection.authenticated = authenticated
connection.bonded = bonded
connection.key_size = key_size
connection.pairing_in_progress = False
# TODO: Handle failure.
if encrypted and connection._pair_event:
connection._pair_event.set()
Expand Down Expand Up @@ -126,6 +136,11 @@
i += 1
return None
else:
if sec_type in SEC_TYPES_PEER:

Check failure on line 139 in micropython/bluetooth/aioble/aioble/security.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

micropython/bluetooth/aioble/aioble/security.py:139:28: F821 Undefined name `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).
key = sec_type, bytes(key)
return _secrets.get(key, None)
Expand Down
Loading