[][MAC80211][app][Add runtime testmode/normal mode switch cmd in iwpriv wrapper]

[Description]
Add runtime testmode/normal mode switch cmd in iwpriv wrapper

[Release-log]
N/A

Change-Id: Ieb0538c980873809c27cf6a941083cf2f1bc870a
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7329680
diff --git a/feed/atenl/files/iwpriv.sh b/feed/atenl/files/iwpriv.sh
index 6739392..a84c61e 100755
--- a/feed/atenl/files/iwpriv.sh
+++ b/feed/atenl/files/iwpriv.sh
@@ -887,27 +887,29 @@
             local offchan_ch="$(echo $param | cut -d ':' -f1)"
             local offchan_bw="$(echo $param | cut -d ':' -f2)"
 
-	    if [ "$offchan_bw" = "0" ]; then
-            offchan_bw="20"
-	    elif [ "$offchan_bw" = "1" ]; then
-            offchan_bw="40"
-	    elif [ "$offchan_bw" = "2" ]; then
-            offchan_bw="80"
-	    fi
+            if [ "$offchan_bw" = "0" ]; then
+                offchan_bw="20"
+            elif [ "$offchan_bw" = "1" ]; then
+                offchan_bw="40"
+            elif [ "$offchan_bw" = "2" ]; then
+                offchan_bw="80"
+            elif [ "$offchan_bw" = "3" ]; then
+                offchan_bw="160"
+            fi
 
-	    do_cmd "mt76-test phy${phy_idx} set state=idle"
-	    do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
+            do_cmd "mt76-test phy${phy_idx} set state=idle"
+            do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
             ;;
         "DfsRxHist")
             local ipi_th="$(echo $param | cut -d ':' -f 1)"
             local ipi_period="$(echo $param | cut -d ':' -f 2)"
-	    local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
+	        local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
 
-	    if [ -z $ipi_antenna ]; then
-	        do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
-	    else
-		do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
-	    fi
+            if [ -z $ipi_antenna ]; then
+                do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
+            else
+                do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
+            fi
             ;;
         *)
     esac
@@ -1365,6 +1367,44 @@
 ## dump command is only for vendor commands
 elif [ "${cmd_type}" = "dump" ]; then
     do_cmd "mt76-vendor $*"
+elif [ "${cmd_type}" = "switch" ]; then
+    eeprom_mode_file=sys/kernel/debug/ieee80211/phy0/mt76/eeprom_mode
+    eeprom_mode=$(cat ${eeprom_mode_file} | grep "mode" | sed -n 2p | cut -d " " -f 4)
+    eeprom_testmode_offset="1af"
+    testmode_enable="0"
+
+    if [ ${is_eagle} == "0" ]; then
+        return
+    fi
+
+    if [ "${cmd}" = "testmode" ]; then
+        testmode_enable="1"
+    fi
+
+    if [ "${eeprom_mode}" = "flash" ]; then
+        ## flash mode should set eeprom testmode offset bit
+        ## efuse/bin file/default bin mode rely on module param only
+        do_cmd "atenl -i ${interface} -c \"eeprom set 0x${eeprom_testmode_offset}=0x${testmode_enable}\""
+        ## If has no precal, it would not affect
+        do_cmd "atenl -i ${interface} -c \"eeprom precal sync\""
+        do_cmd "atenl -i ${interface} -c \"sync eeprom all\""
+    fi
+
+    do_cmd "rmmod mt7996e"
+    do_cmd "rmmod mt76-connac-lib"
+    do_cmd "rmmod mt76"
+    do_cmd "rmmod mac80211"
+    do_cmd "rmmod cfg80211"
+    do_cmd "rmmod compat"
+    do_cmd "insmod compat"
+    do_cmd "insmod cfg80211"
+    do_cmd "insmod mac80211"
+    do_cmd "insmod mt76"
+    do_cmd "insmod mt76-connac-lib"
+    do_cmd "insmod mt7996e testmode_enable=${testmode_enable}"
+    do_cmd "sleep 5"
+    do_cmd "killall hostapd"
+    do_cmd "killall netifd"
 else
     echo "Unknown command"
 fi