summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/btstack
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2020-11-24 23:54:46 +1100
committerDamien George <damien@micropython.org>2020-12-02 14:40:49 +1100
commita1fcf301217b34ae74fbb937a9488be5bc6e61a5 (patch)
tree0625c5cabd5c5072c35e43b4ba0c6688d34e3fef /extmod/btstack
parent05fef8c6a4113bc05dd09ddd8d0bf7d136d59f39 (diff)
downloadmicropython-a1fcf301217b34ae74fbb937a9488be5bc6e61a5.tar.gz
micropython-a1fcf301217b34ae74fbb937a9488be5bc6e61a5.zip
extmod/modbluetooth: Allow configuration of pairing/bonding parameters.
This allows setting the security and MITM-protection requirements. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'extmod/btstack')
-rw-r--r--extmod/btstack/modbluetooth_btstack.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/extmod/btstack/modbluetooth_btstack.c b/extmod/btstack/modbluetooth_btstack.c
index 825a9ab7b1..ae4bac0094 100644
--- a/extmod/btstack/modbluetooth_btstack.c
+++ b/extmod/btstack/modbluetooth_btstack.c
@@ -53,6 +53,11 @@ STATIC const uint16_t BTSTACK_GAP_DEVICE_NAME_HANDLE = 3;
volatile int mp_bluetooth_btstack_state = MP_BLUETOOTH_BTSTACK_STATE_OFF;
+// sm_set_authentication_requirements is set-only, so cache current value.
+#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
+STATIC uint8_t mp_bluetooth_btstack_sm_auth_req = 0;
+#endif
+
#define ERRNO_BLUETOOTH_NOT_ACTIVE MP_ENODEV
STATIC int btstack_error_to_errno(int err) {
@@ -795,6 +800,39 @@ void mp_bluetooth_set_address_mode(uint8_t addr_mode) {
}
}
+#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
+void mp_bluetooth_set_bonding(bool enabled) {
+ if (enabled) {
+ mp_bluetooth_btstack_sm_auth_req |= SM_AUTHREQ_BONDING;
+ } else {
+ mp_bluetooth_btstack_sm_auth_req &= ~SM_AUTHREQ_BONDING;
+ }
+ sm_set_authentication_requirements(mp_bluetooth_btstack_sm_auth_req);
+}
+
+void mp_bluetooth_set_mitm_protection(bool enabled) {
+ if (enabled) {
+ mp_bluetooth_btstack_sm_auth_req |= SM_AUTHREQ_MITM_PROTECTION;
+ } else {
+ mp_bluetooth_btstack_sm_auth_req &= ~SM_AUTHREQ_MITM_PROTECTION;
+ }
+ sm_set_authentication_requirements(mp_bluetooth_btstack_sm_auth_req);
+}
+
+void mp_bluetooth_set_le_secure(bool enabled) {
+ if (enabled) {
+ mp_bluetooth_btstack_sm_auth_req |= SM_AUTHREQ_SECURE_CONNECTION;
+ } else {
+ mp_bluetooth_btstack_sm_auth_req &= ~SM_AUTHREQ_SECURE_CONNECTION;
+ }
+ sm_set_authentication_requirements(mp_bluetooth_btstack_sm_auth_req);
+}
+
+void mp_bluetooth_set_io_capability(uint8_t capability) {
+ sm_set_io_capabilities(capability);
+}
+#endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
+
size_t mp_bluetooth_gap_get_device_name(const uint8_t **buf) {
uint8_t *value = NULL;
size_t value_len = 0;