blob: c2b2b88f69ea25d16a8cfb366c05aad43ccf24e6 [file] [log] [blame]
developerb9b4cd12022-10-11 13:18:59 +08001#!/bin/ash
2
3interface=$1 # phy0/phy1/ra0
developer13655da2023-01-10 19:53:25 +08004cmd_type=$2 # set/show/e2p/mac/dump
developerb9b4cd12022-10-11 13:18:59 +08005full_cmd=$3
6interface_ori=${interface}
developer13655da2023-01-10 19:53:25 +08007SOC_start_idx="0"
developer3f784572023-01-31 15:21:28 +08008SOC_end_idx="0"
developerc8796032023-08-09 10:28:15 +08009is_connac3="0"
developerb9b4cd12022-10-11 13:18:59 +080010
11work_mode="RUN" # RUN/PRINT/DEBUG
12iwpriv_file="/tmp/iwpriv_wrapper"
13interface_file="/tmp/interface"
14phy_idx=$(echo ${interface} | tr -dc '0-9')
15
16function do_cmd() {
17 case ${work_mode} in
18 "RUN")
19 eval "$1"
20 ;;
21 "PRINT")
22 echo "$1"
23 ;;
24 "DEBUG")
developerb9b4cd12022-10-11 13:18:59 +080025 echo "$1"
developerb403ad02022-11-08 10:16:29 +080026 eval "$1"
developerb9b4cd12022-10-11 13:18:59 +080027 ;;
28 esac
29}
30
31function print_debug() {
32 if [ "${work_mode}" = "DEBUG" ]; then
33 echo "$1"
34 fi
35}
36
37function write_dmesg() {
38 echo "$1" > /dev/kmsg
39}
40
41function record_config() {
42 local config=$1
43 local tmp_file=$3
44
developer13655da2023-01-10 19:53:25 +080045 # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
developer3f784572023-01-31 15:21:28 +080046 if [ ${tmp_file} != ${interface_file} ]; then
developer13655da2023-01-10 19:53:25 +080047 if [ $phy_idx -lt $SOC_start_idx ]; then
developerb9b4cd12022-10-11 13:18:59 +080048 config="${config}_PCIE"
developer13655da2023-01-10 19:53:25 +080049 elif [ $phy_idx -ge $SOC_start_idx ]; then
50 config="${config}_SOC"
developerb9b4cd12022-10-11 13:18:59 +080051 fi
52 fi
53
54 if [ -f ${tmp_file} ]; then
55 if grep -q ${config} ${tmp_file}; then
56 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
57 else
58 echo "${config}=$2" >> ${tmp_file}
59 fi
60 else
61 echo "${config}=$2" >> ${tmp_file}
62 fi
63}
64
65function get_config() {
66 local config=$1
67 local tmp_file=$2
68
69 if [ ! -f ${tmp_file} ]; then
70 echo ""
71 return
72 fi
73
developer13655da2023-01-10 19:53:25 +080074 # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
developer3f784572023-01-31 15:21:28 +080075 if [ ${tmp_file} != ${interface_file} ]; then
developer13655da2023-01-10 19:53:25 +080076 if [ $phy_idx -lt $SOC_start_idx ]; then
developerb9b4cd12022-10-11 13:18:59 +080077 config="${config}_PCIE"
developer13655da2023-01-10 19:53:25 +080078 elif [ $phy_idx -ge $SOC_start_idx ]; then
79 config="${config}_SOC"
developerb9b4cd12022-10-11 13:18:59 +080080 fi
81 fi
82
83 if grep -q ${config} ${tmp_file}; then
84 echo "$(cat ${tmp_file} | grep ${config} | sed s/=/' '/g | cut -d " " -f 2)"
85 else
86 echo ""
87 fi
88}
89
developer3f784572023-01-31 15:21:28 +080090function parse_sku {
developer13655da2023-01-10 19:53:25 +080091 SOC_start_idx=$(get_config "STARTIDX" ${interface_file})
developer3f784572023-01-31 15:21:28 +080092 SOC_end_idx=$(get_config "ENDIDX" ${interface_file})
developerc8796032023-08-09 10:28:15 +080093 is_connac3=$(get_config "IS_CONNAC3" ${interface_file})
developerb9b4cd12022-10-11 13:18:59 +080094 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
developerc8796032023-08-09 10:28:15 +080095 if [ -z "${SOC_start_idx}" ] || [ -z "${SOC_end_idx}" ] || [ -z "${is_connac3}" ]; then
developerb9b4cd12022-10-11 13:18:59 +080096 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
developer13655da2023-01-10 19:53:25 +080097 SOC_start_idx="2"
developer3f784572023-01-31 15:21:28 +080098 SOC_end_idx="3"
developerc8796032023-08-09 10:28:15 +080099 is_connac3="0"
developerb9b4cd12022-10-11 13:18:59 +0800100 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
developer13655da2023-01-10 19:53:25 +0800101 SOC_start_idx="1"
developer3f784572023-01-31 15:21:28 +0800102 SOC_end_idx="2"
developerc8796032023-08-09 10:28:15 +0800103 is_connac3="0"
developer70180b02023-11-14 17:01:47 +0800104 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7981")" ]; then
105 SOC_start_idx="0"
106 SOC_end_idx="1"
107 is_connac3="0"
developerb9b4cd12022-10-11 13:18:59 +0800108 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
developer13655da2023-01-10 19:53:25 +0800109 SOC_start_idx="0"
developer3f784572023-01-31 15:21:28 +0800110 SOC_end_idx="1"
developerc8796032023-08-09 10:28:15 +0800111 is_connac3="0"
developer13655da2023-01-10 19:53:25 +0800112 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then
113 SOC_start_idx="0"
developer3f784572023-01-31 15:21:28 +0800114 SOC_end_idx="2"
developerc8796032023-08-09 10:28:15 +0800115 is_connac3="1"
116 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7992")" ]; then
117 SOC_start_idx="0"
118 SOC_end_idx="1"
119 is_connac3="1"
developerb9b4cd12022-10-11 13:18:59 +0800120 else
121 echo "Interface Conversion Failed!"
122 echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
developer70180b02023-11-14 17:01:47 +0800123 echo "For AX3000/AX6000:"
developer3f784572023-01-31 15:21:28 +0800124 echo " echo STARTIDX=0 >> ${interface_file}"
125 echo " echo ENDIDX=1 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800126 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800127 echo "For AX7800:"
128 echo " echo STARTIDX=2 >> ${interface_file}"
129 echo " echo ENDIDX=3 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800130 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800131 echo "For AX8400:"
132 echo " echo STARTIDX=1 >> ${interface_file}"
133 echo " echo ENDIDX=2 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800134 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800135 echo "For Eagle:"
developerc8796032023-08-09 10:28:15 +0800136 echo " echo STARTIDX=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800137 echo " echo ENDIDX=2 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800138 echo " echo IS_CONNAC3=1 >> ${interface_file}"
139 echo "For Kite:"
140 echo " echo STARTIDX=0 >> ${interface_file}"
141 echo " echo ENDIDX=1 >> ${interface_file}"
142 echo " echo IS_CONNAC3=1 >> ${interface_file}"
developerb9b4cd12022-10-11 13:18:59 +0800143 exit 0
144 fi
developer13655da2023-01-10 19:53:25 +0800145 record_config "STARTIDX" ${SOC_start_idx} ${interface_file}
developer3f784572023-01-31 15:21:28 +0800146 record_config "ENDIDX" ${SOC_end_idx} ${interface_file}
developerc8796032023-08-09 10:28:15 +0800147 record_config "IS_CONNAC3" ${is_connac3} ${interface_file}
developerb9b4cd12022-10-11 13:18:59 +0800148 fi
developer3f784572023-01-31 15:21:28 +0800149}
developerb9b4cd12022-10-11 13:18:59 +0800150
developer3f784572023-01-31 15:21:28 +0800151function convert_interface {
developerc8796032023-08-09 10:28:15 +0800152 if [ ${is_connac3} == "0" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800153 if [[ $1 == "raix"* ]]; then
developer13655da2023-01-10 19:53:25 +0800154 phy_idx=1
155 elif [[ $1 == "rai"* ]]; then
developerb9b4cd12022-10-11 13:18:59 +0800156 phy_idx=0
157 elif [[ $1 == "rax"* ]]; then
developer13655da2023-01-10 19:53:25 +0800158 phy_idx=$((SOC_start_idx+1))
159 else
160 phy_idx=$SOC_start_idx
developerb9b4cd12022-10-11 13:18:59 +0800161 fi
developer13655da2023-01-10 19:53:25 +0800162
163 # convert phy index according to band idx
164 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
165 if [ "${band_idx}" = "0" ]; then
166 if [[ $1 == "raix"* ]]; then
167 phy_idx=0
168 elif [[ $1 == "rax"* ]]; then
169 phy_idx=$SOC_start_idx
170 fi
171 elif [ "${band_idx}" = "1" ]; then
172 if [[ $1 == "rai"* ]]; then
173 # AX8400: mt7915 remain phy0
174 # AX7800: mt7916 becomes phy1
175 phy_idx=$((SOC_start_idx-1))
176 elif [[ $1 == "ra"* ]]; then
177 phy_idx=$((SOC_start_idx+1))
178 fi
179 fi
180 else
181 # Eagle has different mapping method
182 # phy0: ra0
183 # phy1: rai0
184 # phy2: rax0
developerb9b4cd12022-10-11 13:18:59 +0800185 if [[ $1 == "rai"* ]]; then
developer13655da2023-01-10 19:53:25 +0800186 phy_idx=1
187 elif [[ $1 == "rax"* ]]; then
188 phy_idx=2
189 else
190 phy_idx=0
developerb9b4cd12022-10-11 13:18:59 +0800191 fi
192 fi
193
194 interface="phy${phy_idx}"
195}
196
197function change_band_idx {
198 local new_idx=$1
199 local new_phy_idx=$phy_idx
200
201 local old_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
202
203
204 if [[ ${interface_ori} == "ra"* ]]; then
205 if [ -z "${old_idx}" ] || [ "${old_idx}" != "${new_idx}" ]; then
206 if [ "${new_idx}" = "0" ]; then
207 # raix0 & rai0 becomes rai0
208 if [[ $interface_ori == "rai"* ]]; then
209 new_phy_idx=0
210 # rax0 & ra0 becomes ra0
211 elif [[ $interface_ori == "ra"* ]]; then
developer13655da2023-01-10 19:53:25 +0800212 new_phy_idx=$SOC_start_idx
developerb9b4cd12022-10-11 13:18:59 +0800213 fi
214 elif [ "${new_idx}" = "1" ]; then
215 # raix0 & rai0 becomes raix0
216 if [[ $interface_ori == "rai"* ]]; then
developerc5ce7502022-12-19 11:33:22 +0800217 # For AX8400 => don't change phy idx
developer13655da2023-01-10 19:53:25 +0800218 if [ ${SOC_start_idx} != "1" ]; then
developerc5ce7502022-12-19 11:33:22 +0800219 new_phy_idx=1
220 fi
developerb9b4cd12022-10-11 13:18:59 +0800221 # rax0 & ra0 becomes rax0
222 elif [[ $interface_ori == "ra"* ]]; then
developer13655da2023-01-10 19:53:25 +0800223 new_phy_idx=$((SOC_start_idx+1))
developerb9b4cd12022-10-11 13:18:59 +0800224 fi
225 fi
226 fi
227
228 if [ ${new_phy_idx} != ${phy_idx} ]; then
229 do_ate_work "ATESTOP"
230 phy_idx=$new_phy_idx
231 interface="phy${phy_idx}"
232 do_ate_work "ATESTART"
233 fi
234 fi
235 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
236}
237
238function simple_convert() {
239 if [ "$1" = "ATETXCNT" ]; then
240 echo "tx_count"
241 elif [ "$1" = "ATETXLEN" ]; then
242 echo "tx_length"
243 elif [ "$1" = "ATETXMCS" ]; then
244 echo "tx_rate_idx"
245 elif [ "$1" = "ATEVHTNSS" ]; then
246 echo "tx_rate_nss"
247 elif [ "$1" = "ATETXLDPC" ]; then
248 echo "tx_rate_ldpc"
249 elif [ "$1" = "ATETXSTBC" ]; then
250 echo "tx_rate_stbc"
251 elif [ "$1" = "ATEPKTTXTIME" ]; then
252 echo "tx_time"
253 elif [ "$1" = "ATEIPG" ]; then
254 echo "tx_ipg"
255 elif [ "$1" = "ATEDUTYCYCLE" ]; then
256 echo "tx_duty_cycle"
257 elif [ "$1" = "ATETXFREQOFFSET" ]; then
258 echo "freq_offset"
259 else
260 echo "undefined"
261 fi
262}
263
264function convert_tx_mode() {
developerc5ce7502022-12-19 11:33:22 +0800265 # Remove leading zeros
developer3f784572023-01-31 15:21:28 +0800266 local tx_mode=$(echo $1 | sed -r 's/0+([0-9]+)/\1/g')
developerc5ce7502022-12-19 11:33:22 +0800267
268 if [ "$tx_mode" = "0" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800269 echo "cck"
developerc5ce7502022-12-19 11:33:22 +0800270 elif [ "$tx_mode" = "1" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800271 echo "ofdm"
developerc5ce7502022-12-19 11:33:22 +0800272 elif [ "$tx_mode" = "2" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800273 echo "ht"
developerc5ce7502022-12-19 11:33:22 +0800274 elif [ "$tx_mode" = "4" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800275 echo "vht"
developerc5ce7502022-12-19 11:33:22 +0800276 elif [ "$tx_mode" = "8" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800277 echo "he_su"
developerc5ce7502022-12-19 11:33:22 +0800278 elif [ "$tx_mode" = "9" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800279 echo "he_er"
developerc5ce7502022-12-19 11:33:22 +0800280 elif [ "$tx_mode" = "10" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800281 echo "he_tb"
developerc5ce7502022-12-19 11:33:22 +0800282 elif [ "$tx_mode" = "11" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800283 echo "he_mu"
developerbb6ddff2023-03-08 17:22:32 +0800284 elif [ "$tx_mode" = "13" ]; then
285 echo "eht_su"
286 elif [ "$tx_mode" = "14" ]; then
287 echo "eht_tb"
288 elif [ "$tx_mode" = "15" ]; then
289 echo "eht_mu"
developerb9b4cd12022-10-11 13:18:59 +0800290 else
291 echo "undefined"
292 fi
293}
294
295function convert_gi {
296 local tx_mode=$1
297 local val=$2
298 local sgi="0"
299 local he_ltf="0"
300
301 case ${tx_mode} in
302 "ht"|"vht")
303 sgi=${val}
304 ;;
305 "he_su"|"he_er")
306 case ${val} in
307 "0")
308 ;;
309 "1")
310 he_ltf="1"
311 ;;
312 "2")
313 sgi="1"
314 he_ltf="1"
315 ;;
316 "3")
317 sgi="2"
318 he_ltf="2"
319 ;;
320 "4")
321 he_ltf="2"
322 ;;
323 *)
324 echo "unknown gi"
325 esac
326 ;;
327 "he_mu")
328 case ${val} in
329 "0")
330 he_ltf="2"
331 ;;
332 "1")
333 he_ltf="1"
334 ;;
335 "2")
336 sgi="1"
337 he_ltf="1"
338 ;;
339 "3")
340 sgi="2"
341 he_ltf="2"
342 ;;
343 *)
344 echo "unknown gi"
345 esac
346 ;;
347 "he_tb")
348 case ${val} in
349 "0")
350 sgi="1"
351 ;;
352 "1")
353 sgi="1"
354 he_ltf="1"
355 ;;
356 "2")
357 sgi="2"
358 he_ltf="2"
359 ;;
360 *)
361 echo "unknown gi"
362 esac
363 ;;
364 *)
365 print_debug "legacy mode no need gi"
366 esac
367
368 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
369}
370
371function convert_channel {
372 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
373 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
374 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
375 local bw_str="HT20"
376 local base_chan=1
377 local control_freq=0
378 local base_freq=0
developerc5ce7502022-12-19 11:33:22 +0800379 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
380 local temp=$((phy_idx+1))
developerb9b4cd12022-10-11 13:18:59 +0800381
developerc5ce7502022-12-19 11:33:22 +0800382 # Handle ATECTRLBANDIDX
383 if [ ! -z ${ctrl_band_idx} ]; then
384 if [ "${ctrl_band_idx}" == "1" ] && [ ${band} == "0" ]; then
385 local temp=$(cat "/etc/config/wireless"| grep "option band" | sed -n ${temp}p | cut -c 15)
386 if [ "${temp}" == "2" ]; then
387 local band=0
388 elif [ "${temp}" == "5" ]; then
389 local band=1
390 elif [ "${temp}" == "6" ]; then
391 local band=2
392 else
393 echo "iwpriv wrapper band translate error!"
394 fi
395 else
396 # mt7915 in AX8400 case: band should be determined by only the input band
developer13655da2023-01-10 19:53:25 +0800397 if [ "${SOC_start_idx}" == "1" ] && [ ${phy_idx} == "0" ]; then
developerc5ce7502022-12-19 11:33:22 +0800398 local band=$((band))
399 else
400 local band=$((ctrl_band_idx * band))
401 fi
402 fi
developerb9b4cd12022-10-11 13:18:59 +0800403 fi
404
405 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
406 case ${bw} in
407 "1")
408 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
409 local bw_str="HT20"
410 else
411 local bw_str="HT40+"
412 ch=$(expr ${ch} - "2")
413 fi
414 ;;
415 esac
416 local base_freq=2412
417 elif [ "${band}" = "1" ]; then
418 case ${bw} in
419 "5")
420 bw_str="160MHz"
421 if [ ${ch} -lt "68" ]; then
422 ch="36"
423 elif [ ${ch} -lt "100" ]; then
424 ch="68"
425 elif [ ${ch} -lt "132" ]; then
426 ch="100"
427 elif [ ${ch} -lt "181" ]; then
428 ch="149"
429 fi
430 ;;
431 "2")
432 bw_str="80MHz"
433 if [ ${ch} -lt "52" ]; then
434 ch="36"
435 elif [ ${ch} -lt "68" ]; then
436 ch="52"
437 elif [ ${ch} -lt "84" ]; then
438 ch="68"
439 elif [ ${ch} -lt "100" ]; then
440 ch="84"
441 elif [ ${ch} -lt "116" ]; then
442 ch="100"
443 elif [ ${ch} -lt "132" ]; then
444 ch="116"
445 elif [ ${ch} -lt "149" ]; then
446 ch="132"
447 elif [ ${ch} -lt "165" ]; then
448 ch="149"
449 elif [ ${ch} -lt "181" ]; then
450 ch="165"
451 fi
452 ;;
453 "1")
454 if [ ${ch} -lt "44" ]; then
455 ch=$([ "${ch}" -lt "40" ] && echo "36" || echo "40")
456 bw_str=$([ "${ch}" -le "38" ] && echo "HT40+" || echo "HT40-")
457 elif [ ${ch} -lt "52" ]; then
458 ch=$([ "${ch}" -lt "48" ] && echo "44" || echo "48")
459 bw_str=$([ "${ch}" -le "46" ] && echo "HT40+" || echo "HT40-")
460 elif [ ${ch} -lt "60" ]; then
461 ch=$([ "${ch}" -lt "56" ] && echo "52" || echo "56")
462 bw_str=$([ "${ch}" -le "54" ] && echo "HT40+" || echo "HT40-")
463 elif [ ${ch} -lt "68" ]; then
464 ch=$([ "${ch}" -lt "64" ] && echo "60" || echo "64")
465 bw_str=$([ "${ch}" -le "62" ] && echo "HT40+" || echo "HT40-")
466 elif [ ${ch} -lt "76" ]; then
467 ch=$([ "${ch}" -lt "72" ] && echo "68" || echo "72")
468 bw_str=$([ "${ch}" -le "70" ] && echo "HT40+" || echo "HT40-")
469 elif [ ${ch} -lt "84" ]; then
470 ch=$([ "${ch}" -lt "80" ] && echo "76" || echo "80")
471 bw_str=$([ "${ch}" -le "78" ] && echo "HT40+" || echo "HT40-")
472 elif [ ${ch} -lt "92" ]; then
473 ch=$([ "${ch}" -lt "88" ] && echo "84" || echo "88")
474 bw_str=$([ "${ch}" -le "86" ] && echo "HT40+" || echo "HT40-")
475 elif [ ${ch} -lt "100" ]; then
476 ch=$([ "${ch}" -lt "96" ] && echo "92" || echo "96")
477 bw_str=$([ "${ch}" -le "94" ] && echo "HT40+" || echo "HT40-")
478 elif [ ${ch} -lt "108" ]; then
479 ch=$([ "${ch}" -lt "104" ] && echo "100" || echo "104")
480 bw_str=$([ "${ch}" -le "102" ] && echo "HT40+" || echo "HT40-")
481 elif [ ${ch} -lt "116" ]; then
482 ch=$([ "${ch}" -lt "112" ] && echo "108" || echo "112")
483 bw_str=$([ "${ch}" -le "110" ] && echo "HT40+" || echo "HT40-")
484 elif [ ${ch} -lt "124" ]; then
485 ch=$([ "${ch}" -lt "120" ] && echo "116" || echo "120")
486 bw_str=$([ "${ch}" -le "118" ] && echo "HT40+" || echo "HT40-")
487 elif [ ${ch} -lt "132" ]; then
488 ch=$([ "${ch}" -lt "128" ] && echo "124" || echo "128")
489 bw_str=$([ "${ch}" -le "126" ] && echo "HT40+" || echo "HT40-")
490 elif [ ${ch} -lt "140" ]; then
491 ch=$([ "${ch}" -lt "136" ] && echo "132" || echo "136")
492 bw_str=$([ "${ch}" -le "134" ] && echo "HT40+" || echo "HT40-")
493 elif [ ${ch} -lt "149" ]; then
494 ch=$([ "${ch}" -lt "144" ] && echo "140" || echo "144")
495 bw_str=$([ "${ch}" -le "142" ] && echo "HT40+" || echo "HT40-")
496 elif [ ${ch} -lt "157" ]; then
497 ch=$([ "${ch}" -lt "153" ] && echo "149" || echo "153")
498 bw_str=$([ "${ch}" -le "151" ] && echo "HT40+" || echo "HT40-")
499 elif [ ${ch} -lt "165" ]; then
500 ch=$([ "${ch}" -lt "161" ] && echo "157" || echo "161")
501 bw_str=$([ "${ch}" -le "159" ] && echo "HT40+" || echo "HT40-")
502 elif [ ${ch} -lt "173" ]; then
503 ch=$([ "${ch}" -lt "169" ] && echo "165" || echo "169")
504 bw_str=$([ "${ch}" -le "167" ] && echo "HT40+" || echo "HT40-")
505 elif [ ${ch} -lt "181" ]; then
506 ch=$([ "${ch}" -lt "177" ] && echo "173" || echo "177")
507 bw_str=$([ "${ch}" -le "175" ] && echo "HT40+" || echo "HT40-")
508 fi
509 ;;
510 "0")
511 local bw_str="HT20"
512 ;;
513 esac
514 local base_freq=5180
515 local base_chan=36
516 else
developerbb6ddff2023-03-08 17:22:32 +0800517 local base_freq=5955
developerb9b4cd12022-10-11 13:18:59 +0800518 case ${bw} in
developerbb6ddff2023-03-08 17:22:32 +0800519 "12")
520 local bw_str="320"
521 if [ ${ch} == "31" ]; then
522 local control_freq="5955"
523 elif [ ${ch} == "63" ]; then
524 local control_freq="6115"
525 elif [ ${ch} == "95" ]; then
526 local control_freq="6275"
527 elif [ ${ch} == "127" ]; then
528 local control_freq="6435"
529 elif [ ${ch} == "159" ]; then
530 local control_freq="6595"
531 elif [ ${ch} == "191" ]; then
532 local control_freq="6755"
533 fi
534 local center_freq=$(((ch - base_chan) * 5 + base_freq))
535 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str} ${center_freq}"
536 return
537 ;;
developerb9b4cd12022-10-11 13:18:59 +0800538 "5")
539 bw_str="160MHz"
540 if [ ${ch} -lt "33" ]; then
541 ch="1"
542 elif [ ${ch} -lt "65" ]; then
543 ch="33"
544 elif [ ${ch} -lt "97" ]; then
545 ch="65"
546 elif [ ${ch} -lt "129" ]; then
547 ch="97"
548 elif [ ${ch} -lt "161" ]; then
549 ch="129"
550 elif [ ${ch} -lt "193" ]; then
551 ch="161"
552 elif [ ${ch} -lt "225" ]; then
553 ch="193"
554 fi
555 ;;
556 "2")
557 bw_str="80MHz"
558 if [ ${ch} -lt "17" ]; then
559 ch="1"
560 elif [ ${ch} -lt "33" ]; then
561 ch="17"
562 elif [ ${ch} -lt "49" ]; then
563 ch="33"
564 elif [ ${ch} -lt "65" ]; then
565 ch="49"
566 elif [ ${ch} -lt "81" ]; then
567 ch="65"
568 elif [ ${ch} -lt "97" ]; then
569 ch="81"
570 elif [ ${ch} -lt "113" ]; then
571 ch="97"
572 elif [ ${ch} -lt "129" ]; then
573 ch="113"
574 elif [ ${ch} -lt "145" ]; then
575 ch="129"
576 elif [ ${ch} -lt "161" ]; then
577 ch="145"
578 elif [ ${ch} -lt "177" ]; then
579 ch="161"
580 elif [ ${ch} -lt "193" ]; then
581 ch="177"
582 elif [ ${ch} -lt "209" ]; then
583 ch="193"
584 elif [ ${ch} -lt "225" ]; then
585 ch="209"
586 fi
587 ;;
588 "1")
589 if [ ${ch} -lt "9" ]; then
590 ch=$([ "${ch}" -lt "5" ] && echo "1" || echo "5")
591 bw_str=$([ "${ch}" -le "3" ] && echo "HT40+" || echo "HT40-")
592 elif [ ${ch} -lt "17" ]; then
593 ch=$([ "${ch}" -lt "13" ] && echo "9" || echo "13")
594 bw_str=$([ "${ch}" -le "11" ] && echo "HT40+" || echo "HT40-")
595 elif [ ${ch} -lt "25" ]; then
596 ch=$([ "${ch}" -lt "21" ] && echo "17" || echo "21")
597 bw_str=$([ "${ch}" -le "19" ] && echo "HT40+" || echo "HT40-")
598 elif [ ${ch} -lt "33" ]; then
599 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
600 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
601 elif [ ${ch} -lt "33" ]; then
602 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
603 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
604 elif [ ${ch} -lt "41" ]; then
605 ch=$([ "${ch}" -lt "37" ] && echo "33" || echo "37")
606 bw_str=$([ "${ch}" -le "35" ] && echo "HT40+" || echo "HT40-")
607 elif [ ${ch} -lt "49" ]; then
608 ch=$([ "${ch}" -lt "45" ] && echo "41" || echo "45")
609 bw_str=$([ "${ch}" -le "43" ] && echo "HT40+" || echo "HT40-")
610 elif [ ${ch} -lt "57" ]; then
611 ch=$([ "${ch}" -lt "53" ] && echo "49" || echo "53")
612 bw_str=$([ "${ch}" -le "51" ] && echo "HT40+" || echo "HT40-")
613 elif [ ${ch} -lt "65" ]; then
614 ch=$([ "${ch}" -lt "61" ] && echo "57" || echo "61")
615 bw_str=$([ "${ch}" -le "59" ] && echo "HT40+" || echo "HT40-")
616 elif [ ${ch} -lt "73" ]; then
617 ch=$([ "${ch}" -lt "69" ] && echo "65" || echo "69")
618 bw_str=$([ "${ch}" -le "67" ] && echo "HT40+" || echo "HT40-")
619 elif [ ${ch} -lt "81" ]; then
620 ch=$([ "${ch}" -lt "77" ] && echo "73" || echo "77")
621 bw_str=$([ "${ch}" -le "75" ] && echo "HT40+" || echo "HT40-")
622 elif [ ${ch} -lt "89" ]; then
623 ch=$([ "${ch}" -lt "85" ] && echo "81" || echo "85")
624 bw_str=$([ "${ch}" -le "83" ] && echo "HT40+" || echo "HT40-")
625 elif [ ${ch} -lt "97" ]; then
626 ch=$([ "${ch}" -lt "93" ] && echo "89" || echo "93")
627 bw_str=$([ "${ch}" -le "91" ] && echo "HT40+" || echo "HT40-")
628 elif [ ${ch} -lt "105" ]; then
629 ch=$([ "${ch}" -lt "101" ] && echo "97" || echo "101")
630 bw_str=$([ "${ch}" -le "99" ] && echo "HT40+" || echo "HT40-")
631 elif [ ${ch} -lt "113" ]; then
632 ch=$([ "${ch}" -lt "109" ] && echo "105" || echo "109")
633 bw_str=$([ "${ch}" -le "107" ] && echo "HT40+" || echo "HT40-")
634 elif [ ${ch} -lt "121" ]; then
635 ch=$([ "${ch}" -lt "117" ] && echo "113" || echo "117")
636 bw_str=$([ "${ch}" -le "115" ] && echo "HT40+" || echo "HT40-")
637 elif [ ${ch} -lt "129" ]; then
638 ch=$([ "${ch}" -lt "125" ] && echo "121" || echo "125")
639 bw_str=$([ "${ch}" -le "123" ] && echo "HT40+" || echo "HT40-")
640 elif [ ${ch} -lt "137" ]; then
641 ch=$([ "${ch}" -lt "133" ] && echo "129" || echo "133")
642 bw_str=$([ "${ch}" -le "131" ] && echo "HT40+" || echo "HT40-")
643 elif [ ${ch} -lt "145" ]; then
644 ch=$([ "${ch}" -lt "141" ] && echo "137" || echo "141")
645 bw_str=$([ "${ch}" -le "139" ] && echo "HT40+" || echo "HT40-")
646 elif [ ${ch} -lt "153" ]; then
647 ch=$([ "${ch}" -lt "149" ] && echo "145" || echo "149")
648 bw_str=$([ "${ch}" -le "147" ] && echo "HT40+" || echo "HT40-")
649 elif [ ${ch} -lt "161" ]; then
650 ch=$([ "${ch}" -lt "157" ] && echo "153" || echo "157")
651 bw_str=$([ "${ch}" -le "155" ] && echo "HT40+" || echo "HT40-")
652 elif [ ${ch} -lt "169" ]; then
653 ch=$([ "${ch}" -lt "165" ] && echo "161" || echo "165")
654 bw_str=$([ "${ch}" -le "163" ] && echo "HT40+" || echo "HT40-")
655 elif [ ${ch} -lt "177" ]; then
656 ch=$([ "${ch}" -lt "173" ] && echo "169" || echo "173")
657 bw_str=$([ "${ch}" -le "171" ] && echo "HT40+" || echo "HT40-")
658 elif [ ${ch} -lt "185" ]; then
659 ch=$([ "${ch}" -lt "181" ] && echo "177" || echo "181")
660 bw_str=$([ "${ch}" -le "179" ] && echo "HT40+" || echo "HT40-")
661 elif [ ${ch} -lt "193" ]; then
662 ch=$([ "${ch}" -lt "189" ] && echo "185" || echo "189")
663 bw_str=$([ "${ch}" -le "187" ] && echo "HT40+" || echo "HT40-")
664 elif [ ${ch} -lt "201" ]; then
665 ch=$([ "${ch}" -lt "197" ] && echo "193" || echo "197")
666 bw_str=$([ "${ch}" -le "195" ] && echo "HT40+" || echo "HT40-")
667 elif [ ${ch} -lt "209" ]; then
668 ch=$([ "${ch}" -lt "205" ] && echo "201" || echo "205")
669 bw_str=$([ "${ch}" -le "203" ] && echo "HT40+" || echo "HT40-")
670 elif [ ${ch} -lt "217" ]; then
671 ch=$([ "${ch}" -lt "213" ] && echo "209" || echo "213")
672 bw_str=$([ "${ch}" -le "211" ] && echo "HT40+" || echo "HT40-")
673 elif [ ${ch} -lt "225" ]; then
674 ch=$([ "${ch}" -lt "221" ] && echo "217" || echo "221")
675 bw_str=$([ "${ch}" -le "219" ] && echo "HT40+" || echo "HT40-")
676 elif [ ${ch} -lt "233" ]; then
677 ch=$([ "${ch}" -lt "229" ] && echo "225" || echo "229")
678 bw_str=$([ "${ch}" -le "227" ] && echo "HT40+" || echo "HT40-")
679 fi
680 ;;
681 "0")
682 local bw_str="HT20"
683 ;;
684 esac
developerb9b4cd12022-10-11 13:18:59 +0800685 fi
686
687 local control_freq=$(((ch - base_chan) * 5 + base_freq))
688 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
689}
690
691function convert_rxstat {
692 local res=$(do_cmd "mt76-test ${interface} dump stats")
693 local mdrdy=$(echo "${res}" | grep "rx_packets" | cut -d "=" -f 2)
694 local fcs_error=$(echo "${res}" | grep "rx_fcs_error" | cut -d "=" -f 2)
695 local rcpi=$(echo "${res}" | grep "last_rcpi" | cut -d "=" -f 2 | sed 's/,/ /g')
696 local ib_rssi=$(echo "${res}" | grep "last_ib_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
697 local wb_rssi=$(echo "${res}" | grep "last_wb_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
698 local rx_ok=$(expr ${mdrdy} - ${fcs_error})
699
700 write_dmesg "rcpi: ${rcpi}"
701 write_dmesg "fagc rssi ib: ${ib_rssi}"
702 write_dmesg "fagc rssi wb: ${wb_rssi}"
703 write_dmesg "all_mac_rx_mdrdy_cnt: ${mdrdy}"
704 write_dmesg "all_mac_rx_fcs_err_cnt: ${fcs_error}"
705 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
706}
707
708function set_mac_addr {
709 record_config ${cmd} ${param} ${iwpriv_file}
710
711 local addr1=$(get_config "ATEDA" ${iwpriv_file})
712 local addr2=$(get_config "ATESA" ${iwpriv_file})
713 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
714
715 if [ -z "${addr1}" ]; then
716 addr1="00:11:22:33:44:55"
717 fi
718 if [ -z "${addr2}" ]; then
719 addr2="00:11:22:33:44:55"
720 fi
721 if [ -z "${addr3}" ]; then
722 addr3="00:11:22:33:44:55"
723 fi
724
725 do_cmd "mt76-test phy${phy_idx} set mac_addrs=${addr1},${addr2},${addr3}"
726}
727
728function convert_ibf {
729 local cmd=$1
730 local param=$2
731 local new_cmd=""
732 local new_param=$(echo ${param} | sed s/":"/","/g)
733
734 case ${cmd} in
735 "ATETxBfInit")
736 new_cmd="init"
developerc5ce7502022-12-19 11:33:22 +0800737 new_param="1"
738 do_cmd "mt76-test phy${phy_idx} set state=idle"
739 ;;
740 "ATETxBfGdInit")
741 new_cmd="golden_init"
742 new_param="1"
developerb9b4cd12022-10-11 13:18:59 +0800743 do_cmd "mt76-test phy${phy_idx} set state=idle"
744 ;;
745 "ATEIBFPhaseComp")
746 new_cmd="phase_comp"
developerc5ce7502022-12-19 11:33:22 +0800747 new_param="${new_param}"
developerb9b4cd12022-10-11 13:18:59 +0800748 ;;
749 "ATEEBfProfileConfig")
750 new_cmd="ebf_prof_update"
751 ;;
752 "ATEIBfProfileConfig")
753 new_cmd="ibf_prof_update"
754 ;;
755 "ATEIBfInstCal")
756 new_cmd="phase_cal"
757 ;;
758 "ATEIBfGdCal")
developera46f6132024-03-26 14:09:54 +0800759 local group=${new_param:0:2}
760 local group_l_m_h=${new_param:3:2}
761 local band_idx=${new_param:6:2}
762 local cal_type=${new_param:9:2}
763 local version=${new_param:12}
764 local lna_level="00"
765
766 # only ibf 2.0 will set version, so add null check for backward compatibility
767 if [ -z $version ]; then
768 version="00"
769 fi
770
developerb9b4cd12022-10-11 13:18:59 +0800771 new_cmd="phase_cal"
developera46f6132024-03-26 14:09:54 +0800772 new_param="${group},${group_l_m_h},${band_idx},${cal_type},${lna_level},${version}"
developerb9b4cd12022-10-11 13:18:59 +0800773 ;;
774 "TxBfTxApply")
775 new_cmd="apply_tx"
776 ;;
777 "ATETxPacketWithBf")
778 local bf_on=${new_param:0:2}
779 local aid="01"
780 local wlan_idx=${new_param:3:2}
781 local update="00"
developera46f6132024-03-26 14:09:54 +0800782 local tx_count=${new_param:6}
developerb9b4cd12022-10-11 13:18:59 +0800783
784 new_cmd="tx_prep"
785 new_param="${bf_on},${aid},${wlan_idx},${update}"
developera46f6132024-03-26 14:09:54 +0800786 if [ "${tx_count}" = "00" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800787 new_param="${new_param} aid=1 tx_count=10000000 tx_length=1024"
788 else
developera46f6132024-03-26 14:09:54 +0800789 new_param="${new_param} aid=1 tx_count=${tx_count} tx_length=1024"
developerb9b4cd12022-10-11 13:18:59 +0800790 fi
791 do_cmd "mt76-test phy${phy_idx} set state=idle"
792 ;;
793 "TxBfProfileData20MAllWrite")
794 new_cmd="prof_update_all"
795 ;;
796 "ATEIBFPhaseE2pUpdate")
797 new_cmd="e2p_update"
798 ;;
developerc5ce7502022-12-19 11:33:22 +0800799 "ATEIBFPhaseVerify")
800 local group=${new_param:0:2}
801 local group_l_m_h=${new_param:3:2}
802 local band_idx=${new_param:6:2}
803 local phase_cal_type=${new_param:9:2}
804 local LNA_gain_level=${new_param:12:2}
805 local read_from_e2p=${new_param:15:2}
806
807 do_cmd "mt76-test phy${phy_idx} set txbf_act=phase_comp txbf_param=1,${band_idx},${group},${read_from_e2p},0"
808 new_cmd="phase_cal"
809 new_param="${group},${group_l_m_h},${band_idx},${phase_cal_type},${LNA_gain_level}"
810 ;;
811 "TxBfProfileTagRead")
812 new_cmd="pfmu_tag_read"
813 ;;
814 "TxBfProfileTagWrite")
815 new_cmd="pfmu_tag_write"
816 ;;
817 "TxBfProfileTagInValid")
818 new_cmd="set_invalid_prof"
819 ;;
820 "StaRecBfRead")
821 new_cmd="sta_rec_read"
822 ;;
823 "TriggerSounding")
824 new_cmd="trigger_sounding"
825 ;;
826 "StopSounding")
827 new_cmd="stop_sounding"
828 new_param="0"
829 ;;
developer7af0f762023-05-22 15:16:16 +0800830 "TxBfTxCmd")
831 new_cmd="txcmd"
832 ;;
developerc5ce7502022-12-19 11:33:22 +0800833 "ATEConTxETxBfGdProc")
834 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
835 local tx_rate_idx=${new_param:3:2}
836 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
837 local channel=${new_param:9:3}
838 local channel2=${new_param:13:3}
839 local band=${new_param:17}
840
841 new_cmd="ebf_golden_init"
842 do_ate_work "ATESTART"
843 do_cmd "mt76-test phy${phy_idx} set state=idle"
844 record_config "ATETXBW" ${bw} ${iwpriv_file}
845 convert_channel "${channel}:${band}"
846 if [ "${bw}" = "5" ]; then
847 new_param="1,1"
848 else
849 new_param="1,0"
850 fi
851 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_sgi=0"
852 ;;
853 "ATEConTxETxBfInitProc")
854 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
855 local tx_rate_idx=${new_param:3:2}
856 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
857 local tx_rate_nss=${new_param:9:2}
858 local tx_stream=${new_param:12:2}
859 local tx_power=${new_param:15:2}
developer7af0f762023-05-22 15:16:16 +0800860 local channel=$(echo ${new_param:18:3} | sed 's/^0//')
developerc5ce7502022-12-19 11:33:22 +0800861 local channel2=${new_param:22:3}
862 local band=${new_param:26:1}
developer7af0f762023-05-22 15:16:16 +0800863 local tx_length=$(echo ${new_param:28:5} | sed 's/^0//')
developerc5ce7502022-12-19 11:33:22 +0800864
865 new_cmd="ebf_init"
866 do_ate_work "ATESTART"
867 do_cmd "mt76-test phy${phy_idx} set state=idle"
868 record_config "ATETXBW" ${bw} ${iwpriv_file}
869 convert_channel "${channel}:${band}"
870 new_param="1"
871 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"
872 ;;
developerb9b4cd12022-10-11 13:18:59 +0800873 *)
874 esac
875
876 do_cmd "mt76-test phy${phy_idx} set txbf_act=${new_cmd} txbf_param=${new_param}"
877
878 if [ "${cmd}" = "ATETxPacketWithBf" ]; then
879 do_cmd "mt76-test phy${phy_idx} set state=tx_frames"
developerc5ce7502022-12-19 11:33:22 +0800880 elif [ "${cmd}" = "ATEConTxETxBfInitProc" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800881 local wlan_idx="1"
developerc8796032023-08-09 10:28:15 +0800882 if [ ${is_connac3} == "1" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800883 local wlan_idx=$((phy_idx+1))
884 fi
developerc5ce7502022-12-19 11:33:22 +0800885 do_cmd "mt76-test phy${phy_idx} set aid=1"
886 do_cmd "mt76-test phy${phy_idx} set txbf_act=stop_sounding txbf_param=1"
887 do_cmd "mt76-test phy${phy_idx} set txbf_act=update_ch txbf_param=1"
888 do_cmd "mt76-test phy${phy_idx} set txbf_act=ebf_prof_update txbf_param=0,0,0"
developerbb6ddff2023-03-08 17:22:32 +0800889 do_cmd "mt76-test phy${phy_idx} set txbf_act=apply_tx txbf_param=${wlan_idx},1,0,0,0"
developerc8796032023-08-09 10:28:15 +0800890 if [ ${is_connac3} == "1" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800891 do_cmd "mt76-test phy${phy_idx} set txbf_act=txcmd txbf_param=1,1,1"
892 fi
developerc5ce7502022-12-19 11:33:22 +0800893 do_cmd "mt76-test phy${phy_idx} set txbf_act=pfmu_tag_read txbf_param=0,1"
developerbb6ddff2023-03-08 17:22:32 +0800894 do_cmd "mt76-test phy${phy_idx} set txbf_act=sta_rec_read txbf_param=${wlan_idx}"
895 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=0,1,0,${wlan_idx},0,0,0"
896 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=2,1,ff,${wlan_idx},0,0,0"
developerc5ce7502022-12-19 11:33:22 +0800897 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
898 elif [ "${cmd}" = "ATEConTxETxBfGdProc" ]; then
899 do_cmd "mt76-test phy${phy_idx} set aid=1"
900 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
901 elif [ "${cmd}" = "ATETxBfInit" ]; then
902 do_cmd "mt76-test phy${phy_idx} set aid=1"
903 elif [ "${cmd}" = "ATETxBfGdInit" ]; then
904 do_cmd "mt76-test phy${phy_idx} set aid=1"
developerf9b00212023-07-31 12:27:06 +0800905 elif [ "${cmd}" = "ATEIBFPhaseE2pUpdate" ]; then
906 do_cmd "atenl -i phy${phy_idx} -c \"eeprom ibf sync\""
developerb9b4cd12022-10-11 13:18:59 +0800907 fi
908}
909
developer9a587882023-07-17 11:11:44 +0800910function convert_ruinfo {
911 local new_param=$1
912
913 do_cmd "mt76-test phy${phy_idx} set state=idle"
914 while [ -n "$new_param" ]
915 do
916 [ ${new_param:1:1} = ':' ] && {
917 new_param=${new_param:2}
918 }
919 local oIFS="$IFS"; IFS=":"; set -- $new_param; IFS="$oIFS"
920
921 parsing_ruinfo $new_param
922 new_param=${new_param:${#1}+1}
923 done
924}
925
926function parsing_ruinfo {
927 local new_param=$1
928 local oIFS="$IFS"; IFS="-:"; set -- $new_param; IFS="$oIFS"
929
930 # $7 is Start spatial stream and it should be 0, $9 is alpha, not used
931 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=he_mu tx_rate_sgi=0 tx_ltf=0 ru_alloc=$1 aid=$2 ru_idx=$3\
932 tx_rate_idx=$4 tx_rate_ldpc=$5 tx_rate_nss=$6 tx_length=$8"
933}
934
developerb403ad02022-11-08 10:16:29 +0800935function convert_dfs {
936 local cmd=$1
937 local param=$2
938
939 case ${cmd} in
940 "DfsRxCtrl")
941 local offchan_ch="$(echo $param | cut -d ':' -f1)"
942 local offchan_bw="$(echo $param | cut -d ':' -f2)"
943
developerc9333e12023-04-06 18:07:42 +0800944 if [ "$offchan_bw" = "0" ]; then
945 offchan_bw="20"
946 elif [ "$offchan_bw" = "1" ]; then
947 offchan_bw="40"
948 elif [ "$offchan_bw" = "2" ]; then
949 offchan_bw="80"
950 elif [ "$offchan_bw" = "3" ]; then
951 offchan_bw="160"
952 fi
developerb403ad02022-11-08 10:16:29 +0800953
developerc9333e12023-04-06 18:07:42 +0800954 do_cmd "mt76-test phy${phy_idx} set state=idle"
955 do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
developerb403ad02022-11-08 10:16:29 +0800956 ;;
957 "DfsRxHist")
958 local ipi_th="$(echo $param | cut -d ':' -f 1)"
959 local ipi_period="$(echo $param | cut -d ':' -f 2)"
developerc9333e12023-04-06 18:07:42 +0800960 local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
developerb403ad02022-11-08 10:16:29 +0800961
developerc9333e12023-04-06 18:07:42 +0800962 if [ -z $ipi_antenna ]; then
963 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
964 else
965 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
966 fi
developerb403ad02022-11-08 10:16:29 +0800967 ;;
968 *)
969 esac
970}
971
developerb9b4cd12022-10-11 13:18:59 +0800972function do_ate_work() {
973 local ate_cmd=$1
974
975 case ${ate_cmd} in
976 "ATESTART")
977 local if_str=$(ifconfig | grep mon${phy_idx})
978
979 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
980 echo "ATE already starts."
981 else
982 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
developer3f784572023-01-31 15:21:28 +0800983
984 if [ $phy_idx -ge $SOC_start_idx ]; then
985 local end_idx=$SOC_end_idx
986 local start_idx=$SOC_start_idx
987 else
988 local end_idx=$((SOC_start_idx-1))
989 local start_idx="0"
990 fi
991
992 for phy_index in $( seq $start_idx $end_idx )
993 do
994 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
995 local prev_phy_index=$((phy_index-1))
996 local if_num=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep -c Interface)
997 local j="1"
998 # avoid del_if_count reset to 0 when start ate on another band in dbdc case
999 local del_if_count=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
1000 if [ -z "${del_if_count}" ]; then
1001 local del_if_count="0"
1002 fi
1003
1004 for if_count in $( seq 1 $if_num )
1005 do
1006 local del_if=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep Interface | sed -n ${j}p | cut -d " " -f 2)
1007 if [ ! -z "${del_if}" ] && [[ "$del_if" != *"mon"* ]]; then
1008 do_cmd "iw dev ${del_if} del"
1009 del_if_count=$((del_if_count+1))
1010 # handle the case of multiple interface in a phy
1011 record_config "DEL_IF${phy_index}-${del_if_count}" ${del_if} ${interface_file}
1012 else
1013 # j add 1 to skip mon interface
1014 j=$((j+1))
1015 fi
1016 done
1017 record_config "DEL_IF${phy_index}_NUM" ${del_if_count} ${interface_file}
1018 done
1019
developerb9b4cd12022-10-11 13:18:59 +08001020 do_cmd "ifconfig mon${phy_idx} up"
1021 do_cmd "iw reg set VV"
1022 fi
1023 ;;
1024 "ATESTOP")
1025 local if_str=$(ifconfig | grep mon${phy_idx})
1026
1027 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
1028 echo "ATE does not start."
1029 else
1030 do_cmd "mt76-test ${interface} set state=off"
1031 do_cmd "iw dev mon${phy_idx} del"
developer3f784572023-01-31 15:21:28 +08001032
1033 if [ $phy_idx -ge $SOC_start_idx ]; then
1034 local end_idx=$SOC_end_idx
1035 local start_idx=$SOC_start_idx
1036 else
1037 local end_idx=$((SOC_start_idx-1))
1038 local start_idx="0"
1039 fi
1040
1041 # first check its phy and dbdc band phy has monitor interface or not
1042 # if has at lease one mon interface, then skip adding back normal interface
1043 local has_mon="0"
1044 for phy_index in $( seq $start_idx $end_idx )
1045 do
1046 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
1047 local prev_phy_index=$((phy_index-1))
1048 local has_mon_phy=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep "Interface mon")
1049 # if this phy interface has mon interface
1050 if [ ! -z "${has_mon_phy}" ]; then
1051 local has_mon="1"
1052 fi
1053 done
1054
1055 for phy_index in $( seq $start_idx $end_idx )
1056 do
1057 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
1058 local prev_phy_index=$((phy_index-1))
1059 local j="1"
1060 local add_if_num=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
1061 if [ -z "${add_if_num}" ]; then
1062 local add_if_num="0"
1063 fi
1064 # if this phy interface (including its dbdc phy) has no mon interface and can find deleted interface in file, then add it back
1065 if [ "${has_mon}" == "0" ] && [ $add_if_num -ge "1" ]; then
1066 local if_index=$add_if_num
1067 # add interface backwards
1068 while [ $if_index -gt "0" ]
1069 do
1070 local add_if=$(get_config "DEL_IF${phy_index}-${if_index}" ${interface_file})
1071 do_cmd "iw phy phy${phy_index} interface add ${add_if} type managed"
1072 # remove the deleted interface in interface_file since it is added back
1073 sed -i "/DEL_IF${phy_index}-${if_index}=/d" ${interface_file}
1074 if_index=$((if_index-1))
1075 done
1076 # remove the number of deleted interface in interface_file since it is all added back
1077 sed -i "/DEL_IF${phy_index}_NUM=/d" ${interface_file}
1078 fi
1079 done
1080
developerb9b4cd12022-10-11 13:18:59 +08001081 do_cmd "mt76-test ${interface} set aid=0"
1082 fi
1083
developer13655da2023-01-10 19:53:25 +08001084 if [ ${phy_idx} -lt ${SOC_start_idx} ]; then
developerb9b4cd12022-10-11 13:18:59 +08001085 sed -i '/_PCIE=/d' ${iwpriv_file}
developer13655da2023-01-10 19:53:25 +08001086 elif [ ${phy_idx} -ge ${SOC_start_idx} ]; then
1087 sed -i '/_SOC=/d' ${iwpriv_file}
developerb9b4cd12022-10-11 13:18:59 +08001088 fi
1089 ;;
1090 "TXCOMMIT")
1091 do_cmd "mt76-test ${interface} set aid=1"
1092 ;;
1093 "TXFRAME")
1094 do_cmd "mt76-test ${interface} set state=tx_frames"
1095 ;;
1096 "TXSTOP"|"RXSTOP")
1097 do_cmd "mt76-test ${interface} set state=idle"
1098 ;;
1099 "TXREVERT")
1100 do_cmd "mt76-test ${interface} set aid=0"
1101 ;;
1102 "RXFRAME")
1103 do_cmd "mt76-test ${interface} set state=rx_frames"
1104 ;;
1105 "TXCONT")
1106 do_cmd "mt76-test ${interface} set state=tx_cont"
1107 ;;
1108 "GROUPREK")
1109 do_cmd "mt76-test ${interface} set state=group_prek"
1110 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
1111 ;;
1112 "GROUPREKDump")
1113 do_cmd "mt76-test ${interface} set state=group_prek_dump"
1114 ;;
1115 "GROUPREKClean")
1116 do_cmd "mt76-test ${interface} set state=group_prek_clean"
1117 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
1118 ;;
1119 "DPD2G")
1120 do_cmd "mt76-test ${interface} set state=dpd_2g"
1121 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
1122 ;;
1123 "DPD5G")
1124 do_cmd "mt76-test ${interface} set state=dpd_5g"
1125 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
1126 ;;
1127 "DPD6G")
1128 do_cmd "mt76-test ${interface} set state=dpd_6g"
1129 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
1130 ;;
1131 "DPDDump")
1132 do_cmd "mt76-test ${interface} set state=dpd_dump"
1133 ;;
1134 "DPDClean")
1135 do_cmd "mt76-test ${interface} set state=dpd_clean"
1136 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
1137 ;;
1138 *)
1139 print_debug "skip ${ate_cmd}"
1140 ;;
1141 esac
1142}
1143
developer13655da2023-01-10 19:53:25 +08001144function dump_usage {
1145 echo "Usage:"
1146 echo " mwctl <interface> set csi ctrl=<opt1>,<opt2>,<opt3>,<opt4> (macaddr=<macaddr>)"
1147 echo " mwctl <interface> set csi interval=<interval (us)>"
1148 echo " mwctl <interface> dump csi <packet num> <filename>"
1149 echo " mwctl <interface> set amnt <index>(0x0~0xf) <mac addr>(xx:xx:xx:xx:xx:xx)"
1150 echo " mwctl <interface> dump amnt <index> (0x0~0xf or 0xff)"
1151 echo " mwctl <interface> set ap_rfeatures he_gi=<val>"
1152 echo " mwctl <interface> set ap_rfeatures he_ltf=<val>"
1153 echo " mwctl <interface> set ap_rfeatures trig_type=<enable>,<val> (val: 0-7)"
1154 echo " mwctl <interface> set ap_rfeatures ack_policy=<val> (val: 0-4)"
1155 echo " mwctl <interface> set ap_wireless fixed_mcs=<val>"
1156 echo " mwctl <interface> set ap_wireless ofdma=<val> (0: disable, 1: DL, 2: UL)"
1157 echo " mwctl <interface> set ap_wireless nusers_ofdma=<val>"
1158 echo " mwctl <interface> set ap_wireless ppdu_type=<val> (0: SU, 1: MU, 4: LEGACY)"
1159 echo " mwctl <interface> set ap_wireless add_ba_req_bufsize=<val>"
1160 echo " mwctl <interface> set ap_wireless mimo=<val> (0: DL, 1: UL)"
1161 echo " mwctl <interface> set ap_wireless ampdu=<enable>"
1162 echo " mwctl <interface> set ap_wireless amsdu=<enable>"
1163 echo " mwctl <interface> set ap_wireless cert=<enable>"
developer2c78ce72023-02-24 11:26:12 +08001164 echo " mwctl <interface> set mu onoff=<val> (bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0))"
developer13655da2023-01-10 19:53:25 +08001165 echo " mwctl <interface> dump phy_capa"
1166}
1167
developer092b55c2023-01-18 18:20:58 +08001168function register_handler {
1169
1170 local phy_idx=$1
1171 local offset=$2
1172 local val=$3
1173 local cmd=$4
1174 local w_cmd="write"
1175
1176 regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
1177 regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
1178
1179 echo ${offset} > ${regidx}
1180 if [[ "${cmd}" == "${w_cmd}" ]]; then
1181 echo ${val} > ${regval}
1182 fi
1183
1184 res=$(cat ${regval} | cut -d 'x' -f 2)
1185 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
1186}
1187
developerb9b4cd12022-10-11 13:18:59 +08001188# main start here
developer3f784572023-01-31 15:21:28 +08001189parse_sku
developer13655da2023-01-10 19:53:25 +08001190if [ -z ${interface} ]; then
1191 dump_usage
1192 exit
1193elif [[ ${interface} == "ra"* ]]; then
developerb9b4cd12022-10-11 13:18:59 +08001194 convert_interface $interface
developerbb6ddff2023-03-08 17:22:32 +08001195elif [[ ${interface} == "phy" ]]; then
1196 # handle mwctl phy phy0 e2p ... case
1197 interface=$2
1198 cmd_type=$3
1199 full_cmd=$4
developerb9b4cd12022-10-11 13:18:59 +08001200fi
1201
1202tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
1203
1204if [ ! -z ${tmp_work_mode} ]; then
1205 work_mode=${tmp_work_mode}
1206fi
1207
1208cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
1209param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
developera20cdc22024-05-31 18:57:31 +08001210mld=$(iw dev | grep 'link ID')
developerb9b4cd12022-10-11 13:18:59 +08001211
1212if [ "${cmd_type}" = "set" ]; then
1213 skip=0
1214 case ${cmd} in
developer13655da2023-01-10 19:53:25 +08001215 ## In wifi 7 chipset, testmode & vendor command both use mwctl
1216 ## Therefore this wrapper would translate it to either mt76-test or mt76-vendor based on the attribute of the command
1217 ## Translate to mt76-vendor command
developer327aa322023-07-10 13:49:56 +08001218 "csi"|"amnt"|"ap_rfeatures"|"ap_wireless"|"mu"|"set_muru_manual_config")
developera20cdc22024-05-31 18:57:31 +08001219 cert_cmd="$*"
1220 if [ ! -z "$mld" ]; then
1221 mld_interface=$(iw dev | grep Interface | awk '{print $2}')
1222 cert_cmd="$(echo $* | sed 's/band[0-9]/${mld_interface}/')"
1223 fi
developerc8796032023-08-09 10:28:15 +08001224 if [ ${is_connac3} == "1" ]; then
developera20cdc22024-05-31 18:57:31 +08001225 hostapd_cmd="$(echo $cert_cmd | sed 's/set/raw/')"
developer1475cf22023-05-05 13:45:43 +08001226 do_cmd "hostapd_cli -i $hostapd_cmd"
developerbb6ddff2023-03-08 17:22:32 +08001227 else
developera20cdc22024-05-31 18:57:31 +08001228 do_cmd "mt76-vendor $cert_cmd"
developerbb6ddff2023-03-08 17:22:32 +08001229 fi
1230 skip=1
developer13655da2023-01-10 19:53:25 +08001231 ;;
developerb9b4cd12022-10-11 13:18:59 +08001232 "ATE")
1233 do_ate_work ${param}
1234
1235 skip=1
1236 ;;
1237 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
1238 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
1239 cmd_new=$(simple_convert ${cmd})
1240 if [ "${param_new}" = "undefined" ]; then
1241 echo "unknown cmd: ${cmd}"
1242 exit
1243 fi
1244 param_new=${param}
developerc5ce7502022-12-19 11:33:22 +08001245 if [ "${cmd}" = "ATETXCNT" ] && [ "${param}" = "0" ]; then
developer15c355d2023-03-21 17:28:34 +08001246 param_new="0xFFFFFFFF"
developerc5ce7502022-12-19 11:33:22 +08001247 fi
developerb9b4cd12022-10-11 13:18:59 +08001248 ;;
1249 "ATETXANT"|"ATERXANT")
1250 cmd_new="tx_antenna"
1251 param_new=${param}
1252 ;;
1253 "ATETXGI")
developerc8796032023-08-09 10:28:15 +08001254 if [ ${is_connac3} == "0" ]; then
developerbb6ddff2023-03-08 17:22:32 +08001255 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
1256 convert_gi ${tx_mode} ${param}
1257 skip=1
1258 else
1259 cmd_new="tx_rate_sgi"
1260 param_new=${param}
1261 fi
developerb9b4cd12022-10-11 13:18:59 +08001262 ;;
1263 "ATETXMODE")
1264 cmd_new="tx_rate_mode"
1265 param_new=$(convert_tx_mode ${param})
1266 if [ "${param_new}" = "undefined" ]; then
1267 echo "unknown tx mode"
1268 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
1269 exit
1270 else
1271 record_config ${cmd} ${param} ${iwpriv_file}
1272 fi
1273 ;;
developerbb6ddff2023-03-08 17:22:32 +08001274 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3"|"ATETXPOW")
developerb9b4cd12022-10-11 13:18:59 +08001275 cmd_new="tx_power"
developerbb6ddff2023-03-08 17:22:32 +08001276 if [ "${param}" == "127" ]; then
1277 # for iTest verification
1278 exit
1279 fi
developerb9b4cd12022-10-11 13:18:59 +08001280 param_new="${param},0,0,0"
1281 ;;
developerbb6ddff2023-03-08 17:22:32 +08001282 "ATEMUAID")
1283 cmd_new="aid"
1284 param_new=${param}
1285 ;;
developerb9b4cd12022-10-11 13:18:59 +08001286 "ATETXBW")
1287 record_config ${cmd} ${param} ${iwpriv_file}
1288 skip=1
1289 ;;
1290 "ATECHANNEL")
1291 convert_channel ${param}
1292 skip=1
1293 ;;
1294 "ATERXSTAT")
1295 convert_rxstat
1296 skip=1
1297 ;;
1298 "ATECTRLBANDIDX")
1299 change_band_idx ${param}
1300 skip=1
1301 ;;
1302 "ATEDA"|"ATESA"|"ATEBSSID")
1303 set_mac_addr ${cmd} ${param}
1304 skip=1
1305 ;;
developerb403ad02022-11-08 10:16:29 +08001306 "DfsRxCtrl"|"DfsRxHist")
1307 convert_dfs ${cmd} ${param}
1308 skip=1
1309 ;;
developerc5ce7502022-12-19 11:33:22 +08001310 "ATETxBfInit"|"ATETxBfGdInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
1311 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"| \
developer7af0f762023-05-22 15:16:16 +08001312 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate"|"TriggerSounding"|"StopSounding"|"TxBfTxCmd"| \
developerc5ce7502022-12-19 11:33:22 +08001313 "StaRecBfRead"|"TxBfProfileTagInValid"|"TxBfProfileTagWrite"|"TxBfProfileTagRead"| \
1314 "ATEIBFPhaseVerify"|"ATEConTxETxBfGdProc"|"ATEConTxETxBfInitProc")
developerb9b4cd12022-10-11 13:18:59 +08001315 convert_ibf ${cmd} ${param}
1316 skip=1
1317 ;;
1318 "bufferMode")
1319 if [ "${param}" = "2" ]; then
1320 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
1321 fi
1322 skip=1
1323 ;;
1324 "ResetCounter"|"ATERXSTATRESET")
1325 skip=1
1326 ;;
1327 "WORKMODE")
1328 record_config "WORKMODE" ${param} ${iwpriv_file}
1329 echo "Entering ${param} mode in iwpriv"
1330 skip=1
1331 ;;
developer9a587882023-07-17 11:11:44 +08001332 "ATERUINFO")
1333 convert_ruinfo ${param}
1334 skip=1
1335 ;;
developerb9b4cd12022-10-11 13:18:59 +08001336 *)
1337 print_debug "Unknown command to set: ${cmd}"
1338 skip=1
1339 esac
1340
1341 if [ "${skip}" != "1" ]; then
1342 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
1343 fi
1344
1345elif [ "${cmd_type}" = "show" ]; then
developerc5ce7502022-12-19 11:33:22 +08001346 if [ "${cmd}" = "wtbl" ]; then
1347 wlan_idx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wlan_idx
1348 wtbl_info=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wtbl_info
1349
1350 do_cmd "echo ${param} > ${wlan_idx}"
1351 do_cmd "cat ${wtbl_info}"
developerbb6ddff2023-03-08 17:22:32 +08001352 elif [ "${cmd}" = "ATERXSTAT" ]; then
1353 convert_rxstat
developerc5ce7502022-12-19 11:33:22 +08001354 else
1355 do_cmd "mt76-test ${interface} dump"
1356 do_cmd "mt76-test ${interface} dump stats"
1357 fi
developerb9b4cd12022-10-11 13:18:59 +08001358
1359elif [ "${cmd_type}" = "e2p" ]; then
developer13655da2023-01-10 19:53:25 +08001360 # support multiple read write
developerb9b4cd12022-10-11 13:18:59 +08001361 # eeprom offset write
1362 if [[ ${full_cmd} == *"="* ]]; then
developer13655da2023-01-10 19:53:25 +08001363 IFS=,
1364 for tuple in $full_cmd
1365 do
1366 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1367 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1368 offset=$(printf "0x%s" ${cmd})
1369 val=$(printf "0x%s" ${param})
1370 tmp=$((${val} & 0xff))
1371 tmp=$(printf "0x%x" ${tmp})
1372 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developerb9b4cd12022-10-11 13:18:59 +08001373
developer13655da2023-01-10 19:53:25 +08001374 offset=$((${offset}))
1375 offset=$(expr ${offset} + "1")
1376 offset=$(printf "0x%x" ${offset})
1377 tmp=$(((${val} >> 8) & 0xff))
1378 tmp=$(printf "0x%x" ${tmp})
1379 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
1380 done
developerb9b4cd12022-10-11 13:18:59 +08001381 else
developer13655da2023-01-10 19:53:25 +08001382 IFS=,
1383 for tuple in $full_cmd
1384 do
1385 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1386 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1387 offset=$(printf "0x%s" ${cmd})
1388 val=$(printf "0x%s" ${param})
1389 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
1390 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developerb9b4cd12022-10-11 13:18:59 +08001391
developer13655da2023-01-10 19:53:25 +08001392 tmp=$(printf "0x%s" ${param})
1393 tmp=$((${tmp}))
1394 param2=$(expr ${tmp} + "1")
1395 param2=$(printf "%x" ${param2})
1396 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
1397 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developerb9b4cd12022-10-11 13:18:59 +08001398
developer13655da2023-01-10 19:53:25 +08001399 param=$(printf "0x%s" ${param})
1400 param=$(printf "%04x" ${param})
1401 param=$(echo $param | tr 'a-z' 'A-Z')
1402 printf "%s e2p:\n" ${interface_ori}
1403 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
1404 done
developerb9b4cd12022-10-11 13:18:59 +08001405 fi
1406
1407elif [ "${cmd_type}" = "mac" ]; then
developerb9b4cd12022-10-11 13:18:59 +08001408 offset=$(printf "0x%s" ${cmd})
1409 val=$(printf "0x%s" ${param})
1410
developerb9b4cd12022-10-11 13:18:59 +08001411 # reg write
1412 if [[ ${full_cmd} == *"="* ]]; then
developer092b55c2023-01-18 18:20:58 +08001413 register_handler ${phy_idx} ${offset} ${val} "write"
1414 else
1415 start_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 1)
1416 end_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 2)
1417 loop=$((0x${end_addr}-0x${start_addr}))
developerb9b4cd12022-10-11 13:18:59 +08001418
developer092b55c2023-01-18 18:20:58 +08001419 if [[ ${loop} == "0" ]]; then
1420 register_handler ${phy_idx} ${offset} ${val}
1421 else
1422 i=0
1423 while [ $i -le $loop ]; do
1424 addr=$((0x${start_addr}+$i))
1425 offset=$(printf "0x%x" ${addr})
1426 register_handler ${phy_idx} ${offset} ${val}
1427 i=$(($i + 4))
1428 done
1429 fi
1430 fi
developerb9b4cd12022-10-11 13:18:59 +08001431
developer13655da2023-01-10 19:53:25 +08001432## dump command is only for vendor commands
1433elif [ "${cmd_type}" = "dump" ]; then
1434 do_cmd "mt76-vendor $*"
developerc9333e12023-04-06 18:07:42 +08001435elif [ "${cmd_type}" = "switch" ]; then
developer2299de92023-10-27 15:40:47 +08001436 eeprom_mode_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom_mode
developerc9333e12023-04-06 18:07:42 +08001437 eeprom_mode=$(cat ${eeprom_mode_file} | grep "mode" | sed -n 2p | cut -d " " -f 4)
1438 eeprom_testmode_offset="1af"
1439 testmode_enable="0"
1440
developerc8796032023-08-09 10:28:15 +08001441 if [ ${is_connac3} == "0" ]; then
developerc9333e12023-04-06 18:07:42 +08001442 return
1443 fi
1444
1445 if [ "${cmd}" = "testmode" ]; then
1446 testmode_enable="1"
developerdad89a32024-04-29 14:17:17 +08001447 do_cmd "wifi down"
1448 do_cmd "uci set wireless.radio0.disabled=1"
1449 do_cmd "uci set wireless.radio1.disabled=1"
1450 do_cmd "uci set wireless.radio2.disabled=1"
1451 do_cmd "uci commit"
developerc9333e12023-04-06 18:07:42 +08001452 fi
1453
1454 if [ "${eeprom_mode}" = "flash" ]; then
1455 ## flash mode should set eeprom testmode offset bit
1456 ## efuse/bin file/default bin mode rely on module param only
1457 do_cmd "atenl -i ${interface} -c \"eeprom set 0x${eeprom_testmode_offset}=0x${testmode_enable}\""
1458 ## If has no precal, it would not affect
1459 do_cmd "atenl -i ${interface} -c \"eeprom precal sync\""
1460 do_cmd "atenl -i ${interface} -c \"sync eeprom all\""
1461 fi
1462
1463 do_cmd "rmmod mt7996e"
1464 do_cmd "rmmod mt76-connac-lib"
1465 do_cmd "rmmod mt76"
1466 do_cmd "rmmod mac80211"
1467 do_cmd "rmmod cfg80211"
1468 do_cmd "rmmod compat"
1469 do_cmd "insmod compat"
1470 do_cmd "insmod cfg80211"
1471 do_cmd "insmod mac80211"
1472 do_cmd "insmod mt76"
1473 do_cmd "insmod mt76-connac-lib"
1474 do_cmd "insmod mt7996e testmode_enable=${testmode_enable}"
1475 do_cmd "sleep 5"
1476 do_cmd "killall hostapd"
1477 do_cmd "killall netifd"
developerb9b4cd12022-10-11 13:18:59 +08001478else
1479 echo "Unknown command"
1480fi