Blue-Falcon

Kotlin Multiplatform BLE library for iOS, Android, macos, windows and javascript

View the Project on GitHub Reedyuk/blue-falcon

ADR 0005: BLE Device Cloning Plugin

Status: ✅ Implemented

Date: 2026-05-15

Deciders: Andrew Reed, Community Contributors

Technical Story: Feature request to clone a BLE device — capturing advertisement data, services, characteristics, and descriptors into a portable snapshot that can be replayed or used for testing/simulation.

Context

During development and testing of BLE applications, engineers frequently need to:

  1. Capture a device profile for offline development when the physical hardware is unavailable.
  2. Reproduce issues by sharing exact device snapshots with team members who don’t have the hardware.
  3. Create test fixtures that represent real-world device topologies (services, characteristics, descriptors, and their values).
  4. Audit devices by taking full snapshots of advertisement payloads and GATT tables for analysis.

Currently, there is no built-in way to capture a full device profile (advertisement info + GATT table) through Blue Falcon. Developers resort to manual note-taking, platform-specific tools (nRF Connect, LightBlue), or custom one-off scripts.

With the plugin architecture from ADR 0002, we can provide this as an optional plugin that hooks into discovery, connection, and characteristic read events to build a complete device clone.

What “Cloning” Means

A BLE device clone in this context is a read-only snapshot containing:

This is not about spoofing or impersonating a BLE device on the radio layer — it is a data capture for development, testing, and documentation purposes.

Decision

We will implement a BLE device cloning plugin (blue-falcon-plugin-clone) that captures a complete snapshot of a connected BLE peripheral’s advertisement data and GATT table.

The plugin will:

  1. Follow the existing plugin pattern established by ADR 0002 (interceptor hooks, plugin lifecycle).
  2. Capture advertisement data during scan/discovery by hooking into peripheral discovery events.
  3. Capture the full GATT table after connection and service/characteristic discovery completes, by reading all readable characteristics and descriptors.
  4. Produce a serializable DeviceClone data model that can be exported to JSON and re-imported.
  5. Support selective cloning — users can choose to clone only advertisement data, only GATT structure, or a full deep clone (including reading all characteristic/descriptor values).
  6. Provide a CloneCallback interface for progress reporting (useful when reading many characteristics sequentially).
  7. Operate cross-platform using only Blue Falcon’s core BLE operations (scan, connect, discoverServices, readCharacteristic, readDescriptor).

Data Model

@Serializable
data class DeviceClone(
    val peripheralId: String,
    val peripheralName: String?,
    val capturedAt: String, // ISO-8601 timestamp
    val platform: String,
    val rssi: Float?,
    val mtuSize: Int?,
    val advertisement: AdvertisementClone,
    val services: List<ServiceClone>
)

@Serializable
data class AdvertisementClone(
    val localName: String?,
    val manufacturerData: ByteArray?,
    val serviceUuids: List<String>,
    val txPowerLevel: Int?
)

@Serializable
data class ServiceClone(
    val uuid: String,
    val name: String?,
    val characteristics: List<CharacteristicClone>
)

@Serializable
data class CharacteristicClone(
    val uuid: String,
    val name: String?,
    val properties: List<String>, // e.g. ["read", "write", "notify"]
    val value: ByteArray?,
    val descriptors: List<DescriptorClone>
)

@Serializable
data class DescriptorClone(
    val uuid: String,
    val value: ByteArray?
)

Plugin API

class DeviceClonePlugin(
    private val config: CloneConfig = CloneConfig()
) : BlueFalconPlugin {

    suspend fun cloneDevice(peripheral: BluetoothPeripheral): DeviceClone

    fun exportToJson(clone: DeviceClone): String
    fun importFromJson(json: String): DeviceClone
}

data class CloneConfig(
    val readCharacteristicValues: Boolean = true,
    val readDescriptorValues: Boolean = true,
    val includeAdvertisementData: Boolean = true,
    val readTimeoutMs: Long = 5000,
    val callback: CloneCallback? = null
)

interface CloneCallback {
    fun onCloneProgress(current: Int, total: Int, message: String)
    fun onCloneComplete(clone: DeviceClone)
    fun onCloneError(error: Throwable)
}

Consequences

Positive

Negative

Neutral

Alternatives Considered

Alternative 1: Built-in Core Feature

Add cloning directly to the core BlueFalcon class.

Pros:

Cons:

Why not chosen: The plugin architecture exists precisely for optional features like this.

Alternative 2: Export-Only (No Data Model)

Simply dump raw platform-specific GATT data to a log or text format.

Pros:

Cons:

Why not chosen: A structured, serializable data model is essential for the use cases (testing, sharing, future simulation).

Alternative 3: Platform-Specific Clone Tools

Recommend users use nRF Connect, LightBlue, or similar platform tools.

Pros:

Cons:

Why not chosen: Integration with Blue Falcon’s plugin system enables programmatic use within applications, CI pipelines, and test frameworks.

Implementation Notes

References