XU XUv0.13.1
中文

#embedded/bluetooth

import: #embedded/bluetooth

counts: 102 functions, 28 methods, 14 types, 158 constants, 0 method sets

Xu Bluetooth Standard Library Package Portable Bluetooth Low Energy stack for bare-metal Xu targets. The package is split into a portable core and a thin chip binding backend.xu chip hook table (`BtBackend`) btdm.xu BTDM application layer: OSI table, controller lifecycle, sleep sequencing, VHCI host transport, work dispatch hci.xu H4 transport framing (command / ACL / SCO / event) ke.xu KE style event scheduler skeleton hogp.xu HOGP (HID Over GATT Profile) & Report Map for Mouse, Consumer & Keyboard att.xu Attribute Protocol (ATT) & Lightweight GATT Server The BTDM application layer is Espressif-generic: the same semantics serve esp32, esp32c3 and esp32s3. Only a few operations touch chip registers or ROM entry points, and those live behind `BtBackend`, so a chip package registers its implementation instead of the core importing a chip. Usage import bt #embedded/bluetooth $ctl := bt.btdm_controller_create bt.btdm_controller_init($&ctl, bt.btdm_config_mask_load, bt.ESP_BT_MODE_BLE) bt.btdm_controller_enable($&ctl) bt.api_vhci_host_register_callback($&ctl,...) $att := bt.att_server_create("XU-Agent-HID") $report := bt.hogp_build_consumer(bt.HID_CC_VOLUME_UP) $acl_pkt := bt.hogp_make_acl_notification(0x0000, bt.ATT_HANDLE_CONSUMER_REPORT, report) $wire_bytes := bt.hci_encode(&acl_pkt) bt.api_vhci_host_send_packet($&ctl, wire_bytes) The closed Espressif library this package replaces is `libbtdm_app.a` the recovered ABI contract is documented in `src/embedded/bluetooth/BTDM_XU_PORT.md` and the reverse engineering evidence in `docs/rea-btdm/BTDM_REA_DOSSIER.md`.

const ATT_CID

XuAPI
pub const ATT_CID = 0x0004

Purpose

One-connection, fixed-database ATT/GATT HID server. A 23-byte ATT MTU keeps an entire L2CAP SDU within the baseline 27-byte LE ACL buffer. SMP and HCI ACL fragmentation/reassembly belong to the host transport.

const ATT_SERVER_MTU

XuAPI
pub const ATT_SERVER_MTU = 23

Purpose

Constant ATT_SERVER_MTU, defining protocol or algorithm parameters.

const ATT_LAST_HANDLE

XuAPI
pub const ATT_LAST_HANDLE = 0x0032

Purpose

Constant ATT_LAST_HANDLE, defining protocol or algorithm parameters.

const ATT_OP_ERROR_RSP

XuAPI
pub const ATT_OP_ERROR_RSP = 0x01

Purpose

Constant ATT_OP_ERROR_RSP, defining protocol or algorithm parameters.

const ATT_OP_EXCHANGE_MTU_REQ

XuAPI
pub const ATT_OP_EXCHANGE_MTU_REQ = 0x02

Purpose

Constant ATT_OP_EXCHANGE_MTU_REQ, defining protocol or algorithm parameters.

const ATT_OP_EXCHANGE_MTU_RSP

XuAPI
pub const ATT_OP_EXCHANGE_MTU_RSP = 0x03

Purpose

Constant ATT_OP_EXCHANGE_MTU_RSP, defining protocol or algorithm parameters.

const ATT_OP_FIND_INFO_REQ

XuAPI
pub const ATT_OP_FIND_INFO_REQ = 0x04

Purpose

Constant ATT_OP_FIND_INFO_REQ, defining protocol or algorithm parameters.

const ATT_OP_FIND_INFO_RSP

XuAPI
pub const ATT_OP_FIND_INFO_RSP = 0x05

Purpose

Constant ATT_OP_FIND_INFO_RSP, defining protocol or algorithm parameters.

const ATT_OP_FIND_BY_TYPE_VALUE_REQ

XuAPI
pub const ATT_OP_FIND_BY_TYPE_VALUE_REQ = 0x06

Purpose

Constant ATT_OP_FIND_BY_TYPE_VALUE_REQ, defining protocol or algorithm parameters.

const ATT_OP_FIND_BY_TYPE_VALUE_RSP

XuAPI
pub const ATT_OP_FIND_BY_TYPE_VALUE_RSP = 0x07

Purpose

Constant ATT_OP_FIND_BY_TYPE_VALUE_RSP, defining protocol or algorithm parameters.

const ATT_OP_READ_BY_TYPE_REQ

XuAPI
pub const ATT_OP_READ_BY_TYPE_REQ = 0x08

Purpose

Constant ATT_OP_READ_BY_TYPE_REQ, defining protocol or algorithm parameters.

const ATT_OP_READ_BY_TYPE_RSP

XuAPI
pub const ATT_OP_READ_BY_TYPE_RSP = 0x09

Purpose

Constant ATT_OP_READ_BY_TYPE_RSP, defining protocol or algorithm parameters.

const ATT_OP_READ_REQ

XuAPI
pub const ATT_OP_READ_REQ = 0x0A

Purpose

Constant ATT_OP_READ_REQ, defining protocol or algorithm parameters.

const ATT_OP_READ_RSP

XuAPI
pub const ATT_OP_READ_RSP = 0x0B

Purpose

Constant ATT_OP_READ_RSP, defining protocol or algorithm parameters.

const ATT_OP_READ_BLOB_REQ

XuAPI
pub const ATT_OP_READ_BLOB_REQ = 0x0C

Purpose

Constant ATT_OP_READ_BLOB_REQ, defining protocol or algorithm parameters.

const ATT_OP_READ_BLOB_RSP

XuAPI
pub const ATT_OP_READ_BLOB_RSP = 0x0D

Purpose

Constant ATT_OP_READ_BLOB_RSP, defining protocol or algorithm parameters.

const ATT_OP_READ_BY_GROUP_TYPE_REQ

XuAPI
pub const ATT_OP_READ_BY_GROUP_TYPE_REQ = 0x10

Purpose

Constant ATT_OP_READ_BY_GROUP_TYPE_REQ, defining protocol or algorithm parameters.

const ATT_OP_READ_BY_GROUP_TYPE_RSP

XuAPI
pub const ATT_OP_READ_BY_GROUP_TYPE_RSP = 0x11

Purpose

Constant ATT_OP_READ_BY_GROUP_TYPE_RSP, defining protocol or algorithm parameters.

const ATT_OP_WRITE_REQ

XuAPI
pub const ATT_OP_WRITE_REQ = 0x12

Purpose

Constant ATT_OP_WRITE_REQ, defining protocol or algorithm parameters.

const ATT_OP_WRITE_RSP

XuAPI
pub const ATT_OP_WRITE_RSP = 0x13

Purpose

Constant ATT_OP_WRITE_RSP, defining protocol or algorithm parameters.

const ATT_OP_HANDLE_VALUE_NTF

XuAPI
pub const ATT_OP_HANDLE_VALUE_NTF = 0x1B

Purpose

Constant ATT_OP_HANDLE_VALUE_NTF, defining protocol or algorithm parameters.

const ATT_OP_WRITE_CMD

XuAPI
pub const ATT_OP_WRITE_CMD = 0x52

Purpose

Constant ATT_OP_WRITE_CMD, defining protocol or algorithm parameters.

const ATT_ERR_INVALID_HANDLE

XuAPI
pub const ATT_ERR_INVALID_HANDLE = 0x01

Purpose

Constant ATT_ERR_INVALID_HANDLE, defining protocol or algorithm parameters.

const ATT_ERR_READ_NOT_PERMITTED

XuAPI
pub const ATT_ERR_READ_NOT_PERMITTED = 0x02

Purpose

Constant ATT_ERR_READ_NOT_PERMITTED, defining protocol or algorithm parameters.

const ATT_ERR_WRITE_NOT_PERMITTED

XuAPI
pub const ATT_ERR_WRITE_NOT_PERMITTED = 0x03

Purpose

Constant ATT_ERR_WRITE_NOT_PERMITTED, defining protocol or algorithm parameters.

const ATT_ERR_INVALID_PDU

XuAPI
pub const ATT_ERR_INVALID_PDU = 0x04

Purpose

Constant ATT_ERR_INVALID_PDU, defining protocol or algorithm parameters.

const ATT_ERR_REQUEST_NOT_SUPPORTED

XuAPI
pub const ATT_ERR_REQUEST_NOT_SUPPORTED = 0x06

Purpose

Constant ATT_ERR_REQUEST_NOT_SUPPORTED, defining protocol or algorithm parameters.

const ATT_ERR_INVALID_OFFSET

XuAPI
pub const ATT_ERR_INVALID_OFFSET = 0x07

Purpose

Constant ATT_ERR_INVALID_OFFSET, defining protocol or algorithm parameters.

const ATT_ERR_ATTR_NOT_FOUND

XuAPI
pub const ATT_ERR_ATTR_NOT_FOUND = 0x0A

Purpose

Constant ATT_ERR_ATTR_NOT_FOUND, defining protocol or algorithm parameters.

const ATT_ERR_INVALID_VALUE_LENGTH

XuAPI
pub const ATT_ERR_INVALID_VALUE_LENGTH = 0x0D

Purpose

Constant ATT_ERR_INVALID_VALUE_LENGTH, defining protocol or algorithm parameters.

const ATT_ERR_INSUFFICIENT_ENCRYPTION

XuAPI
pub const ATT_ERR_INSUFFICIENT_ENCRYPTION = 0x0F

Purpose

Constant ATT_ERR_INSUFFICIENT_ENCRYPTION, defining protocol or algorithm parameters.

const ATT_ERR_UNSUPPORTED_GROUP_TYPE

XuAPI
pub const ATT_ERR_UNSUPPORTED_GROUP_TYPE = 0x10

Purpose

Constant ATT_ERR_UNSUPPORTED_GROUP_TYPE, defining protocol or algorithm parameters.

const ATT_ERR_VALUE_NOT_ALLOWED

XuAPI
pub const ATT_ERR_VALUE_NOT_ALLOWED = 0x13

Purpose

Constant ATT_ERR_VALUE_NOT_ALLOWED, defining protocol or algorithm parameters.

struct AttServer

XuAPI
pub struct AttServer {
    pub mtu int
    pub notifications_enabled bool // aggregate compatibility view; never authorizes a report
    pub dev_name string
    pub encrypted bool
    pub suspended bool
    pub mouse_cccd int
    pub keyboard_cccd int
    pub consumer_cccd int
    pub service_changed_cccd int
}

Purpose

Structure encapsulating mtu, notifications_enabled, dev_name, encrypted, suspended.

Public fields

mtu int
field (int)
notifications_enabled bool // aggregate compatibility view; never authorizes a report
field (bool // aggregate compatibility view; never authorizes a report)
dev_name string
field (string)
encrypted bool
field (bool)
suspended bool
field (bool)
mouse_cccd int
field (int)
keyboard_cccd int
field (int)
consumer_cccd int
field (int)
service_changed_cccd int
field (int)

att_server_create

XuAPI
pub fn att_server_create(name string) AttServer

Purpose

Att server create.

Parameters

name string
name (string)

Returns

AttServer — a value of this type

att_error_response

XuAPI
pub fn att_error_response(request int, handle int, code int) []int

Purpose

Att error response.

Parameters

request int
request (int)
handle int
handle (int)
code int
code (int)

Returns

[]int — slice result

($&AttServer) handle_att_pdu

XuAPI
pub fn (s $&AttServer) handle_att_pdu(pdu &[]int) []int

Purpose

Operation on $&AttServer: handle att pdu.

Parameters

s $&AttServer
The AttServer instance used by this call (exclusive borrow).
pdu &[]int
pdu (read-only borrow; caller keeps the original; type &[]int)

Returns

[]int — slice result

($&AttServer) process_acl_packet

XuAPI
pub fn (s $&AttServer) process_acl_packet(packet &HciPacket) HciPacket

Purpose

Only complete, single-SDU ACL packets are accepted. A transport with a smaller controller ACL buffer must reassemble continuation packets before calling this method; truncated/concatenated SDUs are never indexed.

Parameters

s $&AttServer
The AttServer instance used by this call (exclusive borrow).
packet &HciPacket
packet (read-only borrow; caller keeps the original; type &HciPacket)

Returns

HciPacket — a value of this type

(&AttServer) report_notifications_enabled

XuAPI
pub fn (s &AttServer) report_notifications_enabled(handle int) bool

Purpose

Operation on &AttServer: report notifications enabled.

Parameters

s &AttServer
The AttServer instance used by this call (borrow).
handle int
handle (int)

Returns

bool — true or false

($&AttServer) make_hid_notification

XuAPI
pub fn (s $&AttServer) make_hid_notification(connection int, handle int, report []int) HciPacket

Purpose

Prefer this method over the raw HOGP packet builder: it enforces the selected characteristic's CCCD, encrypted link, report length and suspend.

Parameters

s $&AttServer
The AttServer instance used by this call (exclusive borrow).
connection int
connection (int)
handle int
handle (int)
report []int
report ([]int)

Returns

HciPacket — a value of this type

struct BtBackend

XuAPI
pub struct BtBackend {
    pub lpclk_select_src fn(int) bool
    pub lpclk_set_div fn(int) bool
    pub lpclk_read_div fn() int
    pub lpclk_read_src fn() int
    pub wakeup_request fn()
    pub rf_init_phase2 fn()
}

Purpose

Structure encapsulating lpclk_select_src, lpclk_set_div, lpclk_read_div, lpclk_read_src, wakeup_request.

Public fields

lpclk_select_src fn(int) bool
Selects the low power clock source. sel is one of BTDM_LPCLK_SEL_XTAL / _XTAL32K / _RTC_SLOW / _8M. Returns false when the chip cannot honour the request.
lpclk_set_div fn(int) bool
Writes the 12 bit integer divider of the low power clock.
lpclk_read_div fn() int
Reads the low power clock integer divider back.
lpclk_read_src fn() int
Reads the low power clock source selection bits back.
wakeup_request fn()
Asks the radio to leave deep sleep.
rf_init_phase2 fn()
Second phase of the baseband / RF bring up, after the PHY is powered.

bt_default_backend

XuAPI
pub fn bt_default_backend() BtBackend

Purpose

A backend whose hooks do nothing but report failure. Use it when the application does not drive the radio clock directly.

Parameters

No arguments are required.

Returns

BtBackend — a value of this type

bt_lpclk_select_src

XuAPI
pub fn bt_lpclk_select_src(backend &BtBackend, sel int) bool

Purpose

Bt lpclk select src.

Parameters

backend &BtBackend
backend (read-only borrow; caller keeps the original; type &BtBackend)
sel int
sel (int)

Returns

bool — true or false

bt_lpclk_set_div

XuAPI
pub fn bt_lpclk_set_div(backend &BtBackend, div int) bool

Purpose

Bt lpclk set div.

Parameters

backend &BtBackend
backend (read-only borrow; caller keeps the original; type &BtBackend)
div int
div (int)

Returns

bool — true or false

bt_lpclk_read_div

XuAPI
pub fn bt_lpclk_read_div(backend &BtBackend) int

Purpose

Bt lpclk read div.

Parameters

backend &BtBackend
backend (read-only borrow; caller keeps the original; type &BtBackend)

Returns

int — a value of this type

bt_lpclk_read_src

XuAPI
pub fn bt_lpclk_read_src(backend &BtBackend) int

Purpose

Bt lpclk read src.

Parameters

backend &BtBackend
backend (read-only borrow; caller keeps the original; type &BtBackend)

Returns

int — a value of this type

bt_wakeup_request

XuAPI
pub fn bt_wakeup_request(backend &BtBackend)

Purpose

Bt wakeup request.

Parameters

backend &BtBackend
backend (read-only borrow; caller keeps the original; type &BtBackend)

Returns

This call does not return a value.

bt_rf_init_phase2

XuAPI
pub fn bt_rf_init_phase2(backend &BtBackend)

Purpose

Bt rf init phase2.

Parameters

backend &BtBackend
backend (read-only borrow; caller keeps the original; type &BtBackend)

Returns

This call does not return a value.

const BOND_RECORD_BYTES

XuAPI
pub const BOND_RECORD_BYTES = 64

Purpose

Portable single-peer legacy bond storage codec. The 64 bytes contain keys the platform owns storage and must not print or send this record to a log. This restores a key cache only: link encryption/CCCDs still require actual controller and ATT events. Peer identity resolution is not implemented.

bond_crc32

XuAPI
pub fn bond_crc32(data &[]int, count int) int

Purpose

Bond crc32.

Parameters

data &[]int
data (read-only borrow; caller keeps the original; type &[]int)
count int
count (int)

Returns

int — a value of this type

bond_record_valid

XuAPI
pub fn bond_record_valid(data &[]int) bool

Purpose

Bond record valid.

Parameters

data &[]int
data (read-only borrow; caller keeps the original; type &[]int)

Returns

bool — true or false

bond_record_generation

XuAPI
pub fn bond_record_generation(data &[]int) int

Purpose

Bond record generation.

Parameters

data &[]int
data (read-only borrow; caller keeps the original; type &[]int)

Returns

int — a value of this type

bond_record_select

XuAPI
pub fn bond_record_select(first &[]int, second &[]int) int

Purpose

1 no valid slot, -2 conflicting generations/content; no arbitrary choice.

Parameters

first &[]int
first (read-only borrow; caller keeps the original; type &[]int)
second &[]int
second (read-only borrow; caller keeps the original; type &[]int)

Returns

int — a value of this type

bond_record_next_generation

XuAPI
pub fn bond_record_next_generation(generation int) int

Purpose

Bond record next generation.

Parameters

generation int
generation (int)

Returns

int — a value of this type

(&PeripheralHost) bond_snapshot

XuAPI
pub fn (h &PeripheralHost) bond_snapshot(generation int) []int

Purpose

Operation on &PeripheralHost: bond snapshot.

Parameters

h &PeripheralHost
The PeripheralHost instance used by this call (borrow).
generation int
generation (int)

Returns

[]int — slice result

(&PeripheralHost) bond_clear_snapshot

XuAPI
pub fn (h &PeripheralHost) bond_clear_snapshot(generation int) []int

Purpose

Persist this higher-generation tombstone before retiring the old slot. Erasing both slots alone is not a power-fail-safe revocation operation.

Parameters

h &PeripheralHost
The PeripheralHost instance used by this call (borrow).
generation int
generation (int)

Returns

[]int — slice result

($&PeripheralHost) restore_bond_snapshot

XuAPI
pub fn (h $&PeripheralHost) restore_bond_snapshot(data &[]int) bool

Purpose

Operation on $&PeripheralHost: restore bond snapshot.

Parameters

h $&PeripheralHost
The PeripheralHost instance used by this call (exclusive borrow).
data &[]int
data (read-only borrow; caller keeps the original; type &[]int)

Returns

bool — true or false

bond_record_same_payload

XuAPI
pub fn bond_record_same_payload(first &[]int, second &[]int) bool

Purpose

Avoid flash wear on an unchanged restored bond; generation/CRC are ignored.

Parameters

first &[]int
first (read-only borrow; caller keeps the original; type &[]int)
second &[]int
second (read-only borrow; caller keeps the original; type &[]int)

Returns

bool — true or false

const OSI_VERSION

XuAPI
pub const OSI_VERSION = 0x00010003

Purpose

Version of the OSI table. The ESP32 variant uses 0x00010003; the ESP32-C3 and ESP32-S3 variants use 0x00010006. Do not mix them up.

const OSI_MAGIC_VALUE

XuAPI
pub const OSI_MAGIC_VALUE = 0xFADEBEAD

Purpose

Constant OSI_MAGIC_VALUE, defining protocol or algorithm parameters.

const OSI_FUNCS_TIME_BLOCKING

XuAPI
pub const OSI_FUNCS_TIME_BLOCKING = 0xFFFFFFFF

Purpose

Constant OSI_FUNCS_TIME_BLOCKING, defining protocol or algorithm parameters.

const BTDM_OSI_ERR_NULL

XuAPI
pub const BTDM_OSI_ERR_NULL    = -1

Purpose

Return codes of btdm_osi_funcs_register, recovered from the closed library by REA/Ghidra (esp32 osi.o @0x10018). They are plain negative ints, not ESP-IDF error codes: -1 null pointer, -2 magic mismatch, 3 version mismatch, 0 success.

const BTDM_OSI_ERR_MAGIC

XuAPI
pub const BTDM_OSI_ERR_MAGIC   = -2

Purpose

Constant BTDM_OSI_ERR_MAGIC, defining protocol or algorithm parameters.

const BTDM_OSI_ERR_VERSION

XuAPI
pub const BTDM_OSI_ERR_VERSION = -3

Purpose

Constant BTDM_OSI_ERR_VERSION, defining protocol or algorithm parameters.

const OSI_FUNC_SLOT_COUNT

XuAPI
pub const OSI_FUNC_SLOT_COUNT = 59

Purpose

Number of function slots in struct osi_funcs_t (bt.c lines 118-180).

const BTDM_CFG_BT_DATA_RELEASE

XuAPI
pub const BTDM_CFG_BT_DATA_RELEASE         = 1

Purpose

Constant BTDM_CFG_BT_DATA_RELEASE, defining protocol or algorithm parameters.

const BTDM_CFG_HCI_UART

XuAPI
pub const BTDM_CFG_HCI_UART                = 2

Purpose

Constant BTDM_CFG_HCI_UART, defining protocol or algorithm parameters.

const BTDM_CFG_CONTROLLER_RUN_APP_CPU

XuAPI
pub const BTDM_CFG_CONTROLLER_RUN_APP_CPU  = 4

Purpose

Constant BTDM_CFG_CONTROLLER_RUN_APP_CPU, defining protocol or algorithm parameters.

const BTDM_CFG_SCAN_DUPLICATE_OPTIONS

XuAPI
pub const BTDM_CFG_SCAN_DUPLICATE_OPTIONS  = 8

Purpose

Constant BTDM_CFG_SCAN_DUPLICATE_OPTIONS, defining protocol or algorithm parameters.

const BTDM_CFG_SEND_ADV_RESERVED_SIZE

XuAPI
pub const BTDM_CFG_SEND_ADV_RESERVED_SIZE  = 16

Purpose

Constant BTDM_CFG_SEND_ADV_RESERVED_SIZE, defining protocol or algorithm parameters.

const BTDM_CFG_BLE_FULL_SCAN_SUPPORTED

XuAPI
pub const BTDM_CFG_BLE_FULL_SCAN_SUPPORTED = 32

Purpose

Constant BTDM_CFG_BLE_FULL_SCAN_SUPPORTED, defining protocol or algorithm parameters.

const BTDM_MODEM_SLEEP_MODE_NONE

XuAPI
pub const BTDM_MODEM_SLEEP_MODE_NONE = 0

Purpose

Constant BTDM_MODEM_SLEEP_MODE_NONE, defining protocol or algorithm parameters.

const BTDM_MODEM_SLEEP_MODE_ORIG

XuAPI
pub const BTDM_MODEM_SLEEP_MODE_ORIG = 1

Purpose

Constant BTDM_MODEM_SLEEP_MODE_ORIG, defining protocol or algorithm parameters.

const BTDM_MODEM_SLEEP_MODE_EVED

XuAPI
pub const BTDM_MODEM_SLEEP_MODE_EVED = 2

Purpose

Constant BTDM_MODEM_SLEEP_MODE_EVED, defining protocol or algorithm parameters.

const BTDM_LPCLK_SEL_XTAL

XuAPI
pub const BTDM_LPCLK_SEL_XTAL     = 0

Purpose

Constant BTDM_LPCLK_SEL_XTAL, defining protocol or algorithm parameters.

const BTDM_LPCLK_SEL_XTAL32K

XuAPI
pub const BTDM_LPCLK_SEL_XTAL32K  = 1

Purpose

Constant BTDM_LPCLK_SEL_XTAL32K, defining protocol or algorithm parameters.

const BTDM_LPCLK_SEL_RTC_SLOW

XuAPI
pub const BTDM_LPCLK_SEL_RTC_SLOW = 2

Purpose

Constant BTDM_LPCLK_SEL_RTC_SLOW, defining protocol or algorithm parameters.

const BTDM_LPCLK_SEL_8M

XuAPI
pub const BTDM_LPCLK_SEL_8M       = 3

Purpose

Constant BTDM_LPCLK_SEL_8M, defining protocol or algorithm parameters.

const BTDM_MIN_SLEEP_DURATION

XuAPI
pub const BTDM_MIN_SLEEP_DURATION = 12

Purpose

Threshold of interval in slots to allow to fall into modem sleep.

const BTDM_MODEM_WAKE_UP_DELAY

XuAPI
pub const BTDM_MODEM_WAKE_UP_DELAY = 4

Purpose

Delay in slots of the modem wake up procedure (PHY/RF re-enable).

const ESP_BT_CONTROLLER_STATUS_IDLE

XuAPI
pub const ESP_BT_CONTROLLER_STATUS_IDLE    = 0

Purpose

Constant ESP_BT_CONTROLLER_STATUS_IDLE, defining protocol or algorithm parameters.

const ESP_BT_CONTROLLER_STATUS_INITED

XuAPI
pub const ESP_BT_CONTROLLER_STATUS_INITED  = 1

Purpose

Constant ESP_BT_CONTROLLER_STATUS_INITED, defining protocol or algorithm parameters.

const ESP_BT_CONTROLLER_STATUS_ENABLED

XuAPI
pub const ESP_BT_CONTROLLER_STATUS_ENABLED = 2

Purpose

Constant ESP_BT_CONTROLLER_STATUS_ENABLED, defining protocol or algorithm parameters.

const ESP_BT_MODE_IDLE

XuAPI
pub const ESP_BT_MODE_IDLE       = 0

Purpose

Constant ESP_BT_MODE_IDLE, defining protocol or algorithm parameters.

const ESP_BT_MODE_BLE

XuAPI
pub const ESP_BT_MODE_BLE        = 1

Purpose

Constant ESP_BT_MODE_BLE, defining protocol or algorithm parameters.

const ESP_BT_MODE_CLASSIC_BT

XuAPI
pub const ESP_BT_MODE_CLASSIC_BT = 2

Purpose

Constant ESP_BT_MODE_CLASSIC_BT, defining protocol or algorithm parameters.

const ESP_BT_MODE_BTDM

XuAPI
pub const ESP_BT_MODE_BTDM       = 3

Purpose

Constant ESP_BT_MODE_BTDM, defining protocol or algorithm parameters.

const ESP_OK

XuAPI
pub const ESP_OK                 = 0

Purpose

Constant ESP_OK, defining protocol or algorithm parameters.

const ESP_FAIL

XuAPI
pub const ESP_FAIL               = -1

Purpose

Constant ESP_FAIL, defining protocol or algorithm parameters.

const ESP_ERR_NO_MEM

XuAPI
pub const ESP_ERR_NO_MEM         = 0x101

Purpose

Constant ESP_ERR_NO_MEM, defining protocol or algorithm parameters.

const ESP_ERR_INVALID_ARG

XuAPI
pub const ESP_ERR_INVALID_ARG    = 0x102

Purpose

Constant ESP_ERR_INVALID_ARG, defining protocol or algorithm parameters.

const ESP_ERR_INVALID_STATE

XuAPI
pub const ESP_ERR_INVALID_STATE  = 0x103

Purpose

Constant ESP_ERR_INVALID_STATE, defining protocol or algorithm parameters.

const ESP_ERR_NOT_SUPPORTED

XuAPI
pub const ESP_ERR_NOT_SUPPORTED  = 0x106

Purpose

Constant ESP_ERR_NOT_SUPPORTED, defining protocol or algorithm parameters.

const BTDM_LPCK_DIV_NUM_MASK

XuAPI
pub const BTDM_LPCK_DIV_NUM_MASK   = 0x00000FFF

Purpose

Field masks of the two registers.

const BTDM_LPCK_BTEXTWAKEUP_REQ

XuAPI
pub const BTDM_LPCK_BTEXTWAKEUP_REQ = 0x00001000

Purpose

Constant BTDM_LPCK_BTEXTWAKEUP_REQ, defining protocol or algorithm parameters.

const BTDM_LPCK_SEL_RTC_SLOW

XuAPI
pub const BTDM_LPCK_SEL_RTC_SLOW   = 0x01000000

Purpose

Constant BTDM_LPCK_SEL_RTC_SLOW, defining protocol or algorithm parameters.

const BTDM_LPCK_SEL_8M

XuAPI
pub const BTDM_LPCK_SEL_8M         = 0x02000000

Purpose

Constant BTDM_LPCK_SEL_8M, defining protocol or algorithm parameters.

const BTDM_LPCK_SEL_XTAL

XuAPI
pub const BTDM_LPCK_SEL_XTAL       = 0x04000000

Purpose

Constant BTDM_LPCK_SEL_XTAL, defining protocol or algorithm parameters.

const BTDM_LPCK_SEL_XTAL32K

XuAPI
pub const BTDM_LPCK_SEL_XTAL32K    = 0x08000000

Purpose

Constant BTDM_LPCK_SEL_XTAL32K, defining protocol or algorithm parameters.

const BTDM_LPCK_SEL_MASK

XuAPI
pub const BTDM_LPCK_SEL_MASK       = 0x0F000000

Purpose

Constant BTDM_LPCK_SEL_MASK, defining protocol or algorithm parameters.

const RTC_CLK_CAL_FRACT

XuAPI
pub const RTC_CLK_CAL_FRACT = 19

Purpose

RTC_CLK_CAL_FRACT is 19 on ESP32.

const BTDM_LPCYCLE_US_DEFAULT

XuAPI
pub const BTDM_LPCYCLE_US_DEFAULT = 1048576

Purpose

Default low power clock period in microseconds, expressed as 2 << RTC_CLK_CAL_FRACT in the C code.

const BTDM_ISR_SLOTS

XuAPI
pub const BTDM_ISR_SLOTS          = 32

Purpose

Constant BTDM_ISR_SLOTS, defining protocol or algorithm parameters.

const BTDM_SEM_SLOTS

XuAPI
pub const BTDM_SEM_SLOTS          = 8

Purpose

Constant BTDM_SEM_SLOTS, defining protocol or algorithm parameters.

const BTDM_MUTEX_SLOTS

XuAPI
pub const BTDM_MUTEX_SLOTS        = 8

Purpose

Constant BTDM_MUTEX_SLOTS, defining protocol or algorithm parameters.

const BTDM_QUEUE_SLOTS

XuAPI
pub const BTDM_QUEUE_SLOTS        = 8

Purpose

Constant BTDM_QUEUE_SLOTS, defining protocol or algorithm parameters.

const BTDM_QUEUE_MAX_ITEMS

XuAPI
pub const BTDM_QUEUE_MAX_ITEMS    = 32

Purpose

Constant BTDM_QUEUE_MAX_ITEMS, defining protocol or algorithm parameters.

const BTDM_MAC_SLOT_BYTES

XuAPI
pub const BTDM_MAC_SLOT_BYTES      = 6

Purpose

Constant BTDM_MAC_SLOT_BYTES, defining protocol or algorithm parameters.

const BTDM_MAC_SLOTS

XuAPI
pub const BTDM_MAC_SLOTS           = 3

Purpose

Constant BTDM_MAC_SLOTS, defining protocol or algorithm parameters.

const BTDM_VHCI_TX_SLOTS

XuAPI
pub const BTDM_VHCI_TX_SLOTS        = 4

Purpose

Constant BTDM_VHCI_TX_SLOTS, defining protocol or algorithm parameters.

const BTDM_VHCI_RX_SLOTS

XuAPI
pub const BTDM_VHCI_RX_SLOTS        = 4

Purpose

Constant BTDM_VHCI_RX_SLOTS, defining protocol or algorithm parameters.

const BTDM_WORK_SLOTS

XuAPI
pub const BTDM_WORK_SLOTS           = 8

Purpose

Constant BTDM_WORK_SLOTS, defining protocol or algorithm parameters.

const BTDM_SPIN_TRY

XuAPI
pub const BTDM_SPIN_TRY      = 1

Purpose

Bounded spin limits for the cooperative synchronisation primitives.

const BTDM_SPIN_BLOCKING

XuAPI
pub const BTDM_SPIN_BLOCKING = 4096

Purpose

Constant BTDM_SPIN_BLOCKING, defining protocol or algorithm parameters.

const BTDM_WORK_NONE

XuAPI
pub const BTDM_WORK_NONE            = 0

Purpose

Work item ids dispatched to the controller task.

const BTDM_WORK_WAKEUP_REQUEST

XuAPI
pub const BTDM_WORK_WAKEUP_REQUEST  = 1

Purpose

Constant BTDM_WORK_WAKEUP_REQUEST, defining protocol or algorithm parameters.

const BTDM_WORK_SLEEP_TIMER

XuAPI
pub const BTDM_WORK_SLEEP_TIMER     = 2

Purpose

Constant BTDM_WORK_SLEEP_TIMER, defining protocol or algorithm parameters.

const BTDM_WORK_VHCI_RX

XuAPI
pub const BTDM_WORK_VHCI_RX         = 3

Purpose

Constant BTDM_WORK_VHCI_RX, defining protocol or algorithm parameters.

const BTDM_EVT_WORK

XuAPI
pub const BTDM_EVT_WORK = 0x01

Purpose

Controller task event ids.

const BTDM_EVT_TIMER

XuAPI
pub const BTDM_EVT_TIMER = 0x02

Purpose

Constant BTDM_EVT_TIMER, defining protocol or algorithm parameters.

const BTDM_EVT_VHCI_RX

XuAPI
pub const BTDM_EVT_VHCI_RX = 0x03

Purpose

Constant BTDM_EVT_VHCI_RX, defining protocol or algorithm parameters.

struct OsiIsrArgs

XuAPI
pub struct OsiIsrArgs {
    pub n int
    pub handler int   // Xu handler id (the C version passes a function pointer)
    pub arg int
}

Purpose

_set_isr(int n, xt_handler f, void *arg) / _set_isr_l3(...).

Public fields

n int
count, length, or limit
handler int // Xu handler id (the C version passes a function pointer)
field (int // Xu handler id (the C version passes a function pointer))
arg int
field (int)

struct OsiQueueArgs

XuAPI
pub struct OsiQueueArgs {
    pub queue int
    pub item int
    pub block_time_ms int
}

Purpose

_queue_send(queue, item, block_time_ms) and friends.

Public fields

queue int
field (int)
item int
field (int)
block_time_ms int
field (int)

struct OsiTaskArgs

XuAPI
pub struct OsiTaskArgs {
    pub task_cb int    // index into ctx.task_cbs, the C version passes a pointer
    pub name string
    pub stack_depth int
    pub param int
    pub prio int
    pub task_handle int
    pub core_id int
}

Purpose

_task_create(task_func, name, stack_depth, param, prio, task_handle, core_id).

Public fields

task_cb int // index into ctx.task_cbs, the C version passes a pointer
field (int // index into ctx.task_cbs, the C version passes a pointer)
name string
name
stack_depth int
field (int)
param int
field (int)
prio int
field (int)
task_handle int
field (int)
core_id int
field (int)

struct OsiCoexArgs

XuAPI
pub struct OsiCoexArgs {
    pub event int
    pub latency int
    pub duration int
}

Purpose

_coex_bt_request(event, latency, duration).

Public fields

event int
field (int)
latency int
field (int)
duration int
field (int)

struct VhciHostCallback

XuAPI
pub struct VhciHostCallback {
    pub notify_host_send_available fn()
    pub notify_host_recv fn(int, int) int
}

Purpose

Host side callbacks of the VHCI transport. The C contract (components/bt/include/esp32/include/esp_bt.h:388-419) is void (*notify_host_send_available)(void) int (*notify_host_recv)(uint8_t *data, uint16_t len) The Xu version replaces the uint8_t *data pointer with a slot index into the receive pool owned by the context, because Xu has no int-to-pointer conversion. The host reads the bytes from btdm_vhci_rx_slot.

Public fields

notify_host_send_available fn()
field (function value; type fn())
notify_host_recv fn(int, int) int
field (function value; type fn(int, int) int)

struct VhciState

XuAPI
pub struct VhciState {
    pub registered bool
    pub notify_host_send_available fn()
    pub notify_host_recv fn(int, int) int
    pub send_available bool
    pub tx_packets int
    pub tx_bytes int
    pub rx_packets int
    pub tx_slot int
    pub tx_len int
    pub rx_slot int
    pub rx_len int
    pub notify_send_available_calls int
    pub notify_recv_calls int
}

Purpose

VHCI transport state.

Public fields

registered bool
field (bool)
notify_host_send_available fn()
field (function value; type fn())
notify_host_recv fn(int, int) int
field (function value; type fn(int, int) int)
send_available bool
field (bool)
tx_packets int
field (int)
tx_bytes int
field (int)
rx_packets int
field (int)
tx_slot int
field (int)
tx_len int
field (int)
rx_slot int
field (int)
rx_len int
field (int)
notify_send_available_calls int
Number of times the host callbacks were invoked. The counters are incremented *after* the callback returned, so a non zero value proves that the callback really ran.
notify_recv_calls int
field (int)

struct BtdmController

XuAPI
pub struct BtdmController {
    pub status int
    pub mode int
    pub config_mask int
    pub lpclk_sel int
    pub lpclk_div int
    pub registered bool
    pub osi OsiFuncs
    pub backend BtBackend
    pub lpcycle_us int
    pub lpcycle_us_frac int
    pub sleep_mode int
    pub sleep_enabled bool
    pub in_wakeup_requesting bool
    pub power_active bool
    pub int_depth int
    pub ints_mask int
    pub isr_handlers []int
    pub isr_args []int
    pub rand_state int
    pub tick int
    pub sem_active []int
    pub sem_count []int
    pub sem_max []int
    pub mutex_active []int
    pub mutex_locked []int
    pub mutex_owner []int
    pub queue_active []int
    pub queue_len []int
    pub queue_item_size []int
    pub queue_items []int
    pub queue_head []int
    pub queue_tail []int
    pub pool []int
    pub mac_bytes []int
    pub mac_slots []int
    pub task_cbs []int
    pub task_count int
    pub work_ids []int
    pub work_args []int
    pub work_head int
    pub work_tail int
    pub task KeTask
    pub vhci VhciState
}

Purpose

Structure encapsulating status, mode, config_mask, lpclk_sel, lpclk_div.

Public fields

status int
Controller status and mode.
mode int
mode
config_mask int
field (int)
lpclk_sel int
field (int)
lpclk_div int
field (int)
registered bool
field (bool)
osi OsiFuncs
The OSI table. The table holds fn values that take a writable borrow of the controller, so the type graph is cyclic by design.
backend BtBackend
Chip binding hooks (see backend.xu). A chip package fills this in the default hooks report failure instead of touching an unknown register, so a controller created without a binding is still safe.
lpcycle_us int
Low power clock calibration (bt.c: btdm_lpcycle_us / _frac).
lpcycle_us_frac int
field (int)
sleep_mode int
Sleep / power state.
sleep_enabled bool
field (bool)
in_wakeup_requesting bool
field (bool)
power_active bool
field (bool)
int_depth int
Interrupt bookkeeping.
ints_mask int
field (int)
isr_handlers []int
field ([]int)
isr_args []int
field ([]int)
rand_state int
Random number generator state.
tick int
Tick counter for the controller task.
sem_active []int
Counting semaphores.
sem_count []int
field ([]int)
sem_max []int
field ([]int)
mutex_active []int
Mutexes.
mutex_locked []int
field ([]int)
mutex_owner []int
field ([]int)
queue_active []int
Message queues.
queue_len []int
field ([]int)
queue_item_size []int
field ([]int)
queue_items []int
field ([]int)
queue_head []int
field ([]int)
queue_tail []int
field ([]int)
pool []int
VHCI byte pool (transmit slots followed by receive slots).
mac_bytes []int
Bluetooth MAC.
mac_slots []int
field ([]int)
task_cbs []int
Task registry (the C version creates real FreeRTOS tasks).
task_count int
field (int)
work_ids []int
Work items pending for the controller task.
work_args []int
field ([]int)
work_head int
field (int)
work_tail int
field (int)
task KeTask
Controller task context.
vhci VhciState
VHCI transport.

struct OsiFuncs

XuAPI
pub struct OsiFuncs {
    pub version int
    pub set_isr fn($&BtdmController, OsiIsrArgs) int
    pub ints_on fn($&BtdmController, int)
    pub interrupt_disable fn($&BtdmController)
    pub interrupt_restore fn($&BtdmController)
    pub task_yield fn($&BtdmController)
    pub task_yield_from_isr fn($&BtdmController)
    pub semphr_create fn($&BtdmController, int, int) int
    pub semphr_delete fn($&BtdmController, int)
    pub semphr_take_from_isr fn($&BtdmController, int, int) int
    pub semphr_give_from_isr fn($&BtdmController, int, int) int
    pub semphr_take fn($&BtdmController, int, int) int
    pub semphr_give fn($&BtdmController, int) int
    pub mutex_create fn($&BtdmController) int
    pub mutex_delete fn($&BtdmController, int)
    pub mutex_lock fn($&BtdmController, int) int
    pub mutex_unlock fn($&BtdmController, int) int
    pub queue_create fn($&BtdmController, int, int) int
    pub queue_delete fn($&BtdmController, int)
    pub queue_send fn($&BtdmController, OsiQueueArgs) int
    pub queue_send_from_isr fn($&BtdmController, OsiQueueArgs) int
    pub queue_recv fn($&BtdmController, OsiQueueArgs) int
    pub queue_recv_from_isr fn($&BtdmController, OsiQueueArgs) int
    pub task_create fn($&BtdmController, OsiTaskArgs) int
    pub task_delete fn($&BtdmController, int)
    pub is_in_isr fn($&BtdmController) bool
    pub cause_sw_intr_to_core fn($&BtdmController, int, int) int
    pub malloc fn($&BtdmController, int) int
    pub malloc_internal fn($&BtdmController, int) int
    pub free fn($&BtdmController, int)
    pub read_efuse_mac fn($&BtdmController, int) int
    pub srand fn($&BtdmController, int)
    pub rand fn($&BtdmController) int
    pub btdm_lpcycles_2_us fn($&BtdmController, int) int
    pub btdm_us_2_lpcycles fn($&BtdmController, int) int
    pub btdm_sleep_check_duration fn($&BtdmController, $&int) bool
    pub btdm_sleep_enter_phase1 fn($&BtdmController, int)
    pub btdm_sleep_enter_phase2 fn($&BtdmController)
    pub btdm_sleep_exit_phase1 fn($&BtdmController)
    pub btdm_sleep_exit_phase2 fn($&BtdmController)
    pub btdm_sleep_exit_phase3 fn($&BtdmController)
    pub coex_bt_wakeup_request fn($&BtdmController) bool
    pub coex_bt_wakeup_request_end fn($&BtdmController)
    pub coex_bt_request fn($&BtdmController, OsiCoexArgs) int
    pub coex_bt_release fn($&BtdmController, int) int
    pub coex_register_bt_cb fn($&BtdmController, int) int
    pub coex_bb_reset_lock fn($&BtdmController) int
    pub coex_bb_reset_unlock fn($&BtdmController, int)
    pub coex_schm_register_btdm_callback fn($&BtdmController, int) int
    pub coex_schm_status_bit_clear fn($&BtdmController, int, int)
    pub coex_schm_status_bit_set fn($&BtdmController, int, int)
    pub coex_schm_interval_get fn($&BtdmController) int
    pub coex_schm_curr_period_get fn($&BtdmController) int
    pub coex_schm_curr_phase_get fn($&BtdmController) int
    pub coex_wifi_channel_get fn($&BtdmController, int) int
    pub coex_register_wifi_channel_change_callback fn($&BtdmController, int) int
    pub set_isr_l3 fn($&BtdmController, OsiIsrArgs) int
    pub interrupt_l3_disable fn($&BtdmController)
    pub interrupt_l3_restore fn($&BtdmController)
    pub customer_queue_create fn($&BtdmController, int, int) int
    pub magic int
}

Purpose

The 59 function slots of struct osi_funcs_t, in the C field order.

Public fields

version int
field (int)
set_isr fn($&BtdmController, OsiIsrArgs) int
field (function value; type fn($&BtdmController, OsiIsrArgs) int)
ints_on fn($&BtdmController, int)
field (function value; type fn($&BtdmController, int))
interrupt_disable fn($&BtdmController)
field (function value; type fn($&BtdmController))
interrupt_restore fn($&BtdmController)
field (function value; type fn($&BtdmController))
task_yield fn($&BtdmController)
field (function value; type fn($&BtdmController))
task_yield_from_isr fn($&BtdmController)
field (function value; type fn($&BtdmController))
semphr_create fn($&BtdmController, int, int) int
field (function value; type fn($&BtdmController, int, int) int)
semphr_delete fn($&BtdmController, int)
field (function value; type fn($&BtdmController, int))
semphr_take_from_isr fn($&BtdmController, int, int) int
field (function value; type fn($&BtdmController, int, int) int)
semphr_give_from_isr fn($&BtdmController, int, int) int
field (function value; type fn($&BtdmController, int, int) int)
semphr_take fn($&BtdmController, int, int) int
field (function value; type fn($&BtdmController, int, int) int)
semphr_give fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
mutex_create fn($&BtdmController) int
field (function value; type fn($&BtdmController) int)
mutex_delete fn($&BtdmController, int)
field (function value; type fn($&BtdmController, int))
mutex_lock fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
mutex_unlock fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
queue_create fn($&BtdmController, int, int) int
field (function value; type fn($&BtdmController, int, int) int)
queue_delete fn($&BtdmController, int)
field (function value; type fn($&BtdmController, int))
queue_send fn($&BtdmController, OsiQueueArgs) int
field (function value; type fn($&BtdmController, OsiQueueArgs) int)
queue_send_from_isr fn($&BtdmController, OsiQueueArgs) int
field (function value; type fn($&BtdmController, OsiQueueArgs) int)
queue_recv fn($&BtdmController, OsiQueueArgs) int
field (function value; type fn($&BtdmController, OsiQueueArgs) int)
queue_recv_from_isr fn($&BtdmController, OsiQueueArgs) int
field (function value; type fn($&BtdmController, OsiQueueArgs) int)
task_create fn($&BtdmController, OsiTaskArgs) int
field (function value; type fn($&BtdmController, OsiTaskArgs) int)
task_delete fn($&BtdmController, int)
field (function value; type fn($&BtdmController, int))
is_in_isr fn($&BtdmController) bool
field (function value; type fn($&BtdmController) bool)
cause_sw_intr_to_core fn($&BtdmController, int, int) int
field (function value; type fn($&BtdmController, int, int) int)
malloc fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
malloc_internal fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
free fn($&BtdmController, int)
field (function value; type fn($&BtdmController, int))
read_efuse_mac fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
srand fn($&BtdmController, int)
field (function value; type fn($&BtdmController, int))
rand fn($&BtdmController) int
field (function value; type fn($&BtdmController) int)
btdm_lpcycles_2_us fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
btdm_us_2_lpcycles fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
btdm_sleep_check_duration fn($&BtdmController, $&int) bool
field (function value; type fn($&BtdmController, $&int) bool)
btdm_sleep_enter_phase1 fn($&BtdmController, int)
field (function value; type fn($&BtdmController, int))
btdm_sleep_enter_phase2 fn($&BtdmController)
field (function value; type fn($&BtdmController))
btdm_sleep_exit_phase1 fn($&BtdmController)
field (function value; type fn($&BtdmController))
btdm_sleep_exit_phase2 fn($&BtdmController)
field (function value; type fn($&BtdmController))
btdm_sleep_exit_phase3 fn($&BtdmController)
field (function value; type fn($&BtdmController))
coex_bt_wakeup_request fn($&BtdmController) bool
field (function value; type fn($&BtdmController) bool)
coex_bt_wakeup_request_end fn($&BtdmController)
field (function value; type fn($&BtdmController))
coex_bt_request fn($&BtdmController, OsiCoexArgs) int
field (function value; type fn($&BtdmController, OsiCoexArgs) int)
coex_bt_release fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
coex_register_bt_cb fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
coex_bb_reset_lock fn($&BtdmController) int
field (function value; type fn($&BtdmController) int)
coex_bb_reset_unlock fn($&BtdmController, int)
field (function value; type fn($&BtdmController, int))
coex_schm_register_btdm_callback fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
coex_schm_status_bit_clear fn($&BtdmController, int, int)
field (function value; type fn($&BtdmController, int, int))
coex_schm_status_bit_set fn($&BtdmController, int, int)
field (function value; type fn($&BtdmController, int, int))
coex_schm_interval_get fn($&BtdmController) int
field (function value; type fn($&BtdmController) int)
coex_schm_curr_period_get fn($&BtdmController) int
field (function value; type fn($&BtdmController) int)
coex_schm_curr_phase_get fn($&BtdmController) int
field (function value; type fn($&BtdmController) int)
coex_wifi_channel_get fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
coex_register_wifi_channel_change_callback fn($&BtdmController, int) int
field (function value; type fn($&BtdmController, int) int)
set_isr_l3 fn($&BtdmController, OsiIsrArgs) int
field (function value; type fn($&BtdmController, OsiIsrArgs) int)
interrupt_l3_disable fn($&BtdmController)
field (function value; type fn($&BtdmController))
interrupt_l3_restore fn($&BtdmController)
field (function value; type fn($&BtdmController))
customer_queue_create fn($&BtdmController, int, int) int
field (function value; type fn($&BtdmController, int, int) int)
magic int
field (int)

btdm_controller_create

XuAPI
pub fn btdm_controller_create() BtdmController

Purpose

Create a controller instance. The caller owns the value; there is no package global because xu forbids mutable globals.

Parameters

No arguments are required.

Returns

BtdmController — a value of this type

btdm_osi_funcs_ro

XuAPI
pub fn btdm_osi_funcs_ro() OsiFuncs

Purpose

Build the read only OSI table. The field order mirrors struct osi_funcs_t in bt.c line by line.

Parameters

No arguments are required.

Returns

OsiFuncs — a value of this type

btdm_osi_funcs_register

XuAPI
pub fn btdm_osi_funcs_register(ctl $&BtdmController) int

Purpose

btdm_osi_funcs_register(void *osi_funcs) The C version hands the table to the closed source controller. The Xu version validates the table identity and records it on the controller. The validation order and the return codes below are not guesses: they are recovered from the closed library by REA/Ghidra. The esp32 variant is undefined4 btdm_osi_funcs_register(int *param_1) { uVar1 = -1; // null pointer if (param_1 != NULL) { uVar1 = -2; // magic mismatch if ((param_1[0x3c] == 0xFADEBEAD) // _magic, offset 0xF0 && (uVar1 = -3, *param_1 == 0x00010003)) { // _version, offset 0x00 uVar1 = 0 r_osi_funcs_p = param_1 } } return uVar1 } So the magic is compared FIRST (short-circuit &&), the version SECOND. The esp32 controller prints no diagnostic on mismatch, which is why the return code is the only signal a caller gets.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)

Returns

int — a value of this type

btdm_dispatch_work_to_controller

XuAPI
pub fn btdm_dispatch_work_to_controller(ctl $&BtdmController, work_id int, arg int, blocking bool) int

Purpose

Dispatch work to the controller task context. The C signature is int btdm_dispatch_work_to_controller(workitem_handler_t cb, void *arg, bool blocking) The Xu version identifies the work item by an id instead of a function pointer, because an Xu fn value cannot be nested inside a function type. blocking selects whether the caller waits for the work to be executed.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)
work_id int
work_id (int)
arg int
arg (int)
blocking bool
blocking (bool)

Returns

int — a value of this type

btdm_controller_pump

XuAPI
pub fn btdm_controller_pump(ctl $&BtdmController, max_events int) int

Purpose

Run the controller task loop for up to max_events posted events.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)
max_events int
max_events (int)

Returns

int — a value of this type

api_vhci_host_register_callback

XuAPI
pub fn api_vhci_host_register_callback(ctx $&BtdmController, cb VhciHostCallback) int

Purpose

api_vhci_host_register_callback(const vhci_host_callback_t *callback)

Parameters

ctx $&BtdmController
ctx (exclusive borrow; may modify the original; type $&BtdmController)
cb VhciHostCallback
cb (VhciHostCallback)

Returns

int — a value of this type

api_vhci_host_check_send_available

XuAPI
pub fn api_vhci_host_check_send_available(ctx $&BtdmController) bool

Purpose

api_vhci_host_check_send_available(void) True when the controller can accept another packet from the host.

Parameters

ctx $&BtdmController
ctx (exclusive borrow; may modify the original; type $&BtdmController)

Returns

bool — true or false

api_vhci_host_send_packet

XuAPI
pub fn api_vhci_host_send_packet(ctx $&BtdmController, frame []int)

Purpose

api_vhci_host_send_packet(uint8_t *data, uint16_t len) frame is the H4 framed packet (type byte + payload). The C contract is a *copy* contract: the host frees its buffer as soon as the call returns (ble_hci_trans_buf_free(cmd) in the NimBLE transport), so the controller must copy the bytes before returning. The Xu port copies the frame into the transmit pool of the context.

Parameters

ctx $&BtdmController
ctx (exclusive borrow; may modify the original; type $&BtdmController)
frame []int
frame ([]int)

Returns

This call does not return a value.

btdm_vhci_tx_byte

XuAPI
pub fn btdm_vhci_tx_byte(ctx &BtdmController, slot int, index int) int

Purpose

Bytes of a transmitted frame, for inspection and for the self test.

Parameters

ctx &BtdmController
ctx (read-only borrow; caller keeps the original; type &BtdmController)
slot int
slot (int)
index int
index (int)

Returns

int — a value of this type

btdm_vhci_deliver_to_host

XuAPI
pub fn btdm_vhci_deliver_to_host(ctx $&BtdmController, frame []int) int

Purpose

Deliver a packet from the controller to the host. The controller owns the buffer: the host callback receives a slot index and the length, and reads the bytes with btdm_vhci_rx_byte.

Parameters

ctx $&BtdmController
ctx (exclusive borrow; may modify the original; type $&BtdmController)
frame []int
frame ([]int)

Returns

int — a value of this type

btdm_vhci_rx_byte

XuAPI
pub fn btdm_vhci_rx_byte(ctx &BtdmController, slot int, index int) int

Purpose

Byte of a received frame.

Parameters

ctx &BtdmController
ctx (read-only borrow; caller keeps the original; type &BtdmController)
slot int
slot (int)
index int
index (int)

Returns

int — a value of this type

const BTDM_ASYNC_WAKEUP_REQ_HCI

XuAPI
pub const BTDM_ASYNC_WAKEUP_REQ_HCI = 0

Purpose

Asynchronous wake up request sources (bt.c lines 1031-1034).

const BTDM_ASYNC_WAKEUP_REQ_COEX

XuAPI
pub const BTDM_ASYNC_WAKEUP_REQ_COEX = 1

Purpose

Constant BTDM_ASYNC_WAKEUP_REQ_COEX, defining protocol or algorithm parameters.

const BTDM_ASYNC_WAKEUP_REQ_CTRL_DISA

XuAPI
pub const BTDM_ASYNC_WAKEUP_REQ_CTRL_DISA = 2

Purpose

Constant BTDM_ASYNC_WAKEUP_REQ_CTRL_DISA, defining protocol or algorithm parameters.

btdm_power_state_active

XuAPI
pub fn btdm_power_state_active(ctl &BtdmController) bool

Purpose

btdm_power_state_active(void)

Parameters

ctl &BtdmController
ctl (read-only borrow; caller keeps the original; type &BtdmController)

Returns

bool — true or false

btdm_wakeup_request

XuAPI
pub fn btdm_wakeup_request(ctl $&BtdmController)

Purpose

btdm_wakeup_request(void) TODO(BTDM-P2): the real wake up request pokes the closed source controller (rwip.o). The xu port raises the power state and asks the controller task to run.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)

Returns

This call does not return a value.

btdm_in_wakeup_requesting_set

XuAPI
pub fn btdm_in_wakeup_requesting_set(ctl $&BtdmController, in_wakeup_requesting bool)

Purpose

btdm_in_wakeup_requesting_set(bool in_wakeup_requesting)

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)
in_wakeup_requesting bool
in_wakeup_requesting (bool)

Returns

This call does not return a value.

btdm_controller_enable_sleep

XuAPI
pub fn btdm_controller_enable_sleep(ctl $&BtdmController, enable bool)

Purpose

btdm_controller_enable_sleep(bool enable)

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)
enable bool
enable (bool)

Returns

This call does not return a value.

btdm_controller_set_sleep_mode

XuAPI
pub fn btdm_controller_set_sleep_mode(ctl $&BtdmController, mode int)

Purpose

btdm_controller_set_sleep_mode(uint8_t mode)

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)
mode int
mode (int)

Returns

This call does not return a value.

btdm_controller_get_sleep_mode

XuAPI
pub fn btdm_controller_get_sleep_mode(ctl &BtdmController) int

Purpose

btdm_controller_get_sleep_mode(void)

Parameters

ctl &BtdmController
ctl (read-only borrow; caller keeps the original; type &BtdmController)

Returns

int — a value of this type

btdm_async_wakeup_request

XuAPI
pub fn btdm_async_wakeup_request(ctx $&BtdmController, event int) bool

Purpose

Asynchronous wake up handshake (bt.c lines 1052-1108).

Parameters

ctx $&BtdmController
ctx (exclusive borrow; may modify the original; type $&BtdmController)
event int
event (int)

Returns

bool — true or false

btdm_async_wakeup_request_end

XuAPI
pub fn btdm_async_wakeup_request_end(ctx $&BtdmController, event int)

Purpose

Btdm async wakeup request end.

Parameters

ctx $&BtdmController
ctx (exclusive borrow; may modify the original; type $&BtdmController)
event int
event (int)

Returns

This call does not return a value.

btdm_lpclk_select_src

XuAPI
pub fn btdm_lpclk_select_src(ctl $&BtdmController, sel int) bool

Purpose

btdm_lpclk_select_src(uint32_t sel) Selects the low power clock source. The source selection is a chip register, so the actual write goes through the chip binding hooks in backend.xu; this layer only validates the request.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)
sel int
sel (int)

Returns

bool — true or false

btdm_lpclk_set_div

XuAPI
pub fn btdm_lpclk_set_div(ctl $&BtdmController, div int) bool

Purpose

btdm_lpclk_set_div(uint32_t div) Writes the 12 bit integer divider of the low power clock. The fractional divider fields are left untouched because the C contract only carries an integer divider.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)
div int
div (int)

Returns

bool — true or false

btdm_lpclk_select_src_raw

XuAPI
pub fn btdm_lpclk_select_src_raw(backend &BtBackend, sel int) bool

Purpose

Low power clock source selection without a controller instance. sel is one of BTDM_LPCLK_SEL_XTAL / _XTAL32K / _RTC_SLOW / _8M. The mapping from that selection to the chip register bits belongs to the chip binding.

Parameters

backend &BtBackend
backend (read-only borrow; caller keeps the original; type &BtBackend)
sel int
sel (int)

Returns

bool — true or false

btdm_lpclk_set_div_raw

XuAPI
pub fn btdm_lpclk_set_div_raw(backend &BtBackend, div int) bool

Purpose

Low power clock divider without a controller instance. ESP-IDF computes the divider as esp_clk_xtal_freq * 2 / MHZ - 1, which is 79 for the 40 MHz main crystal of the ESP32.

Parameters

backend &BtBackend
backend (read-only borrow; caller keeps the original; type &BtBackend)
div int
div (int)

Returns

bool — true or false

btdm_lpclk_configure_default

XuAPI
pub fn btdm_lpclk_configure_default(backend &BtBackend) bool

Purpose

Configure the Bluetooth low power clock the way the C init path does main crystal as the source and the 40 MHz / 80 / 2 divider.

Parameters

backend &BtBackend
backend (read-only borrow; caller keeps the original; type &BtBackend)

Returns

bool — true or false

btdm_lpclk_div_int

XuAPI
pub fn btdm_lpclk_div_int(backend &BtBackend) int

Purpose

Read back the low power clock state, for the self test.

Parameters

backend &BtBackend
backend (read-only borrow; caller keeps the original; type &BtBackend)

Returns

int — a value of this type

btdm_lpclk_frac

XuAPI
pub fn btdm_lpclk_frac(backend &BtBackend) int

Purpose

Btdm lpclk frac.

Parameters

backend &BtBackend
backend (read-only borrow; caller keeps the original; type &BtBackend)

Returns

int — a value of this type

btdm_config_mask_load

XuAPI
pub fn btdm_config_mask_load() int

Purpose

Configuration mask of this build (bt.c lines 1251-1269). The ESP32 build scans with duplicates enabled and reserves the extra advertising room; the UART transport and the second CPU are off.

Parameters

No arguments are required.

Returns

int — a value of this type

btdm_controller_init

XuAPI
pub fn btdm_controller_init(ctl $&BtdmController, config_mask int, mode int) int

Purpose

btdm_controller_init(uint32_t config_mask, esp_bt_controller_config_t *cfg) The C version hands the configuration to the closed source controller. The Xu port initialises the OSI table, the low power clock and the controller task, and records the requested mode.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)
config_mask int
config_mask (int)
mode int
mode (int)

Returns

int — a value of this type

btdm_controller_enable

XuAPI
pub fn btdm_controller_enable(ctl $&BtdmController, mode int) int

Purpose

btdm_controller_enable(esp_bt_mode_t mode)

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)
mode int
mode (int)

Returns

int — a value of this type

btdm_controller_disable

XuAPI
pub fn btdm_controller_disable(ctl $&BtdmController) int

Purpose

btdm_controller_disable(void)

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)

Returns

int — a value of this type

btdm_controller_deinit

XuAPI
pub fn btdm_controller_deinit(ctl $&BtdmController) int

Purpose

btdm_controller_deinit(void)

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)

Returns

int — a value of this type

btdm_controller_get_mode

XuAPI
pub fn btdm_controller_get_mode(ctl &BtdmController) int

Purpose

btdm_controller_get_mode(void)

Parameters

ctl &BtdmController
ctl (read-only borrow; caller keeps the original; type &BtdmController)

Returns

int — a value of this type

btdm_controller_get_compile_version

XuAPI
pub fn btdm_controller_get_compile_version(ctl &BtdmController) string

Purpose

btdm_controller_get_compile_version(void)

Parameters

ctl &BtdmController
ctl (read-only borrow; caller keeps the original; type &BtdmController)

Returns

string — result string

esp_bt_controller_shutdown

XuAPI
pub fn esp_bt_controller_shutdown(ctl $&BtdmController)

Purpose

esp_bt_controller_shutdown(void) TODO(BTDM-P2): the C version stops the controller and powers the PHY off. The xu port stops the controller task and marks the controller idle.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)

Returns

This call does not return a value.

btdm_set_mac

XuAPI
pub fn btdm_set_mac(ctl $&BtdmController, mac []int)

Purpose

Inject the Bluetooth MAC into the context (see osi_read_efuse_mac).

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)
mac []int
mac ([]int)

Returns

This call does not return a value.

ble_txpwr_set

XuAPI
pub fn ble_txpwr_set(power_type int, power_level int) int

Purpose

ble_txpwr_set(int power_type, int power_level)

Parameters

power_type int
power_type (int)
power_level int
power_level (int)

Returns

int — a value of this type

ble_txpwr_get

XuAPI
pub fn ble_txpwr_get(power_type int) int

Purpose

ble_txpwr_get(int power_type) Returns ESP_ERR_NOT_SUPPORTED rather than a plausible looking power level, so that a caller cannot mistake the placeholder for a real value.

Parameters

power_type int
power_type (int)

Returns

int — a value of this type

bredr_txpwr_set

XuAPI
pub fn bredr_txpwr_set(min_power_level int, max_power_level int) int

Purpose

bredr_txpwr_set(int min_power_level, int max_power_level)

Parameters

min_power_level int
min_power_level (int)
max_power_level int
max_power_level (int)

Returns

int — a value of this type

bredr_txpwr_get

XuAPI
pub fn bredr_txpwr_get(min_power_level int, max_power_level int) int

Purpose

bredr_txpwr_get(int *min_power_level, int *max_power_level)

Parameters

min_power_level int
min_power_level (int)
max_power_level int
max_power_level (int)

Returns

int — a value of this type

bredr_sco_datapath_set

XuAPI
pub fn bredr_sco_datapath_set(data_path int)

Purpose

bredr_sco_datapath_set(uint8_t data_path)

Parameters

data_path int
data_path (int)

Returns

This call does not return a value.

btdm_controller_scan_duplicate_list_clear

XuAPI
pub fn btdm_controller_scan_duplicate_list_clear(ctl $&BtdmController)

Purpose

btdm_controller_scan_duplicate_list_clear(void)

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)

Returns

This call does not return a value.

btdm_rf_bb_init_phase2

XuAPI
pub fn btdm_rf_bb_init_phase2(ctl $&BtdmController)

Purpose

btdm_rf_bb_init_phase2(void) TODO(BTDM-P2): the baseband initialisation after the PHY/RF is switched on belongs to the closed source radio core.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)

Returns

This call does not return a value.

btdm_irq_dispatch

XuAPI
pub fn btdm_irq_dispatch(ctx &BtdmController, n int) int

Purpose

Look up the interrupt handler that the OSI _set_isr slot registered for interrupt n and return its handler id (-1 when nothing is registered). The C _set_isr slot takes a function pointer. An Xu fn value cannot be nested inside a function type, so the Xu table stores a handler *id* and the application maps that id to its own handler. The application calls this from its fn irq_N entry.

Parameters

ctx &BtdmController
ctx (read-only borrow; caller keeps the original; type &BtdmController)
n int
count, length, or limit (int)

Returns

int — a value of this type

const DPORT_BT_LPCK_DIV_INT_REG

XuAPI
pub const DPORT_BT_LPCK_DIV_INT_REG   = 0x3FF000D4

Purpose

Constant DPORT_BT_LPCK_DIV_INT_REG, defining protocol or algorithm parameters.

const DPORT_BT_LPCK_DIV_FRAC_REG

XuAPI
pub const DPORT_BT_LPCK_DIV_FRAC_REG  = 0x3FF000D8

Purpose

Constant DPORT_BT_LPCK_DIV_FRAC_REG, defining protocol or algorithm parameters.

bt_backend_esp32

XuAPI
pub fn bt_backend_esp32() BtBackend

Purpose

Bt backend esp32.

Parameters

No arguments are required.

Returns

BtBackend — a value of this type

ble_btdm_create

XuAPI
pub fn ble_btdm_create() BtdmController

Purpose

Ble btdm create.

Parameters

No arguments are required.

Returns

BtdmController — a value of this type

ble_btdm_init

XuAPI
pub fn ble_btdm_init(ctl $&BtdmController, mode int) bool

Purpose

Ble btdm init.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)
mode int
mode (int)

Returns

bool — true or false

ble_btdm_enable

XuAPI
pub fn ble_btdm_enable(ctl $&BtdmController) bool

Purpose

Ble btdm enable.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)

Returns

bool — true or false

ble_btdm_disable

XuAPI
pub fn ble_btdm_disable(ctl $&BtdmController) bool

Purpose

Ble btdm disable.

Parameters

ctl $&BtdmController
ctl (exclusive borrow; may modify the original; type $&BtdmController)

Returns

bool — true or false

const HCI_PKT_COMMAND

XuAPI
pub const HCI_PKT_COMMAND = 0x01

Purpose

Constant HCI_PKT_COMMAND, defining protocol or algorithm parameters.

const HCI_PKT_ACLDATA

XuAPI
pub const HCI_PKT_ACLDATA = 0x02

Purpose

Constant HCI_PKT_ACLDATA, defining protocol or algorithm parameters.

const HCI_PKT_SCODATA

XuAPI
pub const HCI_PKT_SCODATA = 0x03

Purpose

Constant HCI_PKT_SCODATA, defining protocol or algorithm parameters.

const HCI_PKT_EVENT

XuAPI
pub const HCI_PKT_EVENT   = 0x04

Purpose

Constant HCI_PKT_EVENT, defining protocol or algorithm parameters.

const HCI_HDR_COMMAND

XuAPI
pub const HCI_HDR_COMMAND = 3

Purpose

Header sizes, excluding the packet type byte.

const HCI_HDR_ACL

XuAPI
pub const HCI_HDR_ACL     = 4

Purpose

Constant HCI_HDR_ACL, defining protocol or algorithm parameters.

const HCI_HDR_SCO

XuAPI
pub const HCI_HDR_SCO     = 3

Purpose

Constant HCI_HDR_SCO, defining protocol or algorithm parameters.

const HCI_HDR_EVENT

XuAPI
pub const HCI_HDR_EVENT   = 2

Purpose

Constant HCI_HDR_EVENT, defining protocol or algorithm parameters.

const HCI_MAX_PAYLOAD

XuAPI
pub const HCI_MAX_PAYLOAD = 255

Purpose

Constant HCI_MAX_PAYLOAD, defining protocol or algorithm parameters.

const HCI_MAX_FRAME

XuAPI
pub const HCI_MAX_FRAME   = 260

Purpose

1 (type byte) + HCI_HDR_ACL (4) + HCI_MAX_PAYLOAD (255). xu const initialisers must be literals, so the sum is written out.

const HCI_BTLE_ENC_RND

XuAPI
pub const HCI_BTLE_ENC_RND      = 0x01

Purpose

HCI packet types as seen on the wire.

const HCI_BTLE_ACL_START

XuAPI
pub const HCI_BTLE_ACL_START    = 0x02

Purpose

Constant HCI_BTLE_ACL_START, defining protocol or algorithm parameters.

const HCI_BTLE_ACL_CONT

XuAPI
pub const HCI_BTLE_ACL_CONT     = 0x03

Purpose

Constant HCI_BTLE_ACL_CONT, defining protocol or algorithm parameters.

const HCI_BTLE_SCO_START

XuAPI
pub const HCI_BTLE_SCO_START    = 0x08

Purpose

Constant HCI_BTLE_SCO_START, defining protocol or algorithm parameters.

const HCI_BTLE_SCO_CONT

XuAPI
pub const HCI_BTLE_SCO_CONT     = 0x09

Purpose

Constant HCI_BTLE_SCO_CONT, defining protocol or algorithm parameters.

const HCI_BTLE_SCO_COMPLETE

XuAPI
pub const HCI_BTLE_SCO_COMPLETE = 0x0A

Purpose

Constant HCI_BTLE_SCO_COMPLETE, defining protocol or algorithm parameters.

struct HciPacket

XuAPI
pub struct HciPacket {
    pub valid bool
    pub kind int      // HCI_PKT_*
    pub opcode int    // command opcode, or event code for events
    pub handle int    // ACL/SCO handle
    pub len int       // payload length in bytes
    pub payload []int // payload bytes, 0..255 each
}

Purpose

A decoded HCI packet.

Public fields

valid bool
field (bool)
kind int // HCI_PKT_*
kind tag
opcode int // command opcode, or event code for events
field (int // command opcode, or event code for events)
handle int // ACL/SCO handle
field (int // ACL/SCO handle)
len int // payload length in bytes
field (int // payload length in bytes)
payload []int // payload bytes, 0..255 each
field ([]int // payload bytes, 0..255 each)

hci_zeros

XuAPI
pub fn hci_zeros(n int) []int

Purpose

Allocate a zero filled byte buffer of n entries.

Parameters

n int
count, length, or limit (int)

Returns

[]int — slice result

hci_packet_command

XuAPI
pub fn hci_packet_command(opcode int, params []int) HciPacket

Purpose

Hci packet command.

Parameters

opcode int
opcode (int)
params []int
params ([]int)

Returns

HciPacket — a value of this type

hci_packet_acl

XuAPI
pub fn hci_packet_acl(handle int, params []int) HciPacket

Purpose

Hci packet acl.

Parameters

handle int
handle (int)
params []int
params ([]int)

Returns

HciPacket — a value of this type

hci_packet_sco

XuAPI
pub fn hci_packet_sco(handle int, params []int) HciPacket

Purpose

Hci packet sco.

Parameters

handle int
handle (int)
params []int
params ([]int)

Returns

HciPacket — a value of this type

hci_packet_event

XuAPI
pub fn hci_packet_event(code int, params []int) HciPacket

Purpose

Hci packet event.

Parameters

code int
code (int)
params []int
params ([]int)

Returns

HciPacket — a value of this type

hci_header_len

XuAPI
pub fn hci_header_len(kind int) int

Purpose

Header size of a packet kind, or -1 for an unknown kind.

Parameters

kind int
kind tag (int)

Returns

int — a value of this type

hci_frame_length

XuAPI
pub fn hci_frame_length(p &HciPacket) int

Purpose

Total wire length of a packet (type byte + header + payload).

Parameters

p &HciPacket
p (read-only borrow; caller keeps the original; type &HciPacket)

Returns

int — a value of this type

hci_frame_buffer

XuAPI
pub fn hci_frame_buffer(p &HciPacket) []int

Purpose

Allocate a buffer large enough to hold the framed packet.

Parameters

p &HciPacket
p (read-only borrow; caller keeps the original; type &HciPacket)

Returns

[]int — slice result

hci_encode

XuAPI
pub fn hci_encode(p &HciPacket) []int

Purpose

Encode p into a freshly allocated wire buffer. Returns the framed buffer; an invalid packet yields an empty buffer. xu slices are owning values: passing one to a function moves it, so the encoder allocates instead of filling a caller supplied buffer. Use hci_encode_into when the caller already owns a buffer and is done with it afterwards.

Parameters

p &HciPacket
p (read-only borrow; caller keeps the original; type &HciPacket)

Returns

[]int — slice result

hci_decode

XuAPI
pub fn hci_decode(buf &[]int, n int) HciPacket

Purpose

Decode one framed packet from buf[0..n). The decoder is tolerant: a truncated buffer yields an invalid packet instead of trapping, so the caller can resynchronise on the next type byte.

Parameters

buf &[]int
buffer (read-only borrow; caller keeps the original; type &[]int)
n int
count, length, or limit (int)

Returns

HciPacket — a value of this type

hci_frame

XuAPI
pub fn hci_frame(p &HciPacket) []int

Purpose

Convenience: build the wire buffer for a packet in one step.

Parameters

p &HciPacket
p (read-only borrow; caller keeps the original; type &HciPacket)

Returns

[]int — slice result

hci_classify

XuAPI
pub fn hci_classify(kind int) int

Purpose

Classify a raw packet type byte. Returns 0 for an unknown type.

Parameters

kind int
kind tag (int)

Returns

int — a value of this type

hci_cmd_reset

XuAPI
pub fn hci_cmd_reset() HciPacket

Purpose

1. HCI_Reset (0x0C03)

Parameters

No arguments are required.

Returns

HciPacket — a value of this type

hci_cmd_set_adv_params

XuAPI
pub fn hci_cmd_set_adv_params(min_int int, max_int int) HciPacket

Purpose

2. HCI_LE_Set_Advertising_Parameters (0x2006) min_int, max_int in units of 0.625ms (e.g. 0x0030 = 30ms)

Parameters

min_int int
min_int (int)
max_int int
max_int (int)

Returns

HciPacket — a value of this type

hci_cmd_set_adv_data

XuAPI
pub fn hci_cmd_set_adv_data(name string) HciPacket

Purpose

3. HCI_LE_Set_Advertising_Data (0x2008) flags + appearance (0x03C2 Mouse) + 16-bit UUID (0x1812 HID) + Complete Name

Parameters

name string
name (string)

Returns

HciPacket — a value of this type

hci_cmd_set_adv_enable

XuAPI
pub fn hci_cmd_set_adv_enable(enable bool) HciPacket

Purpose

4. HCI_LE_Set_Advertise_Enable (0x200A)

Parameters

enable bool
enable (bool)

Returns

HciPacket — a value of this type

const HID_RPT_ID_MOUSE

XuAPI
pub const HID_RPT_ID_MOUSE    = 1

Purpose

Constant HID_RPT_ID_MOUSE, defining protocol or algorithm parameters.

const HID_RPT_ID_KEYBOARD

XuAPI
pub const HID_RPT_ID_KEYBOARD = 2

Purpose

Constant HID_RPT_ID_KEYBOARD, defining protocol or algorithm parameters.

const HID_RPT_ID_CONSUMER

XuAPI
pub const HID_RPT_ID_CONSUMER = 3

Purpose

Constant HID_RPT_ID_CONSUMER, defining protocol or algorithm parameters.

const HID_MOUSE_ABS_MAX

XuAPI
pub const HID_MOUSE_ABS_MAX = 32767

Purpose

Absolute pointer logical range shared by Android/iOS absolute mouse hosts. Pixel mapping uses inclusive endpoints: 0 and span-1 own 0 and 32767.

const HID_CC_VOLUME_UP

XuAPI
pub const HID_CC_VOLUME_UP   = 0x01

Purpose

Standard USB HID Consumer Usage Codes

const HID_CC_VOLUME_DOWN

XuAPI
pub const HID_CC_VOLUME_DOWN = 0x02

Purpose

Constant HID_CC_VOLUME_DOWN, defining protocol or algorithm parameters.

const HID_CC_MUTE

XuAPI
pub const HID_CC_MUTE        = 0x04

Purpose

Constant HID_CC_MUTE, defining protocol or algorithm parameters.

const HID_CC_POWER

XuAPI
pub const HID_CC_POWER       = 0x08

Purpose

Constant HID_CC_POWER, defining protocol or algorithm parameters.

const HID_CC_MENU

XuAPI
pub const HID_CC_MENU        = 0x10

Purpose

Constant HID_CC_MENU, defining protocol or algorithm parameters.

const ATT_HANDLE_MOUSE_REPORT

XuAPI
pub const ATT_HANDLE_MOUSE_REPORT    = 0x0028

Purpose

GATT Handles for HID Attributes

const ATT_HANDLE_KEYBOARD_REPORT

XuAPI
pub const ATT_HANDLE_KEYBOARD_REPORT = 0x002C

Purpose

Constant ATT_HANDLE_KEYBOARD_REPORT, defining protocol or algorithm parameters.

const ATT_HANDLE_CONSUMER_REPORT

XuAPI
pub const ATT_HANDLE_CONSUMER_REPORT = 0x0030

Purpose

Constant ATT_HANDLE_CONSUMER_REPORT, defining protocol or algorithm parameters.

hogp_report_map

XuAPI
pub fn hogp_report_map() []int

Purpose

BLE HID Report Map: absolute mouse (no relative wheel), keyboard, consumer.

Parameters

No arguments are required.

Returns

[]int — slice result

hogp_scale_axis

XuAPI
pub fn hogp_scale_axis(pixel int, span int) int

Purpose

Map a pixel on [0, span) onto the absolute HID axis. Inclusive endpoints own 0 and HID_MOUSE_ABS_MAX so phone edges are not biased inward.

Parameters

pixel int
pixel (int)
span int
span (int)

Returns

int — a value of this type

hogp_build_mouse

XuAPI
pub fn hogp_build_mouse(buttons int, x int, y int) []int

Purpose

Build absolute Mouse Report (Report ID 1): buttons, X low/high, Y low/high.

Parameters

buttons int
buttons (int)
x int
value (int)
y int
value (int)

Returns

[]int — slice result

hogp_build_consumer

XuAPI
pub fn hogp_build_consumer(mask int) []int

Purpose

Build Consumer Control Report (Report ID 3)

Parameters

mask int
mask (int)

Returns

[]int — slice result

hogp_build_keyboard

XuAPI
pub fn hogp_build_keyboard(modifier int, keycode int) []int

Purpose

Build Keyboard Report (Report ID 2)

Parameters

modifier int
modifier (int)
keycode int
keycode (int)

Returns

[]int — slice result

hogp_make_acl_notification

XuAPI
pub fn hogp_make_acl_notification(conn_handle int, att_handle int, report []int) HciPacket

Purpose

Raw wire builder only: it does not imply encryption or a subscribed CCCD. Use AttServer.make_hid_notification for the connection's permission gate.

Parameters

conn_handle int
conn_handle (int)
att_handle int
att_handle (int)
report []int
report ([]int)

Returns

HciPacket — a value of this type

hogp_make_acl_notification_ref

XuAPI
pub fn hogp_make_acl_notification_ref(conn_handle int, att_handle int, report &[]int) HciPacket

Purpose

Hogp make acl notification ref.

Parameters

conn_handle int
conn_handle (int)
att_handle int
att_handle (int)
report &[]int
report (read-only borrow; caller keeps the original; type &[]int)

Returns

HciPacket — a value of this type

const KE_QUEUE_MAX

XuAPI
pub const KE_QUEUE_MAX = 32

Purpose

Constant KE_QUEUE_MAX, defining protocol or algorithm parameters.

const KE_TIMER_MAX

XuAPI
pub const KE_TIMER_MAX = 8

Purpose

Constant KE_TIMER_MAX, defining protocol or algorithm parameters.

struct KeTask

XuAPI
pub struct KeTask {
    pub name string
    pub event_ids []int      // FIFO event ids
    pub event_params []int   // FIFO event parameters
    pub timer_ids []int
    pub timer_deadlines []int
    pub timer_periods []int
    pub timer_active []int   // 0 = free, 1 = armed
    pub handler fn(int, int) int   // (event_id, param) -> status
    pub timer_handler fn(int) int  // (timer_id) -> status
    pub in_isr bool
    pub posted int
    pub dispatched int
    pub dropped int
    pub tick int
    pub dispatched_ids []int
    pub last_result int
}

Purpose

A controller task context.

Public fields

name string
name
event_ids []int // FIFO event ids
field ([]int // FIFO event ids)
event_params []int // FIFO event parameters
field ([]int // FIFO event parameters)
timer_ids []int
field ([]int)
timer_deadlines []int
field ([]int)
timer_periods []int
field ([]int)
timer_active []int // 0 = free, 1 = armed
field ([]int // 0 = free, 1 = armed)
handler fn(int, int) int // (event_id, param) -> status
field (function value; type fn(int, int) int // (event_id, param) -> status)
timer_handler fn(int) int // (timer_id) -> status
field (function value; type fn(int) int // (timer_id) -> status)
in_isr bool
field (bool)
posted int
field (int)
dispatched int
field (int)
dropped int
field (int)
tick int
field (int)
dispatched_ids []int
Dispatch order log and the result of the last handler call. They let a caller (and the self test) verify the FIFO order without having to capture state inside a callback, which xu does not allow.
last_result int
field (int)

ke_task_create

XuAPI
pub fn ke_task_create(name string, handler fn(int, int) int, timer_handler fn(int) int) KeTask

Purpose

Ke task create.

Parameters

name string
name (string)
handler fn(int, int) int
handler (function value; type fn(int, int) int)
timer_handler fn(int) int
timer_handler (function value; type fn(int) int)

Returns

KeTask — a value of this type

ke_post_event

XuAPI
pub fn ke_post_event(t $&KeTask, id int, param int) bool

Purpose

Post an event to the task queue. Returns false when the queue is full, mirroring the FreeRTOS xQueueSend failure path used by the original queue_send OSI wrapper.

Parameters

t $&KeTask
t (exclusive borrow; may modify the original; type $&KeTask)
id int
id (int)
param int
param (int)

Returns

bool — true or false

ke_post_event_isr

XuAPI
pub fn ke_post_event_isr(t $&KeTask, id int, param int) bool

Purpose

Post from an interrupt handler. The xu bare metal model has a single execution context, so the ISR path only records that we are inside an ISR the actual queueing still happens in FIFO order.

Parameters

t $&KeTask
t (exclusive borrow; may modify the original; type $&KeTask)
id int
id (int)
param int
param (int)

Returns

bool — true or false

ke_peek_event_id

XuAPI
pub fn ke_peek_event_id(t &KeTask) int

Purpose

Id of the oldest pending event, or -1 when the queue is empty.

Parameters

t &KeTask
t (read-only borrow; caller keeps the original; type &KeTask)

Returns

int — a value of this type

ke_peek_event_param

XuAPI
pub fn ke_peek_event_param(t &KeTask) int

Purpose

Parameter of the oldest pending event, or -1 when the queue is empty.

Parameters

t &KeTask
t (read-only borrow; caller keeps the original; type &KeTask)

Returns

int — a value of this type

ke_pop_event

XuAPI
pub fn ke_pop_event(t $&KeTask) bool

Purpose

Drop the oldest event. Callers must have peeked it first.

Parameters

t $&KeTask
t (exclusive borrow; may modify the original; type $&KeTask)

Returns

bool — true or false

ke_run_once

XuAPI
pub fn ke_run_once(t $&KeTask) int

Purpose

Dispatch one event. Returns the number of events dispatched (0 or 1).

Parameters

t $&KeTask
t (exclusive borrow; may modify the original; type $&KeTask)

Returns

int — a value of this type

ke_run

XuAPI
pub fn ke_run(t $&KeTask, max_events int) int

Purpose

Dispatch up to max_events events in FIFO order. Returns the count.

Parameters

t $&KeTask
t (exclusive borrow; may modify the original; type $&KeTask)
max_events int
max_events (int)

Returns

int — a value of this type

ke_tick

XuAPI
pub fn ke_tick(t $&KeTask) int

Purpose

Advance the task tick counter.

Parameters

t $&KeTask
t (exclusive borrow; may modify the original; type $&KeTask)

Returns

int — a value of this type

ke_timer_add

XuAPI
pub fn ke_timer_add(t $&KeTask, now int, id int, delay int, period int) int

Purpose

Register a timer. delay is relative to now, period is the repeat interval in ticks (0 means one shot). Returns the timer slot index.

Parameters

t $&KeTask
t (exclusive borrow; may modify the original; type $&KeTask)
now int
now (int)
id int
id (int)
delay int
delay (int)
period int
period (int)

Returns

int — a value of this type

ke_timer_cancel

XuAPI
pub fn ke_timer_cancel(t $&KeTask, slot int) bool

Purpose

Ke timer cancel.

Parameters

t $&KeTask
t (exclusive borrow; may modify the original; type $&KeTask)
slot int
slot (int)

Returns

bool — true or false

ke_timer_poll

XuAPI
pub fn ke_timer_poll(t $&KeTask, now int) int

Purpose

Fire every timer whose deadline has passed. Returns the number of callbacks that ran.

Parameters

t $&KeTask
t (exclusive borrow; may modify the original; type $&KeTask)
now int
now (int)

Returns

int — a value of this type

const PERIPHERAL_QUEUE_SLOTS

XuAPI
pub const PERIPHERAL_QUEUE_SLOTS = 4

Purpose

Single-link peripheral host over actual H4 events/ACL. Fixed four-slot output queue and 27-byte L2CAP reassembly; no implicit encryption, keys, transport acknowledgements, controller credits or persistent bonding.

const PERIPHERAL_FRAME_BYTES

XuAPI
pub const PERIPHERAL_FRAME_BYTES = 32

Purpose

Constant PERIPHERAL_FRAME_BYTES, defining protocol or algorithm parameters.

const PERIPHERAL_ERROR_FRAME

XuAPI
pub const PERIPHERAL_ERROR_FRAME = 1

Purpose

Constant PERIPHERAL_ERROR_FRAME, defining protocol or algorithm parameters.

const PERIPHERAL_ERROR_UNSUPPORTED

XuAPI
pub const PERIPHERAL_ERROR_UNSUPPORTED = 2

Purpose

Constant PERIPHERAL_ERROR_UNSUPPORTED, defining protocol or algorithm parameters.

const PERIPHERAL_ERROR_QUEUE

XuAPI
pub const PERIPHERAL_ERROR_QUEUE = 3

Purpose

Constant PERIPHERAL_ERROR_QUEUE, defining protocol or algorithm parameters.

const PERIPHERAL_ERROR_ENTROPY

XuAPI
pub const PERIPHERAL_ERROR_ENTROPY = 4

Purpose

Constant PERIPHERAL_ERROR_ENTROPY, defining protocol or algorithm parameters.

const PERIPHERAL_ERROR_CREDITS

XuAPI
pub const PERIPHERAL_ERROR_CREDITS = 5

Purpose

Constant PERIPHERAL_ERROR_CREDITS, defining protocol or algorithm parameters.

const PERIPHERAL_ERROR_CONTROLLER

XuAPI
pub const PERIPHERAL_ERROR_CONTROLLER = 6

Purpose

Constant PERIPHERAL_ERROR_CONTROLLER, defining protocol or algorithm parameters.

const PERIPHERAL_ERROR_FRAGMENT

XuAPI
pub const PERIPHERAL_ERROR_FRAGMENT = 7

Purpose

Constant PERIPHERAL_ERROR_FRAGMENT, defining protocol or algorithm parameters.

const PERIPHERAL_ERROR_SECURITY

XuAPI
pub const PERIPHERAL_ERROR_SECURITY = 8

Purpose

Constant PERIPHERAL_ERROR_SECURITY, defining protocol or algorithm parameters.

const PERIPHERAL_ERROR_TIMEOUT

XuAPI
pub const PERIPHERAL_ERROR_TIMEOUT = 9

Purpose

Constant PERIPHERAL_ERROR_TIMEOUT, defining protocol or algorithm parameters.

struct PeripheralHost

XuAPI
pub struct PeripheralHost {
    pub ready bool
    pub connected bool
    pub closing bool
    pub connection int
    pub local_type int // set before connecting; default static random (HCI 2005)
    pub encrypted bool
    pub authenticated bool // legacy NoIO Just Works never sets this
    pub needs_advertising bool
    pub last_error int
    pub rejected_frames int
    pub acl_mtu int
    pub acl_capacity int
    pub acl_credits int
    pub acl_outstanding int
    pub command_credits int
    pub bond_available bool // one RAM record, not proof of an OS bond
    pub accept_connection_parameters bool // opt in to validated remote updates
}

Purpose

Structure encapsulating ready, connected, closing, connection, local_type.

Public fields

ready bool
field (bool)
connected bool
field (bool)
closing bool
field (bool)
connection int
field (int)
local_type int // set before connecting; default static random (HCI 2005)
field (int // set before connecting; default static random (HCI 2005))
encrypted bool
field (bool)
authenticated bool // legacy NoIO Just Works never sets this
field (bool // legacy NoIO Just Works never sets this)
needs_advertising bool
field (bool)
last_error int
field (int)
rejected_frames int
field (int)
acl_mtu int
field (int)
acl_capacity int
field (int)
acl_credits int
field (int)
acl_outstanding int
field (int)
command_credits int
field (int)
bond_available bool // one RAM record, not proof of an OS bond
field (bool // one RAM record, not proof of an OS bond)
accept_connection_parameters bool // opt in to validated remote updates
field (bool // opt in to validated remote updates)

($&PeripheralHost) set_device_name

XuAPI
pub fn (h $&PeripheralHost) set_device_name(name string) bool

Purpose

Set before connecting so GAP reads and advertising can use one name.

Parameters

h $&PeripheralHost
The PeripheralHost instance used by this call (exclusive borrow).
name string
name (string)

Returns

bool — true or false

peripheral_host_create

XuAPI
pub fn peripheral_host_create(local_addr []int, aes fn(&[]int, &[]int) []int, random fn(int) []int) PeripheralHost

Purpose

Peripheral host create.

Parameters

local_addr []int
local_addr ([]int)
aes fn(&[]int, &[]int) []int
aes (function value; type fn(&[]int, &[]int) []int)
random fn(int) []int
random (function value; type fn(int) []int)

Returns

PeripheralHost — a value of this type

($&PeripheralHost) next_output

XuAPI
pub fn (h $&PeripheralHost) next_output() []int

Purpose

Returned frames remain pending until output_accepted. Retry the same returned bytes on a blocked transport; this method never invents TX acks.

Parameters

h $&PeripheralHost
The PeripheralHost instance used by this call (exclusive borrow).

Returns

[]int — slice result

($&PeripheralHost) output_accepted

XuAPI
pub fn (h $&PeripheralHost) output_accepted() bool

Purpose

Operation on $&PeripheralHost: output accepted.

Parameters

h $&PeripheralHost
The PeripheralHost instance used by this call (exclusive borrow).

Returns

bool — true or false

($&PeripheralHost) poll

XuAPI
pub fn (h $&PeripheralHost) poll(now_ms int) []int

Purpose

Execute poll on $&PeripheralHost.

Parameters

h $&PeripheralHost
The PeripheralHost instance used by this call (exclusive borrow).
now_ms int
now_ms (int)

Returns

[]int — slice result

($&PeripheralHost) handle_h4

XuAPI
pub fn (h $&PeripheralHost) handle_h4(frame &[]int, now_ms int) []int

Purpose

Operation on $&PeripheralHost: handle h4.

Parameters

h $&PeripheralHost
The PeripheralHost instance used by this call (exclusive borrow).
frame &[]int
frame (read-only borrow; caller keeps the original; type &[]int)
now_ms int
now_ms (int)

Returns

[]int — slice result

($&PeripheralHost) queue_hid_notification

XuAPI
pub fn (h $&PeripheralHost) queue_hid_notification(handle int, report []int) bool

Purpose

Operation on $&PeripheralHost: queue hid notification.

Parameters

h $&PeripheralHost
The PeripheralHost instance used by this call (exclusive borrow).
handle int
handle (int)
report []int
report ([]int)

Returns

bool — true or false

(&PeripheralHost) hid_notifications_enabled

XuAPI
pub fn (h &PeripheralHost) hid_notifications_enabled(handle int) bool

Purpose

Operation on &PeripheralHost: hid notifications enabled.

Parameters

h &PeripheralHost
The PeripheralHost instance used by this call (borrow).
handle int
handle (int)

Returns

bool — true or false

($&PeripheralHost) request_disconnect

XuAPI
pub fn (h $&PeripheralHost) request_disconnect(error int) []int

Purpose

Application-side transport failures must revoke the real session without fabricating a controller event. Send the returned Disconnect like any other pending command; it still requires an actual command credit.

Parameters

h $&PeripheralHost
The PeripheralHost instance used by this call (exclusive borrow).
error int
error (int)

Returns

[]int — slice result

const SMP_CID

XuAPI
pub const SMP_CID = 0x0006

Purpose

Legacy Just Works peripheral SMP, one connection per instance. No SC, OOB, MITM, identity-key distribution, or signed-write support is claimed. AES uses Bluetooth little-endian key/block/result bytes. The caller must supply fresh 16-byte radio-entropy random material for every connection. Only TK is the protocol-defined zero value; STK/LTK are never constants.

const SMP_IDLE

XuAPI
pub const SMP_IDLE = 0

Purpose

Constant SMP_IDLE, defining protocol or algorithm parameters.

const SMP_WAIT_CONFIRM

XuAPI
pub const SMP_WAIT_CONFIRM = 1

Purpose

Constant SMP_WAIT_CONFIRM, defining protocol or algorithm parameters.

const SMP_WAIT_RANDOM

XuAPI
pub const SMP_WAIT_RANDOM = 2

Purpose

Constant SMP_WAIT_RANDOM, defining protocol or algorithm parameters.

const SMP_WAIT_ENCRYPTION

XuAPI
pub const SMP_WAIT_ENCRYPTION = 3

Purpose

Constant SMP_WAIT_ENCRYPTION, defining protocol or algorithm parameters.

const SMP_ENCRYPTED

XuAPI
pub const SMP_ENCRYPTED = 4

Purpose

Constant SMP_ENCRYPTED, defining protocol or algorithm parameters.

const SMP_FAILED

XuAPI
pub const SMP_FAILED = 5

Purpose

Constant SMP_FAILED, defining protocol or algorithm parameters.

const SMP_ERROR_OOB_UNAVAILABLE

XuAPI
pub const SMP_ERROR_OOB_UNAVAILABLE = 0x02

Purpose

Constant SMP_ERROR_OOB_UNAVAILABLE, defining protocol or algorithm parameters.

const SMP_ERROR_AUTH_REQUIREMENTS

XuAPI
pub const SMP_ERROR_AUTH_REQUIREMENTS = 0x03

Purpose

Constant SMP_ERROR_AUTH_REQUIREMENTS, defining protocol or algorithm parameters.

const SMP_ERROR_CONFIRM_FAILED

XuAPI
pub const SMP_ERROR_CONFIRM_FAILED = 0x04

Purpose

Constant SMP_ERROR_CONFIRM_FAILED, defining protocol or algorithm parameters.

const SMP_ERROR_KEY_SIZE

XuAPI
pub const SMP_ERROR_KEY_SIZE = 0x06

Purpose

Constant SMP_ERROR_KEY_SIZE, defining protocol or algorithm parameters.

const SMP_ERROR_COMMAND_UNSUPPORTED

XuAPI
pub const SMP_ERROR_COMMAND_UNSUPPORTED = 0x07

Purpose

Constant SMP_ERROR_COMMAND_UNSUPPORTED, defining protocol or algorithm parameters.

const SMP_ERROR_UNSPECIFIED

XuAPI
pub const SMP_ERROR_UNSPECIFIED = 0x08

Purpose

Constant SMP_ERROR_UNSPECIFIED, defining protocol or algorithm parameters.

const SMP_ERROR_REPEATED_ATTEMPTS

XuAPI
pub const SMP_ERROR_REPEATED_ATTEMPTS = 0x09

Purpose

Constant SMP_ERROR_REPEATED_ATTEMPTS, defining protocol or algorithm parameters.

const SMP_ERROR_INVALID_PARAMETERS

XuAPI
pub const SMP_ERROR_INVALID_PARAMETERS = 0x0A

Purpose

Constant SMP_ERROR_INVALID_PARAMETERS, defining protocol or algorithm parameters.

smp_c1

XuAPI
pub fn smp_c1(aes fn(&[]int, &[]int) []int, key &[]int, random &[]int, request &[]int, response &[]int, initiator_type int, responder_type int, initiator &[]int, responder &[]int) []int

Purpose

Core legacy c1: p1 = pres || preq || rat || iat and p2 = padding || ia || ra, represented least-significant byte first.

Parameters

aes fn(&[]int, &[]int) []int
aes (function value; type fn(&[]int, &[]int) []int)
key &[]int
key (read-only borrow; caller keeps the original; type &[]int)
random &[]int
random (read-only borrow; caller keeps the original; type &[]int)
request &[]int
request (read-only borrow; caller keeps the original; type &[]int)
response &[]int
response (read-only borrow; caller keeps the original; type &[]int)
initiator_type int
initiator_type (int)
responder_type int
responder_type (int)
initiator &[]int
initiator (read-only borrow; caller keeps the original; type &[]int)
responder &[]int
responder (read-only borrow; caller keeps the original; type &[]int)

Returns

[]int — slice result

smp_s1

XuAPI
pub fn smp_s1(aes fn(&[]int, &[]int) []int, key &[]int, responder_random &[]int, initiator_random &[]int) []int

Purpose

s1(TK, responder random, initiator random). Only their low 64 bits participate, matching ble_sm_alg_s1(rands, randm) in the reference host.

Parameters

aes fn(&[]int, &[]int) []int
aes (function value; type fn(&[]int, &[]int) []int)
key &[]int
key (read-only borrow; caller keeps the original; type &[]int)
responder_random &[]int
responder_random (read-only borrow; caller keeps the original; type &[]int)
initiator_random &[]int
initiator_random (read-only borrow; caller keeps the original; type &[]int)

Returns

[]int — slice result

struct SmpServer

XuAPI
pub struct SmpServer {
    pub ready bool
    pub connection int
    pub state int
    pub failure_reason int
    pub encrypted bool
    pub paired bool // encrypted legacy session, not a claim of bonding
    pub authenticated bool // always false for NoInputNoOutput Just Works
    pub require_authenticated bool // explicit strict policy rejects this JW-only server
    pub bonding bool
    pub bond_distributed bool
    pub timed_out bool
    pub initiator_type int
    pub responder_type int
}

Purpose

Structure encapsulating ready, connection, state, failure_reason, encrypted.

Public fields

ready bool
field (bool)
connection int
field (int)
state int
field (int)
failure_reason int
field (int)
encrypted bool
field (bool)
paired bool // encrypted legacy session, not a claim of bonding
field (bool // encrypted legacy session, not a claim of bonding)
authenticated bool // always false for NoInputNoOutput Just Works
field (bool // always false for NoInputNoOutput Just Works)
require_authenticated bool // explicit strict policy rejects this JW-only server
field (bool // explicit strict policy rejects this JW-only server)
bonding bool
field (bool)
bond_distributed bool
field (bool)
timed_out bool
field (bool)
initiator_type int
field (int)
responder_type int
field (int)

smp_server_create

XuAPI
pub fn smp_server_create(connection int, local_type int, local []int, peer_type int, peer []int, local_random []int, aes fn(&[]int, &[]int) []int) SmpServer

Purpose

Address bytes must be the exact little-endian addresses used on the connection (including random/static address type), not display strings.

Parameters

connection int
connection (int)
local_type int
local_type (int)
local []int
local ([]int)
peer_type int
peer_type (int)
peer []int
peer ([]int)
local_random []int
local_random ([]int)
aes fn(&[]int, &[]int) []int
aes (function value; type fn(&[]int, &[]int) []int)

Returns

SmpServer — a value of this type

($&SmpServer) provide_bond_material

XuAPI
pub fn (s $&SmpServer) provide_bond_material(ltk &[]int, random &[]int, ediv int) bool

Purpose

Optional fresh responder LTK material. No flash writes and no implicit random generation. A key with EDIV/RAND both zero would collide with STK.

Parameters

s $&SmpServer
The SmpServer instance used by this call (exclusive borrow).
ltk &[]int
ltk (read-only borrow; caller keeps the original; type &[]int)
random &[]int
random (read-only borrow; caller keeps the original; type &[]int)
ediv int
ediv (int)

Returns

bool — true or false

($&SmpServer) restore_bond

XuAPI
pub fn (s $&SmpServer) restore_bond(peer_type int, peer &[]int, ltk &[]int, random &[]int, ediv int) bool

Purpose

Restore only a bond matching this exact connection address/type. RPA identity resolution is not implemented. Do not replace the actual c1 connection addresses with identity addresses to work around a mismatch.

Parameters

s $&SmpServer
The SmpServer instance used by this call (exclusive borrow).
peer_type int
peer_type (int)
peer &[]int
peer (read-only borrow; caller keeps the original; type &[]int)
ltk &[]int
ltk (read-only borrow; caller keeps the original; type &[]int)
random &[]int
random (read-only borrow; caller keeps the original; type &[]int)
ediv int
ediv (int)

Returns

bool — true or false

($&SmpServer) poll_timeout

XuAPI
pub fn (s $&SmpServer) poll_timeout(now_ms int) bool

Purpose

Host must poll using its monotonic milliseconds and disconnect a timed out procedure. The deadline is renewed on each accepted SMP exchange. No further SMP messages are sent after the 30 s timeout.

Parameters

s $&SmpServer
The SmpServer instance used by this call (exclusive borrow).
now_ms int
now_ms (int)

Returns

bool — true or false

(&SmpServer) security_request

XuAPI
pub fn (s &SmpServer) security_request() []int

Purpose

Operation on &SmpServer: security request.

Parameters

s &SmpServer
The SmpServer instance used by this call (borrow).

Returns

[]int — slice result

($&SmpServer) handle_smp_pdu

XuAPI
pub fn (s $&SmpServer) handle_smp_pdu(pdu &[]int, now_ms int) []int

Purpose

Operation on $&SmpServer: handle smp pdu.

Parameters

s $&SmpServer
The SmpServer instance used by this call (exclusive borrow).
pdu &[]int
pdu (read-only borrow; caller keeps the original; type &[]int)
now_ms int
now_ms (int)

Returns

[]int — slice result

($&SmpServer) handle_ltk_request

XuAPI
pub fn (s $&SmpServer) handle_ltk_request(event &HciPacket) HciPacket

Purpose

Handles LE Long Term Key Request (subevent 05). The positive response is permitted only after confirm validation or for a restored peer bond.

Parameters

s $&SmpServer
The SmpServer instance used by this call (exclusive borrow).
event &HciPacket
event (read-only borrow; caller keeps the original; type &HciPacket)

Returns

HciPacket — a value of this type

($&SmpServer) handle_encryption_change

XuAPI
pub fn (s $&SmpServer) handle_encryption_change(event &HciPacket) bool

Purpose

Only verified HCI event 08 with matching connection and successful encryption can authorize ATT/HID. Pairing Confirm/Random alone cannot.

Parameters

s $&SmpServer
The SmpServer instance used by this call (exclusive borrow).
event &HciPacket
event (read-only borrow; caller keeps the original; type &HciPacket)

Returns

bool — true or false

(&SmpServer) key_distribution_pdu

XuAPI
pub fn (s &SmpServer) key_distribution_pdu() []int

Purpose

Peek without consuming: repeat this PDU until the host transport accepts it, then call key_distribution_sent. Key distribution is encrypted only.

Parameters

s &SmpServer
The SmpServer instance used by this call (borrow).

Returns

[]int — slice result

($&SmpServer) key_distribution_sent

XuAPI
pub fn (s $&SmpServer) key_distribution_sent() bool

Purpose

Operation on $&SmpServer: key distribution sent.

Parameters

s $&SmpServer
The SmpServer instance used by this call (exclusive borrow).

Returns

bool — true or false

($&SmpServer) process_smp_acl

XuAPI
pub fn (s $&SmpServer) process_smp_acl(packet &HciPacket, now_ms int) HciPacket

Purpose

Operation on $&SmpServer: process smp acl.

Parameters

s $&SmpServer
The SmpServer instance used by this call (exclusive borrow).
packet &HciPacket
packet (read-only borrow; caller keeps the original; type &HciPacket)
now_ms int
now_ms (int)

Returns

HciPacket — a value of this type

($&SmpServer) close_connection

XuAPI
pub fn (s $&SmpServer) close_connection()

Purpose

Revoke and erase a disconnected session. A caller that wants RAM-only reconnects must retain the provisioned bond separately before this call an MCU reset loses that store unless a separate persistent owner exists.

Parameters

s $&SmpServer
The SmpServer instance used by this call (exclusive borrow).

Returns

This call does not return a value.