blob: e989e446cd785f494524a923e38dc05d40ec51dd [file] [log] [blame]
developer3abe1ad2022-01-24 11:13:32 +08001#!/bin/ash
2# This script is used for wrapping atenl daemon to ated
developer679a6aa2022-09-07 09:52:41 +08003# 0 is normal mode, 1 is used for doing specific commands such as "sync eeprom all"
developer3abe1ad2022-01-24 11:13:32 +08004
developer679a6aa2022-09-07 09:52:41 +08005work_mode="RUN" # RUN/PRINT/DEBUG
developer3abe1ad2022-01-24 11:13:32 +08006mode="0"
7add_quote="0"
8cmd="atenl"
developer679a6aa2022-09-07 09:52:41 +08009interface=""
10phy_idx=0
11ated_file="/tmp/interface"
developerf90c9af2022-12-28 22:40:23 +080012SOC_start_idx="0"
13is_eagle="0"
developer679a6aa2022-09-07 09:52:41 +080014
15function do_cmd() {
16 case ${work_mode} in
17 "RUN")
18 eval "$1"
19 ;;
20 "PRINT")
21 echo "$1"
22 ;;
23 "DEBUG")
24 eval "$1"
25 echo "$1"
26 ;;
27 esac
28}
29
30function record_config() {
developerf90c9af2022-12-28 22:40:23 +080031 local config=$1
developer679a6aa2022-09-07 09:52:41 +080032 local tmp_file=$3
developerf90c9af2022-12-28 22:40:23 +080033
34 # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
35 if [ ${config} != "STARTIDX" ] && [ ${config} != "IS_EAGLE" ]; then
36 if [ $phy_idx -lt $SOC_start_idx ]; then
37 config="${config}_PCIE"
38 elif [ $phy_idx -ge $SOC_start_idx ]; then
39 config="${config}_SOC"
40 fi
41 fi
42
developer679a6aa2022-09-07 09:52:41 +080043 if [ -f ${tmp_file} ]; then
developerf90c9af2022-12-28 22:40:23 +080044 if grep -q ${config} ${tmp_file}; then
45 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
developer679a6aa2022-09-07 09:52:41 +080046 else
developerf90c9af2022-12-28 22:40:23 +080047 echo "${config}=$2" >> ${tmp_file}
developer679a6aa2022-09-07 09:52:41 +080048 fi
49 else
developerf90c9af2022-12-28 22:40:23 +080050 echo "${config}=$2" >> ${tmp_file}
developer679a6aa2022-09-07 09:52:41 +080051 fi
52}
53
54function get_config() {
developerf90c9af2022-12-28 22:40:23 +080055 local config=$1
developer679a6aa2022-09-07 09:52:41 +080056 local tmp_file=$2
developerf90c9af2022-12-28 22:40:23 +080057
developer679a6aa2022-09-07 09:52:41 +080058 if [ ! -f ${tmp_file} ]; then
59 echo ""
60 return
61 fi
62
developerf90c9af2022-12-28 22:40:23 +080063 # check it is SOC(mt7986)/Eagle or PCIE card (mt7915/7916), and write its config
64 if [ ${config} != "STARTIDX" ] && [ ${config} != "IS_EAGLE" ]; then
65 if [ $phy_idx -lt $SOC_start_idx ]; then
66 config="${config}_PCIE"
67 elif [ $phy_idx -ge $SOC_start_idx ]; then
68 config="${config}_SOC"
69 fi
70 fi
71
72 if grep -q ${config} ${tmp_file}; then
73 echo "$(cat ${tmp_file} | grep ${config} | sed s/=/' '/g | cut -d " " -f 2)"
developer679a6aa2022-09-07 09:52:41 +080074 else
75 echo ""
76 fi
77}
78
79function convert_interface {
developerf90c9af2022-12-28 22:40:23 +080080 SOC_start_idx=$(get_config "STARTIDX" ${ated_file})
81 is_eagle=$(get_config "IS_EAGLE" ${ated_file})
developer679a6aa2022-09-07 09:52:41 +080082 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
developerf90c9af2022-12-28 22:40:23 +080083 if [ -z "${SOC_start_idx}" ] || [ -z "${is_eagle}" ]; then
developer679a6aa2022-09-07 09:52:41 +080084 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
developerf90c9af2022-12-28 22:40:23 +080085 SOC_start_idx="2"
86 is_eagle="0"
developer679a6aa2022-09-07 09:52:41 +080087 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
developerf90c9af2022-12-28 22:40:23 +080088 SOC_start_idx="1"
89 is_eagle="0"
developer679a6aa2022-09-07 09:52:41 +080090 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
developerf90c9af2022-12-28 22:40:23 +080091 SOC_start_idx="0"
92 is_eagle="0"
93 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7990")" ]; then
94 SOC_start_idx="0"
95 is_eagle="1"
developer679a6aa2022-09-07 09:52:41 +080096 else
developerf90c9af2022-12-28 22:40:23 +080097 echo "Interface Conversion Failed!"
98 echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
99 echo "For AX6000/Eagle: echo STARTIDX=0 >> ${ated_file}"
developer679a6aa2022-09-07 09:52:41 +0800100 echo "For AX7800: echo STARTIDX=2 >> ${ated_file}"
101 echo "For AX8400: echo STARTIDX=1 >> ${ated_file}"
developerf90c9af2022-12-28 22:40:23 +0800102 exit 0
developer679a6aa2022-09-07 09:52:41 +0800103 fi
developerf90c9af2022-12-28 22:40:23 +0800104 record_config "STARTIDX" ${SOC_start_idx} ${ated_file}
105 record_config "IS_EAGLE" ${is_eagle} ${ated_file}
developer679a6aa2022-09-07 09:52:41 +0800106 fi
107
developerf90c9af2022-12-28 22:40:23 +0800108
109 if [ ${is_eagle} == "0" ]; then
110 if [[ $1 == "raix"* ]]; then
111 phy_idx=1
112 elif [[ $1 == "rai"* ]]; then
113 phy_idx=0
114 elif [[ $1 == "rax"* ]]; then
115 phy_idx=$((SOC_start_idx+1))
116 else
117 phy_idx=$SOC_start_idx
118 fi
119
120 # convert phy index according to band idx
121 local band_idx=$(get_config "ATECTRLBANDIDX" ${ated_file})
122 if [ "${band_idx}" = "0" ]; then
123 if [[ $1 == "raix"* ]]; then
124 phy_idx=0
125 elif [[ $1 == "rax"* ]]; then
126 phy_idx=$SOC_start_idx
127 fi
128 elif [ "${band_idx}" = "1" ]; then
129 if [[ $1 == "rai"* ]]; then
130 # AX8400: mt7915 remain phy0
131 # AX7800: mt7916 becomes phy1
132 phy_idx=$((SOC_start_idx-1))
133 elif [[ $1 == "ra"* ]]; then
134 phy_idx=$((SOC_start_idx+1))
135 fi
136 fi
developer679a6aa2022-09-07 09:52:41 +0800137 else
developerf90c9af2022-12-28 22:40:23 +0800138 # Eagle has different mapping method
139 # phy0: ra0
140 # phy1: rai0
141 # phy2: rax0
142 if [[ $1 == "rai"* ]]; then
143 phy_idx=1
144 elif [[ $1 == "rax"* ]]; then
145 phy_idx=2
146 else
147 phy_idx=0
148 fi
developer679a6aa2022-09-07 09:52:41 +0800149 fi
developer679a6aa2022-09-07 09:52:41 +0800150
developerf90c9af2022-12-28 22:40:23 +0800151 interface="phy${phy_idx}"
152}
developer3abe1ad2022-01-24 11:13:32 +0800153
154for i in "$@"
155do
156 if [ "$i" = "-c" ]; then
157 cmd="${cmd} -c"
158 mode="1"
159 add_quote="1"
160 elif [ "${add_quote}" = "1" ]; then
161 cmd="${cmd} \"${i}\""
162 add_quote="0"
163 else
developer679a6aa2022-09-07 09:52:41 +0800164 if [[ ${i} == "ra"* ]]; then
165 convert_interface $i
166 cmd="${cmd} ${interface}"
167 else
168 cmd="${cmd} ${i}"
developer9b7cdad2022-03-10 14:24:55 +0800169 fi
developer3abe1ad2022-01-24 11:13:32 +0800170 fi
171done
172
173if [ "$mode" = "0" ]; then
developer461cb542022-04-29 18:17:44 +0800174 killall atenl > /dev/null 2>&1
developer3abe1ad2022-01-24 11:13:32 +0800175fi
176
developer679a6aa2022-09-07 09:52:41 +0800177do_cmd "${cmd}"