From f38e378f7199ca45aca0034bdadabbee44385fcb Mon Sep 17 00:00:00 2001 From: Daniel Flanagan <37907774+FlantasticDan@users.noreply.github.com> Date: Fri, 24 Feb 2023 04:26:29 -0800 Subject: [PATCH] extmod/modblutooth_btstack: Implement gap_passkey(...) Adds nimble equivalent behavior to btstack BLE implementations --- extmod/btstack/modbluetooth_btstack.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/extmod/btstack/modbluetooth_btstack.c b/extmod/btstack/modbluetooth_btstack.c index e9c0037394..242401053d 100644 --- a/extmod/btstack/modbluetooth_btstack.c +++ b/extmod/btstack/modbluetooth_btstack.c @@ -1240,7 +1240,26 @@ int mp_bluetooth_gap_pair(uint16_t conn_handle) { int mp_bluetooth_gap_passkey(uint16_t conn_handle, uint8_t action, mp_int_t passkey) { DEBUG_printf("mp_bluetooth_gap_passkey: conn_handle=%d action=%d passkey=%d\n", conn_handle, action, (int)passkey); - return MP_EOPNOTSUPP; + switch (action) { + case MP_BLUETOOTH_PASSKEY_ACTION_INPUT: { + sm_passkey_input(conn_handle, passkey); + break; + } + case MP_BLUETOOTH_PASSKEY_ACTION_DISPLAY: { + sm_use_fixed_passkey_in_display_role(passkey); + break; + } + case MP_BLUETOOTH_PASSKEY_ACTION_NUMERIC_COMPARISON: { + if (passkey != 0) { + sm_numeric_comparison_confirm(conn_handle); + } + break; + } + default: { + return MP_EINVAL; + } + } + return 0; } #endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING