blob: f1162ba9dbf2317ed8478ebb5d564089949f9422 [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
developer78911262022-12-21 20:28:18 +0800129 # AX8400: mt7915 remain phy0
130 # AX7800: mt7916 becomes phy1
131 phy_idx=$((start_idx_7986-1))
developer679a6aa2022-09-07 09:52:41 +0800132 elif [[ $1 == "ra"* ]]; then
133 phy_idx=$((start_idx_7986+1))
134 fi
135 fi
136
137 interface="phy${phy_idx}"
138}
139
140function change_band_idx {
141 local new_idx=$1
142 local new_phy_idx=$phy_idx
143
144 local old_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
145
146
147 if [[ ${interface_ori} == "ra"* ]]; then
148 if [ -z "${old_idx}" ] || [ "${old_idx}" != "${new_idx}" ]; then
149 if [ "${new_idx}" = "0" ]; then
150 # raix0 & rai0 becomes rai0
151 if [[ $interface_ori == "rai"* ]]; then
152 new_phy_idx=0
153 # rax0 & ra0 becomes ra0
154 elif [[ $interface_ori == "ra"* ]]; then
155 new_phy_idx=$start_idx_7986
156 fi
157 elif [ "${new_idx}" = "1" ]; then
158 # raix0 & rai0 becomes raix0
159 if [[ $interface_ori == "rai"* ]]; then
developer1346ce52022-12-15 21:36:14 +0800160 # For AX8400 => don't change phy idx
161 if [ ${start_idx_7986} != "1" ]; then
162 new_phy_idx=1
163 fi
developer679a6aa2022-09-07 09:52:41 +0800164 # rax0 & ra0 becomes rax0
165 elif [[ $interface_ori == "ra"* ]]; then
166 new_phy_idx=$((start_idx_7986+1))
167 fi
168 fi
169 fi
170
171 if [ ${new_phy_idx} != ${phy_idx} ]; then
172 do_ate_work "ATESTOP"
173 phy_idx=$new_phy_idx
174 interface="phy${phy_idx}"
175 do_ate_work "ATESTART"
176 fi
developereebce5c2022-08-26 19:05:56 +0800177 fi
developer679a6aa2022-09-07 09:52:41 +0800178 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
developereebce5c2022-08-26 19:05:56 +0800179}
180
developer3abe1ad2022-01-24 11:13:32 +0800181function simple_convert() {
182 if [ "$1" = "ATETXCNT" ]; then
183 echo "tx_count"
184 elif [ "$1" = "ATETXLEN" ]; then
185 echo "tx_length"
186 elif [ "$1" = "ATETXMCS" ]; then
187 echo "tx_rate_idx"
188 elif [ "$1" = "ATEVHTNSS" ]; then
189 echo "tx_rate_nss"
190 elif [ "$1" = "ATETXLDPC" ]; then
191 echo "tx_rate_ldpc"
192 elif [ "$1" = "ATETXSTBC" ]; then
193 echo "tx_rate_stbc"
194 elif [ "$1" = "ATEPKTTXTIME" ]; then
195 echo "tx_time"
196 elif [ "$1" = "ATEIPG" ]; then
197 echo "tx_ipg"
198 elif [ "$1" = "ATEDUTYCYCLE" ]; then
199 echo "tx_duty_cycle"
200 elif [ "$1" = "ATETXFREQOFFSET" ]; then
201 echo "freq_offset"
202 else
developer679a6aa2022-09-07 09:52:41 +0800203 echo "undefined"
developer3abe1ad2022-01-24 11:13:32 +0800204 fi
205}
206
207function convert_tx_mode() {
developer1346ce52022-12-15 21:36:14 +0800208 # Remove leading zeros
209 local tx_mode=$(echo $1 | sed 's/^0*//')
210
211 if [ "$tx_mode" = "0" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800212 echo "cck"
developer1346ce52022-12-15 21:36:14 +0800213 elif [ "$tx_mode" = "1" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800214 echo "ofdm"
developer1346ce52022-12-15 21:36:14 +0800215 elif [ "$tx_mode" = "2" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800216 echo "ht"
developer1346ce52022-12-15 21:36:14 +0800217 elif [ "$tx_mode" = "4" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800218 echo "vht"
developer1346ce52022-12-15 21:36:14 +0800219 elif [ "$tx_mode" = "8" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800220 echo "he_su"
developer1346ce52022-12-15 21:36:14 +0800221 elif [ "$tx_mode" = "9" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800222 echo "he_er"
developer1346ce52022-12-15 21:36:14 +0800223 elif [ "$tx_mode" = "10" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800224 echo "he_tb"
developer1346ce52022-12-15 21:36:14 +0800225 elif [ "$tx_mode" = "11" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800226 echo "he_mu"
227 else
developer679a6aa2022-09-07 09:52:41 +0800228 echo "undefined"
developer3abe1ad2022-01-24 11:13:32 +0800229 fi
230}
231
232function convert_gi {
233 local tx_mode=$1
234 local val=$2
235 local sgi="0"
236 local he_ltf="0"
237
238 case ${tx_mode} in
239 "ht"|"vht")
240 sgi=${val}
241 ;;
242 "he_su"|"he_er")
243 case ${val} in
244 "0")
245 ;;
246 "1")
247 he_ltf="1"
248 ;;
249 "2")
250 sgi="1"
251 he_ltf="1"
252 ;;
253 "3")
254 sgi="2"
255 he_ltf="2"
256 ;;
257 "4")
258 he_ltf="2"
259 ;;
260 *)
261 echo "unknown gi"
262 esac
263 ;;
264 "he_mu")
265 case ${val} in
266 "0")
267 he_ltf="2"
268 ;;
269 "1")
270 he_ltf="1"
271 ;;
272 "2")
273 sgi="1"
274 he_ltf="1"
275 ;;
276 "3")
277 sgi="2"
278 he_ltf="2"
279 ;;
280 *)
281 echo "unknown gi"
282 esac
283 ;;
284 "he_tb")
285 case ${val} in
286 "0")
287 sgi="1"
288 ;;
289 "1")
290 sgi="1"
291 he_ltf="1"
292 ;;
293 "2")
294 sgi="2"
295 he_ltf="2"
296 ;;
297 *)
298 echo "unknown gi"
299 esac
300 ;;
301 *)
developer9b7cdad2022-03-10 14:24:55 +0800302 print_debug "legacy mode no need gi"
developer3abe1ad2022-01-24 11:13:32 +0800303 esac
304
305 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
306}
307
308function convert_channel {
developer679a6aa2022-09-07 09:52:41 +0800309 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
developer3abe1ad2022-01-24 11:13:32 +0800310 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
developer679a6aa2022-09-07 09:52:41 +0800311 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
developer10946c32022-03-04 18:28:43 +0800312 local bw_str="HT20"
developereebce5c2022-08-26 19:05:56 +0800313 local base_chan=1
314 local control_freq=0
315 local base_freq=0
developer1346ce52022-12-15 21:36:14 +0800316 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
317 local temp=$((phy_idx+1))
developer3abe1ad2022-01-24 11:13:32 +0800318
developer1346ce52022-12-15 21:36:14 +0800319 # Handle ATECTRLBANDIDX
320 if [ ! -z ${ctrl_band_idx} ]; then
321 if [ "${ctrl_band_idx}" == "1" ] && [ ${band} == "0" ]; then
322 local temp=$(cat "/etc/config/wireless"| grep "option band" | sed -n ${temp}p | cut -c 15)
323 if [ "${temp}" == "2" ]; then
324 local band=0
325 elif [ "${temp}" == "5" ]; then
326 local band=1
327 elif [ "${temp}" == "6" ]; then
328 local band=2
329 else
330 echo "iwpriv wrapper band translate error!"
331 fi
332 else
333 # mt7915 in AX8400 case: band should be determined by only the input band
334 if [ "${start_idx_7986}" == "1" ] && [ ${phy_idx} == "0" ]; then
335 local band=$((band))
336 else
337 local band=$((ctrl_band_idx * band))
338 fi
339 fi
developer679a6aa2022-09-07 09:52:41 +0800340 fi
341
developer9b7cdad2022-03-10 14:24:55 +0800342 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800343 case ${bw} in
344 "1")
developer461cb542022-04-29 18:17:44 +0800345 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
346 local bw_str="HT20"
developer3abe1ad2022-01-24 11:13:32 +0800347 else
developer461cb542022-04-29 18:17:44 +0800348 local bw_str="HT40+"
349 ch=$(expr ${ch} - "2")
developer3abe1ad2022-01-24 11:13:32 +0800350 fi
351 ;;
developer3abe1ad2022-01-24 11:13:32 +0800352 esac
developereebce5c2022-08-26 19:05:56 +0800353 local base_freq=2412
developera6267142022-01-26 20:50:22 +0800354 elif [ "${band}" = "1" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800355 case ${bw} in
developera6267142022-01-26 20:50:22 +0800356 "5")
developer10946c32022-03-04 18:28:43 +0800357 bw_str="160MHz"
358 if [ ${ch} -lt "68" ]; then
359 ch="36"
360 elif [ ${ch} -lt "100" ]; then
361 ch="68"
362 elif [ ${ch} -lt "132" ]; then
363 ch="100"
364 elif [ ${ch} -lt "181" ]; then
365 ch="149"
366 fi
developera6267142022-01-26 20:50:22 +0800367 ;;
developer3abe1ad2022-01-24 11:13:32 +0800368 "2")
developer10946c32022-03-04 18:28:43 +0800369 bw_str="80MHz"
370 if [ ${ch} -lt "52" ]; then
371 ch="36"
372 elif [ ${ch} -lt "68" ]; then
373 ch="52"
374 elif [ ${ch} -lt "84" ]; then
375 ch="68"
376 elif [ ${ch} -lt "100" ]; then
377 ch="84"
378 elif [ ${ch} -lt "116" ]; then
379 ch="100"
380 elif [ ${ch} -lt "132" ]; then
381 ch="116"
382 elif [ ${ch} -lt "149" ]; then
383 ch="132"
384 elif [ ${ch} -lt "165" ]; then
385 ch="149"
386 elif [ ${ch} -lt "181" ]; then
387 ch="165"
388 fi
developer3abe1ad2022-01-24 11:13:32 +0800389 ;;
390 "1")
developer10946c32022-03-04 18:28:43 +0800391 if [ ${ch} -lt "44" ]; then
392 ch=$([ "${ch}" -lt "40" ] && echo "36" || echo "40")
393 bw_str=$([ "${ch}" -le "38" ] && echo "HT40+" || echo "HT40-")
394 elif [ ${ch} -lt "52" ]; then
395 ch=$([ "${ch}" -lt "48" ] && echo "44" || echo "48")
396 bw_str=$([ "${ch}" -le "46" ] && echo "HT40+" || echo "HT40-")
397 elif [ ${ch} -lt "60" ]; then
398 ch=$([ "${ch}" -lt "56" ] && echo "52" || echo "56")
399 bw_str=$([ "${ch}" -le "54" ] && echo "HT40+" || echo "HT40-")
400 elif [ ${ch} -lt "68" ]; then
401 ch=$([ "${ch}" -lt "64" ] && echo "60" || echo "64")
402 bw_str=$([ "${ch}" -le "62" ] && echo "HT40+" || echo "HT40-")
403 elif [ ${ch} -lt "76" ]; then
404 ch=$([ "${ch}" -lt "72" ] && echo "68" || echo "72")
405 bw_str=$([ "${ch}" -le "70" ] && echo "HT40+" || echo "HT40-")
406 elif [ ${ch} -lt "84" ]; then
407 ch=$([ "${ch}" -lt "80" ] && echo "76" || echo "80")
408 bw_str=$([ "${ch}" -le "78" ] && echo "HT40+" || echo "HT40-")
409 elif [ ${ch} -lt "92" ]; then
410 ch=$([ "${ch}" -lt "88" ] && echo "84" || echo "88")
411 bw_str=$([ "${ch}" -le "86" ] && echo "HT40+" || echo "HT40-")
412 elif [ ${ch} -lt "100" ]; then
413 ch=$([ "${ch}" -lt "96" ] && echo "92" || echo "96")
414 bw_str=$([ "${ch}" -le "94" ] && echo "HT40+" || echo "HT40-")
415 elif [ ${ch} -lt "108" ]; then
416 ch=$([ "${ch}" -lt "104" ] && echo "100" || echo "104")
417 bw_str=$([ "${ch}" -le "102" ] && echo "HT40+" || echo "HT40-")
418 elif [ ${ch} -lt "116" ]; then
419 ch=$([ "${ch}" -lt "112" ] && echo "108" || echo "112")
420 bw_str=$([ "${ch}" -le "110" ] && echo "HT40+" || echo "HT40-")
421 elif [ ${ch} -lt "124" ]; then
422 ch=$([ "${ch}" -lt "120" ] && echo "116" || echo "120")
423 bw_str=$([ "${ch}" -le "118" ] && echo "HT40+" || echo "HT40-")
424 elif [ ${ch} -lt "132" ]; then
425 ch=$([ "${ch}" -lt "128" ] && echo "124" || echo "128")
426 bw_str=$([ "${ch}" -le "126" ] && echo "HT40+" || echo "HT40-")
427 elif [ ${ch} -lt "140" ]; then
428 ch=$([ "${ch}" -lt "136" ] && echo "132" || echo "136")
429 bw_str=$([ "${ch}" -le "134" ] && echo "HT40+" || echo "HT40-")
430 elif [ ${ch} -lt "149" ]; then
431 ch=$([ "${ch}" -lt "144" ] && echo "140" || echo "144")
432 bw_str=$([ "${ch}" -le "142" ] && echo "HT40+" || echo "HT40-")
433 elif [ ${ch} -lt "157" ]; then
434 ch=$([ "${ch}" -lt "153" ] && echo "149" || echo "153")
435 bw_str=$([ "${ch}" -le "151" ] && echo "HT40+" || echo "HT40-")
436 elif [ ${ch} -lt "165" ]; then
437 ch=$([ "${ch}" -lt "161" ] && echo "157" || echo "161")
438 bw_str=$([ "${ch}" -le "159" ] && echo "HT40+" || echo "HT40-")
439 elif [ ${ch} -lt "173" ]; then
440 ch=$([ "${ch}" -lt "169" ] && echo "165" || echo "169")
441 bw_str=$([ "${ch}" -le "167" ] && echo "HT40+" || echo "HT40-")
442 elif [ ${ch} -lt "181" ]; then
443 ch=$([ "${ch}" -lt "177" ] && echo "173" || echo "177")
444 bw_str=$([ "${ch}" -le "175" ] && echo "HT40+" || echo "HT40-")
developer3abe1ad2022-01-24 11:13:32 +0800445 fi
446 ;;
447 "0")
448 local bw_str="HT20"
449 ;;
450 esac
developereebce5c2022-08-26 19:05:56 +0800451 local base_freq=5180
452 local base_chan=36
developera6267142022-01-26 20:50:22 +0800453 else
developereebce5c2022-08-26 19:05:56 +0800454 case ${bw} in
455 "5")
456 bw_str="160MHz"
457 if [ ${ch} -lt "33" ]; then
458 ch="1"
459 elif [ ${ch} -lt "65" ]; then
460 ch="33"
461 elif [ ${ch} -lt "97" ]; then
462 ch="65"
463 elif [ ${ch} -lt "129" ]; then
464 ch="97"
465 elif [ ${ch} -lt "161" ]; then
466 ch="129"
467 elif [ ${ch} -lt "193" ]; then
468 ch="161"
469 elif [ ${ch} -lt "225" ]; then
470 ch="193"
471 fi
472 ;;
473 "2")
474 bw_str="80MHz"
475 if [ ${ch} -lt "17" ]; then
476 ch="1"
477 elif [ ${ch} -lt "33" ]; then
478 ch="17"
479 elif [ ${ch} -lt "49" ]; then
480 ch="33"
481 elif [ ${ch} -lt "65" ]; then
482 ch="49"
483 elif [ ${ch} -lt "81" ]; then
484 ch="65"
485 elif [ ${ch} -lt "97" ]; then
486 ch="81"
487 elif [ ${ch} -lt "113" ]; then
488 ch="97"
489 elif [ ${ch} -lt "129" ]; then
490 ch="113"
491 elif [ ${ch} -lt "145" ]; then
492 ch="129"
493 elif [ ${ch} -lt "161" ]; then
494 ch="145"
495 elif [ ${ch} -lt "177" ]; then
496 ch="161"
497 elif [ ${ch} -lt "193" ]; then
498 ch="177"
499 elif [ ${ch} -lt "209" ]; then
500 ch="193"
501 elif [ ${ch} -lt "225" ]; then
502 ch="209"
503 fi
504 ;;
505 "1")
506 if [ ${ch} -lt "9" ]; then
507 ch=$([ "${ch}" -lt "5" ] && echo "1" || echo "5")
508 bw_str=$([ "${ch}" -le "3" ] && echo "HT40+" || echo "HT40-")
509 elif [ ${ch} -lt "17" ]; then
510 ch=$([ "${ch}" -lt "13" ] && echo "9" || echo "13")
511 bw_str=$([ "${ch}" -le "11" ] && echo "HT40+" || echo "HT40-")
512 elif [ ${ch} -lt "25" ]; then
513 ch=$([ "${ch}" -lt "21" ] && echo "17" || echo "21")
514 bw_str=$([ "${ch}" -le "19" ] && echo "HT40+" || echo "HT40-")
515 elif [ ${ch} -lt "33" ]; then
516 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
517 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
518 elif [ ${ch} -lt "33" ]; then
519 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
520 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
521 elif [ ${ch} -lt "41" ]; then
522 ch=$([ "${ch}" -lt "37" ] && echo "33" || echo "37")
523 bw_str=$([ "${ch}" -le "35" ] && echo "HT40+" || echo "HT40-")
524 elif [ ${ch} -lt "49" ]; then
525 ch=$([ "${ch}" -lt "45" ] && echo "41" || echo "45")
526 bw_str=$([ "${ch}" -le "43" ] && echo "HT40+" || echo "HT40-")
527 elif [ ${ch} -lt "57" ]; then
528 ch=$([ "${ch}" -lt "53" ] && echo "49" || echo "53")
529 bw_str=$([ "${ch}" -le "51" ] && echo "HT40+" || echo "HT40-")
530 elif [ ${ch} -lt "65" ]; then
531 ch=$([ "${ch}" -lt "61" ] && echo "57" || echo "61")
532 bw_str=$([ "${ch}" -le "59" ] && echo "HT40+" || echo "HT40-")
533 elif [ ${ch} -lt "73" ]; then
534 ch=$([ "${ch}" -lt "69" ] && echo "65" || echo "69")
535 bw_str=$([ "${ch}" -le "67" ] && echo "HT40+" || echo "HT40-")
536 elif [ ${ch} -lt "81" ]; then
537 ch=$([ "${ch}" -lt "77" ] && echo "73" || echo "77")
538 bw_str=$([ "${ch}" -le "75" ] && echo "HT40+" || echo "HT40-")
539 elif [ ${ch} -lt "89" ]; then
540 ch=$([ "${ch}" -lt "85" ] && echo "81" || echo "85")
541 bw_str=$([ "${ch}" -le "83" ] && echo "HT40+" || echo "HT40-")
542 elif [ ${ch} -lt "97" ]; then
543 ch=$([ "${ch}" -lt "93" ] && echo "89" || echo "93")
544 bw_str=$([ "${ch}" -le "91" ] && echo "HT40+" || echo "HT40-")
545 elif [ ${ch} -lt "105" ]; then
546 ch=$([ "${ch}" -lt "101" ] && echo "97" || echo "101")
547 bw_str=$([ "${ch}" -le "99" ] && echo "HT40+" || echo "HT40-")
548 elif [ ${ch} -lt "113" ]; then
549 ch=$([ "${ch}" -lt "109" ] && echo "105" || echo "109")
550 bw_str=$([ "${ch}" -le "107" ] && echo "HT40+" || echo "HT40-")
551 elif [ ${ch} -lt "121" ]; then
552 ch=$([ "${ch}" -lt "117" ] && echo "113" || echo "117")
553 bw_str=$([ "${ch}" -le "115" ] && echo "HT40+" || echo "HT40-")
554 elif [ ${ch} -lt "129" ]; then
555 ch=$([ "${ch}" -lt "125" ] && echo "121" || echo "125")
556 bw_str=$([ "${ch}" -le "123" ] && echo "HT40+" || echo "HT40-")
557 elif [ ${ch} -lt "137" ]; then
558 ch=$([ "${ch}" -lt "133" ] && echo "129" || echo "133")
559 bw_str=$([ "${ch}" -le "131" ] && echo "HT40+" || echo "HT40-")
560 elif [ ${ch} -lt "145" ]; then
561 ch=$([ "${ch}" -lt "141" ] && echo "137" || echo "141")
562 bw_str=$([ "${ch}" -le "139" ] && echo "HT40+" || echo "HT40-")
563 elif [ ${ch} -lt "153" ]; then
564 ch=$([ "${ch}" -lt "149" ] && echo "145" || echo "149")
565 bw_str=$([ "${ch}" -le "147" ] && echo "HT40+" || echo "HT40-")
566 elif [ ${ch} -lt "161" ]; then
567 ch=$([ "${ch}" -lt "157" ] && echo "153" || echo "157")
568 bw_str=$([ "${ch}" -le "155" ] && echo "HT40+" || echo "HT40-")
569 elif [ ${ch} -lt "169" ]; then
570 ch=$([ "${ch}" -lt "165" ] && echo "161" || echo "165")
571 bw_str=$([ "${ch}" -le "163" ] && echo "HT40+" || echo "HT40-")
572 elif [ ${ch} -lt "177" ]; then
573 ch=$([ "${ch}" -lt "173" ] && echo "169" || echo "173")
574 bw_str=$([ "${ch}" -le "171" ] && echo "HT40+" || echo "HT40-")
575 elif [ ${ch} -lt "185" ]; then
576 ch=$([ "${ch}" -lt "181" ] && echo "177" || echo "181")
577 bw_str=$([ "${ch}" -le "179" ] && echo "HT40+" || echo "HT40-")
578 elif [ ${ch} -lt "193" ]; then
579 ch=$([ "${ch}" -lt "189" ] && echo "185" || echo "189")
580 bw_str=$([ "${ch}" -le "187" ] && echo "HT40+" || echo "HT40-")
581 elif [ ${ch} -lt "201" ]; then
582 ch=$([ "${ch}" -lt "197" ] && echo "193" || echo "197")
583 bw_str=$([ "${ch}" -le "195" ] && echo "HT40+" || echo "HT40-")
584 elif [ ${ch} -lt "209" ]; then
585 ch=$([ "${ch}" -lt "205" ] && echo "201" || echo "205")
586 bw_str=$([ "${ch}" -le "203" ] && echo "HT40+" || echo "HT40-")
587 elif [ ${ch} -lt "217" ]; then
588 ch=$([ "${ch}" -lt "213" ] && echo "209" || echo "213")
589 bw_str=$([ "${ch}" -le "211" ] && echo "HT40+" || echo "HT40-")
590 elif [ ${ch} -lt "225" ]; then
591 ch=$([ "${ch}" -lt "221" ] && echo "217" || echo "221")
592 bw_str=$([ "${ch}" -le "219" ] && echo "HT40+" || echo "HT40-")
593 elif [ ${ch} -lt "233" ]; then
594 ch=$([ "${ch}" -lt "229" ] && echo "225" || echo "229")
595 bw_str=$([ "${ch}" -le "227" ] && echo "HT40+" || echo "HT40-")
596 fi
597 ;;
598 "0")
599 local bw_str="HT20"
600 ;;
601 esac
602 local base_freq=5955
developer3abe1ad2022-01-24 11:13:32 +0800603 fi
604
developereebce5c2022-08-26 19:05:56 +0800605 local control_freq=$(((ch - base_chan) * 5 + base_freq))
606 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
developer3abe1ad2022-01-24 11:13:32 +0800607}
608
developer10946c32022-03-04 18:28:43 +0800609function convert_rxstat {
610 local res=$(do_cmd "mt76-test ${interface} dump stats")
611 local mdrdy=$(echo "${res}" | grep "rx_packets" | cut -d "=" -f 2)
612 local fcs_error=$(echo "${res}" | grep "rx_fcs_error" | cut -d "=" -f 2)
613 local rcpi=$(echo "${res}" | grep "last_rcpi" | cut -d "=" -f 2 | sed 's/,/ /g')
614 local ib_rssi=$(echo "${res}" | grep "last_ib_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
615 local wb_rssi=$(echo "${res}" | grep "last_wb_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
616 local rx_ok=$(expr ${mdrdy} - ${fcs_error})
617
developer461cb542022-04-29 18:17:44 +0800618 write_dmesg "rcpi: ${rcpi}"
619 write_dmesg "fagc rssi ib: ${ib_rssi}"
620 write_dmesg "fagc rssi wb: ${wb_rssi}"
621 write_dmesg "all_mac_rx_mdrdy_cnt: ${mdrdy}"
622 write_dmesg "all_mac_rx_fcs_err_cnt: ${fcs_error}"
developer9b7cdad2022-03-10 14:24:55 +0800623 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
developer10946c32022-03-04 18:28:43 +0800624}
625
developer10946c32022-03-04 18:28:43 +0800626function set_mac_addr {
developer679a6aa2022-09-07 09:52:41 +0800627 record_config ${cmd} ${param} ${iwpriv_file}
developer10946c32022-03-04 18:28:43 +0800628
developer679a6aa2022-09-07 09:52:41 +0800629 local addr1=$(get_config "ATEDA" ${iwpriv_file})
630 local addr2=$(get_config "ATESA" ${iwpriv_file})
631 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
developer10946c32022-03-04 18:28:43 +0800632
633 if [ -z "${addr1}" ]; then
634 addr1="00:11:22:33:44:55"
635 fi
636 if [ -z "${addr2}" ]; then
637 addr2="00:11:22:33:44:55"
638 fi
639 if [ -z "${addr3}" ]; then
640 addr3="00:11:22:33:44:55"
641 fi
642
643 do_cmd "mt76-test phy${phy_idx} set mac_addrs=${addr1},${addr2},${addr3}"
644}
645
developerf9843e22022-09-13 10:57:15 +0800646function convert_ibf {
647 local cmd=$1
648 local param=$2
649 local new_cmd=""
650 local new_param=$(echo ${param} | sed s/":"/","/g)
651
652 case ${cmd} in
653 "ATETxBfInit")
654 new_cmd="init"
developer1346ce52022-12-15 21:36:14 +0800655 new_param="1"
656 do_cmd "mt76-test phy${phy_idx} set state=idle"
657 ;;
658 "ATETxBfGdInit")
659 new_cmd="golden_init"
660 new_param="1"
developerf9843e22022-09-13 10:57:15 +0800661 do_cmd "mt76-test phy${phy_idx} set state=idle"
662 ;;
663 "ATEIBFPhaseComp")
664 new_cmd="phase_comp"
developer1346ce52022-12-15 21:36:14 +0800665 new_param="${new_param}"
developerf9843e22022-09-13 10:57:15 +0800666 ;;
667 "ATEEBfProfileConfig")
668 new_cmd="ebf_prof_update"
669 ;;
670 "ATEIBfProfileConfig")
671 new_cmd="ibf_prof_update"
672 ;;
673 "ATEIBfInstCal")
674 new_cmd="phase_cal"
675 ;;
676 "ATEIBfGdCal")
677 new_cmd="phase_cal"
678 new_param="${new_param},00"
679 ;;
680 "TxBfTxApply")
681 new_cmd="apply_tx"
682 ;;
683 "ATETxPacketWithBf")
684 local bf_on=${new_param:0:2}
685 local aid="01"
686 local wlan_idx=${new_param:3:2}
687 local update="00"
688 local tx_len=${new_param:6}
689
690 new_cmd="tx_prep"
691 new_param="${bf_on},${aid},${wlan_idx},${update}"
692 if [ "${tx_len}" = "00" ]; then
693 new_param="${new_param} aid=1 tx_count=10000000 tx_length=1024"
694 else
695 new_param="${new_param} aid=1 tx_count=${tx_len} tx_length=1024"
696 fi
697 do_cmd "mt76-test phy${phy_idx} set state=idle"
698 ;;
699 "TxBfProfileData20MAllWrite")
700 new_cmd="prof_update_all"
701 ;;
702 "ATEIBFPhaseE2pUpdate")
703 new_cmd="e2p_update"
704 ;;
developer1346ce52022-12-15 21:36:14 +0800705 "ATEIBFPhaseVerify")
706 local group=${new_param:0:2}
707 local group_l_m_h=${new_param:3:2}
708 local band_idx=${new_param:6:2}
709 local phase_cal_type=${new_param:9:2}
710 local LNA_gain_level=${new_param:12:2}
711 local read_from_e2p=${new_param:15:2}
712
713 do_cmd "mt76-test phy${phy_idx} set txbf_act=phase_comp txbf_param=1,${band_idx},${group},${read_from_e2p},0"
714 new_cmd="phase_cal"
715 new_param="${group},${group_l_m_h},${band_idx},${phase_cal_type},${LNA_gain_level}"
716 ;;
717 "TxBfProfileTagRead")
718 new_cmd="pfmu_tag_read"
719 ;;
720 "TxBfProfileTagWrite")
721 new_cmd="pfmu_tag_write"
722 ;;
723 "TxBfProfileTagInValid")
724 new_cmd="set_invalid_prof"
725 ;;
726 "StaRecBfRead")
727 new_cmd="sta_rec_read"
728 ;;
729 "TriggerSounding")
730 new_cmd="trigger_sounding"
731 ;;
732 "StopSounding")
733 new_cmd="stop_sounding"
734 new_param="0"
735 ;;
736 "ATEConTxETxBfGdProc")
737 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
738 local tx_rate_idx=${new_param:3:2}
739 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
740 local channel=${new_param:9:3}
741 local channel2=${new_param:13:3}
742 local band=${new_param:17}
743
744 new_cmd="ebf_golden_init"
745 do_ate_work "ATESTART"
746 do_cmd "mt76-test phy${phy_idx} set state=idle"
747 record_config "ATETXBW" ${bw} ${iwpriv_file}
748 convert_channel "${channel}:${band}"
749 if [ "${bw}" = "5" ]; then
750 new_param="1,1"
751 else
752 new_param="1,0"
753 fi
754 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_sgi=0"
755 ;;
756 "ATEConTxETxBfInitProc")
757 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
758 local tx_rate_idx=${new_param:3:2}
759 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
760 local tx_rate_nss=${new_param:9:2}
761 local tx_stream=${new_param:12:2}
762 local tx_power=${new_param:15:2}
763 local channel=${new_param:18:3}
764 local channel2=${new_param:22:3}
765 local band=${new_param:26:1}
766 local tx_length=${new_param:28:5}
767
768 new_cmd="ebf_init"
769 do_ate_work "ATESTART"
770 do_cmd "mt76-test phy${phy_idx} set state=idle"
771 record_config "ATETXBW" ${bw} ${iwpriv_file}
772 convert_channel "${channel}:${band}"
773 new_param="1"
774 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"
775 ;;
developerf9843e22022-09-13 10:57:15 +0800776 *)
777 esac
778
779 do_cmd "mt76-test phy${phy_idx} set txbf_act=${new_cmd} txbf_param=${new_param}"
780
781 if [ "${cmd}" = "ATETxPacketWithBf" ]; then
782 do_cmd "mt76-test phy${phy_idx} set state=tx_frames"
developer1346ce52022-12-15 21:36:14 +0800783 elif [ "${cmd}" = "ATEConTxETxBfInitProc" ]; then
784 do_cmd "mt76-test phy${phy_idx} set aid=1"
785 do_cmd "mt76-test phy${phy_idx} set txbf_act=stop_sounding txbf_param=1"
786 do_cmd "mt76-test phy${phy_idx} set txbf_act=update_ch txbf_param=1"
787 do_cmd "mt76-test phy${phy_idx} set txbf_act=ebf_prof_update txbf_param=0,0,0"
788 do_cmd "mt76-test phy${phy_idx} set txbf_act=apply_tx txbf_param=1,1,0,0,0"
789 do_cmd "mt76-test phy${phy_idx} set txbf_act=pfmu_tag_read txbf_param=0,1"
790 do_cmd "mt76-test phy${phy_idx} set txbf_act=sta_rec_read txbf_param=1"
791 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=0,1,0,1,0,0,0"
792 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=2,1,ff,1,0,0,0"
793 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
794 elif [ "${cmd}" = "ATEConTxETxBfGdProc" ]; then
795 do_cmd "mt76-test phy${phy_idx} set aid=1"
796 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
797 elif [ "${cmd}" = "ATETxBfInit" ]; then
798 do_cmd "mt76-test phy${phy_idx} set aid=1"
799 elif [ "${cmd}" = "ATETxBfGdInit" ]; then
800 do_cmd "mt76-test phy${phy_idx} set aid=1"
developerf9843e22022-09-13 10:57:15 +0800801 fi
802}
803
developer887da632022-10-28 09:35:38 +0800804function convert_dfs {
805 local cmd=$1
806 local param=$2
807
808 case ${cmd} in
809 "DfsRxCtrl")
810 local offchan_ch="$(echo $param | cut -d ':' -f1)"
811 local offchan_bw="$(echo $param | cut -d ':' -f2)"
812
813 if [ "$offchan_bw" = "0" ]; then
814 offchan_bw="20"
815 elif [ "$offchan_bw" = "1" ]; then
816 offchan_bw="40"
817 elif [ "$offchan_bw" = "2" ]; then
818 offchan_bw="80"
819 fi
820
821 do_cmd "mt76-test phy${phy_idx} set state=idle"
822 do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
823 ;;
824 "DfsRxHist")
825 local ipi_th="$(echo $param | cut -d ':' -f 1)"
826 local ipi_period="$(echo $param | cut -d ':' -f 2)"
827 local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
828
829 if [ -z $ipi_antenna ]; then
830 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
831 else
832 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
833 fi
834 ;;
835 *)
836 esac
837}
838
developera6267142022-01-26 20:50:22 +0800839function do_ate_work() {
840 local ate_cmd=$1
841
842 case ${ate_cmd} in
843 "ATESTART")
844 local if_str=$(ifconfig | grep mon${phy_idx})
845
846 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
847 echo "ATE already starts."
848 else
849 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
850 do_cmd "iw dev wlan${phy_idx} del"
851 do_cmd "ifconfig mon${phy_idx} up"
developer9b7cdad2022-03-10 14:24:55 +0800852 do_cmd "iw reg set VV"
developera6267142022-01-26 20:50:22 +0800853 fi
854 ;;
855 "ATESTOP")
856 local if_str=$(ifconfig | grep mon${phy_idx})
857
858 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
859 echo "ATE does not start."
860 else
861 do_cmd "mt76-test ${interface} set state=off"
862 do_cmd "iw dev mon${phy_idx} del"
863 do_cmd "iw phy ${interface} interface add wlan${phy_idx} type managed"
developer461cb542022-04-29 18:17:44 +0800864 do_cmd "mt76-test ${interface} set aid=0"
developera6267142022-01-26 20:50:22 +0800865 fi
developer10946c32022-03-04 18:28:43 +0800866
developer679a6aa2022-09-07 09:52:41 +0800867 if [ ${phy_idx} -lt ${start_idx_7986} ]; then
868 sed -i '/_PCIE=/d' ${iwpriv_file}
869 elif [ ${phy_idx} -ge ${start_idx_7986} ]; then
870 sed -i '/_7986=/d' ${iwpriv_file}
871 fi
developera6267142022-01-26 20:50:22 +0800872 ;;
developer461cb542022-04-29 18:17:44 +0800873 "TXCOMMIT")
874 do_cmd "mt76-test ${interface} set aid=1"
875 ;;
developera6267142022-01-26 20:50:22 +0800876 "TXFRAME")
877 do_cmd "mt76-test ${interface} set state=tx_frames"
878 ;;
developer9b7cdad2022-03-10 14:24:55 +0800879 "TXSTOP"|"RXSTOP")
developera6267142022-01-26 20:50:22 +0800880 do_cmd "mt76-test ${interface} set state=idle"
881 ;;
developer461cb542022-04-29 18:17:44 +0800882 "TXREVERT")
883 do_cmd "mt76-test ${interface} set aid=0"
884 ;;
developera6267142022-01-26 20:50:22 +0800885 "RXFRAME")
886 do_cmd "mt76-test ${interface} set state=rx_frames"
887 ;;
888 "TXCONT")
889 do_cmd "mt76-test ${interface} set state=tx_cont"
890 ;;
developer071927d2022-08-31 20:39:29 +0800891 "GROUPREK")
892 do_cmd "mt76-test ${interface} set state=group_prek"
893 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
894 ;;
895 "GROUPREKDump")
896 do_cmd "mt76-test ${interface} set state=group_prek_dump"
897 ;;
898 "GROUPREKClean")
899 do_cmd "mt76-test ${interface} set state=group_prek_clean"
900 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
901 ;;
902 "DPD2G")
903 do_cmd "mt76-test ${interface} set state=dpd_2g"
904 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
905 ;;
906 "DPD5G")
907 do_cmd "mt76-test ${interface} set state=dpd_5g"
908 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
909 ;;
910 "DPD6G")
911 do_cmd "mt76-test ${interface} set state=dpd_6g"
912 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
913 ;;
914 "DPDDump")
915 do_cmd "mt76-test ${interface} set state=dpd_dump"
916 ;;
917 "DPDClean")
918 do_cmd "mt76-test ${interface} set state=dpd_clean"
919 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
920 ;;
developer9b7cdad2022-03-10 14:24:55 +0800921 *)
developer9b7cdad2022-03-10 14:24:55 +0800922 print_debug "skip ${ate_cmd}"
developera6267142022-01-26 20:50:22 +0800923 ;;
924 esac
925}
926
developer10946c32022-03-04 18:28:43 +0800927# main start here
928
929if [[ ${interface} == "ra"* ]]; then
developereebce5c2022-08-26 19:05:56 +0800930 convert_interface $interface
developer10946c32022-03-04 18:28:43 +0800931fi
932
developer679a6aa2022-09-07 09:52:41 +0800933tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
934
935if [ ! -z ${tmp_work_mode} ]; then
936 work_mode=${tmp_work_mode}
937fi
938
developer10946c32022-03-04 18:28:43 +0800939cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
940param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
941
developer3abe1ad2022-01-24 11:13:32 +0800942if [ "${cmd_type}" = "set" ]; then
943 skip=0
developer3abe1ad2022-01-24 11:13:32 +0800944 case ${cmd} in
945 "ATE")
946 do_ate_work ${param}
947
948 skip=1
949 ;;
950 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
951 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
952 cmd_new=$(simple_convert ${cmd})
developer679a6aa2022-09-07 09:52:41 +0800953 if [ "${param_new}" = "undefined" ]; then
954 echo "unknown cmd: ${cmd}"
955 exit
956 fi
developer3abe1ad2022-01-24 11:13:32 +0800957 param_new=${param}
developer1346ce52022-12-15 21:36:14 +0800958 if [ "${cmd}" = "ATETXCNT" ] && [ "${param}" = "0" ]; then
959 param_new="10000000"
960 fi
developer3abe1ad2022-01-24 11:13:32 +0800961 ;;
962 "ATETXANT"|"ATERXANT")
963 cmd_new="tx_antenna"
964 param_new=${param}
965 ;;
966 "ATETXGI")
developer679a6aa2022-09-07 09:52:41 +0800967 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
developer3abe1ad2022-01-24 11:13:32 +0800968 convert_gi ${tx_mode} ${param}
969 skip=1
970 ;;
971 "ATETXMODE")
972 cmd_new="tx_rate_mode"
973 param_new=$(convert_tx_mode ${param})
developer679a6aa2022-09-07 09:52:41 +0800974 if [ "${param_new}" = "undefined" ]; then
975 echo "unknown tx mode"
976 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
977 exit
978 else
979 record_config ${cmd} ${param} ${iwpriv_file}
980 fi
developer3abe1ad2022-01-24 11:13:32 +0800981 ;;
982 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3")
983 cmd_new="tx_power"
984 param_new="${param},0,0,0"
985 ;;
986 "ATETXBW")
developer679a6aa2022-09-07 09:52:41 +0800987 record_config ${cmd} ${param} ${iwpriv_file}
developer3abe1ad2022-01-24 11:13:32 +0800988 skip=1
989 ;;
990 "ATECHANNEL")
991 convert_channel ${param}
992 skip=1
993 ;;
developer10946c32022-03-04 18:28:43 +0800994 "ATERXSTAT")
995 convert_rxstat
996 skip=1
997 ;;
developer3abe1ad2022-01-24 11:13:32 +0800998 "ATECTRLBANDIDX")
developer10946c32022-03-04 18:28:43 +0800999 change_band_idx ${param}
developer3abe1ad2022-01-24 11:13:32 +08001000 skip=1
1001 ;;
developer10946c32022-03-04 18:28:43 +08001002 "ATEDA"|"ATESA"|"ATEBSSID")
1003 set_mac_addr ${cmd} ${param}
1004 skip=1
1005 ;;
developer887da632022-10-28 09:35:38 +08001006 "DfsRxCtrl"|"DfsRxHist")
1007 convert_dfs ${cmd} ${param}
1008 skip=1
1009 ;;
developer1346ce52022-12-15 21:36:14 +08001010 "ATETxBfInit"|"ATETxBfGdInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
1011 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"| \
1012 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate"|"TriggerSounding"|"StopSounding"| \
1013 "StaRecBfRead"|"TxBfProfileTagInValid"|"TxBfProfileTagWrite"|"TxBfProfileTagRead"| \
1014 "ATEIBFPhaseVerify"|"ATEConTxETxBfGdProc"|"ATEConTxETxBfInitProc")
developerf9843e22022-09-13 10:57:15 +08001015 convert_ibf ${cmd} ${param}
1016 skip=1
1017 ;;
developer3abe1ad2022-01-24 11:13:32 +08001018 "bufferMode")
1019 if [ "${param}" = "2" ]; then
developer461cb542022-04-29 18:17:44 +08001020 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
developer3abe1ad2022-01-24 11:13:32 +08001021 fi
1022 skip=1
1023 ;;
developera6267142022-01-26 20:50:22 +08001024 "ResetCounter"|"ATERXSTATRESET")
1025 skip=1
1026 ;;
developer679a6aa2022-09-07 09:52:41 +08001027 "WORKMODE")
1028 record_config "WORKMODE" ${param} ${iwpriv_file}
1029 echo "Entering ${param} mode in iwpriv"
1030 skip=1
1031 ;;
developer3abe1ad2022-01-24 11:13:32 +08001032 *)
developer9b7cdad2022-03-10 14:24:55 +08001033 print_debug "Unknown command to set: ${cmd}"
developer3abe1ad2022-01-24 11:13:32 +08001034 skip=1
1035 esac
1036
1037 if [ "${skip}" != "1" ]; then
1038 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
1039 fi
developer10946c32022-03-04 18:28:43 +08001040
developer3abe1ad2022-01-24 11:13:32 +08001041elif [ "${cmd_type}" = "show" ]; then
developer1346ce52022-12-15 21:36:14 +08001042 if [ "${cmd}" = "wtbl" ]; then
1043 wlan_idx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wlan_idx
1044 wtbl_info=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wtbl_info
1045
1046 do_cmd "echo ${param} > ${wlan_idx}"
1047 do_cmd "cat ${wtbl_info}"
1048 else
1049 do_cmd "mt76-test ${interface} dump"
1050 do_cmd "mt76-test ${interface} dump stats"
1051 fi
developer10946c32022-03-04 18:28:43 +08001052
developer3abe1ad2022-01-24 11:13:32 +08001053elif [ "${cmd_type}" = "e2p" ]; then
developera6267142022-01-26 20:50:22 +08001054 offset=$(printf "0x%s" ${cmd})
1055 val=$(printf "0x%s" ${param})
1056
1057 # eeprom offset write
1058 if [[ ${full_cmd} == *"="* ]]; then
1059 tmp=$((${val} & 0xff))
1060 tmp=$(printf "0x%x" ${tmp})
developer461cb542022-04-29 18:17:44 +08001061 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developera6267142022-01-26 20:50:22 +08001062
1063 offset=$((${offset}))
1064 offset=$(expr ${offset} + "1")
1065 offset=$(printf "0x%x" ${offset})
1066 tmp=$(((${val} >> 8) & 0xff))
1067 tmp=$(printf "0x%x" ${tmp})
developer461cb542022-04-29 18:17:44 +08001068 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developera6267142022-01-26 20:50:22 +08001069 else
developer461cb542022-04-29 18:17:44 +08001070 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
developera6267142022-01-26 20:50:22 +08001071 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developer3abe1ad2022-01-24 11:13:32 +08001072
developera6267142022-01-26 20:50:22 +08001073 tmp=$(printf "0x%s" ${param})
1074 tmp=$((${tmp}))
1075 param2=$(expr ${tmp} + "1")
1076 param2=$(printf "%x" ${param2})
developer461cb542022-04-29 18:17:44 +08001077 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
developera6267142022-01-26 20:50:22 +08001078 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
1079
1080 param=$(printf "0x%s" ${param})
developer461cb542022-04-29 18:17:44 +08001081 param=$(printf "%04x" ${param})
1082 param=$(echo $param | tr 'a-z' 'A-Z')
developer9b7cdad2022-03-10 14:24:55 +08001083 printf "%s e2p:\n" ${interface_ori}
developer461cb542022-04-29 18:17:44 +08001084 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
developera6267142022-01-26 20:50:22 +08001085 fi
developer10946c32022-03-04 18:28:43 +08001086
developera6267142022-01-26 20:50:22 +08001087elif [ "${cmd_type}" = "mac" ]; then
1088 regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
1089 regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
1090 offset=$(printf "0x%s" ${cmd})
1091 val=$(printf "0x%s" ${param})
1092
1093 echo ${offset} > ${regidx}
1094 # reg write
1095 if [[ ${full_cmd} == *"="* ]]; then
1096 echo ${val} > ${regval}
developera6267142022-01-26 20:50:22 +08001097 fi
developer10946c32022-03-04 18:28:43 +08001098
developer461cb542022-04-29 18:17:44 +08001099 res=$(cat ${regval} | cut -d 'x' -f 2)
1100 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
1101
developer3abe1ad2022-01-24 11:13:32 +08001102else
1103 echo "Unknown command"
1104fi