BSController
English | 简体中文
BSController is a Bluetooth LE Controller written in Python. Host stacks connect over standard H4 HCI, and Controllers exchange radio packets through a shared BabbleSim PHY. The PHY advances a discrete simulation clock for reproducible timing.
Quick start
BSController requires Linux, Python 3.11 or newer, and a BabbleSim build. Install the build tools on Ubuntu 24.04 x86_64.
sudo apt-get update
sudo apt-get install -y git repo build-essential gcc-multilib g++-multilib python3-venv
Fetch BabbleSim and build the PHY, modem and channel models.
mkdir -p "$HOME/bsim" && cd "$HOME/bsim"
repo init -u https://github.com/BabbleSim/manifest.git -m everything.xml -b master
repo sync
export BSIM_OUT_PATH="$PWD/build"
export BSIM_COMPONENTS_PATH="$PWD/components"
make -j"$(nproc)" ext_2G4_phy_v1 ext_2G4_modem_BLE_simple ext_2G4_channel_multiatt
Keep BSIM_OUT_PATH exported in the shell used to run BSController. Other checkout and build options are covered in the BabbleSim fetching and building guides.
Return to the BSController directory to install the package.
python3 -m venv .venv
source .venv/bin/activate
python -m pip install .
Standalone Controller
bscontroller serve starts a BabbleSim PHY and exposes H4 HCI on a Unix socket. Point the Host at the socket path.
bscontroller serve --hci-socket /tmp/radio.sock
Pass multiple paths to --hci-socket to run Controllers on a shared PHY. Each socket gets its own Controller, named hci0, hci1, and so on. Public addresses increment from --address, which defaults to F0:F1:F2:F3:F4:01.
bscontroller serve --hci-socket /tmp/radio0.sock /tmp/radio1.sock
Add --capture-air --log-dir /tmp/bscontroller to save a shared ellisys.bttrp and two captures per Controller, radioN.pcapng and hciN.btsnoop.
The Ellisys trace records all Controller transmissions in simulation order. Each PCAPNG records that Controller's transmissions and packets returned by the PHY during reception. Each BTSnoop records H4 traffic between the Host and its Controller.
Simulation time advances as fast as the machine allows by default. For a Host that uses wall-clock timers, add --realtime to keep simulation time in step with wall-clock time.
bscontroller serve --hci-socket /tmp/radio.sock --realtime
Using BSController with BlueZ
To discover one BlueZ adapter from another, start two Controllers in real time.
bscontroller serve --hci-socket /tmp/radio0.sock /tmp/radio1.sock --realtime
Once serve lists both sockets, use socat to create a pseudo-terminal for each socket. Attach the terminals as HCI UART devices with BlueZ's btattach. Run each command in a separate terminal.
socat PTY,link=/tmp/bscontroller-tty0,rawer UNIX-CONNECT:/tmp/radio0.sock
socat PTY,link=/tmp/bscontroller-tty1,rawer UNIX-CONNECT:/tmp/radio1.sock
sudo btattach -B "$(readlink -f /tmp/bscontroller-tty0)" -P h4
sudo btattach -B "$(readlink -f /tmp/bscontroller-tty1)" -P h4
In bluetoothctl, use select F0:F1:F2:F3:F4:01 to select the advertising adapter and enable advertising. Select F0:F1:F2:F3:F4:02 and start scanning.
Using BSController from Python
Create a RadioController inside a running asyncio event loop. It runs the Controller in a dedicated thread. RadioSession starts and stops that thread and attaches the Controller to a running PHY.
For this example, start the PHY with sim_id set to example and two device slots. The Controller uses device 0, and the Host clock uses device 1.
import asyncio
from pathlib import Path
from bscontroller import RadioController, RadioEventLoop, RadioSession
async def main():
controller = RadioController(
"controller", "F0:F1:F2:F3:F4:01", hci_socket=Path("/tmp/radio.sock")
)
async with RadioSession("example", [(0, controller)], clock_dev_id=1):
await controller.terminated
with asyncio.Runner(loop_factory=RadioEventLoop) as runner:
runner.run(main())
Choose the Host connection when creating the Controller.
- Unix socket with
hci_socket. The worker opens the socket on startup and begins processing HCI commands once the Controller has synchronized with the PHY. - In-process H4 with
hci_socketomitted. Before starting the Controller, register a sink withcontroller.set_packet_sink(sink). The sink receives H4 packets through itson_packet(packet: bytes)method. To send an H4 packet to the Controller, callcontroller.on_packet(packet).
Pass hci_snoop_file=Path(...) to record a BTSnoop capture, timestamped with simulation time.
Pass rf_pcap_file=Path(...) to write the Controller's radio traffic to PCAPNG. To merge transmissions from multiple Controllers, create one EllisysCapture(Path(...)) and pass it as ellisys_capture to each Controller. Close it after the RadioSession exits to save the trace.
The package also exposes Radio, Phy, Received and the HCI packet classes in hci. Controller settings are described under Configuration.
When managing the simulation from Python, keep the PHY running for the lifetime of the session.
- Start the PHY with
bscontroller.runtime.PhyProcessbefore enteringRadioSession. - To run the Host on simulation time, use a
RadioEventLoopand give its clock aclock_dev_iddistinct from the Controller device IDs. - Exiting
RadioSessionstops the Controllers before closing its Host clock connection. ExitPhyProcessafter the session ends.
For runnable examples of advertising, scanning, GATT, periodic synchronization and concurrent roles, see the Bumble Host samples.
Configuration
ControllerConfig defines the values the Bluetooth specification leaves to the Controller. Fields you omit retain their defaults.
| JSON key | Default | Range | Spec (Vol 4, Part E) |
|---|---|---|---|
hciVersion |
0x0F (6.1) |
0x06–0x10 |
7.4.1 |
hciRevision |
0 |
0–0xFFFF |
7.4.1 |
lmpVersion |
0x0F (6.1) |
0x06–0x10 |
7.4.1 |
lmpSubversion |
0 |
0–0xFFFF |
7.4.1 |
manufacturer |
0xFFFF |
0–0xFFFF |
7.4.1 |
aclPacketCount |
8 |
1–255 |
7.8.2 |
aclPacketLength |
251 |
27–65535 |
7.8.2 |
maxTxOctets |
251 |
27–251 |
7.8.46 |
maxTxTime |
17040 |
328–17040 |
7.8.46 |
maxRxOctets |
251 |
27–251 |
7.8.46 |
maxRxTime |
17040 |
328–17040 |
7.8.46 |
advertisingSetCount |
16 |
1–240 |
7.8.58 |
maxAdvertisingDataLength |
1650 |
31–1650 |
7.8.57 |
filterAcceptListSize |
16 |
1–255 |
7.8.14 |
resolvingListSize |
16 |
1–255 |
7.8.41 |
periodicAdvertiserListSize |
8 |
1–255 |
7.8.73 |
maxConnections |
64 |
1–3839 |
5.3.1 |
maxPeriodicSyncs |
16 |
1–3839 |
5.3.1 |
isoPacketCount |
16 |
1–255 |
7.8.2 |
isoPacketLength |
251 |
5–16383 |
7.8.2 |
maxBigs |
4 |
1–240 |
7.8.103, 7.8.106 |
maxBis |
16 |
1–3839 |
5.3.1, 7.8.103, 7.8.106 |
Use defaults for settings shared by all Controllers and controllers for overrides by name.
{
"defaults": {"aclPacketCount": 16},
"controllers": {"hci0": {"maxConnections": 2}, "hci1": {"maxTxOctets": 27}}
}
Keys accept camelCase and snake_case. Settings in defaults override the built-in values, and controllers.<name> overrides the shared settings for that Controller. ControllerConfig.load() and ControllerConfig.from_mapping() also accept keyword overrides with the highest priority. An unknown key or out-of-range value triggers a warning and leaves the current settings for that entry in effect.
Export the built-in defaults to a file, edit it and pass it to serve.
bscontroller config > bsc.json # every default, ready to edit
bscontroller serve --hci-socket /tmp/radio0.sock /tmp/radio1.sock --config bsc.json
In a running asyncio event loop, pass a file path, an equivalent mapping or a ControllerConfig to RadioController. A file or mapping applies the controllers entry matching the Controller name.
from bscontroller import ControllerConfig, RadioController
central = RadioController("hci0", "F0:F1:F2:F3:F4:01", config="bsc.json")
peripheral = RadioController("hci1", "F0:F1:F2:F3:F4:02", config="bsc.json")
other = RadioController("x", "F0:F1:F2:F3:F4:03", config=ControllerConfig(max_connections=2))
ControllerConfig(...) raises ValueError for an invalid value.
Supported features
The table groups Link Layer features by the Bluetooth Core version that introduced them. * marks implemented features. BSController reports the assigned feature bits in the LE FeatureSet. See Vol 6, Part B, 4.6.
| Core spec version | Link Layer feature | Supported |
|---|---|---|
| 4.0 | LE Encryption | * |
| 4.1 | Connection Parameters Request Procedure | * |
| 4.1 | Extended Reject Indication | * |
| 4.1 | Peripheral-initiated Features Exchange | * |
| 4.1 | LE Ping Procedure | * |
| 4.2 | LE Data Packet Length Extension | * |
| 4.2 | LL Privacy | * |
| 4.2 | Extended Scanner Filter Policies | * |
| 5.0 | LE 2M PHY | * |
| 5.0 | LE Coded PHY | * |
| 5.0 | Channel Selection Algorithm #2 | * |
| 5.0 | Minimum Number of Used Channels Procedure | * |
| 5.0 | Extended Advertising | * |
| 5.0 | Periodic Advertising | * |
| 5.1 | Connection CTE Request | |
| 5.1 | Connection CTE Response | |
| 5.1 | Connectionless CTE Transmitter | |
| 5.1 | Connectionless CTE Receiver | |
| 5.1 | Periodic Advertising Sync Transfer | * |
| 5.1 | Initiating Periodic Advertising Sync Transfer for Local Periodic Advertising | * |
| 5.1 | Initiating Periodic Advertising Sync Transfer for Remote Periodic Advertising | * |
| 5.2 | Isochronous Broadcaster | * |
| 5.2 | Synchronized Receiver | * |
| 5.2 | Connected Isochronous Stream (CIS) | |
| 5.3 | Periodic Advertising ADI Support | * |
| 5.3 | LE Channel Classification | |
| 5.3 | Connection Subrating | |
| 5.4 | Periodic Advertising with Responses | * |
| 6.0 | Channel Sounding | |
| 6.0 | Decision-Based Advertising Filtering | * |
| 6.0 | LL Extended Feature Set | * |
| 6.0 | Monitoring Advertisers | * |
| 6.0 | Frame Space Update | |
| 6.1 | Randomized RPA Updates | * |
| 6.2 | Shorter Connection Intervals | |
| 6.2 | Channel Sounding Amplitude-based Attack Resilience | |
| 6.3 | Channel Sounding Inline Phase Correction Term Transfer |
How it works
The HCI layer exchanges packets with the Host. The Link Layer implements the controller procedures, and the radio adapter passes packets to and from the BabbleSim PHY. Protocol behavior follows Bluetooth Core 6.3.
Figure 1: Controllers on a shared PHY
The Link Layer has separate managers for advertising, scanning, initiating connections, synchronization and connections. Each ACL connection keeps its own control-procedure state, encryption state and event executor. A single scheduler coordinates radio use across the roles.
Each Controller thread has its own event loop and PHY connection. The Host and Controller exchange complete H4 packets. The PHY advances simulation time in integer microseconds as the Controllers and any Host clock synchronize with it.
| Object | Owns |
|---|---|
RadioController |
Worker thread, Controller event loop, radio connection |
RadioSession |
Starting and stopping workers, optional Host clock |
H4Server |
Unix socket, the Host connection, H4 framing |
PhyProcess |
BabbleSim PHY process, its logs and simulation directory |
Development
.
├── src/bscontroller/ # Package: HCI, Link Layer, radio, runtime, config
├── samples/ # Bumble Host scenarios, including concurrent roles
└── tests/
├── unit/ # Unit tests that run without a PHY
└── qualification/ # HCI and Link Layer specification tests
python -m pip install -e '.[test]'
python -m pytest tests/unit -n auto -q
python -m pytest tests/qualification -n auto -v -rs # Radio cases use BSIM_OUT_PATH
python -m build # sdist and wheel in dist/
The qualification suite uses independent lower testers to exercise 821 selected HCI and Link Layer cases from the Bluetooth test specifications. See the test guide for coverage, setup and logs.
Licensing and third-party notices are in LICENSE and NOTICE.
Metadata
Release files for bscontroller 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bscontroller-0.1.3.tar.gz | 1.1 MB | With provenance | Details for bscontroller-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bscontroller-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for bscontroller-0.1.3-py3-none-any.whl |
Total release size: 1.3 MB
Release files / bscontroller-0.1.3.tar.gz
| Download URL | bscontroller-0.1.3.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eaa9147025612a65206c2aa96516a79ba38a26d50369618cdcde990b8f3f97c6
|
|
BLAKE2b-256 checksum How to use checksums |
7290dae040bae5fd836a1e9a2aa1c4f36ffbd81bd32e66a79badffb2fbeff535
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / bscontroller-0.1.3-py3-none-any.whl
| Download URL | bscontroller-0.1.3-py3-none-any.whl |
|---|---|
| Size | 281.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f95d8e119062b780ef81fce3f99e70b7b22905c9a6635e3943fc877f5c8230b4
|
|
BLAKE2b-256 checksum How to use checksums |
2140fbb685e82d757597e0844b2fa223489753cda2eb9fdc27f607181b46794f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logSecurity for bscontroller 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for bscontroller-0.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.