fix: move RTL-SDR to userspace

This commit is contained in:
2026-08-29 10:02:32 +02:00
parent b1f1cfe32b
commit 5cd5c2e6be
35 changed files with 1922 additions and 1592 deletions
+44
View File
@@ -0,0 +1,44 @@
.TH RTLSDR 3
.SH NAME
rtlsdr.lib - userspace RTL2832U and R820T2 radio driver
.SH SYNOPSIS
.nf
#include <rtlsdr/rtlsdr.h>
.fi
.SH DESCRIPTION
The library at
.B 0:/os/rtlsdr.lib
drives supported Realtek RTL2832U USB receivers from userspace through the
generic process-owned USB API. Supported USB product IDs are 0bda:2832 and
0bda:2838. Samples are returned as interleaved unsigned 8-bit I/Q pairs.
Applications load the library with libloader, resolve the
.B rtlsdr_*
symbols declared in the header, enumerate devices, open one, configure it,
start bulk reception, read samples, stop, and close it. Claims are exclusive
and are released by the kernel if the process exits or the device disconnects.
.SH API
.B rtlsdr_count
and
.B rtlsdr_get_device_info
enumerate compatible unbound USB interfaces.
.B rtlsdr_open
claims an interface and returns an opaque device pointer.
.B rtlsdr_set_center_freq,
.B rtlsdr_set_sample_rate,
.B rtlsdr_set_tuner_gain_mode,
.B rtlsdr_set_tuner_gain,
.B rtlsdr_set_freq_correction,
.B rtlsdr_set_agc_mode,
and
.B rtlsdr_set_direct_sampling
configure the receiver.
.B rtlsdr_start,
.B rtlsdr_read,
and
.B rtlsdr_stop
control non-blocking reception.
.SH NOTES
Syscall numbers 140 through 148 are reserved former SDR slots and are not an
API. Device-specific control and tuner programming live entirely in this
library.
+47 -43
View File
@@ -650,58 +650,62 @@
Forget a paired device; it must re-pair next time.
int montauk::bt_forget(const uint8_t* bdAddr);
.SH SOFTWARE-DEFINED RADIO
Receive-only SDR API. Receivers are enumerated by index in
[0, SYS_SDR_COUNT); SYS_SDR_OPEN returns a handle used by the
rest of the calls. Samples are delivered as interleaved 8-bit
unsigned I/Q (CU8, SDR_FORMAT_CU8) from the device's ring
buffer. Backed by an RTL-SDR (RTL2832U + R820T2) driver.
.SH GENERIC USB INTERFACES
Process-owned access to USB interfaces that do not have a bound kernel
class driver. Claims are exclusive and are released automatically at
process exit. The current xHCI device model records one interface per
device slot, so claiming that interface temporarily claims the whole slot.
Kernel-owned HID, Bluetooth, mass-storage, and RTL-SDR interfaces are
visible in SYS_USB_LIST but cannot be claimed.
.B SYS_SDR_COUNT (140)
Number of available SDR receivers.
int montauk::sdr_count();
.B SYS_USB_LIST (178)
List currently connected USB interfaces. Each UsbInterfaceInfo contains
stable identifiers for the current connection, endpoint addresses, maximum
packet sizes, and kernelDriverBound/claimed flags.
int montauk::usb_list(montauk::abi::UsbInterfaceInfo* buf, int maxCount);
.B SYS_SDR_INFO (141)
Get static/dynamic info for one receiver by index (name, tuner,
frequency/sample-rate ranges, gain steps, present/streaming
flags).
int montauk::sdr_info(int index, montauk::abi::SdrDeviceInfo* out);
.B SYS_USB_CLAIM (179)
Exclusively claim an unbound interface. Returns a generation-checked handle
owned by the calling process.
int montauk::usb_claim(uint8_t slotId, uint8_t interfaceNumber);
.B SYS_SDR_OPEN (142)
Open a receiver by index. Returns a handle.
int montauk::sdr_open(int index);
.B SYS_USB_CLOSE (180)
Stop active transfers and release a USB claim.
int montauk::usb_close(int handle);
.B SYS_SDR_CLOSE (143)
Close a receiver handle.
int montauk::sdr_close(int handle);
.B SYS_USB_CONTROL (181)
Execute a USB control transfer on endpoint zero. The requestType direction
bit determines whether data is read or written. request.length must equal
dataLen; control payloads are currently limited to 4096 bytes.
int montauk::usb_control(int handle, const montauk::abi::UsbControlRequest* request,
void* data, uint32_t dataLen);
.B SYS_SDR_START (144)
Begin streaming samples.
int montauk::sdr_start(int handle);
.B SYS_USB_BULK_IN_START (182)
Start a continuous bulk-IN transfer pool. transferBytes is 1..4096 and
bufferCount is 1..16. Completed data is copied into a 256 KiB per-claim
ring buffer.
int montauk::usb_bulk_in_start(int handle, uint32_t transferBytes,
uint32_t bufferCount);
.B SYS_SDR_STOP (145)
Stop streaming samples.
int montauk::sdr_stop(int handle);
.B SYS_USB_BULK_IN_STOP (183)
Stop continuous bulk-IN transfers without releasing the claim.
int montauk::usb_bulk_in_stop(int handle);
.B SYS_SDR_READ (146)
Non-blocking read of queued I/Q samples. Returns bytes copied.
int montauk::sdr_read(int handle, void* buf, uint32_t len);
.B SYS_USB_BULK_IN_READ (184)
Non-blocking read from the bulk-IN ring. Returns bytes copied, zero when no
data is queued, or USB_ERR_DISCONNECTED after queued data has been drained.
int montauk::usb_bulk_in_read(int handle, void* data, uint32_t dataLen);
.B SYS_SDR_SETPARAM (147)
Set a tunable parameter (see SDR_PARAM_* below).
int montauk::sdr_set_param(int handle, int param, uint64_t value);
Errors are USB_ERR_INVALID (-1), USB_ERR_BUSY (-2),
USB_ERR_DISCONNECTED (-3), USB_ERR_UNSUPPORTED (-4), USB_ERR_IO (-5),
USB_ERR_NO_RESOURCES (-6), USB_ERR_NOT_FOUND (-7), and
USB_ERR_KERNEL_BOUND (-8).
.B SYS_SDR_GETPARAM (148)
Get a tunable parameter's current value.
int64_t montauk::sdr_get_param(int handle, int param);
Parameters (montauk::abi::SDR_PARAM_*): FREQ (center frequency,
Hz), SAMPLE_RATE (Hz), GAIN_MODE (0=auto/AGC, 1=manual), GAIN
(tenths of dB), FREQ_CORR (ppm), AGC (demod digital AGC, 0/1),
DIRECT_SAMP (0=off, 1=I, 2=Q). Convenience wrappers exist for
each: sdr_set_freq/sdr_get_freq, sdr_set_sample_rate/
sdr_get_sample_rate, sdr_set_gain_mode, sdr_set_gain,
sdr_set_freq_correction, sdr_set_agc.
.SH RESERVED SYSCALL NUMBERS
Syscall numbers 140 through 148 are reserved. They were used by an
experimental kernel SDR API and are intentionally not dispatched or exposed
through userspace syscall wrappers. RTL-SDR support is provided by
0:/os/rtlsdr.lib over the generic userspace USB API.
.SH CLIPBOARD
.B SYS_CLIPBOARD_SET_TEXT (119)