# rfidresearchgroup/chameleonultra architecture

> Architecture diagram of the GitHub repository rfidresearchgroup/chameleonultra, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rfidresearchgroup/chameleonultra
- Repository: https://github.com/rfidresearchgroup/chameleonultra

## Overview

1. **Project shape**
   - This repository is a full product stack for the ChameleonUltra RFID device: embedded firmware, host-side tooling, hardware reference files, and documentation.
   - The architectural center is the **firmware** for an nRF52-based device; the other directories support flashing, control, and card-key recovery workflows.

2. **Device runtime split: bootloader vs application**
   - `firmware/bootloader` is a separate DFU-capable bootloader image.
   - `firmware/application` is the main product firmware.
   - The boundary is important: the bootloader handles secure firmware update and image validation, while the application owns all product behavior.

3. **Embedded platform layer**
   - The firmware is built on Nordic’s **nRF5 SDK** (`firmware/nrf52_sdk`) plus local common code in `firmware/common`.
   - These layers provide the SoC runtime, SoftDevice/BLE integration, USB/device drivers, logging, timers, flash storage, and low-level board support.
   - The application code sits on top of this SDK layer and should be treated as the product-specific logic.

4. **Main application responsibilities**
   - `firmware/application/src/app_main.c`, `rfid_main.c`, `ble_main.c`, `usb_main.c`, and `settings.c` indicate the application is split into:
     - device initialization and lifecycle
     - BLE transport
     - USB transport
     - RFID functionality
     - persistent settings/state
   - `app_cmd.*` and `data_cmd.h` suggest a command-driven core, with transport adapters feeding a shared command/data path.

5. **RFID subsystem**
   - The largest application subtree is `firmware/application/src/rfid`, showing this is the core product function.
   - It is organized into:
     - **reader** code for interacting with tags/cards
     - **nfctag** code for tag emulation
     - protocol utilities such as parity, CRC, byte/hex helpers, and Crypto1-related code
   - This subsystem is split by frequency band and protocol family:
     - **HF/NFC**: MIFARE/NFC-A/NTAG-style handling
     - **LF/125 kHz**: EM410x, HID Prox, ioprox, Viking, PAC, Wiegand, T55xx-related flows
   - The architecture implies a protocol dispatcher above hardware radio primitives and protocol-specific codecs below it.

6. **RFID data flow**
   - The hardware-facing radio code captures or transmits signal frames.
   - Protocol decoders/encoders translate those frames into structured tag/reader data.
   - Tag emulation modules then replay or synthesize responses based on stored tag state.
   - Persistence (`tag_persistence.c`) indicates emulated tag profiles can survive resets via flash-backed storage.

7. **Wireless and USB transport boundaries**
   - `ble_main.c` and `usb_main.c` are transport front ends, not the domain logic itself.
   - They likely bridge the device’s internal command/data model to host clients over:
     - **BLE** for mobile/desktop companion apps
     - **USB** for CLI and wired tooling
   - This keeps transport concerns separate from RFID and device-state logic.

8. **State, storage, and system services**
   - `settings.c`, `utils/fds_util.c`, `utils/delayed_reset.c`, `utils/timeslot.c`, `utils/syssleep.c`, and the `bsp` helpers show a set of shared services for:
     - nonvolatile settings
     - flash storage
     - reset/power management
     - timing and radio coexistence
   - These are the main cross-cutting infrastructure pieces used by RFID, BLE, and USB modules.

9. **Host-side software stack**
   - `software/` contains the companion tooling used to talk to the device and perform offline cryptographic attacks/recovery.
   - `software/script` is a Python-based CLI and communication layer.
   - `software/src` is a native C/CMake codebase containing RFID attack/recovery algorithms, especially **hardnested** and **nested** MIFARE-related tooling.
   - The host software is therefore not just a UI; it is a computational backend for card-key recovery and device orchestration.

10. **Host/device interaction model**
    - The Python layer (`chameleon_cli_main.py`, `chameleon_com.py`, `chameleon_cmd.py`) appears to be the primary control plane for issuing commands to the device.
    - The native C code in `software/src/HardnestedRecovery` and related files provides the heavier cryptanalysis algorithms that complement the embedded device’s capture/emulation capabilities.
    - So the system boundary is: **device firmware handles live RFID operations; host software handles control and expensive offline computation**.

11. **Key distribution and update infrastructure**
    - `resource/dfu_key/chameleon.pem` and the DFU scripts show a signed-update pipeline.
    - `resource/tools/enter_dfu.py` and `enter_dfu_over_ble.py` imply multiple update entry paths: USB and BLE.
    - This means firmware updates are a first-class architectural path, not an afterthought.

12. **Hardware boundary**
    - `hardware/lite`, `hardware/ultra`, and `hardware/dev-tools` contain reference schematics/packaging documents and zips.
    - These are not executable components, but they define the physical hardware variants the firmware must support.
    - The repo therefore spans both product firmware and board-specific hardware definitions.

13. **Build and release orchestration**
    - GitHub Actions workflows cover firmware builds, client builds, Python checks, changelog reminders, wiki deployment, and PR/push validation.
    - The `firmware/Dockerfile` and build scripts indicate a containerized/reproducible firmware toolchain.
    - Architecture-wise, this is a multi-artifact repo: firmware images, host tools, docs, and packaged hardware assets are all produced from the same source tree.

14. **Overall system view**
    - The clearest diagram is a three-tier model:
      - **Hardware device**: nRF52 board running bootloader + application
      - **Transport/control clients**: BLE/USB host tools and mobile/desktop apps
      - **Offline tooling**: Python/C recovery and CLI utilities
    - The primary data path is RFID signal acquisition/emulation on-device, with command/control and key-recovery flows coming in from host tools.

Main entry points: [`firmware/application/src/app_main.c`](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/app_main.c) (App Core), [`firmware/bootloader/src/main.c`](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/bootloader/src/main.c) (Bootloader), [`firmware/application/src/app_cmd.c`](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/app_cmd.c) (Command Core), [`.github/workflows/build_firmware.yml`](https://github.com/rfidresearchgroup/chameleonultra/blob/main/.github/workflows/build_firmware.yml) (CI / Build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Firmware"]
  node_bootloader["Bootloader<br/>dfu boot image<br/>[main.c]"]
  node_app_main["App Core<br/>device runtime<br/>[app_main.c]"]
  node_app_cmd["Command Core<br/>command router<br/>[app_cmd.c]"]
  node_ble_main["BLE Transport<br/>transport adapter<br/>[ble_main.c]"]
  node_usb_main["USB Transport<br/>transport adapter<br/>[usb_main.c]"]
  node_rfid_main["RFID Runtime<br/>rfid orchestration<br/>[rfid_main.c]"]
  node_rfid_reader["Readers<br/>rfid capture"]
  node_rfid_emu["Tag Emu<br/>rfid emulation"]
  node_rfid_proto["Protocols<br/>protocol codec<br/>[crc_utils.c]"]
  node_settings["Settings<br/>persistent state<br/>[settings.c]"]
  node_platform["Platform<br/>sdk layer<br/>[hw_connect.c]"]
end

subgraph group_host["Host Tools"]
  node_cli["Python CLI<br/>host control plane"]
  node_recovery["Recovery Core<br/>native crypto<br/>[hardnested_main.c]"]
  node_host_crypto["Legacy Crypto<br/>crypto utilities<br/>[crypto1.c]"]
end

subgraph group_assets["Assets"]
  node_dfu_tools["DFU Tools<br/>update tooling<br/>[enter_dfu.py]"]
  node_dfu_key["DFU Key<br/>signing asset<br/>[chameleon.pem]"]
  node_hardware["Hardware<br/>board refs"]
end

subgraph group_ops["Build Ops"]
  node_ci["CI / Build<br/>build automation<br/>[build_firmware.yml]"]
end

node_bootloader -->|"validates"| node_dfu_key
node_bootloader -->|"hands off"| node_app_main
node_app_main -->|"runs on"| node_platform
node_app_main -->|"hosts"| node_app_cmd
node_app_main -->|"starts"| node_rfid_main
node_app_main -->|"enables"| node_ble_main
node_app_main -->|"enables"| node_usb_main
node_ble_main -->|"bridges"| node_app_cmd
node_usb_main -->|"bridges"| node_app_cmd
node_rfid_main -->|"orchestrates"| node_rfid_reader
node_rfid_main -->|"orchestrates"| node_rfid_emu
node_rfid_reader -->|"decodes"| node_rfid_proto
node_rfid_emu -->|"encodes"| node_rfid_proto
node_rfid_emu -->|"persists"| node_settings
node_settings -->|"stores in"| node_platform
node_cli -->|"controls"| node_app_cmd
node_cli -->|"invokes"| node_recovery
node_recovery -->|"uses"| node_host_crypto
node_dfu_tools -->|"enters"| node_bootloader
node_ci -->|"builds"| node_bootloader
node_ci -->|"builds"| node_app_main
node_ci -->|"builds"| node_cli
node_hardware -->|"targets"| node_platform

click node_bootloader "https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/bootloader/src/main.c"
click node_app_main "https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/app_main.c"
click node_app_cmd "https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/app_cmd.c"
click node_ble_main "https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/ble_main.c"
click node_usb_main "https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/usb_main.c"
click node_rfid_main "https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/rfid_main.c"
click node_rfid_reader "https://github.com/rfidresearchgroup/chameleonultra/tree/main/firmware/application/src/rfid/reader"
click node_rfid_emu "https://github.com/rfidresearchgroup/chameleonultra/tree/main/firmware/application/src/rfid/nfctag"
click node_rfid_proto "https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/rfid/crc_utils.c"
click node_settings "https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/settings.c"
click node_platform "https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/common/hw_connect.c"
click node_cli "https://github.com/rfidresearchgroup/chameleonultra/blob/main/software/script/chameleon_cli_main.py"
click node_recovery "https://github.com/rfidresearchgroup/chameleonultra/blob/main/software/src/HardnestedRecovery/hardnested_main.c"
click node_host_crypto "https://github.com/rfidresearchgroup/chameleonultra/blob/main/software/src/crypto1.c"
click node_dfu_tools "https://github.com/rfidresearchgroup/chameleonultra/blob/main/resource/tools/enter_dfu.py"
click node_dfu_key "https://github.com/rfidresearchgroup/chameleonultra/blob/main/resource/dfu_key/chameleon.pem"
click node_hardware "https://github.com/rfidresearchgroup/chameleonultra/blob/main/hardware/ultra/Chameleon_nrf52_ultra_V1.0.pdf"
click node_ci "https://github.com/rfidresearchgroup/chameleonultra/blob/main/.github/workflows/build_firmware.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_bootloader,node_app_main,node_app_cmd,node_ble_main,node_usb_main,node_rfid_main,node_rfid_reader,node_rfid_emu,node_rfid_proto,node_settings,node_platform toneBlue
class node_cli,node_recovery,node_host_crypto toneAmber
class node_dfu_tools,node_dfu_key,node_hardware toneMint
class node_ci toneRose
```

## Components

### Firmware

Device-side bootloader, application, and embedded platform layer

- [Bootloader](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/bootloader/src/main.c): dfu boot image · Signed update bootloader with image validation and startup handoff · `firmware/bootloader/src/main.c`
- [App Core](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/app_main.c): device runtime · Main product firmware entrypoint and lifecycle · `firmware/application/src/app_main.c`
- [Command Core](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/app_cmd.c): command router · Shared command/data dispatch for transports and device actions · `firmware/application/src/app_cmd.c`
- [BLE Transport](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/ble_main.c): transport adapter · Bluetooth control and data front end · `firmware/application/src/ble_main.c`
- [USB Transport](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/usb_main.c): transport adapter · USB control and wired host front end · `firmware/application/src/usb_main.c`
- [RFID Runtime](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/rfid_main.c): rfid orchestration · Top-level RFID lifecycle and mode coordination · `firmware/application/src/rfid_main.c`
- [Readers](https://github.com/rfidresearchgroup/chameleonultra/tree/main/firmware/application/src/rfid/reader): rfid capture · HF and LF reader-side radio capture and decoding · `firmware/application/src/rfid/reader`
- [Tag Emu](https://github.com/rfidresearchgroup/chameleonultra/tree/main/firmware/application/src/rfid/nfctag): rfid emulation · HF/LF tag emulation and replay state machines · `firmware/application/src/rfid/nfctag`
- [Protocols](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/rfid/crc_utils.c): protocol codec · Parity, CRC, Crypto1, and protocol helpers · `firmware/application/src/rfid/crc_utils.c`
- [Settings](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/application/src/settings.c): persistent state · Device configuration and flash-backed state · `firmware/application/src/settings.c`
- [Platform](https://github.com/rfidresearchgroup/chameleonultra/blob/main/firmware/common/hw_connect.c): sdk layer · nRF5 SDK, common board support, storage, timing, logging, and BLE/USB drivers · `firmware/common/hw_connect.c`

### Host Tools

Python CLI and native recovery tooling

- [Python CLI](https://github.com/rfidresearchgroup/chameleonultra/blob/main/software/script/chameleon_cli_main.py): host control plane · Primary host command interface and device communication layer · `software/script/chameleon_cli_main.py`
- [Recovery Core](https://github.com/rfidresearchgroup/chameleonultra/blob/main/software/src/HardnestedRecovery/hardnested_main.c): native crypto · Offline nested and hardnested key recovery algorithms · `software/src/HardnestedRecovery/hardnested_main.c`
- [Legacy Crypto](https://github.com/rfidresearchgroup/chameleonultra/blob/main/software/src/crypto1.c): crypto utilities · Shared host-side MIFARE Crypto1 and attack helpers · `software/src/crypto1.c`

### Assets

Hardware references, DFU keys, and packaging artifacts

- [DFU Tools](https://github.com/rfidresearchgroup/chameleonultra/blob/main/resource/tools/enter_dfu.py): update tooling · Scripts for entering DFU mode and driving signed updates · `resource/tools/enter_dfu.py`
- [DFU Key](https://github.com/rfidresearchgroup/chameleonultra/blob/main/resource/dfu_key/chameleon.pem): signing asset · Firmware signing key material for update validation · `resource/dfu_key/chameleon.pem`
- [Hardware](https://github.com/rfidresearchgroup/chameleonultra/blob/main/hardware/ultra/Chameleon_nrf52_ultra_V1.0.pdf): board refs · Reference designs and packaged board variants · `hardware/ultra/Chameleon_nrf52_ultra_V1.0.pdf`

### Build Ops

Container, scripts, and CI workflows

- [CI / Build](https://github.com/rfidresearchgroup/chameleonultra/blob/main/.github/workflows/build_firmware.yml): build automation · Repository workflows and containerized build orchestration · `.github/workflows/build_firmware.yml`

## Connections

- Bootloader → DFU Key: validates · Bootloader uses signing key material to validate update images
- Bootloader → App Core: hands off · Bootloader starts the main application after DFU checks
- App Core → Platform: runs on · Application depends on Nordic SDK and common platform services
- App Core → Command Core: hosts · Device lifecycle initializes the shared command/data core
- App Core → RFID Runtime: starts · Product runtime enters RFID control paths
- App Core → BLE Transport: enables · Application brings up BLE transport
- App Core → USB Transport: enables · Application brings up USB transport
- BLE Transport → Command Core: bridges · BLE forwards host commands into the shared device model
- USB Transport → Command Core: bridges · USB forwards wired commands into the shared device model
- RFID Runtime → Readers: orchestrates · RFID runtime coordinates capture and decode flows
- RFID Runtime → Tag Emu: orchestrates · RFID runtime coordinates emulation flows
- Readers → Protocols: decodes · Reader-side raw frames are translated by protocol helpers
- Tag Emu → Protocols: encodes · Emulation synthesizes responses through protocol helpers
- Tag Emu → Settings: persists · Tag profiles and emulation state are stored across resets
- Settings → Platform: stores in · Persistent state relies on flash storage and system services
- Python CLI → Command Core: controls · Python CLI issues commands to the device
- Python CLI → Recovery Core: invokes · CLI workflows can hand off to offline key recovery
- Recovery Core → Legacy Crypto: uses · Native recovery algorithms share Crypto1-related code
- DFU Tools → Bootloader: enters · Update scripts trigger DFU mode for bootloader-based flashing
- CI / Build → Bootloader: builds · CI produces bootloader artifacts
- CI / Build → App Core: builds · CI produces application firmware artifacts
- CI / Build → Python CLI: builds · CI validates host tooling artifacts
- Hardware → Platform: targets · Hardware variants define the supported board boundary for firmware
