Skip to content

Protocol Capture

import { Aside } from ‘@astrojs/starlight/components’;

mcbluetooth can capture raw Bluetooth HCI (Host Controller Interface) traffic for protocol analysis and debugging.

HCI captures record all communication between the Bluetooth stack and hardware adapter. This includes:

  • Device discovery packets
  • Pairing and authentication
  • Connection management
  • Audio streaming data
  • BLE GATT operations
bt_capture_start output_file="/tmp/bluetooth.btsnoop"

Returns:

{
"status": "started",
"capture_id": "capture_abc123",
"output_file": "/tmp/bluetooth.btsnoop"
}
# Capture from specific adapter
bt_capture_start output_file="/tmp/hci0.btsnoop" adapter="0"
# Include voice data (SCO)
bt_capture_start output_file="/tmp/calls.btsnoop" include_sco=true
# Include audio streaming (A2DP)
bt_capture_start output_file="/tmp/audio.btsnoop" include_a2dp=true
# Include LE Audio (ISO)
bt_capture_start output_file="/tmp/le_audio.btsnoop" include_iso=true
bt_capture_stop capture_id="capture_abc123"

Returns:

{
"status": "stopped",
"output_file": "/tmp/bluetooth.btsnoop",
"packets_captured": 1542,
"file_size": 245760
}
bt_capture_list_active
bt_capture_parse filepath="/tmp/bluetooth.btsnoop"

Returns packet summaries:

{
"total_packets": 1542,
"packet_types": {
"HCI_CMD": 234,
"HCI_EVENT": 456,
"ACL_DATA": 852
},
"packets": [
{
"index": 0,
"timestamp": "2024-01-15T10:30:00.123456",
"type": "HCI_CMD",
"direction": "TX",
"summary": "Inquiry"
}
]
}
# Only HCI commands
bt_capture_parse filepath="..." packet_type_filter="HCI_CMD"
# Only received packets
bt_capture_parse filepath="..." direction_filter="RX"
# Limit results
bt_capture_parse filepath="..." max_packets=100
bt_capture_analyze filepath="/tmp/bluetooth.btsnoop"

Returns high-level statistics:

{
"duration_seconds": 45.2,
"total_packets": 1542,
"protocols": {
"L2CAP": 423,
"RFCOMM": 156,
"SDP": 34,
"ATT": 289
},
"connections": [
{
"address": "AA:BB:CC:DD:EE:FF",
"packets": 892,
"bytes": 45678
}
]
}
bt_capture_read_raw filepath="/tmp/bluetooth.btsnoop" offset=0 count=50

Returns btmon-style decoded output for detailed inspection.

# Start capture
bt_capture_start output_file="/tmp/pairing_debug.btsnoop"
# Attempt pairing
bt_pair adapter="hci0" address="AA:BB:CC:DD:EE:FF"
# Stop and analyze
bt_capture_stop capture_id="..."
bt_capture_parse filepath="/tmp/pairing_debug.btsnoop" packet_type_filter="HCI_EVENT"
# Capture with A2DP data
bt_capture_start output_file="/tmp/audio_debug.btsnoop" include_a2dp=true
# Play audio for 30 seconds
# Stop and check for errors
bt_capture_stop capture_id="..."
bt_capture_analyze filepath="/tmp/audio_debug.btsnoop"
# Start capture
bt_capture_start output_file="/tmp/ble_sensor.btsnoop"
# Connect and interact with sensor
bt_connect adapter="hci0" address="AA:BB:CC:DD:EE:FF"
bt_ble_read adapter="hci0" address="..." char_uuid="..."
# Analyze ATT/GATT traffic
bt_capture_stop capture_id="..."
bt_capture_parse filepath="/tmp/ble_sensor.btsnoop"

Captures are saved in btsnoop format, compatible with:

ToolUsage
WiresharkFull GUI analysis
btmonCommand-line decode
hcidumpLegacy analysis
Terminal window
wireshark /tmp/bluetooth.btsnoop

Wireshark provides:

  • Protocol dissection
  • Conversation tracking
  • Expert analysis
  • Export options

The capture functionality uses btmon which needs access to the Bluetooth monitor socket:

Terminal window
# Option 1: Run as root
sudo btmon
# Option 2: Add capability (one-time setup)
sudo setcap cap_net_raw+ep /usr/bin/btmon
Terminal window
# Check btmon capability
getcap /usr/bin/btmon
# Add if missing
sudo setcap cap_net_raw+ep /usr/bin/btmon
  • Ensure adapter is active: bt_adapter_power adapter="hci0" on=true
  • Verify Bluetooth activity is occurring
  • Check btmon is running: bt_capture_list_active

Audio data generates significant traffic:

ContentApproximate Size
Discovery/pairing~10 KB/min
BLE sensors~50 KB/min
A2DP audio~2 MB/min
HFP calls~500 KB/min

Use without audio flags for general debugging:

bt_capture_start output_file="..." include_sco=false include_a2dp=false

Verify file format:

Terminal window
file /tmp/capture.btsnoop
# Should show: BTSnoop version 1, HCI UART (H4)

If corrupted, the capture may have been interrupted. Always use bt_capture_stop to properly close files.