ath11k_nss: Enhance nss_diag to properly list ifaces

Also optimized to use more native functions

Signed-off-by: Sean Khan <datapronix@protonmail.com>
This commit is contained in:
Sean Khan
2024-10-05 14:50:44 -04:00
parent 3c2ddb1d25
commit c7855bed69

View File

@@ -1,92 +1,80 @@
#!/bin/sh #!/bin/sh
# shellcheck disable=3037,3060,2034,1091 # shellcheck disable=3037,3060,2034,1091,2166
blue=""
red=""
green=""
yellow=""
white=""
reset=""
bold=""
# check if stdout is a terminal, then set colors. # check if stdout is a terminal, then set colors.
if test -t 1; then if [ -t 1 ]; then
fg=$(printf '\033[38;5;') red="\033[31m"
bg=$(printf '\033[48;5;') green="\033[32m"
red=$(printf '\033[31m') yellow="\033[33m"
green=$(printf '\033[32m') blue="\033[34m"
yellow=$(printf '\033[33m') magenta="\033[35m"
blue=$(printf '\033[34m') cyan="\033[36m"
magenta=$(printf '\033[35m') white="\033[37m"
cyan=$(printf '\033[36m') reset="\033[m"
white=$(printf '\033[37m') bold="\033[1m"
reset=$(printf '\033[m')
bold=$(printf '\033[1m')
underline=$(printf '\033[4m')
blink=$(printf '\033[5m')
invert=$(printf '\033[7m')
resetbold=$(printf '\033[21m')
resetunderline=$(printf '\033[24m')
else
fg=""
bg=""
red=""
green=""
yellow=""
blue=""
magenta=""
cyan=""
white=""
reset=""
bold=""
underline=""
blink=""
invert=""
resetbold=""
resetunderline=""
fi fi
# Retrieve OpenWRT version
[ -r /etc/openwrt_version ] && openwrt_rev=$(cat /etc/openwrt_version) [ -r /etc/openwrt_version ] && openwrt_rev=$(cat /etc/openwrt_version)
# Retrieve device model
model=$(jsonfilter -e ''@.model.name'' < /etc/board.json | sed -e "s/,/_/g") model=$(jsonfilter -e ''@.model.name'' < /etc/board.json | sed -e "s/,/_/g")
# NSS firmware version # NSS firmware version
nss_fw="/lib/firmware/qca*.bin" nss_fw="/lib/firmware/qca*.bin"
# shellcheck disable=2086
[ "$(ls $nss_fw 2> /dev/null)" ] && nss_version=$(grep -h -m 1 -a -o 'Version:.[^[:cntrl:]]*' $nss_fw | head -1 | cut -d ' ' -f 2) [ "$(ls $nss_fw 2> /dev/null)" ] && nss_version=$(grep -h -m 1 -a -o 'Version:.[^[:cntrl:]]*' $nss_fw | head -1 | cut -d ' ' -f 2)
# ATH11K firmware version # ATH11K firmware version
ath11k_fw=$(grep -h -m 1 -a -o 'WLAN.[^[:cntrl:]]*SILICONZ-1' /lib/firmware/*/q6* | head -1) ath11k_fw=$(grep -hm1 -a -o 'WLAN.[^[:cntrl:]]*SILICONZ-1' /lib/firmware/*/q6* | head -1)
# MAC80211 (backports) version # MAC80211 (backports) version
mac80211_version=$(awk '/version/{print $NF;exit}' /lib/modules/*/compat.ko) mac80211_version=$(awk '/version/{print $NF;exit}' /lib/modules/*/compat.ko)
# OpenWRT IPQ # OpenWRT IPQ release details
[ -r /etc/ipq_release ] && . /etc/ipq_release [ -r /etc/ipq_release ] && . /etc/ipq_release
ipq_branch=${IPQ_BRANCH:-"N/A"} ipq_branch=${IPQ_BRANCH:-"N/A"}
ipq_commit=${IPQ_COMMIT:-"N/A"} ipq_commit=${IPQ_COMMIT:-"N/A"}
ipq_date=${IPQ_DATE:-"N/A"} ipq_date=${IPQ_DATE:-"N/A"}
[ -z "$openwrt_rev" ] && openwrt_rev="N/A" # Defaults for empty variables
[ -z "$model" ] && model="N/A" openwrt_rev=${openwrt_rev:-"N/A"}
model=${model:-"N/A"}
nss_version=${nss_version:-"N/A"}
ath11k_fw=${ath11k_fw:-"N/A"}
mac80211_version=${mac80211_version:-"N/A"}
# Display the information
echo -e "${bold}${red} MODEL${reset}: ${blue}${bold}${model}${reset}"
echo -e "${bold}${red} OPENWRT${reset}: ${white}${openwrt_rev}${reset}"
echo -e "${bold}${red}IPQ BRANCH${reset}: ${cyan}${ipq_branch}${reset}"
echo -e "${bold}${red}IPQ COMMIT${reset}: ${cyan}${ipq_commit}${reset}"
echo -e "${bold}${red} IPQ DATE${reset}: ${cyan}${ipq_date}${reset}"
echo -e "${bold}${red} NSS FW${reset}: ${magenta}${nss_version}${reset}"
echo -e "${bold}${red} MAC80211${reset}: ${yellow}${mac80211_version}${reset}"
echo -e "${bold}${red} ATH11K FW${reset}: ${green}${ath11k_fw}${reset}"
[ -z "$nss_version" ] && nss_version="N/A" # Display GRO Fragmentation status using BusyBox
[ -z "$ath11k_fw" ] && ath11k_fw="N/A"
[ -z "$mac80211_version" ] && mac80211_version="N/A"
echo -e "${bold}${red} MODEL${reset}: ${white}${model}${reset}"
echo -e "${bold}${red} OPENWRT${reset}: ${yellow}${openwrt_rev}${reset}"
echo -e "${bold}${red}IPQ BRANCH${reset}: ${green}${ipq_branch}${reset}"
echo -e "${bold}${red}IPQ COMMIT${reset}: ${green}${ipq_commit}${reset}"
echo -e "${bold}${red} IPQ DATE${reset}: ${green}${ipq_date}${reset}"
echo -e "${bold}${red} NSS FW${reset}: ${cyan}${nss_version}${reset}"
echo -e "${bold}${red} MAC80211${reset}: ${white}${mac80211_version}${reset}${reset}"
echo -e "${bold}${red} ATH11K FW${reset}: ${cyan}${ath11k_fw}${reset}"
echo -ne "${bold}${red} GRO FRAG${reset}: ${white}" echo -ne "${bold}${red} GRO FRAG${reset}: ${white}"
n=0
count=0 for iface in /sys/class/net/*; do
iface=${iface##*/}
for i in wan br-lan /sys/class/net/br-lan/brif/*; do [ "$iface" = "lo" -o "$iface" = "miireg" ] && continue
i=${i##*\/} gro_status=$(ethtool -k "$iface" 2> /dev/null | awk '/rx-gro-list/{print $2}')
ethtool -k ${i} | awk -v count=$count -v i=$i -v white=$white -v green=$green -v r=$reset ' gro_status=${gro_status:-"N/A"}
/rx-gro-list/ { color=$green
if(count>0) tab=" " [ "$gro_status" = "on" ] && color=$red
color=red [ $n -gt 0 ] && spacing=" "
if($2=="off") color=green printf "%s%-11s : %b%s%b\n" "$spacing" "$iface" "$color" "$gro_status" "$reset"
printf "%s%-11s : %s%s%s\n",tab,i,color,$2,r n=$((n + 1))
}'
count=$((count + 1))
done done
echo -e "${reset}" echo -e "${reset}"