blob: 949c371425bf9a22378aadb810aea665ca057382 [file] [log] [blame]
developer3abe1ad2022-01-24 11:13:32 +08001#!/bin/ash
2
developer071927d2022-08-31 20:39:29 +08003interface=$1 # phy0/phy1/ra0
4cmd_type=$2 # set/show/e2p/mac
developer3abe1ad2022-01-24 11:13:32 +08005full_cmd=$3
developer9b7cdad2022-03-10 14:24:55 +08006interface_ori=${interface}
developer679a6aa2022-09-07 09:52:41 +08007start_idx_7986="0"
developer3abe1ad2022-01-24 11:13:32 +08008
9work_mode="RUN" # RUN/PRINT/DEBUG
developer679a6aa2022-09-07 09:52:41 +080010iwpriv_file="/tmp/iwpriv_wrapper"
11interface_file="/tmp/interface"
developer3abe1ad2022-01-24 11:13:32 +080012phy_idx=$(echo ${interface} | tr -dc '0-9')
13
developer3abe1ad2022-01-24 11:13:32 +080014function do_cmd() {
15 case ${work_mode} in
16 "RUN")
17 eval "$1"
18 ;;
19 "PRINT")
20 echo "$1"
21 ;;
22 "DEBUG")
developer3abe1ad2022-01-24 11:13:32 +080023 echo "$1"
developer887da632022-10-28 09:35:38 +080024 eval "$1"
developer3abe1ad2022-01-24 11:13:32 +080025 ;;
26 esac
27}
28
developer9b7cdad2022-03-10 14:24:55 +080029function print_debug() {
30 if [ "${work_mode}" = "DEBUG" ]; then
31 echo "$1"
32 fi
33}
34
developer10946c32022-03-04 18:28:43 +080035function write_dmesg() {
36 echo "$1" > /dev/kmsg
37}
38
developer3abe1ad2022-01-24 11:13:32 +080039function record_config() {
developer679a6aa2022-09-07 09:52:41 +080040 local config=$1
41 local tmp_file=$3
42
43 # check is mt7986 or mt7915/7916, and write its config
44 if [ ${config} != "STARTIDX" ]; then
45 if [ $phy_idx -lt $start_idx_7986 ]; then
46 config="${config}_PCIE"
47 elif [ $phy_idx -ge $start_idx_7986 ]; then
48 config="${config}_7986"
49 fi
50 fi
51
developer3abe1ad2022-01-24 11:13:32 +080052 if [ -f ${tmp_file} ]; then
developer679a6aa2022-09-07 09:52:41 +080053 if grep -q ${config} ${tmp_file}; then
54 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
developer3abe1ad2022-01-24 11:13:32 +080055 else
developer679a6aa2022-09-07 09:52:41 +080056 echo "${config}=$2" >> ${tmp_file}
developer3abe1ad2022-01-24 11:13:32 +080057 fi
58 else
developer679a6aa2022-09-07 09:52:41 +080059 echo "${config}=$2" >> ${tmp_file}
developer3abe1ad2022-01-24 11:13:32 +080060 fi
61}
62
63function get_config() {
developer679a6aa2022-09-07 09:52:41 +080064 local config=$1
65 local tmp_file=$2
66
developer10946c32022-03-04 18:28:43 +080067 if [ ! -f ${tmp_file} ]; then
68 echo ""
69 return
70 fi
71
developer679a6aa2022-09-07 09:52:41 +080072 # check is mt7986 or mt7915/7916, and load its config
73 if [ ${config} != "STARTIDX" ]; then
74 if [ $phy_idx -lt $start_idx_7986 ]; then
75 config="${config}_PCIE"
76 elif [ $phy_idx -ge $start_idx_7986 ]; then
77 config="${config}_7986"
78 fi
79 fi
80
81 if grep -q ${config} ${tmp_file}; then
82 echo "$(cat ${tmp_file} | grep ${config} | sed s/=/' '/g | cut -d " " -f 2)"
developer10946c32022-03-04 18:28:43 +080083 else
84 echo ""
85 fi
developer3abe1ad2022-01-24 11:13:32 +080086}
87
developereebce5c2022-08-26 19:05:56 +080088function convert_interface {
developer679a6aa2022-09-07 09:52:41 +080089 start_idx_7986=$(get_config "STARTIDX" ${interface_file})
90 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
developereebce5c2022-08-26 19:05:56 +080091 if [ -z "${start_idx_7986}" ]; then
developer679a6aa2022-09-07 09:52:41 +080092 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
developereebce5c2022-08-26 19:05:56 +080093 start_idx_7986="2"
developer679a6aa2022-09-07 09:52:41 +080094 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
95 start_idx_7986="1"
96 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
97 start_idx_7986="0"
developereebce5c2022-08-26 19:05:56 +080098 else
developer679a6aa2022-09-07 09:52:41 +080099 echo "Interface Conversion Failed!"
100 echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
101 echo "For AX6000: echo STARTIDX=0 >> ${interface_file}"
102 echo "For AX7800: echo STARTIDX=2 >> ${interface_file}"
103 echo "For AX8400: echo STARTIDX=1 >> ${interface_file}"
104 exit 0
developereebce5c2022-08-26 19:05:56 +0800105 fi
developer679a6aa2022-09-07 09:52:41 +0800106 record_config "STARTIDX" ${start_idx_7986} ${interface_file}
developereebce5c2022-08-26 19:05:56 +0800107 fi
108
109 if [[ $1 == "raix"* ]]; then
developereebce5c2022-08-26 19:05:56 +0800110 phy_idx=1
111 elif [[ $1 == "rai"* ]]; then
developereebce5c2022-08-26 19:05:56 +0800112 phy_idx=0
113 elif [[ $1 == "rax"* ]]; then
114 phy_idx=$((start_idx_7986+1))
developereebce5c2022-08-26 19:05:56 +0800115 else
116 phy_idx=$start_idx_7986
developer679a6aa2022-09-07 09:52:41 +0800117 fi
118
119 # convert phy index according to band idx
120 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
121 if [ "${band_idx}" = "0" ]; then
122 if [[ $1 == "raix"* ]]; then
123 phy_idx=0
124 elif [[ $1 == "rax"* ]]; then
125 phy_idx=$start_idx_7986
126 fi
127 elif [ "${band_idx}" = "1" ]; then
128 if [[ $1 == "rai"* ]]; then
129 phy_idx=1
130 elif [[ $1 == "ra"* ]]; then
131 phy_idx=$((start_idx_7986+1))
132 fi
133 fi
134
135 interface="phy${phy_idx}"
136}
137
138function change_band_idx {
139 local new_idx=$1
140 local new_phy_idx=$phy_idx
141
142 local old_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
143
144
145 if [[ ${interface_ori} == "ra"* ]]; then
146 if [ -z "${old_idx}" ] || [ "${old_idx}" != "${new_idx}" ]; then
147 if [ "${new_idx}" = "0" ]; then
148 # raix0 & rai0 becomes rai0
149 if [[ $interface_ori == "rai"* ]]; then
150 new_phy_idx=0
151 # rax0 & ra0 becomes ra0
152 elif [[ $interface_ori == "ra"* ]]; then
153 new_phy_idx=$start_idx_7986
154 fi
155 elif [ "${new_idx}" = "1" ]; then
156 # raix0 & rai0 becomes raix0
157 if [[ $interface_ori == "rai"* ]]; then
developer1346ce52022-12-15 21:36:14 +0800158 # For AX8400 => don't change phy idx
159 if [ ${start_idx_7986} != "1" ]; then
160 new_phy_idx=1
161 fi
developer679a6aa2022-09-07 09:52:41 +0800162 # rax0 & ra0 becomes rax0
163 elif [[ $interface_ori == "ra"* ]]; then
164 new_phy_idx=$((start_idx_7986+1))
165 fi
166 fi
167 fi
168
169 if [ ${new_phy_idx} != ${phy_idx} ]; then
170 do_ate_work "ATESTOP"
171 phy_idx=$new_phy_idx
172 interface="phy${phy_idx}"
173 do_ate_work "ATESTART"
174 fi
developereebce5c2022-08-26 19:05:56 +0800175 fi
developer679a6aa2022-09-07 09:52:41 +0800176 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
developereebce5c2022-08-26 19:05:56 +0800177}
178
developer3abe1ad2022-01-24 11:13:32 +0800179function simple_convert() {
180 if [ "$1" = "ATETXCNT" ]; then
181 echo "tx_count"
182 elif [ "$1" = "ATETXLEN" ]; then
183 echo "tx_length"
184 elif [ "$1" = "ATETXMCS" ]; then
185 echo "tx_rate_idx"
186 elif [ "$1" = "ATEVHTNSS" ]; then
187 echo "tx_rate_nss"
188 elif [ "$1" = "ATETXLDPC" ]; then
189 echo "tx_rate_ldpc"
190 elif [ "$1" = "ATETXSTBC" ]; then
191 echo "tx_rate_stbc"
192 elif [ "$1" = "ATEPKTTXTIME" ]; then
193 echo "tx_time"
194 elif [ "$1" = "ATEIPG" ]; then
195 echo "tx_ipg"
196 elif [ "$1" = "ATEDUTYCYCLE" ]; then
197 echo "tx_duty_cycle"
198 elif [ "$1" = "ATETXFREQOFFSET" ]; then
199 echo "freq_offset"
200 else
developer679a6aa2022-09-07 09:52:41 +0800201 echo "undefined"
developer3abe1ad2022-01-24 11:13:32 +0800202 fi
203}
204
205function convert_tx_mode() {
developer1346ce52022-12-15 21:36:14 +0800206 # Remove leading zeros
207 local tx_mode=$(echo $1 | sed 's/^0*//')
208
209 if [ "$tx_mode" = "0" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800210 echo "cck"
developer1346ce52022-12-15 21:36:14 +0800211 elif [ "$tx_mode" = "1" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800212 echo "ofdm"
developer1346ce52022-12-15 21:36:14 +0800213 elif [ "$tx_mode" = "2" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800214 echo "ht"
developer1346ce52022-12-15 21:36:14 +0800215 elif [ "$tx_mode" = "4" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800216 echo "vht"
developer1346ce52022-12-15 21:36:14 +0800217 elif [ "$tx_mode" = "8" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800218 echo "he_su"
developer1346ce52022-12-15 21:36:14 +0800219 elif [ "$tx_mode" = "9" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800220 echo "he_er"
developer1346ce52022-12-15 21:36:14 +0800221 elif [ "$tx_mode" = "10" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800222 echo "he_tb"
developer1346ce52022-12-15 21:36:14 +0800223 elif [ "$tx_mode" = "11" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800224 echo "he_mu"
225 else
developer679a6aa2022-09-07 09:52:41 +0800226 echo "undefined"
developer3abe1ad2022-01-24 11:13:32 +0800227 fi
228}
229
230function convert_gi {
231 local tx_mode=$1
232 local val=$2
233 local sgi="0"
234 local he_ltf="0"
235
236 case ${tx_mode} in
237 "ht"|"vht")
238 sgi=${val}
239 ;;
240 "he_su"|"he_er")
241 case ${val} in
242 "0")
243 ;;
244 "1")
245 he_ltf="1"
246 ;;
247 "2")
248 sgi="1"
249 he_ltf="1"
250 ;;
251 "3")
252 sgi="2"
253 he_ltf="2"
254 ;;
255 "4")
256 he_ltf="2"
257 ;;
258 *)
259 echo "unknown gi"
260 esac
261 ;;
262 "he_mu")
263 case ${val} in
264 "0")
265 he_ltf="2"
266 ;;
267 "1")
268 he_ltf="1"
269 ;;
270 "2")
271 sgi="1"
272 he_ltf="1"
273 ;;
274 "3")
275 sgi="2"
276 he_ltf="2"
277 ;;
278 *)
279 echo "unknown gi"
280 esac
281 ;;
282 "he_tb")
283 case ${val} in
284 "0")
285 sgi="1"
286 ;;
287 "1")
288 sgi="1"
289 he_ltf="1"
290 ;;
291 "2")
292 sgi="2"
293 he_ltf="2"
294 ;;
295 *)
296 echo "unknown gi"
297 esac
298 ;;
299 *)
developer9b7cdad2022-03-10 14:24:55 +0800300 print_debug "legacy mode no need gi"
developer3abe1ad2022-01-24 11:13:32 +0800301 esac
302
303 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
304}
305
306function convert_channel {
developer679a6aa2022-09-07 09:52:41 +0800307 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
developer3abe1ad2022-01-24 11:13:32 +0800308 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
developer679a6aa2022-09-07 09:52:41 +0800309 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
developer10946c32022-03-04 18:28:43 +0800310 local bw_str="HT20"
developereebce5c2022-08-26 19:05:56 +0800311 local base_chan=1
312 local control_freq=0
313 local base_freq=0
developer1346ce52022-12-15 21:36:14 +0800314 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
315 local temp=$((phy_idx+1))
developer3abe1ad2022-01-24 11:13:32 +0800316
developer1346ce52022-12-15 21:36:14 +0800317 # Handle ATECTRLBANDIDX
318 if [ ! -z ${ctrl_band_idx} ]; then
319 if [ "${ctrl_band_idx}" == "1" ] && [ ${band} == "0" ]; then
320 local temp=$(cat "/etc/config/wireless"| grep "option band" | sed -n ${temp}p | cut -c 15)
321 if [ "${temp}" == "2" ]; then
322 local band=0
323 elif [ "${temp}" == "5" ]; then
324 local band=1
325 elif [ "${temp}" == "6" ]; then
326 local band=2
327 else
328 echo "iwpriv wrapper band translate error!"
329 fi
330 else
331 # mt7915 in AX8400 case: band should be determined by only the input band
332 if [ "${start_idx_7986}" == "1" ] && [ ${phy_idx} == "0" ]; then
333 local band=$((band))
334 else
335 local band=$((ctrl_band_idx * band))
336 fi
337 fi
developer679a6aa2022-09-07 09:52:41 +0800338 fi
339
developer9b7cdad2022-03-10 14:24:55 +0800340 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800341 case ${bw} in
342 "1")
developer461cb542022-04-29 18:17:44 +0800343 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
344 local bw_str="HT20"
developer3abe1ad2022-01-24 11:13:32 +0800345 else
developer461cb542022-04-29 18:17:44 +0800346 local bw_str="HT40+"
347 ch=$(expr ${ch} - "2")
developer3abe1ad2022-01-24 11:13:32 +0800348 fi
349 ;;
developer3abe1ad2022-01-24 11:13:32 +0800350 esac
developereebce5c2022-08-26 19:05:56 +0800351 local base_freq=2412
developera6267142022-01-26 20:50:22 +0800352 elif [ "${band}" = "1" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800353 case ${bw} in
developera6267142022-01-26 20:50:22 +0800354 "5")
developer10946c32022-03-04 18:28:43 +0800355 bw_str="160MHz"
356 if [ ${ch} -lt "68" ]; then
357 ch="36"
358 elif [ ${ch} -lt "100" ]; then
359 ch="68"
360 elif [ ${ch} -lt "132" ]; then
361 ch="100"
362 elif [ ${ch} -lt "181" ]; then
363 ch="149"
364 fi
developera6267142022-01-26 20:50:22 +0800365 ;;
developer3abe1ad2022-01-24 11:13:32 +0800366 "2")
developer10946c32022-03-04 18:28:43 +0800367 bw_str="80MHz"
368 if [ ${ch} -lt "52" ]; then
369 ch="36"
370 elif [ ${ch} -lt "68" ]; then
371 ch="52"
372 elif [ ${ch} -lt "84" ]; then
373 ch="68"
374 elif [ ${ch} -lt "100" ]; then
375 ch="84"
376 elif [ ${ch} -lt "116" ]; then
377 ch="100"
378 elif [ ${ch} -lt "132" ]; then
379 ch="116"
380 elif [ ${ch} -lt "149" ]; then
381 ch="132"
382 elif [ ${ch} -lt "165" ]; then
383 ch="149"
384 elif [ ${ch} -lt "181" ]; then
385 ch="165"
386 fi
developer3abe1ad2022-01-24 11:13:32 +0800387 ;;
388 "1")
developer10946c32022-03-04 18:28:43 +0800389 if [ ${ch} -lt "44" ]; then
390 ch=$([ "${ch}" -lt "40" ] && echo "36" || echo "40")
391 bw_str=$([ "${ch}" -le "38" ] && echo "HT40+" || echo "HT40-")
392 elif [ ${ch} -lt "52" ]; then
393 ch=$([ "${ch}" -lt "48" ] && echo "44" || echo "48")
394 bw_str=$([ "${ch}" -le "46" ] && echo "HT40+" || echo "HT40-")
395 elif [ ${ch} -lt "60" ]; then
396 ch=$([ "${ch}" -lt "56" ] && echo "52" || echo "56")
397 bw_str=$([ "${ch}" -le "54" ] && echo "HT40+" || echo "HT40-")
398 elif [ ${ch} -lt "68" ]; then
399 ch=$([ "${ch}" -lt "64" ] && echo "60" || echo "64")
400 bw_str=$([ "${ch}" -le "62" ] && echo "HT40+" || echo "HT40-")
401 elif [ ${ch} -lt "76" ]; then
402 ch=$([ "${ch}" -lt "72" ] && echo "68" || echo "72")
403 bw_str=$([ "${ch}" -le "70" ] && echo "HT40+" || echo "HT40-")
404 elif [ ${ch} -lt "84" ]; then
405 ch=$([ "${ch}" -lt "80" ] && echo "76" || echo "80")
406 bw_str=$([ "${ch}" -le "78" ] && echo "HT40+" || echo "HT40-")
407 elif [ ${ch} -lt "92" ]; then
408 ch=$([ "${ch}" -lt "88" ] && echo "84" || echo "88")
409 bw_str=$([ "${ch}" -le "86" ] && echo "HT40+" || echo "HT40-")
410 elif [ ${ch} -lt "100" ]; then
411 ch=$([ "${ch}" -lt "96" ] && echo "92" || echo "96")
412 bw_str=$([ "${ch}" -le "94" ] && echo "HT40+" || echo "HT40-")
413 elif [ ${ch} -lt "108" ]; then
414 ch=$([ "${ch}" -lt "104" ] && echo "100" || echo "104")
415 bw_str=$([ "${ch}" -le "102" ] && echo "HT40+" || echo "HT40-")
416 elif [ ${ch} -lt "116" ]; then
417 ch=$([ "${ch}" -lt "112" ] && echo "108" || echo "112")
418 bw_str=$([ "${ch}" -le "110" ] && echo "HT40+" || echo "HT40-")
419 elif [ ${ch} -lt "124" ]; then
420 ch=$([ "${ch}" -lt "120" ] && echo "116" || echo "120")
421 bw_str=$([ "${ch}" -le "118" ] && echo "HT40+" || echo "HT40-")
422 elif [ ${ch} -lt "132" ]; then
423 ch=$([ "${ch}" -lt "128" ] && echo "124" || echo "128")
424 bw_str=$([ "${ch}" -le "126" ] && echo "HT40+" || echo "HT40-")
425 elif [ ${ch} -lt "140" ]; then
426 ch=$([ "${ch}" -lt "136" ] && echo "132" || echo "136")
427 bw_str=$([ "${ch}" -le "134" ] && echo "HT40+" || echo "HT40-")
428 elif [ ${ch} -lt "149" ]; then
429 ch=$([ "${ch}" -lt "144" ] && echo "140" || echo "144")
430 bw_str=$([ "${ch}" -le "142" ] && echo "HT40+" || echo "HT40-")
431 elif [ ${ch} -lt "157" ]; then
432 ch=$([ "${ch}" -lt "153" ] && echo "149" || echo "153")
433 bw_str=$([ "${ch}" -le "151" ] && echo "HT40+" || echo "HT40-")
434 elif [ ${ch} -lt "165" ]; then
435 ch=$([ "${ch}" -lt "161" ] && echo "157" || echo "161")
436 bw_str=$([ "${ch}" -le "159" ] && echo "HT40+" || echo "HT40-")
437 elif [ ${ch} -lt "173" ]; then
438 ch=$([ "${ch}" -lt "169" ] && echo "165" || echo "169")
439 bw_str=$([ "${ch}" -le "167" ] && echo "HT40+" || echo "HT40-")
440 elif [ ${ch} -lt "181" ]; then
441 ch=$([ "${ch}" -lt "177" ] && echo "173" || echo "177")
442 bw_str=$([ "${ch}" -le "175" ] && echo "HT40+" || echo "HT40-")
developer3abe1ad2022-01-24 11:13:32 +0800443 fi
444 ;;
445 "0")
446 local bw_str="HT20"
447 ;;
448 esac
developereebce5c2022-08-26 19:05:56 +0800449 local base_freq=5180
450 local base_chan=36
developera6267142022-01-26 20:50:22 +0800451 else
developereebce5c2022-08-26 19:05:56 +0800452 case ${bw} in
453 "5")
454 bw_str="160MHz"
455 if [ ${ch} -lt "33" ]; then
456 ch="1"
457 elif [ ${ch} -lt "65" ]; then
458 ch="33"
459 elif [ ${ch} -lt "97" ]; then
460 ch="65"
461 elif [ ${ch} -lt "129" ]; then
462 ch="97"
463 elif [ ${ch} -lt "161" ]; then
464 ch="129"
465 elif [ ${ch} -lt "193" ]; then
466 ch="161"
467 elif [ ${ch} -lt "225" ]; then
468 ch="193"
469 fi
470 ;;
471 "2")
472 bw_str="80MHz"
473 if [ ${ch} -lt "17" ]; then
474 ch="1"
475 elif [ ${ch} -lt "33" ]; then
476 ch="17"
477 elif [ ${ch} -lt "49" ]; then
478 ch="33"
479 elif [ ${ch} -lt "65" ]; then
480 ch="49"
481 elif [ ${ch} -lt "81" ]; then
482 ch="65"
483 elif [ ${ch} -lt "97" ]; then
484 ch="81"
485 elif [ ${ch} -lt "113" ]; then
486 ch="97"
487 elif [ ${ch} -lt "129" ]; then
488 ch="113"
489 elif [ ${ch} -lt "145" ]; then
490 ch="129"
491 elif [ ${ch} -lt "161" ]; then
492 ch="145"
493 elif [ ${ch} -lt "177" ]; then
494 ch="161"
495 elif [ ${ch} -lt "193" ]; then
496 ch="177"
497 elif [ ${ch} -lt "209" ]; then
498 ch="193"
499 elif [ ${ch} -lt "225" ]; then
500 ch="209"
501 fi
502 ;;
503 "1")
504 if [ ${ch} -lt "9" ]; then
505 ch=$([ "${ch}" -lt "5" ] && echo "1" || echo "5")
506 bw_str=$([ "${ch}" -le "3" ] && echo "HT40+" || echo "HT40-")
507 elif [ ${ch} -lt "17" ]; then
508 ch=$([ "${ch}" -lt "13" ] && echo "9" || echo "13")
509 bw_str=$([ "${ch}" -le "11" ] && echo "HT40+" || echo "HT40-")
510 elif [ ${ch} -lt "25" ]; then
511 ch=$([ "${ch}" -lt "21" ] && echo "17" || echo "21")
512 bw_str=$([ "${ch}" -le "19" ] && echo "HT40+" || echo "HT40-")
513 elif [ ${ch} -lt "33" ]; then
514 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
515 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
516 elif [ ${ch} -lt "33" ]; then
517 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
518 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
519 elif [ ${ch} -lt "41" ]; then
520 ch=$([ "${ch}" -lt "37" ] && echo "33" || echo "37")
521 bw_str=$([ "${ch}" -le "35" ] && echo "HT40+" || echo "HT40-")
522 elif [ ${ch} -lt "49" ]; then
523 ch=$([ "${ch}" -lt "45" ] && echo "41" || echo "45")
524 bw_str=$([ "${ch}" -le "43" ] && echo "HT40+" || echo "HT40-")
525 elif [ ${ch} -lt "57" ]; then
526 ch=$([ "${ch}" -lt "53" ] && echo "49" || echo "53")
527 bw_str=$([ "${ch}" -le "51" ] && echo "HT40+" || echo "HT40-")
528 elif [ ${ch} -lt "65" ]; then
529 ch=$([ "${ch}" -lt "61" ] && echo "57" || echo "61")
530 bw_str=$([ "${ch}" -le "59" ] && echo "HT40+" || echo "HT40-")
531 elif [ ${ch} -lt "73" ]; then
532 ch=$([ "${ch}" -lt "69" ] && echo "65" || echo "69")
533 bw_str=$([ "${ch}" -le "67" ] && echo "HT40+" || echo "HT40-")
534 elif [ ${ch} -lt "81" ]; then
535 ch=$([ "${ch}" -lt "77" ] && echo "73" || echo "77")
536 bw_str=$([ "${ch}" -le "75" ] && echo "HT40+" || echo "HT40-")
537 elif [ ${ch} -lt "89" ]; then
538 ch=$([ "${ch}" -lt "85" ] && echo "81" || echo "85")
539 bw_str=$([ "${ch}" -le "83" ] && echo "HT40+" || echo "HT40-")
540 elif [ ${ch} -lt "97" ]; then
541 ch=$([ "${ch}" -lt "93" ] && echo "89" || echo "93")
542 bw_str=$([ "${ch}" -le "91" ] && echo "HT40+" || echo "HT40-")
543 elif [ ${ch} -lt "105" ]; then
544 ch=$([ "${ch}" -lt "101" ] && echo "97" || echo "101")
545 bw_str=$([ "${ch}" -le "99" ] && echo "HT40+" || echo "HT40-")
546 elif [ ${ch} -lt "113" ]; then
547 ch=$([ "${ch}" -lt "109" ] && echo "105" || echo "109")
548 bw_str=$([ "${ch}" -le "107" ] && echo "HT40+" || echo "HT40-")
549 elif [ ${ch} -lt "121" ]; then
550 ch=$([ "${ch}" -lt "117" ] && echo "113" || echo "117")
551 bw_str=$([ "${ch}" -le "115" ] && echo "HT40+" || echo "HT40-")
552 elif [ ${ch} -lt "129" ]; then
553 ch=$([ "${ch}" -lt "125" ] && echo "121" || echo "125")
554 bw_str=$([ "${ch}" -le "123" ] && echo "HT40+" || echo "HT40-")
555 elif [ ${ch} -lt "137" ]; then
556 ch=$([ "${ch}" -lt "133" ] && echo "129" || echo "133")
557 bw_str=$([ "${ch}" -le "131" ] && echo "HT40+" || echo "HT40-")
558 elif [ ${ch} -lt "145" ]; then
559 ch=$([ "${ch}" -lt "141" ] && echo "137" || echo "141")
560 bw_str=$([ "${ch}" -le "139" ] && echo "HT40+" || echo "HT40-")
561 elif [ ${ch} -lt "153" ]; then
562 ch=$([ "${ch}" -lt "149" ] && echo "145" || echo "149")
563 bw_str=$([ "${ch}" -le "147" ] && echo "HT40+" || echo "HT40-")
564 elif [ ${ch} -lt "161" ]; then
565 ch=$([ "${ch}" -lt "157" ] && echo "153" || echo "157")
566 bw_str=$([ "${ch}" -le "155" ] && echo "HT40+" || echo "HT40-")
567 elif [ ${ch} -lt "169" ]; then
568 ch=$([ "${ch}" -lt "165" ] && echo "161" || echo "165")
569 bw_str=$([ "${ch}" -le "163" ] && echo "HT40+" || echo "HT40-")
570 elif [ ${ch} -lt "177" ]; then
571 ch=$([ "${ch}" -lt "173" ] && echo "169" || echo "173")
572 bw_str=$([ "${ch}" -le "171" ] && echo "HT40+" || echo "HT40-")
573 elif [ ${ch} -lt "185" ]; then
574 ch=$([ "${ch}" -lt "181" ] && echo "177" || echo "181")
575 bw_str=$([ "${ch}" -le "179" ] && echo "HT40+" || echo "HT40-")
576 elif [ ${ch} -lt "193" ]; then
577 ch=$([ "${ch}" -lt "189" ] && echo "185" || echo "189")
578 bw_str=$([ "${ch}" -le "187" ] && echo "HT40+" || echo "HT40-")
579 elif [ ${ch} -lt "201" ]; then
580 ch=$([ "${ch}" -lt "197" ] && echo "193" || echo "197")
581 bw_str=$([ "${ch}" -le "195" ] && echo "HT40+" || echo "HT40-")
582 elif [ ${ch} -lt "209" ]; then
583 ch=$([ "${ch}" -lt "205" ] && echo "201" || echo "205")
584 bw_str=$([ "${ch}" -le "203" ] && echo "HT40+" || echo "HT40-")
585 elif [ ${ch} -lt "217" ]; then
586 ch=$([ "${ch}" -lt "213" ] && echo "209" || echo "213")
587 bw_str=$([ "${ch}" -le "211" ] && echo "HT40+" || echo "HT40-")
588 elif [ ${ch} -lt "225" ]; then
589 ch=$([ "${ch}" -lt "221" ] && echo "217" || echo "221")
590 bw_str=$([ "${ch}" -le "219" ] && echo "HT40+" || echo "HT40-")
591 elif [ ${ch} -lt "233" ]; then
592 ch=$([ "${ch}" -lt "229" ] && echo "225" || echo "229")
593 bw_str=$([ "${ch}" -le "227" ] && echo "HT40+" || echo "HT40-")
594 fi
595 ;;
596 "0")
597 local bw_str="HT20"
598 ;;
599 esac
600 local base_freq=5955
developer3abe1ad2022-01-24 11:13:32 +0800601 fi
602
developereebce5c2022-08-26 19:05:56 +0800603 local control_freq=$(((ch - base_chan) * 5 + base_freq))
604 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
developer3abe1ad2022-01-24 11:13:32 +0800605}
606
developer10946c32022-03-04 18:28:43 +0800607function convert_rxstat {
608 local res=$(do_cmd "mt76-test ${interface} dump stats")
609 local mdrdy=$(echo "${res}" | grep "rx_packets" | cut -d "=" -f 2)
610 local fcs_error=$(echo "${res}" | grep "rx_fcs_error" | cut -d "=" -f 2)
611 local rcpi=$(echo "${res}" | grep "last_rcpi" | cut -d "=" -f 2 | sed 's/,/ /g')
612 local ib_rssi=$(echo "${res}" | grep "last_ib_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
613 local wb_rssi=$(echo "${res}" | grep "last_wb_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
614 local rx_ok=$(expr ${mdrdy} - ${fcs_error})
615
developer461cb542022-04-29 18:17:44 +0800616 write_dmesg "rcpi: ${rcpi}"
617 write_dmesg "fagc rssi ib: ${ib_rssi}"
618 write_dmesg "fagc rssi wb: ${wb_rssi}"
619 write_dmesg "all_mac_rx_mdrdy_cnt: ${mdrdy}"
620 write_dmesg "all_mac_rx_fcs_err_cnt: ${fcs_error}"
developer9b7cdad2022-03-10 14:24:55 +0800621 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
developer10946c32022-03-04 18:28:43 +0800622}
623
developer10946c32022-03-04 18:28:43 +0800624function set_mac_addr {
developer679a6aa2022-09-07 09:52:41 +0800625 record_config ${cmd} ${param} ${iwpriv_file}
developer10946c32022-03-04 18:28:43 +0800626
developer679a6aa2022-09-07 09:52:41 +0800627 local addr1=$(get_config "ATEDA" ${iwpriv_file})
628 local addr2=$(get_config "ATESA" ${iwpriv_file})
629 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
developer10946c32022-03-04 18:28:43 +0800630
631 if [ -z "${addr1}" ]; then
632 addr1="00:11:22:33:44:55"
633 fi
634 if [ -z "${addr2}" ]; then
635 addr2="00:11:22:33:44:55"
636 fi
637 if [ -z "${addr3}" ]; then
638 addr3="00:11:22:33:44:55"
639 fi
640
641 do_cmd "mt76-test phy${phy_idx} set mac_addrs=${addr1},${addr2},${addr3}"
642}
643
developerf9843e22022-09-13 10:57:15 +0800644function convert_ibf {
645 local cmd=$1
646 local param=$2
647 local new_cmd=""
648 local new_param=$(echo ${param} | sed s/":"/","/g)
649
650 case ${cmd} in
651 "ATETxBfInit")
652 new_cmd="init"
developer1346ce52022-12-15 21:36:14 +0800653 new_param="1"
654 do_cmd "mt76-test phy${phy_idx} set state=idle"
655 ;;
656 "ATETxBfGdInit")
657 new_cmd="golden_init"
658 new_param="1"
developerf9843e22022-09-13 10:57:15 +0800659 do_cmd "mt76-test phy${phy_idx} set state=idle"
660 ;;
661 "ATEIBFPhaseComp")
662 new_cmd="phase_comp"
developer1346ce52022-12-15 21:36:14 +0800663 new_param="${new_param}"
developerf9843e22022-09-13 10:57:15 +0800664 ;;
665 "ATEEBfProfileConfig")
666 new_cmd="ebf_prof_update"
667 ;;
668 "ATEIBfProfileConfig")
669 new_cmd="ibf_prof_update"
670 ;;
671 "ATEIBfInstCal")
672 new_cmd="phase_cal"
673 ;;
674 "ATEIBfGdCal")
675 new_cmd="phase_cal"
676 new_param="${new_param},00"
677 ;;
678 "TxBfTxApply")
679 new_cmd="apply_tx"
680 ;;
681 "ATETxPacketWithBf")
682 local bf_on=${new_param:0:2}
683 local aid="01"
684 local wlan_idx=${new_param:3:2}
685 local update="00"
686 local tx_len=${new_param:6}
687
688 new_cmd="tx_prep"
689 new_param="${bf_on},${aid},${wlan_idx},${update}"
690 if [ "${tx_len}" = "00" ]; then
691 new_param="${new_param} aid=1 tx_count=10000000 tx_length=1024"
692 else
693 new_param="${new_param} aid=1 tx_count=${tx_len} tx_length=1024"
694 fi
695 do_cmd "mt76-test phy${phy_idx} set state=idle"
696 ;;
697 "TxBfProfileData20MAllWrite")
698 new_cmd="prof_update_all"
699 ;;
700 "ATEIBFPhaseE2pUpdate")
701 new_cmd="e2p_update"
702 ;;
developer1346ce52022-12-15 21:36:14 +0800703 "ATEIBFPhaseVerify")
704 local group=${new_param:0:2}
705 local group_l_m_h=${new_param:3:2}
706 local band_idx=${new_param:6:2}
707 local phase_cal_type=${new_param:9:2}
708 local LNA_gain_level=${new_param:12:2}
709 local read_from_e2p=${new_param:15:2}
710
711 do_cmd "mt76-test phy${phy_idx} set txbf_act=phase_comp txbf_param=1,${band_idx},${group},${read_from_e2p},0"
712 new_cmd="phase_cal"
713 new_param="${group},${group_l_m_h},${band_idx},${phase_cal_type},${LNA_gain_level}"
714 ;;
715 "TxBfProfileTagRead")
716 new_cmd="pfmu_tag_read"
717 ;;
718 "TxBfProfileTagWrite")
719 new_cmd="pfmu_tag_write"
720 ;;
721 "TxBfProfileTagInValid")
722 new_cmd="set_invalid_prof"
723 ;;
724 "StaRecBfRead")
725 new_cmd="sta_rec_read"
726 ;;
727 "TriggerSounding")
728 new_cmd="trigger_sounding"
729 ;;
730 "StopSounding")
731 new_cmd="stop_sounding"
732 new_param="0"
733 ;;
734 "ATEConTxETxBfGdProc")
735 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
736 local tx_rate_idx=${new_param:3:2}
737 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
738 local channel=${new_param:9:3}
739 local channel2=${new_param:13:3}
740 local band=${new_param:17}
741
742 new_cmd="ebf_golden_init"
743 do_ate_work "ATESTART"
744 do_cmd "mt76-test phy${phy_idx} set state=idle"
745 record_config "ATETXBW" ${bw} ${iwpriv_file}
746 convert_channel "${channel}:${band}"
747 if [ "${bw}" = "5" ]; then
748 new_param="1,1"
749 else
750 new_param="1,0"
751 fi
752 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_sgi=0"
753 ;;
754 "ATEConTxETxBfInitProc")
755 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
756 local tx_rate_idx=${new_param:3:2}
757 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
758 local tx_rate_nss=${new_param:9:2}
759 local tx_stream=${new_param:12:2}
760 local tx_power=${new_param:15:2}
761 local channel=${new_param:18:3}
762 local channel2=${new_param:22:3}
763 local band=${new_param:26:1}
764 local tx_length=${new_param:28:5}
765
766 new_cmd="ebf_init"
767 do_ate_work "ATESTART"
768 do_cmd "mt76-test phy${phy_idx} set state=idle"
769 record_config "ATETXBW" ${bw} ${iwpriv_file}
770 convert_channel "${channel}:${band}"
771 new_param="1"
772 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"
773 ;;
developerf9843e22022-09-13 10:57:15 +0800774 *)
775 esac
776
777 do_cmd "mt76-test phy${phy_idx} set txbf_act=${new_cmd} txbf_param=${new_param}"
778
779 if [ "${cmd}" = "ATETxPacketWithBf" ]; then
780 do_cmd "mt76-test phy${phy_idx} set state=tx_frames"
developer1346ce52022-12-15 21:36:14 +0800781 elif [ "${cmd}" = "ATEConTxETxBfInitProc" ]; then
782 do_cmd "mt76-test phy${phy_idx} set aid=1"
783 do_cmd "mt76-test phy${phy_idx} set txbf_act=stop_sounding txbf_param=1"
784 do_cmd "mt76-test phy${phy_idx} set txbf_act=update_ch txbf_param=1"
785 do_cmd "mt76-test phy${phy_idx} set txbf_act=ebf_prof_update txbf_param=0,0,0"
786 do_cmd "mt76-test phy${phy_idx} set txbf_act=apply_tx txbf_param=1,1,0,0,0"
787 do_cmd "mt76-test phy${phy_idx} set txbf_act=pfmu_tag_read txbf_param=0,1"
788 do_cmd "mt76-test phy${phy_idx} set txbf_act=sta_rec_read txbf_param=1"
789 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=0,1,0,1,0,0,0"
790 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=2,1,ff,1,0,0,0"
791 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
792 elif [ "${cmd}" = "ATEConTxETxBfGdProc" ]; then
793 do_cmd "mt76-test phy${phy_idx} set aid=1"
794 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
795 elif [ "${cmd}" = "ATETxBfInit" ]; then
796 do_cmd "mt76-test phy${phy_idx} set aid=1"
797 elif [ "${cmd}" = "ATETxBfGdInit" ]; then
798 do_cmd "mt76-test phy${phy_idx} set aid=1"
developerf9843e22022-09-13 10:57:15 +0800799 fi
800}
801
developer887da632022-10-28 09:35:38 +0800802function convert_dfs {
803 local cmd=$1
804 local param=$2
805
806 case ${cmd} in
807 "DfsRxCtrl")
808 local offchan_ch="$(echo $param | cut -d ':' -f1)"
809 local offchan_bw="$(echo $param | cut -d ':' -f2)"
810
811 if [ "$offchan_bw" = "0" ]; then
812 offchan_bw="20"
813 elif [ "$offchan_bw" = "1" ]; then
814 offchan_bw="40"
815 elif [ "$offchan_bw" = "2" ]; then
816 offchan_bw="80"
817 fi
818
819 do_cmd "mt76-test phy${phy_idx} set state=idle"
820 do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
821 ;;
822 "DfsRxHist")
823 local ipi_th="$(echo $param | cut -d ':' -f 1)"
824 local ipi_period="$(echo $param | cut -d ':' -f 2)"
825 local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
826
827 if [ -z $ipi_antenna ]; then
828 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
829 else
830 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
831 fi
832 ;;
833 *)
834 esac
835}
836
developera6267142022-01-26 20:50:22 +0800837function do_ate_work() {
838 local ate_cmd=$1
839
840 case ${ate_cmd} in
841 "ATESTART")
842 local if_str=$(ifconfig | grep mon${phy_idx})
843
844 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
845 echo "ATE already starts."
846 else
847 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
848 do_cmd "iw dev wlan${phy_idx} del"
849 do_cmd "ifconfig mon${phy_idx} up"
developer9b7cdad2022-03-10 14:24:55 +0800850 do_cmd "iw reg set VV"
developera6267142022-01-26 20:50:22 +0800851 fi
852 ;;
853 "ATESTOP")
854 local if_str=$(ifconfig | grep mon${phy_idx})
855
856 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
857 echo "ATE does not start."
858 else
859 do_cmd "mt76-test ${interface} set state=off"
860 do_cmd "iw dev mon${phy_idx} del"
861 do_cmd "iw phy ${interface} interface add wlan${phy_idx} type managed"
developer461cb542022-04-29 18:17:44 +0800862 do_cmd "mt76-test ${interface} set aid=0"
developera6267142022-01-26 20:50:22 +0800863 fi
developer10946c32022-03-04 18:28:43 +0800864
developer679a6aa2022-09-07 09:52:41 +0800865 if [ ${phy_idx} -lt ${start_idx_7986} ]; then
866 sed -i '/_PCIE=/d' ${iwpriv_file}
867 elif [ ${phy_idx} -ge ${start_idx_7986} ]; then
868 sed -i '/_7986=/d' ${iwpriv_file}
869 fi
developera6267142022-01-26 20:50:22 +0800870 ;;
developer461cb542022-04-29 18:17:44 +0800871 "TXCOMMIT")
872 do_cmd "mt76-test ${interface} set aid=1"
873 ;;
developera6267142022-01-26 20:50:22 +0800874 "TXFRAME")
875 do_cmd "mt76-test ${interface} set state=tx_frames"
876 ;;
developer9b7cdad2022-03-10 14:24:55 +0800877 "TXSTOP"|"RXSTOP")
developera6267142022-01-26 20:50:22 +0800878 do_cmd "mt76-test ${interface} set state=idle"
879 ;;
developer461cb542022-04-29 18:17:44 +0800880 "TXREVERT")
881 do_cmd "mt76-test ${interface} set aid=0"
882 ;;
developera6267142022-01-26 20:50:22 +0800883 "RXFRAME")
884 do_cmd "mt76-test ${interface} set state=rx_frames"
885 ;;
886 "TXCONT")
887 do_cmd "mt76-test ${interface} set state=tx_cont"
888 ;;
developer071927d2022-08-31 20:39:29 +0800889 "GROUPREK")
890 do_cmd "mt76-test ${interface} set state=group_prek"
891 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
892 ;;
893 "GROUPREKDump")
894 do_cmd "mt76-test ${interface} set state=group_prek_dump"
895 ;;
896 "GROUPREKClean")
897 do_cmd "mt76-test ${interface} set state=group_prek_clean"
898 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
899 ;;
900 "DPD2G")
901 do_cmd "mt76-test ${interface} set state=dpd_2g"
902 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
903 ;;
904 "DPD5G")
905 do_cmd "mt76-test ${interface} set state=dpd_5g"
906 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
907 ;;
908 "DPD6G")
909 do_cmd "mt76-test ${interface} set state=dpd_6g"
910 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
911 ;;
912 "DPDDump")
913 do_cmd "mt76-test ${interface} set state=dpd_dump"
914 ;;
915 "DPDClean")
916 do_cmd "mt76-test ${interface} set state=dpd_clean"
917 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
918 ;;
developer9b7cdad2022-03-10 14:24:55 +0800919 *)
developer9b7cdad2022-03-10 14:24:55 +0800920 print_debug "skip ${ate_cmd}"
developera6267142022-01-26 20:50:22 +0800921 ;;
922 esac
923}
924
developer10946c32022-03-04 18:28:43 +0800925# main start here
926
927if [[ ${interface} == "ra"* ]]; then
developereebce5c2022-08-26 19:05:56 +0800928 convert_interface $interface
developer10946c32022-03-04 18:28:43 +0800929fi
930
developer679a6aa2022-09-07 09:52:41 +0800931tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
932
933if [ ! -z ${tmp_work_mode} ]; then
934 work_mode=${tmp_work_mode}
935fi
936
developer10946c32022-03-04 18:28:43 +0800937cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
938param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
939
developer3abe1ad2022-01-24 11:13:32 +0800940if [ "${cmd_type}" = "set" ]; then
941 skip=0
developer3abe1ad2022-01-24 11:13:32 +0800942 case ${cmd} in
943 "ATE")
944 do_ate_work ${param}
945
946 skip=1
947 ;;
948 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
949 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
950 cmd_new=$(simple_convert ${cmd})
developer679a6aa2022-09-07 09:52:41 +0800951 if [ "${param_new}" = "undefined" ]; then
952 echo "unknown cmd: ${cmd}"
953 exit
954 fi
developer3abe1ad2022-01-24 11:13:32 +0800955 param_new=${param}
developer1346ce52022-12-15 21:36:14 +0800956 if [ "${cmd}" = "ATETXCNT" ] && [ "${param}" = "0" ]; then
957 param_new="10000000"
958 fi
developer3abe1ad2022-01-24 11:13:32 +0800959 ;;
960 "ATETXANT"|"ATERXANT")
961 cmd_new="tx_antenna"
962 param_new=${param}
963 ;;
964 "ATETXGI")
developer679a6aa2022-09-07 09:52:41 +0800965 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
developer3abe1ad2022-01-24 11:13:32 +0800966 convert_gi ${tx_mode} ${param}
967 skip=1
968 ;;
969 "ATETXMODE")
970 cmd_new="tx_rate_mode"
971 param_new=$(convert_tx_mode ${param})
developer679a6aa2022-09-07 09:52:41 +0800972 if [ "${param_new}" = "undefined" ]; then
973 echo "unknown tx mode"
974 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
975 exit
976 else
977 record_config ${cmd} ${param} ${iwpriv_file}
978 fi
developer3abe1ad2022-01-24 11:13:32 +0800979 ;;
980 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3")
981 cmd_new="tx_power"
982 param_new="${param},0,0,0"
983 ;;
984 "ATETXBW")
developer679a6aa2022-09-07 09:52:41 +0800985 record_config ${cmd} ${param} ${iwpriv_file}
developer3abe1ad2022-01-24 11:13:32 +0800986 skip=1
987 ;;
988 "ATECHANNEL")
989 convert_channel ${param}
990 skip=1
991 ;;
developer10946c32022-03-04 18:28:43 +0800992 "ATERXSTAT")
993 convert_rxstat
994 skip=1
995 ;;
developer3abe1ad2022-01-24 11:13:32 +0800996 "ATECTRLBANDIDX")
developer10946c32022-03-04 18:28:43 +0800997 change_band_idx ${param}
developer3abe1ad2022-01-24 11:13:32 +0800998 skip=1
999 ;;
developer10946c32022-03-04 18:28:43 +08001000 "ATEDA"|"ATESA"|"ATEBSSID")
1001 set_mac_addr ${cmd} ${param}
1002 skip=1
1003 ;;
developer887da632022-10-28 09:35:38 +08001004 "DfsRxCtrl"|"DfsRxHist")
1005 convert_dfs ${cmd} ${param}
1006 skip=1
1007 ;;
developer1346ce52022-12-15 21:36:14 +08001008 "ATETxBfInit"|"ATETxBfGdInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
1009 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"| \
1010 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate"|"TriggerSounding"|"StopSounding"| \
1011 "StaRecBfRead"|"TxBfProfileTagInValid"|"TxBfProfileTagWrite"|"TxBfProfileTagRead"| \
1012 "ATEIBFPhaseVerify"|"ATEConTxETxBfGdProc"|"ATEConTxETxBfInitProc")
developerf9843e22022-09-13 10:57:15 +08001013 convert_ibf ${cmd} ${param}
1014 skip=1
1015 ;;
developer3abe1ad2022-01-24 11:13:32 +08001016 "bufferMode")
1017 if [ "${param}" = "2" ]; then
developer461cb542022-04-29 18:17:44 +08001018 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
developer3abe1ad2022-01-24 11:13:32 +08001019 fi
1020 skip=1
1021 ;;
developera6267142022-01-26 20:50:22 +08001022 "ResetCounter"|"ATERXSTATRESET")
1023 skip=1
1024 ;;
developer679a6aa2022-09-07 09:52:41 +08001025 "WORKMODE")
1026 record_config "WORKMODE" ${param} ${iwpriv_file}
1027 echo "Entering ${param} mode in iwpriv"
1028 skip=1
1029 ;;
developer3abe1ad2022-01-24 11:13:32 +08001030 *)
developer9b7cdad2022-03-10 14:24:55 +08001031 print_debug "Unknown command to set: ${cmd}"
developer3abe1ad2022-01-24 11:13:32 +08001032 skip=1
1033 esac
1034
1035 if [ "${skip}" != "1" ]; then
1036 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
1037 fi
developer10946c32022-03-04 18:28:43 +08001038
developer3abe1ad2022-01-24 11:13:32 +08001039elif [ "${cmd_type}" = "show" ]; then
developer1346ce52022-12-15 21:36:14 +08001040 if [ "${cmd}" = "wtbl" ]; then
1041 wlan_idx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wlan_idx
1042 wtbl_info=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wtbl_info
1043
1044 do_cmd "echo ${param} > ${wlan_idx}"
1045 do_cmd "cat ${wtbl_info}"
1046 else
1047 do_cmd "mt76-test ${interface} dump"
1048 do_cmd "mt76-test ${interface} dump stats"
1049 fi
developer10946c32022-03-04 18:28:43 +08001050
developer3abe1ad2022-01-24 11:13:32 +08001051elif [ "${cmd_type}" = "e2p" ]; then
developera6267142022-01-26 20:50:22 +08001052 offset=$(printf "0x%s" ${cmd})
1053 val=$(printf "0x%s" ${param})
1054
1055 # eeprom offset write
1056 if [[ ${full_cmd} == *"="* ]]; then
1057 tmp=$((${val} & 0xff))
1058 tmp=$(printf "0x%x" ${tmp})
developer461cb542022-04-29 18:17:44 +08001059 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developera6267142022-01-26 20:50:22 +08001060
1061 offset=$((${offset}))
1062 offset=$(expr ${offset} + "1")
1063 offset=$(printf "0x%x" ${offset})
1064 tmp=$(((${val} >> 8) & 0xff))
1065 tmp=$(printf "0x%x" ${tmp})
developer461cb542022-04-29 18:17:44 +08001066 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developera6267142022-01-26 20:50:22 +08001067 else
developer461cb542022-04-29 18:17:44 +08001068 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
developera6267142022-01-26 20:50:22 +08001069 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developer3abe1ad2022-01-24 11:13:32 +08001070
developera6267142022-01-26 20:50:22 +08001071 tmp=$(printf "0x%s" ${param})
1072 tmp=$((${tmp}))
1073 param2=$(expr ${tmp} + "1")
1074 param2=$(printf "%x" ${param2})
developer461cb542022-04-29 18:17:44 +08001075 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
developera6267142022-01-26 20:50:22 +08001076 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
1077
1078 param=$(printf "0x%s" ${param})
developer461cb542022-04-29 18:17:44 +08001079 param=$(printf "%04x" ${param})
1080 param=$(echo $param | tr 'a-z' 'A-Z')
developer9b7cdad2022-03-10 14:24:55 +08001081 printf "%s e2p:\n" ${interface_ori}
developer461cb542022-04-29 18:17:44 +08001082 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
developera6267142022-01-26 20:50:22 +08001083 fi
developer10946c32022-03-04 18:28:43 +08001084
developera6267142022-01-26 20:50:22 +08001085elif [ "${cmd_type}" = "mac" ]; then
1086 regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
1087 regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
1088 offset=$(printf "0x%s" ${cmd})
1089 val=$(printf "0x%s" ${param})
1090
1091 echo ${offset} > ${regidx}
1092 # reg write
1093 if [[ ${full_cmd} == *"="* ]]; then
1094 echo ${val} > ${regval}
developera6267142022-01-26 20:50:22 +08001095 fi
developer10946c32022-03-04 18:28:43 +08001096
developer461cb542022-04-29 18:17:44 +08001097 res=$(cat ${regval} | cut -d 'x' -f 2)
1098 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
1099
developer3abe1ad2022-01-24 11:13:32 +08001100else
1101 echo "Unknown command"
1102fi