Skip to content

drivers/wireless/cc1101: Add MSK/4-FSK, dynamic PATABLE ramping, and fix IOCTL safety#18527

Merged
simbit18 merged 1 commit intoapache:masterfrom
AuroraRAS:ioctl1101
Mar 11, 2026
Merged

drivers/wireless/cc1101: Add MSK/4-FSK, dynamic PATABLE ramping, and fix IOCTL safety#18527
simbit18 merged 1 commit intoapache:masterfrom
AuroraRAS:ioctl1101

Conversation

@AuroraRAS
Copy link
Contributor

Summary

This PR introduces a comprehensive refactoring and stabilization of the CC1101 wireless character driver. It aligns the driver's software logic with the physical hardware state machine defined in the Texas Instruments specifications (DN013/SWRA151A), ensuring safe cross-band operation and robust IOCTL memory safety.

Key Modifications:

  • Modulation Support: Extended ioctl.h to include WLIOC_MSK and WLIOC_4FSK. Implemented strict hardware constraint checks in WLIOC_SETMODU (e.g., rejecting MSK if baud rate <= 26 kBaud, enforcing Manchester coding exclusions).
  • Dynamic PA Ramping: Deprecated static rfsettings->PA logic. Introduced a frequency-aware g_cc1101_pa_calibration matrix to dynamically reconstruct the PATABLE via Burst Access. This natively resolves ASK/OOK pulse truncation and minimizes FSK adjacent-channel splatter.
  • Standardized TX Power: WLIOC_SETTXPOWER and WLIOC_GETTXPOWER now strictly operate on dBm units (as defined by ioctl.h) using a quantized nearest-match algorithm, abandoning the arbitrary 0-8 indexing.
  • Math & Overflow Safety: Implemented hard clamping for mantissa calculations in WLIOC_FSK_SETBITRATE (256-511) and WLIOC_FSK_SETFDEV (8-15) to prevent silent register wrap-around under extreme input parameters.
  • Kernel Memory Safety: Replaced uncompiled DEBUGASSERT checks with strict if (ptr == NULL) return -EFAULT; validations across all IOCTL branches to prevent user-space-triggered segmentation faults.
  • Low-Power Reliability: Added a mandatory PATABLE reconstruction call inside cc1101_powerup() to fix the known hardware issue where indices 1-7 are lost during SLEEP state.

Impact

  • Is new feature added? Yes. MSK and 4-FSK modulation.
  • Is existing feature changed? Yes. WLIOC_SETTXPOWER now accepts dBm instead of raw index values.
  • Impact on Build: None.
  • Impact on Hardware: Significantly improves RF spectral purity and communication stability across diverse frequency bands (315/433/868/915 MHz).

Testing

I confirm that changes are verified locally.

  • Build Host: Fedora 43

  • Target Architecture: Xtensa / ESP32 (Hardware setup featuring dual CC1101 transceivers and an nRF24L01, EvilCrowRF-V2 layout).

  • Testing Methods & Results:

    • IOCTL Parameter & Clamping Verification: Successfully validated the full suite of standard IOCTLs (WLIOC_SETRADIOFREQ, WLIOC_SETTXPOWER, WLIOC_SETMODU, WLIOC_FSK_SETBITRATE, WLIOC_FSK_SETFDEV) on both /dev/radio0 and /dev/radio1. The mathematical saturation and clamping logic proved accurate against the hardware limits (e.g., configuring a 250,000 bps target bitrate cleanly quantized to an actual 249,938 bps; 47,000 Hz target FDEV quantized to 44,433 Hz).
    • Cross-Band RF Validation: Executed bidirectional TX/RX payload verification and 100-packet throughput stress tests across all four primary ISM bands to guarantee the new dynamic PATABLE generator adapts correctly to WLIOC_SETRADIOFREQ calls:
      • 315 MHz & 433 MHz: Achieved near-perfect reliability with 98%–100% packet delivery rates and throughputs peaking at ~3.95 KB/s (31.5 kbps).
      • 868 MHz & 915 MHz: Payload verification passed successfully in both directions. Stress tests completed with delivery rates ranging from 54% to 91%, handling the dynamic frequency shifts without state machine lockups.
    • Driver Coexistence / Regression:
      Confirmed that the SPI bus and IOCTL interface behavior for other wireless drivers on the same hardware (/dev/nrf24l01) remain completely unaffected by the CC1101 IOCTL architecture changes.

…L safety

This commit overhauls the CC1101 RF driver to address physical hardware
constraints, prevent register wrap-around overflows, and support accurate
dBm power scaling via the standard IOCTL interface.

What this change does:
1. Adds WLIOC_MSK and WLIOC_4FSK modulation support in `ioctl.h` and driver.
2. Replaces static PATABLE initialization with a dynamic Ramp-up curve
   generator `cc1101_ioctl_apply_power()` based on lab calibration data.
3. Modifies WLIOC_SETTXPOWER and WLIOC_GETTXPOWER to process actual dBm
   values with a nearest-match algorithm instead of raw array indices.
4. Removes DEBUGASSERT on user-space IOCTL pointers and replaces them
   with strict -EFAULT checks.
5. Implements saturation clamping (e.g., mantissa to 256-511) to prevent
   bitrate and frequency deviation calculation overflows.
6. Rebuilds volatile PATABLE memory upon SLEEP mode wake-up.

Why it is necessary & what it fixes:
- Fixes severe OOK modulation distortion and FSK spectral splatter caused
  by statically assigned PATABLE indices.
- Fixes potential kernel panic in flat builds when IOCTL receives a NULL
  pointer from user space.
- Fixes register wrap-around (silent failures) when users pass
  out-of-bounds baud rate or FDEV values.
- Prevents RF silence after SLEEP mode due to PATABLE volatility.
- Resolves inaccurate power output when changing frequencies dynamically.

Impact:
Changes the behavior of CC1101 TX power and modulation IOCTLs to strictly
comply with standard `wlioc` definitions. Improves overall driver stability
and hardware safety.

Signed-off-by: Chip L. <chplee@gmail.com>
@github-actions github-actions bot added Area: Drivers Drivers issues Size: M The size of the change in this PR is medium labels Mar 11, 2026
@jerpelea jerpelea changed the title wireless/cc1101: Add MSK/4-FSK, dynamic PATABLE ramping, and fix IOCTL safety drivers/wireless/cc1101: Add MSK/4-FSK, dynamic PATABLE ramping, and fix IOCTL safety Mar 11, 2026
@simbit18 simbit18 merged commit 7bfd6ee into apache:master Mar 11, 2026
117 of 151 checks passed
@AuroraRAS AuroraRAS deleted the ioctl1101 branch March 11, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants