BleCentralHal

interface BleCentralHal

Low-level BLE Central Hardware Abstraction Layer (HAL) used to back BLE mdoc transports.

All ISO/IEC 18013-5 protocol state machines, continuation management, retry/backoff loops, BLEIdent HKDF verification, GATT message chunking/reassembly, and L2CAP 4-byte length-prefixed framing are handled by Multipaz's shared BLE central manager. Implementations of this interface perform low-level Bluetooth central operations and forward asynchronous events to Callback.

Types

Link copied to clipboard
interface Callback

Asynchronous callbacks invoked by a BleCentralHal implementation.

Properties

Link copied to clipboard
abstract val isConnected: Boolean

Whether a connection to the peripheral has already been established.

Functions

Link copied to clipboard
abstract fun close()

Immediately closes the HAL and releases any underlying resources.

Link copied to clipboard

Cleans up any partially established L2CAP channel attempt before retrying.

Link copied to clipboard
abstract fun connectL2cap(psm: Int)

Initiates an L2CAP Connection-Oriented Channel to psm on the peripheral.

Link copied to clipboard
abstract fun connectToPeripheral()

Initiates a BLE connection to the discovered peripheral.

Link copied to clipboard
abstract fun discoverCharacteristics(stateCharacteristicUuid: UUID, client2ServerCharacteristicUuid: UUID, server2ClientCharacteristicUuid: UUID, identCharacteristicUuid: UUID?, l2capCharacteristicUuid: UUID?)

Discovers the ISO/IEC 18013-5 GATT characteristics on the connected peripheral.

Link copied to clipboard
abstract fun discoverServices(serviceUuid: UUID)

Discovers GATT services on the connected peripheral, checking for serviceUuid.

Link copied to clipboard
abstract fun enableNotifications(characteristicUuid: UUID)

Enables GATT notifications on characteristicUuid by writing its CCCD.

Link copied to clipboard

Notifies the HAL that scanning has been stopped after discovering the target peripheral.

Link copied to clipboard
abstract fun readCharacteristic(uuid: UUID)

Reads the GATT characteristic with uuid.

Link copied to clipboard
abstract fun requestMtu(mtu: Int)

Requests a GATT ATT MTU of mtu bytes.

Link copied to clipboard
abstract fun setCallback(callback: BleCentralHal.Callback)

Registers the Callback receiver for asynchronous BLE central events.

Link copied to clipboard
open suspend fun shutdown()

Gracefully shuts down active BLE central connections/controllers before close.

Link copied to clipboard
abstract fun startScan(serviceUuid: UUID)

Starts scanning for peripherals advertising serviceUuid.

Link copied to clipboard
abstract fun stopScan()

Stops an active BLE scan.

Link copied to clipboard
abstract fun waitForPowerOn()

Checks or waits for the BLE central radio/stack to power on, reporting via Callback.onPowerOn.

Link copied to clipboard
abstract fun writeCharacteristic(uuid: UUID, value: ByteArray)

Writes value to the GATT characteristic with uuid (using Write Without Response or Write With Response according to the characteristic's properties) and invokes Callback.onCharacteristicWrite when completed.