@@ -131,6 +131,7 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
131
131
}
132
132
GattCharacteristic *p_char = service.getCharacteristic (i);
133
133
GattAttribute *p_description_descriptor = NULL ;
134
+ GattAttribute *p_presentation_format_descriptor = NULL ;
134
135
135
136
/* Skip any incompletely defined, read-only characteristics. */
136
137
if ((p_char->getValueAttribute ().getValuePtr () == NULL ) &&
@@ -141,18 +142,25 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
141
142
142
143
nordicUUID = custom_convert_to_nordic_uuid (p_char->getValueAttribute ().getUUID ());
143
144
144
- /* The user-description descriptor is a special case which needs to be
145
- * handled at the time of adding the characteristic. The following block
146
- * is meant to discover its presence. */
145
+ /* The user-description and presentation-format descriptors are special cases
146
+ * that need to be handled at the time of adding each characteristic. The
147
+ * following block is meant to discover their presence. */
147
148
const uint8_t *userDescriptionDescriptorValuePtr = NULL ;
148
149
uint16_t userDescriptionDescriptorValueLen = 0 ;
150
+ const uint8_t *presentationFormatDescriptorValuePtr = NULL ;
151
+ uint16_t presentationFormatDescriptorValueLen = 0 ;
149
152
for (uint8_t j = 0 ; j < p_char->getDescriptorCount (); j++) {
150
153
GattAttribute *p_desc = p_char->getDescriptor (j);
151
154
if (p_desc->getUUID () == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
152
155
p_description_descriptor = p_desc;
153
156
userDescriptionDescriptorValuePtr = p_desc->getValuePtr ();
154
157
userDescriptionDescriptorValueLen = p_desc->getLength ();
155
158
}
159
+ if (p_desc->getUUID () == BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT) {
160
+ p_presentation_format_descriptor = p_desc;
161
+ presentationFormatDescriptorValuePtr = p_desc->getValuePtr ();
162
+ presentationFormatDescriptorValueLen = p_desc->getLength ();
163
+ }
156
164
}
157
165
158
166
ASSERT_TRUE ( ERROR_NONE ==
@@ -166,6 +174,8 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
166
174
p_char->getValueAttribute ().hasVariableLength (),
167
175
userDescriptionDescriptorValuePtr,
168
176
userDescriptionDescriptorValueLen,
177
+ presentationFormatDescriptorValuePtr,
178
+ presentationFormatDescriptorValueLen,
169
179
p_char->isReadAuthorizationEnabled (),
170
180
p_char->isWriteAuthorizationEnabled (),
171
181
&nrfCharacteristicHandles[characteristicCount]),
@@ -179,6 +189,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
179
189
nrfCharacteristicHandles[characteristicCount].user_desc_handle
180
190
);
181
191
}
192
+ if (p_presentation_format_descriptor) {
193
+ // The handle is not available from the SoftDevice
194
+ p_presentation_format_descriptor->setHandle (GattAttribute::INVALID_HANDLE);
195
+ }
182
196
characteristicCount++;
183
197
184
198
/* Add optional descriptors if any */
@@ -188,8 +202,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
188
202
}
189
203
190
204
GattAttribute *p_desc = p_char->getDescriptor (j);
191
- /* skip the user-description-descriptor here; this has already been handled when adding the characteristic (above). */
192
- if (p_desc->getUUID () == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
205
+ /* skip the user-description or presentation-format descriptor here;
206
+ * they have already been handled when adding the characteristic (above). */
207
+ if (p_desc->getUUID () == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC
208
+ || p_desc->getUUID () == BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT) {
193
209
continue ;
194
210
}
195
211
0 commit comments