Skip to content

BLE support in emulator#4838

Merged
mmilata merged 4 commits intomainfrom
mmilata/ble-unix
Oct 29, 2025
Merged

BLE support in emulator#4838
mmilata merged 4 commits intomainfrom
mmilata/ble-unix

Conversation

@mmilata
Copy link
Copy Markdown
Member

@mmilata mmilata commented Mar 27, 2025

🐧🐧🐧 Linux-only 🐧🐧🐧

Consists of:

  • exposing core BLE interface to the outside as two UDP sockets, no connection state handling
  • trezorlib transport that talks to these sockets - as there is no connection state handling it might be useful for writing tests for e.g. misbehaving nRF but not much else
  • python script that launches dbus-daemon and a mock Linux BLE API on it - using env variable you can convince Suite/trezorlib to talk to it instead of the actual BLE devices

Usage:

  • start emu.py
  • start core/tools/bluez-emu-bridge.py -v
  • override dbus socket path export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/tmp/dbus-bluez-emu-bridge
  • run Suite in the same environment ⬆️
  • same environment variable also works for trezorctl -B -p ble: ... commands

TBD in following PR(s):

  • launch DBus api from emu.py
  • configurable DBus listen address
    • needed for multicore tests
    • might be easier for trezor-user-env to expose a port than unix socket
  • t-u-e integration
  • add device test for e.g. pairing flow

@github-project-automation github-project-automation Bot moved this to 🔎 Needs review in Firmware Mar 27, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 27, 2025

en main(all)

model device_test click_test persistence_test
T2T1 test(all) main(all) test(all) main(all) test(all) main(all)
T3B1 test(all) main(all) test(all) main(all) test(all) main(all)
T3T1 test(all) main(all) test(all) main(all) test(all) main(all)
T3W1 test(all) main(all) test(all) main(all) test(all) main(all)
Translations

cs main(all)

model device_test click_test
T2T1 test(all) main(all) test(all) main(all)
T3B1 test(all) main(all) test(all) main(all)
T3T1 test(all) main(all) test(all) main(all)
T3W1 test(all) main(all) test(all) main(all)

de main(all)

model device_test click_test
T2T1 test(all) main(all) test(all) main(all)
T3B1 test(all) main(all) test(all) main(all)
T3T1 test(all) main(all) test(all) main(all)
T3W1 test(all) main(all) test(all) main(all)

es main(all)

model device_test click_test
T2T1 test(all) main(all) test(all) main(all)
T3B1 test(all) main(all) test(all) main(all)
T3T1 test(all) main(all) test(all) main(all)
T3W1 test(all) main(all) test(all) main(all)

fr main(all)

model device_test click_test
T2T1 test(all) main(all) test(all) main(all)
T3B1 test(all) main(all) test(all) main(all)
T3T1 test(all) main(all) test(all) main(all)
T3W1 test(all) main(all) test(all) main(all)

pt main(all)

model device_test click_test
T2T1 test(all) main(all) test(all) main(all)
T3B1 test(all) main(all) test(all) main(all)
T3T1 test(all) main(all) test(all) main(all)
T3W1 test(all) main(all) test(all) main(all)

Latest CI run: 18919133241

@M1nd3r M1nd3r force-pushed the m1nd3r/thp-trezorlib branch from 3cb9f35 to 8866c8e Compare March 27, 2025 12:06
@mmilata mmilata force-pushed the mmilata/ble-unix branch 3 times, most recently from 5315ffc to 8665cf6 Compare March 30, 2025 20:41
@M1nd3r M1nd3r force-pushed the m1nd3r/thp-trezorlib branch 2 times, most recently from 4d0bb99 to a5afe1e Compare April 7, 2025 17:33
@mmilata mmilata force-pushed the mmilata/ble-unix branch from 8665cf6 to df5a2a9 Compare April 8, 2025 14:59
@mmilata mmilata changed the base branch from m1nd3r/thp-trezorlib to main April 8, 2025 14:59
@mmilata mmilata force-pushed the mmilata/ble-unix branch 2 times, most recently from 5aa68e9 to 7d787fb Compare October 24, 2025 14:58
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Oct 24, 2025

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

@mmilata mmilata marked this pull request as ready for review October 25, 2025 21:36
@mmilata mmilata self-assigned this Oct 25, 2025
@mmilata mmilata added core Trezor Core firmware. Runs on Trezor Model T and Safe models. emulator only Issue which does not appear on the physical device - but on emulator only. T3W1 Trezor Safe 7 labels Oct 25, 2025
Comment thread core/embed/io/ble/unix/ble.c Outdated
Comment thread core/embed/io/ble/unix/ble.c
Comment thread core/embed/io/ble/unix/ble.c Outdated
Comment thread core/embed/io/ble/unix/ble.c Outdated
Comment thread core/embed/io/ble/unix/ble.c Outdated
Comment thread core/tools/bluez-emu-bridge.py Outdated
Comment thread core/tools/bluez-emu-bridge.py Outdated
Comment thread core/tools/bluez-emu-bridge.py Outdated
Comment thread core/tools/bluez-emu-bridge.py
Comment thread core/tools/bluez-emu-bridge.py Outdated
@mmilata
Copy link
Copy Markdown
Member Author

mmilata commented Oct 27, 2025

Thanks for the feedback @romanz, I've pushed some fixes. Did you manage to get this to work (with trezorctl or suite) on your machine?

@romanz romanz self-requested a review October 28, 2025 07:52
Copy link
Copy Markdown
Contributor

@romanz romanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Tested successfully with trezorctl & Trezor-Suite-25.10.2-linux-x86_64.AppImage (on Ubuntu 24.04.3)

Comment thread core/embed/io/ble/unix/ble.c Outdated
return;
}
size_t last = drv->bonds_len - 1;
if (i + 1 != drv->bonds_len) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
if (i + 1 != drv->bonds_len) {
if (i != last) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof 999cda5

Comment thread python/src/trezorlib/_internal/emu_ble.py Outdated
Comment thread core/tools/bluez_emu_bridge/adapter1.py
Comment thread core/tools/bluez_emu_bridge/device1.py Outdated
Comment thread core/tools/bluez_emu_bridge/device1.py Outdated
Comment thread python/src/trezorlib/_internal/emu_ble.py
Comment thread core/embed/io/ble/unix/ble.c
Comment thread core/embed/io/usb/unix/sock.c Outdated
Comment thread core/embed/io/ble/unix/ble.c Outdated
Copy link
Copy Markdown
Contributor

@romanz romanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmilata mmilata added the translations Put this label on a PR to run tests in all languages label Oct 29, 2025
@mmilata mmilata merged commit 038e877 into main Oct 29, 2025
165 checks passed
@mmilata mmilata deleted the mmilata/ble-unix branch October 29, 2025 20:18
@github-project-automation github-project-automation Bot moved this from 🔎 Needs review to 🤝 Needs QA in Firmware Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Trezor Core firmware. Runs on Trezor Model T and Safe models. emulator only Issue which does not appear on the physical device - but on emulator only. T3W1 Trezor Safe 7 translations Put this label on a PR to run tests in all languages

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants