blob: a9bcfab0955b83780b6c4ad1795427b742938ab7 [file] [log] [blame]
developer3abe1ad2022-01-24 11:13:32 +08001#!/bin/ash
2
developer071927d2022-08-31 20:39:29 +08003interface=$1 # phy0/phy1/ra0
developerf90c9af2022-12-28 22:40:23 +08004cmd_type=$2 # set/show/e2p/mac/dump
developer3abe1ad2022-01-24 11:13:32 +08005full_cmd=$3
developer9b7cdad2022-03-10 14:24:55 +08006interface_ori=${interface}
developerf90c9af2022-12-28 22:40:23 +08007SOC_start_idx="0"
developerb4b29472023-01-06 19:07:21 +08008SOC_end_idx="0"
developer6edd8a22023-08-01 15:47:43 +08009is_connac3="0"
developer3abe1ad2022-01-24 11:13:32 +080010
11work_mode="RUN" # RUN/PRINT/DEBUG
developer679a6aa2022-09-07 09:52:41 +080012iwpriv_file="/tmp/iwpriv_wrapper"
13interface_file="/tmp/interface"
developer3abe1ad2022-01-24 11:13:32 +080014phy_idx=$(echo ${interface} | tr -dc '0-9')
15
developer3abe1ad2022-01-24 11:13:32 +080016function do_cmd() {
17 case ${work_mode} in
18 "RUN")
19 eval "$1"
20 ;;
21 "PRINT")
22 echo "$1"
23 ;;
24 "DEBUG")
developer3abe1ad2022-01-24 11:13:32 +080025 echo "$1"
developer887da632022-10-28 09:35:38 +080026 eval "$1"
developer3abe1ad2022-01-24 11:13:32 +080027 ;;
28 esac
29}
30
developer9b7cdad2022-03-10 14:24:55 +080031function print_debug() {
32 if [ "${work_mode}" = "DEBUG" ]; then
33 echo "$1"
34 fi
35}
36
developer10946c32022-03-04 18:28:43 +080037function write_dmesg() {
38 echo "$1" > /dev/kmsg
39}
40
developer3abe1ad2022-01-24 11:13:32 +080041function record_config() {
developer679a6aa2022-09-07 09:52:41 +080042 local config=$1
43 local tmp_file=$3
44
developerf90c9af2022-12-28 22:40:23 +080045 # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
developerb4b29472023-01-06 19:07:21 +080046 if [ ${tmp_file} != ${interface_file} ]; then
developerf90c9af2022-12-28 22:40:23 +080047 if [ $phy_idx -lt $SOC_start_idx ]; then
developer679a6aa2022-09-07 09:52:41 +080048 config="${config}_PCIE"
developerf90c9af2022-12-28 22:40:23 +080049 elif [ $phy_idx -ge $SOC_start_idx ]; then
50 config="${config}_SOC"
developer679a6aa2022-09-07 09:52:41 +080051 fi
52 fi
53
developer3abe1ad2022-01-24 11:13:32 +080054 if [ -f ${tmp_file} ]; then
developer679a6aa2022-09-07 09:52:41 +080055 if grep -q ${config} ${tmp_file}; then
56 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
developer3abe1ad2022-01-24 11:13:32 +080057 else
developer679a6aa2022-09-07 09:52:41 +080058 echo "${config}=$2" >> ${tmp_file}
developer3abe1ad2022-01-24 11:13:32 +080059 fi
60 else
developer679a6aa2022-09-07 09:52:41 +080061 echo "${config}=$2" >> ${tmp_file}
developer3abe1ad2022-01-24 11:13:32 +080062 fi
63}
64
65function get_config() {
developer679a6aa2022-09-07 09:52:41 +080066 local config=$1
67 local tmp_file=$2
68
developer10946c32022-03-04 18:28:43 +080069 if [ ! -f ${tmp_file} ]; then
70 echo ""
71 return
72 fi
73
developerf90c9af2022-12-28 22:40:23 +080074 # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
developerb4b29472023-01-06 19:07:21 +080075 if [ ${tmp_file} != ${interface_file} ]; then
developerf90c9af2022-12-28 22:40:23 +080076 if [ $phy_idx -lt $SOC_start_idx ]; then
developer679a6aa2022-09-07 09:52:41 +080077 config="${config}_PCIE"
developerf90c9af2022-12-28 22:40:23 +080078 elif [ $phy_idx -ge $SOC_start_idx ]; then
79 config="${config}_SOC"
developer679a6aa2022-09-07 09:52:41 +080080 fi
81 fi
82
83 if grep -q ${config} ${tmp_file}; then
84 echo "$(cat ${tmp_file} | grep ${config} | sed s/=/' '/g | cut -d " " -f 2)"
developer10946c32022-03-04 18:28:43 +080085 else
86 echo ""
87 fi
developer3abe1ad2022-01-24 11:13:32 +080088}
89
developerb4b29472023-01-06 19:07:21 +080090function parse_sku {
developerf90c9af2022-12-28 22:40:23 +080091 SOC_start_idx=$(get_config "STARTIDX" ${interface_file})
developerb4b29472023-01-06 19:07:21 +080092 SOC_end_idx=$(get_config "ENDIDX" ${interface_file})
developer6edd8a22023-08-01 15:47:43 +080093 is_connac3=$(get_config "IS_CONNAC3" ${interface_file})
developer679a6aa2022-09-07 09:52:41 +080094 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
developer6edd8a22023-08-01 15:47:43 +080095 if [ -z "${SOC_start_idx}" ] || [ -z "${SOC_end_idx}" ] || [ -z "${is_connac3}" ]; then
developer679a6aa2022-09-07 09:52:41 +080096 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
developerf90c9af2022-12-28 22:40:23 +080097 SOC_start_idx="2"
developerb4b29472023-01-06 19:07:21 +080098 SOC_end_idx="3"
developer6edd8a22023-08-01 15:47:43 +080099 is_connac3="0"
developer679a6aa2022-09-07 09:52:41 +0800100 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
developerf90c9af2022-12-28 22:40:23 +0800101 SOC_start_idx="1"
developerb4b29472023-01-06 19:07:21 +0800102 SOC_end_idx="2"
developer6edd8a22023-08-01 15:47:43 +0800103 is_connac3="0"
developer36364002023-10-31 16:53:21 +0800104 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7981")" ]; then
105 SOC_start_idx="0"
106 SOC_end_idx="1"
107 is_connac3="0"
developer679a6aa2022-09-07 09:52:41 +0800108 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
developerf90c9af2022-12-28 22:40:23 +0800109 SOC_start_idx="0"
developerb4b29472023-01-06 19:07:21 +0800110 SOC_end_idx="1"
developer6edd8a22023-08-01 15:47:43 +0800111 is_connac3="0"
developerf90c9af2022-12-28 22:40:23 +0800112 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then
113 SOC_start_idx="0"
developerb4b29472023-01-06 19:07:21 +0800114 SOC_end_idx="2"
developer6edd8a22023-08-01 15:47:43 +0800115 is_connac3="1"
116 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7992")" ]; then
117 SOC_start_idx="0"
118 SOC_end_idx="1"
119 is_connac3="1"
developereebce5c2022-08-26 19:05:56 +0800120 else
developer679a6aa2022-09-07 09:52:41 +0800121 echo "Interface Conversion Failed!"
122 echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
developer36364002023-10-31 16:53:21 +0800123 echo "For AX3000/AX6000:"
developerb4b29472023-01-06 19:07:21 +0800124 echo " echo STARTIDX=0 >> ${interface_file}"
125 echo " echo ENDIDX=1 >> ${interface_file}"
developer6edd8a22023-08-01 15:47:43 +0800126 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developerb4b29472023-01-06 19:07:21 +0800127 echo "For AX7800:"
128 echo " echo STARTIDX=2 >> ${interface_file}"
129 echo " echo ENDIDX=3 >> ${interface_file}"
developer6edd8a22023-08-01 15:47:43 +0800130 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developerb4b29472023-01-06 19:07:21 +0800131 echo "For AX8400:"
132 echo " echo STARTIDX=1 >> ${interface_file}"
133 echo " echo ENDIDX=2 >> ${interface_file}"
developer6edd8a22023-08-01 15:47:43 +0800134 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developerb4b29472023-01-06 19:07:21 +0800135 echo "For Eagle:"
developer6edd8a22023-08-01 15:47:43 +0800136 echo " echo STARTIDX=0 >> ${interface_file}"
developerb4b29472023-01-06 19:07:21 +0800137 echo " echo ENDIDX=2 >> ${interface_file}"
developer6edd8a22023-08-01 15:47:43 +0800138 echo " echo IS_CONNAC3=1 >> ${interface_file}"
139 echo "For Kite:"
140 echo " echo STARTIDX=0 >> ${interface_file}"
141 echo " echo ENDIDX=1 >> ${interface_file}"
142 echo " echo IS_CONNAC3=1 >> ${interface_file}"
developer679a6aa2022-09-07 09:52:41 +0800143 exit 0
developereebce5c2022-08-26 19:05:56 +0800144 fi
developerf90c9af2022-12-28 22:40:23 +0800145 record_config "STARTIDX" ${SOC_start_idx} ${interface_file}
developerb4b29472023-01-06 19:07:21 +0800146 record_config "ENDIDX" ${SOC_end_idx} ${interface_file}
developer6edd8a22023-08-01 15:47:43 +0800147 record_config "IS_CONNAC3" ${is_connac3} ${interface_file}
developereebce5c2022-08-26 19:05:56 +0800148 fi
developerb4b29472023-01-06 19:07:21 +0800149}
developer679a6aa2022-09-07 09:52:41 +0800150
developerb4b29472023-01-06 19:07:21 +0800151function convert_interface {
developer6edd8a22023-08-01 15:47:43 +0800152 if [ ${is_connac3} == "0" ]; then
developer679a6aa2022-09-07 09:52:41 +0800153 if [[ $1 == "raix"* ]]; then
developerf90c9af2022-12-28 22:40:23 +0800154 phy_idx=1
155 elif [[ $1 == "rai"* ]]; then
developer679a6aa2022-09-07 09:52:41 +0800156 phy_idx=0
157 elif [[ $1 == "rax"* ]]; then
developerf90c9af2022-12-28 22:40:23 +0800158 phy_idx=$((SOC_start_idx+1))
159 else
160 phy_idx=$SOC_start_idx
developer679a6aa2022-09-07 09:52:41 +0800161 fi
developerf90c9af2022-12-28 22:40:23 +0800162
163 # convert phy index according to band idx
164 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
165 if [ "${band_idx}" = "0" ]; then
166 if [[ $1 == "raix"* ]]; then
167 phy_idx=0
168 elif [[ $1 == "rax"* ]]; then
169 phy_idx=$SOC_start_idx
170 fi
171 elif [ "${band_idx}" = "1" ]; then
172 if [[ $1 == "rai"* ]]; then
173 # AX8400: mt7915 remain phy0
174 # AX7800: mt7916 becomes phy1
175 phy_idx=$((SOC_start_idx-1))
176 elif [[ $1 == "ra"* ]]; then
177 phy_idx=$((SOC_start_idx+1))
178 fi
179 fi
180 else
181 # Eagle has different mapping method
182 # phy0: ra0
183 # phy1: rai0
184 # phy2: rax0
developer679a6aa2022-09-07 09:52:41 +0800185 if [[ $1 == "rai"* ]]; then
developerf90c9af2022-12-28 22:40:23 +0800186 phy_idx=1
187 elif [[ $1 == "rax"* ]]; then
188 phy_idx=2
189 else
190 phy_idx=0
developer679a6aa2022-09-07 09:52:41 +0800191 fi
192 fi
193
194 interface="phy${phy_idx}"
195}
196
197function change_band_idx {
198 local new_idx=$1
199 local new_phy_idx=$phy_idx
200
201 local old_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
202
203
204 if [[ ${interface_ori} == "ra"* ]]; then
205 if [ -z "${old_idx}" ] || [ "${old_idx}" != "${new_idx}" ]; then
206 if [ "${new_idx}" = "0" ]; then
207 # raix0 & rai0 becomes rai0
208 if [[ $interface_ori == "rai"* ]]; then
209 new_phy_idx=0
210 # rax0 & ra0 becomes ra0
211 elif [[ $interface_ori == "ra"* ]]; then
developerf90c9af2022-12-28 22:40:23 +0800212 new_phy_idx=$SOC_start_idx
developer679a6aa2022-09-07 09:52:41 +0800213 fi
214 elif [ "${new_idx}" = "1" ]; then
215 # raix0 & rai0 becomes raix0
216 if [[ $interface_ori == "rai"* ]]; then
developer1346ce52022-12-15 21:36:14 +0800217 # For AX8400 => don't change phy idx
developerf90c9af2022-12-28 22:40:23 +0800218 if [ ${SOC_start_idx} != "1" ]; then
developer1346ce52022-12-15 21:36:14 +0800219 new_phy_idx=1
220 fi
developer679a6aa2022-09-07 09:52:41 +0800221 # rax0 & ra0 becomes rax0
222 elif [[ $interface_ori == "ra"* ]]; then
developerf90c9af2022-12-28 22:40:23 +0800223 new_phy_idx=$((SOC_start_idx+1))
developer679a6aa2022-09-07 09:52:41 +0800224 fi
225 fi
226 fi
227
228 if [ ${new_phy_idx} != ${phy_idx} ]; then
229 do_ate_work "ATESTOP"
230 phy_idx=$new_phy_idx
231 interface="phy${phy_idx}"
232 do_ate_work "ATESTART"
233 fi
developereebce5c2022-08-26 19:05:56 +0800234 fi
developer679a6aa2022-09-07 09:52:41 +0800235 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
developereebce5c2022-08-26 19:05:56 +0800236}
237
developer3abe1ad2022-01-24 11:13:32 +0800238function simple_convert() {
239 if [ "$1" = "ATETXCNT" ]; then
240 echo "tx_count"
241 elif [ "$1" = "ATETXLEN" ]; then
242 echo "tx_length"
243 elif [ "$1" = "ATETXMCS" ]; then
244 echo "tx_rate_idx"
245 elif [ "$1" = "ATEVHTNSS" ]; then
246 echo "tx_rate_nss"
247 elif [ "$1" = "ATETXLDPC" ]; then
248 echo "tx_rate_ldpc"
249 elif [ "$1" = "ATETXSTBC" ]; then
250 echo "tx_rate_stbc"
251 elif [ "$1" = "ATEPKTTXTIME" ]; then
252 echo "tx_time"
253 elif [ "$1" = "ATEIPG" ]; then
254 echo "tx_ipg"
255 elif [ "$1" = "ATEDUTYCYCLE" ]; then
256 echo "tx_duty_cycle"
257 elif [ "$1" = "ATETXFREQOFFSET" ]; then
258 echo "freq_offset"
259 else
developer679a6aa2022-09-07 09:52:41 +0800260 echo "undefined"
developer3abe1ad2022-01-24 11:13:32 +0800261 fi
262}
263
264function convert_tx_mode() {
developer1346ce52022-12-15 21:36:14 +0800265 # Remove leading zeros
developer4feb1012023-01-30 17:29:07 +0800266 local tx_mode=$(echo $1 | sed -r 's/0+([0-9]+)/\1/g')
developer1346ce52022-12-15 21:36:14 +0800267
268 if [ "$tx_mode" = "0" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800269 echo "cck"
developer1346ce52022-12-15 21:36:14 +0800270 elif [ "$tx_mode" = "1" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800271 echo "ofdm"
developer1346ce52022-12-15 21:36:14 +0800272 elif [ "$tx_mode" = "2" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800273 echo "ht"
developer1346ce52022-12-15 21:36:14 +0800274 elif [ "$tx_mode" = "4" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800275 echo "vht"
developer1346ce52022-12-15 21:36:14 +0800276 elif [ "$tx_mode" = "8" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800277 echo "he_su"
developer1346ce52022-12-15 21:36:14 +0800278 elif [ "$tx_mode" = "9" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800279 echo "he_er"
developer1346ce52022-12-15 21:36:14 +0800280 elif [ "$tx_mode" = "10" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800281 echo "he_tb"
developer1346ce52022-12-15 21:36:14 +0800282 elif [ "$tx_mode" = "11" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800283 echo "he_mu"
developercec48ac2023-03-01 17:00:33 +0800284 elif [ "$tx_mode" = "13" ]; then
285 echo "eht_su"
286 elif [ "$tx_mode" = "14" ]; then
287 echo "eht_tb"
288 elif [ "$tx_mode" = "15" ]; then
289 echo "eht_mu"
developer3abe1ad2022-01-24 11:13:32 +0800290 else
developer679a6aa2022-09-07 09:52:41 +0800291 echo "undefined"
developer3abe1ad2022-01-24 11:13:32 +0800292 fi
293}
294
295function convert_gi {
296 local tx_mode=$1
297 local val=$2
298 local sgi="0"
299 local he_ltf="0"
300
301 case ${tx_mode} in
302 "ht"|"vht")
303 sgi=${val}
304 ;;
305 "he_su"|"he_er")
306 case ${val} in
307 "0")
308 ;;
309 "1")
310 he_ltf="1"
311 ;;
312 "2")
313 sgi="1"
314 he_ltf="1"
315 ;;
316 "3")
317 sgi="2"
318 he_ltf="2"
319 ;;
320 "4")
321 he_ltf="2"
322 ;;
323 *)
324 echo "unknown gi"
325 esac
326 ;;
327 "he_mu")
328 case ${val} in
329 "0")
330 he_ltf="2"
331 ;;
332 "1")
333 he_ltf="1"
334 ;;
335 "2")
336 sgi="1"
337 he_ltf="1"
338 ;;
339 "3")
340 sgi="2"
341 he_ltf="2"
342 ;;
343 *)
344 echo "unknown gi"
345 esac
346 ;;
347 "he_tb")
348 case ${val} in
349 "0")
350 sgi="1"
351 ;;
352 "1")
353 sgi="1"
354 he_ltf="1"
355 ;;
356 "2")
357 sgi="2"
358 he_ltf="2"
359 ;;
360 *)
361 echo "unknown gi"
362 esac
363 ;;
364 *)
developer9b7cdad2022-03-10 14:24:55 +0800365 print_debug "legacy mode no need gi"
developer3abe1ad2022-01-24 11:13:32 +0800366 esac
367
368 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
369}
370
371function convert_channel {
developer679a6aa2022-09-07 09:52:41 +0800372 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
developer3abe1ad2022-01-24 11:13:32 +0800373 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
developer679a6aa2022-09-07 09:52:41 +0800374 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
developer10946c32022-03-04 18:28:43 +0800375 local bw_str="HT20"
developereebce5c2022-08-26 19:05:56 +0800376 local base_chan=1
377 local control_freq=0
378 local base_freq=0
developer1346ce52022-12-15 21:36:14 +0800379 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
380 local temp=$((phy_idx+1))
developer3abe1ad2022-01-24 11:13:32 +0800381
developer1346ce52022-12-15 21:36:14 +0800382 # Handle ATECTRLBANDIDX
383 if [ ! -z ${ctrl_band_idx} ]; then
384 if [ "${ctrl_band_idx}" == "1" ] && [ ${band} == "0" ]; then
385 local temp=$(cat "/etc/config/wireless"| grep "option band" | sed -n ${temp}p | cut -c 15)
386 if [ "${temp}" == "2" ]; then
387 local band=0
388 elif [ "${temp}" == "5" ]; then
389 local band=1
390 elif [ "${temp}" == "6" ]; then
391 local band=2
392 else
393 echo "iwpriv wrapper band translate error!"
394 fi
395 else
396 # mt7915 in AX8400 case: band should be determined by only the input band
developerf90c9af2022-12-28 22:40:23 +0800397 if [ "${SOC_start_idx}" == "1" ] && [ ${phy_idx} == "0" ]; then
developer1346ce52022-12-15 21:36:14 +0800398 local band=$((band))
399 else
400 local band=$((ctrl_band_idx * band))
401 fi
402 fi
developer679a6aa2022-09-07 09:52:41 +0800403 fi
404
developer9b7cdad2022-03-10 14:24:55 +0800405 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800406 case ${bw} in
407 "1")
developer461cb542022-04-29 18:17:44 +0800408 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
409 local bw_str="HT20"
developer3abe1ad2022-01-24 11:13:32 +0800410 else
developer461cb542022-04-29 18:17:44 +0800411 local bw_str="HT40+"
412 ch=$(expr ${ch} - "2")
developer3abe1ad2022-01-24 11:13:32 +0800413 fi
414 ;;
developer3abe1ad2022-01-24 11:13:32 +0800415 esac
developereebce5c2022-08-26 19:05:56 +0800416 local base_freq=2412
developera6267142022-01-26 20:50:22 +0800417 elif [ "${band}" = "1" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800418 case ${bw} in
developera6267142022-01-26 20:50:22 +0800419 "5")
developer10946c32022-03-04 18:28:43 +0800420 bw_str="160MHz"
421 if [ ${ch} -lt "68" ]; then
422 ch="36"
423 elif [ ${ch} -lt "100" ]; then
424 ch="68"
425 elif [ ${ch} -lt "132" ]; then
426 ch="100"
427 elif [ ${ch} -lt "181" ]; then
428 ch="149"
429 fi
developera6267142022-01-26 20:50:22 +0800430 ;;
developer3abe1ad2022-01-24 11:13:32 +0800431 "2")
developer10946c32022-03-04 18:28:43 +0800432 bw_str="80MHz"
433 if [ ${ch} -lt "52" ]; then
434 ch="36"
435 elif [ ${ch} -lt "68" ]; then
436 ch="52"
437 elif [ ${ch} -lt "84" ]; then
438 ch="68"
439 elif [ ${ch} -lt "100" ]; then
440 ch="84"
441 elif [ ${ch} -lt "116" ]; then
442 ch="100"
443 elif [ ${ch} -lt "132" ]; then
444 ch="116"
445 elif [ ${ch} -lt "149" ]; then
446 ch="132"
447 elif [ ${ch} -lt "165" ]; then
448 ch="149"
449 elif [ ${ch} -lt "181" ]; then
450 ch="165"
451 fi
developer3abe1ad2022-01-24 11:13:32 +0800452 ;;
453 "1")
developer10946c32022-03-04 18:28:43 +0800454 if [ ${ch} -lt "44" ]; then
455 ch=$([ "${ch}" -lt "40" ] && echo "36" || echo "40")
456 bw_str=$([ "${ch}" -le "38" ] && echo "HT40+" || echo "HT40-")
457 elif [ ${ch} -lt "52" ]; then
458 ch=$([ "${ch}" -lt "48" ] && echo "44" || echo "48")
459 bw_str=$([ "${ch}" -le "46" ] && echo "HT40+" || echo "HT40-")
460 elif [ ${ch} -lt "60" ]; then
461 ch=$([ "${ch}" -lt "56" ] && echo "52" || echo "56")
462 bw_str=$([ "${ch}" -le "54" ] && echo "HT40+" || echo "HT40-")
463 elif [ ${ch} -lt "68" ]; then
464 ch=$([ "${ch}" -lt "64" ] && echo "60" || echo "64")
465 bw_str=$([ "${ch}" -le "62" ] && echo "HT40+" || echo "HT40-")
466 elif [ ${ch} -lt "76" ]; then
467 ch=$([ "${ch}" -lt "72" ] && echo "68" || echo "72")
468 bw_str=$([ "${ch}" -le "70" ] && echo "HT40+" || echo "HT40-")
469 elif [ ${ch} -lt "84" ]; then
470 ch=$([ "${ch}" -lt "80" ] && echo "76" || echo "80")
471 bw_str=$([ "${ch}" -le "78" ] && echo "HT40+" || echo "HT40-")
472 elif [ ${ch} -lt "92" ]; then
473 ch=$([ "${ch}" -lt "88" ] && echo "84" || echo "88")
474 bw_str=$([ "${ch}" -le "86" ] && echo "HT40+" || echo "HT40-")
475 elif [ ${ch} -lt "100" ]; then
476 ch=$([ "${ch}" -lt "96" ] && echo "92" || echo "96")
477 bw_str=$([ "${ch}" -le "94" ] && echo "HT40+" || echo "HT40-")
478 elif [ ${ch} -lt "108" ]; then
479 ch=$([ "${ch}" -lt "104" ] && echo "100" || echo "104")
480 bw_str=$([ "${ch}" -le "102" ] && echo "HT40+" || echo "HT40-")
481 elif [ ${ch} -lt "116" ]; then
482 ch=$([ "${ch}" -lt "112" ] && echo "108" || echo "112")
483 bw_str=$([ "${ch}" -le "110" ] && echo "HT40+" || echo "HT40-")
484 elif [ ${ch} -lt "124" ]; then
485 ch=$([ "${ch}" -lt "120" ] && echo "116" || echo "120")
486 bw_str=$([ "${ch}" -le "118" ] && echo "HT40+" || echo "HT40-")
487 elif [ ${ch} -lt "132" ]; then
488 ch=$([ "${ch}" -lt "128" ] && echo "124" || echo "128")
489 bw_str=$([ "${ch}" -le "126" ] && echo "HT40+" || echo "HT40-")
490 elif [ ${ch} -lt "140" ]; then
491 ch=$([ "${ch}" -lt "136" ] && echo "132" || echo "136")
492 bw_str=$([ "${ch}" -le "134" ] && echo "HT40+" || echo "HT40-")
493 elif [ ${ch} -lt "149" ]; then
494 ch=$([ "${ch}" -lt "144" ] && echo "140" || echo "144")
495 bw_str=$([ "${ch}" -le "142" ] && echo "HT40+" || echo "HT40-")
496 elif [ ${ch} -lt "157" ]; then
497 ch=$([ "${ch}" -lt "153" ] && echo "149" || echo "153")
498 bw_str=$([ "${ch}" -le "151" ] && echo "HT40+" || echo "HT40-")
499 elif [ ${ch} -lt "165" ]; then
500 ch=$([ "${ch}" -lt "161" ] && echo "157" || echo "161")
501 bw_str=$([ "${ch}" -le "159" ] && echo "HT40+" || echo "HT40-")
502 elif [ ${ch} -lt "173" ]; then
503 ch=$([ "${ch}" -lt "169" ] && echo "165" || echo "169")
504 bw_str=$([ "${ch}" -le "167" ] && echo "HT40+" || echo "HT40-")
505 elif [ ${ch} -lt "181" ]; then
506 ch=$([ "${ch}" -lt "177" ] && echo "173" || echo "177")
507 bw_str=$([ "${ch}" -le "175" ] && echo "HT40+" || echo "HT40-")
developer3abe1ad2022-01-24 11:13:32 +0800508 fi
509 ;;
510 "0")
511 local bw_str="HT20"
512 ;;
513 esac
developereebce5c2022-08-26 19:05:56 +0800514 local base_freq=5180
515 local base_chan=36
developera6267142022-01-26 20:50:22 +0800516 else
developercec48ac2023-03-01 17:00:33 +0800517 local base_freq=5955
developereebce5c2022-08-26 19:05:56 +0800518 case ${bw} in
developercec48ac2023-03-01 17:00:33 +0800519 "12")
520 local bw_str="320"
521 if [ ${ch} == "31" ]; then
522 local control_freq="5955"
523 elif [ ${ch} == "63" ]; then
524 local control_freq="6115"
525 elif [ ${ch} == "95" ]; then
526 local control_freq="6275"
527 elif [ ${ch} == "127" ]; then
528 local control_freq="6435"
529 elif [ ${ch} == "159" ]; then
530 local control_freq="6595"
531 elif [ ${ch} == "191" ]; then
532 local control_freq="6755"
533 fi
534 local center_freq=$(((ch - base_chan) * 5 + base_freq))
535 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str} ${center_freq}"
536 return
537 ;;
developereebce5c2022-08-26 19:05:56 +0800538 "5")
539 bw_str="160MHz"
540 if [ ${ch} -lt "33" ]; then
541 ch="1"
542 elif [ ${ch} -lt "65" ]; then
543 ch="33"
544 elif [ ${ch} -lt "97" ]; then
545 ch="65"
546 elif [ ${ch} -lt "129" ]; then
547 ch="97"
548 elif [ ${ch} -lt "161" ]; then
549 ch="129"
550 elif [ ${ch} -lt "193" ]; then
551 ch="161"
552 elif [ ${ch} -lt "225" ]; then
553 ch="193"
554 fi
555 ;;
556 "2")
557 bw_str="80MHz"
558 if [ ${ch} -lt "17" ]; then
559 ch="1"
560 elif [ ${ch} -lt "33" ]; then
561 ch="17"
562 elif [ ${ch} -lt "49" ]; then
563 ch="33"
564 elif [ ${ch} -lt "65" ]; then
565 ch="49"
566 elif [ ${ch} -lt "81" ]; then
567 ch="65"
568 elif [ ${ch} -lt "97" ]; then
569 ch="81"
570 elif [ ${ch} -lt "113" ]; then
571 ch="97"
572 elif [ ${ch} -lt "129" ]; then
573 ch="113"
574 elif [ ${ch} -lt "145" ]; then
575 ch="129"
576 elif [ ${ch} -lt "161" ]; then
577 ch="145"
578 elif [ ${ch} -lt "177" ]; then
579 ch="161"
580 elif [ ${ch} -lt "193" ]; then
581 ch="177"
582 elif [ ${ch} -lt "209" ]; then
583 ch="193"
584 elif [ ${ch} -lt "225" ]; then
585 ch="209"
586 fi
587 ;;
588 "1")
589 if [ ${ch} -lt "9" ]; then
590 ch=$([ "${ch}" -lt "5" ] && echo "1" || echo "5")
591 bw_str=$([ "${ch}" -le "3" ] && echo "HT40+" || echo "HT40-")
592 elif [ ${ch} -lt "17" ]; then
593 ch=$([ "${ch}" -lt "13" ] && echo "9" || echo "13")
594 bw_str=$([ "${ch}" -le "11" ] && echo "HT40+" || echo "HT40-")
595 elif [ ${ch} -lt "25" ]; then
596 ch=$([ "${ch}" -lt "21" ] && echo "17" || echo "21")
597 bw_str=$([ "${ch}" -le "19" ] && echo "HT40+" || echo "HT40-")
598 elif [ ${ch} -lt "33" ]; then
599 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
600 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
601 elif [ ${ch} -lt "33" ]; then
602 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
603 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
604 elif [ ${ch} -lt "41" ]; then
605 ch=$([ "${ch}" -lt "37" ] && echo "33" || echo "37")
606 bw_str=$([ "${ch}" -le "35" ] && echo "HT40+" || echo "HT40-")
607 elif [ ${ch} -lt "49" ]; then
608 ch=$([ "${ch}" -lt "45" ] && echo "41" || echo "45")
609 bw_str=$([ "${ch}" -le "43" ] && echo "HT40+" || echo "HT40-")
610 elif [ ${ch} -lt "57" ]; then
611 ch=$([ "${ch}" -lt "53" ] && echo "49" || echo "53")
612 bw_str=$([ "${ch}" -le "51" ] && echo "HT40+" || echo "HT40-")
613 elif [ ${ch} -lt "65" ]; then
614 ch=$([ "${ch}" -lt "61" ] && echo "57" || echo "61")
615 bw_str=$([ "${ch}" -le "59" ] && echo "HT40+" || echo "HT40-")
616 elif [ ${ch} -lt "73" ]; then
617 ch=$([ "${ch}" -lt "69" ] && echo "65" || echo "69")
618 bw_str=$([ "${ch}" -le "67" ] && echo "HT40+" || echo "HT40-")
619 elif [ ${ch} -lt "81" ]; then
620 ch=$([ "${ch}" -lt "77" ] && echo "73" || echo "77")
621 bw_str=$([ "${ch}" -le "75" ] && echo "HT40+" || echo "HT40-")
622 elif [ ${ch} -lt "89" ]; then
623 ch=$([ "${ch}" -lt "85" ] && echo "81" || echo "85")
624 bw_str=$([ "${ch}" -le "83" ] && echo "HT40+" || echo "HT40-")
625 elif [ ${ch} -lt "97" ]; then
626 ch=$([ "${ch}" -lt "93" ] && echo "89" || echo "93")
627 bw_str=$([ "${ch}" -le "91" ] && echo "HT40+" || echo "HT40-")
628 elif [ ${ch} -lt "105" ]; then
629 ch=$([ "${ch}" -lt "101" ] && echo "97" || echo "101")
630 bw_str=$([ "${ch}" -le "99" ] && echo "HT40+" || echo "HT40-")
631 elif [ ${ch} -lt "113" ]; then
632 ch=$([ "${ch}" -lt "109" ] && echo "105" || echo "109")
633 bw_str=$([ "${ch}" -le "107" ] && echo "HT40+" || echo "HT40-")
634 elif [ ${ch} -lt "121" ]; then
635 ch=$([ "${ch}" -lt "117" ] && echo "113" || echo "117")
636 bw_str=$([ "${ch}" -le "115" ] && echo "HT40+" || echo "HT40-")
637 elif [ ${ch} -lt "129" ]; then
638 ch=$([ "${ch}" -lt "125" ] && echo "121" || echo "125")
639 bw_str=$([ "${ch}" -le "123" ] && echo "HT40+" || echo "HT40-")
640 elif [ ${ch} -lt "137" ]; then
641 ch=$([ "${ch}" -lt "133" ] && echo "129" || echo "133")
642 bw_str=$([ "${ch}" -le "131" ] && echo "HT40+" || echo "HT40-")
643 elif [ ${ch} -lt "145" ]; then
644 ch=$([ "${ch}" -lt "141" ] && echo "137" || echo "141")
645 bw_str=$([ "${ch}" -le "139" ] && echo "HT40+" || echo "HT40-")
646 elif [ ${ch} -lt "153" ]; then
647 ch=$([ "${ch}" -lt "149" ] && echo "145" || echo "149")
648 bw_str=$([ "${ch}" -le "147" ] && echo "HT40+" || echo "HT40-")
649 elif [ ${ch} -lt "161" ]; then
650 ch=$([ "${ch}" -lt "157" ] && echo "153" || echo "157")
651 bw_str=$([ "${ch}" -le "155" ] && echo "HT40+" || echo "HT40-")
652 elif [ ${ch} -lt "169" ]; then
653 ch=$([ "${ch}" -lt "165" ] && echo "161" || echo "165")
654 bw_str=$([ "${ch}" -le "163" ] && echo "HT40+" || echo "HT40-")
655 elif [ ${ch} -lt "177" ]; then
656 ch=$([ "${ch}" -lt "173" ] && echo "169" || echo "173")
657 bw_str=$([ "${ch}" -le "171" ] && echo "HT40+" || echo "HT40-")
658 elif [ ${ch} -lt "185" ]; then
659 ch=$([ "${ch}" -lt "181" ] && echo "177" || echo "181")
660 bw_str=$([ "${ch}" -le "179" ] && echo "HT40+" || echo "HT40-")
661 elif [ ${ch} -lt "193" ]; then
662 ch=$([ "${ch}" -lt "189" ] && echo "185" || echo "189")
663 bw_str=$([ "${ch}" -le "187" ] && echo "HT40+" || echo "HT40-")
664 elif [ ${ch} -lt "201" ]; then
665 ch=$([ "${ch}" -lt "197" ] && echo "193" || echo "197")
666 bw_str=$([ "${ch}" -le "195" ] && echo "HT40+" || echo "HT40-")
667 elif [ ${ch} -lt "209" ]; then
668 ch=$([ "${ch}" -lt "205" ] && echo "201" || echo "205")
669 bw_str=$([ "${ch}" -le "203" ] && echo "HT40+" || echo "HT40-")
670 elif [ ${ch} -lt "217" ]; then
671 ch=$([ "${ch}" -lt "213" ] && echo "209" || echo "213")
672 bw_str=$([ "${ch}" -le "211" ] && echo "HT40+" || echo "HT40-")
673 elif [ ${ch} -lt "225" ]; then
674 ch=$([ "${ch}" -lt "221" ] && echo "217" || echo "221")
675 bw_str=$([ "${ch}" -le "219" ] && echo "HT40+" || echo "HT40-")
676 elif [ ${ch} -lt "233" ]; then
677 ch=$([ "${ch}" -lt "229" ] && echo "225" || echo "229")
678 bw_str=$([ "${ch}" -le "227" ] && echo "HT40+" || echo "HT40-")
679 fi
680 ;;
681 "0")
682 local bw_str="HT20"
683 ;;
684 esac
developer3abe1ad2022-01-24 11:13:32 +0800685 fi
686
developereebce5c2022-08-26 19:05:56 +0800687 local control_freq=$(((ch - base_chan) * 5 + base_freq))
688 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
developer3abe1ad2022-01-24 11:13:32 +0800689}
690
developer10946c32022-03-04 18:28:43 +0800691function convert_rxstat {
692 local res=$(do_cmd "mt76-test ${interface} dump stats")
693 local mdrdy=$(echo "${res}" | grep "rx_packets" | cut -d "=" -f 2)
694 local fcs_error=$(echo "${res}" | grep "rx_fcs_error" | cut -d "=" -f 2)
695 local rcpi=$(echo "${res}" | grep "last_rcpi" | cut -d "=" -f 2 | sed 's/,/ /g')
696 local ib_rssi=$(echo "${res}" | grep "last_ib_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
697 local wb_rssi=$(echo "${res}" | grep "last_wb_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
698 local rx_ok=$(expr ${mdrdy} - ${fcs_error})
699
developer461cb542022-04-29 18:17:44 +0800700 write_dmesg "rcpi: ${rcpi}"
701 write_dmesg "fagc rssi ib: ${ib_rssi}"
702 write_dmesg "fagc rssi wb: ${wb_rssi}"
703 write_dmesg "all_mac_rx_mdrdy_cnt: ${mdrdy}"
704 write_dmesg "all_mac_rx_fcs_err_cnt: ${fcs_error}"
developer9b7cdad2022-03-10 14:24:55 +0800705 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
developer10946c32022-03-04 18:28:43 +0800706}
707
developer10946c32022-03-04 18:28:43 +0800708function set_mac_addr {
developer679a6aa2022-09-07 09:52:41 +0800709 record_config ${cmd} ${param} ${iwpriv_file}
developer10946c32022-03-04 18:28:43 +0800710
developer679a6aa2022-09-07 09:52:41 +0800711 local addr1=$(get_config "ATEDA" ${iwpriv_file})
712 local addr2=$(get_config "ATESA" ${iwpriv_file})
713 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
developer10946c32022-03-04 18:28:43 +0800714
715 if [ -z "${addr1}" ]; then
716 addr1="00:11:22:33:44:55"
717 fi
718 if [ -z "${addr2}" ]; then
719 addr2="00:11:22:33:44:55"
720 fi
721 if [ -z "${addr3}" ]; then
722 addr3="00:11:22:33:44:55"
723 fi
724
725 do_cmd "mt76-test phy${phy_idx} set mac_addrs=${addr1},${addr2},${addr3}"
726}
727
developerf9843e22022-09-13 10:57:15 +0800728function convert_ibf {
729 local cmd=$1
730 local param=$2
731 local new_cmd=""
732 local new_param=$(echo ${param} | sed s/":"/","/g)
733
734 case ${cmd} in
735 "ATETxBfInit")
736 new_cmd="init"
developer1346ce52022-12-15 21:36:14 +0800737 new_param="1"
738 do_cmd "mt76-test phy${phy_idx} set state=idle"
739 ;;
740 "ATETxBfGdInit")
741 new_cmd="golden_init"
742 new_param="1"
developerf9843e22022-09-13 10:57:15 +0800743 do_cmd "mt76-test phy${phy_idx} set state=idle"
744 ;;
745 "ATEIBFPhaseComp")
746 new_cmd="phase_comp"
developer1346ce52022-12-15 21:36:14 +0800747 new_param="${new_param}"
developerf9843e22022-09-13 10:57:15 +0800748 ;;
749 "ATEEBfProfileConfig")
750 new_cmd="ebf_prof_update"
751 ;;
752 "ATEIBfProfileConfig")
753 new_cmd="ibf_prof_update"
754 ;;
755 "ATEIBfInstCal")
756 new_cmd="phase_cal"
757 ;;
758 "ATEIBfGdCal")
759 new_cmd="phase_cal"
760 new_param="${new_param},00"
761 ;;
762 "TxBfTxApply")
763 new_cmd="apply_tx"
764 ;;
765 "ATETxPacketWithBf")
766 local bf_on=${new_param:0:2}
767 local aid="01"
768 local wlan_idx=${new_param:3:2}
769 local update="00"
770 local tx_len=${new_param:6}
771
772 new_cmd="tx_prep"
773 new_param="${bf_on},${aid},${wlan_idx},${update}"
774 if [ "${tx_len}" = "00" ]; then
775 new_param="${new_param} aid=1 tx_count=10000000 tx_length=1024"
776 else
777 new_param="${new_param} aid=1 tx_count=${tx_len} tx_length=1024"
778 fi
779 do_cmd "mt76-test phy${phy_idx} set state=idle"
780 ;;
781 "TxBfProfileData20MAllWrite")
782 new_cmd="prof_update_all"
783 ;;
784 "ATEIBFPhaseE2pUpdate")
785 new_cmd="e2p_update"
786 ;;
developer1346ce52022-12-15 21:36:14 +0800787 "ATEIBFPhaseVerify")
788 local group=${new_param:0:2}
789 local group_l_m_h=${new_param:3:2}
790 local band_idx=${new_param:6:2}
791 local phase_cal_type=${new_param:9:2}
792 local LNA_gain_level=${new_param:12:2}
793 local read_from_e2p=${new_param:15:2}
794
795 do_cmd "mt76-test phy${phy_idx} set txbf_act=phase_comp txbf_param=1,${band_idx},${group},${read_from_e2p},0"
796 new_cmd="phase_cal"
797 new_param="${group},${group_l_m_h},${band_idx},${phase_cal_type},${LNA_gain_level}"
798 ;;
799 "TxBfProfileTagRead")
800 new_cmd="pfmu_tag_read"
801 ;;
802 "TxBfProfileTagWrite")
803 new_cmd="pfmu_tag_write"
804 ;;
805 "TxBfProfileTagInValid")
806 new_cmd="set_invalid_prof"
807 ;;
808 "StaRecBfRead")
809 new_cmd="sta_rec_read"
810 ;;
811 "TriggerSounding")
812 new_cmd="trigger_sounding"
813 ;;
814 "StopSounding")
815 new_cmd="stop_sounding"
816 new_param="0"
817 ;;
developer77215642023-05-15 13:52:35 +0800818 "TxBfTxCmd")
819 new_cmd="txcmd"
820 ;;
developer1346ce52022-12-15 21:36:14 +0800821 "ATEConTxETxBfGdProc")
822 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
823 local tx_rate_idx=${new_param:3:2}
824 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
825 local channel=${new_param:9:3}
826 local channel2=${new_param:13:3}
827 local band=${new_param:17}
828
829 new_cmd="ebf_golden_init"
830 do_ate_work "ATESTART"
831 do_cmd "mt76-test phy${phy_idx} set state=idle"
832 record_config "ATETXBW" ${bw} ${iwpriv_file}
833 convert_channel "${channel}:${band}"
834 if [ "${bw}" = "5" ]; then
835 new_param="1,1"
836 else
837 new_param="1,0"
838 fi
839 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_sgi=0"
840 ;;
841 "ATEConTxETxBfInitProc")
842 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
843 local tx_rate_idx=${new_param:3:2}
844 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
845 local tx_rate_nss=${new_param:9:2}
846 local tx_stream=${new_param:12:2}
847 local tx_power=${new_param:15:2}
developer77215642023-05-15 13:52:35 +0800848 local channel=$(echo ${new_param:18:3} | sed 's/^0//')
developer1346ce52022-12-15 21:36:14 +0800849 local channel2=${new_param:22:3}
850 local band=${new_param:26:1}
developer77215642023-05-15 13:52:35 +0800851 local tx_length=$(echo ${new_param:28:5} | sed 's/^0//')
developer1346ce52022-12-15 21:36:14 +0800852
853 new_cmd="ebf_init"
854 do_ate_work "ATESTART"
855 do_cmd "mt76-test phy${phy_idx} set state=idle"
856 record_config "ATETXBW" ${bw} ${iwpriv_file}
857 convert_channel "${channel}:${band}"
858 new_param="1"
859 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_nss=${tx_rate_nss} tx_rate_sgi=0 tx_rate_ldpc=1 tx_power=${tx_power},0,0,0 tx_count=10000000 tx_length=${tx_length} tx_ipg=4"
860 ;;
developerf9843e22022-09-13 10:57:15 +0800861 *)
862 esac
863
864 do_cmd "mt76-test phy${phy_idx} set txbf_act=${new_cmd} txbf_param=${new_param}"
865
866 if [ "${cmd}" = "ATETxPacketWithBf" ]; then
867 do_cmd "mt76-test phy${phy_idx} set state=tx_frames"
developer1346ce52022-12-15 21:36:14 +0800868 elif [ "${cmd}" = "ATEConTxETxBfInitProc" ]; then
developercec48ac2023-03-01 17:00:33 +0800869 local wlan_idx="1"
developer6edd8a22023-08-01 15:47:43 +0800870 if [ ${is_connac3} == "1" ]; then
developercec48ac2023-03-01 17:00:33 +0800871 local wlan_idx=$((phy_idx+1))
872 fi
developer1346ce52022-12-15 21:36:14 +0800873 do_cmd "mt76-test phy${phy_idx} set aid=1"
874 do_cmd "mt76-test phy${phy_idx} set txbf_act=stop_sounding txbf_param=1"
875 do_cmd "mt76-test phy${phy_idx} set txbf_act=update_ch txbf_param=1"
876 do_cmd "mt76-test phy${phy_idx} set txbf_act=ebf_prof_update txbf_param=0,0,0"
developercec48ac2023-03-01 17:00:33 +0800877 do_cmd "mt76-test phy${phy_idx} set txbf_act=apply_tx txbf_param=${wlan_idx},1,0,0,0"
developer6edd8a22023-08-01 15:47:43 +0800878 if [ ${is_connac3} == "1" ]; then
developercec48ac2023-03-01 17:00:33 +0800879 do_cmd "mt76-test phy${phy_idx} set txbf_act=txcmd txbf_param=1,1,1"
880 fi
developer1346ce52022-12-15 21:36:14 +0800881 do_cmd "mt76-test phy${phy_idx} set txbf_act=pfmu_tag_read txbf_param=0,1"
developercec48ac2023-03-01 17:00:33 +0800882 do_cmd "mt76-test phy${phy_idx} set txbf_act=sta_rec_read txbf_param=${wlan_idx}"
883 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=0,1,0,${wlan_idx},0,0,0"
884 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=2,1,ff,${wlan_idx},0,0,0"
developer1346ce52022-12-15 21:36:14 +0800885 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
886 elif [ "${cmd}" = "ATEConTxETxBfGdProc" ]; then
887 do_cmd "mt76-test phy${phy_idx} set aid=1"
888 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
889 elif [ "${cmd}" = "ATETxBfInit" ]; then
890 do_cmd "mt76-test phy${phy_idx} set aid=1"
891 elif [ "${cmd}" = "ATETxBfGdInit" ]; then
892 do_cmd "mt76-test phy${phy_idx} set aid=1"
developer44ae8e92023-07-21 13:42:14 +0800893 elif [ "${cmd}" = "ATEIBFPhaseE2pUpdate" ]; then
894 do_cmd "atenl -i phy${phy_idx} -c \"eeprom ibf sync\""
developerf9843e22022-09-13 10:57:15 +0800895 fi
896}
897
developer91af1042023-07-10 18:19:30 +0800898function convert_ruinfo {
899 local new_param=$1
900
901 do_cmd "mt76-test phy${phy_idx} set state=idle"
902 while [ -n "$new_param" ]
903 do
904 [ ${new_param:1:1} = ':' ] && {
905 new_param=${new_param:2}
906 }
907 local oIFS="$IFS"; IFS=":"; set -- $new_param; IFS="$oIFS"
908
909 parsing_ruinfo $new_param
910 new_param=${new_param:${#1}+1}
911 done
912}
913
914function parsing_ruinfo {
915 local new_param=$1
916 local oIFS="$IFS"; IFS="-:"; set -- $new_param; IFS="$oIFS"
917
918 # $7 is Start spatial stream and it should be 0, $9 is alpha, not used
919 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=he_mu tx_rate_sgi=0 tx_ltf=0 ru_alloc=$1 aid=$2 ru_idx=$3\
920 tx_rate_idx=$4 tx_rate_ldpc=$5 tx_rate_nss=$6 tx_length=$8"
921}
922
developer887da632022-10-28 09:35:38 +0800923function convert_dfs {
924 local cmd=$1
925 local param=$2
926
927 case ${cmd} in
928 "DfsRxCtrl")
929 local offchan_ch="$(echo $param | cut -d ':' -f1)"
930 local offchan_bw="$(echo $param | cut -d ':' -f2)"
931
developer9f846582023-03-31 17:51:46 +0800932 if [ "$offchan_bw" = "0" ]; then
933 offchan_bw="20"
934 elif [ "$offchan_bw" = "1" ]; then
935 offchan_bw="40"
936 elif [ "$offchan_bw" = "2" ]; then
937 offchan_bw="80"
938 elif [ "$offchan_bw" = "3" ]; then
939 offchan_bw="160"
940 fi
developer887da632022-10-28 09:35:38 +0800941
developer9f846582023-03-31 17:51:46 +0800942 do_cmd "mt76-test phy${phy_idx} set state=idle"
943 do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
developer887da632022-10-28 09:35:38 +0800944 ;;
945 "DfsRxHist")
946 local ipi_th="$(echo $param | cut -d ':' -f 1)"
947 local ipi_period="$(echo $param | cut -d ':' -f 2)"
developer9f846582023-03-31 17:51:46 +0800948 local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
developer887da632022-10-28 09:35:38 +0800949
developer9f846582023-03-31 17:51:46 +0800950 if [ -z $ipi_antenna ]; then
951 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
952 else
953 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
954 fi
developer887da632022-10-28 09:35:38 +0800955 ;;
956 *)
957 esac
958}
959
developera6267142022-01-26 20:50:22 +0800960function do_ate_work() {
961 local ate_cmd=$1
962
963 case ${ate_cmd} in
964 "ATESTART")
965 local if_str=$(ifconfig | grep mon${phy_idx})
966
967 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
968 echo "ATE already starts."
969 else
970 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
developerb4b29472023-01-06 19:07:21 +0800971
972 if [ $phy_idx -ge $SOC_start_idx ]; then
973 local end_idx=$SOC_end_idx
974 local start_idx=$SOC_start_idx
975 else
976 local end_idx=$((SOC_start_idx-1))
977 local start_idx="0"
978 fi
979
980 for phy_index in $( seq $start_idx $end_idx )
981 do
982 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
983 local prev_phy_index=$((phy_index-1))
984 local if_num=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep -c Interface)
985 local j="1"
986 # avoid del_if_count reset to 0 when start ate on another band in dbdc case
987 local del_if_count=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
988 if [ -z "${del_if_count}" ]; then
989 local del_if_count="0"
990 fi
991
992 for if_count in $( seq 1 $if_num )
993 do
994 local del_if=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep Interface | sed -n ${j}p | cut -d " " -f 2)
995 if [ ! -z "${del_if}" ] && [[ "$del_if" != *"mon"* ]]; then
996 do_cmd "iw dev ${del_if} del"
997 del_if_count=$((del_if_count+1))
998 # handle the case of multiple interface in a phy
999 record_config "DEL_IF${phy_index}-${del_if_count}" ${del_if} ${interface_file}
1000 else
1001 # j add 1 to skip mon interface
1002 j=$((j+1))
1003 fi
1004 done
1005 record_config "DEL_IF${phy_index}_NUM" ${del_if_count} ${interface_file}
1006 done
1007
developera6267142022-01-26 20:50:22 +08001008 do_cmd "ifconfig mon${phy_idx} up"
developer9b7cdad2022-03-10 14:24:55 +08001009 do_cmd "iw reg set VV"
developera6267142022-01-26 20:50:22 +08001010 fi
1011 ;;
1012 "ATESTOP")
1013 local if_str=$(ifconfig | grep mon${phy_idx})
1014
1015 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
1016 echo "ATE does not start."
1017 else
1018 do_cmd "mt76-test ${interface} set state=off"
1019 do_cmd "iw dev mon${phy_idx} del"
developerb4b29472023-01-06 19:07:21 +08001020
1021 if [ $phy_idx -ge $SOC_start_idx ]; then
1022 local end_idx=$SOC_end_idx
1023 local start_idx=$SOC_start_idx
1024 else
1025 local end_idx=$((SOC_start_idx-1))
1026 local start_idx="0"
1027 fi
1028
1029 # first check its phy and dbdc band phy has monitor interface or not
1030 # if has at lease one mon interface, then skip adding back normal interface
1031 local has_mon="0"
1032 for phy_index in $( seq $start_idx $end_idx )
1033 do
1034 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
1035 local prev_phy_index=$((phy_index-1))
1036 local has_mon_phy=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep "Interface mon")
1037 # if this phy interface has mon interface
1038 if [ ! -z "${has_mon_phy}" ]; then
1039 local has_mon="1"
1040 fi
1041 done
1042
1043 for phy_index in $( seq $start_idx $end_idx )
1044 do
1045 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
1046 local prev_phy_index=$((phy_index-1))
1047 local j="1"
1048 local add_if_num=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
1049 if [ -z "${add_if_num}" ]; then
1050 local add_if_num="0"
1051 fi
1052 # if this phy interface (including its dbdc phy) has no mon interface and can find deleted interface in file, then add it back
1053 if [ "${has_mon}" == "0" ] && [ $add_if_num -ge "1" ]; then
1054 local if_index=$add_if_num
1055 # add interface backwards
1056 while [ $if_index -gt "0" ]
1057 do
1058 local add_if=$(get_config "DEL_IF${phy_index}-${if_index}" ${interface_file})
1059 do_cmd "iw phy phy${phy_index} interface add ${add_if} type managed"
1060 # remove the deleted interface in interface_file since it is added back
1061 sed -i "/DEL_IF${phy_index}-${if_index}=/d" ${interface_file}
1062 if_index=$((if_index-1))
1063 done
1064 # remove the number of deleted interface in interface_file since it is all added back
1065 sed -i "/DEL_IF${phy_index}_NUM=/d" ${interface_file}
1066 fi
1067 done
1068
developer461cb542022-04-29 18:17:44 +08001069 do_cmd "mt76-test ${interface} set aid=0"
developera6267142022-01-26 20:50:22 +08001070 fi
developer10946c32022-03-04 18:28:43 +08001071
developerf90c9af2022-12-28 22:40:23 +08001072 if [ ${phy_idx} -lt ${SOC_start_idx} ]; then
developer679a6aa2022-09-07 09:52:41 +08001073 sed -i '/_PCIE=/d' ${iwpriv_file}
developerf90c9af2022-12-28 22:40:23 +08001074 elif [ ${phy_idx} -ge ${SOC_start_idx} ]; then
1075 sed -i '/_SOC=/d' ${iwpriv_file}
developer679a6aa2022-09-07 09:52:41 +08001076 fi
developera6267142022-01-26 20:50:22 +08001077 ;;
developer461cb542022-04-29 18:17:44 +08001078 "TXCOMMIT")
1079 do_cmd "mt76-test ${interface} set aid=1"
1080 ;;
developera6267142022-01-26 20:50:22 +08001081 "TXFRAME")
1082 do_cmd "mt76-test ${interface} set state=tx_frames"
1083 ;;
developer9b7cdad2022-03-10 14:24:55 +08001084 "TXSTOP"|"RXSTOP")
developera6267142022-01-26 20:50:22 +08001085 do_cmd "mt76-test ${interface} set state=idle"
1086 ;;
developer461cb542022-04-29 18:17:44 +08001087 "TXREVERT")
1088 do_cmd "mt76-test ${interface} set aid=0"
1089 ;;
developera6267142022-01-26 20:50:22 +08001090 "RXFRAME")
1091 do_cmd "mt76-test ${interface} set state=rx_frames"
1092 ;;
1093 "TXCONT")
1094 do_cmd "mt76-test ${interface} set state=tx_cont"
1095 ;;
developer071927d2022-08-31 20:39:29 +08001096 "GROUPREK")
1097 do_cmd "mt76-test ${interface} set state=group_prek"
1098 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
1099 ;;
1100 "GROUPREKDump")
1101 do_cmd "mt76-test ${interface} set state=group_prek_dump"
1102 ;;
1103 "GROUPREKClean")
1104 do_cmd "mt76-test ${interface} set state=group_prek_clean"
1105 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
1106 ;;
1107 "DPD2G")
1108 do_cmd "mt76-test ${interface} set state=dpd_2g"
1109 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
1110 ;;
1111 "DPD5G")
1112 do_cmd "mt76-test ${interface} set state=dpd_5g"
1113 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
1114 ;;
1115 "DPD6G")
1116 do_cmd "mt76-test ${interface} set state=dpd_6g"
1117 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
1118 ;;
1119 "DPDDump")
1120 do_cmd "mt76-test ${interface} set state=dpd_dump"
1121 ;;
1122 "DPDClean")
1123 do_cmd "mt76-test ${interface} set state=dpd_clean"
1124 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
1125 ;;
developer9b7cdad2022-03-10 14:24:55 +08001126 *)
developer9b7cdad2022-03-10 14:24:55 +08001127 print_debug "skip ${ate_cmd}"
developera6267142022-01-26 20:50:22 +08001128 ;;
1129 esac
1130}
1131
developerf90c9af2022-12-28 22:40:23 +08001132function dump_usage {
1133 echo "Usage:"
1134 echo " mwctl <interface> set csi ctrl=<opt1>,<opt2>,<opt3>,<opt4> (macaddr=<macaddr>)"
1135 echo " mwctl <interface> set csi interval=<interval (us)>"
1136 echo " mwctl <interface> dump csi <packet num> <filename>"
1137 echo " mwctl <interface> set amnt <index>(0x0~0xf) <mac addr>(xx:xx:xx:xx:xx:xx)"
1138 echo " mwctl <interface> dump amnt <index> (0x0~0xf or 0xff)"
1139 echo " mwctl <interface> set ap_rfeatures he_gi=<val>"
1140 echo " mwctl <interface> set ap_rfeatures he_ltf=<val>"
1141 echo " mwctl <interface> set ap_rfeatures trig_type=<enable>,<val> (val: 0-7)"
1142 echo " mwctl <interface> set ap_rfeatures ack_policy=<val> (val: 0-4)"
1143 echo " mwctl <interface> set ap_wireless fixed_mcs=<val>"
1144 echo " mwctl <interface> set ap_wireless ofdma=<val> (0: disable, 1: DL, 2: UL)"
1145 echo " mwctl <interface> set ap_wireless nusers_ofdma=<val>"
1146 echo " mwctl <interface> set ap_wireless ppdu_type=<val> (0: SU, 1: MU, 4: LEGACY)"
1147 echo " mwctl <interface> set ap_wireless add_ba_req_bufsize=<val>"
1148 echo " mwctl <interface> set ap_wireless mimo=<val> (0: DL, 1: UL)"
1149 echo " mwctl <interface> set ap_wireless ampdu=<enable>"
1150 echo " mwctl <interface> set ap_wireless amsdu=<enable>"
1151 echo " mwctl <interface> set ap_wireless cert=<enable>"
developer57de9b72023-02-20 11:15:54 +08001152 echo " mwctl <interface> set mu onoff=<val> (bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0))"
developerf90c9af2022-12-28 22:40:23 +08001153 echo " mwctl <interface> dump phy_capa"
1154}
1155
developere3d5e5e2023-01-16 16:58:29 +08001156function register_handler {
1157
1158 local phy_idx=$1
1159 local offset=$2
1160 local val=$3
1161 local cmd=$4
1162 local w_cmd="write"
1163
1164 regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
1165 regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
1166
1167 echo ${offset} > ${regidx}
1168 if [[ "${cmd}" == "${w_cmd}" ]]; then
1169 echo ${val} > ${regval}
1170 fi
1171
1172 res=$(cat ${regval} | cut -d 'x' -f 2)
1173 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
1174}
1175
developer10946c32022-03-04 18:28:43 +08001176# main start here
developerb4b29472023-01-06 19:07:21 +08001177parse_sku
developerf90c9af2022-12-28 22:40:23 +08001178if [ -z ${interface} ]; then
1179 dump_usage
1180 exit
1181elif [[ ${interface} == "ra"* ]]; then
developereebce5c2022-08-26 19:05:56 +08001182 convert_interface $interface
developercec48ac2023-03-01 17:00:33 +08001183elif [[ ${interface} == "phy" ]]; then
1184 # handle mwctl phy phy0 e2p ... case
1185 interface=$2
1186 cmd_type=$3
1187 full_cmd=$4
developer10946c32022-03-04 18:28:43 +08001188fi
1189
developer679a6aa2022-09-07 09:52:41 +08001190tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
1191
1192if [ ! -z ${tmp_work_mode} ]; then
1193 work_mode=${tmp_work_mode}
1194fi
1195
developer10946c32022-03-04 18:28:43 +08001196cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
1197param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
1198
developer3abe1ad2022-01-24 11:13:32 +08001199if [ "${cmd_type}" = "set" ]; then
1200 skip=0
developer3abe1ad2022-01-24 11:13:32 +08001201 case ${cmd} in
developerf90c9af2022-12-28 22:40:23 +08001202 ## In wifi 7 chipset, testmode & vendor command both use mwctl
1203 ## Therefore this wrapper would translate it to either mt76-test or mt76-vendor based on the attribute of the command
1204 ## Translate to mt76-vendor command
developer3b15d362023-06-07 16:36:45 +08001205 "csi"|"amnt"|"ap_rfeatures"|"ap_wireless"|"mu"|"set_muru_manual_config")
developer6edd8a22023-08-01 15:47:43 +08001206 if [ ${is_connac3} == "1" ]; then
developer8d613a62023-05-04 10:33:39 +08001207 hostapd_cmd="$(echo $* | sed 's/set/raw/')"
1208 do_cmd "hostapd_cli -i $hostapd_cmd"
developercec48ac2023-03-01 17:00:33 +08001209 else
developer249ac1b2023-02-09 09:54:38 +08001210 do_cmd "mt76-vendor $*"
developercec48ac2023-03-01 17:00:33 +08001211 fi
1212 skip=1
developerf90c9af2022-12-28 22:40:23 +08001213 ;;
developer3abe1ad2022-01-24 11:13:32 +08001214 "ATE")
1215 do_ate_work ${param}
1216
1217 skip=1
1218 ;;
1219 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
1220 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
1221 cmd_new=$(simple_convert ${cmd})
developer679a6aa2022-09-07 09:52:41 +08001222 if [ "${param_new}" = "undefined" ]; then
1223 echo "unknown cmd: ${cmd}"
1224 exit
1225 fi
developer3abe1ad2022-01-24 11:13:32 +08001226 param_new=${param}
developer1346ce52022-12-15 21:36:14 +08001227 if [ "${cmd}" = "ATETXCNT" ] && [ "${param}" = "0" ]; then
developer62713c82023-03-20 10:46:08 +08001228 param_new="0xFFFFFFFF"
developer1346ce52022-12-15 21:36:14 +08001229 fi
developer3abe1ad2022-01-24 11:13:32 +08001230 ;;
1231 "ATETXANT"|"ATERXANT")
1232 cmd_new="tx_antenna"
1233 param_new=${param}
1234 ;;
1235 "ATETXGI")
developer6edd8a22023-08-01 15:47:43 +08001236 if [ ${is_connac3} == "0" ]; then
developercec48ac2023-03-01 17:00:33 +08001237 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
1238 convert_gi ${tx_mode} ${param}
1239 skip=1
1240 else
1241 cmd_new="tx_rate_sgi"
1242 param_new=${param}
1243 fi
developer3abe1ad2022-01-24 11:13:32 +08001244 ;;
1245 "ATETXMODE")
1246 cmd_new="tx_rate_mode"
1247 param_new=$(convert_tx_mode ${param})
developer679a6aa2022-09-07 09:52:41 +08001248 if [ "${param_new}" = "undefined" ]; then
1249 echo "unknown tx mode"
1250 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
1251 exit
1252 else
1253 record_config ${cmd} ${param} ${iwpriv_file}
1254 fi
developer3abe1ad2022-01-24 11:13:32 +08001255 ;;
developercec48ac2023-03-01 17:00:33 +08001256 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3"|"ATETXPOW")
developer3abe1ad2022-01-24 11:13:32 +08001257 cmd_new="tx_power"
developercec48ac2023-03-01 17:00:33 +08001258 if [ "${param}" == "127" ]; then
1259 # for iTest verification
1260 exit
1261 fi
developer3abe1ad2022-01-24 11:13:32 +08001262 param_new="${param},0,0,0"
1263 ;;
developercec48ac2023-03-01 17:00:33 +08001264 "ATEMUAID")
1265 cmd_new="aid"
1266 param_new=${param}
1267 ;;
developer3abe1ad2022-01-24 11:13:32 +08001268 "ATETXBW")
developer679a6aa2022-09-07 09:52:41 +08001269 record_config ${cmd} ${param} ${iwpriv_file}
developer3abe1ad2022-01-24 11:13:32 +08001270 skip=1
1271 ;;
1272 "ATECHANNEL")
1273 convert_channel ${param}
1274 skip=1
1275 ;;
developer10946c32022-03-04 18:28:43 +08001276 "ATERXSTAT")
1277 convert_rxstat
1278 skip=1
1279 ;;
developer3abe1ad2022-01-24 11:13:32 +08001280 "ATECTRLBANDIDX")
developer10946c32022-03-04 18:28:43 +08001281 change_band_idx ${param}
developer3abe1ad2022-01-24 11:13:32 +08001282 skip=1
1283 ;;
developer10946c32022-03-04 18:28:43 +08001284 "ATEDA"|"ATESA"|"ATEBSSID")
1285 set_mac_addr ${cmd} ${param}
1286 skip=1
1287 ;;
developer887da632022-10-28 09:35:38 +08001288 "DfsRxCtrl"|"DfsRxHist")
1289 convert_dfs ${cmd} ${param}
1290 skip=1
1291 ;;
developer1346ce52022-12-15 21:36:14 +08001292 "ATETxBfInit"|"ATETxBfGdInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
1293 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"| \
developer77215642023-05-15 13:52:35 +08001294 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate"|"TriggerSounding"|"StopSounding"|"TxBfTxCmd"| \
developer1346ce52022-12-15 21:36:14 +08001295 "StaRecBfRead"|"TxBfProfileTagInValid"|"TxBfProfileTagWrite"|"TxBfProfileTagRead"| \
1296 "ATEIBFPhaseVerify"|"ATEConTxETxBfGdProc"|"ATEConTxETxBfInitProc")
developerf9843e22022-09-13 10:57:15 +08001297 convert_ibf ${cmd} ${param}
1298 skip=1
1299 ;;
developer3abe1ad2022-01-24 11:13:32 +08001300 "bufferMode")
1301 if [ "${param}" = "2" ]; then
developer461cb542022-04-29 18:17:44 +08001302 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
developer3abe1ad2022-01-24 11:13:32 +08001303 fi
1304 skip=1
1305 ;;
developera6267142022-01-26 20:50:22 +08001306 "ResetCounter"|"ATERXSTATRESET")
1307 skip=1
1308 ;;
developer679a6aa2022-09-07 09:52:41 +08001309 "WORKMODE")
1310 record_config "WORKMODE" ${param} ${iwpriv_file}
1311 echo "Entering ${param} mode in iwpriv"
1312 skip=1
1313 ;;
developer91af1042023-07-10 18:19:30 +08001314 "ATERUINFO")
1315 convert_ruinfo ${param}
1316 skip=1
1317 ;;
developer3abe1ad2022-01-24 11:13:32 +08001318 *)
developer9b7cdad2022-03-10 14:24:55 +08001319 print_debug "Unknown command to set: ${cmd}"
developer3abe1ad2022-01-24 11:13:32 +08001320 skip=1
1321 esac
1322
1323 if [ "${skip}" != "1" ]; then
1324 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
1325 fi
developer10946c32022-03-04 18:28:43 +08001326
developer3abe1ad2022-01-24 11:13:32 +08001327elif [ "${cmd_type}" = "show" ]; then
developer1346ce52022-12-15 21:36:14 +08001328 if [ "${cmd}" = "wtbl" ]; then
1329 wlan_idx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wlan_idx
1330 wtbl_info=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wtbl_info
1331
1332 do_cmd "echo ${param} > ${wlan_idx}"
1333 do_cmd "cat ${wtbl_info}"
developercec48ac2023-03-01 17:00:33 +08001334 elif [ "${cmd}" = "ATERXSTAT" ]; then
1335 convert_rxstat
developer1346ce52022-12-15 21:36:14 +08001336 else
1337 do_cmd "mt76-test ${interface} dump"
1338 do_cmd "mt76-test ${interface} dump stats"
1339 fi
developer10946c32022-03-04 18:28:43 +08001340
developer3abe1ad2022-01-24 11:13:32 +08001341elif [ "${cmd_type}" = "e2p" ]; then
developerf90c9af2022-12-28 22:40:23 +08001342 # support multiple read write
developera6267142022-01-26 20:50:22 +08001343 # eeprom offset write
1344 if [[ ${full_cmd} == *"="* ]]; then
developerf90c9af2022-12-28 22:40:23 +08001345 IFS=,
1346 for tuple in $full_cmd
1347 do
1348 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1349 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1350 offset=$(printf "0x%s" ${cmd})
1351 val=$(printf "0x%s" ${param})
1352 tmp=$((${val} & 0xff))
1353 tmp=$(printf "0x%x" ${tmp})
1354 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developera6267142022-01-26 20:50:22 +08001355
developerf90c9af2022-12-28 22:40:23 +08001356 offset=$((${offset}))
1357 offset=$(expr ${offset} + "1")
1358 offset=$(printf "0x%x" ${offset})
1359 tmp=$(((${val} >> 8) & 0xff))
1360 tmp=$(printf "0x%x" ${tmp})
1361 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
1362 done
developera6267142022-01-26 20:50:22 +08001363 else
developerf90c9af2022-12-28 22:40:23 +08001364 IFS=,
1365 for tuple in $full_cmd
1366 do
1367 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1368 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1369 offset=$(printf "0x%s" ${cmd})
1370 val=$(printf "0x%s" ${param})
1371 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
1372 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developer3abe1ad2022-01-24 11:13:32 +08001373
developerf90c9af2022-12-28 22:40:23 +08001374 tmp=$(printf "0x%s" ${param})
1375 tmp=$((${tmp}))
1376 param2=$(expr ${tmp} + "1")
1377 param2=$(printf "%x" ${param2})
1378 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
1379 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developera6267142022-01-26 20:50:22 +08001380
developerf90c9af2022-12-28 22:40:23 +08001381 param=$(printf "0x%s" ${param})
1382 param=$(printf "%04x" ${param})
1383 param=$(echo $param | tr 'a-z' 'A-Z')
1384 printf "%s e2p:\n" ${interface_ori}
1385 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
1386 done
developera6267142022-01-26 20:50:22 +08001387 fi
developer10946c32022-03-04 18:28:43 +08001388
developera6267142022-01-26 20:50:22 +08001389elif [ "${cmd_type}" = "mac" ]; then
developera6267142022-01-26 20:50:22 +08001390 offset=$(printf "0x%s" ${cmd})
1391 val=$(printf "0x%s" ${param})
1392
developera6267142022-01-26 20:50:22 +08001393 # reg write
1394 if [[ ${full_cmd} == *"="* ]]; then
developere3d5e5e2023-01-16 16:58:29 +08001395 register_handler ${phy_idx} ${offset} ${val} "write"
1396 else
1397 start_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 1)
1398 end_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 2)
1399 loop=$((0x${end_addr}-0x${start_addr}))
developer10946c32022-03-04 18:28:43 +08001400
developere3d5e5e2023-01-16 16:58:29 +08001401 if [[ ${loop} == "0" ]]; then
1402 register_handler ${phy_idx} ${offset} ${val}
1403 else
1404 i=0
1405 while [ $i -le $loop ]; do
1406 addr=$((0x${start_addr}+$i))
1407 offset=$(printf "0x%x" ${addr})
1408 register_handler ${phy_idx} ${offset} ${val}
1409 i=$(($i + 4))
1410 done
1411 fi
1412 fi
developer461cb542022-04-29 18:17:44 +08001413
developerf90c9af2022-12-28 22:40:23 +08001414## dump command is only for vendor commands
1415elif [ "${cmd_type}" = "dump" ]; then
1416 do_cmd "mt76-vendor $*"
developer9f846582023-03-31 17:51:46 +08001417elif [ "${cmd_type}" = "switch" ]; then
developerd64cd9b2023-10-13 18:41:57 +08001418 eeprom_mode_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom_mode
developer9f846582023-03-31 17:51:46 +08001419 eeprom_mode=$(cat ${eeprom_mode_file} | grep "mode" | sed -n 2p | cut -d " " -f 4)
1420 eeprom_testmode_offset="1af"
1421 testmode_enable="0"
1422
developer6edd8a22023-08-01 15:47:43 +08001423 if [ ${is_connac3} == "0" ]; then
developer9f846582023-03-31 17:51:46 +08001424 return
1425 fi
1426
1427 if [ "${cmd}" = "testmode" ]; then
1428 testmode_enable="1"
1429 fi
1430
1431 if [ "${eeprom_mode}" = "flash" ]; then
1432 ## flash mode should set eeprom testmode offset bit
1433 ## efuse/bin file/default bin mode rely on module param only
1434 do_cmd "atenl -i ${interface} -c \"eeprom set 0x${eeprom_testmode_offset}=0x${testmode_enable}\""
1435 ## If has no precal, it would not affect
1436 do_cmd "atenl -i ${interface} -c \"eeprom precal sync\""
1437 do_cmd "atenl -i ${interface} -c \"sync eeprom all\""
1438 fi
1439
1440 do_cmd "rmmod mt7996e"
1441 do_cmd "rmmod mt76-connac-lib"
1442 do_cmd "rmmod mt76"
1443 do_cmd "rmmod mac80211"
1444 do_cmd "rmmod cfg80211"
1445 do_cmd "rmmod compat"
1446 do_cmd "insmod compat"
1447 do_cmd "insmod cfg80211"
1448 do_cmd "insmod mac80211"
1449 do_cmd "insmod mt76"
1450 do_cmd "insmod mt76-connac-lib"
1451 do_cmd "insmod mt7996e testmode_enable=${testmode_enable}"
1452 do_cmd "sleep 5"
1453 do_cmd "killall hostapd"
1454 do_cmd "killall netifd"
developer3abe1ad2022-01-24 11:13:32 +08001455else
1456 echo "Unknown command"
1457fi