blob: 075be04f45696fea8ed7b7d1d143d1a35f113ab8 [file] [log] [blame]
developer3abe1ad2022-01-24 11:13:32 +08001#!/bin/ash
2
3interface=$1
4cmd_type=$2
5full_cmd=$3
6
7work_mode="RUN" # RUN/PRINT/DEBUG
8tmp_file="$HOME/.tmp_ate_config"
9phy_idx=$(echo ${interface} | tr -dc '0-9')
10
11cmd=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 1)
12param=$(echo ${full_cmd} | sed s/=/' '/g | cut -d " " -f 2)
13
14function do_cmd() {
15 case ${work_mode} in
16 "RUN")
17 eval "$1"
18 ;;
19 "PRINT")
20 echo "$1"
21 ;;
22 "DEBUG")
23 eval "$1"
24 echo "$1"
25 ;;
26 esac
27}
28
29function record_config() {
30 if [ -f ${tmp_file} ]; then
31 if grep -q $1 ${tmp_file}; then
32 sed -i "/$1/c\\$1=$2" ${tmp_file}
33 else
34 echo "$1=$2" >> ${tmp_file}
35 fi
36 else
37 echo "$1=$2" >> ${tmp_file}
38 fi
39}
40
41function get_config() {
42 echo "$(cat ${tmp_file} | grep $1 | sed s/=/' '/g | cut -d " " -f 2)"
43}
44
developer3abe1ad2022-01-24 11:13:32 +080045function simple_convert() {
46 if [ "$1" = "ATETXCNT" ]; then
47 echo "tx_count"
48 elif [ "$1" = "ATETXLEN" ]; then
49 echo "tx_length"
50 elif [ "$1" = "ATETXMCS" ]; then
51 echo "tx_rate_idx"
52 elif [ "$1" = "ATEVHTNSS" ]; then
53 echo "tx_rate_nss"
54 elif [ "$1" = "ATETXLDPC" ]; then
55 echo "tx_rate_ldpc"
56 elif [ "$1" = "ATETXSTBC" ]; then
57 echo "tx_rate_stbc"
58 elif [ "$1" = "ATEPKTTXTIME" ]; then
59 echo "tx_time"
60 elif [ "$1" = "ATEIPG" ]; then
61 echo "tx_ipg"
62 elif [ "$1" = "ATEDUTYCYCLE" ]; then
63 echo "tx_duty_cycle"
64 elif [ "$1" = "ATETXFREQOFFSET" ]; then
65 echo "freq_offset"
66 else
67 echo "unknown"
68 fi
69}
70
71function convert_tx_mode() {
72 if [ "$1" = "0" ]; then
73 echo "cck"
74 elif [ "$1" = "1" ]; then
75 echo "ofdm"
76 elif [ "$1" = "2" ]; then
77 echo "ht"
78 elif [ "$1" = "4" ]; then
79 echo "vht"
80 elif [ "$1" = "8" ]; then
81 echo "he_su"
82 elif [ "$1" = "9" ]; then
83 echo "he_er"
84 elif [ "$1" = "10" ]; then
85 echo "he_tb"
86 elif [ "$1" = "11" ]; then
87 echo "he_mu"
88 else
89 echo "unknown"
90 fi
91}
92
93function convert_gi {
94 local tx_mode=$1
95 local val=$2
96 local sgi="0"
97 local he_ltf="0"
98
99 case ${tx_mode} in
100 "ht"|"vht")
101 sgi=${val}
102 ;;
103 "he_su"|"he_er")
104 case ${val} in
105 "0")
106 ;;
107 "1")
108 he_ltf="1"
109 ;;
110 "2")
111 sgi="1"
112 he_ltf="1"
113 ;;
114 "3")
115 sgi="2"
116 he_ltf="2"
117 ;;
118 "4")
119 he_ltf="2"
120 ;;
121 *)
122 echo "unknown gi"
123 esac
124 ;;
125 "he_mu")
126 case ${val} in
127 "0")
128 he_ltf="2"
129 ;;
130 "1")
131 he_ltf="1"
132 ;;
133 "2")
134 sgi="1"
135 he_ltf="1"
136 ;;
137 "3")
138 sgi="2"
139 he_ltf="2"
140 ;;
141 *)
142 echo "unknown gi"
143 esac
144 ;;
145 "he_tb")
146 case ${val} in
147 "0")
148 sgi="1"
149 ;;
150 "1")
151 sgi="1"
152 he_ltf="1"
153 ;;
154 "2")
155 sgi="2"
156 he_ltf="2"
157 ;;
158 *)
159 echo "unknown gi"
160 esac
161 ;;
162 *)
163 echo "unknown tx_rate_mode, can't transform gi"
164 esac
165
166 do_cmd "mt76-test ${interface} set tx_rate_sgi=${sgi} tx_ltf=${he_ltf}"
167}
168
169function convert_channel {
170 local band=$(echo $1 | sed s/:/' '/g | cut -d " " -f 2)
171 local ch=$(echo $1 | sed s/:/' '/g | cut -d " " -f 1)
172 local bw=$(get_config "ATETXBW" | cut -d ":" -f 1)
173
174 if [ "${band}" = "0" ]; then
175 case ${bw} in
176 "1")
177 if [ "${ch}" -ge "1" ] && [ "${ch}" -le "7" ]; then
178 local bw_str="HT40+"
179 else
180 local bw_str="HT40-"
181 fi
182 ;;
183 "0")
184 local bw_str="HT20"
185 ;;
186 esac
developera6267142022-01-26 20:50:22 +0800187 elif [ "${band}" = "1" ]; then
developer3abe1ad2022-01-24 11:13:32 +0800188 case ${bw} in
developera6267142022-01-26 20:50:22 +0800189 "5")
190 local bw_str="160MHz"
191 ;;
developer3abe1ad2022-01-24 11:13:32 +0800192 "2")
193 local bw_str="80MHz"
194 ;;
195 "1")
196 if [ "${ch}" == "36" ] || [ "${ch}" == "44" ] || [ "${ch}" == "52" ] || [ "${ch}" == "60" ] || \
197 [ "${ch}" == "100" ] || [ "${ch}" == "108" ] || [ "${ch}" == "116" ] || [ "${ch}" == "124" ] || \
198 [ "${ch}" == "132" ] || [ "${ch}" == "132" ] || [ "${ch}" == "140" ] || [ "${ch}" == "149" ] || \
199 [ "${ch}" == "157" ]
200 then
201 local bw_str="HT40+"
202 else
203 local bw_str="HT40-"
204 fi
205 ;;
206 "0")
207 local bw_str="HT20"
208 ;;
209 esac
developera6267142022-01-26 20:50:22 +0800210 else
211 echo "6G Todo"
developer3abe1ad2022-01-24 11:13:32 +0800212 fi
213
214 do_cmd "iw dev mon${phy_idx} set channel ${ch} ${bw_str}"
215}
216
developera6267142022-01-26 20:50:22 +0800217function do_ate_work() {
218 local ate_cmd=$1
219
220 case ${ate_cmd} in
221 "ATESTART")
222 local if_str=$(ifconfig | grep mon${phy_idx})
223
224 if [ ! -z "${if_str}" -a "${if_str}" != " " ]; then
225 echo "ATE already starts."
226 else
227 do_cmd "iw phy ${interface} interface add mon${phy_idx} type monitor"
228 do_cmd "iw dev wlan${phy_idx} del"
229 do_cmd "ifconfig mon${phy_idx} up"
230 fi
231 ;;
232 "ATESTOP")
233 local if_str=$(ifconfig | grep mon${phy_idx})
234
235 if [ -z "${if_str}" -a "${if_str}" != " " ]; then
236 echo "ATE does not start."
237 else
238 do_cmd "mt76-test ${interface} set state=off"
239 do_cmd "iw dev mon${phy_idx} del"
240 do_cmd "iw phy ${interface} interface add wlan${phy_idx} type managed"
241 do_cmd "ifconfig wlan${phy_idx} up"
242 fi
243 ;;
244 "TXFRAME")
245 do_cmd "mt76-test ${interface} set state=tx_frames"
246 ;;
247 "TXSTOP"|"RXSTOP"|"TXREVERT")
248 do_cmd "mt76-test ${interface} set state=idle"
249 ;;
250 "RXFRAME")
251 do_cmd "mt76-test ${interface} set state=rx_frames"
252 ;;
253 "TXCONT")
254 do_cmd "mt76-test ${interface} set state=tx_cont"
255 ;;
256 "TXCOMMIT")
257 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE"))
258 case ${tx_mode} in
259 "ht"|"vht"|"he_su")
260 do_cmd "mt76-test ${interface} set aid=1"
261 ;;
262 *)
263 ;;
264 esac
265 do_cmd "mt76-test ${interface} set state=idle"
266 ;;
267 esac
268}
269
developer3abe1ad2022-01-24 11:13:32 +0800270if [ "${cmd_type}" = "set" ]; then
271 skip=0
272 use_ated=0
273 case ${cmd} in
274 "ATE")
275 do_ate_work ${param}
276
277 skip=1
278 ;;
279 "ATETXCNT"|"ATETXLEN"|"ATETXMCS"|"ATEVHTNSS"|"ATETXLDPC"|"ATETXSTBC"| \
280 "ATEPKTTXTIME"|"ATEIPG"|"ATEDUTYCYCLE"|"ATETXFREQOFFSET")
281 cmd_new=$(simple_convert ${cmd})
282 param_new=${param}
283 ;;
284 "ATETXANT"|"ATERXANT")
285 cmd_new="tx_antenna"
286 param_new=${param}
287 ;;
288 "ATETXGI")
289 tx_mode=$(convert_tx_mode $(get_config "ATETXMODE"))
290 convert_gi ${tx_mode} ${param}
291 skip=1
292 ;;
293 "ATETXMODE")
294 cmd_new="tx_rate_mode"
295 param_new=$(convert_tx_mode ${param})
296 record_config ${cmd} ${param}
297 ;;
298 "ATETXPOW0"|"ATETXPOW1"|"ATETXPOW2"|"ATETXPOW3")
299 cmd_new="tx_power"
300 param_new="${param},0,0,0"
301 ;;
302 "ATETXBW")
303 record_config ${cmd} ${param}
304 skip=1
305 ;;
306 "ATECHANNEL")
307 convert_channel ${param}
308 skip=1
309 ;;
310 "ATECTRLBANDIDX")
311 echo "Unused command, please use phy0/phy1 to switch"
312 skip=1
313 ;;
314 "bufferMode")
315 if [ "${param}" = "2" ]; then
316 do_cmd "ated -i ${interface} -c \"eeprom update\""
317 fi
318 skip=1
319 ;;
developera6267142022-01-26 20:50:22 +0800320 "ResetCounter"|"ATERXSTATRESET")
321 skip=1
322 ;;
developer3abe1ad2022-01-24 11:13:32 +0800323 *)
324 echo "Unknown command to set"
325 skip=1
326 esac
327
328 if [ "${skip}" != "1" ]; then
329 do_cmd "mt76-test ${interface} set ${cmd_new}=${param_new}"
330 fi
331elif [ "${cmd_type}" = "show" ]; then
332 do_cmd "mt76-test ${interface} dump"
333 do_cmd "mt76-test ${interface} dump stats"
334elif [ "${cmd_type}" = "e2p" ]; then
developera6267142022-01-26 20:50:22 +0800335 offset=$(printf "0x%s" ${cmd})
336 val=$(printf "0x%s" ${param})
337
338 # eeprom offset write
339 if [[ ${full_cmd} == *"="* ]]; then
340 tmp=$((${val} & 0xff))
341 tmp=$(printf "0x%x" ${tmp})
342 do_cmd "ated -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
343
344 offset=$((${offset}))
345 offset=$(expr ${offset} + "1")
346 offset=$(printf "0x%x" ${offset})
347 tmp=$(((${val} >> 8) & 0xff))
348 tmp=$(printf "0x%x" ${tmp})
349 do_cmd "ated -i ${interface} -c \"eeprom set ${offset}=${tmp}\""
350 else
351 v1=$(do_cmd "ated -i ${interface} -c \"eeprom read ${param}\"")
352 v1=$(echo "${v1}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
developer3abe1ad2022-01-24 11:13:32 +0800353
developera6267142022-01-26 20:50:22 +0800354 tmp=$(printf "0x%s" ${param})
355 tmp=$((${tmp}))
356 param2=$(expr ${tmp} + "1")
357 param2=$(printf "%x" ${param2})
358 v2=$(do_cmd "ated -i ${interface} -c \"eeprom read ${param2}\"")
359 v2=$(echo "${v2}" | grep "val =" | cut -d '(' -f 2 | grep -o -E '[0-9]+')
360
361 param=$(printf "0x%s" ${param})
362 printf "[0x%04x]:0x%02x%02x\n" ${param} ${v2} ${v1}
363 fi
364elif [ "${cmd_type}" = "mac" ]; then
365 regidx=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regidx
366 regval=/sys/kernel/debug/ieee80211/phy${phy_idx}/mt76/regval
367 offset=$(printf "0x%s" ${cmd})
368 val=$(printf "0x%s" ${param})
369
370 echo ${offset} > ${regidx}
371 # reg write
372 if [[ ${full_cmd} == *"="* ]]; then
373 echo ${val} > ${regval}
374 else
375 res=$(cat ${regval} | cut -d 'x' -f 2)
376 printf "%s mac:[%s]:%s\n" ${interface} ${offset} ${res}
377 fi
developer3abe1ad2022-01-24 11:13:32 +0800378else
379 echo "Unknown command"
380fi