Skip to content

Commit e6de665

Browse files
committed
extmod/nimble: Fix flags for descriptor registration.
The att_flags for descriptors does not use the same bitfield as for characteristics. This was leading to NimBLE descriptors getting the wrong flags set. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent bb4ee06 commit e6de665

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

extmod/nimble/modbluetooth_nimble.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ static int characteristic_access_cb(uint16_t conn_handle, uint16_t value_handle,
851851
switch (ctxt->op) {
852852
case BLE_GATT_ACCESS_OP_READ_CHR:
853853
case BLE_GATT_ACCESS_OP_READ_DSC: {
854+
DEBUG_printf("write for %d %d (op=%d)\n", conn_handle, value_handle, ctxt->op);
854855
// Allow Python code to override (by using gatts_write), or deny (by returning false) the read.
855856
// Note this will be a no-op if the ringbuffer implementation is being used (i.e. the stack isn't
856857
// run in the scheduler). The ringbuffer is not used on STM32 and Unix-H4 only.
@@ -872,6 +873,7 @@ static int characteristic_access_cb(uint16_t conn_handle, uint16_t value_handle,
872873
}
873874
case BLE_GATT_ACCESS_OP_WRITE_CHR:
874875
case BLE_GATT_ACCESS_OP_WRITE_DSC:
876+
DEBUG_printf("write for %d %d (op=%d)\n", conn_handle, value_handle, ctxt->op);
875877
entry = mp_bluetooth_gatts_db_lookup(MP_STATE_PORT(bluetooth_nimble_root_pointers)->gatts_db, value_handle);
876878
if (!entry) {
877879
return BLE_ATT_ERR_ATTR_NOT_FOUND;
@@ -963,7 +965,14 @@ int mp_bluetooth_gatts_register_service(mp_obj_bluetooth_uuid_t *service_uuid, m
963965
descriptors[j].uuid = create_nimble_uuid(descriptor_uuids[descriptor_index], NULL);
964966
descriptors[j].access_cb = characteristic_access_cb;
965967
// NimBLE doesn't support security/privacy options on descriptors.
966-
descriptors[j].att_flags = (uint8_t)descriptor_flags[descriptor_index];
968+
uint8_t desc_att_flags = 0;
969+
if (descriptor_flags[descriptor_index] & MP_BLUETOOTH_CHARACTERISTIC_FLAG_READ) {
970+
desc_att_flags |= BLE_ATT_F_READ;
971+
}
972+
if (descriptor_flags[descriptor_index] & (MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE | MP_BLUETOOTH_CHARACTERISTIC_FLAG_WRITE_NO_RESPONSE)) {
973+
desc_att_flags |= BLE_ATT_F_WRITE;
974+
}
975+
descriptors[j].att_flags = desc_att_flags;
967976
descriptors[j].min_key_size = 0;
968977
// Unlike characteristic, Nimble doesn't provide an automatic way to remember the handle, so use the arg.
969978
descriptors[j].arg = &handles[handle_index];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy