Skip to main content

Virtual Bluetooth controller

Project description

RootCanal

Binding to the RootCanal controller implementation. Enables virtual testing of Bluetooth applications directly in Python.

Supported platforms

  • linux-x86_64
  • macos-arm64

Usage

python -m rootcanal [OPTION]

Command line options include:

  • -configuration (controller configuration (see config.proto)) type: string default: ""
  • -configuration_file (controller configuration file path (see config.proto)) type: string default: ""
  • -disable_address_reuse (prevent rootcanal from reusing device addresses) type: bool default: false
  • -enable_baseband_sniffer (enable baseband sniffer) type: bool default: false
  • -enable_hci_sniffer (enable hci sniffer) type: bool default: false
  • -enable_log_color (enable log colors) type: bool default: false
  • -enable_pcap_filter (enable PCAP filter) type: bool default: false
  • -hci_port (hci server tcp port) type: uint32 default: 6402
  • -link_ble_port (le link server tcp port) type: uint32 default: 6404
  • -link_port (link server tcp port) type: uint32 default: 6403
  • -test_port (test tcp port) type: uint32 default: 6401

Example

Example python script to emulate a successful connection establishment for an instance of the RootCanal controller.

import asyncio
from rootcanal.controller import Controller, Any
from rootcanal.bluetooth import Address
from rootcanal.packets import hci
from rootcanal.packets import ll
from rootcanal.packets import llcp
from rootcanal.packets import lmp


async def test():
    controller = Controller(Address("11:11:11:11:11:11"))
    await controller.start()

    # Send HCI Reset to the controller and wait for the response.
    controller.send_cmd(hci.Reset())
    _ = await controller.expect_evt(
        hci.ResetComplete(status=hci.ErrorCode.SUCCESS, num_hci_command_packets=1)
    )

    # Check the local address.
    controller.send_cmd(hci.ReadBdAddr())
    _ = await controller.expect_evt(
        hci.ReadBdAddrComplete(
            status=hci.ErrorCode.SUCCESS,
            num_hci_command_packets=1,
            bd_addr=Address("11:11:11:11:11:11"),
        )
    )

    # Enable page scan.
    controller.send_cmd(hci.WriteScanEnable(scan_enable=hci.ScanEnable.PAGE_SCAN_ONLY))
    _ = await controller.expect_evt(
        hci.WriteScanEnableComplete(
            status=hci.ErrorCode.SUCCESS, num_hci_command_packets=1
        )
    )

    # Send classic connection request.
    controller.send_ll(
        ll.Page(
            class_of_device=0,
            allow_role_switch=0,
            source_address=Address("22:22:22:22:22:22"),
            destination_address=Address("11:11:11:11:11:11"),
        )
    )
    _ = await controller.expect_evt(
        hci.ConnectionRequest(
            bd_addr=Address("22:22:22:22:22:22"),
            class_of_device=0,
            link_type=hci.ConnectionRequestLinkType.ACL,
        )
    )

    # Accept the connection request.
    controller.send_cmd(
        hci.AcceptConnectionRequest(
            bd_addr=Address("22:22:22:22:22:22"),
            role=hci.AcceptConnectionRequestRole.REMAIN_PERIPHERAL,
        )
    )
    _ = await controller.expect_evt(
        hci.AcceptConnectionRequestStatus(
            status=hci.ErrorCode.SUCCESS, num_hci_command_packets=1
        )
    )

    _ = await controller.expect_ll(
        ll.PageResponse(
            source_address=Address("11:11:11:11:11:11"),
            destination_address=Address("22:22:22:22:22:22"),
            try_role_switch=0,
        )
    )

    _ = await controller.expect_evt(
        hci.ConnectionComplete(
            status=hci.ErrorCode.SUCCESS,
            connection_handle=Any(),
            bd_addr=Address("22:22:22:22:22:22"),
            link_type=hci.LinkType.ACL,
            encryption_enabled=hci.Enable.DISABLED,
        )
    )

    controller.stop()


asyncio.get_event_loop().run_until_complete(test())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rootcanal-1.12.0-py3-none-any.whl (33.1 MB view details)

Uploaded Python 3

File details

Details for the file rootcanal-1.12.0-py3-none-any.whl.

File metadata

  • Download URL: rootcanal-1.12.0-py3-none-any.whl
  • Upload date:
  • Size: 33.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rootcanal-1.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 192d2b30c6cad16ef9d6c74fe791b352a595cae209d87f21ec7e06c0b42de7b8
MD5 f4cad19afd6421a9e1becbd9e8edcc70
BLAKE2b-256 9702c9c0255350e77df88ae6caa8687b412e1ba0b6418a443b84f84cb3e8ace6

See more details on using hashes here.

Provenance

The following attestation bundles were made for rootcanal-1.12.0-py3-none-any.whl:

Publisher: publish.yml on google/rootcanal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page