Repository navigation
Expose the GATT status on characteristic and descriptor failures - #41
Merged
Merged
Conversation
CharacteristicReadException, CharacteristicWriteException, DescriptorReadException and DescriptorWriteException gain GattStatus, the GATT status code where one was reported, and GattFailure, which classifies it as InsufficientAuthentication (0x05), InsufficientAuthorization (0x08), InsufficientEncryption (0x0F), Other or None. All four implement the new IGattStatusException, so one catch can recognise a security failure from any of them. Android passes the GattStatus from the read, write and descriptor callbacks. Apple platforms pass the NSError code only when its domain is CBATTErrorDomain, because CBError codes in other domains mean something else. Windows passes the ATT protocol error it already reported. NativeStatus keeps its earlier meaning, including the NSError code whatever its domain on Apple platforms, and every message is unchanged. The new value is set through an added constructor overload, so the existing constructors behave exactly as before. Fixes #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #36.
Stacked on #40 (
feature/bond-request, issue #35), which is itself stacked on #39 (issue #34). This PR merges after #40, and #40 after #39. GitHub retargets each one as the PR below it is merged. The code here does not depend on #39 or #40; it is stacked only so the README and release-note edits do not conflict. The diff shows only the #36 change.Public API (additive only)
enum GattFailure { None, Other, InsufficientAuthentication, InsufficientAuthorization, InsufficientEncryption }interface IGattStatusException { int? GattStatus; GattFailure GattFailure; }, implemented byCharacteristicReadException,CharacteristicWriteException,DescriptorReadExceptionandDescriptorWriteException, so one catch covers all four:GattStatus(int?),GattFailure, and a new constructor overload takinggattStatusafternativeStatus.Where the status comes from
GattStatusGattStatusfromOnCharacteristicRead,OnCharacteristicWrite,OnDescriptorReadandOnDescriptorWriteNSErrorcode, only when its domain isCBATTErrorDomain(CBATTError values are ATT codes).nullfor any other domainA refused subscription arrives as
DescriptorWriteExceptionon Android, because the library writes the configuration descriptor itself, and asCharacteristicReadExceptionon Apple platforms. Both carry the status.GattStatusisnull(GattFailure.None) where no status exists: the operation could not start, or the device disconnected.Unchanged, on purpose
NativeStatuskeeps its meaning. On Apple platforms it is still theNSErrorcode whatever the domain, which is why the ATT-only value is a separate property rather than a reinterpretation of it.GattStatusnull.CharacteristicAuthenticationExceptionfrom the issue is not added. Read, write and descriptor failures have no common base belowBleException, and a derived type of one of them would not catch the others. The interface gives the single catch instead.GATT_ERROR). These areGattFailure.Otherwith the raw value inGattStatus. No mapping of stack-specific codes to the security failures is guessed at.README / release notes
The README Bonding section gains "Recognising a security failure", with the catch example and the per-platform subscribe note.
PackageReleaseNotesextends the "Unreleased" paragraph.Verification
GattStatusnull withNativeStatusand messages unchanged, and that the interface catch pattern works.