blob: 8b0d76fde4e9a6dfd27aa53055d59348bd16ab1d [file] [log] [blame]
developer4616dbd2022-10-11 13:18:59 +08001#!/bin/ash
2
3interface=$1 # phy0/phy1/ra0
developerb9a96602023-01-10 19:53:25 +08004cmd_type=$2 # set/show/e2p/mac/dump
developer4616dbd2022-10-11 13:18:59 +08005full_cmd=$3
6interface_ori=${interface}
developerb9a96602023-01-10 19:53:25 +08007SOC_start_idx="0"
developercf3c4c72023-01-31 15:21:28 +08008SOC_end_idx="0"
developerb9a96602023-01-10 19:53:25 +08009is_eagle="0"
developer4616dbd2022-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')
15
16function do_cmd() {
17 case ${work_mode} in
18 "RUN")
19 eval "$1"
20 ;;
21 "PRINT")
22 echo "$1"
23 ;;
24 "DEBUG")
developer4616dbd2022-10-11 13:18:59 +080025 echo "$1"
developerb81e95d2022-11-08 10:16:29 +080026 eval "$1"
developer4616dbd2022-10-11 13:18:59 +080027 ;;
28 esac
29}
30
31function print_debug() {
32 if [ "${work_mode}" = "DEBUG" ]; then
33 echo "$1"
34 fi
35}
36
37function write_dmesg() {
38 echo "$1" > /dev/kmsg
39}
40
41function record_config() {
42 local config=$1
43 local tmp_file=$3
44
developerb9a96602023-01-10 19:53:25 +080045 # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
developercf3c4c72023-01-31 15:21:28 +080046 if [ ${tmp_file} != ${interface_file} ]; then
developerb9a96602023-01-10 19:53:25 +080047 if [ $phy_idx -lt $SOC_start_idx ]; then
developer4616dbd2022-10-11 13:18:59 +080048 config="${config}_PCIE"
developerb9a96602023-01-10 19:53:25 +080049 elif [ $phy_idx -ge $SOC_start_idx ]; then
50 config="${config}_SOC"
developer4616dbd2022-10-11 13:18:59 +080051 fi
52 fi
53
54 if [ -f ${tmp_file} ]; then
55 if grep -q ${config} ${tmp_file}; then
56 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
57 else
58 echo "${config}=$2" >> ${tmp_file}
59 fi
60 else
61 echo "${config}=$2" >> ${tmp_file}
62 fi
63}
64
65function get_config() {
66 local config=$1
67 local tmp_file=$2
68
69 if [ ! -f ${tmp_file} ]; then
70 echo ""
71 return
72 fi
73
developerb9a96602023-01-10 19:53:25 +080074 # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
developercf3c4c72023-01-31 15:21:28 +080075 if [ ${tmp_file} != ${interface_file} ]; then
developerb9a96602023-01-10 19:53:25 +080076 if [ $phy_idx -lt $SOC_start_idx ]; then
developer4616dbd2022-10-11 13:18:59 +080077 config="${config}_PCIE"
developerb9a96602023-01-10 19:53:25 +080078 elif [ $phy_idx -ge $SOC_start_idx ]; then
79 config="${config}_SOC"
developer4616dbd2022-10-11 13:18:59 +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)"
85 else
86 echo ""
87 fi
88}
89
developercf3c4c72023-01-31 15:21:28 +080090function parse_sku {
developerb9a96602023-01-10 19:53:25 +080091 SOC_start_idx=$(get_config "STARTIDX" ${interface_file})
developercf3c4c72023-01-31 15:21:28 +080092 SOC_end_idx=$(get_config "ENDIDX" ${interface_file})
developerb9a96602023-01-10 19:53:25 +080093 is_eagle=$(get_config "IS_EAGLE" ${interface_file})
developer4616dbd2022-10-11 13:18:59 +080094 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
developercf3c4c72023-01-31 15:21:28 +080095 if [ -z "${SOC_start_idx}" ] || [ -z "${SOC_end_idx}" ] || [ -z "${is_eagle}" ]; then
developer4616dbd2022-10-11 13:18:59 +080096 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
developerb9a96602023-01-10 19:53:25 +080097 SOC_start_idx="2"
developercf3c4c72023-01-31 15:21:28 +080098 SOC_end_idx="3"
developerb9a96602023-01-10 19:53:25 +080099 is_eagle="0"
developer4616dbd2022-10-11 13:18:59 +0800100 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
developerb9a96602023-01-10 19:53:25 +0800101 SOC_start_idx="1"
developercf3c4c72023-01-31 15:21:28 +0800102 SOC_end_idx="2"
developerb9a96602023-01-10 19:53:25 +0800103 is_eagle="0"
developer4616dbd2022-10-11 13:18:59 +0800104 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
developerb9a96602023-01-10 19:53:25 +0800105 SOC_start_idx="0"
developercf3c4c72023-01-31 15:21:28 +0800106 SOC_end_idx="1"
developerb9a96602023-01-10 19:53:25 +0800107 is_eagle="0"
108 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then
109 SOC_start_idx="0"
developercf3c4c72023-01-31 15:21:28 +0800110 SOC_end_idx="2"
developerb9a96602023-01-10 19:53:25 +0800111 is_eagle="1"
developer4616dbd2022-10-11 13:18:59 +0800112 else
113 echo "Interface Conversion Failed!"
114 echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
developercf3c4c72023-01-31 15:21:28 +0800115 echo "For AX6000:"
116 echo " echo STARTIDX=0 >> ${interface_file}"
117 echo " echo ENDIDX=1 >> ${interface_file}"
118 echo " echo IS_EAGLE=0 >> ${interface_file}"
119 echo "For AX7800:"
120 echo " echo STARTIDX=2 >> ${interface_file}"
121 echo " echo ENDIDX=3 >> ${interface_file}"
122 echo " echo IS_EAGLE=0 >> ${interface_file}"
123 echo "For AX8400:"
124 echo " echo STARTIDX=1 >> ${interface_file}"
125 echo " echo ENDIDX=2 >> ${interface_file}"
126 echo " echo IS_EAGLE=0 >> ${interface_file}"
127 echo "For Eagle:"
128 echo " echo STARTIDX=1 >> ${interface_file}"
129 echo " echo ENDIDX=2 >> ${interface_file}"
130 echo " echo IS_EAGLE=1 >> ${interface_file}"
developer4616dbd2022-10-11 13:18:59 +0800131 exit 0
132 fi
developerb9a96602023-01-10 19:53:25 +0800133 record_config "STARTIDX" ${SOC_start_idx} ${interface_file}
developercf3c4c72023-01-31 15:21:28 +0800134 record_config "ENDIDX" ${SOC_end_idx} ${interface_file}
developerb9a96602023-01-10 19:53:25 +0800135 record_config "IS_EAGLE" ${is_eagle} ${interface_file}
developer4616dbd2022-10-11 13:18:59 +0800136 fi
developercf3c4c72023-01-31 15:21:28 +0800137}
developer4616dbd2022-10-11 13:18:59 +0800138
developercf3c4c72023-01-31 15:21:28 +0800139function convert_interface {
developerb9a96602023-01-10 19:53:25 +0800140 if [ ${is_eagle} == "0" ]; then
developer4616dbd2022-10-11 13:18:59 +0800141 if [[ $1 == "raix"* ]]; then
developerb9a96602023-01-10 19:53:25 +0800142 phy_idx=1
143 elif [[ $1 == "rai"* ]]; then
developer4616dbd2022-10-11 13:18:59 +0800144 phy_idx=0
145 elif [[ $1 == "rax"* ]]; then
developerb9a96602023-01-10 19:53:25 +0800146 phy_idx=$((SOC_start_idx+1))
147 else
148 phy_idx=$SOC_start_idx
developer4616dbd2022-10-11 13:18:59 +0800149 fi
developerb9a96602023-01-10 19:53:25 +0800150
151 # convert phy index according to band idx
152 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
153 if [ "${band_idx}" = "0" ]; then
154 if [[ $1 == "raix"* ]]; then
155 phy_idx=0
156 elif [[ $1 == "rax"* ]]; then
157 phy_idx=$SOC_start_idx
158 fi
159 elif [ "${band_idx}" = "1" ]; then
160 if [[ $1 == "rai"* ]]; then
161 # AX8400: mt7915 remain phy0
162 # AX7800: mt7916 becomes phy1
163 phy_idx=$((SOC_start_idx-1))
164 elif [[ $1 == "ra"* ]]; then
165 phy_idx=$((SOC_start_idx+1))
166 fi
167 fi
168 else
169 # Eagle has different mapping method
170 # phy0: ra0
171 # phy1: rai0
172 # phy2: rax0
developer4616dbd2022-10-11 13:18:59 +0800173 if [[ $1 == "rai"* ]]; then
developerb9a96602023-01-10 19:53:25 +0800174 phy_idx=1
175 elif [[ $1 == "rax"* ]]; then
176 phy_idx=2
177 else
178 phy_idx=0
developer4616dbd2022-10-11 13:18:59 +0800179 fi
180 fi
181
182 interface="phy${phy_idx}"
183}
184
185function change_band_idx {
186 local new_idx=$1
187 local new_phy_idx=$phy_idx
188
189 local old_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
190
191
192 if [[ ${interface_ori} == "ra"* ]]; then
193 if [ -z "${old_idx}" ] || [ "${old_idx}" != "${new_idx}" ]; then
194 if [ "${new_idx}" = "0" ]; then
195 # raix0 & rai0 becomes rai0
196 if [[ $interface_ori == "rai"* ]]; then
197 new_phy_idx=0
198 # rax0 & ra0 becomes ra0
199 elif [[ $interface_ori == "ra"* ]]; then
developerb9a96602023-01-10 19:53:25 +0800200 new_phy_idx=$SOC_start_idx
developer4616dbd2022-10-11 13:18:59 +0800201 fi
202 elif [ "${new_idx}" = "1" ]; then
203 # raix0 & rai0 becomes raix0
204 if [[ $interface_ori == "rai"* ]]; then
developer2aa1e642022-12-19 11:33:22 +0800205 # For AX8400 => don't change phy idx
developerb9a96602023-01-10 19:53:25 +0800206 if [ ${SOC_start_idx} != "1" ]; then
developer2aa1e642022-12-19 11:33:22 +0800207 new_phy_idx=1
208 fi
developer4616dbd2022-10-11 13:18:59 +0800209 # rax0 & ra0 becomes rax0
210 elif [[ $interface_ori == "ra"* ]]; then
developerb9a96602023-01-10 19:53:25 +0800211 new_phy_idx=$((SOC_start_idx+1))
developer4616dbd2022-10-11 13:18:59 +0800212 fi
213 fi
214 fi
215
216 if [ ${new_phy_idx} != ${phy_idx} ]; then
217 do_ate_work "ATESTOP"
218 phy_idx=$new_phy_idx
219 interface="phy${phy_idx}"
220 do_ate_work "ATESTART"
221 fi
222 fi
223 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
224}
225
226function simple_convert() {
227 if [ "$1" = "ATETXCNT" ]; then
228 echo "tx_count"
229 elif [ "$1" = "ATETXLEN" ]; then
230 echo "tx_length"
231 elif [ "$1" = "ATETXMCS" ]; then
232 echo "tx_rate_idx"
233 elif [ "$1" = "ATEVHTNSS" ]; then
234 echo "tx_rate_nss"
235 elif [ "$1" = "ATETXLDPC" ]; then
236 echo "tx_rate_ldpc"
237 elif [ "$1" = "ATETXSTBC" ]; then
238 echo "tx_rate_stbc"
239 elif [ "$1" = "ATEPKTTXTIME" ]; then
240 echo "tx_time"
241 elif [ "$1" = "ATEIPG" ]; then
242 echo "tx_ipg"
243 elif [ "$1" = "ATEDUTYCYCLE" ]; then
244 echo "tx_duty_cycle"
245 elif [ "$1" = "ATETXFREQOFFSET" ]; then
246 echo "freq_offset"
247 else
248 echo "undefined"
249 fi
250}
251
252function convert_tx_mode() {
developer2aa1e642022-12-19 11:33:22 +0800253 # Remove leading zeros
developercf3c4c72023-01-31 15:21:28 +0800254 local tx_mode=$(echo $1 | sed -r 's/0+([0-9]+)/\1/g')
developer2aa1e642022-12-19 11:33:22 +0800255
256 if [ "$tx_mode" = "0" ]; then
developer4616dbd2022-10-11 13:18:59 +0800257 echo "cck"
developer2aa1e642022-12-19 11:33:22 +0800258 elif [ "$tx_mode" = "1" ]; then
developer4616dbd2022-10-11 13:18:59 +0800259 echo "ofdm"
developer2aa1e642022-12-19 11:33:22 +0800260 elif [ "$tx_mode" = "2" ]; then
developer4616dbd2022-10-11 13:18:59 +0800261 echo "ht"
developer2aa1e642022-12-19 11:33:22 +0800262 elif [ "$tx_mode" = "4" ]; then
developer4616dbd2022-10-11 13:18:59 +0800263 echo "vht"
developer2aa1e642022-12-19 11:33:22 +0800264 elif [ "$tx_mode" = "8" ]; then
developer4616dbd2022-10-11 13:18:59 +0800265 echo "he_su"
developer2aa1e642022-12-19 11:33:22 +0800266 elif [ "$tx_mode" = "9" ]; then
developer4616dbd2022-10-11 13:18:59 +0800267 echo "he_er"
developer2aa1e642022-12-19 11:33:22 +0800268 elif [ "$tx_mode" = "10" ]; then
developer4616dbd2022-10-11 13:18:59 +0800269 echo "he_tb"
developer2aa1e642022-12-19 11:33:22 +0800270 elif [ "$tx_mode" = "11" ]; then
developer4616dbd2022-10-11 13:18:59 +0800271 echo "he_mu"
272 else
273 echo "undefined"
274 fi
275}
276
277function convert_gi {
278 local tx_mode=$1
279 local val=$2
280 local sgi="0"
281 local he_ltf="0"
282
283 case ${tx_mode} in
284 "ht"|"vht")
285 sgi=${val}
286 ;;
287 "he_su"|"he_er")
288 case ${val} in
289 "0")
290 ;;
291 "1")
292 he_ltf="1"
293 ;;
294 "2")
295 sgi="1"
296 he_ltf="1"
297 ;;
298 "3")
299 sgi="2"
300 he_ltf="2"
301 ;;
302 "4")
303 he_ltf="2"
304 ;;
305 *)
306 echo "unknown gi"
307 esac
308 ;;
309 "he_mu")
310 case ${val} in
311 "0")
312 he_ltf="2"
313 ;;
314 "1")
315 he_ltf="1"
316 ;;
317 "2")
318 sgi="1"
319 he_ltf="1"
320 ;;
321 "3")
322 sgi="2"
323 he_ltf="2"
324 ;;
325 *)
326 echo "unknown gi"
327 esac
328 ;;
329 "he_tb")
330 case ${val} in
331 "0")
332 sgi="1"
333 ;;
334 "1")
335 sgi="1"
336 he_ltf="1"
337 ;;
338 "2")
339 sgi="2"
340 he_ltf="2"
341 ;;
342 *)
343 echo "unknown gi"
344 esac
345 ;;
346 *)
347 print_debug "legacy mode no need gi"
348 esac
349
350 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
351}
352
353function convert_channel {
354 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
355 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
356 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
357 local bw_str="HT20"
358 local base_chan=1
359 local control_freq=0
360 local base_freq=0
developer2aa1e642022-12-19 11:33:22 +0800361 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
362 local temp=$((phy_idx+1))
developer4616dbd2022-10-11 13:18:59 +0800363
developer2aa1e642022-12-19 11:33:22 +0800364 # Handle ATECTRLBANDIDX
365 if [ ! -z ${ctrl_band_idx} ]; then
366 if [ "${ctrl_band_idx}" == "1" ] && [ ${band} == "0" ]; then
367 local temp=$(cat "/etc/config/wireless"| grep "option band" | sed -n ${temp}p | cut -c 15)
368 if [ "${temp}" == "2" ]; then
369 local band=0
370 elif [ "${temp}" == "5" ]; then
371 local band=1
372 elif [ "${temp}" == "6" ]; then
373 local band=2
374 else
375 echo "iwpriv wrapper band translate error!"
376 fi
377 else
378 # mt7915 in AX8400 case: band should be determined by only the input band
developerb9a96602023-01-10 19:53:25 +0800379 if [ "${SOC_start_idx}" == "1" ] && [ ${phy_idx} == "0" ]; then
developer2aa1e642022-12-19 11:33:22 +0800380 local band=$((band))
381 else
382 local band=$((ctrl_band_idx * band))
383 fi
384 fi
developer4616dbd2022-10-11 13:18:59 +0800385 fi
386
387 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
388 case ${bw} in
389 "1")
390 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
391 local bw_str="HT20"
392 else
393 local bw_str="HT40+"
394 ch=$(expr ${ch} - "2")
395 fi
396 ;;
397 esac
398 local base_freq=2412
399 elif [ "${band}" = "1" ]; then
400 case ${bw} in
401 "5")
402 bw_str="160MHz"
403 if [ ${ch} -lt "68" ]; then
404 ch="36"
405 elif [ ${ch} -lt "100" ]; then
406 ch="68"
407 elif [ ${ch} -lt "132" ]; then
408 ch="100"
409 elif [ ${ch} -lt "181" ]; then
410 ch="149"
411 fi
412 ;;
413 "2")
414 bw_str="80MHz"
415 if [ ${ch} -lt "52" ]; then
416 ch="36"
417 elif [ ${ch} -lt "68" ]; then
418 ch="52"
419 elif [ ${ch} -lt "84" ]; then
420 ch="68"
421 elif [ ${ch} -lt "100" ]; then
422 ch="84"
423 elif [ ${ch} -lt "116" ]; then
424 ch="100"
425 elif [ ${ch} -lt "132" ]; then
426 ch="116"
427 elif [ ${ch} -lt "149" ]; then
428 ch="132"
429 elif [ ${ch} -lt "165" ]; then
430 ch="149"
431 elif [ ${ch} -lt "181" ]; then
432 ch="165"
433 fi
434 ;;
435 "1")
436 if [ ${ch} -lt "44" ]; then
437 ch=$([ "${ch}" -lt "40" ] && echo "36" || echo "40")
438 bw_str=$([ "${ch}" -le "38" ] && echo "HT40+" || echo "HT40-")
439 elif [ ${ch} -lt "52" ]; then
440 ch=$([ "${ch}" -lt "48" ] && echo "44" || echo "48")
441 bw_str=$([ "${ch}" -le "46" ] && echo "HT40+" || echo "HT40-")
442 elif [ ${ch} -lt "60" ]; then
443 ch=$([ "${ch}" -lt "56" ] && echo "52" || echo "56")
444 bw_str=$([ "${ch}" -le "54" ] && echo "HT40+" || echo "HT40-")
445 elif [ ${ch} -lt "68" ]; then
446 ch=$([ "${ch}" -lt "64" ] && echo "60" || echo "64")
447 bw_str=$([ "${ch}" -le "62" ] && echo "HT40+" || echo "HT40-")
448 elif [ ${ch} -lt "76" ]; then
449 ch=$([ "${ch}" -lt "72" ] && echo "68" || echo "72")
450 bw_str=$([ "${ch}" -le "70" ] && echo "HT40+" || echo "HT40-")
451 elif [ ${ch} -lt "84" ]; then
452 ch=$([ "${ch}" -lt "80" ] && echo "76" || echo "80")
453 bw_str=$([ "${ch}" -le "78" ] && echo "HT40+" || echo "HT40-")
454 elif [ ${ch} -lt "92" ]; then
455 ch=$([ "${ch}" -lt "88" ] && echo "84" || echo "88")
456 bw_str=$([ "${ch}" -le "86" ] && echo "HT40+" || echo "HT40-")
457 elif [ ${ch} -lt "100" ]; then
458 ch=$([ "${ch}" -lt "96" ] && echo "92" || echo "96")
459 bw_str=$([ "${ch}" -le "94" ] && echo "HT40+" || echo "HT40-")
460 elif [ ${ch} -lt "108" ]; then
461 ch=$([ "${ch}" -lt "104" ] && echo "100" || echo "104")
462 bw_str=$([ "${ch}" -le "102" ] && echo "HT40+" || echo "HT40-")
463 elif [ ${ch} -lt "116" ]; then
464 ch=$([ "${ch}" -lt "112" ] && echo "108" || echo "112")
465 bw_str=$([ "${ch}" -le "110" ] && echo "HT40+" || echo "HT40-")
466 elif [ ${ch} -lt "124" ]; then
467 ch=$([ "${ch}" -lt "120" ] && echo "116" || echo "120")
468 bw_str=$([ "${ch}" -le "118" ] && echo "HT40+" || echo "HT40-")
469 elif [ ${ch} -lt "132" ]; then
470 ch=$([ "${ch}" -lt "128" ] && echo "124" || echo "128")
471 bw_str=$([ "${ch}" -le "126" ] && echo "HT40+" || echo "HT40-")
472 elif [ ${ch} -lt "140" ]; then
473 ch=$([ "${ch}" -lt "136" ] && echo "132" || echo "136")
474 bw_str=$([ "${ch}" -le "134" ] && echo "HT40+" || echo "HT40-")
475 elif [ ${ch} -lt "149" ]; then
476 ch=$([ "${ch}" -lt "144" ] && echo "140" || echo "144")
477 bw_str=$([ "${ch}" -le "142" ] && echo "HT40+" || echo "HT40-")
478 elif [ ${ch} -lt "157" ]; then
479 ch=$([ "${ch}" -lt "153" ] && echo "149" || echo "153")
480 bw_str=$([ "${ch}" -le "151" ] && echo "HT40+" || echo "HT40-")
481 elif [ ${ch} -lt "165" ]; then
482 ch=$([ "${ch}" -lt "161" ] && echo "157" || echo "161")
483 bw_str=$([ "${ch}" -le "159" ] && echo "HT40+" || echo "HT40-")
484 elif [ ${ch} -lt "173" ]; then
485 ch=$([ "${ch}" -lt "169" ] && echo "165" || echo "169")
486 bw_str=$([ "${ch}" -le "167" ] && echo "HT40+" || echo "HT40-")
487 elif [ ${ch} -lt "181" ]; then
488 ch=$([ "${ch}" -lt "177" ] && echo "173" || echo "177")
489 bw_str=$([ "${ch}" -le "175" ] && echo "HT40+" || echo "HT40-")
490 fi
491 ;;
492 "0")
493 local bw_str="HT20"
494 ;;
495 esac
496 local base_freq=5180
497 local base_chan=36
498 else
499 case ${bw} in
500 "5")
501 bw_str="160MHz"
502 if [ ${ch} -lt "33" ]; then
503 ch="1"
504 elif [ ${ch} -lt "65" ]; then
505 ch="33"
506 elif [ ${ch} -lt "97" ]; then
507 ch="65"
508 elif [ ${ch} -lt "129" ]; then
509 ch="97"
510 elif [ ${ch} -lt "161" ]; then
511 ch="129"
512 elif [ ${ch} -lt "193" ]; then
513 ch="161"
514 elif [ ${ch} -lt "225" ]; then
515 ch="193"
516 fi
517 ;;
518 "2")
519 bw_str="80MHz"
520 if [ ${ch} -lt "17" ]; then
521 ch="1"
522 elif [ ${ch} -lt "33" ]; then
523 ch="17"
524 elif [ ${ch} -lt "49" ]; then
525 ch="33"
526 elif [ ${ch} -lt "65" ]; then
527 ch="49"
528 elif [ ${ch} -lt "81" ]; then
529 ch="65"
530 elif [ ${ch} -lt "97" ]; then
531 ch="81"
532 elif [ ${ch} -lt "113" ]; then
533 ch="97"
534 elif [ ${ch} -lt "129" ]; then
535 ch="113"
536 elif [ ${ch} -lt "145" ]; then
537 ch="129"
538 elif [ ${ch} -lt "161" ]; then
539 ch="145"
540 elif [ ${ch} -lt "177" ]; then
541 ch="161"
542 elif [ ${ch} -lt "193" ]; then
543 ch="177"
544 elif [ ${ch} -lt "209" ]; then
545 ch="193"
546 elif [ ${ch} -lt "225" ]; then
547 ch="209"
548 fi
549 ;;
550 "1")
551 if [ ${ch} -lt "9" ]; then
552 ch=$([ "${ch}" -lt "5" ] && echo "1" || echo "5")
553 bw_str=$([ "${ch}" -le "3" ] && echo "HT40+" || echo "HT40-")
554 elif [ ${ch} -lt "17" ]; then
555 ch=$([ "${ch}" -lt "13" ] && echo "9" || echo "13")
556 bw_str=$([ "${ch}" -le "11" ] && echo "HT40+" || echo "HT40-")
557 elif [ ${ch} -lt "25" ]; then
558 ch=$([ "${ch}" -lt "21" ] && echo "17" || echo "21")
559 bw_str=$([ "${ch}" -le "19" ] && echo "HT40+" || echo "HT40-")
560 elif [ ${ch} -lt "33" ]; then
561 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
562 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
563 elif [ ${ch} -lt "33" ]; then
564 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
565 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
566 elif [ ${ch} -lt "41" ]; then
567 ch=$([ "${ch}" -lt "37" ] && echo "33" || echo "37")
568 bw_str=$([ "${ch}" -le "35" ] && echo "HT40+" || echo "HT40-")
569 elif [ ${ch} -lt "49" ]; then
570 ch=$([ "${ch}" -lt "45" ] && echo "41" || echo "45")
571 bw_str=$([ "${ch}" -le "43" ] && echo "HT40+" || echo "HT40-")
572 elif [ ${ch} -lt "57" ]; then
573 ch=$([ "${ch}" -lt "53" ] && echo "49" || echo "53")
574 bw_str=$([ "${ch}" -le "51" ] && echo "HT40+" || echo "HT40-")
575 elif [ ${ch} -lt "65" ]; then
576 ch=$([ "${ch}" -lt "61" ] && echo "57" || echo "61")
577 bw_str=$([ "${ch}" -le "59" ] && echo "HT40+" || echo "HT40-")
578 elif [ ${ch} -lt "73" ]; then
579 ch=$([ "${ch}" -lt "69" ] && echo "65" || echo "69")
580 bw_str=$([ "${ch}" -le "67" ] && echo "HT40+" || echo "HT40-")
581 elif [ ${ch} -lt "81" ]; then
582 ch=$([ "${ch}" -lt "77" ] && echo "73" || echo "77")
583 bw_str=$([ "${ch}" -le "75" ] && echo "HT40+" || echo "HT40-")
584 elif [ ${ch} -lt "89" ]; then
585 ch=$([ "${ch}" -lt "85" ] && echo "81" || echo "85")
586 bw_str=$([ "${ch}" -le "83" ] && echo "HT40+" || echo "HT40-")
587 elif [ ${ch} -lt "97" ]; then
588 ch=$([ "${ch}" -lt "93" ] && echo "89" || echo "93")
589 bw_str=$([ "${ch}" -le "91" ] && echo "HT40+" || echo "HT40-")
590 elif [ ${ch} -lt "105" ]; then
591 ch=$([ "${ch}" -lt "101" ] && echo "97" || echo "101")
592 bw_str=$([ "${ch}" -le "99" ] && echo "HT40+" || echo "HT40-")
593 elif [ ${ch} -lt "113" ]; then
594 ch=$([ "${ch}" -lt "109" ] && echo "105" || echo "109")
595 bw_str=$([ "${ch}" -le "107" ] && echo "HT40+" || echo "HT40-")
596 elif [ ${ch} -lt "121" ]; then
597 ch=$([ "${ch}" -lt "117" ] && echo "113" || echo "117")
598 bw_str=$([ "${ch}" -le "115" ] && echo "HT40+" || echo "HT40-")
599 elif [ ${ch} -lt "129" ]; then
600 ch=$([ "${ch}" -lt "125" ] && echo "121" || echo "125")
601 bw_str=$([ "${ch}" -le "123" ] && echo "HT40+" || echo "HT40-")
602 elif [ ${ch} -lt "137" ]; then
603 ch=$([ "${ch}" -lt "133" ] && echo "129" || echo "133")
604 bw_str=$([ "${ch}" -le "131" ] && echo "HT40+" || echo "HT40-")
605 elif [ ${ch} -lt "145" ]; then
606 ch=$([ "${ch}" -lt "141" ] && echo "137" || echo "141")
607 bw_str=$([ "${ch}" -le "139" ] && echo "HT40+" || echo "HT40-")
608 elif [ ${ch} -lt "153" ]; then
609 ch=$([ "${ch}" -lt "149" ] && echo "145" || echo "149")
610 bw_str=$([ "${ch}" -le "147" ] && echo "HT40+" || echo "HT40-")
611 elif [ ${ch} -lt "161" ]; then
612 ch=$([ "${ch}" -lt "157" ] && echo "153" || echo "157")
613 bw_str=$([ "${ch}" -le "155" ] && echo "HT40+" || echo "HT40-")
614 elif [ ${ch} -lt "169" ]; then
615 ch=$([ "${ch}" -lt "165" ] && echo "161" || echo "165")
616 bw_str=$([ "${ch}" -le "163" ] && echo "HT40+" || echo "HT40-")
617 elif [ ${ch} -lt "177" ]; then
618 ch=$([ "${ch}" -lt "173" ] && echo "169" || echo "173")
619 bw_str=$([ "${ch}" -le "171" ] && echo "HT40+" || echo "HT40-")
620 elif [ ${ch} -lt "185" ]; then
621 ch=$([ "${ch}" -lt "181" ] && echo "177" || echo "181")
622 bw_str=$([ "${ch}" -le "179" ] && echo "HT40+" || echo "HT40-")
623 elif [ ${ch} -lt "193" ]; then
624 ch=$([ "${ch}" -lt "189" ] && echo "185" || echo "189")
625 bw_str=$([ "${ch}" -le "187" ] && echo "HT40+" || echo "HT40-")
626 elif [ ${ch} -lt "201" ]; then
627 ch=$([ "${ch}" -lt "197" ] && echo "193" || echo "197")
628 bw_str=$([ "${ch}" -le "195" ] && echo "HT40+" || echo "HT40-")
629 elif [ ${ch} -lt "209" ]; then
630 ch=$([ "${ch}" -lt "205" ] && echo "201" || echo "205")
631 bw_str=$([ "${ch}" -le "203" ] && echo "HT40+" || echo "HT40-")
632 elif [ ${ch} -lt "217" ]; then
633 ch=$([ "${ch}" -lt "213" ] && echo "209" || echo "213")
634 bw_str=$([ "${ch}" -le "211" ] && echo "HT40+" || echo "HT40-")
635 elif [ ${ch} -lt "225" ]; then
636 ch=$([ "${ch}" -lt "221" ] && echo "217" || echo "221")
637 bw_str=$([ "${ch}" -le "219" ] && echo "HT40+" || echo "HT40-")
638 elif [ ${ch} -lt "233" ]; then
639 ch=$([ "${ch}" -lt "229" ] && echo "225" || echo "229")
640 bw_str=$([ "${ch}" -le "227" ] && echo "HT40+" || echo "HT40-")
641 fi
642 ;;
643 "0")
644 local bw_str="HT20"
645 ;;
646 esac
647 local base_freq=5955
648 fi
649
650 local control_freq=$(((ch - base_chan) * 5 + base_freq))
651 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
652}
653
654function convert_rxstat {
655 local res=$(do_cmd "mt76-test ${interface} dump stats")
656 local mdrdy=$(echo "${res}" | grep "rx_packets" | cut -d "=" -f 2)
657 local fcs_error=$(echo "${res}" | grep "rx_fcs_error" | cut -d "=" -f 2)
658 local rcpi=$(echo "${res}" | grep "last_rcpi" | cut -d "=" -f 2 | sed 's/,/ /g')
659 local ib_rssi=$(echo "${res}" | grep "last_ib_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
660 local wb_rssi=$(echo "${res}" | grep "last_wb_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
661 local rx_ok=$(expr ${mdrdy} - ${fcs_error})
662
663 write_dmesg "rcpi: ${rcpi}"
664 write_dmesg "fagc rssi ib: ${ib_rssi}"
665 write_dmesg "fagc rssi wb: ${wb_rssi}"
666 write_dmesg "all_mac_rx_mdrdy_cnt: ${mdrdy}"
667 write_dmesg "all_mac_rx_fcs_err_cnt: ${fcs_error}"
668 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
669}
670
671function set_mac_addr {
672 record_config ${cmd} ${param} ${iwpriv_file}
673
674 local addr1=$(get_config "ATEDA" ${iwpriv_file})
675 local addr2=$(get_config "ATESA" ${iwpriv_file})
676 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
677
678 if [ -z "${addr1}" ]; then
679 addr1="00:11:22:33:44:55"
680 fi
681 if [ -z "${addr2}" ]; then
682 addr2="00:11:22:33:44:55"
683 fi
684 if [ -z "${addr3}" ]; then
685 addr3="00:11:22:33:44:55"
686 fi
687
688 do_cmd "mt76-test phy${phy_idx} set mac_addrs=${addr1},${addr2},${addr3}"
689}
690
691function convert_ibf {
692 local cmd=$1
693 local param=$2
694 local new_cmd=""
695 local new_param=$(echo ${param} | sed s/":"/","/g)
696
697 case ${cmd} in
698 "ATETxBfInit")
699 new_cmd="init"
developer2aa1e642022-12-19 11:33:22 +0800700 new_param="1"
701 do_cmd "mt76-test phy${phy_idx} set state=idle"
702 ;;
703 "ATETxBfGdInit")
704 new_cmd="golden_init"
705 new_param="1"
developer4616dbd2022-10-11 13:18:59 +0800706 do_cmd "mt76-test phy${phy_idx} set state=idle"
707 ;;
708 "ATEIBFPhaseComp")
709 new_cmd="phase_comp"
developer2aa1e642022-12-19 11:33:22 +0800710 new_param="${new_param}"
developer4616dbd2022-10-11 13:18:59 +0800711 ;;
712 "ATEEBfProfileConfig")
713 new_cmd="ebf_prof_update"
714 ;;
715 "ATEIBfProfileConfig")
716 new_cmd="ibf_prof_update"
717 ;;
718 "ATEIBfInstCal")
719 new_cmd="phase_cal"
720 ;;
721 "ATEIBfGdCal")
722 new_cmd="phase_cal"
723 new_param="${new_param},00"
724 ;;
725 "TxBfTxApply")
726 new_cmd="apply_tx"
727 ;;
728 "ATETxPacketWithBf")
729 local bf_on=${new_param:0:2}
730 local aid="01"
731 local wlan_idx=${new_param:3:2}
732 local update="00"
733 local tx_len=${new_param:6}
734
735 new_cmd="tx_prep"
736 new_param="${bf_on},${aid},${wlan_idx},${update}"
737 if [ "${tx_len}" = "00" ]; then
738 new_param="${new_param} aid=1 tx_count=10000000 tx_length=1024"
739 else
740 new_param="${new_param} aid=1 tx_count=${tx_len} tx_length=1024"
741 fi
742 do_cmd "mt76-test phy${phy_idx} set state=idle"
743 ;;
744 "TxBfProfileData20MAllWrite")
745 new_cmd="prof_update_all"
746 ;;
747 "ATEIBFPhaseE2pUpdate")
748 new_cmd="e2p_update"
749 ;;
developer2aa1e642022-12-19 11:33:22 +0800750 "ATEIBFPhaseVerify")
751 local group=${new_param:0:2}
752 local group_l_m_h=${new_param:3:2}
753 local band_idx=${new_param:6:2}
754 local phase_cal_type=${new_param:9:2}
755 local LNA_gain_level=${new_param:12:2}
756 local read_from_e2p=${new_param:15:2}
757
758 do_cmd "mt76-test phy${phy_idx} set txbf_act=phase_comp txbf_param=1,${band_idx},${group},${read_from_e2p},0"
759 new_cmd="phase_cal"
760 new_param="${group},${group_l_m_h},${band_idx},${phase_cal_type},${LNA_gain_level}"
761 ;;
762 "TxBfProfileTagRead")
763 new_cmd="pfmu_tag_read"
764 ;;
765 "TxBfProfileTagWrite")
766 new_cmd="pfmu_tag_write"
767 ;;
768 "TxBfProfileTagInValid")
769 new_cmd="set_invalid_prof"
770 ;;
771 "StaRecBfRead")
772 new_cmd="sta_rec_read"
773 ;;
774 "TriggerSounding")
775 new_cmd="trigger_sounding"
776 ;;
777 "StopSounding")
778 new_cmd="stop_sounding"
779 new_param="0"
780 ;;
781 "ATEConTxETxBfGdProc")
782 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
783 local tx_rate_idx=${new_param:3:2}
784 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
785 local channel=${new_param:9:3}
786 local channel2=${new_param:13:3}
787 local band=${new_param:17}
788
789 new_cmd="ebf_golden_init"
790 do_ate_work "ATESTART"
791 do_cmd "mt76-test phy${phy_idx} set state=idle"
792 record_config "ATETXBW" ${bw} ${iwpriv_file}
793 convert_channel "${channel}:${band}"
794 if [ "${bw}" = "5" ]; then
795 new_param="1,1"
796 else
797 new_param="1,0"
798 fi
799 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_sgi=0"
800 ;;
801 "ATEConTxETxBfInitProc")
802 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
803 local tx_rate_idx=${new_param:3:2}
804 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
805 local tx_rate_nss=${new_param:9:2}
806 local tx_stream=${new_param:12:2}
807 local tx_power=${new_param:15:2}
808 local channel=${new_param:18:3}
809 local channel2=${new_param:22:3}
810 local band=${new_param:26:1}
811 local tx_length=${new_param:28:5}
812
813 new_cmd="ebf_init"
814 do_ate_work "ATESTART"
815 do_cmd "mt76-test phy${phy_idx} set state=idle"
816 record_config "ATETXBW" ${bw} ${iwpriv_file}
817 convert_channel "${channel}:${band}"
818 new_param="1"
819 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"
820 ;;
developer4616dbd2022-10-11 13:18:59 +0800821 *)
822 esac
823
824 do_cmd "mt76-test phy${phy_idx} set txbf_act=${new_cmd} txbf_param=${new_param}"
825
826 if [ "${cmd}" = "ATETxPacketWithBf" ]; then
827 do_cmd "mt76-test phy${phy_idx} set state=tx_frames"
developer2aa1e642022-12-19 11:33:22 +0800828 elif [ "${cmd}" = "ATEConTxETxBfInitProc" ]; then
829 do_cmd "mt76-test phy${phy_idx} set aid=1"
830 do_cmd "mt76-test phy${phy_idx} set txbf_act=stop_sounding txbf_param=1"
831 do_cmd "mt76-test phy${phy_idx} set txbf_act=update_ch txbf_param=1"
832 do_cmd "mt76-test phy${phy_idx} set txbf_act=ebf_prof_update txbf_param=0,0,0"
833 do_cmd "mt76-test phy${phy_idx} set txbf_act=apply_tx txbf_param=1,1,0,0,0"
834 do_cmd "mt76-test phy${phy_idx} set txbf_act=pfmu_tag_read txbf_param=0,1"
835 do_cmd "mt76-test phy${phy_idx} set txbf_act=sta_rec_read txbf_param=1"
836 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=0,1,0,1,0,0,0"
837 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=2,1,ff,1,0,0,0"
838 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
839 elif [ "${cmd}" = "ATEConTxETxBfGdProc" ]; then
840 do_cmd "mt76-test phy${phy_idx} set aid=1"
841 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
842 elif [ "${cmd}" = "ATETxBfInit" ]; then
843 do_cmd "mt76-test phy${phy_idx} set aid=1"
844 elif [ "${cmd}" = "ATETxBfGdInit" ]; then
845 do_cmd "mt76-test phy${phy_idx} set aid=1"
developer4616dbd2022-10-11 13:18:59 +0800846 fi
847}
848
developerb81e95d2022-11-08 10:16:29 +0800849function convert_dfs {
850 local cmd=$1
851 local param=$2
852
853 case ${cmd} in
854 "DfsRxCtrl")
855 local offchan_ch="$(echo $param | cut -d ':' -f1)"
856 local offchan_bw="$(echo $param | cut -d ':' -f2)"
857
858 if [ "$offchan_bw" = "0" ]; then
859 offchan_bw="20"
860 elif [ "$offchan_bw" = "1" ]; then
861 offchan_bw="40"
862 elif [ "$offchan_bw" = "2" ]; then
863 offchan_bw="80"
864 fi
865
866 do_cmd "mt76-test phy${phy_idx} set state=idle"
867 do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
868 ;;
869 "DfsRxHist")
870 local ipi_th="$(echo $param | cut -d ':' -f 1)"
871 local ipi_period="$(echo $param | cut -d ':' -f 2)"
872 local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
873
874 if [ -z $ipi_antenna ]; then
875 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
876 else
877 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
878 fi
879 ;;
880 *)
881 esac
882}
883
developer4616dbd2022-10-11 13:18:59 +0800884function do_ate_work() {
885 local ate_cmd=$1
886
887 case ${ate_cmd} in
888 "ATESTART")
889 local if_str=$(ifconfig | grep mon${phy_idx})
890
891 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
892 echo "ATE already starts."
893 else
894 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
developercf3c4c72023-01-31 15:21:28 +0800895
896 if [ $phy_idx -ge $SOC_start_idx ]; then
897 local end_idx=$SOC_end_idx
898 local start_idx=$SOC_start_idx
899 else
900 local end_idx=$((SOC_start_idx-1))
901 local start_idx="0"
902 fi
903
904 for phy_index in $( seq $start_idx $end_idx )
905 do
906 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
907 local prev_phy_index=$((phy_index-1))
908 local if_num=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep -c Interface)
909 local j="1"
910 # avoid del_if_count reset to 0 when start ate on another band in dbdc case
911 local del_if_count=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
912 if [ -z "${del_if_count}" ]; then
913 local del_if_count="0"
914 fi
915
916 for if_count in $( seq 1 $if_num )
917 do
918 local del_if=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep Interface | sed -n ${j}p | cut -d " " -f 2)
919 if [ ! -z "${del_if}" ] && [[ "$del_if" != *"mon"* ]]; then
920 do_cmd "iw dev ${del_if} del"
921 del_if_count=$((del_if_count+1))
922 # handle the case of multiple interface in a phy
923 record_config "DEL_IF${phy_index}-${del_if_count}" ${del_if} ${interface_file}
924 else
925 # j add 1 to skip mon interface
926 j=$((j+1))
927 fi
928 done
929 record_config "DEL_IF${phy_index}_NUM" ${del_if_count} ${interface_file}
930 done
931
developer4616dbd2022-10-11 13:18:59 +0800932 do_cmd "ifconfig mon${phy_idx} up"
933 do_cmd "iw reg set VV"
934 fi
935 ;;
936 "ATESTOP")
937 local if_str=$(ifconfig | grep mon${phy_idx})
938
939 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
940 echo "ATE does not start."
941 else
942 do_cmd "mt76-test ${interface} set state=off"
943 do_cmd "iw dev mon${phy_idx} del"
developercf3c4c72023-01-31 15:21:28 +0800944
945 if [ $phy_idx -ge $SOC_start_idx ]; then
946 local end_idx=$SOC_end_idx
947 local start_idx=$SOC_start_idx
948 else
949 local end_idx=$((SOC_start_idx-1))
950 local start_idx="0"
951 fi
952
953 # first check its phy and dbdc band phy has monitor interface or not
954 # if has at lease one mon interface, then skip adding back normal interface
955 local has_mon="0"
956 for phy_index in $( seq $start_idx $end_idx )
957 do
958 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
959 local prev_phy_index=$((phy_index-1))
960 local has_mon_phy=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep "Interface mon")
961 # if this phy interface has mon interface
962 if [ ! -z "${has_mon_phy}" ]; then
963 local has_mon="1"
964 fi
965 done
966
967 for phy_index in $( seq $start_idx $end_idx )
968 do
969 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
970 local prev_phy_index=$((phy_index-1))
971 local j="1"
972 local add_if_num=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
973 if [ -z "${add_if_num}" ]; then
974 local add_if_num="0"
975 fi
976 # if this phy interface (including its dbdc phy) has no mon interface and can find deleted interface in file, then add it back
977 if [ "${has_mon}" == "0" ] && [ $add_if_num -ge "1" ]; then
978 local if_index=$add_if_num
979 # add interface backwards
980 while [ $if_index -gt "0" ]
981 do
982 local add_if=$(get_config "DEL_IF${phy_index}-${if_index}" ${interface_file})
983 do_cmd "iw phy phy${phy_index} interface add ${add_if} type managed"
984 # remove the deleted interface in interface_file since it is added back
985 sed -i "/DEL_IF${phy_index}-${if_index}=/d" ${interface_file}
986 if_index=$((if_index-1))
987 done
988 # remove the number of deleted interface in interface_file since it is all added back
989 sed -i "/DEL_IF${phy_index}_NUM=/d" ${interface_file}
990 fi
991 done
992
developer4616dbd2022-10-11 13:18:59 +0800993 do_cmd "mt76-test ${interface} set aid=0"
994 fi
995
developerb9a96602023-01-10 19:53:25 +0800996 if [ ${phy_idx} -lt ${SOC_start_idx} ]; then
developer4616dbd2022-10-11 13:18:59 +0800997 sed -i '/_PCIE=/d' ${iwpriv_file}
developerb9a96602023-01-10 19:53:25 +0800998 elif [ ${phy_idx} -ge ${SOC_start_idx} ]; then
999 sed -i '/_SOC=/d' ${iwpriv_file}
developer4616dbd2022-10-11 13:18:59 +08001000 fi
1001 ;;
1002 "TXCOMMIT")
1003 do_cmd "mt76-test ${interface} set aid=1"
1004 ;;
1005 "TXFRAME")
1006 do_cmd "mt76-test ${interface} set state=tx_frames"
1007 ;;
1008 "TXSTOP"|"RXSTOP")
1009 do_cmd "mt76-test ${interface} set state=idle"
1010 ;;
1011 "TXREVERT")
1012 do_cmd "mt76-test ${interface} set aid=0"
1013 ;;
1014 "RXFRAME")
1015 do_cmd "mt76-test ${interface} set state=rx_frames"
1016 ;;
1017 "TXCONT")
1018 do_cmd "mt76-test ${interface} set state=tx_cont"
1019 ;;
1020 "GROUPREK")
1021 do_cmd "mt76-test ${interface} set state=group_prek"
1022 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
1023 ;;
1024 "GROUPREKDump")
1025 do_cmd "mt76-test ${interface} set state=group_prek_dump"
1026 ;;
1027 "GROUPREKClean")
1028 do_cmd "mt76-test ${interface} set state=group_prek_clean"
1029 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
1030 ;;
1031 "DPD2G")
1032 do_cmd "mt76-test ${interface} set state=dpd_2g"
1033 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
1034 ;;
1035 "DPD5G")
1036 do_cmd "mt76-test ${interface} set state=dpd_5g"
1037 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
1038 ;;
1039 "DPD6G")
1040 do_cmd "mt76-test ${interface} set state=dpd_6g"
1041 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
1042 ;;
1043 "DPDDump")
1044 do_cmd "mt76-test ${interface} set state=dpd_dump"
1045 ;;
1046 "DPDClean")
1047 do_cmd "mt76-test ${interface} set state=dpd_clean"
1048 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
1049 ;;
1050 *)
1051 print_debug "skip ${ate_cmd}"
1052 ;;
1053 esac
1054}
1055
developerb9a96602023-01-10 19:53:25 +08001056function dump_usage {
1057 echo "Usage:"
1058 echo " mwctl <interface> set csi ctrl=<opt1>,<opt2>,<opt3>,<opt4> (macaddr=<macaddr>)"
1059 echo " mwctl <interface> set csi interval=<interval (us)>"
1060 echo " mwctl <interface> dump csi <packet num> <filename>"
1061 echo " mwctl <interface> set amnt <index>(0x0~0xf) <mac addr>(xx:xx:xx:xx:xx:xx)"
1062 echo " mwctl <interface> dump amnt <index> (0x0~0xf or 0xff)"
1063 echo " mwctl <interface> set ap_rfeatures he_gi=<val>"
1064 echo " mwctl <interface> set ap_rfeatures he_ltf=<val>"
1065 echo " mwctl <interface> set ap_rfeatures trig_type=<enable>,<val> (val: 0-7)"
1066 echo " mwctl <interface> set ap_rfeatures ack_policy=<val> (val: 0-4)"
1067 echo " mwctl <interface> set ap_wireless fixed_mcs=<val>"
1068 echo " mwctl <interface> set ap_wireless ofdma=<val> (0: disable, 1: DL, 2: UL)"
1069 echo " mwctl <interface> set ap_wireless nusers_ofdma=<val>"
1070 echo " mwctl <interface> set ap_wireless ppdu_type=<val> (0: SU, 1: MU, 4: LEGACY)"
1071 echo " mwctl <interface> set ap_wireless add_ba_req_bufsize=<val>"
1072 echo " mwctl <interface> set ap_wireless mimo=<val> (0: DL, 1: UL)"
1073 echo " mwctl <interface> set ap_wireless ampdu=<enable>"
1074 echo " mwctl <interface> set ap_wireless amsdu=<enable>"
1075 echo " mwctl <interface> set ap_wireless cert=<enable>"
developere0a1e0e2023-02-24 11:26:12 +08001076 echo " mwctl <interface> set mu onoff=<val> (bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0))"
developerb9a96602023-01-10 19:53:25 +08001077 echo " mwctl <interface> dump phy_capa"
1078}
1079
developer1c2c7d42023-01-18 18:20:58 +08001080function register_handler {
1081
1082 local phy_idx=$1
1083 local offset=$2
1084 local val=$3
1085 local cmd=$4
1086 local w_cmd="write"
1087
1088 regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
1089 regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
1090
1091 echo ${offset} > ${regidx}
1092 if [[ "${cmd}" == "${w_cmd}" ]]; then
1093 echo ${val} > ${regval}
1094 fi
1095
1096 res=$(cat ${regval} | cut -d 'x' -f 2)
1097 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
1098}
1099
developer4616dbd2022-10-11 13:18:59 +08001100# main start here
developercf3c4c72023-01-31 15:21:28 +08001101parse_sku
developerb9a96602023-01-10 19:53:25 +08001102if [ -z ${interface} ]; then
1103 dump_usage
1104 exit
1105elif [[ ${interface} == "ra"* ]]; then
developer4616dbd2022-10-11 13:18:59 +08001106 convert_interface $interface
1107fi
1108
1109tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
1110
1111if [ ! -z ${tmp_work_mode} ]; then
1112 work_mode=${tmp_work_mode}
1113fi
1114
1115cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
1116param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
1117
1118if [ "${cmd_type}" = "set" ]; then
1119 skip=0
1120 case ${cmd} in
developerb9a96602023-01-10 19:53:25 +08001121 ## In wifi 7 chipset, testmode & vendor command both use mwctl
1122 ## Therefore this wrapper would translate it to either mt76-test or mt76-vendor based on the attribute of the command
1123 ## Translate to mt76-vendor command
developere0a1e0e2023-02-24 11:26:12 +08001124 "csi"|"amnt"|"ap_rfeatures"|"ap_wireless"|"mu")
developerdd6c8922023-02-15 16:38:49 +08001125 if [ ${is_eagle} == "1" ]; then
1126 do_cmd "hostapd_cli -i $*"
1127 skip=1
1128 else
1129 do_cmd "mt76-vendor $*"
1130 skip=1
developerb9a96602023-01-10 19:53:25 +08001131 ;;
developer4616dbd2022-10-11 13:18:59 +08001132 "ATE")
1133 do_ate_work ${param}
1134
1135 skip=1
1136 ;;
1137 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
1138 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
1139 cmd_new=$(simple_convert ${cmd})
1140 if [ "${param_new}" = "undefined" ]; then
1141 echo "unknown cmd: ${cmd}"
1142 exit
1143 fi
1144 param_new=${param}
developer2aa1e642022-12-19 11:33:22 +08001145 if [ "${cmd}" = "ATETXCNT" ] && [ "${param}" = "0" ]; then
1146 param_new="10000000"
1147 fi
developer4616dbd2022-10-11 13:18:59 +08001148 ;;
1149 "ATETXANT"|"ATERXANT")
1150 cmd_new="tx_antenna"
1151 param_new=${param}
1152 ;;
1153 "ATETXGI")
1154 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
1155 convert_gi ${tx_mode} ${param}
1156 skip=1
1157 ;;
1158 "ATETXMODE")
1159 cmd_new="tx_rate_mode"
1160 param_new=$(convert_tx_mode ${param})
1161 if [ "${param_new}" = "undefined" ]; then
1162 echo "unknown tx mode"
1163 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
1164 exit
1165 else
1166 record_config ${cmd} ${param} ${iwpriv_file}
1167 fi
1168 ;;
1169 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3")
1170 cmd_new="tx_power"
1171 param_new="${param},0,0,0"
1172 ;;
1173 "ATETXBW")
1174 record_config ${cmd} ${param} ${iwpriv_file}
1175 skip=1
1176 ;;
1177 "ATECHANNEL")
1178 convert_channel ${param}
1179 skip=1
1180 ;;
1181 "ATERXSTAT")
1182 convert_rxstat
1183 skip=1
1184 ;;
1185 "ATECTRLBANDIDX")
1186 change_band_idx ${param}
1187 skip=1
1188 ;;
1189 "ATEDA"|"ATESA"|"ATEBSSID")
1190 set_mac_addr ${cmd} ${param}
1191 skip=1
1192 ;;
developerb81e95d2022-11-08 10:16:29 +08001193 "DfsRxCtrl"|"DfsRxHist")
1194 convert_dfs ${cmd} ${param}
1195 skip=1
1196 ;;
developer2aa1e642022-12-19 11:33:22 +08001197 "ATETxBfInit"|"ATETxBfGdInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
1198 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"| \
1199 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate"|"TriggerSounding"|"StopSounding"| \
1200 "StaRecBfRead"|"TxBfProfileTagInValid"|"TxBfProfileTagWrite"|"TxBfProfileTagRead"| \
1201 "ATEIBFPhaseVerify"|"ATEConTxETxBfGdProc"|"ATEConTxETxBfInitProc")
developer4616dbd2022-10-11 13:18:59 +08001202 convert_ibf ${cmd} ${param}
1203 skip=1
1204 ;;
1205 "bufferMode")
1206 if [ "${param}" = "2" ]; then
1207 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
1208 fi
1209 skip=1
1210 ;;
1211 "ResetCounter"|"ATERXSTATRESET")
1212 skip=1
1213 ;;
1214 "WORKMODE")
1215 record_config "WORKMODE" ${param} ${iwpriv_file}
1216 echo "Entering ${param} mode in iwpriv"
1217 skip=1
1218 ;;
1219 *)
1220 print_debug "Unknown command to set: ${cmd}"
1221 skip=1
1222 esac
1223
1224 if [ "${skip}" != "1" ]; then
1225 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
1226 fi
1227
1228elif [ "${cmd_type}" = "show" ]; then
developer2aa1e642022-12-19 11:33:22 +08001229 if [ "${cmd}" = "wtbl" ]; then
1230 wlan_idx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wlan_idx
1231 wtbl_info=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wtbl_info
1232
1233 do_cmd "echo ${param} > ${wlan_idx}"
1234 do_cmd "cat ${wtbl_info}"
1235 else
1236 do_cmd "mt76-test ${interface} dump"
1237 do_cmd "mt76-test ${interface} dump stats"
1238 fi
developer4616dbd2022-10-11 13:18:59 +08001239
1240elif [ "${cmd_type}" = "e2p" ]; then
developerb9a96602023-01-10 19:53:25 +08001241 # support multiple read write
developer4616dbd2022-10-11 13:18:59 +08001242 # eeprom offset write
1243 if [[ ${full_cmd} == *"="* ]]; then
developerb9a96602023-01-10 19:53:25 +08001244 IFS=,
1245 for tuple in $full_cmd
1246 do
1247 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1248 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1249 offset=$(printf "0x%s" ${cmd})
1250 val=$(printf "0x%s" ${param})
1251 tmp=$((${val} & 0xff))
1252 tmp=$(printf "0x%x" ${tmp})
1253 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developer4616dbd2022-10-11 13:18:59 +08001254
developerb9a96602023-01-10 19:53:25 +08001255 offset=$((${offset}))
1256 offset=$(expr ${offset} + "1")
1257 offset=$(printf "0x%x" ${offset})
1258 tmp=$(((${val} >> 8) & 0xff))
1259 tmp=$(printf "0x%x" ${tmp})
1260 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
1261 done
developer4616dbd2022-10-11 13:18:59 +08001262 else
developerb9a96602023-01-10 19:53:25 +08001263 IFS=,
1264 for tuple in $full_cmd
1265 do
1266 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1267 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1268 offset=$(printf "0x%s" ${cmd})
1269 val=$(printf "0x%s" ${param})
1270 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
1271 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developer4616dbd2022-10-11 13:18:59 +08001272
developerb9a96602023-01-10 19:53:25 +08001273 tmp=$(printf "0x%s" ${param})
1274 tmp=$((${tmp}))
1275 param2=$(expr ${tmp} + "1")
1276 param2=$(printf "%x" ${param2})
1277 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
1278 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developer4616dbd2022-10-11 13:18:59 +08001279
developerb9a96602023-01-10 19:53:25 +08001280 param=$(printf "0x%s" ${param})
1281 param=$(printf "%04x" ${param})
1282 param=$(echo $param | tr 'a-z' 'A-Z')
1283 printf "%s e2p:\n" ${interface_ori}
1284 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
1285 done
developer4616dbd2022-10-11 13:18:59 +08001286 fi
1287
1288elif [ "${cmd_type}" = "mac" ]; then
developer4616dbd2022-10-11 13:18:59 +08001289 offset=$(printf "0x%s" ${cmd})
1290 val=$(printf "0x%s" ${param})
1291
developer4616dbd2022-10-11 13:18:59 +08001292 # reg write
1293 if [[ ${full_cmd} == *"="* ]]; then
developer1c2c7d42023-01-18 18:20:58 +08001294 register_handler ${phy_idx} ${offset} ${val} "write"
1295 else
1296 start_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 1)
1297 end_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 2)
1298 loop=$((0x${end_addr}-0x${start_addr}))
developer4616dbd2022-10-11 13:18:59 +08001299
developer1c2c7d42023-01-18 18:20:58 +08001300 if [[ ${loop} == "0" ]]; then
1301 register_handler ${phy_idx} ${offset} ${val}
1302 else
1303 i=0
1304 while [ $i -le $loop ]; do
1305 addr=$((0x${start_addr}+$i))
1306 offset=$(printf "0x%x" ${addr})
1307 register_handler ${phy_idx} ${offset} ${val}
1308 i=$(($i + 4))
1309 done
1310 fi
1311 fi
developer4616dbd2022-10-11 13:18:59 +08001312
developerb9a96602023-01-10 19:53:25 +08001313## dump command is only for vendor commands
1314elif [ "${cmd_type}" = "dump" ]; then
1315 do_cmd "mt76-vendor $*"
developer4616dbd2022-10-11 13:18:59 +08001316else
1317 echo "Unknown command"
1318fi