blob: 4fe407a333f7c2b6ef2b5045e97837480d479bea [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"
developerb9b4cd12022-10-11 13:18:59 +0800104 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
developer13655da2023-01-10 19:53:25 +0800105 SOC_start_idx="0"
developer3f784572023-01-31 15:21:28 +0800106 SOC_end_idx="1"
developerc8796032023-08-09 10:28:15 +0800107 is_connac3="0"
developer13655da2023-01-10 19:53:25 +0800108 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then
109 SOC_start_idx="0"
developer3f784572023-01-31 15:21:28 +0800110 SOC_end_idx="2"
developerc8796032023-08-09 10:28:15 +0800111 is_connac3="1"
112 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7992")" ]; then
113 SOC_start_idx="0"
114 SOC_end_idx="1"
115 is_connac3="1"
developerb9b4cd12022-10-11 13:18:59 +0800116 else
117 echo "Interface Conversion Failed!"
118 echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
developer3f784572023-01-31 15:21:28 +0800119 echo "For AX6000:"
120 echo " echo STARTIDX=0 >> ${interface_file}"
121 echo " echo ENDIDX=1 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800122 echo " echo IS_CONNAC3=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800123 echo "For AX7800:"
124 echo " echo STARTIDX=2 >> ${interface_file}"
125 echo " echo ENDIDX=3 >> ${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 AX8400:"
128 echo " echo STARTIDX=1 >> ${interface_file}"
129 echo " echo ENDIDX=2 >> ${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 Eagle:"
developerc8796032023-08-09 10:28:15 +0800132 echo " echo STARTIDX=0 >> ${interface_file}"
developer3f784572023-01-31 15:21:28 +0800133 echo " echo ENDIDX=2 >> ${interface_file}"
developerc8796032023-08-09 10:28:15 +0800134 echo " echo IS_CONNAC3=1 >> ${interface_file}"
135 echo "For Kite:"
136 echo " echo STARTIDX=0 >> ${interface_file}"
137 echo " echo ENDIDX=1 >> ${interface_file}"
138 echo " echo IS_CONNAC3=1 >> ${interface_file}"
developerb9b4cd12022-10-11 13:18:59 +0800139 exit 0
140 fi
developer13655da2023-01-10 19:53:25 +0800141 record_config "STARTIDX" ${SOC_start_idx} ${interface_file}
developer3f784572023-01-31 15:21:28 +0800142 record_config "ENDIDX" ${SOC_end_idx} ${interface_file}
developerc8796032023-08-09 10:28:15 +0800143 record_config "IS_CONNAC3" ${is_connac3} ${interface_file}
developerb9b4cd12022-10-11 13:18:59 +0800144 fi
developer3f784572023-01-31 15:21:28 +0800145}
developerb9b4cd12022-10-11 13:18:59 +0800146
developer3f784572023-01-31 15:21:28 +0800147function convert_interface {
developerc8796032023-08-09 10:28:15 +0800148 if [ ${is_connac3} == "0" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800149 if [[ $1 == "raix"* ]]; then
developer13655da2023-01-10 19:53:25 +0800150 phy_idx=1
151 elif [[ $1 == "rai"* ]]; then
developerb9b4cd12022-10-11 13:18:59 +0800152 phy_idx=0
153 elif [[ $1 == "rax"* ]]; then
developer13655da2023-01-10 19:53:25 +0800154 phy_idx=$((SOC_start_idx+1))
155 else
156 phy_idx=$SOC_start_idx
developerb9b4cd12022-10-11 13:18:59 +0800157 fi
developer13655da2023-01-10 19:53:25 +0800158
159 # convert phy index according to band idx
160 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
161 if [ "${band_idx}" = "0" ]; then
162 if [[ $1 == "raix"* ]]; then
163 phy_idx=0
164 elif [[ $1 == "rax"* ]]; then
165 phy_idx=$SOC_start_idx
166 fi
167 elif [ "${band_idx}" = "1" ]; then
168 if [[ $1 == "rai"* ]]; then
169 # AX8400: mt7915 remain phy0
170 # AX7800: mt7916 becomes phy1
171 phy_idx=$((SOC_start_idx-1))
172 elif [[ $1 == "ra"* ]]; then
173 phy_idx=$((SOC_start_idx+1))
174 fi
175 fi
176 else
177 # Eagle has different mapping method
178 # phy0: ra0
179 # phy1: rai0
180 # phy2: rax0
developerb9b4cd12022-10-11 13:18:59 +0800181 if [[ $1 == "rai"* ]]; then
developer13655da2023-01-10 19:53:25 +0800182 phy_idx=1
183 elif [[ $1 == "rax"* ]]; then
184 phy_idx=2
185 else
186 phy_idx=0
developerb9b4cd12022-10-11 13:18:59 +0800187 fi
188 fi
189
190 interface="phy${phy_idx}"
191}
192
193function change_band_idx {
194 local new_idx=$1
195 local new_phy_idx=$phy_idx
196
197 local old_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
198
199
200 if [[ ${interface_ori} == "ra"* ]]; then
201 if [ -z "${old_idx}" ] || [ "${old_idx}" != "${new_idx}" ]; then
202 if [ "${new_idx}" = "0" ]; then
203 # raix0 & rai0 becomes rai0
204 if [[ $interface_ori == "rai"* ]]; then
205 new_phy_idx=0
206 # rax0 & ra0 becomes ra0
207 elif [[ $interface_ori == "ra"* ]]; then
developer13655da2023-01-10 19:53:25 +0800208 new_phy_idx=$SOC_start_idx
developerb9b4cd12022-10-11 13:18:59 +0800209 fi
210 elif [ "${new_idx}" = "1" ]; then
211 # raix0 & rai0 becomes raix0
212 if [[ $interface_ori == "rai"* ]]; then
developerc5ce7502022-12-19 11:33:22 +0800213 # For AX8400 => don't change phy idx
developer13655da2023-01-10 19:53:25 +0800214 if [ ${SOC_start_idx} != "1" ]; then
developerc5ce7502022-12-19 11:33:22 +0800215 new_phy_idx=1
216 fi
developerb9b4cd12022-10-11 13:18:59 +0800217 # rax0 & ra0 becomes rax0
218 elif [[ $interface_ori == "ra"* ]]; then
developer13655da2023-01-10 19:53:25 +0800219 new_phy_idx=$((SOC_start_idx+1))
developerb9b4cd12022-10-11 13:18:59 +0800220 fi
221 fi
222 fi
223
224 if [ ${new_phy_idx} != ${phy_idx} ]; then
225 do_ate_work "ATESTOP"
226 phy_idx=$new_phy_idx
227 interface="phy${phy_idx}"
228 do_ate_work "ATESTART"
229 fi
230 fi
231 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
232}
233
234function simple_convert() {
235 if [ "$1" = "ATETXCNT" ]; then
236 echo "tx_count"
237 elif [ "$1" = "ATETXLEN" ]; then
238 echo "tx_length"
239 elif [ "$1" = "ATETXMCS" ]; then
240 echo "tx_rate_idx"
241 elif [ "$1" = "ATEVHTNSS" ]; then
242 echo "tx_rate_nss"
243 elif [ "$1" = "ATETXLDPC" ]; then
244 echo "tx_rate_ldpc"
245 elif [ "$1" = "ATETXSTBC" ]; then
246 echo "tx_rate_stbc"
247 elif [ "$1" = "ATEPKTTXTIME" ]; then
248 echo "tx_time"
249 elif [ "$1" = "ATEIPG" ]; then
250 echo "tx_ipg"
251 elif [ "$1" = "ATEDUTYCYCLE" ]; then
252 echo "tx_duty_cycle"
253 elif [ "$1" = "ATETXFREQOFFSET" ]; then
254 echo "freq_offset"
255 else
256 echo "undefined"
257 fi
258}
259
260function convert_tx_mode() {
developerc5ce7502022-12-19 11:33:22 +0800261 # Remove leading zeros
developer3f784572023-01-31 15:21:28 +0800262 local tx_mode=$(echo $1 | sed -r 's/0+([0-9]+)/\1/g')
developerc5ce7502022-12-19 11:33:22 +0800263
264 if [ "$tx_mode" = "0" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800265 echo "cck"
developerc5ce7502022-12-19 11:33:22 +0800266 elif [ "$tx_mode" = "1" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800267 echo "ofdm"
developerc5ce7502022-12-19 11:33:22 +0800268 elif [ "$tx_mode" = "2" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800269 echo "ht"
developerc5ce7502022-12-19 11:33:22 +0800270 elif [ "$tx_mode" = "4" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800271 echo "vht"
developerc5ce7502022-12-19 11:33:22 +0800272 elif [ "$tx_mode" = "8" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800273 echo "he_su"
developerc5ce7502022-12-19 11:33:22 +0800274 elif [ "$tx_mode" = "9" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800275 echo "he_er"
developerc5ce7502022-12-19 11:33:22 +0800276 elif [ "$tx_mode" = "10" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800277 echo "he_tb"
developerc5ce7502022-12-19 11:33:22 +0800278 elif [ "$tx_mode" = "11" ]; then
developerb9b4cd12022-10-11 13:18:59 +0800279 echo "he_mu"
developerbb6ddff2023-03-08 17:22:32 +0800280 elif [ "$tx_mode" = "13" ]; then
281 echo "eht_su"
282 elif [ "$tx_mode" = "14" ]; then
283 echo "eht_tb"
284 elif [ "$tx_mode" = "15" ]; then
285 echo "eht_mu"
developerb9b4cd12022-10-11 13:18:59 +0800286 else
287 echo "undefined"
288 fi
289}
290
291function convert_gi {
292 local tx_mode=$1
293 local val=$2
294 local sgi="0"
295 local he_ltf="0"
296
297 case ${tx_mode} in
298 "ht"|"vht")
299 sgi=${val}
300 ;;
301 "he_su"|"he_er")
302 case ${val} in
303 "0")
304 ;;
305 "1")
306 he_ltf="1"
307 ;;
308 "2")
309 sgi="1"
310 he_ltf="1"
311 ;;
312 "3")
313 sgi="2"
314 he_ltf="2"
315 ;;
316 "4")
317 he_ltf="2"
318 ;;
319 *)
320 echo "unknown gi"
321 esac
322 ;;
323 "he_mu")
324 case ${val} in
325 "0")
326 he_ltf="2"
327 ;;
328 "1")
329 he_ltf="1"
330 ;;
331 "2")
332 sgi="1"
333 he_ltf="1"
334 ;;
335 "3")
336 sgi="2"
337 he_ltf="2"
338 ;;
339 *)
340 echo "unknown gi"
341 esac
342 ;;
343 "he_tb")
344 case ${val} in
345 "0")
346 sgi="1"
347 ;;
348 "1")
349 sgi="1"
350 he_ltf="1"
351 ;;
352 "2")
353 sgi="2"
354 he_ltf="2"
355 ;;
356 *)
357 echo "unknown gi"
358 esac
359 ;;
360 *)
361 print_debug "legacy mode no need gi"
362 esac
363
364 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
365}
366
367function convert_channel {
368 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
369 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
370 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
371 local bw_str="HT20"
372 local base_chan=1
373 local control_freq=0
374 local base_freq=0
developerc5ce7502022-12-19 11:33:22 +0800375 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
376 local temp=$((phy_idx+1))
developerb9b4cd12022-10-11 13:18:59 +0800377
developerc5ce7502022-12-19 11:33:22 +0800378 # Handle ATECTRLBANDIDX
379 if [ ! -z ${ctrl_band_idx} ]; then
380 if [ "${ctrl_band_idx}" == "1" ] && [ ${band} == "0" ]; then
381 local temp=$(cat "/etc/config/wireless"| grep "option band" | sed -n ${temp}p | cut -c 15)
382 if [ "${temp}" == "2" ]; then
383 local band=0
384 elif [ "${temp}" == "5" ]; then
385 local band=1
386 elif [ "${temp}" == "6" ]; then
387 local band=2
388 else
389 echo "iwpriv wrapper band translate error!"
390 fi
391 else
392 # mt7915 in AX8400 case: band should be determined by only the input band
developer13655da2023-01-10 19:53:25 +0800393 if [ "${SOC_start_idx}" == "1" ] && [ ${phy_idx} == "0" ]; then
developerc5ce7502022-12-19 11:33:22 +0800394 local band=$((band))
395 else
396 local band=$((ctrl_band_idx * band))
397 fi
398 fi
developerb9b4cd12022-10-11 13:18:59 +0800399 fi
400
401 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
402 case ${bw} in
403 "1")
404 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
405 local bw_str="HT20"
406 else
407 local bw_str="HT40+"
408 ch=$(expr ${ch} - "2")
409 fi
410 ;;
411 esac
412 local base_freq=2412
413 elif [ "${band}" = "1" ]; then
414 case ${bw} in
415 "5")
416 bw_str="160MHz"
417 if [ ${ch} -lt "68" ]; then
418 ch="36"
419 elif [ ${ch} -lt "100" ]; then
420 ch="68"
421 elif [ ${ch} -lt "132" ]; then
422 ch="100"
423 elif [ ${ch} -lt "181" ]; then
424 ch="149"
425 fi
426 ;;
427 "2")
428 bw_str="80MHz"
429 if [ ${ch} -lt "52" ]; then
430 ch="36"
431 elif [ ${ch} -lt "68" ]; then
432 ch="52"
433 elif [ ${ch} -lt "84" ]; then
434 ch="68"
435 elif [ ${ch} -lt "100" ]; then
436 ch="84"
437 elif [ ${ch} -lt "116" ]; then
438 ch="100"
439 elif [ ${ch} -lt "132" ]; then
440 ch="116"
441 elif [ ${ch} -lt "149" ]; then
442 ch="132"
443 elif [ ${ch} -lt "165" ]; then
444 ch="149"
445 elif [ ${ch} -lt "181" ]; then
446 ch="165"
447 fi
448 ;;
449 "1")
450 if [ ${ch} -lt "44" ]; then
451 ch=$([ "${ch}" -lt "40" ] && echo "36" || echo "40")
452 bw_str=$([ "${ch}" -le "38" ] && echo "HT40+" || echo "HT40-")
453 elif [ ${ch} -lt "52" ]; then
454 ch=$([ "${ch}" -lt "48" ] && echo "44" || echo "48")
455 bw_str=$([ "${ch}" -le "46" ] && echo "HT40+" || echo "HT40-")
456 elif [ ${ch} -lt "60" ]; then
457 ch=$([ "${ch}" -lt "56" ] && echo "52" || echo "56")
458 bw_str=$([ "${ch}" -le "54" ] && echo "HT40+" || echo "HT40-")
459 elif [ ${ch} -lt "68" ]; then
460 ch=$([ "${ch}" -lt "64" ] && echo "60" || echo "64")
461 bw_str=$([ "${ch}" -le "62" ] && echo "HT40+" || echo "HT40-")
462 elif [ ${ch} -lt "76" ]; then
463 ch=$([ "${ch}" -lt "72" ] && echo "68" || echo "72")
464 bw_str=$([ "${ch}" -le "70" ] && echo "HT40+" || echo "HT40-")
465 elif [ ${ch} -lt "84" ]; then
466 ch=$([ "${ch}" -lt "80" ] && echo "76" || echo "80")
467 bw_str=$([ "${ch}" -le "78" ] && echo "HT40+" || echo "HT40-")
468 elif [ ${ch} -lt "92" ]; then
469 ch=$([ "${ch}" -lt "88" ] && echo "84" || echo "88")
470 bw_str=$([ "${ch}" -le "86" ] && echo "HT40+" || echo "HT40-")
471 elif [ ${ch} -lt "100" ]; then
472 ch=$([ "${ch}" -lt "96" ] && echo "92" || echo "96")
473 bw_str=$([ "${ch}" -le "94" ] && echo "HT40+" || echo "HT40-")
474 elif [ ${ch} -lt "108" ]; then
475 ch=$([ "${ch}" -lt "104" ] && echo "100" || echo "104")
476 bw_str=$([ "${ch}" -le "102" ] && echo "HT40+" || echo "HT40-")
477 elif [ ${ch} -lt "116" ]; then
478 ch=$([ "${ch}" -lt "112" ] && echo "108" || echo "112")
479 bw_str=$([ "${ch}" -le "110" ] && echo "HT40+" || echo "HT40-")
480 elif [ ${ch} -lt "124" ]; then
481 ch=$([ "${ch}" -lt "120" ] && echo "116" || echo "120")
482 bw_str=$([ "${ch}" -le "118" ] && echo "HT40+" || echo "HT40-")
483 elif [ ${ch} -lt "132" ]; then
484 ch=$([ "${ch}" -lt "128" ] && echo "124" || echo "128")
485 bw_str=$([ "${ch}" -le "126" ] && echo "HT40+" || echo "HT40-")
486 elif [ ${ch} -lt "140" ]; then
487 ch=$([ "${ch}" -lt "136" ] && echo "132" || echo "136")
488 bw_str=$([ "${ch}" -le "134" ] && echo "HT40+" || echo "HT40-")
489 elif [ ${ch} -lt "149" ]; then
490 ch=$([ "${ch}" -lt "144" ] && echo "140" || echo "144")
491 bw_str=$([ "${ch}" -le "142" ] && echo "HT40+" || echo "HT40-")
492 elif [ ${ch} -lt "157" ]; then
493 ch=$([ "${ch}" -lt "153" ] && echo "149" || echo "153")
494 bw_str=$([ "${ch}" -le "151" ] && echo "HT40+" || echo "HT40-")
495 elif [ ${ch} -lt "165" ]; then
496 ch=$([ "${ch}" -lt "161" ] && echo "157" || echo "161")
497 bw_str=$([ "${ch}" -le "159" ] && echo "HT40+" || echo "HT40-")
498 elif [ ${ch} -lt "173" ]; then
499 ch=$([ "${ch}" -lt "169" ] && echo "165" || echo "169")
500 bw_str=$([ "${ch}" -le "167" ] && echo "HT40+" || echo "HT40-")
501 elif [ ${ch} -lt "181" ]; then
502 ch=$([ "${ch}" -lt "177" ] && echo "173" || echo "177")
503 bw_str=$([ "${ch}" -le "175" ] && echo "HT40+" || echo "HT40-")
504 fi
505 ;;
506 "0")
507 local bw_str="HT20"
508 ;;
509 esac
510 local base_freq=5180
511 local base_chan=36
512 else
developerbb6ddff2023-03-08 17:22:32 +0800513 local base_freq=5955
developerb9b4cd12022-10-11 13:18:59 +0800514 case ${bw} in
developerbb6ddff2023-03-08 17:22:32 +0800515 "12")
516 local bw_str="320"
517 if [ ${ch} == "31" ]; then
518 local control_freq="5955"
519 elif [ ${ch} == "63" ]; then
520 local control_freq="6115"
521 elif [ ${ch} == "95" ]; then
522 local control_freq="6275"
523 elif [ ${ch} == "127" ]; then
524 local control_freq="6435"
525 elif [ ${ch} == "159" ]; then
526 local control_freq="6595"
527 elif [ ${ch} == "191" ]; then
528 local control_freq="6755"
529 fi
530 local center_freq=$(((ch - base_chan) * 5 + base_freq))
531 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str} ${center_freq}"
532 return
533 ;;
developerb9b4cd12022-10-11 13:18:59 +0800534 "5")
535 bw_str="160MHz"
536 if [ ${ch} -lt "33" ]; then
537 ch="1"
538 elif [ ${ch} -lt "65" ]; then
539 ch="33"
540 elif [ ${ch} -lt "97" ]; then
541 ch="65"
542 elif [ ${ch} -lt "129" ]; then
543 ch="97"
544 elif [ ${ch} -lt "161" ]; then
545 ch="129"
546 elif [ ${ch} -lt "193" ]; then
547 ch="161"
548 elif [ ${ch} -lt "225" ]; then
549 ch="193"
550 fi
551 ;;
552 "2")
553 bw_str="80MHz"
554 if [ ${ch} -lt "17" ]; then
555 ch="1"
556 elif [ ${ch} -lt "33" ]; then
557 ch="17"
558 elif [ ${ch} -lt "49" ]; then
559 ch="33"
560 elif [ ${ch} -lt "65" ]; then
561 ch="49"
562 elif [ ${ch} -lt "81" ]; then
563 ch="65"
564 elif [ ${ch} -lt "97" ]; then
565 ch="81"
566 elif [ ${ch} -lt "113" ]; then
567 ch="97"
568 elif [ ${ch} -lt "129" ]; then
569 ch="113"
570 elif [ ${ch} -lt "145" ]; then
571 ch="129"
572 elif [ ${ch} -lt "161" ]; then
573 ch="145"
574 elif [ ${ch} -lt "177" ]; then
575 ch="161"
576 elif [ ${ch} -lt "193" ]; then
577 ch="177"
578 elif [ ${ch} -lt "209" ]; then
579 ch="193"
580 elif [ ${ch} -lt "225" ]; then
581 ch="209"
582 fi
583 ;;
584 "1")
585 if [ ${ch} -lt "9" ]; then
586 ch=$([ "${ch}" -lt "5" ] && echo "1" || echo "5")
587 bw_str=$([ "${ch}" -le "3" ] && echo "HT40+" || echo "HT40-")
588 elif [ ${ch} -lt "17" ]; then
589 ch=$([ "${ch}" -lt "13" ] && echo "9" || echo "13")
590 bw_str=$([ "${ch}" -le "11" ] && echo "HT40+" || echo "HT40-")
591 elif [ ${ch} -lt "25" ]; then
592 ch=$([ "${ch}" -lt "21" ] && echo "17" || echo "21")
593 bw_str=$([ "${ch}" -le "19" ] && echo "HT40+" || echo "HT40-")
594 elif [ ${ch} -lt "33" ]; then
595 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
596 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
597 elif [ ${ch} -lt "33" ]; then
598 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
599 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
600 elif [ ${ch} -lt "41" ]; then
601 ch=$([ "${ch}" -lt "37" ] && echo "33" || echo "37")
602 bw_str=$([ "${ch}" -le "35" ] && echo "HT40+" || echo "HT40-")
603 elif [ ${ch} -lt "49" ]; then
604 ch=$([ "${ch}" -lt "45" ] && echo "41" || echo "45")
605 bw_str=$([ "${ch}" -le "43" ] && echo "HT40+" || echo "HT40-")
606 elif [ ${ch} -lt "57" ]; then
607 ch=$([ "${ch}" -lt "53" ] && echo "49" || echo "53")
608 bw_str=$([ "${ch}" -le "51" ] && echo "HT40+" || echo "HT40-")
609 elif [ ${ch} -lt "65" ]; then
610 ch=$([ "${ch}" -lt "61" ] && echo "57" || echo "61")
611 bw_str=$([ "${ch}" -le "59" ] && echo "HT40+" || echo "HT40-")
612 elif [ ${ch} -lt "73" ]; then
613 ch=$([ "${ch}" -lt "69" ] && echo "65" || echo "69")
614 bw_str=$([ "${ch}" -le "67" ] && echo "HT40+" || echo "HT40-")
615 elif [ ${ch} -lt "81" ]; then
616 ch=$([ "${ch}" -lt "77" ] && echo "73" || echo "77")
617 bw_str=$([ "${ch}" -le "75" ] && echo "HT40+" || echo "HT40-")
618 elif [ ${ch} -lt "89" ]; then
619 ch=$([ "${ch}" -lt "85" ] && echo "81" || echo "85")
620 bw_str=$([ "${ch}" -le "83" ] && echo "HT40+" || echo "HT40-")
621 elif [ ${ch} -lt "97" ]; then
622 ch=$([ "${ch}" -lt "93" ] && echo "89" || echo "93")
623 bw_str=$([ "${ch}" -le "91" ] && echo "HT40+" || echo "HT40-")
624 elif [ ${ch} -lt "105" ]; then
625 ch=$([ "${ch}" -lt "101" ] && echo "97" || echo "101")
626 bw_str=$([ "${ch}" -le "99" ] && echo "HT40+" || echo "HT40-")
627 elif [ ${ch} -lt "113" ]; then
628 ch=$([ "${ch}" -lt "109" ] && echo "105" || echo "109")
629 bw_str=$([ "${ch}" -le "107" ] && echo "HT40+" || echo "HT40-")
630 elif [ ${ch} -lt "121" ]; then
631 ch=$([ "${ch}" -lt "117" ] && echo "113" || echo "117")
632 bw_str=$([ "${ch}" -le "115" ] && echo "HT40+" || echo "HT40-")
633 elif [ ${ch} -lt "129" ]; then
634 ch=$([ "${ch}" -lt "125" ] && echo "121" || echo "125")
635 bw_str=$([ "${ch}" -le "123" ] && echo "HT40+" || echo "HT40-")
636 elif [ ${ch} -lt "137" ]; then
637 ch=$([ "${ch}" -lt "133" ] && echo "129" || echo "133")
638 bw_str=$([ "${ch}" -le "131" ] && echo "HT40+" || echo "HT40-")
639 elif [ ${ch} -lt "145" ]; then
640 ch=$([ "${ch}" -lt "141" ] && echo "137" || echo "141")
641 bw_str=$([ "${ch}" -le "139" ] && echo "HT40+" || echo "HT40-")
642 elif [ ${ch} -lt "153" ]; then
643 ch=$([ "${ch}" -lt "149" ] && echo "145" || echo "149")
644 bw_str=$([ "${ch}" -le "147" ] && echo "HT40+" || echo "HT40-")
645 elif [ ${ch} -lt "161" ]; then
646 ch=$([ "${ch}" -lt "157" ] && echo "153" || echo "157")
647 bw_str=$([ "${ch}" -le "155" ] && echo "HT40+" || echo "HT40-")
648 elif [ ${ch} -lt "169" ]; then
649 ch=$([ "${ch}" -lt "165" ] && echo "161" || echo "165")
650 bw_str=$([ "${ch}" -le "163" ] && echo "HT40+" || echo "HT40-")
651 elif [ ${ch} -lt "177" ]; then
652 ch=$([ "${ch}" -lt "173" ] && echo "169" || echo "173")
653 bw_str=$([ "${ch}" -le "171" ] && echo "HT40+" || echo "HT40-")
654 elif [ ${ch} -lt "185" ]; then
655 ch=$([ "${ch}" -lt "181" ] && echo "177" || echo "181")
656 bw_str=$([ "${ch}" -le "179" ] && echo "HT40+" || echo "HT40-")
657 elif [ ${ch} -lt "193" ]; then
658 ch=$([ "${ch}" -lt "189" ] && echo "185" || echo "189")
659 bw_str=$([ "${ch}" -le "187" ] && echo "HT40+" || echo "HT40-")
660 elif [ ${ch} -lt "201" ]; then
661 ch=$([ "${ch}" -lt "197" ] && echo "193" || echo "197")
662 bw_str=$([ "${ch}" -le "195" ] && echo "HT40+" || echo "HT40-")
663 elif [ ${ch} -lt "209" ]; then
664 ch=$([ "${ch}" -lt "205" ] && echo "201" || echo "205")
665 bw_str=$([ "${ch}" -le "203" ] && echo "HT40+" || echo "HT40-")
666 elif [ ${ch} -lt "217" ]; then
667 ch=$([ "${ch}" -lt "213" ] && echo "209" || echo "213")
668 bw_str=$([ "${ch}" -le "211" ] && echo "HT40+" || echo "HT40-")
669 elif [ ${ch} -lt "225" ]; then
670 ch=$([ "${ch}" -lt "221" ] && echo "217" || echo "221")
671 bw_str=$([ "${ch}" -le "219" ] && echo "HT40+" || echo "HT40-")
672 elif [ ${ch} -lt "233" ]; then
673 ch=$([ "${ch}" -lt "229" ] && echo "225" || echo "229")
674 bw_str=$([ "${ch}" -le "227" ] && echo "HT40+" || echo "HT40-")
675 fi
676 ;;
677 "0")
678 local bw_str="HT20"
679 ;;
680 esac
developerb9b4cd12022-10-11 13:18:59 +0800681 fi
682
683 local control_freq=$(((ch - base_chan) * 5 + base_freq))
684 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
685}
686
687function convert_rxstat {
688 local res=$(do_cmd "mt76-test ${interface} dump stats")
689 local mdrdy=$(echo "${res}" | grep "rx_packets" | cut -d "=" -f 2)
690 local fcs_error=$(echo "${res}" | grep "rx_fcs_error" | cut -d "=" -f 2)
691 local rcpi=$(echo "${res}" | grep "last_rcpi" | cut -d "=" -f 2 | sed 's/,/ /g')
692 local ib_rssi=$(echo "${res}" | grep "last_ib_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
693 local wb_rssi=$(echo "${res}" | grep "last_wb_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
694 local rx_ok=$(expr ${mdrdy} - ${fcs_error})
695
696 write_dmesg "rcpi: ${rcpi}"
697 write_dmesg "fagc rssi ib: ${ib_rssi}"
698 write_dmesg "fagc rssi wb: ${wb_rssi}"
699 write_dmesg "all_mac_rx_mdrdy_cnt: ${mdrdy}"
700 write_dmesg "all_mac_rx_fcs_err_cnt: ${fcs_error}"
701 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
702}
703
704function set_mac_addr {
705 record_config ${cmd} ${param} ${iwpriv_file}
706
707 local addr1=$(get_config "ATEDA" ${iwpriv_file})
708 local addr2=$(get_config "ATESA" ${iwpriv_file})
709 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
710
711 if [ -z "${addr1}" ]; then
712 addr1="00:11:22:33:44:55"
713 fi
714 if [ -z "${addr2}" ]; then
715 addr2="00:11:22:33:44:55"
716 fi
717 if [ -z "${addr3}" ]; then
718 addr3="00:11:22:33:44:55"
719 fi
720
721 do_cmd "mt76-test phy${phy_idx} set mac_addrs=${addr1},${addr2},${addr3}"
722}
723
724function convert_ibf {
725 local cmd=$1
726 local param=$2
727 local new_cmd=""
728 local new_param=$(echo ${param} | sed s/":"/","/g)
729
730 case ${cmd} in
731 "ATETxBfInit")
732 new_cmd="init"
developerc5ce7502022-12-19 11:33:22 +0800733 new_param="1"
734 do_cmd "mt76-test phy${phy_idx} set state=idle"
735 ;;
736 "ATETxBfGdInit")
737 new_cmd="golden_init"
738 new_param="1"
developerb9b4cd12022-10-11 13:18:59 +0800739 do_cmd "mt76-test phy${phy_idx} set state=idle"
740 ;;
741 "ATEIBFPhaseComp")
742 new_cmd="phase_comp"
developerc5ce7502022-12-19 11:33:22 +0800743 new_param="${new_param}"
developerb9b4cd12022-10-11 13:18:59 +0800744 ;;
745 "ATEEBfProfileConfig")
746 new_cmd="ebf_prof_update"
747 ;;
748 "ATEIBfProfileConfig")
749 new_cmd="ibf_prof_update"
750 ;;
751 "ATEIBfInstCal")
752 new_cmd="phase_cal"
753 ;;
754 "ATEIBfGdCal")
755 new_cmd="phase_cal"
756 new_param="${new_param},00"
757 ;;
758 "TxBfTxApply")
759 new_cmd="apply_tx"
760 ;;
761 "ATETxPacketWithBf")
762 local bf_on=${new_param:0:2}
763 local aid="01"
764 local wlan_idx=${new_param:3:2}
765 local update="00"
766 local tx_len=${new_param:6}
767
768 new_cmd="tx_prep"
769 new_param="${bf_on},${aid},${wlan_idx},${update}"
770 if [ "${tx_len}" = "00" ]; then
771 new_param="${new_param} aid=1 tx_count=10000000 tx_length=1024"
772 else
773 new_param="${new_param} aid=1 tx_count=${tx_len} tx_length=1024"
774 fi
775 do_cmd "mt76-test phy${phy_idx} set state=idle"
776 ;;
777 "TxBfProfileData20MAllWrite")
778 new_cmd="prof_update_all"
779 ;;
780 "ATEIBFPhaseE2pUpdate")
781 new_cmd="e2p_update"
782 ;;
developerc5ce7502022-12-19 11:33:22 +0800783 "ATEIBFPhaseVerify")
784 local group=${new_param:0:2}
785 local group_l_m_h=${new_param:3:2}
786 local band_idx=${new_param:6:2}
787 local phase_cal_type=${new_param:9:2}
788 local LNA_gain_level=${new_param:12:2}
789 local read_from_e2p=${new_param:15:2}
790
791 do_cmd "mt76-test phy${phy_idx} set txbf_act=phase_comp txbf_param=1,${band_idx},${group},${read_from_e2p},0"
792 new_cmd="phase_cal"
793 new_param="${group},${group_l_m_h},${band_idx},${phase_cal_type},${LNA_gain_level}"
794 ;;
795 "TxBfProfileTagRead")
796 new_cmd="pfmu_tag_read"
797 ;;
798 "TxBfProfileTagWrite")
799 new_cmd="pfmu_tag_write"
800 ;;
801 "TxBfProfileTagInValid")
802 new_cmd="set_invalid_prof"
803 ;;
804 "StaRecBfRead")
805 new_cmd="sta_rec_read"
806 ;;
807 "TriggerSounding")
808 new_cmd="trigger_sounding"
809 ;;
810 "StopSounding")
811 new_cmd="stop_sounding"
812 new_param="0"
813 ;;
developer7af0f762023-05-22 15:16:16 +0800814 "TxBfTxCmd")
815 new_cmd="txcmd"
816 ;;
developerc5ce7502022-12-19 11:33:22 +0800817 "ATEConTxETxBfGdProc")
818 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
819 local tx_rate_idx=${new_param:3:2}
820 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
821 local channel=${new_param:9:3}
822 local channel2=${new_param:13:3}
823 local band=${new_param:17}
824
825 new_cmd="ebf_golden_init"
826 do_ate_work "ATESTART"
827 do_cmd "mt76-test phy${phy_idx} set state=idle"
828 record_config "ATETXBW" ${bw} ${iwpriv_file}
829 convert_channel "${channel}:${band}"
830 if [ "${bw}" = "5" ]; then
831 new_param="1,1"
832 else
833 new_param="1,0"
834 fi
835 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_sgi=0"
836 ;;
837 "ATEConTxETxBfInitProc")
838 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
839 local tx_rate_idx=${new_param:3:2}
840 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
841 local tx_rate_nss=${new_param:9:2}
842 local tx_stream=${new_param:12:2}
843 local tx_power=${new_param:15:2}
developer7af0f762023-05-22 15:16:16 +0800844 local channel=$(echo ${new_param:18:3} | sed 's/^0//')
developerc5ce7502022-12-19 11:33:22 +0800845 local channel2=${new_param:22:3}
846 local band=${new_param:26:1}
developer7af0f762023-05-22 15:16:16 +0800847 local tx_length=$(echo ${new_param:28:5} | sed 's/^0//')
developerc5ce7502022-12-19 11:33:22 +0800848
849 new_cmd="ebf_init"
850 do_ate_work "ATESTART"
851 do_cmd "mt76-test phy${phy_idx} set state=idle"
852 record_config "ATETXBW" ${bw} ${iwpriv_file}
853 convert_channel "${channel}:${band}"
854 new_param="1"
855 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"
856 ;;
developerb9b4cd12022-10-11 13:18:59 +0800857 *)
858 esac
859
860 do_cmd "mt76-test phy${phy_idx} set txbf_act=${new_cmd} txbf_param=${new_param}"
861
862 if [ "${cmd}" = "ATETxPacketWithBf" ]; then
863 do_cmd "mt76-test phy${phy_idx} set state=tx_frames"
developerc5ce7502022-12-19 11:33:22 +0800864 elif [ "${cmd}" = "ATEConTxETxBfInitProc" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800865 local wlan_idx="1"
developerc8796032023-08-09 10:28:15 +0800866 if [ ${is_connac3} == "1" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800867 local wlan_idx=$((phy_idx+1))
868 fi
developerc5ce7502022-12-19 11:33:22 +0800869 do_cmd "mt76-test phy${phy_idx} set aid=1"
870 do_cmd "mt76-test phy${phy_idx} set txbf_act=stop_sounding txbf_param=1"
871 do_cmd "mt76-test phy${phy_idx} set txbf_act=update_ch txbf_param=1"
872 do_cmd "mt76-test phy${phy_idx} set txbf_act=ebf_prof_update txbf_param=0,0,0"
developerbb6ddff2023-03-08 17:22:32 +0800873 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 +0800874 if [ ${is_connac3} == "1" ]; then
developerbb6ddff2023-03-08 17:22:32 +0800875 do_cmd "mt76-test phy${phy_idx} set txbf_act=txcmd txbf_param=1,1,1"
876 fi
developerc5ce7502022-12-19 11:33:22 +0800877 do_cmd "mt76-test phy${phy_idx} set txbf_act=pfmu_tag_read txbf_param=0,1"
developerbb6ddff2023-03-08 17:22:32 +0800878 do_cmd "mt76-test phy${phy_idx} set txbf_act=sta_rec_read txbf_param=${wlan_idx}"
879 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=0,1,0,${wlan_idx},0,0,0"
880 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 +0800881 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
882 elif [ "${cmd}" = "ATEConTxETxBfGdProc" ]; then
883 do_cmd "mt76-test phy${phy_idx} set aid=1"
884 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
885 elif [ "${cmd}" = "ATETxBfInit" ]; then
886 do_cmd "mt76-test phy${phy_idx} set aid=1"
887 elif [ "${cmd}" = "ATETxBfGdInit" ]; then
888 do_cmd "mt76-test phy${phy_idx} set aid=1"
developerf9b00212023-07-31 12:27:06 +0800889 elif [ "${cmd}" = "ATEIBFPhaseE2pUpdate" ]; then
890 do_cmd "atenl -i phy${phy_idx} -c \"eeprom ibf sync\""
developerb9b4cd12022-10-11 13:18:59 +0800891 fi
892}
893
developer9a587882023-07-17 11:11:44 +0800894function convert_ruinfo {
895 local new_param=$1
896
897 do_cmd "mt76-test phy${phy_idx} set state=idle"
898 while [ -n "$new_param" ]
899 do
900 [ ${new_param:1:1} = ':' ] && {
901 new_param=${new_param:2}
902 }
903 local oIFS="$IFS"; IFS=":"; set -- $new_param; IFS="$oIFS"
904
905 parsing_ruinfo $new_param
906 new_param=${new_param:${#1}+1}
907 done
908}
909
910function parsing_ruinfo {
911 local new_param=$1
912 local oIFS="$IFS"; IFS="-:"; set -- $new_param; IFS="$oIFS"
913
914 # $7 is Start spatial stream and it should be 0, $9 is alpha, not used
915 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\
916 tx_rate_idx=$4 tx_rate_ldpc=$5 tx_rate_nss=$6 tx_length=$8"
917}
918
developerb403ad02022-11-08 10:16:29 +0800919function convert_dfs {
920 local cmd=$1
921 local param=$2
922
923 case ${cmd} in
924 "DfsRxCtrl")
925 local offchan_ch="$(echo $param | cut -d ':' -f1)"
926 local offchan_bw="$(echo $param | cut -d ':' -f2)"
927
developerc9333e12023-04-06 18:07:42 +0800928 if [ "$offchan_bw" = "0" ]; then
929 offchan_bw="20"
930 elif [ "$offchan_bw" = "1" ]; then
931 offchan_bw="40"
932 elif [ "$offchan_bw" = "2" ]; then
933 offchan_bw="80"
934 elif [ "$offchan_bw" = "3" ]; then
935 offchan_bw="160"
936 fi
developerb403ad02022-11-08 10:16:29 +0800937
developerc9333e12023-04-06 18:07:42 +0800938 do_cmd "mt76-test phy${phy_idx} set state=idle"
939 do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
developerb403ad02022-11-08 10:16:29 +0800940 ;;
941 "DfsRxHist")
942 local ipi_th="$(echo $param | cut -d ':' -f 1)"
943 local ipi_period="$(echo $param | cut -d ':' -f 2)"
developerc9333e12023-04-06 18:07:42 +0800944 local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
developerb403ad02022-11-08 10:16:29 +0800945
developerc9333e12023-04-06 18:07:42 +0800946 if [ -z $ipi_antenna ]; then
947 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
948 else
949 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
950 fi
developerb403ad02022-11-08 10:16:29 +0800951 ;;
952 *)
953 esac
954}
955
developerb9b4cd12022-10-11 13:18:59 +0800956function do_ate_work() {
957 local ate_cmd=$1
958
959 case ${ate_cmd} in
960 "ATESTART")
961 local if_str=$(ifconfig | grep mon${phy_idx})
962
963 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
964 echo "ATE already starts."
965 else
966 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
developer3f784572023-01-31 15:21:28 +0800967
968 if [ $phy_idx -ge $SOC_start_idx ]; then
969 local end_idx=$SOC_end_idx
970 local start_idx=$SOC_start_idx
971 else
972 local end_idx=$((SOC_start_idx-1))
973 local start_idx="0"
974 fi
975
976 for phy_index in $( seq $start_idx $end_idx )
977 do
978 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
979 local prev_phy_index=$((phy_index-1))
980 local if_num=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep -c Interface)
981 local j="1"
982 # avoid del_if_count reset to 0 when start ate on another band in dbdc case
983 local del_if_count=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
984 if [ -z "${del_if_count}" ]; then
985 local del_if_count="0"
986 fi
987
988 for if_count in $( seq 1 $if_num )
989 do
990 local del_if=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep Interface | sed -n ${j}p | cut -d " " -f 2)
991 if [ ! -z "${del_if}" ] && [[ "$del_if" != *"mon"* ]]; then
992 do_cmd "iw dev ${del_if} del"
993 del_if_count=$((del_if_count+1))
994 # handle the case of multiple interface in a phy
995 record_config "DEL_IF${phy_index}-${del_if_count}" ${del_if} ${interface_file}
996 else
997 # j add 1 to skip mon interface
998 j=$((j+1))
999 fi
1000 done
1001 record_config "DEL_IF${phy_index}_NUM" ${del_if_count} ${interface_file}
1002 done
1003
developerb9b4cd12022-10-11 13:18:59 +08001004 do_cmd "ifconfig mon${phy_idx} up"
1005 do_cmd "iw reg set VV"
1006 fi
1007 ;;
1008 "ATESTOP")
1009 local if_str=$(ifconfig | grep mon${phy_idx})
1010
1011 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
1012 echo "ATE does not start."
1013 else
1014 do_cmd "mt76-test ${interface} set state=off"
1015 do_cmd "iw dev mon${phy_idx} del"
developer3f784572023-01-31 15:21:28 +08001016
1017 if [ $phy_idx -ge $SOC_start_idx ]; then
1018 local end_idx=$SOC_end_idx
1019 local start_idx=$SOC_start_idx
1020 else
1021 local end_idx=$((SOC_start_idx-1))
1022 local start_idx="0"
1023 fi
1024
1025 # first check its phy and dbdc band phy has monitor interface or not
1026 # if has at lease one mon interface, then skip adding back normal interface
1027 local has_mon="0"
1028 for phy_index in $( seq $start_idx $end_idx )
1029 do
1030 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
1031 local prev_phy_index=$((phy_index-1))
1032 local has_mon_phy=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep "Interface mon")
1033 # if this phy interface has mon interface
1034 if [ ! -z "${has_mon_phy}" ]; then
1035 local has_mon="1"
1036 fi
1037 done
1038
1039 for phy_index in $( seq $start_idx $end_idx )
1040 do
1041 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
1042 local prev_phy_index=$((phy_index-1))
1043 local j="1"
1044 local add_if_num=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
1045 if [ -z "${add_if_num}" ]; then
1046 local add_if_num="0"
1047 fi
1048 # if this phy interface (including its dbdc phy) has no mon interface and can find deleted interface in file, then add it back
1049 if [ "${has_mon}" == "0" ] && [ $add_if_num -ge "1" ]; then
1050 local if_index=$add_if_num
1051 # add interface backwards
1052 while [ $if_index -gt "0" ]
1053 do
1054 local add_if=$(get_config "DEL_IF${phy_index}-${if_index}" ${interface_file})
1055 do_cmd "iw phy phy${phy_index} interface add ${add_if} type managed"
1056 # remove the deleted interface in interface_file since it is added back
1057 sed -i "/DEL_IF${phy_index}-${if_index}=/d" ${interface_file}
1058 if_index=$((if_index-1))
1059 done
1060 # remove the number of deleted interface in interface_file since it is all added back
1061 sed -i "/DEL_IF${phy_index}_NUM=/d" ${interface_file}
1062 fi
1063 done
1064
developerb9b4cd12022-10-11 13:18:59 +08001065 do_cmd "mt76-test ${interface} set aid=0"
1066 fi
1067
developer13655da2023-01-10 19:53:25 +08001068 if [ ${phy_idx} -lt ${SOC_start_idx} ]; then
developerb9b4cd12022-10-11 13:18:59 +08001069 sed -i '/_PCIE=/d' ${iwpriv_file}
developer13655da2023-01-10 19:53:25 +08001070 elif [ ${phy_idx} -ge ${SOC_start_idx} ]; then
1071 sed -i '/_SOC=/d' ${iwpriv_file}
developerb9b4cd12022-10-11 13:18:59 +08001072 fi
1073 ;;
1074 "TXCOMMIT")
1075 do_cmd "mt76-test ${interface} set aid=1"
1076 ;;
1077 "TXFRAME")
1078 do_cmd "mt76-test ${interface} set state=tx_frames"
1079 ;;
1080 "TXSTOP"|"RXSTOP")
1081 do_cmd "mt76-test ${interface} set state=idle"
1082 ;;
1083 "TXREVERT")
1084 do_cmd "mt76-test ${interface} set aid=0"
1085 ;;
1086 "RXFRAME")
1087 do_cmd "mt76-test ${interface} set state=rx_frames"
1088 ;;
1089 "TXCONT")
1090 do_cmd "mt76-test ${interface} set state=tx_cont"
1091 ;;
1092 "GROUPREK")
1093 do_cmd "mt76-test ${interface} set state=group_prek"
1094 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
1095 ;;
1096 "GROUPREKDump")
1097 do_cmd "mt76-test ${interface} set state=group_prek_dump"
1098 ;;
1099 "GROUPREKClean")
1100 do_cmd "mt76-test ${interface} set state=group_prek_clean"
1101 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
1102 ;;
1103 "DPD2G")
1104 do_cmd "mt76-test ${interface} set state=dpd_2g"
1105 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
1106 ;;
1107 "DPD5G")
1108 do_cmd "mt76-test ${interface} set state=dpd_5g"
1109 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
1110 ;;
1111 "DPD6G")
1112 do_cmd "mt76-test ${interface} set state=dpd_6g"
1113 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
1114 ;;
1115 "DPDDump")
1116 do_cmd "mt76-test ${interface} set state=dpd_dump"
1117 ;;
1118 "DPDClean")
1119 do_cmd "mt76-test ${interface} set state=dpd_clean"
1120 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
1121 ;;
1122 *)
1123 print_debug "skip ${ate_cmd}"
1124 ;;
1125 esac
1126}
1127
developer13655da2023-01-10 19:53:25 +08001128function dump_usage {
1129 echo "Usage:"
1130 echo " mwctl <interface> set csi ctrl=<opt1>,<opt2>,<opt3>,<opt4> (macaddr=<macaddr>)"
1131 echo " mwctl <interface> set csi interval=<interval (us)>"
1132 echo " mwctl <interface> dump csi <packet num> <filename>"
1133 echo " mwctl <interface> set amnt <index>(0x0~0xf) <mac addr>(xx:xx:xx:xx:xx:xx)"
1134 echo " mwctl <interface> dump amnt <index> (0x0~0xf or 0xff)"
1135 echo " mwctl <interface> set ap_rfeatures he_gi=<val>"
1136 echo " mwctl <interface> set ap_rfeatures he_ltf=<val>"
1137 echo " mwctl <interface> set ap_rfeatures trig_type=<enable>,<val> (val: 0-7)"
1138 echo " mwctl <interface> set ap_rfeatures ack_policy=<val> (val: 0-4)"
1139 echo " mwctl <interface> set ap_wireless fixed_mcs=<val>"
1140 echo " mwctl <interface> set ap_wireless ofdma=<val> (0: disable, 1: DL, 2: UL)"
1141 echo " mwctl <interface> set ap_wireless nusers_ofdma=<val>"
1142 echo " mwctl <interface> set ap_wireless ppdu_type=<val> (0: SU, 1: MU, 4: LEGACY)"
1143 echo " mwctl <interface> set ap_wireless add_ba_req_bufsize=<val>"
1144 echo " mwctl <interface> set ap_wireless mimo=<val> (0: DL, 1: UL)"
1145 echo " mwctl <interface> set ap_wireless ampdu=<enable>"
1146 echo " mwctl <interface> set ap_wireless amsdu=<enable>"
1147 echo " mwctl <interface> set ap_wireless cert=<enable>"
developer2c78ce72023-02-24 11:26:12 +08001148 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 +08001149 echo " mwctl <interface> dump phy_capa"
1150}
1151
developer092b55c2023-01-18 18:20:58 +08001152function register_handler {
1153
1154 local phy_idx=$1
1155 local offset=$2
1156 local val=$3
1157 local cmd=$4
1158 local w_cmd="write"
1159
1160 regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
1161 regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
1162
1163 echo ${offset} > ${regidx}
1164 if [[ "${cmd}" == "${w_cmd}" ]]; then
1165 echo ${val} > ${regval}
1166 fi
1167
1168 res=$(cat ${regval} | cut -d 'x' -f 2)
1169 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
1170}
1171
developerb9b4cd12022-10-11 13:18:59 +08001172# main start here
developer3f784572023-01-31 15:21:28 +08001173parse_sku
developer13655da2023-01-10 19:53:25 +08001174if [ -z ${interface} ]; then
1175 dump_usage
1176 exit
1177elif [[ ${interface} == "ra"* ]]; then
developerb9b4cd12022-10-11 13:18:59 +08001178 convert_interface $interface
developerbb6ddff2023-03-08 17:22:32 +08001179elif [[ ${interface} == "phy" ]]; then
1180 # handle mwctl phy phy0 e2p ... case
1181 interface=$2
1182 cmd_type=$3
1183 full_cmd=$4
developerb9b4cd12022-10-11 13:18:59 +08001184fi
1185
1186tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
1187
1188if [ ! -z ${tmp_work_mode} ]; then
1189 work_mode=${tmp_work_mode}
1190fi
1191
1192cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
1193param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
1194
1195if [ "${cmd_type}" = "set" ]; then
1196 skip=0
1197 case ${cmd} in
developer13655da2023-01-10 19:53:25 +08001198 ## In wifi 7 chipset, testmode & vendor command both use mwctl
1199 ## Therefore this wrapper would translate it to either mt76-test or mt76-vendor based on the attribute of the command
1200 ## Translate to mt76-vendor command
developer327aa322023-07-10 13:49:56 +08001201 "csi"|"amnt"|"ap_rfeatures"|"ap_wireless"|"mu"|"set_muru_manual_config")
developerc8796032023-08-09 10:28:15 +08001202 if [ ${is_connac3} == "1" ]; then
developer1475cf22023-05-05 13:45:43 +08001203 hostapd_cmd="$(echo $* | sed 's/set/raw/')"
1204 do_cmd "hostapd_cli -i $hostapd_cmd"
developerbb6ddff2023-03-08 17:22:32 +08001205 else
developer88605f72023-02-15 16:38:49 +08001206 do_cmd "mt76-vendor $*"
developerbb6ddff2023-03-08 17:22:32 +08001207 fi
1208 skip=1
developer13655da2023-01-10 19:53:25 +08001209 ;;
developerb9b4cd12022-10-11 13:18:59 +08001210 "ATE")
1211 do_ate_work ${param}
1212
1213 skip=1
1214 ;;
1215 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
1216 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
1217 cmd_new=$(simple_convert ${cmd})
1218 if [ "${param_new}" = "undefined" ]; then
1219 echo "unknown cmd: ${cmd}"
1220 exit
1221 fi
1222 param_new=${param}
developerc5ce7502022-12-19 11:33:22 +08001223 if [ "${cmd}" = "ATETXCNT" ] && [ "${param}" = "0" ]; then
developer15c355d2023-03-21 17:28:34 +08001224 param_new="0xFFFFFFFF"
developerc5ce7502022-12-19 11:33:22 +08001225 fi
developerb9b4cd12022-10-11 13:18:59 +08001226 ;;
1227 "ATETXANT"|"ATERXANT")
1228 cmd_new="tx_antenna"
1229 param_new=${param}
1230 ;;
1231 "ATETXGI")
developerc8796032023-08-09 10:28:15 +08001232 if [ ${is_connac3} == "0" ]; then
developerbb6ddff2023-03-08 17:22:32 +08001233 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
1234 convert_gi ${tx_mode} ${param}
1235 skip=1
1236 else
1237 cmd_new="tx_rate_sgi"
1238 param_new=${param}
1239 fi
developerb9b4cd12022-10-11 13:18:59 +08001240 ;;
1241 "ATETXMODE")
1242 cmd_new="tx_rate_mode"
1243 param_new=$(convert_tx_mode ${param})
1244 if [ "${param_new}" = "undefined" ]; then
1245 echo "unknown tx mode"
1246 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
1247 exit
1248 else
1249 record_config ${cmd} ${param} ${iwpriv_file}
1250 fi
1251 ;;
developerbb6ddff2023-03-08 17:22:32 +08001252 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3"|"ATETXPOW")
developerb9b4cd12022-10-11 13:18:59 +08001253 cmd_new="tx_power"
developerbb6ddff2023-03-08 17:22:32 +08001254 if [ "${param}" == "127" ]; then
1255 # for iTest verification
1256 exit
1257 fi
developerb9b4cd12022-10-11 13:18:59 +08001258 param_new="${param},0,0,0"
1259 ;;
developerbb6ddff2023-03-08 17:22:32 +08001260 "ATEMUAID")
1261 cmd_new="aid"
1262 param_new=${param}
1263 ;;
developerb9b4cd12022-10-11 13:18:59 +08001264 "ATETXBW")
1265 record_config ${cmd} ${param} ${iwpriv_file}
1266 skip=1
1267 ;;
1268 "ATECHANNEL")
1269 convert_channel ${param}
1270 skip=1
1271 ;;
1272 "ATERXSTAT")
1273 convert_rxstat
1274 skip=1
1275 ;;
1276 "ATECTRLBANDIDX")
1277 change_band_idx ${param}
1278 skip=1
1279 ;;
1280 "ATEDA"|"ATESA"|"ATEBSSID")
1281 set_mac_addr ${cmd} ${param}
1282 skip=1
1283 ;;
developerb403ad02022-11-08 10:16:29 +08001284 "DfsRxCtrl"|"DfsRxHist")
1285 convert_dfs ${cmd} ${param}
1286 skip=1
1287 ;;
developerc5ce7502022-12-19 11:33:22 +08001288 "ATETxBfInit"|"ATETxBfGdInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
1289 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"| \
developer7af0f762023-05-22 15:16:16 +08001290 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate"|"TriggerSounding"|"StopSounding"|"TxBfTxCmd"| \
developerc5ce7502022-12-19 11:33:22 +08001291 "StaRecBfRead"|"TxBfProfileTagInValid"|"TxBfProfileTagWrite"|"TxBfProfileTagRead"| \
1292 "ATEIBFPhaseVerify"|"ATEConTxETxBfGdProc"|"ATEConTxETxBfInitProc")
developerb9b4cd12022-10-11 13:18:59 +08001293 convert_ibf ${cmd} ${param}
1294 skip=1
1295 ;;
1296 "bufferMode")
1297 if [ "${param}" = "2" ]; then
1298 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
1299 fi
1300 skip=1
1301 ;;
1302 "ResetCounter"|"ATERXSTATRESET")
1303 skip=1
1304 ;;
1305 "WORKMODE")
1306 record_config "WORKMODE" ${param} ${iwpriv_file}
1307 echo "Entering ${param} mode in iwpriv"
1308 skip=1
1309 ;;
developer9a587882023-07-17 11:11:44 +08001310 "ATERUINFO")
1311 convert_ruinfo ${param}
1312 skip=1
1313 ;;
developerb9b4cd12022-10-11 13:18:59 +08001314 *)
1315 print_debug "Unknown command to set: ${cmd}"
1316 skip=1
1317 esac
1318
1319 if [ "${skip}" != "1" ]; then
1320 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
1321 fi
1322
1323elif [ "${cmd_type}" = "show" ]; then
developerc5ce7502022-12-19 11:33:22 +08001324 if [ "${cmd}" = "wtbl" ]; then
1325 wlan_idx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wlan_idx
1326 wtbl_info=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wtbl_info
1327
1328 do_cmd "echo ${param} > ${wlan_idx}"
1329 do_cmd "cat ${wtbl_info}"
developerbb6ddff2023-03-08 17:22:32 +08001330 elif [ "${cmd}" = "ATERXSTAT" ]; then
1331 convert_rxstat
developerc5ce7502022-12-19 11:33:22 +08001332 else
1333 do_cmd "mt76-test ${interface} dump"
1334 do_cmd "mt76-test ${interface} dump stats"
1335 fi
developerb9b4cd12022-10-11 13:18:59 +08001336
1337elif [ "${cmd_type}" = "e2p" ]; then
developer13655da2023-01-10 19:53:25 +08001338 # support multiple read write
developerb9b4cd12022-10-11 13:18:59 +08001339 # eeprom offset write
1340 if [[ ${full_cmd} == *"="* ]]; then
developer13655da2023-01-10 19:53:25 +08001341 IFS=,
1342 for tuple in $full_cmd
1343 do
1344 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1345 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1346 offset=$(printf "0x%s" ${cmd})
1347 val=$(printf "0x%s" ${param})
1348 tmp=$((${val} & 0xff))
1349 tmp=$(printf "0x%x" ${tmp})
1350 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developerb9b4cd12022-10-11 13:18:59 +08001351
developer13655da2023-01-10 19:53:25 +08001352 offset=$((${offset}))
1353 offset=$(expr ${offset} + "1")
1354 offset=$(printf "0x%x" ${offset})
1355 tmp=$(((${val} >> 8) & 0xff))
1356 tmp=$(printf "0x%x" ${tmp})
1357 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
1358 done
developerb9b4cd12022-10-11 13:18:59 +08001359 else
developer13655da2023-01-10 19:53:25 +08001360 IFS=,
1361 for tuple in $full_cmd
1362 do
1363 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1364 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1365 offset=$(printf "0x%s" ${cmd})
1366 val=$(printf "0x%s" ${param})
1367 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
1368 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developerb9b4cd12022-10-11 13:18:59 +08001369
developer13655da2023-01-10 19:53:25 +08001370 tmp=$(printf "0x%s" ${param})
1371 tmp=$((${tmp}))
1372 param2=$(expr ${tmp} + "1")
1373 param2=$(printf "%x" ${param2})
1374 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
1375 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developerb9b4cd12022-10-11 13:18:59 +08001376
developer13655da2023-01-10 19:53:25 +08001377 param=$(printf "0x%s" ${param})
1378 param=$(printf "%04x" ${param})
1379 param=$(echo $param | tr 'a-z' 'A-Z')
1380 printf "%s e2p:\n" ${interface_ori}
1381 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
1382 done
developerb9b4cd12022-10-11 13:18:59 +08001383 fi
1384
1385elif [ "${cmd_type}" = "mac" ]; then
developerb9b4cd12022-10-11 13:18:59 +08001386 offset=$(printf "0x%s" ${cmd})
1387 val=$(printf "0x%s" ${param})
1388
developerb9b4cd12022-10-11 13:18:59 +08001389 # reg write
1390 if [[ ${full_cmd} == *"="* ]]; then
developer092b55c2023-01-18 18:20:58 +08001391 register_handler ${phy_idx} ${offset} ${val} "write"
1392 else
1393 start_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 1)
1394 end_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 2)
1395 loop=$((0x${end_addr}-0x${start_addr}))
developerb9b4cd12022-10-11 13:18:59 +08001396
developer092b55c2023-01-18 18:20:58 +08001397 if [[ ${loop} == "0" ]]; then
1398 register_handler ${phy_idx} ${offset} ${val}
1399 else
1400 i=0
1401 while [ $i -le $loop ]; do
1402 addr=$((0x${start_addr}+$i))
1403 offset=$(printf "0x%x" ${addr})
1404 register_handler ${phy_idx} ${offset} ${val}
1405 i=$(($i + 4))
1406 done
1407 fi
1408 fi
developerb9b4cd12022-10-11 13:18:59 +08001409
developer13655da2023-01-10 19:53:25 +08001410## dump command is only for vendor commands
1411elif [ "${cmd_type}" = "dump" ]; then
1412 do_cmd "mt76-vendor $*"
developerc9333e12023-04-06 18:07:42 +08001413elif [ "${cmd_type}" = "switch" ]; then
1414 eeprom_mode_file=sys/kernel/debug/ieee80211/phy0/mt76/eeprom_mode
1415 eeprom_mode=$(cat ${eeprom_mode_file} | grep "mode" | sed -n 2p | cut -d " " -f 4)
1416 eeprom_testmode_offset="1af"
1417 testmode_enable="0"
1418
developerc8796032023-08-09 10:28:15 +08001419 if [ ${is_connac3} == "0" ]; then
developerc9333e12023-04-06 18:07:42 +08001420 return
1421 fi
1422
1423 if [ "${cmd}" = "testmode" ]; then
1424 testmode_enable="1"
1425 fi
1426
1427 if [ "${eeprom_mode}" = "flash" ]; then
1428 ## flash mode should set eeprom testmode offset bit
1429 ## efuse/bin file/default bin mode rely on module param only
1430 do_cmd "atenl -i ${interface} -c \"eeprom set 0x${eeprom_testmode_offset}=0x${testmode_enable}\""
1431 ## If has no precal, it would not affect
1432 do_cmd "atenl -i ${interface} -c \"eeprom precal sync\""
1433 do_cmd "atenl -i ${interface} -c \"sync eeprom all\""
1434 fi
1435
1436 do_cmd "rmmod mt7996e"
1437 do_cmd "rmmod mt76-connac-lib"
1438 do_cmd "rmmod mt76"
1439 do_cmd "rmmod mac80211"
1440 do_cmd "rmmod cfg80211"
1441 do_cmd "rmmod compat"
1442 do_cmd "insmod compat"
1443 do_cmd "insmod cfg80211"
1444 do_cmd "insmod mac80211"
1445 do_cmd "insmod mt76"
1446 do_cmd "insmod mt76-connac-lib"
1447 do_cmd "insmod mt7996e testmode_enable=${testmode_enable}"
1448 do_cmd "sleep 5"
1449 do_cmd "killall hostapd"
1450 do_cmd "killall netifd"
developerb9b4cd12022-10-11 13:18:59 +08001451else
1452 echo "Unknown command"
1453fi