@@ -321,10 +321,12 @@ void common_hal_bleio_characteristic_add_descriptor(
321321 bleio_descriptor_obj_t * descriptor ) {
322322
323323 sl_status_t sc = SL_STATUS_FAIL ;
324- const uint8_t value ;
325324 uuid_128 bt_uuid_128 ;
326325 sl_bt_uuid_16_t bt_uuid_16 ;
327326 uint16_t gattdb_session ;
327+ mp_buffer_info_t desc_value_bufinfo ;
328+
329+ mp_get_buffer_raise (descriptor -> initial_value , & desc_value_bufinfo , MP_BUFFER_READ );
328330
329331 sc = sl_bt_gattdb_new_session (& gattdb_session );
330332
@@ -337,30 +339,37 @@ void common_hal_bleio_characteristic_add_descriptor(
337339 bt_uuid_16 .data [0 ] = descriptor -> uuid -> efr_ble_uuid .uuid16 .value & 0xff ;
338340 bt_uuid_16 .data [1 ] = descriptor -> uuid -> efr_ble_uuid .uuid16 .value >> 8 ;
339341
340- sl_bt_gattdb_add_uuid16_descriptor (self -> session ,
342+ sl_bt_gattdb_add_uuid16_descriptor (gattdb_session ,
341343 self -> handle ,
342- descriptor -> handle ,
344+ SL_BT_GATTDB_DESCRIPTOR_READ | SL_BT_GATTDB_DESCRIPTOR_WRITE ,
343345 0 ,
344346 bt_uuid_16 ,
345- sl_bt_gattdb_user_managed_value ,
347+ sl_bt_gattdb_variable_length_value ,
346348 descriptor -> max_length ,
347- 2 ,
348- & value ,
349+ desc_value_bufinfo . len ,
350+ desc_value_bufinfo . buf ,
349351 & descriptor -> handle );
350352 } else {
351353 memcpy (bt_uuid_128 .data , descriptor -> uuid -> efr_ble_uuid .uuid128 .value , 16 );
352354 sl_bt_gattdb_add_uuid128_descriptor (self -> session ,
353355 self -> handle ,
354- descriptor -> handle ,
356+ SL_BT_GATTDB_DESCRIPTOR_READ | SL_BT_GATTDB_DESCRIPTOR_WRITE ,
355357 0 ,
356358 bt_uuid_128 ,
357- sl_bt_gattdb_user_managed_value ,
359+ sl_bt_gattdb_variable_length_value ,
358360 descriptor -> max_length ,
359- 2 ,
360- & value ,
361+ desc_value_bufinfo . len ,
362+ desc_value_bufinfo . buf ,
361363 & descriptor -> handle );
362364 }
363365
366+ // This indicates the new added descriptor shall be started.
367+ sc = sl_bt_gattdb_start_characteristic (gattdb_session , self -> handle );
368+ if (SL_STATUS_OK != sc ) {
369+ mp_raise_bleio_BluetoothError (MP_ERROR_TEXT ("Start charateristic fail." ));
370+ return ;
371+ }
372+
364373 sc = sl_bt_gattdb_commit (gattdb_session );
365374 if (SL_STATUS_OK != sc ) {
366375 mp_raise_bleio_BluetoothError (MP_ERROR_TEXT ("Commit descriptor fail." ));
0 commit comments