Nordic stack and drivers for the mbed BLE API
Fork of nRF51822 by
Revision 119:3ba3e377b972, committed 2015-04-30
- Comitter:
- rgrover1
- Date:
- Thu Apr 30 08:34:38 2015 +0100
- Parent:
- 118:f9e5e2935c5c
- Child:
- 120:9f2d71804cfb
- Commit message:
- Synchronized with git rev ac865c5e
Author: Rohit Grover
Fixes #9: Handle user-description-descriptor properly.
Also tracked by https://github.com/mbedmicro/BLE_API/issues/38
Changed in this revision
--- a/btle/custom/custom_helper.cpp Thu Apr 30 08:34:38 2015 +0100 +++ b/btle/custom/custom_helper.cpp Thu Apr 30 08:34:38 2015 +0100 @@ -203,6 +203,8 @@ 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 @@ 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<uint8_t *>(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};
--- a/btle/custom/custom_helper.h Thu Apr 30 08:34:38 2015 +0100 +++ b/btle/custom/custom_helper.h Thu Apr 30 08:34:38 2015 +0100 @@ -36,6 +36,8 @@ 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);
--- a/nRF51GattServer.cpp Thu Apr 30 08:34:38 2015 +0100 +++ b/nRF51GattServer.cpp Thu Apr 30 08:34:38 2015 +0100 @@ -69,6 +69,19 @@ 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 @@ 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 @@ /* 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());