SecureDfuTransport

class SecureDfuTransport(scanner: BleScanner, connectionFactory: BleConnectionFactory, address: String, dispatcher: CoroutineDispatcher) : DfuUploadTransport(source)

Kable-based transport for the Nordic Secure DFU (Secure DFU over BLE) protocol.

Usage:

  1. triggerButtonlessDfu — connect to the device in normal mode and trigger reboot into DFU mode.

  2. connectToDfuMode — scan for the device in DFU mode and establish the DFU GATT session.

  3. transferInitPacket / transferFirmware — send .dat then .bin.

  4. abort — send ABORT to the device before closing (on cancellation or error).

  5. close — tear down the connection.

Constructors

Link copied to clipboard
constructor(scanner: BleScanner, connectionFactory: BleConnectionFactory, address: String, dispatcher: CoroutineDispatcher)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open suspend override fun abort()

Sends the ABORT opcode to the device, instructing it to discard any in-progress transfer and return to an idle state. Best-effort — never throws.

Link copied to clipboard
open suspend override fun close()

Disconnect from the DFU target and cancel the transport coroutine scope.

Link copied to clipboard
open suspend override fun connectToDfuMode(): Result<Unit>

Scans for the device in DFU mode (address or address+1) and establishes the GATT connection, enabling notifications on the Control Point.

Link copied to clipboard
open suspend override fun transferFirmware(firmware: ByteArray, onProgress: suspend (Float) -> Unit): Result<Unit>

Sends the firmware binary (.bin file) using the DFU object-transfer protocol.

Link copied to clipboard
open suspend override fun transferInitPacket(initPacket: ByteArray): Result<Unit>

Sends the DFU init packet (.dat file). The device verifies this against the bootloader's security requirements before accepting firmware.

Link copied to clipboard

Connects to the device running normal firmware and writes to the Buttonless DFU characteristic so the bootloader takes over. The device disconnects and reboots.