### Codec Connection Setup Example Source: https://github.com/bluez/bluez/blob/master/doc/btmon-hfp.rst Example of codec negotiation during HFP connection setup, showing AG selecting mSBC and HF confirming. ```text AG -> HF: +BCS:2 (select mSBC) HF -> AG: AT+BCS=2 (confirm mSBC) AG -> HF: OK ``` -------------------------------- ### Enable BT_DEFER_SETUP and Listen Source: https://github.com/bluez/bluez/blob/master/doc/l2cap-protocol.rst Enables deferred connection setup for L2CAP channels, requiring user-space authorization before accepting connections. This example also demonstrates listening for incoming connections. ```c int defer_setup = 1; int err = setsockopt(l2cap_socket, SOL_BLUETOOTH, BT_DEFER_SETUP, &defer_setup, sizeof(defer_setup)); if (err == -1) { perror("setsockopt"); return err; } err = listen(l2cap_socket, 5); if (err) { perror("listen"); return err; } struct sockaddr_l2 remote_addr = {0}; socklen_t addr_len = sizeof(remote_addr); int new_socket = accept(l2cap_socket, (struct sockaddr*)&remote_addr, &addr_len); if (new_socket < 0) { perror("accept"); return new_socket; } /* To complete the connection setup of new_socket read 1 byte */ char c; struct pollfd pfd; memset(&pfd, 0, sizeof(pfd)); pfd.fd = new_socket; pfd.events = POLLOUT; err = poll(&pfd, 1, 0); if (err) { perror("poll"); return err; } if (!(pfd.revents & POLLOUT)) { err = read(sk, &c, 1); if (err < 0) { perror("read"); return err; } } ``` -------------------------------- ### Start AVDTP Test Tool (Source Mode with Get Configuration) Source: https://github.com/bluez/bluez/blob/master/doc/qualification/avdtp-pts.rst Initiates the AVDTP test tool in Source (SRC) mode, with logging enabled (-l) and a request to get configuration (-s getconf). Requires root privileges. ```bash sudo avdtptest -d SRC -l -s getconf ``` -------------------------------- ### HCI Enhanced Setup Synchronous Connection Command Source: https://github.com/bluez/bluez/blob/master/doc/btmon-hfp.rst Example of an HCI command used to set up a synchronous connection, specifying parameters like bandwidth, coding format (mSBC), and packet types. ```text < HCI Command: Enhanced Setup Synchronous Connection (0x01|0x003d) plen 59 Handle: 1 Transmit bandwidth: 8000 Receive bandwidth: 8000 Transmit Coding Format: Codec: mSBC (0x05) Receive Coding Format: Codec: mSBC (0x05) Transmit Codec Frame Size: 60 Receive Codec Frame Size: 60 Input Coding Format: Codec: mSBC (0x05) Output Coding Format: Codec: mSBC (0x05) Input Coded Data Size: 16 Output Coded Data Size: 16 Input PCM Data Format: 2's complement Output PCM Data Format: 2's complement Input PCM Sample Payload MSB Position: 0 Output PCM Sample Payload MSB Position: 0 Input Data Path: HCI Output Data Path: HCI Input Transport Unit Size: 60 Output Transport Unit Size: 60 Max latency: 13 Packet type: 0x0008 EV3 may be used Retransmission effort: Optimize for link quality (0x02) ``` -------------------------------- ### AVDTP Start Command and Response Source: https://github.com/bluez/bluez/blob/master/doc/btmon-a2dp.rst These snippets demonstrate the AVDTP Start command and its successful acceptance response. Sending Start initiates the flow of encoded audio data over the media transport channel. ```text < ACL Data TX: Handle 1 flags 0x00 dlen 7 Channel: 64 len 3 [PSM 25 mode Basic (0x00)] {chan 0} AVDTP: Start (0x07) Command (0x00) type 0x00 label 4 nosp 0 ACP SEID: 1 ``` ```text > ACL Data RX: Handle 1 flags 0x02 dlen 6 Channel: 64 len 2 [PSM 25 mode Basic (0x00)] {chan 0} AVDTP: Start (0x07) Response Accept (0x02) type 0x00 label 4 nosp 0 ``` -------------------------------- ### Accept RFCOMM Connection and Complete Setup Source: https://github.com/bluez/bluez/blob/master/doc/rfcomm-protocol.rst Accepts an incoming RFCOMM connection and then reads a byte to complete the deferred setup. Includes error checking. ```c struct sockaddr_rc remote_addr = {0}; socklen_t addr_len = sizeof(remote_addr); int new_socket = accept(rfcomm_socket, (struct sockaddr*)&remote_addr, &addr_len); if (new_socket < 0) { perror("accept"); return new_socket; } /* To complete the connection setup of new_socket read 1 byte */ char c; struct pollfd pfd; memset(&pfd, 0, sizeof(pfd)); pfd.fd = new_socket; pfd.events = POLLOUT; err = poll(&pfd, 1, 0); if (err) { perror("poll"); return err; } if (!(pfd.revents & POLLOUT)) { err = read(sk, &c, 1); if (err < 0) { perror("read"); return err; } } ``` -------------------------------- ### Enable Defer Connection Setup with BT_DEFER_SETUP Source: https://github.com/bluez/bluez/blob/master/doc/sco-protocol.rst Enables deferred connection setup for SCO sockets, requiring user-space authorization before accepting connections. Includes listen and accept calls, followed by a poll and read to complete the setup. ```c int defer_setup = 1; int err = setsockopt(sco_socket, SOL_BLUETOOTH, BT_DEFER_SETUP, &defer_setup, sizeof(defer_setup)); if (err == -1) { perror("setsockopt"); return err; } err = listen(sco_socket, 5); if (err) { perror("listen"); return err; } struct sockaddr_sco remote_addr = {0}; socklen_t addr_len = sizeof(remote_addr); int new_socket = accept(sco_socket, (struct sockaddr*)&remote_addr, &addr_len); if (new_socket < 0) { perror("accept"); return new_socket; } /* To complete the connection setup of new_socket read 1 byte */ char c; struct pollfd pfd; memset(&pfd, 0, sizeof(pfd)); pfd.fd = new_socket; pfd.events = POLLOUT; err = poll(&pfd, 1, 0); if (err) { perror("poll"); return err; } if (!(pfd.revents & POLLOUT)) { err = read(sk, &c, 1); if (err < 0) { perror("read"); return err; } } ``` -------------------------------- ### Verify Stream Flow with grep Source: https://github.com/bluez/bluez/blob/master/doc/btmon-a2dp.rst Use grep to confirm stream setup by looking for 'Start' accept and media data on the specified channel. ```bash grep -n "AVDTP: Start\|PSM 25.*chan 1" output.txt ``` -------------------------------- ### Start Bluetooth Scan Source: https://github.com/bluez/bluez/blob/master/doc/qualification/gatt-pts.rst Example of turning on Bluetooth scanning using bluetoothctl. Used in GATT/CL/GAW/BI-06-C. ```bash - [bluetooth]# scan on ``` -------------------------------- ### Start bluetoothctl for Discoverable Mode Source: https://github.com/bluez/bluez/blob/master/doc/qualification/iopt-pts.rst This command starts the bluetoothctl utility. Use 'discoverable on' to make the device discoverable for testing. ```bash $ bluetoothctl - [bluetooth]# discoverable on ``` -------------------------------- ### Start Bluetooth Advertising Source: https://github.com/bluez/bluez/blob/master/doc/qualification/l2cap-pts.rst Use `bluetoothctl advertise on` to start advertising in a terminal. This is often a prerequisite for L2CAP LE tests. ```bash sudo bluetoothctl advertise on ``` -------------------------------- ### Start Bluetooth Advertising with btmgmt Source: https://github.com/bluez/bluez/blob/master/doc/qualification/l2cap-pts.rst Use `sudo btmgmt advertising on` to start advertising. This is an alternative to `bluetoothctl` and is used in the pre-condition for L2CAP/LE/CPU/BI-02-C. ```bash sudo btmgmt advertising on ``` -------------------------------- ### MGMT Command with Parameters Source: https://github.com/bluez/bluez/blob/master/doc/btmon.rst Example of a MGMT command with parameters, specifically setting the powered state. ```text @ MGMT Command: Set Powered (0x0005) plen 1 {0x0001} [hci0] 12:35:04.033564 Powered: Enabled (0x01) ``` -------------------------------- ### Setup Synchronous Connection (Basic) Source: https://github.com/bluez/bluez/blob/master/doc/btmon-hfp.rst HCI command to establish a basic synchronous connection for voice audio. ```hci < HCI Command: Setup Synchronous Connection (0x01|0x0028) plen 17 Handle: 1 Transmit bandwidth: 8000 Receive bandwidth: 8000 Max latency: 13 Setting: 0x0063 Input Coding: Linear Input Data Format: 2's complement Input Sample Size: 16-bit # of bits padding at MSB: 0 Air Coding Format: Transparent Data Retransmission effort: Optimize for link quality (0x02) Packet type: 0x0008 EV3 may be used ``` -------------------------------- ### Start Scanning for Devices Source: https://github.com/bluez/bluez/blob/master/doc/bluetoothctl.rst Initiates scanning for all device types (LE and Classic). ```bash > scan on ``` -------------------------------- ### Register GATT Application and Start Advertising Source: https://github.com/bluez/bluez/blob/master/doc/qualification/gatt-pts.rst Register a GATT application and then start advertising using bluetoothctl. This is typically done after registering services, characteristics, and descriptors. ```bash gatt.register-application ``` ```bash advertise on ``` -------------------------------- ### Enable Defer Setup for ISO Connection Source: https://github.com/bluez/bluez/blob/master/doc/iso-protocol.rst Configures the socket to defer connection setup, requiring userspace authorization. This is useful for profile-level authorization before establishing a connection. ```c int defer_setup = 1; int err = setsockopt(iso_socket, SOL_BLUETOOTH, BT_DEFER_SETUP, &defer_setup, sizeof(defer_setup)); if (err == -1) { perror("setsockopt"); return err; } err = listen(iso_socket, 5); if (err) { perror("listen"); return err; } struct sockaddr_iso remote_addr = {0}; socklen_t addr_len = sizeof(remote_addr); int new_socket = accept(iso_socket, (struct sockaddr*)&remote_addr, &addr_len); if (new_socket < 0) { perror("accept"); return new_socket; } /* To complete the connection setup of new_socket read 1 byte */ char c; struct pollfd pfd; memset(&pfd, 0, sizeof(pfd)); pfd.fd = new_socket; pfd.events = POLLOUT; err = poll(&pfd, 1, 0); if (err) { perror("poll"); return err; } if (!(pfd.revents & POLLOUT)) { err = read(sk, &c, 1); if (err < 0) { perror("read"); return err; } } ``` -------------------------------- ### Start bluetoothctl Source: https://github.com/bluez/bluez/blob/master/doc/qualification/gap-pts.rst Launches the bluetoothctl utility. This is a fundamental step for interacting with Bluetooth devices via the command line. ```bash sudo bluetoothctl ``` -------------------------------- ### Run btgatt-server Source: https://github.com/bluez/bluez/blob/master/doc/qualification/gatt-pts.rst Execute this command to start the GATT server for testing purposes. This is often used in conjunction with advertising. ```bash btgatt-server ``` -------------------------------- ### Find EATT channel setup Source: https://github.com/bluez/bluez/blob/master/doc/btmon-l2cap.rst Use grep to identify Enhanced Attribute Table (EATT) channel setup messages by searching for specific PSM values and keywords. ```bash grep -n "PSM: 39\|Enhanced Credit" output.txt ``` -------------------------------- ### Process Log Message Example Source: https://github.com/bluez/bluez/blob/master/doc/btmon.rst Example of a process log message from bluetoothd, showing source file, function, and message details. ```text = bluetoothd: src/adapter.c:connected_callback() hci0 devic.. 12:36:18.975307 │ │ │ │ │ └─ Timestamp │ └─ Source file, function, and message (may be truncated) └─ Process name ``` -------------------------------- ### BT_DEFER_SETUP Socket Option Source: https://github.com/bluez/bluez/blob/master/doc/l2cap-protocol.rst Controls whether connection setup requires user-space authorization. ```APIDOC ## BT_DEFER_SETUP Socket Option ### Description Enables or disables deferring connection setup, allowing user-space authorization before responding to connection requests. This option is used with `setsockopt(2)` and `getsockopt(2)` at the `SOL_BLUETOOTH` level. ### Values - `0`: Disable (default), Authorization not required. - `1`: Enable, Authorization required. ### Example ```c int defer_setup = 1; int err = setsockopt(l2cap_socket, SOL_BLUETOOTH, BT_DEFER_SETUP, &defer_setup, sizeof(defer_setup)); if (err == -1) { perror("setsockopt"); return err; } err = listen(l2cap_socket, 5); if (err) { perror("listen"); return err; } struct sockaddr_l2 remote_addr = {0}; socklen_t addr_len = sizeof(remote_addr); int new_socket = accept(l2cap_socket, (struct sockaddr*)&remote_addr, &addr_len); if (new_socket < 0) { perror("accept"); return new_socket; } /* To complete the connection setup of new_socket read 1 byte */ char c; struct pollfd pfd; memset(&pfd, 0, sizeof(pfd)); pfd.fd = new_socket; pfd.events = POLLOUT; err = poll(&pfd, 1, 0); if (err) { perror("poll"); return err; } if (!(pfd.revents & POLLOUT)) { err = read(sk, &c, 1); if (err < 0) { perror("read"); return err; } } ``` ``` -------------------------------- ### Start Bluetooth Discovery Source: https://github.com/bluez/bluez/blob/master/doc/btmon-mgmt.rst Initiate device discovery using the Start Discovery command, specifying the desired address types to scan for. This command precedes HCI-level scan commands. ```bash @ MGMT Command: Start Discovery (0x0023) plen 1 {0x0001} [hci0] 12:36:00.100200 Address type: 0x07 BR/EDR LE Public LE Random ``` ```bash @ MGMT Event: Command Complete (0x0001) plen 5 {0x0001} [hci0] 12:36:00.100500 Start Discovery (0x0023) plen 2 Status: Success (0x00) Address type: 0x07 ``` -------------------------------- ### Kernel Information Notes Source: https://github.com/bluez/bluez/blob/master/doc/btmon.rst Examples of system-level annotations showing kernel and Bluetooth subsystem versions. ```text = Note: Linux version 6.16.0-rc6-0903 (x86_64) 12:34:49.881926 = Note: Bluetooth subsystem version 2.22 12:34:49.881930 ``` -------------------------------- ### BT_DEFER_SETUP Socket Option Source: https://github.com/bluez/bluez/blob/master/doc/rfcomm-protocol.rst Controls whether connection setup requires user authorization. ```APIDOC ## BT_DEFER_SETUP Socket Option ### Description Enables or disables deferral of connection setup, allowing user-space authorization at the profile level. This option is available since Linux kernel 2.6.30. ### Method setsockopt(rfcomm_socket, SOL_BLUETOOTH, BT_DEFER_SETUP, &defer_setup, sizeof(defer_setup)) ### Parameters - **defer_setup** (int): - **0**: Disable (default), Authorization not required - **1**: Enable, Authorization required ### Request Example ```c int defer_setup = 1; int err = setsockopt(rfcomm_socket, SOL_BLUETOOTH, BT_DEFER_SETUP, &defer_setup, sizeof(defer_setup)); if (err == -1) { perror("setsockopt"); return err; } err = listen(rfcomm_socket, 5); if (err) { perror("listen"); return err; } struct sockaddr_rc remote_addr = {0}; socklen_t addr_len = sizeof(remote_addr); int new_socket = accept(rfcomm_socket, (struct sockaddr*)&remote_addr, &addr_len); if (new_socket < 0) { perror("accept"); return new_socket; } /* To complete the connection setup of new_socket read 1 byte */ char c; struct pollfd pfd; memset(&pfd, 0, sizeof(pfd)); pfd.fd = new_socket; pfd.events = POLLOUT; err = poll(&pfd, 1, 0); if (err) { perror("poll"); return err; } if (!(pfd.revents & POLLOUT)) { err = read(sk, &c, 1); if (err < 0) { perror("read"); return err; } } ``` ``` -------------------------------- ### Run GATT Server Source: https://github.com/bluez/bluez/blob/master/doc/qualification/gatt-pts.rst Starts the GATT server process. This is a prerequisite for performing GATT operations and tests. ```bash Run 'btgatt-server' ``` -------------------------------- ### Start Bluetooth Advertising Source: https://github.com/bluez/bluez/blob/master/doc/qualification/gatt-pts.rst Initiates Bluetooth advertising. This command is typically used after registering services or characteristics to make them discoverable. ```bash Run 'bluetoothctl advertise on' ``` -------------------------------- ### Get Receive Buffer Size (BT_RCVMTU) Source: https://github.com/bluez/bluez/blob/master/doc/hci-protocol.rst Example of getting the receive buffer size for HCI communication using BT_RCVMTU. ```c uint16_t mtu; socklen_t len; int err; len = sizeof(mtu); err = getsockopt(sock, SOL_BLUETOOTH, BT_RCVMTU, mtu, &len); ``` -------------------------------- ### Prepare Bluetooth for Testing (Pre-condition) Source: https://github.com/bluez/bluez/blob/master/doc/qualification/sm-pts.rst Initial setup steps for testing, including removing a device, powering off/on, and enabling privacy management. Requires root privileges. ```bash sudo bluetoothctl ``` ```bash [bluetooth]# remove ``` ```bash [bluetooth]# power off ``` ```bash [bluetooth]# mgmt.privacy on ``` ```bash [bluetooth]# power on ``` ```bash [bluetooth]# advertise.name on ``` ```bash [bluetooth]# advertise on ``` -------------------------------- ### Enable BT_DEFER_SETUP and Accept Connection Source: https://github.com/bluez/bluez/wiki/RFCOMM(7) Demonstrates enabling deferred connection setup for RFCOMM sockets, requiring userspace authorization. It then shows how to listen for and accept an incoming connection. ```c int defer_setup = 1; int err = setsockopt(rfcomm_socket, SOL_BLUETOOTH, BT_DEFER_SETUP, &defer_setup, sizeof(defer_setup)); if (err == -1) { perror("setsockopt"); return err; } err = listen(rfcomm_socket, 5); if (err) { perror("listen"); return err; } struct sockaddr_rc remote_addr = {0}; socklen_t addr_len = sizeof(remote_addr); int new_socket = accept(rfcomm_socket, (struct sockaddr*)&remote_addr, &addr_len); if (new_socket < 0) { perror("accept"); return new_socket; } /* To complete the connection setup of new_socket read 1 byte */ char c; struct pollfd pfd; memset(&pfd, 0, sizeof(pfd)); pfd.fd = new_socket; pfd.events = POLLOUT; err = poll(&pfd, 1, 0); if (err) { perror("poll"); return err; } if (!(pfd.revents & POLLOUT)) { err = read(sk, &c, 1); if (err < 0) { perror("read"); return err; } } ``` -------------------------------- ### Set BT_DEFER_SETUP and Listen Source: https://github.com/bluez/bluez/blob/master/doc/rfcomm-protocol.rst Enables deferred connection setup and prepares the socket for incoming connections using listen. Error handling is provided. ```c int defer_setup = 1; int err = setsockopt(rfcomm_socket, SOL_BLUETOOTH, BT_DEFER_SETUP, &defer_setup, sizeof(defer_setup)); if (err == -1) { perror("setsockopt"); return err; } err = listen(rfcomm_socket, 5); if (err) { perror("listen"); return err; } ``` -------------------------------- ### HCI Commands with Parameters Example Source: https://github.com/bluez/bluez/blob/master/doc/btmon.rst Demonstrates an HCI command with parameters, showing indented detail lines for extended advertising settings. ```text < HCI Command: LE Set Extende.. (0x08|0x0039) plen 2 #1 [hci0] 12:35:01.738352 Extended advertising: Disabled (0x00) Number of sets: Disable all sets (0x00) ``` -------------------------------- ### Interactive LC3 Custom Preset Setup Source: https://github.com/bluez/bluez/blob/master/doc/bluetoothctl-endpoint.rst This section demonstrates the interactive prompts for setting up a custom LC3 preset, including codec and Quality of Service (QoS) parameters. ```bash >presets 00002bc9-0000-1000-8000-00805f9b34fb 0x06 ``` ```bash >presets 00002bc9-0000-1000-8000-00805f9b34fb 0x06 ``` -------------------------------- ### Analyze Packet Counts and Traffic Volumes Source: https://github.com/bluez/bluez/blob/master/doc/btmon.rst Get an overview of captured data, including packet counts, connection handles, device addresses, and traffic volumes. This is a good starting point for trace analysis. ```bash btmon -a ``` -------------------------------- ### Enable LE 1M and 2M TX/RX PHYs Source: https://github.com/bluez/bluez/blob/master/doc/bluetoothctl-mgmt.rst Enables LE 1M TX/RX and LE 2M TX/RX PHY configurations. ```bash > phy LE1MTX LE1MRX LE2MTX LE2MRX ``` -------------------------------- ### Enable Discoverable, Advertising, and Scanning in bluetoothctl Source: https://github.com/bluez/bluez/blob/master/doc/qualification/gap-pts.rst Configure the device using bluetoothctl to be discoverable, start advertising, and enable scanning. This setup is required for various LE Peripheral tests involving connection and discovery. ```bash bluetoothctl - [bluetooth]# discoverable on - [bluetooth]# advertise on - [bluetooth]# scan on ``` -------------------------------- ### Show help for set-sysconfig options Source: https://github.com/bluez/bluez/blob/master/doc/bluetoothctl-mgmt.rst Use the -h flag to display help information for system configuration options. ```bash > set-sysconfig -h ``` -------------------------------- ### Get Clock Information Source: https://github.com/bluez/bluez/blob/master/doc/bluetoothctl-mgmt.rst Retrieve clock information using the 'get-clock' command. Omit the address argument to get local clock information, or provide a remote device address to get its clock information. ```bash > get-clock ``` ```bash > get-clock 00:11:22:33:44:55 ``` ```bash > get-clock AA:BB:CC:DD:EE:FF ``` -------------------------------- ### Track Advertising Setup using grep Source: https://github.com/bluez/bluez/blob/master/doc/btmon-advertising.rst Shell command to monitor the local device's advertising configuration commands in a log file. ```bash grep -n "Set Extended Adv\|Set Advertising\|Set Scan Response\|Adv Enable" output.txt ``` -------------------------------- ### HCI Traffic Example Source: https://github.com/bluez/bluez/blob/master/doc/btmon.rst Example of Low Energy ACL traffic, showing pairing request details. ```text > LE-ACL: Handle 2048 flags 0x02 dlen 11 #497 [hci0] 12:36:19.000048 SMP: Pairing Request (0x01) len 6 IO capability: NoInputNoOutput (0x03) OOB data: Authentication data not present (0x00) Authentication requirement: Bonding, MITM, SC, No Keypresses, CT2 (0x2d) Max encryption key size: 16 ``` -------------------------------- ### AVDTP Delay Report Example Source: https://github.com/bluez/bluez/blob/master/doc/btmon-a2dp.rst Example of a Delay Report message exchanged between A2DP sink and source. ```text AVDTP: Delay Report (0x0d) Command (0x00) type 0x00 label 8 nosp 0 ACP SEID: 1 Delay: 15.0ms AVDTP: Delay Report (0x0d) Response Accept (0x02) type 0x00 label 8 nosp 0 ``` -------------------------------- ### MGMT Event Example Source: https://github.com/bluez/bluez/blob/master/doc/btmon.rst Example of a MGMT Event, specifically a Command Complete event for the Set Powered command. ```text @ MGMT Event: Command Complete (0x0001) plen 7 {0x0001} [hci0] 12:35:04.114789 Set Powered (0x0005) plen 4 Status: Success (0x00) Current settings: 0x004e0ac1 Powered Secure Simple Pairing ``` -------------------------------- ### Typical HCI Initialization Trace Source: https://github.com/bluez/bluez/blob/master/doc/btmon-hci-init.rst This is a sample sequence of HCI commands and events observed at the beginning of a btsnoop trace for a dual-mode controller. It shows the initial commands for controller setup and feature discovery. ```text < HCI Command: Reset > HCI Event: Command Complete (Reset) < HCI Command: Read Local Supported Features > HCI Event: Command Complete (Read Local Supported Features) < HCI Command: Read Local Version Information > HCI Event: Command Complete (Read Local Version Information) < HCI Command: Read BD ADDR > HCI Event: Command Complete (Read BD ADDR) ... [Stage 2-4 commands follow] ``` -------------------------------- ### Start GATT Notifications Source: https://github.com/bluez/bluez/blob/master/doc/org.bluez.GattCharacteristic.rst Starts a notification session for a GATT characteristic. Ensure the characteristic supports value notifications or indications. ```bluetoothctl gatt.acquire-notify ``` -------------------------------- ### Verify SCO/eSCO Setup Source: https://github.com/bluez/bluez/blob/master/doc/btmon-hfp.rst Check for specific phrases related to synchronous connection setup to verify SCO or eSCO links. ```bash grep -n "Setup Synchronous\|Enhanced Setup Synchronous\|Synchronous Connection Complete\|Write Voice Setting" output.txt ``` -------------------------------- ### D-Bus Activity Examples Source: https://github.com/bluez/bluez/blob/master/doc/btmon.rst Examples of D-Bus activity, including method calls and signals, indicating communication within the system. ```text = bluetoothd: [:1.21220:method_call] > org.freedesktop.DBus.. 12:34:53.912508 = bluetoothd: [:1.21220:method_return] < [#5] 12:34:53.912546 = bluetoothd: [signal] org.freedesktop.DBus.ObjectManager.I.. 12:36:18.975691 ``` -------------------------------- ### Enable Discoverable Advertising and Set IO Capability Source: https://github.com/bluez/bluez/blob/master/doc/qualification/sm-pts.rst Run 'bluetoothctl advertise.discoverable on', 'bluetoothctl advertise on', and 'sudo btmgmt io-cap 3' to enable discoverable advertising and set the I/O capability to 'DisplayYesNo'. This is often part of a pre-condition for specific test cases. ```bash bluetoothctl advertise.discoverable on ``` ```bash bluetoothctl advertise on ``` ```bash sudo btmgmt io-cap 3 ``` -------------------------------- ### Bluetooth Initialization and Version Handshake Source: https://github.com/bluez/bluez/blob/master/doc/btmon-mgmt.rst Shows the initial MGMT Open, version query, and controller information retrieval when bluetoothd starts. Essential for verifying daemon startup and hardware detection. ```text @ MGMT Open: bluetoothd (privileged) version 1.23 {0x0001} 12:34:49.881936 @ MGMT Command: Read Management Ver.. (0x0001) plen 0 {0x0001} 12:34:49.882003 @ MGMT Event: Command Complete (0x0001) plen 6 {0x0001} 12:34:49.882010 Read Management Version Information (0x0001) plen 3 Status: Success (0x00) Version: 1.23 @ MGMT Command: Read Management Sup.. (0x0002) plen 0 {0x0001} 12:34:49.882050 @ MGMT Event: Command Complete (0x0001) plen 58 {0x0001} 12:34:49.882055 Read Supported Commands (0x0002) plen 55 Status: Success (0x00) Num of commands: 120 Num of events: 38 ``` ```text @ MGMT Command: Read Controller Index List (0x0003) plen 0 {0x0001} 12:34:49.882100 @ MGMT Event: Command Complete (0x0001) plen 7 {0x0001} 12:34:49.882105 Read Controller Index List (0x0003) plen 4 Status: Success (0x00) Num controllers: 1 Controller: hci0 @ MGMT Command: Read Controller Inf.. (0x0004) plen 0 {0x0001} [hci0] 12:34:49.882200 @ MGMT Event: Command Complete (0x0001) plen 283 {0x0001} [hci0] 12:34:49.882210 Read Controller Information (0x0004) plen 280 Status: Success (0x00) Address: 00:11:22:33:44:55 Bluetooth version: 5.4 Manufacturer: Intel (2) Supported settings: 0x003effff Current settings: 0x00000080 ``` -------------------------------- ### Add Advertisement Patterns Monitor Example Source: https://github.com/bluez/bluez/blob/master/doc/mgmt-protocol.rst Example of a pattern structure for advertisement monitoring. This pattern is used to define filtering conditions for advertisements. ```c { 0x16, // Service Data - 16-bit UUID 0x02, // Skip the UUID part. 0x04, // Length of the value {0x11, 0x22, 0x33, 0x44}, } ``` -------------------------------- ### Start Bluetoothctl and manage devices Source: https://github.com/bluez/bluez/blob/master/doc/qualification/gap-pts.rst Run 'sudo bluetoothctl' to enter the interactive Bluetooth control utility. Use commands like 'remove' to unpair devices and 'scan on' to discover new devices. ```bash sudo bluetoothctl ``` ```bash remove ``` ```bash mgmt.sc only ``` ```bash agent off ``` ```bash agent DisplayYesNo ``` ```bash scan on ``` -------------------------------- ### Post-Initialization HCI Actions Source: https://github.com/bluez/bluez/blob/master/doc/btmon-hci-init.rst These actions are performed after the initial stages of HCI setup to apply runtime configurations. They include re-enabling SSP, syncing LE host support, configuring advertising, and setting random addresses. ```text HCI_Write_Simple_Pairing_Mode ``` ```text HCI_Write_LE_Host_Supported ``` ```text LE advertising setup ``` ```text HCI_Write_Authentication_Enable ``` ```text Scan/class/name/EIR updates ``` ```text LE_Set_Random_Address ``` -------------------------------- ### Show Controller Configuration Source: https://github.com/bluez/bluez/blob/master/doc/bluetoothctl-mgmt.rst Displays the current configuration settings of the selected Bluetooth controller. ```bash > config ``` -------------------------------- ### HCI Encryption Start and Event Source: https://github.com/bluez/bluez/blob/master/doc/btmon-smp.rst Shows the HCI command to start encryption and the subsequent Encryption Change event, indicating successful encryption establishment after pairing. ```text < HCI Command: LE Start Encryption (0x08|0x0019) plen 28 #515 [hci0] 0.279002 > HCI Event: Encryption Change (0x08) plen 4 #517 [hci0] 0.342556 Status: Success (0x00) Handle: 2048 Encryption: Enabled with AES-CCM (0x01) ``` -------------------------------- ### Enable LE 1M TX and RX PHYs Source: https://github.com/bluez/bluez/blob/master/doc/bluetoothctl-mgmt.rst Enables both LE 1M TX and RX PHY configurations simultaneously. ```bash > phy LE1MTX LE1MRX ``` -------------------------------- ### HCI LE Extended Advertising Report Example Source: https://github.com/bluez/bluez/blob/master/doc/btmon-advertising.rst Example of an HCI LE Extended Advertising Report event as decoded by btmon, showing device properties and advertising data. ```text > HCI Event: LE Meta Event (0x3e) plen 43 #120 [hci0] 0.500003 LE Extended Advertising Report (0x0d) Event type: 0x0013 Props: 0x0013 Connectable Scannable Complete Address type: Random (0x01) Address: 00:11:22:33:44:55 Primary PHY: LE 1M Secondary PHY: LE 2M SID: 0x01 TX power: 0 dBm RSSI: -55 dBm (0xc9) Data length: 18 ``` -------------------------------- ### Turn on Bluetooth adapter Source: https://github.com/bluez/bluez/blob/master/doc/qualification/sm-pts.rst Use this command to power on the Bluetooth adapter. This is typically done after configuring settings or as a post-condition. ```bash sudo btmgmt power on ``` -------------------------------- ### Example btmon analyze output for L2CAP channel Source: https://github.com/bluez/bluez/blob/master/doc/btmon-l2cap.rst This is an example of the detailed statistics provided by btmon's --analyze mode for an L2CAP channel, including PSM, MTU, MPS, packet counts, latency, size, and speed. ```text Found TX L2CAP channel with CID 64 PSM 128 (0x0080) Mode: LE Credit MTU: 672 MPS: 490 TX packets: 29120/29114 TX Latency: 1-79 msec (~29 msec) TX size: 494-494 octets (~494 octets) TX speed: ~571 Kb/s ``` -------------------------------- ### Stop Discovery Source: https://github.com/bluez/bluez/blob/master/doc/mgmt-protocol.rst Halts the discovery process that was initiated by the 'Start Discovery' command. ```APIDOC ## Stop Discovery ### Description Halts the discovery process that was initiated by the 'Start Discovery' command. ### Command Code 0x0024 ### Parameters #### Command Parameters - **Address_Type** (1 Octet) - Required ### Return Parameters - **Address_Type** (1 Octet) ### Possible Errors - Rejected - Invalid Parameters - Invalid Index ``` -------------------------------- ### StartNotify Source: https://github.com/bluez/bluez/blob/master/doc/org.bluez.GattCharacteristic.rst Starts a notification session from this characteristic if it supports value notifications or indications. ```APIDOC ## StartNotify ### Description Starts a notification session from this characteristic if it supports value notifications or indications. ### Method `StartNotify()` ### Errors - `org.bluez.Error.Failed` - `org.bluez.Error.NotPermitted` - `org.bluez.Error.InProgress` - `org.bluez.Error.NotConnected` - `org.bluez.Error.NotSupported` ### Example ``` bluetoothctl > gatt.acquire-notify ``` ``` -------------------------------- ### Multi-line Comment Formatting Source: https://github.com/bluez/bluez/blob/master/doc/coding-style.rst Multi-line comments should start with the asterisk on the second line. ```c /* * first line comment // correct * ... * last line comment */ ``` -------------------------------- ### Identify Connection Establishment Events Source: https://github.com/bluez/bluez/blob/master/doc/btmon.rst Search for connection establishment events in the analysis output to build a mapping between connection handles and device addresses. ```bash grep -n "Connection Complete\|Enhanced Connection Complete\|CIS Established" output.txt ``` -------------------------------- ### Start bluetoothctl and Enable Advertising/Scanning Source: https://github.com/bluez/bluez/blob/master/doc/qualification/gap-pts.rst Initiates the bluetoothctl utility and enables advertising and scanning for Bluetooth devices. This is a prerequisite for certain GAP/SEC test cases. ```bash bluetoothctl advertise on scan le ``` -------------------------------- ### Get Phonebook Size Source: https://github.com/bluez/bluez/blob/master/doc/org.bluez.obex.PhonebookAccess.rst Retrieves the number of used entries in the selected phonebook object. ```APIDOC ## Get Phonebook Size ### Description Returns the number of entries in the selected phonebook object that are actually used (i.e. indexes that correspond to non-NULL entries). ### Method GetSize ### Returns * uint16 - The number of used entries in the phonebook. ``` -------------------------------- ### Get Thumbnail Source: https://github.com/bluez/bluez/blob/master/doc/org.bluez.obex.Image.rst Retrieves a thumbnail of the image corresponding to the handle and stores it in a local file. ```APIDOC ## Get Thumbnail ### Description Retrieves the image thumbnail corresponding to the handle and store it in a local file. ### Method DBUS CALL ### Interface org.bluez.obex.Image1 ### Parameters #### Path Parameters - **targetfile** (string) - Required - The local file path to store the thumbnail. - **handle** (string) - Required - The handle of the image thumbnail to retrieve. ### Errors - org.bluez.obex.Error.InvalidArguments - org.bluez.obex.Error.Failed ``` -------------------------------- ### Enable LE 1M TX PHY Source: https://github.com/bluez/bluez/blob/master/doc/bluetoothctl-mgmt.rst Enables the LE 1M TX PHY configuration. ```bash > phy LE1MTX ``` -------------------------------- ### Start Service Discovery Source: https://github.com/bluez/bluez/blob/master/doc/btmon-mgmt.rst Initiate service discovery for a specific device by providing its address type, RSSI threshold, and a list of UUIDs to search for. ```bash @ MGMT Command: Start Service Discovery (0x003a) plen 19 {0x0001} [hci0] 12:36:10.100200 Address type: 0x06 LE Public LE Random RSSI threshold: -127 UUIDs: 1 UUID: Heart Rate (0x180d) ``` ```bash @ MGMT Event: Command Complete (0x0001) plen 5 {0x0001} [hci0] 12:36:10.100500 Start Service Discovery (0x003a) plen 2 Status: Success (0x00) ``` -------------------------------- ### Get Clock Information Source: https://github.com/bluez/bluez/blob/master/doc/mgmt-protocol.rst Retrieves local and piconet clock information for a specified controller and device. ```APIDOC ## Get Clock Information ### Description This command is used to get local and piconet clock information. ### Method Not specified (assumed to be part of a command-based protocol) ### Endpoint Not applicable ### Parameters #### Controller Index - **controller id** (integer) - The index of the controller. #### Command Parameters - **Address** (6 Octets) - The Bluetooth address of the device. - **Address_Type** (1 Octet) - The type of the address (e.g., BR/EDR, LE Public, LE Random). ### Return Parameters - **Address** (6 Octets) - The Bluetooth address of the device. - **Address_Type** (1 Octet) - The type of the address. - **Local_Clock** (4 Octets) - The local clock value. - **Piconet_Clock** (4 Octets) - The piconet clock value. - **Accuracy** (2 Octets) - The accuracy of the clock. ### Possible Errors - Not Connected - Not Powered - Invalid Parameters - Invalid Index ``` -------------------------------- ### Enable Advertising with Name Source: https://github.com/bluez/bluez/blob/master/doc/qualification/gap-pts.rst Use this command to set the advertising name before enabling advertising. Ensure 'bluetoothctl' is running. ```bash advertise.name on ``` ```bash advertise on ``` -------------------------------- ### Get Connections Source: https://github.com/bluez/bluez/blob/master/doc/mgmt-protocol.rst Retrieves a list of currently connected devices. This command can only be used when the controller is powered. ```APIDOC ## Get Connections ### Description This command is used to retrieve a list of currently connected devices. ### Method [Not specified, likely a command-line or RPC call] ### Endpoint [Not applicable] ### Parameters #### Path Parameters - **controller id** (integer) - Required - The index of the controller. #### Query Parameters [Not applicable] #### Request Body [None] ### Request Example [Not provided in source] ### Response #### Success Response Generates a Command Complete event on success. #### Response Example [Not provided in source] **Return Parameters:** - **Connection_Count** (2 Octets) - The number of connected devices. - **Address[]** (6 Octets) - The Bluetooth address of each connected device. - **Address_Type[]** (1 Octet) - The type of the address for each device. Possible values: 0x00 (BR/EDR), 0x01 (LE Public), 0x02 (LE Random). **Possible errors:** - Invalid Parameters - Not Powered - Invalid Index ``` -------------------------------- ### LE Setup ISO Data Path Command Source: https://github.com/bluez/bluez/blob/master/doc/btmon-le-audio.rst This HCI command is used to set up the ISO data path for each BIS. It specifies the connection handle, data path direction (output from controller to host), and data path ID. ```text < HCI Command: LE Setup ISO Data Path (0x08|0x006e) plen 13 #140 [hci0] 0.500003 Connection Handle: 0x0010 Data Path Direction: Output (Controller to Host) (0x01) Data Path ID: HCI (0x00) ``` ```text < HCI Command: LE Setup ISO Data Path (0x08|0x006e) plen 13 #145 [hci0] 0.550003 Connection Handle: 0x0011 Data Path Direction: Output (Controller to Host) (0x01) Data Path ID: HCI (0x00) ``` -------------------------------- ### Pre-condition: Apply shared-gatt patch and configure systemd Source: https://github.com/bluez/bluez/blob/master/doc/qualification/gap-pts.rst Sets up the system for testing by applying a patch, creating a systemd configuration directory, and modifying Bluetooth service settings to prefer indications. ```bash - sudo mkdir -p /etc/systemd/system/bluetooth.service.d ``` ```bash - echo -e '[Service]\nExecStart=\nExecStart=/usr/lib/bluetooth/bluetoothd \ --noplugin=gap' | \ sudo tee /etc/systemd/system/bluetooth.service.d/no_gap.conf ``` ```bash - echo -e '[Service]\nEnvironment="PREFER_INDICATION=1"' | \ sudo tee /etc/systemd/system/bluetooth.service.d/indication_env.conf ``` ```bash - sudo systemctl daemon-reload ``` ```bash - sudo systemctl restart bluetooth ``` -------------------------------- ### Broadcast ISO Socket Address Configuration Source: https://github.com/bluez/bluez/blob/master/doc/iso-protocol.rst Example of configuring a sockaddr_iso structure for a broadcast connection. ```c struct sockaddr_iso *addr; size_t addr_len; addr_len = sizeof(*addr) + sizeof(*addr->iso_bc); memset(addr, 0, addr_len); addr->iso_family = AF_BLUETOOTH; bacpy(&addr->iso_bdaddr, bdaddr); addr->iso_bdaddr_type = BDADDR_LE_PUBLIC; ``` -------------------------------- ### Start AVDTP Test Tool (Source Mode) Source: https://github.com/bluez/bluez/blob/master/doc/qualification/avdtp-pts.rst Initiates the AVDTP test tool in Source (SRC) mode, with logging enabled (-l) and playback (-p) functionality. Requires root privileges. ```bash sudo avdtptest -d SRC -l -p ```