This code was originally based on a Reddit post: DFS Radar Causes 5GHz to Drop and Doesn't Come Back. I would like to express my gratitude to u/_daphreak_
and u/try_harder_later
for their initial efforts and contributions.
I have interactively modified this code using DeepSeek-V3 together with DeepSeek-R1-Lite, and the git history reflects the changes made during the process. I am highly satisfied with the capabilities of both DeepSeek-V3 and DeepSeek-R1-Lite, which have significantly streamlined the development and optimization of this script.
The script dfscheck.sh
is designed to monitor the status of wireless interfaces on OpenWrt routers, specifically handling Dynamic Frequency Selection (DFS) channels and radar detection events. When a radar signal causes the wireless interface to shut down, the script automatically switches to a fallback channel to maintain network connectivity and attempts to switch back to the original channel after a specified period.
- Channel Switching: Automatically switches to a fallback channel when the primary DFS channel is disabled due to radar detection, ensuring network connectivity.
- Automatic Recovery: After switching to the fallback channel, the script attempts to revert to the primary channel after a default period of 30 minutes.
- Monitoring and Logging: Continuously monitors the wireless interface status and logs significant events for debugging purposes.
- 5G Radio and Interface Detection: Automatically identifies the 5G radio and its interfaces, eliminating the need for manual configuration.
- Configurable Backoff Strategy: Supports
fixed
,linear
, andexponential
backoff strategies for retries after connectivity failures. The default backoff strategy isfixed
.
- Upload the Script: Place
dfscheck.sh
in the/root/
directory. - Grant Execution Permissions: Run
chmod +x /root/dfscheck.sh
. - Run the Script: Execute the script with root privileges and provide the necessary parameters.
Assuming the following configuration:
- Primary Channel: 108
- Fallback Channel: 149
- Backoff Type: fixed (default)
Run the command:
/root/dfscheck.sh 108 149 fixed
channel
: Primary DFS channel (e.g., 108).fallback_channel
: Fallback channel (e.g., 149).backoff_type
: (Optional) Type of backoff strategy (fixed
,linear
, orexp
). Default isfixed
.
- Privilege Requirements: The script must be run with root privileges.
- Network Disruption: Channel switching may cause temporary network disconnection.
- Logging: Logs can be viewed using
logread
. Note that the "connection is okay" message is printed to the console and not logged, to prevent log clogs. - Legal Compliance: Ensure channel configuration complies with local wireless spectrum regulations. Users are responsible for any consequences arising from non-compliance.
To ensure the script runs automatically at startup, create a service in OpenWrt.
The cron method was attempted but resulted in parsing errors, preventing the script from running automatically. Using a service ensures the script starts at boot without relying on cron, providing a more reliable solution.
-
Use the Service Script from the Repository
The repository includes the service script
dfscheck
. Copy this file to the/etc/init.d/
directory:
cp ./dfscheck /etc/init.d/dfscheck
-
Make the Script Executable
Run the following command to ensure the service script is executable:
chmod +x /etc/init.d/dfscheck
-
Enable the Service
Run the following command to ensure the service starts automatically at boot:
/etc/init.d/dfscheck enable
-
Start the Service (Without Rebooting)
To start the service immediately without rebooting the device, run:
/etc/init.d/dfscheck start
-
Check the Service Status
To verify that the service is running, use the following command:
/etc/init.d/dfscheck status
-
Reboot the Device (Optional)
If you want to verify that the service starts automatically after a reboot, run:
reboot
By following these steps, the script will automatically run upon router reboot, with logs maintained for management and debugging.
The service file now includes default values for the primary channel ( 108
), fallback channel ( 149
), and backoff type ( fixed
). These values can be customized by modifying the service file or passing arguments when starting the script manually.
- Default Backoff Strategy: The default backoff strategy is now
fixed
, which uses a constant backoff time of 15 seconds. - Console Output for "Connection is Okay": The "connection is okay" message is now printed to the console instead of being logged.
- DeepSeek Tools: The script was interactively modified using DeepSeek-V3 together with DeepSeek-R1-Lite, which significantly improved the development process and script functionality.
- Simplified CLI: The script now requires only three arguments (
channel
,fallback_channel
, andbackoff_type
), as it automatically identifies the 5G radio and its interfaces. - Default Values: The service file includes default values for the primary channel, fallback channel, and backoff type.
- Improved Documentation: The README now reflects the latest changes, including the new CLI interface, service file updates, and the use of DeepSeek-V3 and DeepSeek-R1-Lite.
This update ensures the documentation is aligned with the latest script and service file changes, making it easier for users to understand and use the tool.