blob: d42c32bbb42cffb85c3e25b2f5f98262abf04665 [file] [log] [blame]
developerb9b4cd12022-10-11 13:18:59 +08001#!/bin/ash
2
3interface=$1 # phy0/phy1/ra0
4cmd_type=$2 # set/show/e2p/mac
5full_cmd=$3
6interface_ori=${interface}
7start_idx_7986="0"
8
9work_mode="RUN" # RUN/PRINT/DEBUG
10iwpriv_file="/tmp/iwpriv_wrapper"
11interface_file="/tmp/interface"
12phy_idx=$(echo ${interface} | tr -dc '0-9')
13
14function do_cmd() {
15 case ${work_mode} in
16 "RUN")
17 eval "$1"
18 ;;
19 "PRINT")
20 echo "$1"
21 ;;
22 "DEBUG")
developerb9b4cd12022-10-11 13:18:59 +080023 echo "$1"
developerb403ad02022-11-08 10:16:29 +080024 eval "$1"
developerb9b4cd12022-10-11 13:18:59 +080025 ;;
26 esac
27}
28
29function print_debug() {
30 if [ "${work_mode}" = "DEBUG" ]; then
31 echo "$1"
32 fi
33}
34
35function write_dmesg() {
36 echo "$1" > /dev/kmsg
37}
38
39function record_config() {
40 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
52 if [ -f ${tmp_file} ]; then
53 if grep -q ${config} ${tmp_file}; then
54 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
55 else
56 echo "${config}=$2" >> ${tmp_file}
57 fi
58 else
59 echo "${config}=$2" >> ${tmp_file}
60 fi
61}
62
63function get_config() {
64 local config=$1
65 local tmp_file=$2
66
67 if [ ! -f ${tmp_file} ]; then
68 echo ""
69 return
70 fi
71
72 # 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)"
83 else
84 echo ""
85 fi
86}
87
88function convert_interface {
89 start_idx_7986=$(get_config "STARTIDX" ${interface_file})
90 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
91 if [ -z "${start_idx_7986}" ]; then
92 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
93 start_idx_7986="2"
94 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"
98 else
99 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
105 fi
106 record_config "STARTIDX" ${start_idx_7986} ${interface_file}
107 fi
108
109 if [[ $1 == "raix"* ]]; then
110 phy_idx=1
111 elif [[ $1 == "rai"* ]]; then
112 phy_idx=0
113 elif [[ $1 == "rax"* ]]; then
114 phy_idx=$((start_idx_7986+1))
115 else
116 phy_idx=$start_idx_7986
117 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
158 new_phy_idx=1
159 # rax0 & ra0 becomes rax0
160 elif [[ $interface_ori == "ra"* ]]; then
161 new_phy_idx=$((start_idx_7986+1))
162 fi
163 fi
164 fi
165
166 if [ ${new_phy_idx} != ${phy_idx} ]; then
167 do_ate_work "ATESTOP"
168 phy_idx=$new_phy_idx
169 interface="phy${phy_idx}"
170 do_ate_work "ATESTART"
171 fi
172 fi
173 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
174}
175
176function simple_convert() {
177 if [ "$1" = "ATETXCNT" ]; then
178 echo "tx_count"
179 elif [ "$1" = "ATETXLEN" ]; then
180 echo "tx_length"
181 elif [ "$1" = "ATETXMCS" ]; then
182 echo "tx_rate_idx"
183 elif [ "$1" = "ATEVHTNSS" ]; then
184 echo "tx_rate_nss"
185 elif [ "$1" = "ATETXLDPC" ]; then
186 echo "tx_rate_ldpc"
187 elif [ "$1" = "ATETXSTBC" ]; then
188 echo "tx_rate_stbc"
189 elif [ "$1" = "ATEPKTTXTIME" ]; then
190 echo "tx_time"
191 elif [ "$1" = "ATEIPG" ]; then
192 echo "tx_ipg"
193 elif [ "$1" = "ATEDUTYCYCLE" ]; then
194 echo "tx_duty_cycle"
195 elif [ "$1" = "ATETXFREQOFFSET" ]; then
196 echo "freq_offset"
197 else
198 echo "undefined"
199 fi
200}
201
202function convert_tx_mode() {
203 if [ "$1" = "0" ]; then
204 echo "cck"
205 elif [ "$1" = "1" ]; then
206 echo "ofdm"
207 elif [ "$1" = "2" ]; then
208 echo "ht"
209 elif [ "$1" = "4" ]; then
210 echo "vht"
211 elif [ "$1" = "8" ]; then
212 echo "he_su"
213 elif [ "$1" = "9" ]; then
214 echo "he_er"
215 elif [ "$1" = "10" ]; then
216 echo "he_tb"
217 elif [ "$1" = "11" ]; then
218 echo "he_mu"
219 else
220 echo "undefined"
221 fi
222}
223
224function convert_gi {
225 local tx_mode=$1
226 local val=$2
227 local sgi="0"
228 local he_ltf="0"
229
230 case ${tx_mode} in
231 "ht"|"vht")
232 sgi=${val}
233 ;;
234 "he_su"|"he_er")
235 case ${val} in
236 "0")
237 ;;
238 "1")
239 he_ltf="1"
240 ;;
241 "2")
242 sgi="1"
243 he_ltf="1"
244 ;;
245 "3")
246 sgi="2"
247 he_ltf="2"
248 ;;
249 "4")
250 he_ltf="2"
251 ;;
252 *)
253 echo "unknown gi"
254 esac
255 ;;
256 "he_mu")
257 case ${val} in
258 "0")
259 he_ltf="2"
260 ;;
261 "1")
262 he_ltf="1"
263 ;;
264 "2")
265 sgi="1"
266 he_ltf="1"
267 ;;
268 "3")
269 sgi="2"
270 he_ltf="2"
271 ;;
272 *)
273 echo "unknown gi"
274 esac
275 ;;
276 "he_tb")
277 case ${val} in
278 "0")
279 sgi="1"
280 ;;
281 "1")
282 sgi="1"
283 he_ltf="1"
284 ;;
285 "2")
286 sgi="2"
287 he_ltf="2"
288 ;;
289 *)
290 echo "unknown gi"
291 esac
292 ;;
293 *)
294 print_debug "legacy mode no need gi"
295 esac
296
297 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
298}
299
300function convert_channel {
301 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
302 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
303 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
304 local bw_str="HT20"
305 local base_chan=1
306 local control_freq=0
307 local base_freq=0
308
309 if [ -z ${ctrl_band_idx} ]; then
310 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
311 else
312 local band=$ctrl_band_idx
313 fi
314
315 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
316 case ${bw} in
317 "1")
318 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
319 local bw_str="HT20"
320 else
321 local bw_str="HT40+"
322 ch=$(expr ${ch} - "2")
323 fi
324 ;;
325 esac
326 local base_freq=2412
327 elif [ "${band}" = "1" ]; then
328 case ${bw} in
329 "5")
330 bw_str="160MHz"
331 if [ ${ch} -lt "68" ]; then
332 ch="36"
333 elif [ ${ch} -lt "100" ]; then
334 ch="68"
335 elif [ ${ch} -lt "132" ]; then
336 ch="100"
337 elif [ ${ch} -lt "181" ]; then
338 ch="149"
339 fi
340 ;;
341 "2")
342 bw_str="80MHz"
343 if [ ${ch} -lt "52" ]; then
344 ch="36"
345 elif [ ${ch} -lt "68" ]; then
346 ch="52"
347 elif [ ${ch} -lt "84" ]; then
348 ch="68"
349 elif [ ${ch} -lt "100" ]; then
350 ch="84"
351 elif [ ${ch} -lt "116" ]; then
352 ch="100"
353 elif [ ${ch} -lt "132" ]; then
354 ch="116"
355 elif [ ${ch} -lt "149" ]; then
356 ch="132"
357 elif [ ${ch} -lt "165" ]; then
358 ch="149"
359 elif [ ${ch} -lt "181" ]; then
360 ch="165"
361 fi
362 ;;
363 "1")
364 if [ ${ch} -lt "44" ]; then
365 ch=$([ "${ch}" -lt "40" ] && echo "36" || echo "40")
366 bw_str=$([ "${ch}" -le "38" ] && echo "HT40+" || echo "HT40-")
367 elif [ ${ch} -lt "52" ]; then
368 ch=$([ "${ch}" -lt "48" ] && echo "44" || echo "48")
369 bw_str=$([ "${ch}" -le "46" ] && echo "HT40+" || echo "HT40-")
370 elif [ ${ch} -lt "60" ]; then
371 ch=$([ "${ch}" -lt "56" ] && echo "52" || echo "56")
372 bw_str=$([ "${ch}" -le "54" ] && echo "HT40+" || echo "HT40-")
373 elif [ ${ch} -lt "68" ]; then
374 ch=$([ "${ch}" -lt "64" ] && echo "60" || echo "64")
375 bw_str=$([ "${ch}" -le "62" ] && echo "HT40+" || echo "HT40-")
376 elif [ ${ch} -lt "76" ]; then
377 ch=$([ "${ch}" -lt "72" ] && echo "68" || echo "72")
378 bw_str=$([ "${ch}" -le "70" ] && echo "HT40+" || echo "HT40-")
379 elif [ ${ch} -lt "84" ]; then
380 ch=$([ "${ch}" -lt "80" ] && echo "76" || echo "80")
381 bw_str=$([ "${ch}" -le "78" ] && echo "HT40+" || echo "HT40-")
382 elif [ ${ch} -lt "92" ]; then
383 ch=$([ "${ch}" -lt "88" ] && echo "84" || echo "88")
384 bw_str=$([ "${ch}" -le "86" ] && echo "HT40+" || echo "HT40-")
385 elif [ ${ch} -lt "100" ]; then
386 ch=$([ "${ch}" -lt "96" ] && echo "92" || echo "96")
387 bw_str=$([ "${ch}" -le "94" ] && echo "HT40+" || echo "HT40-")
388 elif [ ${ch} -lt "108" ]; then
389 ch=$([ "${ch}" -lt "104" ] && echo "100" || echo "104")
390 bw_str=$([ "${ch}" -le "102" ] && echo "HT40+" || echo "HT40-")
391 elif [ ${ch} -lt "116" ]; then
392 ch=$([ "${ch}" -lt "112" ] && echo "108" || echo "112")
393 bw_str=$([ "${ch}" -le "110" ] && echo "HT40+" || echo "HT40-")
394 elif [ ${ch} -lt "124" ]; then
395 ch=$([ "${ch}" -lt "120" ] && echo "116" || echo "120")
396 bw_str=$([ "${ch}" -le "118" ] && echo "HT40+" || echo "HT40-")
397 elif [ ${ch} -lt "132" ]; then
398 ch=$([ "${ch}" -lt "128" ] && echo "124" || echo "128")
399 bw_str=$([ "${ch}" -le "126" ] && echo "HT40+" || echo "HT40-")
400 elif [ ${ch} -lt "140" ]; then
401 ch=$([ "${ch}" -lt "136" ] && echo "132" || echo "136")
402 bw_str=$([ "${ch}" -le "134" ] && echo "HT40+" || echo "HT40-")
403 elif [ ${ch} -lt "149" ]; then
404 ch=$([ "${ch}" -lt "144" ] && echo "140" || echo "144")
405 bw_str=$([ "${ch}" -le "142" ] && echo "HT40+" || echo "HT40-")
406 elif [ ${ch} -lt "157" ]; then
407 ch=$([ "${ch}" -lt "153" ] && echo "149" || echo "153")
408 bw_str=$([ "${ch}" -le "151" ] && echo "HT40+" || echo "HT40-")
409 elif [ ${ch} -lt "165" ]; then
410 ch=$([ "${ch}" -lt "161" ] && echo "157" || echo "161")
411 bw_str=$([ "${ch}" -le "159" ] && echo "HT40+" || echo "HT40-")
412 elif [ ${ch} -lt "173" ]; then
413 ch=$([ "${ch}" -lt "169" ] && echo "165" || echo "169")
414 bw_str=$([ "${ch}" -le "167" ] && echo "HT40+" || echo "HT40-")
415 elif [ ${ch} -lt "181" ]; then
416 ch=$([ "${ch}" -lt "177" ] && echo "173" || echo "177")
417 bw_str=$([ "${ch}" -le "175" ] && echo "HT40+" || echo "HT40-")
418 fi
419 ;;
420 "0")
421 local bw_str="HT20"
422 ;;
423 esac
424 local base_freq=5180
425 local base_chan=36
426 else
427 case ${bw} in
428 "5")
429 bw_str="160MHz"
430 if [ ${ch} -lt "33" ]; then
431 ch="1"
432 elif [ ${ch} -lt "65" ]; then
433 ch="33"
434 elif [ ${ch} -lt "97" ]; then
435 ch="65"
436 elif [ ${ch} -lt "129" ]; then
437 ch="97"
438 elif [ ${ch} -lt "161" ]; then
439 ch="129"
440 elif [ ${ch} -lt "193" ]; then
441 ch="161"
442 elif [ ${ch} -lt "225" ]; then
443 ch="193"
444 fi
445 ;;
446 "2")
447 bw_str="80MHz"
448 if [ ${ch} -lt "17" ]; then
449 ch="1"
450 elif [ ${ch} -lt "33" ]; then
451 ch="17"
452 elif [ ${ch} -lt "49" ]; then
453 ch="33"
454 elif [ ${ch} -lt "65" ]; then
455 ch="49"
456 elif [ ${ch} -lt "81" ]; then
457 ch="65"
458 elif [ ${ch} -lt "97" ]; then
459 ch="81"
460 elif [ ${ch} -lt "113" ]; then
461 ch="97"
462 elif [ ${ch} -lt "129" ]; then
463 ch="113"
464 elif [ ${ch} -lt "145" ]; then
465 ch="129"
466 elif [ ${ch} -lt "161" ]; then
467 ch="145"
468 elif [ ${ch} -lt "177" ]; then
469 ch="161"
470 elif [ ${ch} -lt "193" ]; then
471 ch="177"
472 elif [ ${ch} -lt "209" ]; then
473 ch="193"
474 elif [ ${ch} -lt "225" ]; then
475 ch="209"
476 fi
477 ;;
478 "1")
479 if [ ${ch} -lt "9" ]; then
480 ch=$([ "${ch}" -lt "5" ] && echo "1" || echo "5")
481 bw_str=$([ "${ch}" -le "3" ] && echo "HT40+" || echo "HT40-")
482 elif [ ${ch} -lt "17" ]; then
483 ch=$([ "${ch}" -lt "13" ] && echo "9" || echo "13")
484 bw_str=$([ "${ch}" -le "11" ] && echo "HT40+" || echo "HT40-")
485 elif [ ${ch} -lt "25" ]; then
486 ch=$([ "${ch}" -lt "21" ] && echo "17" || echo "21")
487 bw_str=$([ "${ch}" -le "19" ] && echo "HT40+" || echo "HT40-")
488 elif [ ${ch} -lt "33" ]; then
489 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
490 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
491 elif [ ${ch} -lt "33" ]; then
492 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
493 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
494 elif [ ${ch} -lt "41" ]; then
495 ch=$([ "${ch}" -lt "37" ] && echo "33" || echo "37")
496 bw_str=$([ "${ch}" -le "35" ] && echo "HT40+" || echo "HT40-")
497 elif [ ${ch} -lt "49" ]; then
498 ch=$([ "${ch}" -lt "45" ] && echo "41" || echo "45")
499 bw_str=$([ "${ch}" -le "43" ] && echo "HT40+" || echo "HT40-")
500 elif [ ${ch} -lt "57" ]; then
501 ch=$([ "${ch}" -lt "53" ] && echo "49" || echo "53")
502 bw_str=$([ "${ch}" -le "51" ] && echo "HT40+" || echo "HT40-")
503 elif [ ${ch} -lt "65" ]; then
504 ch=$([ "${ch}" -lt "61" ] && echo "57" || echo "61")
505 bw_str=$([ "${ch}" -le "59" ] && echo "HT40+" || echo "HT40-")
506 elif [ ${ch} -lt "73" ]; then
507 ch=$([ "${ch}" -lt "69" ] && echo "65" || echo "69")
508 bw_str=$([ "${ch}" -le "67" ] && echo "HT40+" || echo "HT40-")
509 elif [ ${ch} -lt "81" ]; then
510 ch=$([ "${ch}" -lt "77" ] && echo "73" || echo "77")
511 bw_str=$([ "${ch}" -le "75" ] && echo "HT40+" || echo "HT40-")
512 elif [ ${ch} -lt "89" ]; then
513 ch=$([ "${ch}" -lt "85" ] && echo "81" || echo "85")
514 bw_str=$([ "${ch}" -le "83" ] && echo "HT40+" || echo "HT40-")
515 elif [ ${ch} -lt "97" ]; then
516 ch=$([ "${ch}" -lt "93" ] && echo "89" || echo "93")
517 bw_str=$([ "${ch}" -le "91" ] && echo "HT40+" || echo "HT40-")
518 elif [ ${ch} -lt "105" ]; then
519 ch=$([ "${ch}" -lt "101" ] && echo "97" || echo "101")
520 bw_str=$([ "${ch}" -le "99" ] && echo "HT40+" || echo "HT40-")
521 elif [ ${ch} -lt "113" ]; then
522 ch=$([ "${ch}" -lt "109" ] && echo "105" || echo "109")
523 bw_str=$([ "${ch}" -le "107" ] && echo "HT40+" || echo "HT40-")
524 elif [ ${ch} -lt "121" ]; then
525 ch=$([ "${ch}" -lt "117" ] && echo "113" || echo "117")
526 bw_str=$([ "${ch}" -le "115" ] && echo "HT40+" || echo "HT40-")
527 elif [ ${ch} -lt "129" ]; then
528 ch=$([ "${ch}" -lt "125" ] && echo "121" || echo "125")
529 bw_str=$([ "${ch}" -le "123" ] && echo "HT40+" || echo "HT40-")
530 elif [ ${ch} -lt "137" ]; then
531 ch=$([ "${ch}" -lt "133" ] && echo "129" || echo "133")
532 bw_str=$([ "${ch}" -le "131" ] && echo "HT40+" || echo "HT40-")
533 elif [ ${ch} -lt "145" ]; then
534 ch=$([ "${ch}" -lt "141" ] && echo "137" || echo "141")
535 bw_str=$([ "${ch}" -le "139" ] && echo "HT40+" || echo "HT40-")
536 elif [ ${ch} -lt "153" ]; then
537 ch=$([ "${ch}" -lt "149" ] && echo "145" || echo "149")
538 bw_str=$([ "${ch}" -le "147" ] && echo "HT40+" || echo "HT40-")
539 elif [ ${ch} -lt "161" ]; then
540 ch=$([ "${ch}" -lt "157" ] && echo "153" || echo "157")
541 bw_str=$([ "${ch}" -le "155" ] && echo "HT40+" || echo "HT40-")
542 elif [ ${ch} -lt "169" ]; then
543 ch=$([ "${ch}" -lt "165" ] && echo "161" || echo "165")
544 bw_str=$([ "${ch}" -le "163" ] && echo "HT40+" || echo "HT40-")
545 elif [ ${ch} -lt "177" ]; then
546 ch=$([ "${ch}" -lt "173" ] && echo "169" || echo "173")
547 bw_str=$([ "${ch}" -le "171" ] && echo "HT40+" || echo "HT40-")
548 elif [ ${ch} -lt "185" ]; then
549 ch=$([ "${ch}" -lt "181" ] && echo "177" || echo "181")
550 bw_str=$([ "${ch}" -le "179" ] && echo "HT40+" || echo "HT40-")
551 elif [ ${ch} -lt "193" ]; then
552 ch=$([ "${ch}" -lt "189" ] && echo "185" || echo "189")
553 bw_str=$([ "${ch}" -le "187" ] && echo "HT40+" || echo "HT40-")
554 elif [ ${ch} -lt "201" ]; then
555 ch=$([ "${ch}" -lt "197" ] && echo "193" || echo "197")
556 bw_str=$([ "${ch}" -le "195" ] && echo "HT40+" || echo "HT40-")
557 elif [ ${ch} -lt "209" ]; then
558 ch=$([ "${ch}" -lt "205" ] && echo "201" || echo "205")
559 bw_str=$([ "${ch}" -le "203" ] && echo "HT40+" || echo "HT40-")
560 elif [ ${ch} -lt "217" ]; then
561 ch=$([ "${ch}" -lt "213" ] && echo "209" || echo "213")
562 bw_str=$([ "${ch}" -le "211" ] && echo "HT40+" || echo "HT40-")
563 elif [ ${ch} -lt "225" ]; then
564 ch=$([ "${ch}" -lt "221" ] && echo "217" || echo "221")
565 bw_str=$([ "${ch}" -le "219" ] && echo "HT40+" || echo "HT40-")
566 elif [ ${ch} -lt "233" ]; then
567 ch=$([ "${ch}" -lt "229" ] && echo "225" || echo "229")
568 bw_str=$([ "${ch}" -le "227" ] && echo "HT40+" || echo "HT40-")
569 fi
570 ;;
571 "0")
572 local bw_str="HT20"
573 ;;
574 esac
575 local base_freq=5955
576 fi
577
578 local control_freq=$(((ch - base_chan) * 5 + base_freq))
579 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
580}
581
582function convert_rxstat {
583 local res=$(do_cmd "mt76-test ${interface} dump stats")
584 local mdrdy=$(echo "${res}" | grep "rx_packets" | cut -d "=" -f 2)
585 local fcs_error=$(echo "${res}" | grep "rx_fcs_error" | cut -d "=" -f 2)
586 local rcpi=$(echo "${res}" | grep "last_rcpi" | cut -d "=" -f 2 | sed 's/,/ /g')
587 local ib_rssi=$(echo "${res}" | grep "last_ib_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
588 local wb_rssi=$(echo "${res}" | grep "last_wb_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
589 local rx_ok=$(expr ${mdrdy} - ${fcs_error})
590
591 write_dmesg "rcpi: ${rcpi}"
592 write_dmesg "fagc rssi ib: ${ib_rssi}"
593 write_dmesg "fagc rssi wb: ${wb_rssi}"
594 write_dmesg "all_mac_rx_mdrdy_cnt: ${mdrdy}"
595 write_dmesg "all_mac_rx_fcs_err_cnt: ${fcs_error}"
596 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
597}
598
599function set_mac_addr {
600 record_config ${cmd} ${param} ${iwpriv_file}
601
602 local addr1=$(get_config "ATEDA" ${iwpriv_file})
603 local addr2=$(get_config "ATESA" ${iwpriv_file})
604 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
605
606 if [ -z "${addr1}" ]; then
607 addr1="00:11:22:33:44:55"
608 fi
609 if [ -z "${addr2}" ]; then
610 addr2="00:11:22:33:44:55"
611 fi
612 if [ -z "${addr3}" ]; then
613 addr3="00:11:22:33:44:55"
614 fi
615
616 do_cmd "mt76-test phy${phy_idx} set mac_addrs=${addr1},${addr2},${addr3}"
617}
618
619function convert_ibf {
620 local cmd=$1
621 local param=$2
622 local new_cmd=""
623 local new_param=$(echo ${param} | sed s/":"/","/g)
624
625 case ${cmd} in
626 "ATETxBfInit")
627 new_cmd="init"
628 new_param=1
629 do_cmd "mt76-test phy${phy_idx} set state=idle"
630 ;;
631 "ATEIBFPhaseComp")
632 new_cmd="phase_comp"
633 new_param="${new_param} aid=1"
634 ;;
635 "ATEEBfProfileConfig")
636 new_cmd="ebf_prof_update"
637 ;;
638 "ATEIBfProfileConfig")
639 new_cmd="ibf_prof_update"
640 ;;
641 "ATEIBfInstCal")
642 new_cmd="phase_cal"
643 ;;
644 "ATEIBfGdCal")
645 new_cmd="phase_cal"
646 new_param="${new_param},00"
647 ;;
648 "TxBfTxApply")
649 new_cmd="apply_tx"
650 ;;
651 "ATETxPacketWithBf")
652 local bf_on=${new_param:0:2}
653 local aid="01"
654 local wlan_idx=${new_param:3:2}
655 local update="00"
656 local tx_len=${new_param:6}
657
658 new_cmd="tx_prep"
659 new_param="${bf_on},${aid},${wlan_idx},${update}"
660 if [ "${tx_len}" = "00" ]; then
661 new_param="${new_param} aid=1 tx_count=10000000 tx_length=1024"
662 else
663 new_param="${new_param} aid=1 tx_count=${tx_len} tx_length=1024"
664 fi
665 do_cmd "mt76-test phy${phy_idx} set state=idle"
666 ;;
667 "TxBfProfileData20MAllWrite")
668 new_cmd="prof_update_all"
669 ;;
670 "ATEIBFPhaseE2pUpdate")
671 new_cmd="e2p_update"
672 ;;
673 *)
674 esac
675
676 do_cmd "mt76-test phy${phy_idx} set txbf_act=${new_cmd} txbf_param=${new_param}"
677
678 if [ "${cmd}" = "ATETxPacketWithBf" ]; then
679 do_cmd "mt76-test phy${phy_idx} set state=tx_frames"
680 fi
681}
682
developerb403ad02022-11-08 10:16:29 +0800683function convert_dfs {
684 local cmd=$1
685 local param=$2
686
687 case ${cmd} in
688 "DfsRxCtrl")
689 local offchan_ch="$(echo $param | cut -d ':' -f1)"
690 local offchan_bw="$(echo $param | cut -d ':' -f2)"
691
692 if [ "$offchan_bw" = "0" ]; then
693 offchan_bw="20"
694 elif [ "$offchan_bw" = "1" ]; then
695 offchan_bw="40"
696 elif [ "$offchan_bw" = "2" ]; then
697 offchan_bw="80"
698 fi
699
700 do_cmd "mt76-test phy${phy_idx} set state=idle"
701 do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
702 ;;
703 "DfsRxHist")
704 local ipi_th="$(echo $param | cut -d ':' -f 1)"
705 local ipi_period="$(echo $param | cut -d ':' -f 2)"
706 local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
707
708 if [ -z $ipi_antenna ]; then
709 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
710 else
711 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
712 fi
713 ;;
714 *)
715 esac
716}
717
developerb9b4cd12022-10-11 13:18:59 +0800718function do_ate_work() {
719 local ate_cmd=$1
720
721 case ${ate_cmd} in
722 "ATESTART")
723 local if_str=$(ifconfig | grep mon${phy_idx})
724
725 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
726 echo "ATE already starts."
727 else
728 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
729 do_cmd "iw dev wlan${phy_idx} del"
730 do_cmd "ifconfig mon${phy_idx} up"
731 do_cmd "iw reg set VV"
732 fi
733 ;;
734 "ATESTOP")
735 local if_str=$(ifconfig | grep mon${phy_idx})
736
737 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
738 echo "ATE does not start."
739 else
740 do_cmd "mt76-test ${interface} set state=off"
741 do_cmd "iw dev mon${phy_idx} del"
742 do_cmd "iw phy ${interface} interface add wlan${phy_idx} type managed"
743 do_cmd "mt76-test ${interface} set aid=0"
744 fi
745
746 if [ ${phy_idx} -lt ${start_idx_7986} ]; then
747 sed -i '/_PCIE=/d' ${iwpriv_file}
748 elif [ ${phy_idx} -ge ${start_idx_7986} ]; then
749 sed -i '/_7986=/d' ${iwpriv_file}
750 fi
751 ;;
752 "TXCOMMIT")
753 do_cmd "mt76-test ${interface} set aid=1"
754 ;;
755 "TXFRAME")
756 do_cmd "mt76-test ${interface} set state=tx_frames"
757 ;;
758 "TXSTOP"|"RXSTOP")
759 do_cmd "mt76-test ${interface} set state=idle"
760 ;;
761 "TXREVERT")
762 do_cmd "mt76-test ${interface} set aid=0"
763 ;;
764 "RXFRAME")
765 do_cmd "mt76-test ${interface} set state=rx_frames"
766 ;;
767 "TXCONT")
768 do_cmd "mt76-test ${interface} set state=tx_cont"
769 ;;
770 "GROUPREK")
771 do_cmd "mt76-test ${interface} set state=group_prek"
772 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
773 ;;
774 "GROUPREKDump")
775 do_cmd "mt76-test ${interface} set state=group_prek_dump"
776 ;;
777 "GROUPREKClean")
778 do_cmd "mt76-test ${interface} set state=group_prek_clean"
779 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
780 ;;
781 "DPD2G")
782 do_cmd "mt76-test ${interface} set state=dpd_2g"
783 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
784 ;;
785 "DPD5G")
786 do_cmd "mt76-test ${interface} set state=dpd_5g"
787 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
788 ;;
789 "DPD6G")
790 do_cmd "mt76-test ${interface} set state=dpd_6g"
791 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
792 ;;
793 "DPDDump")
794 do_cmd "mt76-test ${interface} set state=dpd_dump"
795 ;;
796 "DPDClean")
797 do_cmd "mt76-test ${interface} set state=dpd_clean"
798 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
799 ;;
800 *)
801 print_debug "skip ${ate_cmd}"
802 ;;
803 esac
804}
805
806# main start here
807
808if [[ ${interface} == "ra"* ]]; then
809 convert_interface $interface
810fi
811
812tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
813
814if [ ! -z ${tmp_work_mode} ]; then
815 work_mode=${tmp_work_mode}
816fi
817
818cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
819param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
820
821if [ "${cmd_type}" = "set" ]; then
822 skip=0
823 case ${cmd} in
824 "ATE")
825 do_ate_work ${param}
826
827 skip=1
828 ;;
829 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
830 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
831 cmd_new=$(simple_convert ${cmd})
832 if [ "${param_new}" = "undefined" ]; then
833 echo "unknown cmd: ${cmd}"
834 exit
835 fi
836 param_new=${param}
837 ;;
838 "ATETXANT"|"ATERXANT")
839 cmd_new="tx_antenna"
840 param_new=${param}
841 ;;
842 "ATETXGI")
843 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
844 convert_gi ${tx_mode} ${param}
845 skip=1
846 ;;
847 "ATETXMODE")
848 cmd_new="tx_rate_mode"
849 param_new=$(convert_tx_mode ${param})
850 if [ "${param_new}" = "undefined" ]; then
851 echo "unknown tx mode"
852 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
853 exit
854 else
855 record_config ${cmd} ${param} ${iwpriv_file}
856 fi
857 ;;
858 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3")
859 cmd_new="tx_power"
860 param_new="${param},0,0,0"
861 ;;
862 "ATETXBW")
863 record_config ${cmd} ${param} ${iwpriv_file}
864 skip=1
865 ;;
866 "ATECHANNEL")
867 convert_channel ${param}
868 skip=1
869 ;;
870 "ATERXSTAT")
871 convert_rxstat
872 skip=1
873 ;;
874 "ATECTRLBANDIDX")
875 change_band_idx ${param}
876 skip=1
877 ;;
878 "ATEDA"|"ATESA"|"ATEBSSID")
879 set_mac_addr ${cmd} ${param}
880 skip=1
881 ;;
developerb403ad02022-11-08 10:16:29 +0800882 "DfsRxCtrl"|"DfsRxHist")
883 convert_dfs ${cmd} ${param}
884 skip=1
885 ;;
developerb9b4cd12022-10-11 13:18:59 +0800886 "ATETxBfInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
887 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"|\
888 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate")
889 convert_ibf ${cmd} ${param}
890 skip=1
891 ;;
892 "bufferMode")
893 if [ "${param}" = "2" ]; then
894 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
895 fi
896 skip=1
897 ;;
898 "ResetCounter"|"ATERXSTATRESET")
899 skip=1
900 ;;
901 "WORKMODE")
902 record_config "WORKMODE" ${param} ${iwpriv_file}
903 echo "Entering ${param} mode in iwpriv"
904 skip=1
905 ;;
906 *)
907 print_debug "Unknown command to set: ${cmd}"
908 skip=1
909 esac
910
911 if [ "${skip}" != "1" ]; then
912 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
913 fi
914
915elif [ "${cmd_type}" = "show" ]; then
916 do_cmd "mt76-test ${interface} dump"
917 do_cmd "mt76-test ${interface} dump stats"
918
919elif [ "${cmd_type}" = "e2p" ]; then
920 offset=$(printf "0x%s" ${cmd})
921 val=$(printf "0x%s" ${param})
922
923 # eeprom offset write
924 if [[ ${full_cmd} == *"="* ]]; then
925 tmp=$((${val} & 0xff))
926 tmp=$(printf "0x%x" ${tmp})
927 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
928
929 offset=$((${offset}))
930 offset=$(expr ${offset} + "1")
931 offset=$(printf "0x%x" ${offset})
932 tmp=$(((${val} >> 8) & 0xff))
933 tmp=$(printf "0x%x" ${tmp})
934 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
935 else
936 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
937 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
938
939 tmp=$(printf "0x%s" ${param})
940 tmp=$((${tmp}))
941 param2=$(expr ${tmp} + "1")
942 param2=$(printf "%x" ${param2})
943 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
944 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
945
946 param=$(printf "0x%s" ${param})
947 param=$(printf "%04x" ${param})
948 param=$(echo $param | tr 'a-z' 'A-Z')
949 printf "%s e2p:\n" ${interface_ori}
950 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
951 fi
952
953elif [ "${cmd_type}" = "mac" ]; then
954 regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
955 regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
956 offset=$(printf "0x%s" ${cmd})
957 val=$(printf "0x%s" ${param})
958
959 echo ${offset} > ${regidx}
960 # reg write
961 if [[ ${full_cmd} == *"="* ]]; then
962 echo ${val} > ${regval}
963 fi
964
965 res=$(cat ${regval} | cut -d 'x' -f 2)
966 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
967
968else
969 echo "Unknown command"
970fi