Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add presentation format descriptor support for nRF5x #5727

Merged
merged 1 commit into from Jan 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -210,6 +210,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
bool has_variable_len,
const uint8_t *userDescriptionDescriptorValuePtr,
uint16_t userDescriptionDescriptorValueLen,
const uint8_t *presentationFormatDescriptorValuePtr,
uint16_t presentationFormatDescriptorValueLen,
bool readAuthorization,
bool writeAuthorization,
ble_gatts_char_handles_t *p_char_handle)
Expand Down Expand Up @@ -238,6 +240,11 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
char_md.char_user_desc_max_size = userDescriptionDescriptorValueLen;
char_md.char_user_desc_size = userDescriptionDescriptorValueLen;
}
if ((presentationFormatDescriptorValueLen > 0) && (presentationFormatDescriptorValuePtr != NULL)) {
ASSERT_TRUE( sizeof(ble_gatts_char_pf_t) == sizeof(GattCharacteristic::PresentationFormat_t), ERROR_INVALID_PARAM );
ASSERT_TRUE( presentationFormatDescriptorValueLen == sizeof(GattCharacteristic::PresentationFormat_t), ERROR_INVALID_PARAM );
char_md.p_char_pf = const_cast<ble_gatts_char_pf_t *>(reinterpret_cast<const ble_gatts_char_pf_t *>(presentationFormatDescriptorValuePtr));
}

/* Attribute declaration */
ble_gatts_attr_md_t attr_md = {0};
Expand Down
Expand Up @@ -52,6 +52,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
bool has_variable_len,
const uint8_t *userDescriptionDescriptorValuePtr,
uint16_t userDescriptionDescriptorValueLen,
const uint8_t *presentationFormatDescriptorValuePtr,
uint16_t presentationFormatDescriptorValueLen,
bool readAuthorization,
bool writeAuthorization,
ble_gatts_char_handles_t *p_char_handle);
Expand Down
Expand Up @@ -131,6 +131,7 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
}
GattCharacteristic *p_char = service.getCharacteristic(i);
GattAttribute *p_description_descriptor = NULL;
GattAttribute *p_presentation_format_descriptor = NULL;

/* Skip any incompletely defined, read-only characteristics. */
if ((p_char->getValueAttribute().getValuePtr() == NULL) &&
Expand All @@ -141,18 +142,25 @@ ble_error_t nRF5xGattServer::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. */
/* The user-description and presentation-format descriptors are special cases
* that need to be handled at the time of adding each characteristic. The
* following block is meant to discover their presence. */
const uint8_t *userDescriptionDescriptorValuePtr = NULL;
uint16_t userDescriptionDescriptorValueLen = 0;
const uint8_t *presentationFormatDescriptorValuePtr = NULL;
uint16_t presentationFormatDescriptorValueLen = 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) {
p_description_descriptor = p_desc;
userDescriptionDescriptorValuePtr = p_desc->getValuePtr();
userDescriptionDescriptorValueLen = p_desc->getLength();
}
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT) {
p_presentation_format_descriptor = p_desc;
presentationFormatDescriptorValuePtr = p_desc->getValuePtr();
presentationFormatDescriptorValueLen = p_desc->getLength();
}
}

ASSERT_TRUE ( ERROR_NONE ==
Expand All @@ -166,6 +174,8 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
p_char->getValueAttribute().hasVariableLength(),
userDescriptionDescriptorValuePtr,
userDescriptionDescriptorValueLen,
presentationFormatDescriptorValuePtr,
presentationFormatDescriptorValueLen,
p_char->isReadAuthorizationEnabled(),
p_char->isWriteAuthorizationEnabled(),
&nrfCharacteristicHandles[characteristicCount]),
Expand All @@ -179,6 +189,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
nrfCharacteristicHandles[characteristicCount].user_desc_handle
);
}
if (p_presentation_format_descriptor) {
// The handle is not available from the SoftDevice
p_presentation_format_descriptor->setHandle(GattAttribute::INVALID_HANDLE);
}
characteristicCount++;

/* Add optional descriptors if any */
Expand All @@ -188,8 +202,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
}

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) {
/* skip the user-description or presentation-format descriptor here;
* they have already been handled when adding the characteristic (above). */
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC
|| p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT) {
continue;
}

Expand Down