Packets: Wireshark and interfaces¶
A profile's messages (every frame it decodes: fields, payload, whether its check passed) can be watched live in Wireshark, each as a packet of the link type Wireshark dissects it as, with what RPPS knows of it alongside: the profile, the message kind, the check and its verdict, the frequency, the quality, the fields. Packets go the other way too: written to an interface (or a capture), they are sent through the profile's transmitter.
rpps rx ble/adv capture.cf32 --fs 4e6 --pcap - | wireshark -k -i - # live, from a file
rpps rx ble/adv --device hackrf --cf 2.402e9 --fs 4e6 --pcap - | wireshark -k -i - # live, from a radio
rpps rx ax25/afsk1200 audio.cf32 --fs 48e3 --pcap pipe:rpps # Windows: wireshark -k -i \\.\pipe\rpps
rpps rx ieee802154/frames zigbee.cf32 --fs 8e6 --tun rpps0:ieee802_15_4_nofcs # Linux: onto an interface
rpps tx ieee802154/frames --from-tun rpps1:ieee802_15_4_nofcs --device hackrf --cf 2.405e9 --rate 250e3
"""Decoded packets in Wireshark, and packets back out: a profile's capture rules, pcapng, and the transmitter
python examples/wireshark_packets.py # writes and checks rpps_packets.pcapng (in the temp dir)
python examples/wireshark_packets.py - | wireshark -k -i - # the same, live in Wireshark
A profile's messages (each decoded frame: its fields, payload and check) become packets of the link type Wireshark dissects them as, by the profile's "capture" rules (rpps.link.capture): Bluetooth LE with its pseudo-header (channel, CRC checked and valid), AX.25, 802.15.4 with its FCS. Each (profile, kind) is an interface of its own in the capture, and each packet's comment says what it was. Here: a Bluetooth LE advertisement and two AX.25 frames are made with the profiles' own transmitters, received, written as pcapng (to a file, or stdout with "-"), read back and checked; then the BLE packet goes back out through rp.profile.Encoder (the capture rule undone) and is received to the same bytes. """ import sys import tempfile from pathlib import Path
import numpy as np
import rpps as rp
def receive(p, x, Fs, sps): rx = p.rx() rx(rp.Data(x, Fs=Fs, sps=sps, flush=True)) return rx.take_messages()
def main(target=None): target = target or str(Path(tempfile.gettempdir())/"rpps_packets.pcapng") # Bluetooth LE: an ADV_NONCONN_IND carrying the advertiser's address and its name ble = rp.profile.load("ble/adv") adv = bytes.fromhex("112233445566") + bytes([2, 1, 6, 5, 9]) + b"RPPS" o = ble.tx()([rp.Data(adv, Fs=1e6, sps=1)], fields={"type": 2, "txadd": 1}, flush=True) ble_msgs = receive(ble, np.asarray(o.data), o.Fs, 4)
# AX.25 (APRS): two UI frames over 1200 baud AFSK
ax = rp.profile.load("ax25/afsk1200", centre=0, sps=10)
call = lambda c, ssid, last: bytes(ord(ch) << 1 for ch in c.ljust(6)) + bytes([0x60 | ssid << 1 | last])
frames = [call("APRS", 0, 0) + call("N0CALL", 7, 1) + b"\x03\xf0" + text for text in (b">hello", b">from rpps")]
tx, s, waves = ax.tx(), None, []
for i, f in enumerate(frames):
d = rp.Data(f, Fs=1200.0, sps=1, stream=s, flush=i == len(frames) - 1)
s = d.stream
waves.append(tx(d).data)
x = np.concatenate([np.zeros(400, np.complex64)] + waves + [np.zeros(400, np.complex64)])
ax_msgs = receive(ax, x, 12e3, 10)
# Every message as a packet of its link type: written as pcapng
packets = ble.capture.packets(ble_msgs) + ax.capture.packets(ax_msgs)
with rp.source.PcapSink(target) as sink:
packets >> sink
if target == "-":
return
recs = list(rp.source.Pcap(target))
assert [r.dlt for r in recs] == [256, 3, 3] # LINKTYPE_BLUETOOTH_LE_LL_WITH_PHDR, LINKTYPE_AX25
assert recs[0].data[10:14] == bytes.fromhex("d6be898e") and adv in recs[0].data # access address, then the PDU
assert [r.data for r in recs[1:]] == frames # AX.25 frames from the destination address, no FCS
assert recs[0].comment.startswith("ble/adv pdu, ok (crc24_ble)") and "type.name=ADV_NONCONN_IND" in recs[0].comment
print(f"{target}: {sink.count} packets, interfaces {sink.per}")
# And back out: the BLE packet through the transmitter, received to the same bytes
enc = rp.profile.Encoder(ble, rate=1e6)
y = np.concatenate((enc.packet(recs[0].data).data, enc.flush().data))
again = ble.capture.packets(receive(ble, y, enc.Fs, 4))
assert [k.data for k in again] == [recs[0].data]
print("the BLE packet, sent again and received: the same bytes")
if name == "main": main(sys.argv[1] if len(sys.argv) > 1 else None)
Capture rules¶
A profile says how each message kind becomes a packet in "capture" (the rules and their transforms:
rpps.link.capture); the link types are definitions, config/linktype (python -m rpps ls linktype).
The shipped profiles' rules:
| Profile | Kind | Link type | What is done |
|---|---|---|---|
ble/adv |
pdu |
ble_ll_phdr (256) |
access address before; the pseudo-header: RF channel, dewhitened, CRC checked and valid |
ax25/afsk1200 |
frame |
ax25 (3) |
the frame without flags or FCS |
ieee802154/frames |
phr |
ieee802_15_4 (195) |
the PSDU with its FCS, which Wireshark checks |
ieee80211b/long |
plcp |
ieee802_11_radiotap (127) |
radiotap: rate (from SIGNAL), channel, FCS at the end |
dvbs/* |
packet |
mpeg2_ts (243) |
transport stream packets |
dvbs2/ts |
ts |
mpeg2_ts (243) |
user packets cut across BBFRAMEs (SYNCD, UPL), CRC-8 checked, sync byte put back, deleted null packets put back |
dvbs2/mpe |
mpe |
raw (101) |
the IP datagrams of MPE sections cut across the transport packets of a pid (pointer field), CRC-32 checked |
dvbs2/si, dvbs/si |
ts, packet |
mpeg2_ts (243) |
the transport packets: Wireshark reads the PSI/SI tables itself; the profile's si messages are the sections, read |
dvbs2/ule |
ule |
raw (101) |
the IPv4 and IPv6 PDUs of ULE SNDUs cut across the transport packets of a pid, CRC-32 checked |
ccsds/tm_packets |
space |
exported PDU, ccsds |
space packets cut across transfer frames per virtual channel (first header pointer) |
dvbs2/*, dvbrcs2/forward |
bbheader |
exported PDU, dvb-s2_modeadapt |
the BBFRAME, header and data field: Wireshark reads GSE and what it carries |
lte/downlink, nr/downlink |
pbch, pdsch |
exported PDU, lte_rrc.* / nr-rrc.* |
the MIB, the SIB1 transport block |
A kind without a rule goes out as Wireshark's exported PDU to its data dissector (Mode S, P25, DMR), its columns
saying the profile, kind and fields. A rule chooses the frame's parts (include: header, payload, FCS), restores what a
link type expects (bit order, a prefix, a sync byte, PPP's compressed address and protocol), adds a pseudo-header,
drops idle frames (drop), and names the fields for the comment. A standard framing Wireshark knows (Cisco HDLC, PPP)
is captured whole, with its link type, and Wireshark separates its header; "linktype": "find" finds where a known
link type starts after a header nobody describes.
DVB service information¶
The tables a DVB receiver finds its way round a multiplex with (EN 300 468, ISO/IEC 13818-1) are sections on known
PIDs: dvbs2/si and dvbs/si give a message per section (kind si), read by header/link/dvb_si: its table in
table_id.name, its descriptors by tag, dates and times decoded, its CRC-32 checked. Its transport packets are
captured as MPEG-TS, which Wireshark reads the tables of too.
"""DVB service information out of a transport stream: the network, its services and the time
python examples/dvb_si.py
The PSI/SI tables a DVB receiver reads to find its way round a multiplex (EN 300 468, ISO/IEC 13818-1) are sections
on known PIDs: the PAT on 0x00, the NIT on 0x10, the SDT on 0x11, the TDT and TOT on 0x14, the PMTs where the PAT says.
header/link/dvb_si reads every one of them (and builds them, transmitting): the section header, the table by its id,
its descriptors by tag, the CRC-32 checked where there is one. Here a NIT, an SDT, a TDT and a TOT are built from
values with that definition, carried in transport packets over DVB-S2 (dvbs2/ts), and received with dvbs2/si: a
message per section, its table in table_id.name, dates, times, frequencies and symbol rates decoded. DVB-S is the
same with dvbs/si.
"""
import numpy as np
import rpps as rp
def section(si, fields, payload): """A section's bytes: the table's payload built with its header's fields in scope, then header, payload and CRC-32, the lengths worked out""" body = si.payload_schema.build(payload, fields) si.control(**fields) return np.packbits(np.asarray((rp.Data(body, flush=True) * si).data, bool)).tobytes()
def packets(sec, pid): """One section in transport packets of a PID: a pointer field in the first, 0xFF filling the last""" data, out = b"\x00" + sec, [] for cc, i in enumerate(range(0, len(data), 184)): head = bytes([0x47, (i == 0) << 6 | pid >> 8, pid & 255, 0x10 | cc % 16]) out.append(head + data[i:i + 184].ljust(184, b"\xff")) return out
def descriptor(tag, **body): return {"tag": tag, "body": body}
def main(): si = rp.link.load("header/dvb_si") syntax = {"ssi": 1, "version_number": 3} nit = section(si, {"table_id": 0x40, "table_id_extension": 0x0055, **syntax}, {"nit": { "descriptors": [descriptor(0x40, network_name="RPPS sat")], "transport_streams": [{"transport_stream_id": 1, "original_network_id": 0x0055, "descriptors": [ descriptor(0x43, frequency=11778000000, orbital_position=192, west_east=1, modulation_system=1, modulation_type=2, symbol_rate=27500000, **{"fec_inner.name": "3/4"})]}]}}) sdt = section(si, {"table_id": 0x42, "table_id_extension": 1, **syntax}, {"sdt": { "original_network_id": 0x0055, "services": [{"service_id": 100, "eit_present_following": 1, "running_status": 4, "descriptors": [ descriptor(0x48, service_type=25, provider_name="RPPS", service_name="Café HD")]}]}}) tdt = section(si, {"table_id": 0x70, "ssi": 0}, {"tdt": {"utc_date": "2026-11-26", "utc_time": "12:34:56"}}) tot = section(si, {"table_id": 0x73, "ssi": 0}, {"tot": { "utc_date": "2026-11-26", "utc_time": "12:34:56", "descriptors": [descriptor(0x58, offsets=[{"country_code": "DEU", "local_time_offset": "01:00", "time_of_change_date": "2027-03-28", "time_of_change_time": "01:00:00", "next_time_offset": "02:00"}])]}}) ts = packets(nit, 0x10) + packets(sdt, 0x11) + packets(tdt, 0x14) + packets(tot, 0x14) ts += [bytes([0x47, 0x1F, 0xFF, 0x10]) + b"\xff"184]2 # (null packets: the last user packet's check needs one after)
# Over DVB-S2 (TS mode), and back
o = rp.profile.load("dvbs2/ts").tx()(rp.Data(np.unpackbits(np.frombuffer(b"".join(ts), np.uint8)).astype(bool),
Fs=1e6, sps=1, flush=True), fields={"modcod": 4, "pilots": 1})
rx = rp.profile.load("dvbs2/si", sync={"timing": {"method": "known"}}).rx()
rx(rp.Data(np.concatenate((o.data, np.zeros(200, np.complex64))), Fs=o.Fs, sps=4, delay=o.delay, flush=True))
tables = {m.fields["table_id.name"]: m for m in rx.take_messages() if m.kind == "si"}
assert set(tables) == {"NIT", "SDT", "TDT", "TOT"} and all(m.crc_ok is not False for m in tables.values())
nit = tables["NIT"].fields["payload"]["nit"]
name = nit["descriptors"][0]["body"]["network_name"]
sat = nit["transport_streams"][0]["descriptors"][0]["body"]
print(f"network {name}: {sat['frequency']/1e9:.3f} GHz, {sat['orbital_position']/10}° "
f"{sat['west_east.name']}, {sat['modulation_system.name']} {sat['modulation_type.name']} "
f"{sat['symbol_rate']/1e6} MBd FEC {sat['fec_inner.name']}")
assert (name, sat["frequency"], sat["symbol_rate"]) == ("RPPS sat", 11778000000, 27500000)
svc = tables["SDT"].fields["payload"]["sdt"]["services"][0]
body = svc["descriptors"][0]["body"]
print(f"service {svc['service_id']}: {body['service_name']} ({body['service_type.name']}, "
f"{svc['running_status.name']}) from {body['provider_name']}")
assert body["service_name"] == "Café HD"
tdt = tables["TDT"].fields["payload"]["tdt"]
off = tables["TOT"].fields["payload"]["tot"]["descriptors"][0]["body"]["offsets"][0]
print(f"UTC {tdt['utc_date']} {tdt['utc_time']} (no CRC: crc_ok {tables['TDT'].crc_ok}); "
f"{off['country_code']} +{off['local_time_offset']}, +{off['next_time_offset']} from {off['time_of_change_date']}")
assert (tdt["utc_date"], tdt["utc_time"], off["local_time_offset"]) == ("2026-11-26", "12:34:56", "01:00")
if name == "main": main()
In Wireshark¶
Each (profile, kind) is an interface of its own (rpps:<profile>:<kind>). Filters:
frame.comment contains "FAILED": frames whose check failed (alsoframe.packet_flags_crc_error == 1).frame.interface_name == "rpps:ble/adv:pdu".- With
--pcap-rpps(orPcapSink(..., rpps=True)) andtools/wireshark/rpps.lua(wireshark -X lua_script:tools/wireshark/rpps.lua, or copy it to Wireshark's plugins folder), each packet carries an RPPS header shown as fields:rpps.crc_ok == 0,rpps.profile == "ble/adv",rpps.field == "type.name=ADV_IND", before its own dissector. --pcap-clock wallstamps packets with the time they are written instead of the stream's own.
Interfaces (Linux)¶
rp.source.Tun is a TUN or TAP interface both ways (rpps.source). A TUN is raw IP, or on Linux
another link type it is set to (802.11, 802.15.4 without FCS, AX.25 with its KISS byte); a TAP is Ethernet. A packet
of a link type that is the interface's with transforms is converted (a link type's "from" in config/linktype: 802.15.4
with its FCS checked and taken off, AX.25 given its KISS byte), and back when transmitting; other packets are skipped
and counted: the pcapng stream carries any. Make the interface once, owned by you, and
RPPS opens it without root:
sudo ip tuntap add dev rpps0 mode tun user $USER
sudo ip link set rpps0 up # (after RPPS set its link type: it is set while the interface is down)
Windows and macOS have the pcapng stream (a named pipe, a FIFO, stdout) instead.
Transmitting¶
rp.profile.Encoder undoes a capture rule (a header part gives the frame's fields; an FCS is made again) and sends each
packet as one frame or burst; rp.source.DeviceSink transmits with a pysdrlib radio (rpps tx --device).
# docs: skip
enc = rp.profile.Encoder("ieee802154/frames", rate=250e3, linktype="ieee802_15_4_nofcs") # (Linux's: no FCS, made here)
with rp.source.Tun("rpps1", linktype="ieee802_15_4_nofcs") as tun, \
rp.source.DeviceSink("hackrf", cf=2.405e9, Fs=8e6, tx_gain=0.2) as radio:
for pkt in tun.packets():
enc.packet(pkt) >> radio
Packets that cross frames go as a stream: dvbs2/ts transmits transport packets given back to back
(p.tx()(rp.Data(bits, ...))), packing them into TS-mode BBFRAMEs itself (SYNCD per frame, each sync byte the CRC-8 of
the packet before), however the stream is cut.
Without a radio, pysdrlib's simulated radios share an air (pysdrlib.air, pysdrlib 0.5.1):
rp.source.DeviceSink("sim", air="lab", transmit=True, ...) sends into it, and
rp.source.Device("sim", air="lab", ...) receives it, in this process or another, at its own frequency and rate (the
loop tests/unit/profile/test_encoder.py runs in real time).