Repository navigation
Secure DFU: handle an error reply to Calculate Checksum instead of throwing in the GATT callback - #529
Open
niklavsBariss wants to merge 1 commit into
Conversation
…rowing in the GATT callback
This branch has not been deployed
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.
Problem
The Calculate Checksum branch of
SecureBluetoothCallback.onCharacteristicChangedreads the offset and CRC without checking the status byte. An error reply (60 03 <status>) has neither, sogetIntValuereturnsnulland the callback throws.BluetoothGattswallows it, the reply is lost, and the upload waits until the target drops the link.How it shows up
Fix
This PR makes an error reply to Calculate Checksum fail the upload with that remote error instead of stalling it. An error goes to the waiting thread like other replies, so
readChecksumreports it as aRemoteDfuException. A reply too short for its status is an invalid response:readChecksumreads an extended error's code fromresponse[3], and an exception there on the service thread would crash the app. The fields come from the notification'svalue, which on Android 13+ the characteristic isn't guaranteed to match.Verified
Xiaomi 14T (Android 16), 2.4.2 from source, with a fault that replaces one checksum reply with
60 03 08. Without the change, the NPE and a stalled upload; with it,Receiving Checksum failed (error 8): OPERATION NOT PERMITTEDand a cleanDFU_FAILED. The short-extended-error check is compile-checked only.