Skip to content

Commit

Permalink
Merge pull request adafruit#8795 from picospuch/circuitpython-main
Browse files Browse the repository at this point in the history
silabs: Fix _bleio.Descriptor.add_to_characteristic
  • Loading branch information
dhalbert authored Jan 13, 2024
2 parents 2c45339 + b6a5690 commit 9beefdb
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions ports/silabs/common-hal/_bleio/Characteristic.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,12 @@ void common_hal_bleio_characteristic_add_descriptor(
bleio_descriptor_obj_t *descriptor) {

sl_status_t sc = SL_STATUS_FAIL;
const uint8_t value;
uuid_128 bt_uuid_128;
sl_bt_uuid_16_t bt_uuid_16;
uint16_t gattdb_session;
mp_buffer_info_t desc_value_bufinfo;

mp_get_buffer_raise(descriptor->initial_value, &desc_value_bufinfo, MP_BUFFER_READ);

sc = sl_bt_gattdb_new_session(&gattdb_session);

Expand All @@ -337,30 +339,37 @@ void common_hal_bleio_characteristic_add_descriptor(
bt_uuid_16.data[0] = descriptor->uuid->efr_ble_uuid.uuid16.value & 0xff;
bt_uuid_16.data[1] = descriptor->uuid->efr_ble_uuid.uuid16.value >> 8;

sl_bt_gattdb_add_uuid16_descriptor(self->session,
sl_bt_gattdb_add_uuid16_descriptor(gattdb_session,
self->handle,
descriptor->handle,
SL_BT_GATTDB_DESCRIPTOR_READ | SL_BT_GATTDB_DESCRIPTOR_WRITE,
0,
bt_uuid_16,
sl_bt_gattdb_user_managed_value,
sl_bt_gattdb_variable_length_value,
descriptor->max_length,
2,
&value,
desc_value_bufinfo.len,
desc_value_bufinfo.buf,
&descriptor->handle);
} else {
memcpy(bt_uuid_128.data, descriptor->uuid->efr_ble_uuid.uuid128.value, 16);
sl_bt_gattdb_add_uuid128_descriptor(self->session,
self->handle,
descriptor->handle,
SL_BT_GATTDB_DESCRIPTOR_READ | SL_BT_GATTDB_DESCRIPTOR_WRITE,
0,
bt_uuid_128,
sl_bt_gattdb_user_managed_value,
sl_bt_gattdb_variable_length_value,
descriptor->max_length,
2,
&value,
desc_value_bufinfo.len,
desc_value_bufinfo.buf,
&descriptor->handle);
}

// This indicates the new added descriptor shall be started.
sc = sl_bt_gattdb_start_characteristic(gattdb_session, self->handle);
if (SL_STATUS_OK != sc) {
mp_raise_bleio_BluetoothError(MP_ERROR_TEXT("Start charateristic fail."));
return;
}

sc = sl_bt_gattdb_commit(gattdb_session);
if (SL_STATUS_OK != sc) {
mp_raise_bleio_BluetoothError(MP_ERROR_TEXT("Commit descriptor fail."));
Expand Down

0 comments on commit 9beefdb

Please sign in to comment.