blob: b636bf8d1e37525ec7ba65d3bfc4fe2dac5abbcd [file] [log] [blame]
developerb9b4cd12022-10-11 13:18:59 +08001#!/bin/ash
2
3interface=$1 # phy0/phy1/ra0
developer13655da2023-01-10 19:53:25 +08004cmd_type=$2 # set/show/e2p/mac/dump
developerb9b4cd12022-10-11 13:18:59 +08005full_cmd=$3
6interface_ori=${interface}
developer13655da2023-01-10 19:53:25 +08007SOC_start_idx="0"
developer3f784572023-01-31 15:21:28 +08008SOC_end_idx="0"
developerc8796032023-08-09 10:28:15 +08009is_connac3="0"
developerb9b4cd12022-10-11 13:18:59 +080010
11work_mode="RUN" # RUN/PRINT/DEBUG
12iwpriv_file="/tmp/iwpriv_wrapper"
13interface_file="/tmp/interface"
14phy_idx=$(echo ${interface} | tr -dc '0-9')
developer9237f442024-06-14 17:13:04 +080015main_phy_idx=0
developerb9b4cd12022-10-11 13:18:59 +080016
17function do_cmd() {
18 case ${work_mode} in
19 "RUN")
20 eval "$1"
21 ;;
22 "PRINT")
23 echo "$1"
24 ;;
25 "DEBUG")
developerb9b4cd12022-10-11 13:18:59 +080026 echo "$1"
developerb403ad02022-11-08 10:16:29 +080027 eval "$1"
developerb9b4cd12022-10-11 13:18:59 +080028 ;;
29 esac
30}
31
32function print_debug() {
33 if [ "${work_mode}" = "DEBUG" ]; then
34 echo "$1"
35 fi
36}
37
38function write_dmesg() {
39 echo "$1" > /dev/kmsg
40}
41
42function record_config() {
43 local config=$1
44 local tmp_file=$3
45
developer9237f442024-06-14 17:13:04 +080046 # check it is SOC(mt7986)/Eagle/Kite or PCIE card (mt7915/7916), and write its config
developer3f784572023-01-31 15:21:28 +080047 if [ ${tmp_file} != ${interface_file} ]; then
developer13655da2023-01-10 19:53:25 +080048 if [ $phy_idx -lt $SOC_start_idx ]; then
developerb9b4cd12022-10-11 13:18:59 +080049 config="${config}_PCIE"
developer13655da2023-01-10 19:53:25 +080050 elif [ $phy_idx -ge $SOC_start_idx ]; then
51 config="${config}_SOC"
developerb9b4cd12022-10-11 13:18:59 +080052 fi
53 fi
54
55 if [ -f ${tmp_file} ]; then
56 if grep -q ${config} ${tmp_file}; then
57 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
58 else
59 echo "${config}=$2" >> ${tmp_file}
60 fi
61 else
62 echo "${config}=$2" >> ${tmp_file}
63 fi
64}
65
66function get_config() {
67 local config=$1
68 local tmp_file=$2
69
70 if [ ! -f ${tmp_file} ]; then
71 echo ""
72 return
73 fi
74
developer9237f442024-06-14 17:13:04 +080075 # check it is SOC(mt7986)/Eagle/Kite or PCIE card (mt7915/7916), and write its config
developer3f784572023-01-31 15:21:28 +080076 if [ ${tmp_file} != ${interface_file} ]; then
developer13655da2023-01-10 19:53:25 +080077 if [ $phy_idx -lt $SOC_start_idx ]; then
developerb9b4cd12022-10-11 13:18:59 +080078 config="${config}_PCIE"
developer13655da2023-01-10 19:53:25 +080079 elif [ $phy_idx -ge $SOC_start_idx ]; then
80 config="${config}_SOC"
developerb9b4cd12022-10-11 13:18:59 +080081 fi
82 fi
83
84 if grep -q ${config} ${tmp_file}; then
85 echo "$(cat ${tmp_file} | grep ${config} | sed s/=/' '/g | cut -d " " -f 2)"
86 else
87 echo ""
88 fi
89}
90
developer3f784572023-01-31 15:21:28 +080091function parse_sku {
developer13655da2023-01-10 19:53:25 +080092 SOC_start_idx=$(get_config "STARTIDX" ${interface_file})
developer3f784572023-01-31 15:21:28 +080093 SOC_end_idx=$(get_config "ENDIDX" ${interface_file})
developerc8796032023-08-09 10:28:15 +080094 is_connac3=$(get_config "IS_CONNAC3" ${interface_file})
developerb9b4cd12022-10-11 13:18:59 +080095 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
developerc8796032023-08-09 10:28:15 +080096 if [ -z "${SOC_start_idx}" ] || [ -z "${SOC_end_idx}" ] || [ -z "${is_connac3}" ]; then
developerb9b4cd12022-10-11 13:18:59 +080097 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
developer13655da2023-01-10 19:53:25 +080098 SOC_start_idx="2"
developer3f784572023-01-31 15:21:28 +080099 SOC_end_idx="3"
developerc8796032023-08-09 10:28:15 +0800100 is_connac3="0"
developerb9b4cd12022-10-11 13:18:59 +0800101 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
developer13655da2023-01-10 19:53:25 +0800102 SOC_start_idx="1"
developer3f784572023-01-31 15:21:28 +0800103 SOC_end_idx="2"
developerc8796032023-08-09 10:28:15 +0800104 is_connac3="0"
developer70180b02023-11-14 17:01:47 +0800105 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7981")" ]; then
106 SOC_start_idx="0"
107 SOC_end_idx="1"
108 is_connac3="0"
developerb9b4cd12022-10-11 13:18:59 +0800109 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
developer13655da2023-01-10 19:53:25 +0800110 SOC_start_idx="0"
developer3f784572023-01-31 15:21:28 +0800111 SOC_end_idx="1"
developerc8796032023-08-09 10:28:15 +0800112 is_connac3="0"
developer13655da2023-01-10 19:53:25 +0800113 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then
114 SOC_start_idx="0"
developer3f784572023-01-31 15:21:28 +0800115 SOC_end_idx="2"
developerc8796032023-08-09 10:28:15 +0800116 is_connac3="1"
117 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7992")" ]; then
118 SOC_start_idx="0"
119 SOC_end_idx="1"
120 is_connac3="1"
developerb9b4cd12022-10-11 13:18:59 +0800121 else
122 echo "Interface Conversion Failed!"
123 echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
developer70180b02023-11-14 17:01:47 +0800124 echo "For AX3000/AX6000:"
developer3f784572023-01-31 15:21:28 +0800125 echo " echo STARTIDX=0 >> ${interface_file}"
126 echo " echo ENDIDX=1 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800127 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800128 echo "For AX7800:"
129 echo " echo STARTIDX=2 >> ${interface_file}"
130 echo " echo ENDIDX=3 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800131 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800132 echo "For AX8400:"
133 echo " echo STARTIDX=1 >> ${interface_file}"
134 echo " echo ENDIDX=2 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800135 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800136 echo "For Eagle:"
developerc8796032023-08-09 10:28:15 +0800137 echo " echo STARTIDX=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800138 echo " echo ENDIDX=2 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800139 echo " echo IS_CONNAC3=1 >> ${interface_file}"
140 echo "For Kite:"
141 echo " echo STARTIDX=0 >> ${interface_file}"
142 echo " echo ENDIDX=1 >> ${interface_file}"
143 echo " echo IS_CONNAC3=1 >> ${interface_file}"
developerb9b4cd12022-10-11 13:18:59 +0800144 exit 0
145 fi
developer13655da2023-01-10 19:53:25 +0800146 record_config "STARTIDX" ${SOC_start_idx} ${interface_file}
developer3f784572023-01-31 15:21:28 +0800147 record_config "ENDIDX" ${SOC_end_idx} ${interface_file}
developerc8796032023-08-09 10:28:15 +0800148 record_config "IS_CONNAC3" ${is_connac3} ${interface_file}
developerb9b4cd12022-10-11 13:18:59 +0800149 fi
developer3f784572023-01-31 15:21:28 +0800150}
developerb9b4cd12022-10-11 13:18:59 +0800151
developer3f784572023-01-31 15:21:28 +0800152function convert_interface {
developerc8796032023-08-09 10:28:15 +0800153 if [ ${is_connac3} == "0" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800154 if [[ $1 == "raix"* ]]; then
developer13655da2023-01-10 19:53:25 +0800155 phy_idx=1
156 elif [[ $1 == "rai"* ]]; then
developerb9b4cd12022-10-11 13:18:59 +0800157 phy_idx=0
158 elif [[ $1 == "rax"* ]]; then
developer13655da2023-01-10 19:53:25 +0800159 phy_idx=$((SOC_start_idx+1))
160 else
161 phy_idx=$SOC_start_idx
developerb9b4cd12022-10-11 13:18:59 +0800162 fi
developer13655da2023-01-10 19:53:25 +0800163
164 # convert phy index according to band idx
165 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
166 if [ "${band_idx}" = "0" ]; then
167 if [[ $1 == "raix"* ]]; then
168 phy_idx=0
169 elif [[ $1 == "rax"* ]]; then
170 phy_idx=$SOC_start_idx
171 fi
172 elif [ "${band_idx}" = "1" ]; then
173 if [[ $1 == "rai"* ]]; then
174 # AX8400: mt7915 remain phy0
175 # AX7800: mt7916 becomes phy1
176 phy_idx=$((SOC_start_idx-1))
177 elif [[ $1 == "ra"* ]]; then
178 phy_idx=$((SOC_start_idx+1))
179 fi
180 fi
181 else
developer9237f442024-06-14 17:13:04 +0800182 # Connac 3 chips has different mapping method
developer13655da2023-01-10 19:53:25 +0800183 # phy0: ra0
184 # phy1: rai0
185 # phy2: rax0
developerb9b4cd12022-10-11 13:18:59 +0800186 if [[ $1 == "rai"* ]]; then
developer13655da2023-01-10 19:53:25 +0800187 phy_idx=1
188 elif [[ $1 == "rax"* ]]; then
189 phy_idx=2
190 else
191 phy_idx=0
developerb9b4cd12022-10-11 13:18:59 +0800192 fi
193 fi
194
195 interface="phy${phy_idx}"
196}
197
198function change_band_idx {
199 local new_idx=$1
200 local new_phy_idx=$phy_idx
201
202 local old_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
203
204
205 if [[ ${interface_ori} == "ra"* ]]; then
206 if [ -z "${old_idx}" ] || [ "${old_idx}" != "${new_idx}" ]; then
207 if [ "${new_idx}" = "0" ]; then
208 # raix0 & rai0 becomes rai0
209 if [[ $interface_ori == "rai"* ]]; then
210 new_phy_idx=0
211 # rax0 & ra0 becomes ra0
212 elif [[ $interface_ori == "ra"* ]]; then
developer13655da2023-01-10 19:53:25 +0800213 new_phy_idx=$SOC_start_idx
developerb9b4cd12022-10-11 13:18:59 +0800214 fi
215 elif [ "${new_idx}" = "1" ]; then
216 # raix0 & rai0 becomes raix0
217 if [[ $interface_ori == "rai"* ]]; then
developerc5ce7502022-12-19 11:33:22 +0800218 # For AX8400 => don't change phy idx
developer13655da2023-01-10 19:53:25 +0800219 if [ ${SOC_start_idx} != "1" ]; then
developerc5ce7502022-12-19 11:33:22 +0800220 new_phy_idx=1
221 fi
developerb9b4cd12022-10-11 13:18:59 +0800222 # rax0 & ra0 becomes rax0
223 elif [[ $interface_ori == "ra"* ]]; then
developer13655da2023-01-10 19:53:25 +0800224 new_phy_idx=$((SOC_start_idx+1))
developerb9b4cd12022-10-11 13:18:59 +0800225 fi
226 fi
227 fi
228
229 if [ ${new_phy_idx} != ${phy_idx} ]; then
230 do_ate_work "ATESTOP"
231 phy_idx=$new_phy_idx
232 interface="phy${phy_idx}"
233 do_ate_work "ATESTART"
234 fi
235 fi
236 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
237}
238
239function simple_convert() {
240 if [ "$1" = "ATETXCNT" ]; then
241 echo "tx_count"
242 elif [ "$1" = "ATETXLEN" ]; then
243 echo "tx_length"
244 elif [ "$1" = "ATETXMCS" ]; then
245 echo "tx_rate_idx"
246 elif [ "$1" = "ATEVHTNSS" ]; then
247 echo "tx_rate_nss"
248 elif [ "$1" = "ATETXLDPC" ]; then
249 echo "tx_rate_ldpc"
250 elif [ "$1" = "ATETXSTBC" ]; then
251 echo "tx_rate_stbc"
252 elif [ "$1" = "ATEPKTTXTIME" ]; then
253 echo "tx_time"
254 elif [ "$1" = "ATEIPG" ]; then
255 echo "tx_ipg"
256 elif [ "$1" = "ATEDUTYCYCLE" ]; then
257 echo "tx_duty_cycle"
258 elif [ "$1" = "ATETXFREQOFFSET" ]; then
259 echo "freq_offset"
260 else
261 echo "undefined"
262 fi
263}
264
265function convert_tx_mode() {
developerc5ce7502022-12-19 11:33:22 +0800266 # Remove leading zeros
developer3f784572023-01-31 15:21:28 +0800267 local tx_mode=$(echo $1 | sed -r 's/0+([0-9]+)/\1/g')
developerc5ce7502022-12-19 11:33:22 +0800268
269 if [ "$tx_mode" = "0" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800270 echo "cck"
developerc5ce7502022-12-19 11:33:22 +0800271 elif [ "$tx_mode" = "1" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800272 echo "ofdm"
developerc5ce7502022-12-19 11:33:22 +0800273 elif [ "$tx_mode" = "2" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800274 echo "ht"
developerc5ce7502022-12-19 11:33:22 +0800275 elif [ "$tx_mode" = "4" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800276 echo "vht"
developerc5ce7502022-12-19 11:33:22 +0800277 elif [ "$tx_mode" = "8" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800278 echo "he_su"
developerc5ce7502022-12-19 11:33:22 +0800279 elif [ "$tx_mode" = "9" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800280 echo "he_er"
developerc5ce7502022-12-19 11:33:22 +0800281 elif [ "$tx_mode" = "10" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800282 echo "he_tb"
developerc5ce7502022-12-19 11:33:22 +0800283 elif [ "$tx_mode" = "11" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800284 echo "he_mu"
developerbb6ddff2023-03-08 17:22:32 +0800285 elif [ "$tx_mode" = "13" ]; then
286 echo "eht_su"
287 elif [ "$tx_mode" = "14" ]; then
288 echo "eht_tb"
289 elif [ "$tx_mode" = "15" ]; then
290 echo "eht_mu"
developerb9b4cd12022-10-11 13:18:59 +0800291 else
292 echo "undefined"
293 fi
294}
295
296function convert_gi {
297 local tx_mode=$1
298 local val=$2
299 local sgi="0"
300 local he_ltf="0"
301
302 case ${tx_mode} in
303 "ht"|"vht")
304 sgi=${val}
305 ;;
306 "he_su"|"he_er")
307 case ${val} in
308 "0")
309 ;;
310 "1")
311 he_ltf="1"
312 ;;
313 "2")
314 sgi="1"
315 he_ltf="1"
316 ;;
317 "3")
318 sgi="2"
319 he_ltf="2"
320 ;;
321 "4")
322 he_ltf="2"
323 ;;
324 *)
325 echo "unknown gi"
326 esac
327 ;;
328 "he_mu")
329 case ${val} in
330 "0")
331 he_ltf="2"
332 ;;
333 "1")
334 he_ltf="1"
335 ;;
336 "2")
337 sgi="1"
338 he_ltf="1"
339 ;;
340 "3")
341 sgi="2"
342 he_ltf="2"
343 ;;
344 *)
345 echo "unknown gi"
346 esac
347 ;;
348 "he_tb")
349 case ${val} in
350 "0")
351 sgi="1"
352 ;;
353 "1")
354 sgi="1"
355 he_ltf="1"
356 ;;
357 "2")
358 sgi="2"
359 he_ltf="2"
360 ;;
361 *)
362 echo "unknown gi"
363 esac
364 ;;
365 *)
366 print_debug "legacy mode no need gi"
367 esac
368
369 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
370}
371
372function convert_channel {
373 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
374 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
375 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
376 local bw_str="HT20"
377 local base_chan=1
378 local control_freq=0
379 local base_freq=0
developerc5ce7502022-12-19 11:33:22 +0800380 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
381 local temp=$((phy_idx+1))
developerb9b4cd12022-10-11 13:18:59 +0800382
developerc5ce7502022-12-19 11:33:22 +0800383 # Handle ATECTRLBANDIDX
384 if [ ! -z ${ctrl_band_idx} ]; then
385 if [ "${ctrl_band_idx}" == "1" ] && [ ${band} == "0" ]; then
386 local temp=$(cat "/etc/config/wireless"| grep "option band" | sed -n ${temp}p | cut -c 15)
387 if [ "${temp}" == "2" ]; then
388 local band=0
389 elif [ "${temp}" == "5" ]; then
390 local band=1
391 elif [ "${temp}" == "6" ]; then
392 local band=2
393 else
394 echo "iwpriv wrapper band translate error!"
395 fi
396 else
397 # mt7915 in AX8400 case: band should be determined by only the input band
developer13655da2023-01-10 19:53:25 +0800398 if [ "${SOC_start_idx}" == "1" ] && [ ${phy_idx} == "0" ]; then
developerc5ce7502022-12-19 11:33:22 +0800399 local band=$((band))
400 else
401 local band=$((ctrl_band_idx * band))
402 fi
403 fi
developerb9b4cd12022-10-11 13:18:59 +0800404 fi
405
406 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
407 case ${bw} in
408 "1")
409 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
410 local bw_str="HT20"
411 else
412 local bw_str="HT40+"
413 ch=$(expr ${ch} - "2")
414 fi
415 ;;
416 esac
417 local base_freq=2412
418 elif [ "${band}" = "1" ]; then
419 case ${bw} in
420 "5")
421 bw_str="160MHz"
422 if [ ${ch} -lt "68" ]; then
423 ch="36"
424 elif [ ${ch} -lt "100" ]; then
425 ch="68"
426 elif [ ${ch} -lt "132" ]; then
427 ch="100"
428 elif [ ${ch} -lt "181" ]; then
429 ch="149"
430 fi
431 ;;
432 "2")
433 bw_str="80MHz"
434 if [ ${ch} -lt "52" ]; then
435 ch="36"
436 elif [ ${ch} -lt "68" ]; then
437 ch="52"
438 elif [ ${ch} -lt "84" ]; then
439 ch="68"
440 elif [ ${ch} -lt "100" ]; then
441 ch="84"
442 elif [ ${ch} -lt "116" ]; then
443 ch="100"
444 elif [ ${ch} -lt "132" ]; then
445 ch="116"
446 elif [ ${ch} -lt "149" ]; then
447 ch="132"
448 elif [ ${ch} -lt "165" ]; then
449 ch="149"
450 elif [ ${ch} -lt "181" ]; then
451 ch="165"
452 fi
453 ;;
454 "1")
455 if [ ${ch} -lt "44" ]; then
456 ch=$([ "${ch}" -lt "40" ] && echo "36" || echo "40")
457 bw_str=$([ "${ch}" -le "38" ] && echo "HT40+" || echo "HT40-")
458 elif [ ${ch} -lt "52" ]; then
459 ch=$([ "${ch}" -lt "48" ] && echo "44" || echo "48")
460 bw_str=$([ "${ch}" -le "46" ] && echo "HT40+" || echo "HT40-")
461 elif [ ${ch} -lt "60" ]; then
462 ch=$([ "${ch}" -lt "56" ] && echo "52" || echo "56")
463 bw_str=$([ "${ch}" -le "54" ] && echo "HT40+" || echo "HT40-")
464 elif [ ${ch} -lt "68" ]; then
465 ch=$([ "${ch}" -lt "64" ] && echo "60" || echo "64")
466 bw_str=$([ "${ch}" -le "62" ] && echo "HT40+" || echo "HT40-")
467 elif [ ${ch} -lt "76" ]; then
468 ch=$([ "${ch}" -lt "72" ] && echo "68" || echo "72")
469 bw_str=$([ "${ch}" -le "70" ] && echo "HT40+" || echo "HT40-")
470 elif [ ${ch} -lt "84" ]; then
471 ch=$([ "${ch}" -lt "80" ] && echo "76" || echo "80")
472 bw_str=$([ "${ch}" -le "78" ] && echo "HT40+" || echo "HT40-")
473 elif [ ${ch} -lt "92" ]; then
474 ch=$([ "${ch}" -lt "88" ] && echo "84" || echo "88")
475 bw_str=$([ "${ch}" -le "86" ] && echo "HT40+" || echo "HT40-")
476 elif [ ${ch} -lt "100" ]; then
477 ch=$([ "${ch}" -lt "96" ] && echo "92" || echo "96")
478 bw_str=$([ "${ch}" -le "94" ] && echo "HT40+" || echo "HT40-")
479 elif [ ${ch} -lt "108" ]; then
480 ch=$([ "${ch}" -lt "104" ] && echo "100" || echo "104")
481 bw_str=$([ "${ch}" -le "102" ] && echo "HT40+" || echo "HT40-")
482 elif [ ${ch} -lt "116" ]; then
483 ch=$([ "${ch}" -lt "112" ] && echo "108" || echo "112")
484 bw_str=$([ "${ch}" -le "110" ] && echo "HT40+" || echo "HT40-")
485 elif [ ${ch} -lt "124" ]; then
486 ch=$([ "${ch}" -lt "120" ] && echo "116" || echo "120")
487 bw_str=$([ "${ch}" -le "118" ] && echo "HT40+" || echo "HT40-")
488 elif [ ${ch} -lt "132" ]; then
489 ch=$([ "${ch}" -lt "128" ] && echo "124" || echo "128")
490 bw_str=$([ "${ch}" -le "126" ] && echo "HT40+" || echo "HT40-")
491 elif [ ${ch} -lt "140" ]; then
492 ch=$([ "${ch}" -lt "136" ] && echo "132" || echo "136")
493 bw_str=$([ "${ch}" -le "134" ] && echo "HT40+" || echo "HT40-")
494 elif [ ${ch} -lt "149" ]; then
495 ch=$([ "${ch}" -lt "144" ] && echo "140" || echo "144")
496 bw_str=$([ "${ch}" -le "142" ] && echo "HT40+" || echo "HT40-")
497 elif [ ${ch} -lt "157" ]; then
498 ch=$([ "${ch}" -lt "153" ] && echo "149" || echo "153")
499 bw_str=$([ "${ch}" -le "151" ] && echo "HT40+" || echo "HT40-")
500 elif [ ${ch} -lt "165" ]; then
501 ch=$([ "${ch}" -lt "161" ] && echo "157" || echo "161")
502 bw_str=$([ "${ch}" -le "159" ] && echo "HT40+" || echo "HT40-")
503 elif [ ${ch} -lt "173" ]; then
504 ch=$([ "${ch}" -lt "169" ] && echo "165" || echo "169")
505 bw_str=$([ "${ch}" -le "167" ] && echo "HT40+" || echo "HT40-")
506 elif [ ${ch} -lt "181" ]; then
507 ch=$([ "${ch}" -lt "177" ] && echo "173" || echo "177")
508 bw_str=$([ "${ch}" -le "175" ] && echo "HT40+" || echo "HT40-")
509 fi
510 ;;
511 "0")
512 local bw_str="HT20"
513 ;;
514 esac
515 local base_freq=5180
516 local base_chan=36
517 else
developerbb6ddff2023-03-08 17:22:32 +0800518 local base_freq=5955
developerb9b4cd12022-10-11 13:18:59 +0800519 case ${bw} in
developerbb6ddff2023-03-08 17:22:32 +0800520 "12")
521 local bw_str="320"
522 if [ ${ch} == "31" ]; then
523 local control_freq="5955"
524 elif [ ${ch} == "63" ]; then
525 local control_freq="6115"
526 elif [ ${ch} == "95" ]; then
527 local control_freq="6275"
528 elif [ ${ch} == "127" ]; then
529 local control_freq="6435"
530 elif [ ${ch} == "159" ]; then
531 local control_freq="6595"
532 elif [ ${ch} == "191" ]; then
533 local control_freq="6755"
534 fi
535 local center_freq=$(((ch - base_chan) * 5 + base_freq))
536 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str} ${center_freq}"
537 return
538 ;;
developerb9b4cd12022-10-11 13:18:59 +0800539 "5")
540 bw_str="160MHz"
541 if [ ${ch} -lt "33" ]; then
542 ch="1"
543 elif [ ${ch} -lt "65" ]; then
544 ch="33"
545 elif [ ${ch} -lt "97" ]; then
546 ch="65"
547 elif [ ${ch} -lt "129" ]; then
548 ch="97"
549 elif [ ${ch} -lt "161" ]; then
550 ch="129"
551 elif [ ${ch} -lt "193" ]; then
552 ch="161"
553 elif [ ${ch} -lt "225" ]; then
554 ch="193"
555 fi
556 ;;
557 "2")
558 bw_str="80MHz"
559 if [ ${ch} -lt "17" ]; then
560 ch="1"
561 elif [ ${ch} -lt "33" ]; then
562 ch="17"
563 elif [ ${ch} -lt "49" ]; then
564 ch="33"
565 elif [ ${ch} -lt "65" ]; then
566 ch="49"
567 elif [ ${ch} -lt "81" ]; then
568 ch="65"
569 elif [ ${ch} -lt "97" ]; then
570 ch="81"
571 elif [ ${ch} -lt "113" ]; then
572 ch="97"
573 elif [ ${ch} -lt "129" ]; then
574 ch="113"
575 elif [ ${ch} -lt "145" ]; then
576 ch="129"
577 elif [ ${ch} -lt "161" ]; then
578 ch="145"
579 elif [ ${ch} -lt "177" ]; then
580 ch="161"
581 elif [ ${ch} -lt "193" ]; then
582 ch="177"
583 elif [ ${ch} -lt "209" ]; then
584 ch="193"
585 elif [ ${ch} -lt "225" ]; then
586 ch="209"
587 fi
588 ;;
589 "1")
590 if [ ${ch} -lt "9" ]; then
591 ch=$([ "${ch}" -lt "5" ] && echo "1" || echo "5")
592 bw_str=$([ "${ch}" -le "3" ] && echo "HT40+" || echo "HT40-")
593 elif [ ${ch} -lt "17" ]; then
594 ch=$([ "${ch}" -lt "13" ] && echo "9" || echo "13")
595 bw_str=$([ "${ch}" -le "11" ] && echo "HT40+" || echo "HT40-")
596 elif [ ${ch} -lt "25" ]; then
597 ch=$([ "${ch}" -lt "21" ] && echo "17" || echo "21")
598 bw_str=$([ "${ch}" -le "19" ] && echo "HT40+" || echo "HT40-")
599 elif [ ${ch} -lt "33" ]; then
600 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
601 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
602 elif [ ${ch} -lt "33" ]; then
603 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
604 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
605 elif [ ${ch} -lt "41" ]; then
606 ch=$([ "${ch}" -lt "37" ] && echo "33" || echo "37")
607 bw_str=$([ "${ch}" -le "35" ] && echo "HT40+" || echo "HT40-")
608 elif [ ${ch} -lt "49" ]; then
609 ch=$([ "${ch}" -lt "45" ] && echo "41" || echo "45")
610 bw_str=$([ "${ch}" -le "43" ] && echo "HT40+" || echo "HT40-")
611 elif [ ${ch} -lt "57" ]; then
612 ch=$([ "${ch}" -lt "53" ] && echo "49" || echo "53")
613 bw_str=$([ "${ch}" -le "51" ] && echo "HT40+" || echo "HT40-")
614 elif [ ${ch} -lt "65" ]; then
615 ch=$([ "${ch}" -lt "61" ] && echo "57" || echo "61")
616 bw_str=$([ "${ch}" -le "59" ] && echo "HT40+" || echo "HT40-")
617 elif [ ${ch} -lt "73" ]; then
618 ch=$([ "${ch}" -lt "69" ] && echo "65" || echo "69")
619 bw_str=$([ "${ch}" -le "67" ] && echo "HT40+" || echo "HT40-")
620 elif [ ${ch} -lt "81" ]; then
621 ch=$([ "${ch}" -lt "77" ] && echo "73" || echo "77")
622 bw_str=$([ "${ch}" -le "75" ] && echo "HT40+" || echo "HT40-")
623 elif [ ${ch} -lt "89" ]; then
624 ch=$([ "${ch}" -lt "85" ] && echo "81" || echo "85")
625 bw_str=$([ "${ch}" -le "83" ] && echo "HT40+" || echo "HT40-")
626 elif [ ${ch} -lt "97" ]; then
627 ch=$([ "${ch}" -lt "93" ] && echo "89" || echo "93")
628 bw_str=$([ "${ch}" -le "91" ] && echo "HT40+" || echo "HT40-")
629 elif [ ${ch} -lt "105" ]; then
630 ch=$([ "${ch}" -lt "101" ] && echo "97" || echo "101")
631 bw_str=$([ "${ch}" -le "99" ] && echo "HT40+" || echo "HT40-")
632 elif [ ${ch} -lt "113" ]; then
633 ch=$([ "${ch}" -lt "109" ] && echo "105" || echo "109")
634 bw_str=$([ "${ch}" -le "107" ] && echo "HT40+" || echo "HT40-")
635 elif [ ${ch} -lt "121" ]; then
636 ch=$([ "${ch}" -lt "117" ] && echo "113" || echo "117")
637 bw_str=$([ "${ch}" -le "115" ] && echo "HT40+" || echo "HT40-")
638 elif [ ${ch} -lt "129" ]; then
639 ch=$([ "${ch}" -lt "125" ] && echo "121" || echo "125")
640 bw_str=$([ "${ch}" -le "123" ] && echo "HT40+" || echo "HT40-")
641 elif [ ${ch} -lt "137" ]; then
642 ch=$([ "${ch}" -lt "133" ] && echo "129" || echo "133")
643 bw_str=$([ "${ch}" -le "131" ] && echo "HT40+" || echo "HT40-")
644 elif [ ${ch} -lt "145" ]; then
645 ch=$([ "${ch}" -lt "141" ] && echo "137" || echo "141")
646 bw_str=$([ "${ch}" -le "139" ] && echo "HT40+" || echo "HT40-")
647 elif [ ${ch} -lt "153" ]; then
648 ch=$([ "${ch}" -lt "149" ] && echo "145" || echo "149")
649 bw_str=$([ "${ch}" -le "147" ] && echo "HT40+" || echo "HT40-")
650 elif [ ${ch} -lt "161" ]; then
651 ch=$([ "${ch}" -lt "157" ] && echo "153" || echo "157")
652 bw_str=$([ "${ch}" -le "155" ] && echo "HT40+" || echo "HT40-")
653 elif [ ${ch} -lt "169" ]; then
654 ch=$([ "${ch}" -lt "165" ] && echo "161" || echo "165")
655 bw_str=$([ "${ch}" -le "163" ] && echo "HT40+" || echo "HT40-")
656 elif [ ${ch} -lt "177" ]; then
657 ch=$([ "${ch}" -lt "173" ] && echo "169" || echo "173")
658 bw_str=$([ "${ch}" -le "171" ] && echo "HT40+" || echo "HT40-")
659 elif [ ${ch} -lt "185" ]; then
660 ch=$([ "${ch}" -lt "181" ] && echo "177" || echo "181")
661 bw_str=$([ "${ch}" -le "179" ] && echo "HT40+" || echo "HT40-")
662 elif [ ${ch} -lt "193" ]; then
663 ch=$([ "${ch}" -lt "189" ] && echo "185" || echo "189")
664 bw_str=$([ "${ch}" -le "187" ] && echo "HT40+" || echo "HT40-")
665 elif [ ${ch} -lt "201" ]; then
666 ch=$([ "${ch}" -lt "197" ] && echo "193" || echo "197")
667 bw_str=$([ "${ch}" -le "195" ] && echo "HT40+" || echo "HT40-")
668 elif [ ${ch} -lt "209" ]; then
669 ch=$([ "${ch}" -lt "205" ] && echo "201" || echo "205")
670 bw_str=$([ "${ch}" -le "203" ] && echo "HT40+" || echo "HT40-")
671 elif [ ${ch} -lt "217" ]; then
672 ch=$([ "${ch}" -lt "213" ] && echo "209" || echo "213")
673 bw_str=$([ "${ch}" -le "211" ] && echo "HT40+" || echo "HT40-")
674 elif [ ${ch} -lt "225" ]; then
675 ch=$([ "${ch}" -lt "221" ] && echo "217" || echo "221")
676 bw_str=$([ "${ch}" -le "219" ] && echo "HT40+" || echo "HT40-")
677 elif [ ${ch} -lt "233" ]; then
678 ch=$([ "${ch}" -lt "229" ] && echo "225" || echo "229")
679 bw_str=$([ "${ch}" -le "227" ] && echo "HT40+" || echo "HT40-")
680 fi
681 ;;
682 "0")
683 local bw_str="HT20"
684 ;;
685 esac
developerb9b4cd12022-10-11 13:18:59 +0800686 fi
687
688 local control_freq=$(((ch - base_chan) * 5 + base_freq))
689 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
690}
691
692function convert_rxstat {
693 local res=$(do_cmd "mt76-test ${interface} dump stats")
694 local mdrdy=$(echo "${res}" | grep "rx_packets" | cut -d "=" -f 2)
695 local fcs_error=$(echo "${res}" | grep "rx_fcs_error" | cut -d "=" -f 2)
696 local rcpi=$(echo "${res}" | grep "last_rcpi" | cut -d "=" -f 2 | sed 's/,/ /g')
697 local ib_rssi=$(echo "${res}" | grep "last_ib_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
698 local wb_rssi=$(echo "${res}" | grep "last_wb_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
699 local rx_ok=$(expr ${mdrdy} - ${fcs_error})
700
701 write_dmesg "rcpi: ${rcpi}"
702 write_dmesg "fagc rssi ib: ${ib_rssi}"
703 write_dmesg "fagc rssi wb: ${wb_rssi}"
704 write_dmesg "all_mac_rx_mdrdy_cnt: ${mdrdy}"
705 write_dmesg "all_mac_rx_fcs_err_cnt: ${fcs_error}"
706 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
707}
708
709function set_mac_addr {
710 record_config ${cmd} ${param} ${iwpriv_file}
711
712 local addr1=$(get_config "ATEDA" ${iwpriv_file})
713 local addr2=$(get_config "ATESA" ${iwpriv_file})
714 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
715
716 if [ -z "${addr1}" ]; then
717 addr1="00:11:22:33:44:55"
718 fi
719 if [ -z "${addr2}" ]; then
720 addr2="00:11:22:33:44:55"
721 fi
722 if [ -z "${addr3}" ]; then
723 addr3="00:11:22:33:44:55"
724 fi
725
726 do_cmd "mt76-test phy${phy_idx} set mac_addrs=${addr1},${addr2},${addr3}"
727}
728
729function convert_ibf {
730 local cmd=$1
731 local param=$2
732 local new_cmd=""
733 local new_param=$(echo ${param} | sed s/":"/","/g)
734
735 case ${cmd} in
736 "ATETxBfInit")
737 new_cmd="init"
developerc5ce7502022-12-19 11:33:22 +0800738 new_param="1"
739 do_cmd "mt76-test phy${phy_idx} set state=idle"
740 ;;
741 "ATETxBfGdInit")
742 new_cmd="golden_init"
743 new_param="1"
developerb9b4cd12022-10-11 13:18:59 +0800744 do_cmd "mt76-test phy${phy_idx} set state=idle"
745 ;;
746 "ATEIBFPhaseComp")
747 new_cmd="phase_comp"
developerc5ce7502022-12-19 11:33:22 +0800748 new_param="${new_param}"
developerb9b4cd12022-10-11 13:18:59 +0800749 ;;
750 "ATEEBfProfileConfig")
751 new_cmd="ebf_prof_update"
752 ;;
753 "ATEIBfProfileConfig")
754 new_cmd="ibf_prof_update"
755 ;;
756 "ATEIBfInstCal")
757 new_cmd="phase_cal"
758 ;;
759 "ATEIBfGdCal")
developera46f6132024-03-26 14:09:54 +0800760 local group=${new_param:0:2}
761 local group_l_m_h=${new_param:3:2}
762 local band_idx=${new_param:6:2}
763 local cal_type=${new_param:9:2}
764 local version=${new_param:12}
765 local lna_level="00"
766
767 # only ibf 2.0 will set version, so add null check for backward compatibility
768 if [ -z $version ]; then
769 version="00"
770 fi
771
developerb9b4cd12022-10-11 13:18:59 +0800772 new_cmd="phase_cal"
developera46f6132024-03-26 14:09:54 +0800773 new_param="${group},${group_l_m_h},${band_idx},${cal_type},${lna_level},${version}"
developerb9b4cd12022-10-11 13:18:59 +0800774 ;;
775 "TxBfTxApply")
776 new_cmd="apply_tx"
777 ;;
778 "ATETxPacketWithBf")
779 local bf_on=${new_param:0:2}
780 local aid="01"
781 local wlan_idx=${new_param:3:2}
782 local update="00"
developera46f6132024-03-26 14:09:54 +0800783 local tx_count=${new_param:6}
developerb9b4cd12022-10-11 13:18:59 +0800784
785 new_cmd="tx_prep"
786 new_param="${bf_on},${aid},${wlan_idx},${update}"
developera46f6132024-03-26 14:09:54 +0800787 if [ "${tx_count}" = "00" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800788 new_param="${new_param} aid=1 tx_count=10000000 tx_length=1024"
789 else
developera46f6132024-03-26 14:09:54 +0800790 new_param="${new_param} aid=1 tx_count=${tx_count} tx_length=1024"
developerb9b4cd12022-10-11 13:18:59 +0800791 fi
792 do_cmd "mt76-test phy${phy_idx} set state=idle"
793 ;;
794 "TxBfProfileData20MAllWrite")
795 new_cmd="prof_update_all"
796 ;;
797 "ATEIBFPhaseE2pUpdate")
798 new_cmd="e2p_update"
799 ;;
developerc5ce7502022-12-19 11:33:22 +0800800 "ATEIBFPhaseVerify")
801 local group=${new_param:0:2}
802 local group_l_m_h=${new_param:3:2}
803 local band_idx=${new_param:6:2}
804 local phase_cal_type=${new_param:9:2}
805 local LNA_gain_level=${new_param:12:2}
806 local read_from_e2p=${new_param:15:2}
807
808 do_cmd "mt76-test phy${phy_idx} set txbf_act=phase_comp txbf_param=1,${band_idx},${group},${read_from_e2p},0"
809 new_cmd="phase_cal"
810 new_param="${group},${group_l_m_h},${band_idx},${phase_cal_type},${LNA_gain_level}"
811 ;;
812 "TxBfProfileTagRead")
813 new_cmd="pfmu_tag_read"
814 ;;
815 "TxBfProfileTagWrite")
816 new_cmd="pfmu_tag_write"
817 ;;
818 "TxBfProfileTagInValid")
819 new_cmd="set_invalid_prof"
820 ;;
821 "StaRecBfRead")
822 new_cmd="sta_rec_read"
823 ;;
824 "TriggerSounding")
825 new_cmd="trigger_sounding"
826 ;;
827 "StopSounding")
828 new_cmd="stop_sounding"
829 new_param="0"
830 ;;
developer7af0f762023-05-22 15:16:16 +0800831 "TxBfTxCmd")
832 new_cmd="txcmd"
833 ;;
developerc5ce7502022-12-19 11:33:22 +0800834 "ATEConTxETxBfGdProc")
835 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
836 local tx_rate_idx=${new_param:3:2}
837 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
838 local channel=${new_param:9:3}
839 local channel2=${new_param:13:3}
840 local band=${new_param:17}
841
842 new_cmd="ebf_golden_init"
843 do_ate_work "ATESTART"
844 do_cmd "mt76-test phy${phy_idx} set state=idle"
845 record_config "ATETXBW" ${bw} ${iwpriv_file}
846 convert_channel "${channel}:${band}"
847 if [ "${bw}" = "5" ]; then
848 new_param="1,1"
849 else
850 new_param="1,0"
851 fi
852 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_sgi=0"
853 ;;
854 "ATEConTxETxBfInitProc")
855 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
856 local tx_rate_idx=${new_param:3:2}
857 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
858 local tx_rate_nss=${new_param:9:2}
859 local tx_stream=${new_param:12:2}
860 local tx_power=${new_param:15:2}
developer7af0f762023-05-22 15:16:16 +0800861 local channel=$(echo ${new_param:18:3} | sed 's/^0//')
developerc5ce7502022-12-19 11:33:22 +0800862 local channel2=${new_param:22:3}
863 local band=${new_param:26:1}
developer7af0f762023-05-22 15:16:16 +0800864 local tx_length=$(echo ${new_param:28:5} | sed 's/^0//')
developerc5ce7502022-12-19 11:33:22 +0800865
866 new_cmd="ebf_init"
867 do_ate_work "ATESTART"
868 do_cmd "mt76-test phy${phy_idx} set state=idle"
869 record_config "ATETXBW" ${bw} ${iwpriv_file}
870 convert_channel "${channel}:${band}"
871 new_param="1"
872 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"
873 ;;
developerb9b4cd12022-10-11 13:18:59 +0800874 *)
875 esac
876
877 do_cmd "mt76-test phy${phy_idx} set txbf_act=${new_cmd} txbf_param=${new_param}"
878
879 if [ "${cmd}" = "ATETxPacketWithBf" ]; then
880 do_cmd "mt76-test phy${phy_idx} set state=tx_frames"
developerc5ce7502022-12-19 11:33:22 +0800881 elif [ "${cmd}" = "ATEConTxETxBfInitProc" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800882 local wlan_idx="1"
developerc8796032023-08-09 10:28:15 +0800883 if [ ${is_connac3} == "1" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800884 local wlan_idx=$((phy_idx+1))
885 fi
developerc5ce7502022-12-19 11:33:22 +0800886 do_cmd "mt76-test phy${phy_idx} set aid=1"
887 do_cmd "mt76-test phy${phy_idx} set txbf_act=stop_sounding txbf_param=1"
888 do_cmd "mt76-test phy${phy_idx} set txbf_act=update_ch txbf_param=1"
889 do_cmd "mt76-test phy${phy_idx} set txbf_act=ebf_prof_update txbf_param=0,0,0"
developerbb6ddff2023-03-08 17:22:32 +0800890 do_cmd "mt76-test phy${phy_idx} set txbf_act=apply_tx txbf_param=${wlan_idx},1,0,0,0"
developerc8796032023-08-09 10:28:15 +0800891 if [ ${is_connac3} == "1" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800892 do_cmd "mt76-test phy${phy_idx} set txbf_act=txcmd txbf_param=1,1,1"
893 fi
developerc5ce7502022-12-19 11:33:22 +0800894 do_cmd "mt76-test phy${phy_idx} set txbf_act=pfmu_tag_read txbf_param=0,1"
developerbb6ddff2023-03-08 17:22:32 +0800895 do_cmd "mt76-test phy${phy_idx} set txbf_act=sta_rec_read txbf_param=${wlan_idx}"
896 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=0,1,0,${wlan_idx},0,0,0"
897 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=2,1,ff,${wlan_idx},0,0,0"
developerc5ce7502022-12-19 11:33:22 +0800898 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
899 elif [ "${cmd}" = "ATEConTxETxBfGdProc" ]; then
900 do_cmd "mt76-test phy${phy_idx} set aid=1"
901 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
902 elif [ "${cmd}" = "ATETxBfInit" ]; then
903 do_cmd "mt76-test phy${phy_idx} set aid=1"
904 elif [ "${cmd}" = "ATETxBfGdInit" ]; then
905 do_cmd "mt76-test phy${phy_idx} set aid=1"
developerf9b00212023-07-31 12:27:06 +0800906 elif [ "${cmd}" = "ATEIBFPhaseE2pUpdate" ]; then
907 do_cmd "atenl -i phy${phy_idx} -c \"eeprom ibf sync\""
developerb9b4cd12022-10-11 13:18:59 +0800908 fi
909}
910
developer9a587882023-07-17 11:11:44 +0800911function convert_ruinfo {
912 local new_param=$1
913
914 do_cmd "mt76-test phy${phy_idx} set state=idle"
915 while [ -n "$new_param" ]
916 do
917 [ ${new_param:1:1} = ':' ] && {
918 new_param=${new_param:2}
919 }
920 local oIFS="$IFS"; IFS=":"; set -- $new_param; IFS="$oIFS"
921
922 parsing_ruinfo $new_param
923 new_param=${new_param:${#1}+1}
924 done
925}
926
927function parsing_ruinfo {
928 local new_param=$1
929 local oIFS="$IFS"; IFS="-:"; set -- $new_param; IFS="$oIFS"
930
931 # $7 is Start spatial stream and it should be 0, $9 is alpha, not used
932 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\
933 tx_rate_idx=$4 tx_rate_ldpc=$5 tx_rate_nss=$6 tx_length=$8"
934}
935
developerb403ad02022-11-08 10:16:29 +0800936function convert_dfs {
937 local cmd=$1
938 local param=$2
939
940 case ${cmd} in
941 "DfsRxCtrl")
942 local offchan_ch="$(echo $param | cut -d ':' -f1)"
943 local offchan_bw="$(echo $param | cut -d ':' -f2)"
944
developerc9333e12023-04-06 18:07:42 +0800945 if [ "$offchan_bw" = "0" ]; then
946 offchan_bw="20"
947 elif [ "$offchan_bw" = "1" ]; then
948 offchan_bw="40"
949 elif [ "$offchan_bw" = "2" ]; then
950 offchan_bw="80"
951 elif [ "$offchan_bw" = "3" ]; then
952 offchan_bw="160"
953 fi
developerb403ad02022-11-08 10:16:29 +0800954
developerc9333e12023-04-06 18:07:42 +0800955 do_cmd "mt76-test phy${phy_idx} set state=idle"
956 do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
developerb403ad02022-11-08 10:16:29 +0800957 ;;
958 "DfsRxHist")
959 local ipi_th="$(echo $param | cut -d ':' -f 1)"
960 local ipi_period="$(echo $param | cut -d ':' -f 2)"
developerc9333e12023-04-06 18:07:42 +0800961 local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
developerb403ad02022-11-08 10:16:29 +0800962
developerc9333e12023-04-06 18:07:42 +0800963 if [ -z $ipi_antenna ]; then
964 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
965 else
966 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
967 fi
developerb403ad02022-11-08 10:16:29 +0800968 ;;
969 *)
970 esac
971}
972
developerb9b4cd12022-10-11 13:18:59 +0800973function do_ate_work() {
974 local ate_cmd=$1
975
976 case ${ate_cmd} in
977 "ATESTART")
978 local if_str=$(ifconfig | grep mon${phy_idx})
979
980 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
981 echo "ATE already starts."
982 else
983 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
developer3f784572023-01-31 15:21:28 +0800984
985 if [ $phy_idx -ge $SOC_start_idx ]; then
986 local end_idx=$SOC_end_idx
987 local start_idx=$SOC_start_idx
988 else
989 local end_idx=$((SOC_start_idx-1))
990 local start_idx="0"
991 fi
992
993 for phy_index in $( seq $start_idx $end_idx )
994 do
995 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
996 local prev_phy_index=$((phy_index-1))
997 local if_num=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep -c Interface)
998 local j="1"
999 # avoid del_if_count reset to 0 when start ate on another band in dbdc case
1000 local del_if_count=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
1001 if [ -z "${del_if_count}" ]; then
1002 local del_if_count="0"
1003 fi
1004
1005 for if_count in $( seq 1 $if_num )
1006 do
1007 local del_if=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep Interface | sed -n ${j}p | cut -d " " -f 2)
1008 if [ ! -z "${del_if}" ] && [[ "$del_if" != *"mon"* ]]; then
1009 do_cmd "iw dev ${del_if} del"
1010 del_if_count=$((del_if_count+1))
1011 # handle the case of multiple interface in a phy
1012 record_config "DEL_IF${phy_index}-${del_if_count}" ${del_if} ${interface_file}
1013 else
1014 # j add 1 to skip mon interface
1015 j=$((j+1))
1016 fi
1017 done
1018 record_config "DEL_IF${phy_index}_NUM" ${del_if_count} ${interface_file}
1019 done
1020
developerb9b4cd12022-10-11 13:18:59 +08001021 do_cmd "ifconfig mon${phy_idx} up"
1022 do_cmd "iw reg set VV"
1023 fi
1024 ;;
1025 "ATESTOP")
1026 local if_str=$(ifconfig | grep mon${phy_idx})
1027
1028 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
1029 echo "ATE does not start."
1030 else
1031 do_cmd "mt76-test ${interface} set state=off"
1032 do_cmd "iw dev mon${phy_idx} del"
developer3f784572023-01-31 15:21:28 +08001033
1034 if [ $phy_idx -ge $SOC_start_idx ]; then
1035 local end_idx=$SOC_end_idx
1036 local start_idx=$SOC_start_idx
1037 else
1038 local end_idx=$((SOC_start_idx-1))
1039 local start_idx="0"
1040 fi
1041
1042 # first check its phy and dbdc band phy has monitor interface or not
1043 # if has at lease one mon interface, then skip adding back normal interface
1044 local has_mon="0"
1045 for phy_index in $( seq $start_idx $end_idx )
1046 do
1047 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
1048 local prev_phy_index=$((phy_index-1))
1049 local has_mon_phy=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep "Interface mon")
1050 # if this phy interface has mon interface
1051 if [ ! -z "${has_mon_phy}" ]; then
1052 local has_mon="1"
1053 fi
1054 done
1055
1056 for phy_index in $( seq $start_idx $end_idx )
1057 do
1058 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
1059 local prev_phy_index=$((phy_index-1))
1060 local j="1"
1061 local add_if_num=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
1062 if [ -z "${add_if_num}" ]; then
1063 local add_if_num="0"
1064 fi
1065 # if this phy interface (including its dbdc phy) has no mon interface and can find deleted interface in file, then add it back
1066 if [ "${has_mon}" == "0" ] && [ $add_if_num -ge "1" ]; then
1067 local if_index=$add_if_num
1068 # add interface backwards
1069 while [ $if_index -gt "0" ]
1070 do
1071 local add_if=$(get_config "DEL_IF${phy_index}-${if_index}" ${interface_file})
1072 do_cmd "iw phy phy${phy_index} interface add ${add_if} type managed"
1073 # remove the deleted interface in interface_file since it is added back
1074 sed -i "/DEL_IF${phy_index}-${if_index}=/d" ${interface_file}
1075 if_index=$((if_index-1))
1076 done
1077 # remove the number of deleted interface in interface_file since it is all added back
1078 sed -i "/DEL_IF${phy_index}_NUM=/d" ${interface_file}
1079 fi
1080 done
1081
developerb9b4cd12022-10-11 13:18:59 +08001082 do_cmd "mt76-test ${interface} set aid=0"
1083 fi
1084
developer13655da2023-01-10 19:53:25 +08001085 if [ ${phy_idx} -lt ${SOC_start_idx} ]; then
developerb9b4cd12022-10-11 13:18:59 +08001086 sed -i '/_PCIE=/d' ${iwpriv_file}
developer13655da2023-01-10 19:53:25 +08001087 elif [ ${phy_idx} -ge ${SOC_start_idx} ]; then
1088 sed -i '/_SOC=/d' ${iwpriv_file}
developerb9b4cd12022-10-11 13:18:59 +08001089 fi
1090 ;;
1091 "TXCOMMIT")
1092 do_cmd "mt76-test ${interface} set aid=1"
1093 ;;
1094 "TXFRAME")
1095 do_cmd "mt76-test ${interface} set state=tx_frames"
1096 ;;
1097 "TXSTOP"|"RXSTOP")
1098 do_cmd "mt76-test ${interface} set state=idle"
1099 ;;
1100 "TXREVERT")
1101 do_cmd "mt76-test ${interface} set aid=0"
1102 ;;
1103 "RXFRAME")
1104 do_cmd "mt76-test ${interface} set state=rx_frames"
1105 ;;
1106 "TXCONT")
1107 do_cmd "mt76-test ${interface} set state=tx_cont"
1108 ;;
1109 "GROUPREK")
1110 do_cmd "mt76-test ${interface} set state=group_prek"
1111 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
1112 ;;
1113 "GROUPREKDump")
1114 do_cmd "mt76-test ${interface} set state=group_prek_dump"
1115 ;;
1116 "GROUPREKClean")
1117 do_cmd "mt76-test ${interface} set state=group_prek_clean"
1118 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
1119 ;;
1120 "DPD2G")
1121 do_cmd "mt76-test ${interface} set state=dpd_2g"
1122 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
1123 ;;
1124 "DPD5G")
1125 do_cmd "mt76-test ${interface} set state=dpd_5g"
1126 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
1127 ;;
1128 "DPD6G")
1129 do_cmd "mt76-test ${interface} set state=dpd_6g"
1130 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
1131 ;;
1132 "DPDDump")
1133 do_cmd "mt76-test ${interface} set state=dpd_dump"
1134 ;;
1135 "DPDClean")
1136 do_cmd "mt76-test ${interface} set state=dpd_clean"
1137 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
1138 ;;
1139 *)
1140 print_debug "skip ${ate_cmd}"
1141 ;;
1142 esac
1143}
1144
developer13655da2023-01-10 19:53:25 +08001145function dump_usage {
1146 echo "Usage:"
1147 echo " mwctl <interface> set csi ctrl=<opt1>,<opt2>,<opt3>,<opt4> (macaddr=<macaddr>)"
1148 echo " mwctl <interface> set csi interval=<interval (us)>"
1149 echo " mwctl <interface> dump csi <packet num> <filename>"
1150 echo " mwctl <interface> set amnt <index>(0x0~0xf) <mac addr>(xx:xx:xx:xx:xx:xx)"
1151 echo " mwctl <interface> dump amnt <index> (0x0~0xf or 0xff)"
1152 echo " mwctl <interface> set ap_rfeatures he_gi=<val>"
1153 echo " mwctl <interface> set ap_rfeatures he_ltf=<val>"
1154 echo " mwctl <interface> set ap_rfeatures trig_type=<enable>,<val> (val: 0-7)"
1155 echo " mwctl <interface> set ap_rfeatures ack_policy=<val> (val: 0-4)"
1156 echo " mwctl <interface> set ap_wireless fixed_mcs=<val>"
1157 echo " mwctl <interface> set ap_wireless ofdma=<val> (0: disable, 1: DL, 2: UL)"
1158 echo " mwctl <interface> set ap_wireless nusers_ofdma=<val>"
1159 echo " mwctl <interface> set ap_wireless ppdu_type=<val> (0: SU, 1: MU, 4: LEGACY)"
1160 echo " mwctl <interface> set ap_wireless add_ba_req_bufsize=<val>"
1161 echo " mwctl <interface> set ap_wireless mimo=<val> (0: DL, 1: UL)"
1162 echo " mwctl <interface> set ap_wireless ampdu=<enable>"
1163 echo " mwctl <interface> set ap_wireless amsdu=<enable>"
1164 echo " mwctl <interface> set ap_wireless cert=<enable>"
developer2c78ce72023-02-24 11:26:12 +08001165 echo " mwctl <interface> set mu onoff=<val> (bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0))"
developer13655da2023-01-10 19:53:25 +08001166 echo " mwctl <interface> dump phy_capa"
1167}
1168
developer092b55c2023-01-18 18:20:58 +08001169function register_handler {
1170
developer9237f442024-06-14 17:13:04 +08001171 local offset=$1
1172 local val=$2
1173 local cmd=$3
developer092b55c2023-01-18 18:20:58 +08001174 local w_cmd="write"
1175
developer9237f442024-06-14 17:13:04 +08001176 regidx=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/regidx
1177 regval=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/regval
developer092b55c2023-01-18 18:20:58 +08001178
1179 echo ${offset} > ${regidx}
1180 if [[ "${cmd}" == "${w_cmd}" ]]; then
1181 echo ${val} > ${regval}
1182 fi
1183
1184 res=$(cat ${regval} | cut -d 'x' -f 2)
1185 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
1186}
1187
developerb9b4cd12022-10-11 13:18:59 +08001188# main start here
developer3f784572023-01-31 15:21:28 +08001189parse_sku
developer13655da2023-01-10 19:53:25 +08001190if [ -z ${interface} ]; then
1191 dump_usage
1192 exit
1193elif [[ ${interface} == "ra"* ]]; then
developerb9b4cd12022-10-11 13:18:59 +08001194 convert_interface $interface
developerbb6ddff2023-03-08 17:22:32 +08001195elif [[ ${interface} == "phy" ]]; then
1196 # handle mwctl phy phy0 e2p ... case
1197 interface=$2
1198 cmd_type=$3
1199 full_cmd=$4
developerb9b4cd12022-10-11 13:18:59 +08001200fi
1201
developer9237f442024-06-14 17:13:04 +08001202# get main phy idx
1203if [ "${phy_idx}" -ge "${SOC_start_idx}" ]; then
1204 main_phy_idx=${SOC_start_idx}
1205fi
1206
developerb9b4cd12022-10-11 13:18:59 +08001207tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
1208
1209if [ ! -z ${tmp_work_mode} ]; then
1210 work_mode=${tmp_work_mode}
1211fi
1212
1213cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
1214param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
developera20cdc22024-05-31 18:57:31 +08001215mld=$(iw dev | grep 'link ID')
developerb9b4cd12022-10-11 13:18:59 +08001216
1217if [ "${cmd_type}" = "set" ]; then
1218 skip=0
1219 case ${cmd} in
developer13655da2023-01-10 19:53:25 +08001220 ## In wifi 7 chipset, testmode & vendor command both use mwctl
1221 ## Therefore this wrapper would translate it to either mt76-test or mt76-vendor based on the attribute of the command
1222 ## Translate to mt76-vendor command
developer327aa322023-07-10 13:49:56 +08001223 "csi"|"amnt"|"ap_rfeatures"|"ap_wireless"|"mu"|"set_muru_manual_config")
developera20cdc22024-05-31 18:57:31 +08001224 cert_cmd="$*"
developer42c7a432024-07-12 14:39:29 +08001225
1226 if [ ! -z "$mld" ]; then
1227 mld_interface=$(iw dev | grep Interface | awk '{print $2}')
1228 if [ $cmd == "ap_rfeatures" ] || [ "$cmd" == "ap_wireless" ]; then
1229
1230 band_number=$(echo "$cert_cmd" | grep -o 'band[0-9]*')
1231
1232 links_info_base="/sys/kernel/debug/ieee80211/phy0/netdev"
1233 links_info_intf="${mld_interface}/mt76_links_info"
1234 links_info_cmd="${links_info_base}:${links_info_intf}"
1235
1236 band_link_id_info=$(
1237 cat "$links_info_cmd" | grep "${band_number}_link_id"
1238 )
1239 band_link_id=$(
1240 echo "$band_link_id_info" | awk -F'=' '{print $2}' | tr -d ' '
1241 )
1242
1243 cmd_w_link_id=$(echo $* | sed "s/band[0-9]/& -l ${band_link_id}/g")
1244 cert_cmd=${cmd_w_link_id}
1245
1246 fi
1247 ## convert bandX to mld interface name
1248 cert_cmd="$(echo ${cert_cmd} | sed 's/band[0-9]/${mld_interface}/')"
1249 fi
1250
developerc8796032023-08-09 10:28:15 +08001251 if [ ${is_connac3} == "1" ]; then
developera20cdc22024-05-31 18:57:31 +08001252 hostapd_cmd="$(echo $cert_cmd | sed 's/set/raw/')"
developer1475cf22023-05-05 13:45:43 +08001253 do_cmd "hostapd_cli -i $hostapd_cmd"
developerbb6ddff2023-03-08 17:22:32 +08001254 else
developera20cdc22024-05-31 18:57:31 +08001255 do_cmd "mt76-vendor $cert_cmd"
developerbb6ddff2023-03-08 17:22:32 +08001256 fi
1257 skip=1
developer13655da2023-01-10 19:53:25 +08001258 ;;
developer42c7a432024-07-12 14:39:29 +08001259 "txbftxsndinfo"|"TxBfTxSndInfo")
1260 cert_cmd="$*"
1261 cmd_setting=$(echo $cert_cmd | awk -F'=' '{print $2}')
1262 snd_cmd_base="/sys/kernel/debug/ieee80211/phy0/mt76/band0/bf_txsnd_info"
1263 mt76_snd_cmd="echo $cmd_setting > $snd_cmd_base"
1264 do_cmd "$mt76_snd_cmd"
1265 skip=1
1266 ;;
1267 "muruDbgInfo")
1268 cert_cmd="$*"
1269 cmd_setting=$(echo $cert_cmd | awk -F'=' '{print $2}')
1270 muru_cmd_base="/sys/kernel/debug/ieee80211/phy0/mt76/muru_dbg"
1271 mt76_muru_cmd="echo $cmd_setting > $muru_cmd_base"
1272 do_cmd "$mt76_muru_cmd"
1273 skip=1
1274 ;;
developerb9b4cd12022-10-11 13:18:59 +08001275 "ATE")
1276 do_ate_work ${param}
1277
1278 skip=1
1279 ;;
1280 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
1281 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
1282 cmd_new=$(simple_convert ${cmd})
1283 if [ "${param_new}" = "undefined" ]; then
1284 echo "unknown cmd: ${cmd}"
1285 exit
1286 fi
1287 param_new=${param}
developerc5ce7502022-12-19 11:33:22 +08001288 if [ "${cmd}" = "ATETXCNT" ] && [ "${param}" = "0" ]; then
developer15c355d2023-03-21 17:28:34 +08001289 param_new="0xFFFFFFFF"
developerc5ce7502022-12-19 11:33:22 +08001290 fi
developerb9b4cd12022-10-11 13:18:59 +08001291 ;;
1292 "ATETXANT"|"ATERXANT")
1293 cmd_new="tx_antenna"
1294 param_new=${param}
1295 ;;
1296 "ATETXGI")
developerc8796032023-08-09 10:28:15 +08001297 if [ ${is_connac3} == "0" ]; then
developerbb6ddff2023-03-08 17:22:32 +08001298 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
1299 convert_gi ${tx_mode} ${param}
1300 skip=1
1301 else
1302 cmd_new="tx_rate_sgi"
1303 param_new=${param}
1304 fi
developerb9b4cd12022-10-11 13:18:59 +08001305 ;;
1306 "ATETXMODE")
1307 cmd_new="tx_rate_mode"
1308 param_new=$(convert_tx_mode ${param})
1309 if [ "${param_new}" = "undefined" ]; then
1310 echo "unknown tx mode"
1311 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
1312 exit
1313 else
1314 record_config ${cmd} ${param} ${iwpriv_file}
1315 fi
1316 ;;
developerbb6ddff2023-03-08 17:22:32 +08001317 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3"|"ATETXPOW")
developerb9b4cd12022-10-11 13:18:59 +08001318 cmd_new="tx_power"
developerbb6ddff2023-03-08 17:22:32 +08001319 if [ "${param}" == "127" ]; then
1320 # for iTest verification
1321 exit
1322 fi
developerb9b4cd12022-10-11 13:18:59 +08001323 param_new="${param},0,0,0"
1324 ;;
developerbb6ddff2023-03-08 17:22:32 +08001325 "ATEMUAID")
1326 cmd_new="aid"
1327 param_new=${param}
1328 ;;
developerb9b4cd12022-10-11 13:18:59 +08001329 "ATETXBW")
1330 record_config ${cmd} ${param} ${iwpriv_file}
1331 skip=1
1332 ;;
1333 "ATECHANNEL")
1334 convert_channel ${param}
1335 skip=1
1336 ;;
1337 "ATERXSTAT")
1338 convert_rxstat
1339 skip=1
1340 ;;
1341 "ATECTRLBANDIDX")
1342 change_band_idx ${param}
1343 skip=1
1344 ;;
1345 "ATEDA"|"ATESA"|"ATEBSSID")
1346 set_mac_addr ${cmd} ${param}
1347 skip=1
1348 ;;
developerb403ad02022-11-08 10:16:29 +08001349 "DfsRxCtrl"|"DfsRxHist")
1350 convert_dfs ${cmd} ${param}
1351 skip=1
1352 ;;
developerc5ce7502022-12-19 11:33:22 +08001353 "ATETxBfInit"|"ATETxBfGdInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
1354 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"| \
developer7af0f762023-05-22 15:16:16 +08001355 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate"|"TriggerSounding"|"StopSounding"|"TxBfTxCmd"| \
developerc5ce7502022-12-19 11:33:22 +08001356 "StaRecBfRead"|"TxBfProfileTagInValid"|"TxBfProfileTagWrite"|"TxBfProfileTagRead"| \
1357 "ATEIBFPhaseVerify"|"ATEConTxETxBfGdProc"|"ATEConTxETxBfInitProc")
developerb9b4cd12022-10-11 13:18:59 +08001358 convert_ibf ${cmd} ${param}
1359 skip=1
1360 ;;
1361 "bufferMode")
1362 if [ "${param}" = "2" ]; then
1363 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
1364 fi
1365 skip=1
1366 ;;
1367 "ResetCounter"|"ATERXSTATRESET")
1368 skip=1
1369 ;;
1370 "WORKMODE")
1371 record_config "WORKMODE" ${param} ${iwpriv_file}
1372 echo "Entering ${param} mode in iwpriv"
1373 skip=1
1374 ;;
developer9a587882023-07-17 11:11:44 +08001375 "ATERUINFO")
1376 convert_ruinfo ${param}
1377 skip=1
1378 ;;
developerb9b4cd12022-10-11 13:18:59 +08001379 *)
1380 print_debug "Unknown command to set: ${cmd}"
1381 skip=1
1382 esac
1383
1384 if [ "${skip}" != "1" ]; then
1385 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
1386 fi
1387
1388elif [ "${cmd_type}" = "show" ]; then
developerc5ce7502022-12-19 11:33:22 +08001389 if [ "${cmd}" = "wtbl" ]; then
developer9237f442024-06-14 17:13:04 +08001390 wlan_idx=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/wlan_idx
1391 wtbl_info=/sys/kernel/debug/ieee80211/phy${main_phy_idx}/mt76/wtbl_info
developerc5ce7502022-12-19 11:33:22 +08001392
1393 do_cmd "echo ${param} > ${wlan_idx}"
1394 do_cmd "cat ${wtbl_info}"
developerbb6ddff2023-03-08 17:22:32 +08001395 elif [ "${cmd}" = "ATERXSTAT" ]; then
1396 convert_rxstat
developerc5ce7502022-12-19 11:33:22 +08001397 else
1398 do_cmd "mt76-test ${interface} dump"
1399 do_cmd "mt76-test ${interface} dump stats"
1400 fi
developerb9b4cd12022-10-11 13:18:59 +08001401
1402elif [ "${cmd_type}" = "e2p" ]; then
developer13655da2023-01-10 19:53:25 +08001403 # support multiple read write
developerb9b4cd12022-10-11 13:18:59 +08001404 # eeprom offset write
1405 if [[ ${full_cmd} == *"="* ]]; then
developer13655da2023-01-10 19:53:25 +08001406 IFS=,
1407 for tuple in $full_cmd
1408 do
1409 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1410 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1411 offset=$(printf "0x%s" ${cmd})
1412 val=$(printf "0x%s" ${param})
1413 tmp=$((${val} & 0xff))
1414 tmp=$(printf "0x%x" ${tmp})
1415 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developerb9b4cd12022-10-11 13:18:59 +08001416
developer13655da2023-01-10 19:53:25 +08001417 offset=$((${offset}))
1418 offset=$(expr ${offset} + "1")
1419 offset=$(printf "0x%x" ${offset})
1420 tmp=$(((${val} >> 8) & 0xff))
1421 tmp=$(printf "0x%x" ${tmp})
1422 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
1423 done
developerb9b4cd12022-10-11 13:18:59 +08001424 else
developer13655da2023-01-10 19:53:25 +08001425 IFS=,
1426 for tuple in $full_cmd
1427 do
1428 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1429 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1430 offset=$(printf "0x%s" ${cmd})
1431 val=$(printf "0x%s" ${param})
1432 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
1433 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developerb9b4cd12022-10-11 13:18:59 +08001434
developer13655da2023-01-10 19:53:25 +08001435 tmp=$(printf "0x%s" ${param})
1436 tmp=$((${tmp}))
1437 param2=$(expr ${tmp} + "1")
1438 param2=$(printf "%x" ${param2})
1439 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
1440 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developerb9b4cd12022-10-11 13:18:59 +08001441
developer13655da2023-01-10 19:53:25 +08001442 param=$(printf "0x%s" ${param})
1443 param=$(printf "%04x" ${param})
1444 param=$(echo $param | tr 'a-z' 'A-Z')
1445 printf "%s e2p:\n" ${interface_ori}
1446 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
1447 done
developerb9b4cd12022-10-11 13:18:59 +08001448 fi
1449
1450elif [ "${cmd_type}" = "mac" ]; then
developerb9b4cd12022-10-11 13:18:59 +08001451 offset=$(printf "0x%s" ${cmd})
1452 val=$(printf "0x%s" ${param})
1453
developerb9b4cd12022-10-11 13:18:59 +08001454 # reg write
1455 if [[ ${full_cmd} == *"="* ]]; then
developer9237f442024-06-14 17:13:04 +08001456 register_handler ${offset} ${val} "write"
developer092b55c2023-01-18 18:20:58 +08001457 else
1458 start_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 1)
1459 end_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 2)
1460 loop=$((0x${end_addr}-0x${start_addr}))
developerb9b4cd12022-10-11 13:18:59 +08001461
developer092b55c2023-01-18 18:20:58 +08001462 if [[ ${loop} == "0" ]]; then
developer9237f442024-06-14 17:13:04 +08001463 register_handler ${offset} ${val}
developer092b55c2023-01-18 18:20:58 +08001464 else
1465 i=0
1466 while [ $i -le $loop ]; do
1467 addr=$((0x${start_addr}+$i))
1468 offset=$(printf "0x%x" ${addr})
developer9237f442024-06-14 17:13:04 +08001469 register_handler ${offset} ${val}
developer092b55c2023-01-18 18:20:58 +08001470 i=$(($i + 4))
1471 done
1472 fi
1473 fi
developerb9b4cd12022-10-11 13:18:59 +08001474
developer13655da2023-01-10 19:53:25 +08001475## dump command is only for vendor commands
1476elif [ "${cmd_type}" = "dump" ]; then
1477 do_cmd "mt76-vendor $*"
developerc9333e12023-04-06 18:07:42 +08001478elif [ "${cmd_type}" = "switch" ]; then
developer2299de92023-10-27 15:40:47 +08001479 eeprom_mode_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom_mode
developerc9333e12023-04-06 18:07:42 +08001480 eeprom_mode=$(cat ${eeprom_mode_file} | grep "mode" | sed -n 2p | cut -d " " -f 4)
1481 eeprom_testmode_offset="1af"
1482 testmode_enable="0"
1483
developerc8796032023-08-09 10:28:15 +08001484 if [ ${is_connac3} == "0" ]; then
developerc9333e12023-04-06 18:07:42 +08001485 return
1486 fi
1487
1488 if [ "${cmd}" = "testmode" ]; then
1489 testmode_enable="1"
developerdad89a32024-04-29 14:17:17 +08001490 do_cmd "wifi down"
1491 do_cmd "uci set wireless.radio0.disabled=1"
1492 do_cmd "uci set wireless.radio1.disabled=1"
1493 do_cmd "uci set wireless.radio2.disabled=1"
1494 do_cmd "uci commit"
developerc9333e12023-04-06 18:07:42 +08001495 fi
1496
1497 if [ "${eeprom_mode}" = "flash" ]; then
1498 ## flash mode should set eeprom testmode offset bit
1499 ## efuse/bin file/default bin mode rely on module param only
1500 do_cmd "atenl -i ${interface} -c \"eeprom set 0x${eeprom_testmode_offset}=0x${testmode_enable}\""
1501 ## If has no precal, it would not affect
1502 do_cmd "atenl -i ${interface} -c \"eeprom precal sync\""
1503 do_cmd "atenl -i ${interface} -c \"sync eeprom all\""
1504 fi
1505
1506 do_cmd "rmmod mt7996e"
1507 do_cmd "rmmod mt76-connac-lib"
1508 do_cmd "rmmod mt76"
1509 do_cmd "rmmod mac80211"
1510 do_cmd "rmmod cfg80211"
1511 do_cmd "rmmod compat"
1512 do_cmd "insmod compat"
1513 do_cmd "insmod cfg80211"
1514 do_cmd "insmod mac80211"
1515 do_cmd "insmod mt76"
1516 do_cmd "insmod mt76-connac-lib"
1517 do_cmd "insmod mt7996e testmode_enable=${testmode_enable}"
1518 do_cmd "sleep 5"
1519 do_cmd "killall hostapd"
1520 do_cmd "killall netifd"
developerb9b4cd12022-10-11 13:18:59 +08001521else
1522 echo "Unknown command"
1523fi