Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Build artifacts
dist/
build/

# Developer scratch files (see CONTRIBUTING.md)
local/
*.spec
*.exe

Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ All notable changes to QuickPRS will be documented in this file.
## [1.3.0] - 2026-10-28

### Added
- `quickprs radio sniff`: record RPM's session with the radio from a Bluetooth trace served by Microsoft's Bluetooth Virtual Sniffer (or a saved pcap/pcapng file), without a virtual COM port driver. It keeps only the serial bytes RPM and the radio exchange, in the capture format `analyze` reads. com0com, which the relay needs, cannot load while Windows 11's Memory Integrity is on
- `quickprs radio sniff`: record RPM's session with the radio from a Bluetooth trace served by Microsoft's Bluetooth Virtual Sniffer (or a saved pcap/pcapng file), without a virtual COM port driver. It keeps only the serial bytes RPM and the radio exchange, in the capture format `analyze` reads, reads traces with or without direction headers, and ends with a report of what the trace held (and why, when it found no serial data). com0com, which the relay needs, cannot load while Windows 11's Memory Integrity is on
- `quickprs radio analyze --transcript`: the conversation in a capture, message by message (chunks going the same way within 50 ms are one message), and the common message sizes and first bytes in each direction
- `--skip-encrypted` for `import-rr`, `auto-setup` and `import-paste`: leave out talkgroups RadioReference lists as fully encrypted

### Fixed
Expand Down
29 changes: 25 additions & 4 deletions docs/bluetooth.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,25 @@ flowchart LR
4. Turn the radio on, and in RPM extract it over its Bluetooth COM port.
5. Press Ctrl+C in QuickPRS, then close BTVS.

When it stops, `sniff` reports what the trace held (packets, Bluetooth
data packets, RFCOMM frames and serial channels) and, if it found no serial
data, the likely reason.

To check the setup before a real session, run steps 2 and 3, then with the
radio on open its port for a few seconds from another console:

```bash
quickprs radio probe --port COM6 --seconds 10
```

After Ctrl+C the report should list RFCOMM frames (the channel opening and
closing) even though nothing was sent.

A full trace holds more than the serial data (Bluetooth link keys among
it); QuickPRS writes only the serial bytes, and only from the radio's link
once the trace has shown which link that is. `--pcap trace.pcapng` reads a
trace saved from Wireshark instead.
trace saved from Wireshark instead. Traces with or without a direction
header (pcap link types 201 and 187) both work.

### Through a virtual null-modem pair

Expand Down Expand Up @@ -112,12 +127,18 @@ Memory Integrity off.

```bash
quickprs radio analyze read.jsonl
quickprs radio analyze read.jsonl --transcript 60
quickprs radio analyze read.jsonl --extract radio.PRS
```

`analyze` counts bytes in each direction, lists readable strings and the
MFC class names it finds, and `--extract` writes out a personality found in
the radio's replies. Protocol bytes after the personality can end up in that
`analyze` counts bytes and messages in each direction, lists the common
message sizes and first bytes, readable strings and the MFC class names it
finds. A message is a run of chunks going the same way with less than
50 ms between them: a serial read returns whatever has arrived, so one
message often comes in several chunks. `--transcript N` lists the first N
messages (40 without a number) with their time, direction, length and first
bytes, which is where a protocol's framing usually shows first.
`--extract` writes out a personality found in the radio's replies. Protocol bytes after the personality can end up in that
file, so treat it as something to compare with the .PRS RPM saved for the
same session, not as a finished file.

Expand Down
8 changes: 7 additions & 1 deletion quickprs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4425,6 +4425,7 @@ def build_parser():
" quickprs radio sniff --log read.jsonl\n"
" quickprs radio relay --pc-port COM21 --radio-port COM6 "
"--log read.jsonl\n"
" quickprs radio analyze read.jsonl --transcript 60\n"
" quickprs radio analyze read.jsonl --extract radio.PRS")
radio_sub = p_radio.add_subparsers(dest="radio_cmd")
p_rscan = radio_sub.add_parser(
Expand Down Expand Up @@ -4476,6 +4477,10 @@ def build_parser():
p_ranalyze = radio_sub.add_parser(
"analyze", help="Summarise a capture file")
p_ranalyze.add_argument("capture", help="Capture (.jsonl) file")
p_ranalyze.add_argument("--transcript", type=int, nargs="?",
const=40, default=None, metavar="N",
help="Show the first N messages of the "
"conversation (default 40)")
p_ranalyze.add_argument("--extract", default=None,
help="Write a personality archive found in the "
"radio's replies to this .PRS path")
Expand Down Expand Up @@ -5769,7 +5774,8 @@ def run_cli(args=None):
all_links=parsed.all_links, note=parsed.note)
if parsed.radio_cmd == "analyze":
return radio_commands.cmd_radio_analyze(
parsed.capture, extract=parsed.extract)
parsed.capture, extract=parsed.extract,
transcript=parsed.transcript)
subcommand_parsers["radio"].print_help()
return 1
elif parsed.command == "import-csv":
Expand Down
52 changes: 51 additions & 1 deletion quickprs/radio/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,48 @@ def summarize(capture, opener_len=2):
return out


@dataclass
class Message:
t: float
direction: str
data: bytes


def messages(capture, gap=0.05):
"""The conversation as messages: consecutive chunks going the same way
with less than ``gap`` seconds between them are one message (a serial
read returns whatever has arrived, so one message often comes in
several chunks)."""
out = []
last_t = None
for c in capture.chunks:
if (out and out[-1].direction == c.direction
and last_t is not None and c.t - last_t < gap):
out[-1].data.extend(c.data)
else:
out.append(Message(c.t, c.direction, bytearray(c.data)))
last_t = c.t
for m in out:
m.data = bytes(m.data)
return out


def transcript(capture, limit=40, width=32, gap=0.05):
"""The first ``limit`` messages, one line each: time, direction,
length, and the first ``width`` bytes in hex and as text."""
lines = []
msgs = messages(capture, gap)
for m in msgs[:limit]:
head = m.data[:width]
text = "".join(chr(b) if 32 <= b < 127 else "." for b in head)
more = " ..." if len(m.data) > width else ""
lines.append(f"{m.t:9.3f} {m.direction:8s} {len(m.data):6,} B "
f"{head.hex(' ')}{more} |{text}|")
if len(msgs) > limit:
lines.append(f"... {len(msgs) - limit} more messages")
return lines


def extract_personality(data):
"""Bytes of a .PRS archive found in ``data``, or None.

Expand Down Expand Up @@ -110,12 +152,20 @@ def report(capture, top=8):
span = capture.chunks[-1].t - capture.chunks[0].t
lines.append(f"{len(capture.chunks)} chunks over {span:.1f} s, "
f"{len(capture.events)} line events")
msgs = messages(capture)
for direction, s in summarize(capture).items():
lines.append("")
mine = [m for m in msgs if m.direction == direction]
lines.append(f"{direction}: {s.total_bytes:,} bytes in "
f"{s.chunks} chunks")
f"{s.chunks} chunks, {len(mine)} messages")
if not s.chunks:
continue
sizes = Counter(len(m.data) for m in mine)
openers = Counter(m.data[:2].hex(" ") for m in mine)
lines.append(" common message sizes: " + ", ".join(
f"{size} B x{n}" for size, n in sizes.most_common(top)))
lines.append(" common message openers: " + ", ".join(
f"[{k}] x{n}" for k, n in openers.most_common(top)))
sizes = ", ".join(f"{size} B x{n}"
for size, n in s.chunk_sizes.most_common(top))
lines.append(f" common chunk sizes: {sizes}")
Expand Down
21 changes: 14 additions & 7 deletions quickprs/radio/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def cmd_radio_sniff(host="127.0.0.1", port=24352, log="session.jsonl",
pcapng file saved from it. Only the serial (RFCOMM) bytes are kept.
"""
import socket
from .hci import read_packets, serial_chunks, PcapError
from .hci import (read_packets, serial_chunks, PcapError, TraceStats,
describe)

if not all_links and address is None:
address = _radio_address()
Expand Down Expand Up @@ -189,10 +190,12 @@ def cmd_radio_sniff(host="127.0.0.1", port=24352, log="session.jsonl",
+ (f", link to {address}" if address else "")
+ f". Run the operation in RPM, then press Ctrl+C here.")

stats = TraceStats()
with CaptureWriter(log, note=note) as writer:
try:
for t, direction, data in serial_chunks(read_packets(stream),
address=address):
address=address,
stats=stats):
writer.add(direction, data, t=t)
counts[direction] += len(data)
except KeyboardInterrupt:
Expand All @@ -201,24 +204,28 @@ def cmd_radio_sniff(host="127.0.0.1", port=24352, log="session.jsonl",
print(f"Error: {e}", file=sys.stderr)
finally:
stream.close()
for line in describe(stats, address):
print(line)
print(f"RPM to radio: {counts['pc>radio']:,} bytes; radio to RPM: "
f"{counts['radio>pc']:,} bytes.")
if not any(counts.values()):
print("No serial data found. Was Full Packet Logging on in the "
"sniffer, and did RPM talk to the radio while it ran?",
file=sys.stderr)
print(f"Analyze with: quickprs radio analyze {log}")
return 0


def cmd_radio_analyze(capture_path, extract=None):
def cmd_radio_analyze(capture_path, extract=None, transcript=None):
try:
cap = read_capture(capture_path)
except (OSError, ValueError) as e:
print(f"Error: {e}", file=sys.stderr)
return 1
for line in report(cap):
print(line)
if transcript:
from .analyze import transcript as conversation
print()
print("Conversation (consecutive chunks one way are one message):")
for line in conversation(cap, limit=transcript):
print(line)
if extract:
data = extract_personality(cap.stream(RADIO_TO_PC))
if data is None:
Expand Down
Loading