#!/bin/sh wfb_soc=$(ipcinfo -c) wfb_key=/etc/drone.key if [ -e /etc/wfb.conf ]; then . /etc/wfb.conf fi load_modules() { devices=$(lsusb | cut -d ' ' -f6 | sort | uniq) for card in $devices; do case "$card" in "0bda:8812" | "0bda:881a" | "0b05:17d2" | "2357:0101" | "2604:0012") driver="88XXau" modprobe 88XXau rtw_tx_pwr_idx_override="$driver_txpower_override" ;; "0bda:a81a") driver="8812eu" modprobe 8812eu rtw_regd_src=1 rtw_tx_pwr_by_rate=0 rtw_tx_pwr_lmt_enable=0 ;; "0bda:f72b") driver="8733bu" modprobe 8733bu rtw_regd_src=1 rtw_tx_pwr_by_rate=0 rtw_tx_pwr_lmt_enable=0 ;; esac done if [ -z "$driver" ]; then echo "Wireless module not detected, check the usb connection." exit 1 else echo "Detected driver: $driver" fi while ! ifconfig -a | grep -q "$wlan"; do if [ "$n" -ge 5 ]; then echo "No interface for $wlan, check the usb connection." exit 1 fi sleep 0.5 n=$((n + 1)) done } load_interface() { ifconfig "$wlan" up iwconfig "$wlan" mode monitor if [ "$driver" = "8812eu" ] || [ "$driver" = "8733bu" ]; then iw dev "$wlan" set txpower fixed $((driver_txpower_override * 50)) fi iw reg set "$region" iwconfig "$wlan" channel "$channel" } start_wfb() { echo "Starting wfb_tx" wfb_tx -p "$stream" -R "$rcv_buf" -K "$wfb_key" -B "$bandwidth" -M "$mcs_index" -C 8000 \ -S "$stbc" -L "$ldpc" -k "$fec_k" -n "$fec_n" -i "$link_id" "$wlan" &> /dev/null & } start_tunnel() { if [ ! -e /usr/bin/tunnel_rx ] || [ ! -e /usr/bin/tunnel_tx ]; then ln -fs /usr/bin/wfb_rx /usr/bin/tunnel_rx ln -fs /usr/bin/wfb_tx /usr/bin/tunnel_tx fi echo "Starting wfb_tun" tunnel_rx -p 160 -u 5800 -K "$wfb_key" -i "$link_id" "$wlan" &> /dev/null & tunnel_tx -p 32 -u 5801 -K "$wfb_key" -M "$mcs_index" -S "$stbc" -L "$ldpc" \ -k "$fec_k" -n "$fec_n" -i "$link_id" "$wlan" &> /dev/null & wfb_tun -a 10.5.0.10/24 > /dev/null & } start_telemetry() { if [ "$wfb_soc" = "gk7205v200" ]; then devmem 0x120C0010 32 0x1E04 elif [ "$wfb_soc" = "ssc33x" ]; then devmem 0x1F207890 16 0x8 fi echo "Starting mavfwd" mavfwd --channels "$channels" --master "$serial" --baudrate "$baud" -p 100 -t -a "$aggregate" \ --out 10.5.0.1:14550 --in 0.0.0.0:14551 > /dev/null & } case "$1" in start) if [ ! -e /etc/system.ok ]; then echo "Preparing system tweaks for $wfb_soc..." tweaksys "$wfb_soc" fi load_modules load_interface start_wfb start_tunnel start_telemetry ;; stop) killall -q wfb_tx killall -q wfb_rx killall -q wfb_tun killall -q tunnel_rx killall -q tunnel_tx killall -q mavfwd ;; *) echo "Usage: $0 {start|stop}" exit 1 ;; esac