diff --git a/btle/custom/custom_helper.cpp b/btle/custom/custom_helper.cpp index ca71615..324d593 100644 --- a/btle/custom/custom_helper.cpp +++ b/btle/custom/custom_helper.cpp @@ -203,6 +203,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle, uint8_t *p_data, uint16_t min_length, uint16_t max_length, + const uint8_t *userDescriptionDescriptorValuePtr, + uint16_t userDescriptionDescriptorValueLen, bool readAuthorization, bool writeAuthorization, ble_gatts_char_handles_t *p_char_handle) @@ -226,6 +228,11 @@ error_t custom_add_in_characteristic(uint16_t service_handle, char_md.char_props = char_props; char_md.p_cccd_md = (char_props.notify || char_props.indicate) ? &cccd_md : NULL; + if ((userDescriptionDescriptorValueLen > 0) && (userDescriptionDescriptorValuePtr != NULL)) { + char_md.p_char_user_desc = const_cast(userDescriptionDescriptorValuePtr); + char_md.char_user_desc_max_size = userDescriptionDescriptorValueLen; + char_md.char_user_desc_size = userDescriptionDescriptorValueLen; + } /* Attribute declaration */ ble_gatts_attr_md_t attr_md = {0}; diff --git a/btle/custom/custom_helper.h b/btle/custom/custom_helper.h index 10732b2..40a8971 100644 --- a/btle/custom/custom_helper.h +++ b/btle/custom/custom_helper.h @@ -36,6 +36,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle, uint8_t *p_data, uint16_t min_length, uint16_t max_length, + const uint8_t *userDescriptionDescriptorValuePtr, + uint16_t userDescriptionDescriptorValueLen, bool readAuthorization, bool writeAuthorization, ble_gatts_char_handles_t *p_char_handle); diff --git a/nRF51GattServer.cpp b/nRF51GattServer.cpp index 48b7ecf..18ff4b0 100644 --- a/nRF51GattServer.cpp +++ b/nRF51GattServer.cpp @@ -69,6 +69,19 @@ ble_error_t nRF51GattServer::addService(GattService &service) nordicUUID = custom_convert_to_nordic_uuid(p_char->getValueAttribute().getUUID()); + /* The user-description descriptor is a special case which needs to be + * handled at the time of adding the characteristic. The following block + * is meant to discover its presence. */ + const uint8_t *userDescriptionDescriptorValuePtr = NULL; + uint16_t userDescriptionDescriptorValueLen = 0; + for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) { + GattAttribute *p_desc = p_char->getDescriptor(j); + if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) { + userDescriptionDescriptorValuePtr = p_desc->getValuePtr(); + userDescriptionDescriptorValueLen = p_desc->getLength(); + } + } + ASSERT ( ERROR_NONE == custom_add_in_characteristic(BLE_GATT_HANDLE_INVALID, &nordicUUID, @@ -76,6 +89,8 @@ ble_error_t nRF51GattServer::addService(GattService &service) p_char->getValueAttribute().getValuePtr(), p_char->getValueAttribute().getInitialLength(), p_char->getValueAttribute().getMaxLength(), + userDescriptionDescriptorValuePtr, + userDescriptionDescriptorValueLen, p_char->isReadAuthorizationEnabled(), p_char->isWriteAuthorizationEnabled(), &nrfCharacteristicHandles[characteristicCount]), @@ -91,6 +106,10 @@ ble_error_t nRF51GattServer::addService(GattService &service) /* ToDo: Make sure we don't overflow the array */ for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) { GattAttribute *p_desc = p_char->getDescriptor(j); + /* skip the user-description-descriptor here; this has already been handled when adding the characteristic (above). */ + if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) { + continue; + } nordicUUID = custom_convert_to_nordic_uuid(p_desc->getUUID());