Skip to content

Developer overview

CDC Badge OS is firmware for the CDC Badge v1.0 hardware security key. This section documents the firmware internals for developers: the component model, the build and flash workflow, and the host API that third-party plugins call into.

The firmware targets the ESP32-S3 and is built with the ESP-IDF framework, driven through PlatformIO.

  • Framework: ESP-IDF (framework = espidf), via the espressif32 platform.
  • Build environment: cdc_badge_usb, board cdc-badge-usb, 16 MB flash, PSRAM enabled.
  • Language standard: C++17 (-std=gnu++17).

These are defined in platformio.ini. See Build and flash for the full command set and partition layout.

The firmware is split into ESP-IDF components. Lower layers know nothing about the layers above them, and the core components never reference feature modules.

LayerComponent(s)Responsibility
Applicationmain/Boot sequence, service wiring, module registration
OS UIcdc_os_uiLock screen, settings, top-level app UI (AppUi)
Reusable viewscdc_viewsList, slider, PIN entry, T9, QR, and other view components
UI frameworkcdc_uiIView, ViewStack, I18n
Feature modulesmod_*Self-contained features (FIDO2, 2FA, password, GPG, and more)
Messagingcdc_msgGeneric badge-to-badge BLE message transfer
Pluginsplugin_manager, wamr_runtimeSandboxed WASM plugin runtime and host API
Serial and USBserial_cmd, usb_badgeSerial command console and USB CDC/HID
Hardware abstractioncdc_halInterfaces for display, keypad, power, secure element, BLE, WiFi, sleep, RTC, buses
Corecdc_coreServiceRegistry, EventBus, ModuleRegistry, PinManager, IModule

The full responsibility breakdown, with the interface that defines each piece, is in Architecture.

This repository is the canonical source of the plugin host API. The Rust plugin SDK lives in a separate sibling repository that consumes a copy of the host API header.

RepoPurposeHost API role
cdc-badge-os (this)Firmware and canonical host_api.hSource of truth
cdc-badge-pluginsRust plugin SDK, examples, web installerConsumes a copy of host_api.h

The canonical header is components/plugin_manager/include/plugin_manager/host_api.h. The SDK copy must stay byte-identical to it, so any change to the host API surface (signatures, error codes, level constants) has to be committed in both repositories together. The firmware repository’s upstream remote is ssh://git@codeberg.org/Krim/cdc-badge-os.git.

  • Architecture: the component model, module isolation, and the IModule lifecycle.
  • Build and flash: the PlatformIO build, the MODULES-list mechanism, partition layout, and the memory model.
  • Host API: the C ABI that plugins call into.
  • Architecture Decision Records: the load-bearing technical decisions (PSRAM-first, module isolation, slot map, the two-KDF PIN hashing, plugin sandbox, and more).
  • Refactoring backlog: documented-only refactors not yet executed.

Host-side unit tests for portable logic (CRC, base64, CP437, message framing, CBOR) run via the PlatformIO native environment with pio test -e native (no hardware, runs in CI). Hardware and protocol behaviour is covered by documented hardware-in-the-loop test plans. The first automated tests and the spec-driven baseline live under specs/001-current-system-spec/.