summaryrefslogtreecommitdiff
path: root/extmod/btstack/modbluetooth_btstack.c
diff options
context:
space:
mode:
authorAndrew Leech <andrew.leech@planetinnovation.com.au>2020-11-04 18:21:59 +1100
committerDamien George <damien@micropython.org>2020-12-02 14:40:15 +1100
commit05fef8c6a4113bc05dd09ddd8d0bf7d136d59f39 (patch)
treeb2bb8f26199614ae31fa30aeccedc77ac023baa1 /extmod/btstack/modbluetooth_btstack.c
parentac89267fef8b2396cf46c6ba19ccbe3d10acff9a (diff)
extmod/modbluetooth: Add _IRQ_ENCRYPTION_UPDATE event.
This allows the application to be notified if any of encrypted, authenticated and bonded state change, as well as the encryption key size. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'extmod/btstack/modbluetooth_btstack.c')
-rw-r--r--extmod/btstack/modbluetooth_btstack.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/extmod/btstack/modbluetooth_btstack.c b/extmod/btstack/modbluetooth_btstack.c
index da9a6f732..825a9ab7b 100644
--- a/extmod/btstack/modbluetooth_btstack.c
+++ b/extmod/btstack/modbluetooth_btstack.c
@@ -359,6 +359,35 @@ STATIC void btstack_packet_handler(uint8_t packet_type, uint8_t *packet, uint8_t
DEBUG_printf(" --> btstack # conns changed\n");
} else if (event_type == HCI_EVENT_VENDOR_SPECIFIC) {
DEBUG_printf(" --> hci vendor specific\n");
+ } else if (event_type == SM_EVENT_AUTHORIZATION_RESULT ||
+ event_type == SM_EVENT_PAIRING_COMPLETE ||
+ // event_type == GAP_EVENT_DEDICATED_BONDING_COMPLETED || // No conn_handle
+ event_type == HCI_EVENT_ENCRYPTION_CHANGE) {
+ DEBUG_printf(" --> enc/auth/pair/bond change\n", );
+ #if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
+ uint16_t conn_handle;
+ switch (event_type) {
+ case SM_EVENT_AUTHORIZATION_RESULT:
+ conn_handle = sm_event_authorization_result_get_handle(packet);
+ break;
+ case SM_EVENT_PAIRING_COMPLETE:
+ conn_handle = sm_event_pairing_complete_get_handle(packet);
+ break;
+ case HCI_EVENT_ENCRYPTION_CHANGE:
+ conn_handle = hci_event_encryption_change_get_connection_handle(packet);
+ break;
+ default:
+ return;
+ }
+
+ hci_connection_t *hci_con = hci_connection_for_handle(conn_handle);
+ sm_connection_t *desc = &hci_con->sm_connection;
+ mp_bluetooth_gatts_on_encryption_update(conn_handle,
+ desc->sm_connection_encrypted,
+ desc->sm_connection_authenticated,
+ desc->sm_le_db_index != -1,
+ desc->sm_actual_encryption_key_size);
+ #endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
} else if (event_type == HCI_EVENT_DISCONNECTION_COMPLETE) {
DEBUG_printf(" --> hci disconnect complete\n");
uint16_t conn_handle = hci_event_disconnection_complete_get_connection_handle(packet);