Skip to content

Fix find info resp when called on non-descriptor attributes #148

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

Merged
merged 1 commit into from
Dec 14, 2020

Conversation

polldo
Copy link
Contributor

@polldo polldo commented Dec 10, 2020

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.

From issue discovered by @ThomasGerstenberg
#147

@@ -683,7 +683,8 @@ void ATTClass::findInfoReq(uint16_t connectionHandle, uint16_t mtu, uint8_t dlen
BLELocalAttribute* attribute = GATT.attribute(i);
uint16_t handle = (i + 1);
bool isValueHandle = (attribute->type() == BLETypeCharacteristic) && (((BLELocalCharacteristic*)attribute)->valueHandle() == handle);
int uuidLen = isValueHandle ? 2 : attribute->uuidLength();
bool isDescriptor = attribute->type() == BLETypeDescriptor;
int uuidLen = isValueHandle ? 2 : (isDescriptor ? attribute->uuidLength() : BLE_ATTRIBUTE_TYPE_SIZE);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. If it's a value handle, it should use the attribute's UUID length right?

If we align it with the if logic on 703, value and descriptor handles memcpy the UUID data, so the uuidLen should reflect as such. Otherwise use the type size of 2

int uuidLen = (isValueHandle || isDescriptor) ? attribute->uuidLength() : BLE_ATTRIBUTE_TYPE_SIZE;
// also can update the if on 703 to match
if (isValueHandle || isDescriptor) {
    // add the UUID
} else {
    // add the type
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're definitely right!
I'm going to update the PR

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.
@polldo polldo force-pushed the fix-find-info-resp branch from 4589b0e to de759d4 Compare December 11, 2020 10:46
Copy link

@ThomasGerstenberg ThomasGerstenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested fix and it works 👍

Capture of handle 0x0e being discovered as a 16-bit uuid
image

@polldo polldo merged commit 953f973 into arduino-libraries:master Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants