8000 aioble/security: Add support for CCCD bonding. · micropython/micropython-lib@68646dc · GitHub
[go: up one dir, main page]

Skip to content

Commit 68646dc

Browse files
committed
aioble/security: Add support for CCCD bonding.
1 parent c8a0f4c commit 68646dc

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

micropython/bluetooth/aioble/aioble/security.py

10000
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
limit_peers = None
3636

3737
SEC_TYPES_SELF = (10, )
38-
SEC_TYPES_PEER = (1, 2, 3, 4)
39-
38+
SEC_TYPES_PEER = (1, 2, 4)
39+
SEC_TYPES_CCCD = (3, )
4040

4141
# Must call this before stack startup.
4242
def load_secrets(path=None):
@@ -124,7 +124,7 @@ def _log_peers(heading=""):
124124
if core.log_level <= 2:
125125
return
126126
log_info("secrets:", heading)
127-
for sec_type in SEC_TYPES_PEER:
127+
for sec_type in SEC_TYPES_PEER + SEC_TYPES_CCCD:
128128
log_info("-", sec_type)
129129

130130
if sec_type not in _secrets:
@@ -171,8 +171,12 @@ def _security_irq(event, data):
171171
_secrets[sec_type] = []
172172
secrets = _secrets[sec_type]
173173

174-
# Delete existing secrets matching the type and key.
175-
removed = _remove_entry(sec_type, key)
174+
# Delete existing secrets matching the type and key as required.
175+
# There should only every be one SEC_TYPES_PEER per addr, but
176+
# multiple entries are allowed for SEC_TYPES_CCCD
177+
removed = False
178+
if is_deleting or sec_type not in SEC_TYPES_CCCD:
179+
removed = _remove_entry(sec_type, key)
176180

177181
if is_deleting and not removed:
178182
# Delete mode, but no entries were deleted
@@ -216,6 +220,9 @@ def _security_irq(event, data):
216220

217221
for k, v in secrets:
218222
if k == key:
223+
if index:
224+
index -= 1
225+
continue
219226
return v
220227
return None
221228

0 commit comments

Comments
 (0)
0