blob: 910e31475130c5f156cb8f4a1448e95e88079036 [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")
23 eval "$1"
24 echo "$1"
25 ;;
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
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
developereebce5c2022-08-26 19:05:56 +0800172 fi
developer679a6aa2022-09-07 09:52:41 +0800173 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
developereebce5c2022-08-26 19:05:56 +0800174}
175
developer3abe1ad2022-01-24 11:13:32 +0800176function 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
developer679a6aa2022-09-07 09:52:41 +0800198 echo "undefined"
developer3abe1ad2022-01-24 11:13:32 +0800199 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
developer679a6aa2022-09-07 09:52:41 +0800220 echo "undefined"
developer3abe1ad2022-01-24 11:13:32 +0800221 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 *)
developer9b7cdad2022-03-10 14:24:55 +0800294 print_debug "legacy mode no need gi"
developer3abe1ad2022-01-24 11:13:32 +0800295 esac
296
297 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
298}
299
300function convert_channel {
developer679a6aa2022-09-07 09:52:41 +0800301 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
developer3abe1ad2022-01-24 11:13:32 +0800302 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
developer679a6aa2022-09-07 09:52:41 +0800303 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
developer10946c32022-03-04 18:28:43 +0800304 local bw_str="HT20"
developereebce5c2022-08-26 19:05:56 +0800305 local base_chan=1
306 local control_freq=0
307 local base_freq=0
developer3abe1ad2022-01-24 11:13:32 +0800308
developer679a6aa2022-09-07 09:52:41 +0800309 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
developer9b7cdad2022-03-10 14:24:55 +0800315 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800316 case ${bw} in
317 "1")
developer461cb542022-04-29 18:17:44 +0800318 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
319 local bw_str="HT20"
developer3abe1ad2022-01-24 11:13:32 +0800320 else
developer461cb542022-04-29 18:17:44 +0800321 local bw_str="HT40+"
322 ch=$(expr ${ch} - "2")
developer3abe1ad2022-01-24 11:13:32 +0800323 fi
324 ;;
developer3abe1ad2022-01-24 11:13:32 +0800325 esac
developereebce5c2022-08-26 19:05:56 +0800326 local base_freq=2412
developera6267142022-01-26 20:50:22 +0800327 elif [ "${band}" = "1" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800328 case ${bw} in
developera6267142022-01-26 20:50:22 +0800329 "5")
developer10946c32022-03-04 18:28:43 +0800330 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
developera6267142022-01-26 20:50:22 +0800340 ;;
developer3abe1ad2022-01-24 11:13:32 +0800341 "2")
developer10946c32022-03-04 18:28:43 +0800342 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
developer3abe1ad2022-01-24 11:13:32 +0800362 ;;
363 "1")
developer10946c32022-03-04 18:28:43 +0800364 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-")
developer3abe1ad2022-01-24 11:13:32 +0800418 fi
419 ;;
420 "0")
421 local bw_str="HT20"
422 ;;
423 esac
developereebce5c2022-08-26 19:05:56 +0800424 local base_freq=5180
425 local base_chan=36
developera6267142022-01-26 20:50:22 +0800426 else
developereebce5c2022-08-26 19:05:56 +0800427 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
developer3abe1ad2022-01-24 11:13:32 +0800576 fi
577
developereebce5c2022-08-26 19:05:56 +0800578 local control_freq=$(((ch - base_chan) * 5 + base_freq))
579 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
developer3abe1ad2022-01-24 11:13:32 +0800580}
581
developer10946c32022-03-04 18:28:43 +0800582function 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
developer461cb542022-04-29 18:17:44 +0800591 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}"
developer9b7cdad2022-03-10 14:24:55 +0800596 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
developer10946c32022-03-04 18:28:43 +0800597}
598
developer10946c32022-03-04 18:28:43 +0800599function set_mac_addr {
developer679a6aa2022-09-07 09:52:41 +0800600 record_config ${cmd} ${param} ${iwpriv_file}
developer10946c32022-03-04 18:28:43 +0800601
developer679a6aa2022-09-07 09:52:41 +0800602 local addr1=$(get_config "ATEDA" ${iwpriv_file})
603 local addr2=$(get_config "ATESA" ${iwpriv_file})
604 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
developer10946c32022-03-04 18:28:43 +0800605
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
developerf9843e22022-09-13 10:57:15 +0800619function 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
developera6267142022-01-26 20:50:22 +0800683function do_ate_work() {
684 local ate_cmd=$1
685
686 case ${ate_cmd} in
687 "ATESTART")
688 local if_str=$(ifconfig | grep mon${phy_idx})
689
690 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
691 echo "ATE already starts."
692 else
693 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
694 do_cmd "iw dev wlan${phy_idx} del"
695 do_cmd "ifconfig mon${phy_idx} up"
developer9b7cdad2022-03-10 14:24:55 +0800696 do_cmd "iw reg set VV"
developera6267142022-01-26 20:50:22 +0800697 fi
698 ;;
699 "ATESTOP")
700 local if_str=$(ifconfig | grep mon${phy_idx})
701
702 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
703 echo "ATE does not start."
704 else
705 do_cmd "mt76-test ${interface} set state=off"
706 do_cmd "iw dev mon${phy_idx} del"
707 do_cmd "iw phy ${interface} interface add wlan${phy_idx} type managed"
developer461cb542022-04-29 18:17:44 +0800708 do_cmd "mt76-test ${interface} set aid=0"
developera6267142022-01-26 20:50:22 +0800709 fi
developer10946c32022-03-04 18:28:43 +0800710
developer679a6aa2022-09-07 09:52:41 +0800711 if [ ${phy_idx} -lt ${start_idx_7986} ]; then
712 sed -i '/_PCIE=/d' ${iwpriv_file}
713 elif [ ${phy_idx} -ge ${start_idx_7986} ]; then
714 sed -i '/_7986=/d' ${iwpriv_file}
715 fi
developera6267142022-01-26 20:50:22 +0800716 ;;
developer461cb542022-04-29 18:17:44 +0800717 "TXCOMMIT")
718 do_cmd "mt76-test ${interface} set aid=1"
719 ;;
developera6267142022-01-26 20:50:22 +0800720 "TXFRAME")
721 do_cmd "mt76-test ${interface} set state=tx_frames"
722 ;;
developer9b7cdad2022-03-10 14:24:55 +0800723 "TXSTOP"|"RXSTOP")
developera6267142022-01-26 20:50:22 +0800724 do_cmd "mt76-test ${interface} set state=idle"
725 ;;
developer461cb542022-04-29 18:17:44 +0800726 "TXREVERT")
727 do_cmd "mt76-test ${interface} set aid=0"
728 ;;
developera6267142022-01-26 20:50:22 +0800729 "RXFRAME")
730 do_cmd "mt76-test ${interface} set state=rx_frames"
731 ;;
732 "TXCONT")
733 do_cmd "mt76-test ${interface} set state=tx_cont"
734 ;;
developer071927d2022-08-31 20:39:29 +0800735 "GROUPREK")
736 do_cmd "mt76-test ${interface} set state=group_prek"
737 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
738 ;;
739 "GROUPREKDump")
740 do_cmd "mt76-test ${interface} set state=group_prek_dump"
741 ;;
742 "GROUPREKClean")
743 do_cmd "mt76-test ${interface} set state=group_prek_clean"
744 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
745 ;;
746 "DPD2G")
747 do_cmd "mt76-test ${interface} set state=dpd_2g"
748 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
749 ;;
750 "DPD5G")
751 do_cmd "mt76-test ${interface} set state=dpd_5g"
752 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
753 ;;
754 "DPD6G")
755 do_cmd "mt76-test ${interface} set state=dpd_6g"
756 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
757 ;;
758 "DPDDump")
759 do_cmd "mt76-test ${interface} set state=dpd_dump"
760 ;;
761 "DPDClean")
762 do_cmd "mt76-test ${interface} set state=dpd_clean"
763 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
764 ;;
developer9b7cdad2022-03-10 14:24:55 +0800765 *)
developer9b7cdad2022-03-10 14:24:55 +0800766 print_debug "skip ${ate_cmd}"
developera6267142022-01-26 20:50:22 +0800767 ;;
768 esac
769}
770
developer10946c32022-03-04 18:28:43 +0800771# main start here
772
773if [[ ${interface} == "ra"* ]]; then
developereebce5c2022-08-26 19:05:56 +0800774 convert_interface $interface
developer10946c32022-03-04 18:28:43 +0800775fi
776
developer679a6aa2022-09-07 09:52:41 +0800777tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
778
779if [ ! -z ${tmp_work_mode} ]; then
780 work_mode=${tmp_work_mode}
781fi
782
developer10946c32022-03-04 18:28:43 +0800783cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
784param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
785
developer3abe1ad2022-01-24 11:13:32 +0800786if [ "${cmd_type}" = "set" ]; then
787 skip=0
developer3abe1ad2022-01-24 11:13:32 +0800788 case ${cmd} in
789 "ATE")
790 do_ate_work ${param}
791
792 skip=1
793 ;;
794 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
795 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
796 cmd_new=$(simple_convert ${cmd})
developer679a6aa2022-09-07 09:52:41 +0800797 if [ "${param_new}" = "undefined" ]; then
798 echo "unknown cmd: ${cmd}"
799 exit
800 fi
developer3abe1ad2022-01-24 11:13:32 +0800801 param_new=${param}
802 ;;
803 "ATETXANT"|"ATERXANT")
804 cmd_new="tx_antenna"
805 param_new=${param}
806 ;;
807 "ATETXGI")
developer679a6aa2022-09-07 09:52:41 +0800808 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
developer3abe1ad2022-01-24 11:13:32 +0800809 convert_gi ${tx_mode} ${param}
810 skip=1
811 ;;
812 "ATETXMODE")
813 cmd_new="tx_rate_mode"
814 param_new=$(convert_tx_mode ${param})
developer679a6aa2022-09-07 09:52:41 +0800815 if [ "${param_new}" = "undefined" ]; then
816 echo "unknown tx mode"
817 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
818 exit
819 else
820 record_config ${cmd} ${param} ${iwpriv_file}
821 fi
developer3abe1ad2022-01-24 11:13:32 +0800822 ;;
823 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3")
824 cmd_new="tx_power"
825 param_new="${param},0,0,0"
826 ;;
827 "ATETXBW")
developer679a6aa2022-09-07 09:52:41 +0800828 record_config ${cmd} ${param} ${iwpriv_file}
developer3abe1ad2022-01-24 11:13:32 +0800829 skip=1
830 ;;
831 "ATECHANNEL")
832 convert_channel ${param}
833 skip=1
834 ;;
developer10946c32022-03-04 18:28:43 +0800835 "ATERXSTAT")
836 convert_rxstat
837 skip=1
838 ;;
developer3abe1ad2022-01-24 11:13:32 +0800839 "ATECTRLBANDIDX")
developer10946c32022-03-04 18:28:43 +0800840 change_band_idx ${param}
developer3abe1ad2022-01-24 11:13:32 +0800841 skip=1
842 ;;
developer10946c32022-03-04 18:28:43 +0800843 "ATEDA"|"ATESA"|"ATEBSSID")
844 set_mac_addr ${cmd} ${param}
845 skip=1
846 ;;
developerf9843e22022-09-13 10:57:15 +0800847 "ATETxBfInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
848 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"|\
849 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate")
850 convert_ibf ${cmd} ${param}
851 skip=1
852 ;;
developer3abe1ad2022-01-24 11:13:32 +0800853 "bufferMode")
854 if [ "${param}" = "2" ]; then
developer461cb542022-04-29 18:17:44 +0800855 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
developer3abe1ad2022-01-24 11:13:32 +0800856 fi
857 skip=1
858 ;;
developera6267142022-01-26 20:50:22 +0800859 "ResetCounter"|"ATERXSTATRESET")
860 skip=1
861 ;;
developer679a6aa2022-09-07 09:52:41 +0800862 "WORKMODE")
863 record_config "WORKMODE" ${param} ${iwpriv_file}
864 echo "Entering ${param} mode in iwpriv"
865 skip=1
866 ;;
developer3abe1ad2022-01-24 11:13:32 +0800867 *)
developer9b7cdad2022-03-10 14:24:55 +0800868 print_debug "Unknown command to set: ${cmd}"
developer3abe1ad2022-01-24 11:13:32 +0800869 skip=1
870 esac
871
872 if [ "${skip}" != "1" ]; then
873 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
874 fi
developer10946c32022-03-04 18:28:43 +0800875
developer3abe1ad2022-01-24 11:13:32 +0800876elif [ "${cmd_type}" = "show" ]; then
877 do_cmd "mt76-test ${interface} dump"
878 do_cmd "mt76-test ${interface} dump stats"
developer10946c32022-03-04 18:28:43 +0800879
developer3abe1ad2022-01-24 11:13:32 +0800880elif [ "${cmd_type}" = "e2p" ]; then
developera6267142022-01-26 20:50:22 +0800881 offset=$(printf "0x%s" ${cmd})
882 val=$(printf "0x%s" ${param})
883
884 # eeprom offset write
885 if [[ ${full_cmd} == *"="* ]]; then
886 tmp=$((${val} & 0xff))
887 tmp=$(printf "0x%x" ${tmp})
developer461cb542022-04-29 18:17:44 +0800888 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developera6267142022-01-26 20:50:22 +0800889
890 offset=$((${offset}))
891 offset=$(expr ${offset} + "1")
892 offset=$(printf "0x%x" ${offset})
893 tmp=$(((${val} >> 8) & 0xff))
894 tmp=$(printf "0x%x" ${tmp})
developer461cb542022-04-29 18:17:44 +0800895 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developera6267142022-01-26 20:50:22 +0800896 else
developer461cb542022-04-29 18:17:44 +0800897 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
developera6267142022-01-26 20:50:22 +0800898 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developer3abe1ad2022-01-24 11:13:32 +0800899
developera6267142022-01-26 20:50:22 +0800900 tmp=$(printf "0x%s" ${param})
901 tmp=$((${tmp}))
902 param2=$(expr ${tmp} + "1")
903 param2=$(printf "%x" ${param2})
developer461cb542022-04-29 18:17:44 +0800904 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
developera6267142022-01-26 20:50:22 +0800905 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
906
907 param=$(printf "0x%s" ${param})
developer461cb542022-04-29 18:17:44 +0800908 param=$(printf "%04x" ${param})
909 param=$(echo $param | tr 'a-z' 'A-Z')
developer9b7cdad2022-03-10 14:24:55 +0800910 printf "%s e2p:\n" ${interface_ori}
developer461cb542022-04-29 18:17:44 +0800911 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
developera6267142022-01-26 20:50:22 +0800912 fi
developer10946c32022-03-04 18:28:43 +0800913
developera6267142022-01-26 20:50:22 +0800914elif [ "${cmd_type}" = "mac" ]; then
915 regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
916 regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
917 offset=$(printf "0x%s" ${cmd})
918 val=$(printf "0x%s" ${param})
919
920 echo ${offset} > ${regidx}
921 # reg write
922 if [[ ${full_cmd} == *"="* ]]; then
923 echo ${val} > ${regval}
developera6267142022-01-26 20:50:22 +0800924 fi
developer10946c32022-03-04 18:28:43 +0800925
developer461cb542022-04-29 18:17:44 +0800926 res=$(cat ${regval} | cut -d 'x' -f 2)
927 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
928
developer3abe1ad2022-01-24 11:13:32 +0800929else
930 echo "Unknown command"
931fi