blob: 333852deab7a386a54a773ff400d3a4ce59b4d62 [file] [log] [blame]
developer3abe1ad2022-01-24 11:13:32 +08001#!/bin/ash
2
developer071927d2022-08-31 20:39:29 +08003interface=$1 # phy0/phy1/ra0
developerf90c9af2022-12-28 22:40:23 +08004cmd_type=$2 # set/show/e2p/mac/dump
developer3abe1ad2022-01-24 11:13:32 +08005full_cmd=$3
developer9b7cdad2022-03-10 14:24:55 +08006interface_ori=${interface}
developerf90c9af2022-12-28 22:40:23 +08007SOC_start_idx="0"
developerb4b29472023-01-06 19:07:21 +08008SOC_end_idx="0"
developerf90c9af2022-12-28 22:40:23 +08009is_eagle="0"
developer3abe1ad2022-01-24 11:13:32 +080010
11work_mode="RUN" # RUN/PRINT/DEBUG
developer679a6aa2022-09-07 09:52:41 +080012iwpriv_file="/tmp/iwpriv_wrapper"
13interface_file="/tmp/interface"
developer3abe1ad2022-01-24 11:13:32 +080014phy_idx=$(echo ${interface} | tr -dc '0-9')
15
developer3abe1ad2022-01-24 11:13:32 +080016function do_cmd() {
17 case ${work_mode} in
18 "RUN")
19 eval "$1"
20 ;;
21 "PRINT")
22 echo "$1"
23 ;;
24 "DEBUG")
developer3abe1ad2022-01-24 11:13:32 +080025 echo "$1"
developer887da632022-10-28 09:35:38 +080026 eval "$1"
developer3abe1ad2022-01-24 11:13:32 +080027 ;;
28 esac
29}
30
developer9b7cdad2022-03-10 14:24:55 +080031function print_debug() {
32 if [ "${work_mode}" = "DEBUG" ]; then
33 echo "$1"
34 fi
35}
36
developer10946c32022-03-04 18:28:43 +080037function write_dmesg() {
38 echo "$1" > /dev/kmsg
39}
40
developer3abe1ad2022-01-24 11:13:32 +080041function record_config() {
developer679a6aa2022-09-07 09:52:41 +080042 local config=$1
43 local tmp_file=$3
44
developerf90c9af2022-12-28 22:40:23 +080045 # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
developerb4b29472023-01-06 19:07:21 +080046 if [ ${tmp_file} != ${interface_file} ]; then
developerf90c9af2022-12-28 22:40:23 +080047 if [ $phy_idx -lt $SOC_start_idx ]; then
developer679a6aa2022-09-07 09:52:41 +080048 config="${config}_PCIE"
developerf90c9af2022-12-28 22:40:23 +080049 elif [ $phy_idx -ge $SOC_start_idx ]; then
50 config="${config}_SOC"
developer679a6aa2022-09-07 09:52:41 +080051 fi
52 fi
53
developer3abe1ad2022-01-24 11:13:32 +080054 if [ -f ${tmp_file} ]; then
developer679a6aa2022-09-07 09:52:41 +080055 if grep -q ${config} ${tmp_file}; then
56 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
developer3abe1ad2022-01-24 11:13:32 +080057 else
developer679a6aa2022-09-07 09:52:41 +080058 echo "${config}=$2" >> ${tmp_file}
developer3abe1ad2022-01-24 11:13:32 +080059 fi
60 else
developer679a6aa2022-09-07 09:52:41 +080061 echo "${config}=$2" >> ${tmp_file}
developer3abe1ad2022-01-24 11:13:32 +080062 fi
63}
64
65function get_config() {
developer679a6aa2022-09-07 09:52:41 +080066 local config=$1
67 local tmp_file=$2
68
developer10946c32022-03-04 18:28:43 +080069 if [ ! -f ${tmp_file} ]; then
70 echo ""
71 return
72 fi
73
developerf90c9af2022-12-28 22:40:23 +080074 # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
developerb4b29472023-01-06 19:07:21 +080075 if [ ${tmp_file} != ${interface_file} ]; then
developerf90c9af2022-12-28 22:40:23 +080076 if [ $phy_idx -lt $SOC_start_idx ]; then
developer679a6aa2022-09-07 09:52:41 +080077 config="${config}_PCIE"
developerf90c9af2022-12-28 22:40:23 +080078 elif [ $phy_idx -ge $SOC_start_idx ]; then
79 config="${config}_SOC"
developer679a6aa2022-09-07 09:52:41 +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)"
developer10946c32022-03-04 18:28:43 +080085 else
86 echo ""
87 fi
developer3abe1ad2022-01-24 11:13:32 +080088}
89
developerb4b29472023-01-06 19:07:21 +080090function parse_sku {
developerf90c9af2022-12-28 22:40:23 +080091 SOC_start_idx=$(get_config "STARTIDX" ${interface_file})
developerb4b29472023-01-06 19:07:21 +080092 SOC_end_idx=$(get_config "ENDIDX" ${interface_file})
developerf90c9af2022-12-28 22:40:23 +080093 is_eagle=$(get_config "IS_EAGLE" ${interface_file})
developer679a6aa2022-09-07 09:52:41 +080094 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
developerb4b29472023-01-06 19:07:21 +080095 if [ -z "${SOC_start_idx}" ] || [ -z "${SOC_end_idx}" ] || [ -z "${is_eagle}" ]; then
developer679a6aa2022-09-07 09:52:41 +080096 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
developerf90c9af2022-12-28 22:40:23 +080097 SOC_start_idx="2"
developerb4b29472023-01-06 19:07:21 +080098 SOC_end_idx="3"
developerf90c9af2022-12-28 22:40:23 +080099 is_eagle="0"
developer679a6aa2022-09-07 09:52:41 +0800100 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
developerf90c9af2022-12-28 22:40:23 +0800101 SOC_start_idx="1"
developerb4b29472023-01-06 19:07:21 +0800102 SOC_end_idx="2"
developerf90c9af2022-12-28 22:40:23 +0800103 is_eagle="0"
developer679a6aa2022-09-07 09:52:41 +0800104 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
developerf90c9af2022-12-28 22:40:23 +0800105 SOC_start_idx="0"
developerb4b29472023-01-06 19:07:21 +0800106 SOC_end_idx="1"
developerf90c9af2022-12-28 22:40:23 +0800107 is_eagle="0"
108 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then
109 SOC_start_idx="0"
developerb4b29472023-01-06 19:07:21 +0800110 SOC_end_idx="2"
developerf90c9af2022-12-28 22:40:23 +0800111 is_eagle="1"
developereebce5c2022-08-26 19:05:56 +0800112 else
developer679a6aa2022-09-07 09:52:41 +0800113 echo "Interface Conversion Failed!"
114 echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
developerb4b29472023-01-06 19:07:21 +0800115 echo "For AX6000:"
116 echo " echo STARTIDX=0 >> ${interface_file}"
117 echo " echo ENDIDX=1 >> ${interface_file}"
118 echo " echo IS_EAGLE=0 >> ${interface_file}"
119 echo "For AX7800:"
120 echo " echo STARTIDX=2 >> ${interface_file}"
121 echo " echo ENDIDX=3 >> ${interface_file}"
122 echo " echo IS_EAGLE=0 >> ${interface_file}"
123 echo "For AX8400:"
124 echo " echo STARTIDX=1 >> ${interface_file}"
125 echo " echo ENDIDX=2 >> ${interface_file}"
126 echo " echo IS_EAGLE=0 >> ${interface_file}"
127 echo "For Eagle:"
128 echo " echo STARTIDX=1 >> ${interface_file}"
129 echo " echo ENDIDX=2 >> ${interface_file}"
130 echo " echo IS_EAGLE=1 >> ${interface_file}"
developer679a6aa2022-09-07 09:52:41 +0800131 exit 0
developereebce5c2022-08-26 19:05:56 +0800132 fi
developerf90c9af2022-12-28 22:40:23 +0800133 record_config "STARTIDX" ${SOC_start_idx} ${interface_file}
developerb4b29472023-01-06 19:07:21 +0800134 record_config "ENDIDX" ${SOC_end_idx} ${interface_file}
developerf90c9af2022-12-28 22:40:23 +0800135 record_config "IS_EAGLE" ${is_eagle} ${interface_file}
developereebce5c2022-08-26 19:05:56 +0800136 fi
developerb4b29472023-01-06 19:07:21 +0800137}
developer679a6aa2022-09-07 09:52:41 +0800138
developerb4b29472023-01-06 19:07:21 +0800139function convert_interface {
developerf90c9af2022-12-28 22:40:23 +0800140 if [ ${is_eagle} == "0" ]; then
developer679a6aa2022-09-07 09:52:41 +0800141 if [[ $1 == "raix"* ]]; then
developerf90c9af2022-12-28 22:40:23 +0800142 phy_idx=1
143 elif [[ $1 == "rai"* ]]; then
developer679a6aa2022-09-07 09:52:41 +0800144 phy_idx=0
145 elif [[ $1 == "rax"* ]]; then
developerf90c9af2022-12-28 22:40:23 +0800146 phy_idx=$((SOC_start_idx+1))
147 else
148 phy_idx=$SOC_start_idx
developer679a6aa2022-09-07 09:52:41 +0800149 fi
developerf90c9af2022-12-28 22:40:23 +0800150
151 # convert phy index according to band idx
152 local band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
153 if [ "${band_idx}" = "0" ]; then
154 if [[ $1 == "raix"* ]]; then
155 phy_idx=0
156 elif [[ $1 == "rax"* ]]; then
157 phy_idx=$SOC_start_idx
158 fi
159 elif [ "${band_idx}" = "1" ]; then
160 if [[ $1 == "rai"* ]]; then
161 # AX8400: mt7915 remain phy0
162 # AX7800: mt7916 becomes phy1
163 phy_idx=$((SOC_start_idx-1))
164 elif [[ $1 == "ra"* ]]; then
165 phy_idx=$((SOC_start_idx+1))
166 fi
167 fi
168 else
169 # Eagle has different mapping method
170 # phy0: ra0
171 # phy1: rai0
172 # phy2: rax0
developer679a6aa2022-09-07 09:52:41 +0800173 if [[ $1 == "rai"* ]]; then
developerf90c9af2022-12-28 22:40:23 +0800174 phy_idx=1
175 elif [[ $1 == "rax"* ]]; then
176 phy_idx=2
177 else
178 phy_idx=0
developer679a6aa2022-09-07 09:52:41 +0800179 fi
180 fi
181
182 interface="phy${phy_idx}"
183}
184
185function change_band_idx {
186 local new_idx=$1
187 local new_phy_idx=$phy_idx
188
189 local old_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
190
191
192 if [[ ${interface_ori} == "ra"* ]]; then
193 if [ -z "${old_idx}" ] || [ "${old_idx}" != "${new_idx}" ]; then
194 if [ "${new_idx}" = "0" ]; then
195 # raix0 & rai0 becomes rai0
196 if [[ $interface_ori == "rai"* ]]; then
197 new_phy_idx=0
198 # rax0 & ra0 becomes ra0
199 elif [[ $interface_ori == "ra"* ]]; then
developerf90c9af2022-12-28 22:40:23 +0800200 new_phy_idx=$SOC_start_idx
developer679a6aa2022-09-07 09:52:41 +0800201 fi
202 elif [ "${new_idx}" = "1" ]; then
203 # raix0 & rai0 becomes raix0
204 if [[ $interface_ori == "rai"* ]]; then
developer1346ce52022-12-15 21:36:14 +0800205 # For AX8400 => don't change phy idx
developerf90c9af2022-12-28 22:40:23 +0800206 if [ ${SOC_start_idx} != "1" ]; then
developer1346ce52022-12-15 21:36:14 +0800207 new_phy_idx=1
208 fi
developer679a6aa2022-09-07 09:52:41 +0800209 # rax0 & ra0 becomes rax0
210 elif [[ $interface_ori == "ra"* ]]; then
developerf90c9af2022-12-28 22:40:23 +0800211 new_phy_idx=$((SOC_start_idx+1))
developer679a6aa2022-09-07 09:52:41 +0800212 fi
213 fi
214 fi
215
216 if [ ${new_phy_idx} != ${phy_idx} ]; then
217 do_ate_work "ATESTOP"
218 phy_idx=$new_phy_idx
219 interface="phy${phy_idx}"
220 do_ate_work "ATESTART"
221 fi
developereebce5c2022-08-26 19:05:56 +0800222 fi
developer679a6aa2022-09-07 09:52:41 +0800223 record_config "ATECTRLBANDIDX" ${new_idx} ${iwpriv_file}
developereebce5c2022-08-26 19:05:56 +0800224}
225
developer3abe1ad2022-01-24 11:13:32 +0800226function simple_convert() {
227 if [ "$1" = "ATETXCNT" ]; then
228 echo "tx_count"
229 elif [ "$1" = "ATETXLEN" ]; then
230 echo "tx_length"
231 elif [ "$1" = "ATETXMCS" ]; then
232 echo "tx_rate_idx"
233 elif [ "$1" = "ATEVHTNSS" ]; then
234 echo "tx_rate_nss"
235 elif [ "$1" = "ATETXLDPC" ]; then
236 echo "tx_rate_ldpc"
237 elif [ "$1" = "ATETXSTBC" ]; then
238 echo "tx_rate_stbc"
239 elif [ "$1" = "ATEPKTTXTIME" ]; then
240 echo "tx_time"
241 elif [ "$1" = "ATEIPG" ]; then
242 echo "tx_ipg"
243 elif [ "$1" = "ATEDUTYCYCLE" ]; then
244 echo "tx_duty_cycle"
245 elif [ "$1" = "ATETXFREQOFFSET" ]; then
246 echo "freq_offset"
247 else
developer679a6aa2022-09-07 09:52:41 +0800248 echo "undefined"
developer3abe1ad2022-01-24 11:13:32 +0800249 fi
250}
251
252function convert_tx_mode() {
developer1346ce52022-12-15 21:36:14 +0800253 # Remove leading zeros
developer4feb1012023-01-30 17:29:07 +0800254 local tx_mode=$(echo $1 | sed -r 's/0+([0-9]+)/\1/g')
developer1346ce52022-12-15 21:36:14 +0800255
256 if [ "$tx_mode" = "0" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800257 echo "cck"
developer1346ce52022-12-15 21:36:14 +0800258 elif [ "$tx_mode" = "1" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800259 echo "ofdm"
developer1346ce52022-12-15 21:36:14 +0800260 elif [ "$tx_mode" = "2" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800261 echo "ht"
developer1346ce52022-12-15 21:36:14 +0800262 elif [ "$tx_mode" = "4" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800263 echo "vht"
developer1346ce52022-12-15 21:36:14 +0800264 elif [ "$tx_mode" = "8" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800265 echo "he_su"
developer1346ce52022-12-15 21:36:14 +0800266 elif [ "$tx_mode" = "9" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800267 echo "he_er"
developer1346ce52022-12-15 21:36:14 +0800268 elif [ "$tx_mode" = "10" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800269 echo "he_tb"
developer1346ce52022-12-15 21:36:14 +0800270 elif [ "$tx_mode" = "11" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800271 echo "he_mu"
272 else
developer679a6aa2022-09-07 09:52:41 +0800273 echo "undefined"
developer3abe1ad2022-01-24 11:13:32 +0800274 fi
275}
276
277function convert_gi {
278 local tx_mode=$1
279 local val=$2
280 local sgi="0"
281 local he_ltf="0"
282
283 case ${tx_mode} in
284 "ht"|"vht")
285 sgi=${val}
286 ;;
287 "he_su"|"he_er")
288 case ${val} in
289 "0")
290 ;;
291 "1")
292 he_ltf="1"
293 ;;
294 "2")
295 sgi="1"
296 he_ltf="1"
297 ;;
298 "3")
299 sgi="2"
300 he_ltf="2"
301 ;;
302 "4")
303 he_ltf="2"
304 ;;
305 *)
306 echo "unknown gi"
307 esac
308 ;;
309 "he_mu")
310 case ${val} in
311 "0")
312 he_ltf="2"
313 ;;
314 "1")
315 he_ltf="1"
316 ;;
317 "2")
318 sgi="1"
319 he_ltf="1"
320 ;;
321 "3")
322 sgi="2"
323 he_ltf="2"
324 ;;
325 *)
326 echo "unknown gi"
327 esac
328 ;;
329 "he_tb")
330 case ${val} in
331 "0")
332 sgi="1"
333 ;;
334 "1")
335 sgi="1"
336 he_ltf="1"
337 ;;
338 "2")
339 sgi="2"
340 he_ltf="2"
341 ;;
342 *)
343 echo "unknown gi"
344 esac
345 ;;
346 *)
developer9b7cdad2022-03-10 14:24:55 +0800347 print_debug "legacy mode no need gi"
developer3abe1ad2022-01-24 11:13:32 +0800348 esac
349
350 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
351}
352
353function convert_channel {
developer679a6aa2022-09-07 09:52:41 +0800354 local ctrl_band_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
developer3abe1ad2022-01-24 11:13:32 +0800355 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
developer679a6aa2022-09-07 09:52:41 +0800356 local bw=$(get_config "ATETXBW" ${iwpriv_file} | cut -d ":" -f 1)
developer10946c32022-03-04 18:28:43 +0800357 local bw_str="HT20"
developereebce5c2022-08-26 19:05:56 +0800358 local base_chan=1
359 local control_freq=0
360 local base_freq=0
developer1346ce52022-12-15 21:36:14 +0800361 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
362 local temp=$((phy_idx+1))
developer3abe1ad2022-01-24 11:13:32 +0800363
developer1346ce52022-12-15 21:36:14 +0800364 # Handle ATECTRLBANDIDX
365 if [ ! -z ${ctrl_band_idx} ]; then
366 if [ "${ctrl_band_idx}" == "1" ] && [ ${band} == "0" ]; then
367 local temp=$(cat "/etc/config/wireless"| grep "option band" | sed -n ${temp}p | cut -c 15)
368 if [ "${temp}" == "2" ]; then
369 local band=0
370 elif [ "${temp}" == "5" ]; then
371 local band=1
372 elif [ "${temp}" == "6" ]; then
373 local band=2
374 else
375 echo "iwpriv wrapper band translate error!"
376 fi
377 else
378 # mt7915 in AX8400 case: band should be determined by only the input band
developerf90c9af2022-12-28 22:40:23 +0800379 if [ "${SOC_start_idx}" == "1" ] && [ ${phy_idx} == "0" ]; then
developer1346ce52022-12-15 21:36:14 +0800380 local band=$((band))
381 else
382 local band=$((ctrl_band_idx * band))
383 fi
384 fi
developer679a6aa2022-09-07 09:52:41 +0800385 fi
386
developer9b7cdad2022-03-10 14:24:55 +0800387 if [[ $1 != *":"* ]] || [ "${band}" = "0" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800388 case ${bw} in
389 "1")
developer461cb542022-04-29 18:17:44 +0800390 if [ "${ch}" -lt "3" ] || [ "${ch}" -gt "12" ]; then
391 local bw_str="HT20"
developer3abe1ad2022-01-24 11:13:32 +0800392 else
developer461cb542022-04-29 18:17:44 +0800393 local bw_str="HT40+"
394 ch=$(expr ${ch} - "2")
developer3abe1ad2022-01-24 11:13:32 +0800395 fi
396 ;;
developer3abe1ad2022-01-24 11:13:32 +0800397 esac
developereebce5c2022-08-26 19:05:56 +0800398 local base_freq=2412
developera6267142022-01-26 20:50:22 +0800399 elif [ "${band}" = "1" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800400 case ${bw} in
developera6267142022-01-26 20:50:22 +0800401 "5")
developer10946c32022-03-04 18:28:43 +0800402 bw_str="160MHz"
403 if [ ${ch} -lt "68" ]; then
404 ch="36"
405 elif [ ${ch} -lt "100" ]; then
406 ch="68"
407 elif [ ${ch} -lt "132" ]; then
408 ch="100"
409 elif [ ${ch} -lt "181" ]; then
410 ch="149"
411 fi
developera6267142022-01-26 20:50:22 +0800412 ;;
developer3abe1ad2022-01-24 11:13:32 +0800413 "2")
developer10946c32022-03-04 18:28:43 +0800414 bw_str="80MHz"
415 if [ ${ch} -lt "52" ]; then
416 ch="36"
417 elif [ ${ch} -lt "68" ]; then
418 ch="52"
419 elif [ ${ch} -lt "84" ]; then
420 ch="68"
421 elif [ ${ch} -lt "100" ]; then
422 ch="84"
423 elif [ ${ch} -lt "116" ]; then
424 ch="100"
425 elif [ ${ch} -lt "132" ]; then
426 ch="116"
427 elif [ ${ch} -lt "149" ]; then
428 ch="132"
429 elif [ ${ch} -lt "165" ]; then
430 ch="149"
431 elif [ ${ch} -lt "181" ]; then
432 ch="165"
433 fi
developer3abe1ad2022-01-24 11:13:32 +0800434 ;;
435 "1")
developer10946c32022-03-04 18:28:43 +0800436 if [ ${ch} -lt "44" ]; then
437 ch=$([ "${ch}" -lt "40" ] && echo "36" || echo "40")
438 bw_str=$([ "${ch}" -le "38" ] && echo "HT40+" || echo "HT40-")
439 elif [ ${ch} -lt "52" ]; then
440 ch=$([ "${ch}" -lt "48" ] && echo "44" || echo "48")
441 bw_str=$([ "${ch}" -le "46" ] && echo "HT40+" || echo "HT40-")
442 elif [ ${ch} -lt "60" ]; then
443 ch=$([ "${ch}" -lt "56" ] && echo "52" || echo "56")
444 bw_str=$([ "${ch}" -le "54" ] && echo "HT40+" || echo "HT40-")
445 elif [ ${ch} -lt "68" ]; then
446 ch=$([ "${ch}" -lt "64" ] && echo "60" || echo "64")
447 bw_str=$([ "${ch}" -le "62" ] && echo "HT40+" || echo "HT40-")
448 elif [ ${ch} -lt "76" ]; then
449 ch=$([ "${ch}" -lt "72" ] && echo "68" || echo "72")
450 bw_str=$([ "${ch}" -le "70" ] && echo "HT40+" || echo "HT40-")
451 elif [ ${ch} -lt "84" ]; then
452 ch=$([ "${ch}" -lt "80" ] && echo "76" || echo "80")
453 bw_str=$([ "${ch}" -le "78" ] && echo "HT40+" || echo "HT40-")
454 elif [ ${ch} -lt "92" ]; then
455 ch=$([ "${ch}" -lt "88" ] && echo "84" || echo "88")
456 bw_str=$([ "${ch}" -le "86" ] && echo "HT40+" || echo "HT40-")
457 elif [ ${ch} -lt "100" ]; then
458 ch=$([ "${ch}" -lt "96" ] && echo "92" || echo "96")
459 bw_str=$([ "${ch}" -le "94" ] && echo "HT40+" || echo "HT40-")
460 elif [ ${ch} -lt "108" ]; then
461 ch=$([ "${ch}" -lt "104" ] && echo "100" || echo "104")
462 bw_str=$([ "${ch}" -le "102" ] && echo "HT40+" || echo "HT40-")
463 elif [ ${ch} -lt "116" ]; then
464 ch=$([ "${ch}" -lt "112" ] && echo "108" || echo "112")
465 bw_str=$([ "${ch}" -le "110" ] && echo "HT40+" || echo "HT40-")
466 elif [ ${ch} -lt "124" ]; then
467 ch=$([ "${ch}" -lt "120" ] && echo "116" || echo "120")
468 bw_str=$([ "${ch}" -le "118" ] && echo "HT40+" || echo "HT40-")
469 elif [ ${ch} -lt "132" ]; then
470 ch=$([ "${ch}" -lt "128" ] && echo "124" || echo "128")
471 bw_str=$([ "${ch}" -le "126" ] && echo "HT40+" || echo "HT40-")
472 elif [ ${ch} -lt "140" ]; then
473 ch=$([ "${ch}" -lt "136" ] && echo "132" || echo "136")
474 bw_str=$([ "${ch}" -le "134" ] && echo "HT40+" || echo "HT40-")
475 elif [ ${ch} -lt "149" ]; then
476 ch=$([ "${ch}" -lt "144" ] && echo "140" || echo "144")
477 bw_str=$([ "${ch}" -le "142" ] && echo "HT40+" || echo "HT40-")
478 elif [ ${ch} -lt "157" ]; then
479 ch=$([ "${ch}" -lt "153" ] && echo "149" || echo "153")
480 bw_str=$([ "${ch}" -le "151" ] && echo "HT40+" || echo "HT40-")
481 elif [ ${ch} -lt "165" ]; then
482 ch=$([ "${ch}" -lt "161" ] && echo "157" || echo "161")
483 bw_str=$([ "${ch}" -le "159" ] && echo "HT40+" || echo "HT40-")
484 elif [ ${ch} -lt "173" ]; then
485 ch=$([ "${ch}" -lt "169" ] && echo "165" || echo "169")
486 bw_str=$([ "${ch}" -le "167" ] && echo "HT40+" || echo "HT40-")
487 elif [ ${ch} -lt "181" ]; then
488 ch=$([ "${ch}" -lt "177" ] && echo "173" || echo "177")
489 bw_str=$([ "${ch}" -le "175" ] && echo "HT40+" || echo "HT40-")
developer3abe1ad2022-01-24 11:13:32 +0800490 fi
491 ;;
492 "0")
493 local bw_str="HT20"
494 ;;
495 esac
developereebce5c2022-08-26 19:05:56 +0800496 local base_freq=5180
497 local base_chan=36
developera6267142022-01-26 20:50:22 +0800498 else
developereebce5c2022-08-26 19:05:56 +0800499 case ${bw} in
500 "5")
501 bw_str="160MHz"
502 if [ ${ch} -lt "33" ]; then
503 ch="1"
504 elif [ ${ch} -lt "65" ]; then
505 ch="33"
506 elif [ ${ch} -lt "97" ]; then
507 ch="65"
508 elif [ ${ch} -lt "129" ]; then
509 ch="97"
510 elif [ ${ch} -lt "161" ]; then
511 ch="129"
512 elif [ ${ch} -lt "193" ]; then
513 ch="161"
514 elif [ ${ch} -lt "225" ]; then
515 ch="193"
516 fi
517 ;;
518 "2")
519 bw_str="80MHz"
520 if [ ${ch} -lt "17" ]; then
521 ch="1"
522 elif [ ${ch} -lt "33" ]; then
523 ch="17"
524 elif [ ${ch} -lt "49" ]; then
525 ch="33"
526 elif [ ${ch} -lt "65" ]; then
527 ch="49"
528 elif [ ${ch} -lt "81" ]; then
529 ch="65"
530 elif [ ${ch} -lt "97" ]; then
531 ch="81"
532 elif [ ${ch} -lt "113" ]; then
533 ch="97"
534 elif [ ${ch} -lt "129" ]; then
535 ch="113"
536 elif [ ${ch} -lt "145" ]; then
537 ch="129"
538 elif [ ${ch} -lt "161" ]; then
539 ch="145"
540 elif [ ${ch} -lt "177" ]; then
541 ch="161"
542 elif [ ${ch} -lt "193" ]; then
543 ch="177"
544 elif [ ${ch} -lt "209" ]; then
545 ch="193"
546 elif [ ${ch} -lt "225" ]; then
547 ch="209"
548 fi
549 ;;
550 "1")
551 if [ ${ch} -lt "9" ]; then
552 ch=$([ "${ch}" -lt "5" ] && echo "1" || echo "5")
553 bw_str=$([ "${ch}" -le "3" ] && echo "HT40+" || echo "HT40-")
554 elif [ ${ch} -lt "17" ]; then
555 ch=$([ "${ch}" -lt "13" ] && echo "9" || echo "13")
556 bw_str=$([ "${ch}" -le "11" ] && echo "HT40+" || echo "HT40-")
557 elif [ ${ch} -lt "25" ]; then
558 ch=$([ "${ch}" -lt "21" ] && echo "17" || echo "21")
559 bw_str=$([ "${ch}" -le "19" ] && echo "HT40+" || echo "HT40-")
560 elif [ ${ch} -lt "33" ]; then
561 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
562 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
563 elif [ ${ch} -lt "33" ]; then
564 ch=$([ "${ch}" -lt "29" ] && echo "25" || echo "29")
565 bw_str=$([ "${ch}" -le "27" ] && echo "HT40+" || echo "HT40-")
566 elif [ ${ch} -lt "41" ]; then
567 ch=$([ "${ch}" -lt "37" ] && echo "33" || echo "37")
568 bw_str=$([ "${ch}" -le "35" ] && echo "HT40+" || echo "HT40-")
569 elif [ ${ch} -lt "49" ]; then
570 ch=$([ "${ch}" -lt "45" ] && echo "41" || echo "45")
571 bw_str=$([ "${ch}" -le "43" ] && echo "HT40+" || echo "HT40-")
572 elif [ ${ch} -lt "57" ]; then
573 ch=$([ "${ch}" -lt "53" ] && echo "49" || echo "53")
574 bw_str=$([ "${ch}" -le "51" ] && echo "HT40+" || echo "HT40-")
575 elif [ ${ch} -lt "65" ]; then
576 ch=$([ "${ch}" -lt "61" ] && echo "57" || echo "61")
577 bw_str=$([ "${ch}" -le "59" ] && echo "HT40+" || echo "HT40-")
578 elif [ ${ch} -lt "73" ]; then
579 ch=$([ "${ch}" -lt "69" ] && echo "65" || echo "69")
580 bw_str=$([ "${ch}" -le "67" ] && echo "HT40+" || echo "HT40-")
581 elif [ ${ch} -lt "81" ]; then
582 ch=$([ "${ch}" -lt "77" ] && echo "73" || echo "77")
583 bw_str=$([ "${ch}" -le "75" ] && echo "HT40+" || echo "HT40-")
584 elif [ ${ch} -lt "89" ]; then
585 ch=$([ "${ch}" -lt "85" ] && echo "81" || echo "85")
586 bw_str=$([ "${ch}" -le "83" ] && echo "HT40+" || echo "HT40-")
587 elif [ ${ch} -lt "97" ]; then
588 ch=$([ "${ch}" -lt "93" ] && echo "89" || echo "93")
589 bw_str=$([ "${ch}" -le "91" ] && echo "HT40+" || echo "HT40-")
590 elif [ ${ch} -lt "105" ]; then
591 ch=$([ "${ch}" -lt "101" ] && echo "97" || echo "101")
592 bw_str=$([ "${ch}" -le "99" ] && echo "HT40+" || echo "HT40-")
593 elif [ ${ch} -lt "113" ]; then
594 ch=$([ "${ch}" -lt "109" ] && echo "105" || echo "109")
595 bw_str=$([ "${ch}" -le "107" ] && echo "HT40+" || echo "HT40-")
596 elif [ ${ch} -lt "121" ]; then
597 ch=$([ "${ch}" -lt "117" ] && echo "113" || echo "117")
598 bw_str=$([ "${ch}" -le "115" ] && echo "HT40+" || echo "HT40-")
599 elif [ ${ch} -lt "129" ]; then
600 ch=$([ "${ch}" -lt "125" ] && echo "121" || echo "125")
601 bw_str=$([ "${ch}" -le "123" ] && echo "HT40+" || echo "HT40-")
602 elif [ ${ch} -lt "137" ]; then
603 ch=$([ "${ch}" -lt "133" ] && echo "129" || echo "133")
604 bw_str=$([ "${ch}" -le "131" ] && echo "HT40+" || echo "HT40-")
605 elif [ ${ch} -lt "145" ]; then
606 ch=$([ "${ch}" -lt "141" ] && echo "137" || echo "141")
607 bw_str=$([ "${ch}" -le "139" ] && echo "HT40+" || echo "HT40-")
608 elif [ ${ch} -lt "153" ]; then
609 ch=$([ "${ch}" -lt "149" ] && echo "145" || echo "149")
610 bw_str=$([ "${ch}" -le "147" ] && echo "HT40+" || echo "HT40-")
611 elif [ ${ch} -lt "161" ]; then
612 ch=$([ "${ch}" -lt "157" ] && echo "153" || echo "157")
613 bw_str=$([ "${ch}" -le "155" ] && echo "HT40+" || echo "HT40-")
614 elif [ ${ch} -lt "169" ]; then
615 ch=$([ "${ch}" -lt "165" ] && echo "161" || echo "165")
616 bw_str=$([ "${ch}" -le "163" ] && echo "HT40+" || echo "HT40-")
617 elif [ ${ch} -lt "177" ]; then
618 ch=$([ "${ch}" -lt "173" ] && echo "169" || echo "173")
619 bw_str=$([ "${ch}" -le "171" ] && echo "HT40+" || echo "HT40-")
620 elif [ ${ch} -lt "185" ]; then
621 ch=$([ "${ch}" -lt "181" ] && echo "177" || echo "181")
622 bw_str=$([ "${ch}" -le "179" ] && echo "HT40+" || echo "HT40-")
623 elif [ ${ch} -lt "193" ]; then
624 ch=$([ "${ch}" -lt "189" ] && echo "185" || echo "189")
625 bw_str=$([ "${ch}" -le "187" ] && echo "HT40+" || echo "HT40-")
626 elif [ ${ch} -lt "201" ]; then
627 ch=$([ "${ch}" -lt "197" ] && echo "193" || echo "197")
628 bw_str=$([ "${ch}" -le "195" ] && echo "HT40+" || echo "HT40-")
629 elif [ ${ch} -lt "209" ]; then
630 ch=$([ "${ch}" -lt "205" ] && echo "201" || echo "205")
631 bw_str=$([ "${ch}" -le "203" ] && echo "HT40+" || echo "HT40-")
632 elif [ ${ch} -lt "217" ]; then
633 ch=$([ "${ch}" -lt "213" ] && echo "209" || echo "213")
634 bw_str=$([ "${ch}" -le "211" ] && echo "HT40+" || echo "HT40-")
635 elif [ ${ch} -lt "225" ]; then
636 ch=$([ "${ch}" -lt "221" ] && echo "217" || echo "221")
637 bw_str=$([ "${ch}" -le "219" ] && echo "HT40+" || echo "HT40-")
638 elif [ ${ch} -lt "233" ]; then
639 ch=$([ "${ch}" -lt "229" ] && echo "225" || echo "229")
640 bw_str=$([ "${ch}" -le "227" ] && echo "HT40+" || echo "HT40-")
641 fi
642 ;;
643 "0")
644 local bw_str="HT20"
645 ;;
646 esac
647 local base_freq=5955
developer3abe1ad2022-01-24 11:13:32 +0800648 fi
649
developereebce5c2022-08-26 19:05:56 +0800650 local control_freq=$(((ch - base_chan) * 5 + base_freq))
651 do_cmd "iw dev mon${phy_idx} set freq ${control_freq} ${bw_str}"
developer3abe1ad2022-01-24 11:13:32 +0800652}
653
developer10946c32022-03-04 18:28:43 +0800654function convert_rxstat {
655 local res=$(do_cmd "mt76-test ${interface} dump stats")
656 local mdrdy=$(echo "${res}" | grep "rx_packets" | cut -d "=" -f 2)
657 local fcs_error=$(echo "${res}" | grep "rx_fcs_error" | cut -d "=" -f 2)
658 local rcpi=$(echo "${res}" | grep "last_rcpi" | cut -d "=" -f 2 | sed 's/,/ /g')
659 local ib_rssi=$(echo "${res}" | grep "last_ib_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
660 local wb_rssi=$(echo "${res}" | grep "last_wb_rssi" | cut -d "=" -f 2 | sed 's/,/ /g')
661 local rx_ok=$(expr ${mdrdy} - ${fcs_error})
662
developer461cb542022-04-29 18:17:44 +0800663 write_dmesg "rcpi: ${rcpi}"
664 write_dmesg "fagc rssi ib: ${ib_rssi}"
665 write_dmesg "fagc rssi wb: ${wb_rssi}"
666 write_dmesg "all_mac_rx_mdrdy_cnt: ${mdrdy}"
667 write_dmesg "all_mac_rx_fcs_err_cnt: ${fcs_error}"
developer9b7cdad2022-03-10 14:24:55 +0800668 write_dmesg "all_mac_rx_ok_cnt : ${rx_ok}"
developer10946c32022-03-04 18:28:43 +0800669}
670
developer10946c32022-03-04 18:28:43 +0800671function set_mac_addr {
developer679a6aa2022-09-07 09:52:41 +0800672 record_config ${cmd} ${param} ${iwpriv_file}
developer10946c32022-03-04 18:28:43 +0800673
developer679a6aa2022-09-07 09:52:41 +0800674 local addr1=$(get_config "ATEDA" ${iwpriv_file})
675 local addr2=$(get_config "ATESA" ${iwpriv_file})
676 local addr3=$(get_config "ATEBSSID" ${iwpriv_file})
developer10946c32022-03-04 18:28:43 +0800677
678 if [ -z "${addr1}" ]; then
679 addr1="00:11:22:33:44:55"
680 fi
681 if [ -z "${addr2}" ]; then
682 addr2="00:11:22:33:44:55"
683 fi
684 if [ -z "${addr3}" ]; then
685 addr3="00:11:22:33:44:55"
686 fi
687
688 do_cmd "mt76-test phy${phy_idx} set mac_addrs=${addr1},${addr2},${addr3}"
689}
690
developerf9843e22022-09-13 10:57:15 +0800691function convert_ibf {
692 local cmd=$1
693 local param=$2
694 local new_cmd=""
695 local new_param=$(echo ${param} | sed s/":"/","/g)
696
697 case ${cmd} in
698 "ATETxBfInit")
699 new_cmd="init"
developer1346ce52022-12-15 21:36:14 +0800700 new_param="1"
701 do_cmd "mt76-test phy${phy_idx} set state=idle"
702 ;;
703 "ATETxBfGdInit")
704 new_cmd="golden_init"
705 new_param="1"
developerf9843e22022-09-13 10:57:15 +0800706 do_cmd "mt76-test phy${phy_idx} set state=idle"
707 ;;
708 "ATEIBFPhaseComp")
709 new_cmd="phase_comp"
developer1346ce52022-12-15 21:36:14 +0800710 new_param="${new_param}"
developerf9843e22022-09-13 10:57:15 +0800711 ;;
712 "ATEEBfProfileConfig")
713 new_cmd="ebf_prof_update"
714 ;;
715 "ATEIBfProfileConfig")
716 new_cmd="ibf_prof_update"
717 ;;
718 "ATEIBfInstCal")
719 new_cmd="phase_cal"
720 ;;
721 "ATEIBfGdCal")
722 new_cmd="phase_cal"
723 new_param="${new_param},00"
724 ;;
725 "TxBfTxApply")
726 new_cmd="apply_tx"
727 ;;
728 "ATETxPacketWithBf")
729 local bf_on=${new_param:0:2}
730 local aid="01"
731 local wlan_idx=${new_param:3:2}
732 local update="00"
733 local tx_len=${new_param:6}
734
735 new_cmd="tx_prep"
736 new_param="${bf_on},${aid},${wlan_idx},${update}"
737 if [ "${tx_len}" = "00" ]; then
738 new_param="${new_param} aid=1 tx_count=10000000 tx_length=1024"
739 else
740 new_param="${new_param} aid=1 tx_count=${tx_len} tx_length=1024"
741 fi
742 do_cmd "mt76-test phy${phy_idx} set state=idle"
743 ;;
744 "TxBfProfileData20MAllWrite")
745 new_cmd="prof_update_all"
746 ;;
747 "ATEIBFPhaseE2pUpdate")
748 new_cmd="e2p_update"
749 ;;
developer1346ce52022-12-15 21:36:14 +0800750 "ATEIBFPhaseVerify")
751 local group=${new_param:0:2}
752 local group_l_m_h=${new_param:3:2}
753 local band_idx=${new_param:6:2}
754 local phase_cal_type=${new_param:9:2}
755 local LNA_gain_level=${new_param:12:2}
756 local read_from_e2p=${new_param:15:2}
757
758 do_cmd "mt76-test phy${phy_idx} set txbf_act=phase_comp txbf_param=1,${band_idx},${group},${read_from_e2p},0"
759 new_cmd="phase_cal"
760 new_param="${group},${group_l_m_h},${band_idx},${phase_cal_type},${LNA_gain_level}"
761 ;;
762 "TxBfProfileTagRead")
763 new_cmd="pfmu_tag_read"
764 ;;
765 "TxBfProfileTagWrite")
766 new_cmd="pfmu_tag_write"
767 ;;
768 "TxBfProfileTagInValid")
769 new_cmd="set_invalid_prof"
770 ;;
771 "StaRecBfRead")
772 new_cmd="sta_rec_read"
773 ;;
774 "TriggerSounding")
775 new_cmd="trigger_sounding"
776 ;;
777 "StopSounding")
778 new_cmd="stop_sounding"
779 new_param="0"
780 ;;
781 "ATEConTxETxBfGdProc")
782 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
783 local tx_rate_idx=${new_param:3:2}
784 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
785 local channel=${new_param:9:3}
786 local channel2=${new_param:13:3}
787 local band=${new_param:17}
788
789 new_cmd="ebf_golden_init"
790 do_ate_work "ATESTART"
791 do_cmd "mt76-test phy${phy_idx} set state=idle"
792 record_config "ATETXBW" ${bw} ${iwpriv_file}
793 convert_channel "${channel}:${band}"
794 if [ "${bw}" = "5" ]; then
795 new_param="1,1"
796 else
797 new_param="1,0"
798 fi
799 do_cmd "mt76-test phy${phy_idx} set tx_rate_mode=${tx_rate_mode} tx_rate_idx=${tx_rate_idx} tx_rate_sgi=0"
800 ;;
801 "ATEConTxETxBfInitProc")
802 local tx_rate_mode=$(convert_tx_mode ${new_param:0:2})
803 local tx_rate_idx=${new_param:3:2}
804 local bw=$(echo ${new_param:6:2} | sed 's/^0//')
805 local tx_rate_nss=${new_param:9:2}
806 local tx_stream=${new_param:12:2}
807 local tx_power=${new_param:15:2}
808 local channel=${new_param:18:3}
809 local channel2=${new_param:22:3}
810 local band=${new_param:26:1}
811 local tx_length=${new_param:28:5}
812
813 new_cmd="ebf_init"
814 do_ate_work "ATESTART"
815 do_cmd "mt76-test phy${phy_idx} set state=idle"
816 record_config "ATETXBW" ${bw} ${iwpriv_file}
817 convert_channel "${channel}:${band}"
818 new_param="1"
819 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"
820 ;;
developerf9843e22022-09-13 10:57:15 +0800821 *)
822 esac
823
824 do_cmd "mt76-test phy${phy_idx} set txbf_act=${new_cmd} txbf_param=${new_param}"
825
826 if [ "${cmd}" = "ATETxPacketWithBf" ]; then
827 do_cmd "mt76-test phy${phy_idx} set state=tx_frames"
developer1346ce52022-12-15 21:36:14 +0800828 elif [ "${cmd}" = "ATEConTxETxBfInitProc" ]; then
829 do_cmd "mt76-test phy${phy_idx} set aid=1"
830 do_cmd "mt76-test phy${phy_idx} set txbf_act=stop_sounding txbf_param=1"
831 do_cmd "mt76-test phy${phy_idx} set txbf_act=update_ch txbf_param=1"
832 do_cmd "mt76-test phy${phy_idx} set txbf_act=ebf_prof_update txbf_param=0,0,0"
833 do_cmd "mt76-test phy${phy_idx} set txbf_act=apply_tx txbf_param=1,1,0,0,0"
834 do_cmd "mt76-test phy${phy_idx} set txbf_act=pfmu_tag_read txbf_param=0,1"
835 do_cmd "mt76-test phy${phy_idx} set txbf_act=sta_rec_read txbf_param=1"
836 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=0,1,0,1,0,0,0"
837 do_cmd "mt76-test phy${phy_idx} set txbf_act=trigger_sounding txbf_param=2,1,ff,1,0,0,0"
838 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
839 elif [ "${cmd}" = "ATEConTxETxBfGdProc" ]; then
840 do_cmd "mt76-test phy${phy_idx} set aid=1"
841 do_cmd "mt76-test phy${phy_idx} set state=rx_frames"
842 elif [ "${cmd}" = "ATETxBfInit" ]; then
843 do_cmd "mt76-test phy${phy_idx} set aid=1"
844 elif [ "${cmd}" = "ATETxBfGdInit" ]; then
845 do_cmd "mt76-test phy${phy_idx} set aid=1"
developerf9843e22022-09-13 10:57:15 +0800846 fi
847}
848
developer887da632022-10-28 09:35:38 +0800849function convert_dfs {
850 local cmd=$1
851 local param=$2
852
853 case ${cmd} in
854 "DfsRxCtrl")
855 local offchan_ch="$(echo $param | cut -d ':' -f1)"
856 local offchan_bw="$(echo $param | cut -d ':' -f2)"
857
858 if [ "$offchan_bw" = "0" ]; then
859 offchan_bw="20"
860 elif [ "$offchan_bw" = "1" ]; then
861 offchan_bw="40"
862 elif [ "$offchan_bw" = "2" ]; then
863 offchan_bw="80"
864 fi
865
866 do_cmd "mt76-test phy${phy_idx} set state=idle"
867 do_cmd "mt76-test phy${phy_idx} set offchan_ch=${offchan_ch} offchan_bw=${offchan_bw}"
868 ;;
869 "DfsRxHist")
870 local ipi_th="$(echo $param | cut -d ':' -f 1)"
871 local ipi_period="$(echo $param | cut -d ':' -f 2)"
872 local ipi_antenna="$(echo $param | cut -d ':' -f 3)"
873
874 if [ -z $ipi_antenna ]; then
875 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period}"
876 else
877 do_cmd "mt76-test phy${phy_idx} set ipi_threshold=${ipi_th} ipi_period=${ipi_period} ipi_antenna_idx=${ipi_antenna}"
878 fi
879 ;;
880 *)
881 esac
882}
883
developera6267142022-01-26 20:50:22 +0800884function do_ate_work() {
885 local ate_cmd=$1
886
887 case ${ate_cmd} in
888 "ATESTART")
889 local if_str=$(ifconfig | grep mon${phy_idx})
890
891 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
892 echo "ATE already starts."
893 else
894 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
developerb4b29472023-01-06 19:07:21 +0800895
896 if [ $phy_idx -ge $SOC_start_idx ]; then
897 local end_idx=$SOC_end_idx
898 local start_idx=$SOC_start_idx
899 else
900 local end_idx=$((SOC_start_idx-1))
901 local start_idx="0"
902 fi
903
904 for phy_index in $( seq $start_idx $end_idx )
905 do
906 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
907 local prev_phy_index=$((phy_index-1))
908 local if_num=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep -c Interface)
909 local j="1"
910 # avoid del_if_count reset to 0 when start ate on another band in dbdc case
911 local del_if_count=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
912 if [ -z "${del_if_count}" ]; then
913 local del_if_count="0"
914 fi
915
916 for if_count in $( seq 1 $if_num )
917 do
918 local del_if=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep Interface | sed -n ${j}p | cut -d " " -f 2)
919 if [ ! -z "${del_if}" ] && [[ "$del_if" != *"mon"* ]]; then
920 do_cmd "iw dev ${del_if} del"
921 del_if_count=$((del_if_count+1))
922 # handle the case of multiple interface in a phy
923 record_config "DEL_IF${phy_index}-${del_if_count}" ${del_if} ${interface_file}
924 else
925 # j add 1 to skip mon interface
926 j=$((j+1))
927 fi
928 done
929 record_config "DEL_IF${phy_index}_NUM" ${del_if_count} ${interface_file}
930 done
931
developera6267142022-01-26 20:50:22 +0800932 do_cmd "ifconfig mon${phy_idx} up"
developer9b7cdad2022-03-10 14:24:55 +0800933 do_cmd "iw reg set VV"
developera6267142022-01-26 20:50:22 +0800934 fi
935 ;;
936 "ATESTOP")
937 local if_str=$(ifconfig | grep mon${phy_idx})
938
939 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
940 echo "ATE does not start."
941 else
942 do_cmd "mt76-test ${interface} set state=off"
943 do_cmd "iw dev mon${phy_idx} del"
developerb4b29472023-01-06 19:07:21 +0800944
945 if [ $phy_idx -ge $SOC_start_idx ]; then
946 local end_idx=$SOC_end_idx
947 local start_idx=$SOC_start_idx
948 else
949 local end_idx=$((SOC_start_idx-1))
950 local start_idx="0"
951 fi
952
953 # first check its phy and dbdc band phy has monitor interface or not
954 # if has at lease one mon interface, then skip adding back normal interface
955 local has_mon="0"
956 for phy_index in $( seq $start_idx $end_idx )
957 do
958 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
959 local prev_phy_index=$((phy_index-1))
960 local has_mon_phy=$(iw dev | awk "/phy#${phy_index}/,/phy#${prev_phy_index}/" | grep "Interface mon")
961 # if this phy interface has mon interface
962 if [ ! -z "${has_mon_phy}" ]; then
963 local has_mon="1"
964 fi
965 done
966
967 for phy_index in $( seq $start_idx $end_idx )
968 do
969 # "phy#-1" would not be in iw dev, therefore it will grep the line from the phy#${phy_index} to the end
970 local prev_phy_index=$((phy_index-1))
971 local j="1"
972 local add_if_num=$(get_config "DEL_IF${phy_index}_NUM" ${interface_file})
973 if [ -z "${add_if_num}" ]; then
974 local add_if_num="0"
975 fi
976 # if this phy interface (including its dbdc phy) has no mon interface and can find deleted interface in file, then add it back
977 if [ "${has_mon}" == "0" ] && [ $add_if_num -ge "1" ]; then
978 local if_index=$add_if_num
979 # add interface backwards
980 while [ $if_index -gt "0" ]
981 do
982 local add_if=$(get_config "DEL_IF${phy_index}-${if_index}" ${interface_file})
983 do_cmd "iw phy phy${phy_index} interface add ${add_if} type managed"
984 # remove the deleted interface in interface_file since it is added back
985 sed -i "/DEL_IF${phy_index}-${if_index}=/d" ${interface_file}
986 if_index=$((if_index-1))
987 done
988 # remove the number of deleted interface in interface_file since it is all added back
989 sed -i "/DEL_IF${phy_index}_NUM=/d" ${interface_file}
990 fi
991 done
992
developer461cb542022-04-29 18:17:44 +0800993 do_cmd "mt76-test ${interface} set aid=0"
developera6267142022-01-26 20:50:22 +0800994 fi
developer10946c32022-03-04 18:28:43 +0800995
developerf90c9af2022-12-28 22:40:23 +0800996 if [ ${phy_idx} -lt ${SOC_start_idx} ]; then
developer679a6aa2022-09-07 09:52:41 +0800997 sed -i '/_PCIE=/d' ${iwpriv_file}
developerf90c9af2022-12-28 22:40:23 +0800998 elif [ ${phy_idx} -ge ${SOC_start_idx} ]; then
999 sed -i '/_SOC=/d' ${iwpriv_file}
developer679a6aa2022-09-07 09:52:41 +08001000 fi
developera6267142022-01-26 20:50:22 +08001001 ;;
developer461cb542022-04-29 18:17:44 +08001002 "TXCOMMIT")
1003 do_cmd "mt76-test ${interface} set aid=1"
1004 ;;
developera6267142022-01-26 20:50:22 +08001005 "TXFRAME")
1006 do_cmd "mt76-test ${interface} set state=tx_frames"
1007 ;;
developer9b7cdad2022-03-10 14:24:55 +08001008 "TXSTOP"|"RXSTOP")
developera6267142022-01-26 20:50:22 +08001009 do_cmd "mt76-test ${interface} set state=idle"
1010 ;;
developer461cb542022-04-29 18:17:44 +08001011 "TXREVERT")
1012 do_cmd "mt76-test ${interface} set aid=0"
1013 ;;
developera6267142022-01-26 20:50:22 +08001014 "RXFRAME")
1015 do_cmd "mt76-test ${interface} set state=rx_frames"
1016 ;;
1017 "TXCONT")
1018 do_cmd "mt76-test ${interface} set state=tx_cont"
1019 ;;
developer071927d2022-08-31 20:39:29 +08001020 "GROUPREK")
1021 do_cmd "mt76-test ${interface} set state=group_prek"
1022 do_cmd "atenl -i ${interface} -c \"eeprom precal sync group\""
1023 ;;
1024 "GROUPREKDump")
1025 do_cmd "mt76-test ${interface} set state=group_prek_dump"
1026 ;;
1027 "GROUPREKClean")
1028 do_cmd "mt76-test ${interface} set state=group_prek_clean"
1029 do_cmd "atenl -i ${interface} -c \"eeprom precal group clean\""
1030 ;;
1031 "DPD2G")
1032 do_cmd "mt76-test ${interface} set state=dpd_2g"
1033 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 2g\""
1034 ;;
1035 "DPD5G")
1036 do_cmd "mt76-test ${interface} set state=dpd_5g"
1037 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 5g\""
1038 ;;
1039 "DPD6G")
1040 do_cmd "mt76-test ${interface} set state=dpd_6g"
1041 do_cmd "atenl -i ${interface} -c \"eeprom precal sync dpd 6g\""
1042 ;;
1043 "DPDDump")
1044 do_cmd "mt76-test ${interface} set state=dpd_dump"
1045 ;;
1046 "DPDClean")
1047 do_cmd "mt76-test ${interface} set state=dpd_clean"
1048 do_cmd "atenl -i ${interface} -c \"eeprom precal dpd clean\""
1049 ;;
developer9b7cdad2022-03-10 14:24:55 +08001050 *)
developer9b7cdad2022-03-10 14:24:55 +08001051 print_debug "skip ${ate_cmd}"
developera6267142022-01-26 20:50:22 +08001052 ;;
1053 esac
1054}
1055
developerf90c9af2022-12-28 22:40:23 +08001056function dump_usage {
1057 echo "Usage:"
1058 echo " mwctl <interface> set csi ctrl=<opt1>,<opt2>,<opt3>,<opt4> (macaddr=<macaddr>)"
1059 echo " mwctl <interface> set csi interval=<interval (us)>"
1060 echo " mwctl <interface> dump csi <packet num> <filename>"
1061 echo " mwctl <interface> set amnt <index>(0x0~0xf) <mac addr>(xx:xx:xx:xx:xx:xx)"
1062 echo " mwctl <interface> dump amnt <index> (0x0~0xf or 0xff)"
1063 echo " mwctl <interface> set ap_rfeatures he_gi=<val>"
1064 echo " mwctl <interface> set ap_rfeatures he_ltf=<val>"
1065 echo " mwctl <interface> set ap_rfeatures trig_type=<enable>,<val> (val: 0-7)"
1066 echo " mwctl <interface> set ap_rfeatures ack_policy=<val> (val: 0-4)"
1067 echo " mwctl <interface> set ap_wireless fixed_mcs=<val>"
1068 echo " mwctl <interface> set ap_wireless ofdma=<val> (0: disable, 1: DL, 2: UL)"
1069 echo " mwctl <interface> set ap_wireless nusers_ofdma=<val>"
1070 echo " mwctl <interface> set ap_wireless ppdu_type=<val> (0: SU, 1: MU, 4: LEGACY)"
1071 echo " mwctl <interface> set ap_wireless add_ba_req_bufsize=<val>"
1072 echo " mwctl <interface> set ap_wireless mimo=<val> (0: DL, 1: UL)"
1073 echo " mwctl <interface> set ap_wireless ampdu=<enable>"
1074 echo " mwctl <interface> set ap_wireless amsdu=<enable>"
1075 echo " mwctl <interface> set ap_wireless cert=<enable>"
1076 echo " mwctl <interface> set hemu onoff=<val> (bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0))"
1077 echo " mwctl <interface> dump phy_capa"
1078}
1079
developere3d5e5e2023-01-16 16:58:29 +08001080function register_handler {
1081
1082 local phy_idx=$1
1083 local offset=$2
1084 local val=$3
1085 local cmd=$4
1086 local w_cmd="write"
1087
1088 regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
1089 regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
1090
1091 echo ${offset} > ${regidx}
1092 if [[ "${cmd}" == "${w_cmd}" ]]; then
1093 echo ${val} > ${regval}
1094 fi
1095
1096 res=$(cat ${regval} | cut -d 'x' -f 2)
1097 printf "%s mac:[%s]:%s\n" ${interface_ori} ${offset} ${res}
1098}
1099
developer10946c32022-03-04 18:28:43 +08001100# main start here
developerb4b29472023-01-06 19:07:21 +08001101parse_sku
developerf90c9af2022-12-28 22:40:23 +08001102if [ -z ${interface} ]; then
1103 dump_usage
1104 exit
1105elif [[ ${interface} == "ra"* ]]; then
developereebce5c2022-08-26 19:05:56 +08001106 convert_interface $interface
developer10946c32022-03-04 18:28:43 +08001107fi
1108
developer679a6aa2022-09-07 09:52:41 +08001109tmp_work_mode=$(get_config "WORKMODE" ${iwpriv_file})
1110
1111if [ ! -z ${tmp_work_mode} ]; then
1112 work_mode=${tmp_work_mode}
1113fi
1114
developer10946c32022-03-04 18:28:43 +08001115cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
1116param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
1117
developer3abe1ad2022-01-24 11:13:32 +08001118if [ "${cmd_type}" = "set" ]; then
1119 skip=0
developer3abe1ad2022-01-24 11:13:32 +08001120 case ${cmd} in
developerf90c9af2022-12-28 22:40:23 +08001121 ## In wifi 7 chipset, testmode & vendor command both use mwctl
1122 ## Therefore this wrapper would translate it to either mt76-test or mt76-vendor based on the attribute of the command
1123 ## Translate to mt76-vendor command
1124 "csi"|"amnt"|"ap_rfeatures"|"ap_wireless"|"hemu")
developer249ac1b2023-02-09 09:54:38 +08001125 if [ ${is_eagle} == "1" ]; then
1126 do_cmd "hostapd_cli -i $*"
1127 skip=1
1128 else
1129 do_cmd "mt76-vendor $*"
1130 skip=1
developerf90c9af2022-12-28 22:40:23 +08001131 ;;
developer3abe1ad2022-01-24 11:13:32 +08001132 "ATE")
1133 do_ate_work ${param}
1134
1135 skip=1
1136 ;;
1137 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
1138 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
1139 cmd_new=$(simple_convert ${cmd})
developer679a6aa2022-09-07 09:52:41 +08001140 if [ "${param_new}" = "undefined" ]; then
1141 echo "unknown cmd: ${cmd}"
1142 exit
1143 fi
developer3abe1ad2022-01-24 11:13:32 +08001144 param_new=${param}
developer1346ce52022-12-15 21:36:14 +08001145 if [ "${cmd}" = "ATETXCNT" ] && [ "${param}" = "0" ]; then
1146 param_new="10000000"
1147 fi
developer3abe1ad2022-01-24 11:13:32 +08001148 ;;
1149 "ATETXANT"|"ATERXANT")
1150 cmd_new="tx_antenna"
1151 param_new=${param}
1152 ;;
1153 "ATETXGI")
developer679a6aa2022-09-07 09:52:41 +08001154 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE" ${iwpriv_file}))
developer3abe1ad2022-01-24 11:13:32 +08001155 convert_gi ${tx_mode} ${param}
1156 skip=1
1157 ;;
1158 "ATETXMODE")
1159 cmd_new="tx_rate_mode"
1160 param_new=$(convert_tx_mode ${param})
developer679a6aa2022-09-07 09:52:41 +08001161 if [ "${param_new}" = "undefined" ]; then
1162 echo "unknown tx mode"
1163 echo "0:cck, 1:ofdm, 2:ht, 4:vht, 8:he_su, 9:he_er, 10:he_tb, 11:he_mu"
1164 exit
1165 else
1166 record_config ${cmd} ${param} ${iwpriv_file}
1167 fi
developer3abe1ad2022-01-24 11:13:32 +08001168 ;;
1169 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3")
1170 cmd_new="tx_power"
1171 param_new="${param},0,0,0"
1172 ;;
1173 "ATETXBW")
developer679a6aa2022-09-07 09:52:41 +08001174 record_config ${cmd} ${param} ${iwpriv_file}
developer3abe1ad2022-01-24 11:13:32 +08001175 skip=1
1176 ;;
1177 "ATECHANNEL")
1178 convert_channel ${param}
1179 skip=1
1180 ;;
developer10946c32022-03-04 18:28:43 +08001181 "ATERXSTAT")
1182 convert_rxstat
1183 skip=1
1184 ;;
developer3abe1ad2022-01-24 11:13:32 +08001185 "ATECTRLBANDIDX")
developer10946c32022-03-04 18:28:43 +08001186 change_band_idx ${param}
developer3abe1ad2022-01-24 11:13:32 +08001187 skip=1
1188 ;;
developer10946c32022-03-04 18:28:43 +08001189 "ATEDA"|"ATESA"|"ATEBSSID")
1190 set_mac_addr ${cmd} ${param}
1191 skip=1
1192 ;;
developer887da632022-10-28 09:35:38 +08001193 "DfsRxCtrl"|"DfsRxHist")
1194 convert_dfs ${cmd} ${param}
1195 skip=1
1196 ;;
developer1346ce52022-12-15 21:36:14 +08001197 "ATETxBfInit"|"ATETxBfGdInit"|"ATEIBFPhaseComp"|"ATEEBfProfileConfig"|"ATEIBfProfileConfig"| \
1198 "TxBfTxApply"|"ATETxPacketWithBf"|"TxBfProfileData20MAllWrite"|"ATEIBfInstCal"| \
1199 "ATEIBfGdCal"|"ATEIBFPhaseE2pUpdate"|"TriggerSounding"|"StopSounding"| \
1200 "StaRecBfRead"|"TxBfProfileTagInValid"|"TxBfProfileTagWrite"|"TxBfProfileTagRead"| \
1201 "ATEIBFPhaseVerify"|"ATEConTxETxBfGdProc"|"ATEConTxETxBfInitProc")
developerf9843e22022-09-13 10:57:15 +08001202 convert_ibf ${cmd} ${param}
1203 skip=1
1204 ;;
developer3abe1ad2022-01-24 11:13:32 +08001205 "bufferMode")
1206 if [ "${param}" = "2" ]; then
developer461cb542022-04-29 18:17:44 +08001207 do_cmd "atenl -i ${interface} -c \"eeprom update buffermode\""
developer3abe1ad2022-01-24 11:13:32 +08001208 fi
1209 skip=1
1210 ;;
developera6267142022-01-26 20:50:22 +08001211 "ResetCounter"|"ATERXSTATRESET")
1212 skip=1
1213 ;;
developer679a6aa2022-09-07 09:52:41 +08001214 "WORKMODE")
1215 record_config "WORKMODE" ${param} ${iwpriv_file}
1216 echo "Entering ${param} mode in iwpriv"
1217 skip=1
1218 ;;
developer3abe1ad2022-01-24 11:13:32 +08001219 *)
developer9b7cdad2022-03-10 14:24:55 +08001220 print_debug "Unknown command to set: ${cmd}"
developer3abe1ad2022-01-24 11:13:32 +08001221 skip=1
1222 esac
1223
1224 if [ "${skip}" != "1" ]; then
1225 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
1226 fi
developer10946c32022-03-04 18:28:43 +08001227
developer3abe1ad2022-01-24 11:13:32 +08001228elif [ "${cmd_type}" = "show" ]; then
developer1346ce52022-12-15 21:36:14 +08001229 if [ "${cmd}" = "wtbl" ]; then
1230 wlan_idx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wlan_idx
1231 wtbl_info=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/wtbl_info
1232
1233 do_cmd "echo ${param} > ${wlan_idx}"
1234 do_cmd "cat ${wtbl_info}"
1235 else
1236 do_cmd "mt76-test ${interface} dump"
1237 do_cmd "mt76-test ${interface} dump stats"
1238 fi
developer10946c32022-03-04 18:28:43 +08001239
developer3abe1ad2022-01-24 11:13:32 +08001240elif [ "${cmd_type}" = "e2p" ]; then
developerf90c9af2022-12-28 22:40:23 +08001241 # support multiple read write
developera6267142022-01-26 20:50:22 +08001242 # eeprom offset write
1243 if [[ ${full_cmd} == *"="* ]]; then
developerf90c9af2022-12-28 22:40:23 +08001244 IFS=,
1245 for tuple in $full_cmd
1246 do
1247 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1248 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1249 offset=$(printf "0x%s" ${cmd})
1250 val=$(printf "0x%s" ${param})
1251 tmp=$((${val} & 0xff))
1252 tmp=$(printf "0x%x" ${tmp})
1253 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
developera6267142022-01-26 20:50:22 +08001254
developerf90c9af2022-12-28 22:40:23 +08001255 offset=$((${offset}))
1256 offset=$(expr ${offset} + "1")
1257 offset=$(printf "0x%x" ${offset})
1258 tmp=$(((${val} >> 8) & 0xff))
1259 tmp=$(printf "0x%x" ${tmp})
1260 do_cmd "atenl -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
1261 done
developera6267142022-01-26 20:50:22 +08001262 else
developerf90c9af2022-12-28 22:40:23 +08001263 IFS=,
1264 for tuple in $full_cmd
1265 do
1266 cmd=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 1)
1267 param=$(echo ${tuple} | sed s/=/' '/g | cut -d " " -f 2)
1268 offset=$(printf "0x%s" ${cmd})
1269 val=$(printf "0x%s" ${param})
1270 v1=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param}\"")
1271 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developer3abe1ad2022-01-24 11:13:32 +08001272
developerf90c9af2022-12-28 22:40:23 +08001273 tmp=$(printf "0x%s" ${param})
1274 tmp=$((${tmp}))
1275 param2=$(expr ${tmp} + "1")
1276 param2=$(printf "%x" ${param2})
1277 v2=$(do_cmd "atenl -i ${interface} -c \"eeprom read ${param2}\"")
1278 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developera6267142022-01-26 20:50:22 +08001279
developerf90c9af2022-12-28 22:40:23 +08001280 param=$(printf "0x%s" ${param})
1281 param=$(printf "%04x" ${param})
1282 param=$(echo $param | tr 'a-z' 'A-Z')
1283 printf "%s e2p:\n" ${interface_ori}
1284 printf "[0x%s]:0x%02x%02x\n" ${param} ${v2} ${v1}
1285 done
developera6267142022-01-26 20:50:22 +08001286 fi
developer10946c32022-03-04 18:28:43 +08001287
developera6267142022-01-26 20:50:22 +08001288elif [ "${cmd_type}" = "mac" ]; then
developera6267142022-01-26 20:50:22 +08001289 offset=$(printf "0x%s" ${cmd})
1290 val=$(printf "0x%s" ${param})
1291
developera6267142022-01-26 20:50:22 +08001292 # reg write
1293 if [[ ${full_cmd} == *"="* ]]; then
developere3d5e5e2023-01-16 16:58:29 +08001294 register_handler ${phy_idx} ${offset} ${val} "write"
1295 else
1296 start_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 1)
1297 end_addr=$(echo ${full_cmd} | sed s/-/' '/g | cut -d " " -f 2)
1298 loop=$((0x${end_addr}-0x${start_addr}))
developer10946c32022-03-04 18:28:43 +08001299
developere3d5e5e2023-01-16 16:58:29 +08001300 if [[ ${loop} == "0" ]]; then
1301 register_handler ${phy_idx} ${offset} ${val}
1302 else
1303 i=0
1304 while [ $i -le $loop ]; do
1305 addr=$((0x${start_addr}+$i))
1306 offset=$(printf "0x%x" ${addr})
1307 register_handler ${phy_idx} ${offset} ${val}
1308 i=$(($i + 4))
1309 done
1310 fi
1311 fi
developer461cb542022-04-29 18:17:44 +08001312
developerf90c9af2022-12-28 22:40:23 +08001313## dump command is only for vendor commands
1314elif [ "${cmd_type}" = "dump" ]; then
1315 do_cmd "mt76-vendor $*"
developer3abe1ad2022-01-24 11:13:32 +08001316else
1317 echo "Unknown command"
1318fi