Skip to content

Commit de759d4

Browse files
committed
Fix find info resp when called on non-descriptor attributes
Before this fix, if the 'ATT information request' was called on an handle belonging to a non-descriptor attribute, then the response would contain the uuid of the actual attribute's type but with the format of the attribute uuid (0x01 for 16 bit length, 0x02 for 128 bit length). So, for instance, if the info request was performed on an handle belonging to a service with a uuid of 128 bit, then the response would have been malformed because the size of the attribute's type is 16 bit.
1 parent 840501e commit de759d4

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/local/BLELocalAttribute.h

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "utility/BLEUuid.h"
2424

25+
#define BLE_ATTRIBUTE_TYPE_SIZE 2
26+
2527
enum BLEAttributeType {
2628
BLETypeUnknown = 0x0000,
2729

src/utility/ATT.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,8 @@ void ATTClass::findInfoReq(uint16_t connectionHandle, uint16_t mtu, uint8_t dlen
683683
BLELocalAttribute* attribute = GATT.attribute(i);
684684
uint16_t handle = (i + 1);
685685
bool isValueHandle = (attribute->type() == BLETypeCharacteristic) && (((BLELocalCharacteristic*)attribute)->valueHandle() == handle);
686-
int uuidLen = isValueHandle ? 2 : attribute->uuidLength();
686+
bool isDescriptor = attribute->type() == BLETypeDescriptor;
687+
int uuidLen = (isValueHandle || isDescriptor) ? attribute->uuidLength() : BLE_ATTRIBUTE_TYPE_SIZE;
687688
int infoType = (uuidLen == 2) ? 0x01 : 0x02;
688689

689690
if (response[1] == 0) {
@@ -699,7 +700,7 @@ void ATTClass::findInfoReq(uint16_t connectionHandle, uint16_t mtu, uint8_t dlen
699700
memcpy(&response[responseLength], &handle, sizeof(handle));
700701
responseLength += sizeof(handle);
701702

702-
if (isValueHandle || attribute->type() == BLETypeDescriptor) {
703+
if (isValueHandle || isDescriptor) {
703704
// add the UUID
704705
memcpy(&response[responseLength], attribute->uuidData(), uuidLen);
705706
responseLength += uuidLen;

0 commit comments

Comments
 (0)