blob: e989e446cd785f494524a923e38dc05d40ec51dd [file] [log] [blame]
developer4616dbd2022-10-11 13:18:59 +08001#!/bin/ash
2# This script is used for wrapping atenl daemon to ated
3# 0 is normal mode, 1 is used for doing specific commands such as "sync eeprom all"
4
5work_mode="RUN" # RUN/PRINT/DEBUG
6mode="0"
7add_quote="0"
8cmd="atenl"
9interface=""
10phy_idx=0
11ated_file="/tmp/interface"
developerb9a96602023-01-10 19:53:25 +080012SOC_start_idx="0"
13is_eagle="0"
developer4616dbd2022-10-11 13:18:59 +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() {
developerb9a96602023-01-10 19:53:25 +080031 local config=$1
developer4616dbd2022-10-11 13:18:59 +080032 local tmp_file=$3
developerb9a96602023-01-10 19:53:25 +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
developer4616dbd2022-10-11 13:18:59 +080043 if [ -f ${tmp_file} ]; then
developerb9a96602023-01-10 19:53:25 +080044 if grep -q ${config} ${tmp_file}; then
45 sed -i "/${config}/c\\${config}=$2" ${tmp_file}
developer4616dbd2022-10-11 13:18:59 +080046 else
developerb9a96602023-01-10 19:53:25 +080047 echo "${config}=$2" >> ${tmp_file}
developer4616dbd2022-10-11 13:18:59 +080048 fi
49 else
developerb9a96602023-01-10 19:53:25 +080050 echo "${config}=$2" >> ${tmp_file}
developer4616dbd2022-10-11 13:18:59 +080051 fi
52}
53
54function get_config() {
developerb9a96602023-01-10 19:53:25 +080055 local config=$1
developer4616dbd2022-10-11 13:18:59 +080056 local tmp_file=$2
developerb9a96602023-01-10 19:53:25 +080057
developer4616dbd2022-10-11 13:18:59 +080058 if [ ! -f ${tmp_file} ]; then
59 echo ""
60 return
61 fi
62
developerb9a96602023-01-10 19:53:25 +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)"
developer4616dbd2022-10-11 13:18:59 +080074 else
75 echo ""
76 fi
77}
78
79function convert_interface {
developerb9a96602023-01-10 19:53:25 +080080 SOC_start_idx=$(get_config "STARTIDX" ${ated_file})
81 is_eagle=$(get_config "IS_EAGLE" ${ated_file})
developer4616dbd2022-10-11 13:18:59 +080082 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
developerb9a96602023-01-10 19:53:25 +080083 if [ -z "${SOC_start_idx}" ] || [ -z "${is_eagle}" ]; then
developer4616dbd2022-10-11 13:18:59 +080084 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
developerb9a96602023-01-10 19:53:25 +080085 SOC_start_idx="2"
86 is_eagle="0"
developer4616dbd2022-10-11 13:18:59 +080087 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
developerb9a96602023-01-10 19:53:25 +080088 SOC_start_idx="1"
89 is_eagle="0"
developer4616dbd2022-10-11 13:18:59 +080090 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
developerb9a96602023-01-10 19:53:25 +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"
developer4616dbd2022-10-11 13:18:59 +080096 else
developerb9a96602023-01-10 19:53:25 +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}"
developer4616dbd2022-10-11 13:18:59 +0800100 echo "For AX7800: echo STARTIDX=2 >> ${ated_file}"
101 echo "For AX8400: echo STARTIDX=1 >> ${ated_file}"
developerb9a96602023-01-10 19:53:25 +0800102 exit 0
developer4616dbd2022-10-11 13:18:59 +0800103 fi
developerb9a96602023-01-10 19:53:25 +0800104 record_config "STARTIDX" ${SOC_start_idx} ${ated_file}
105 record_config "IS_EAGLE" ${is_eagle} ${ated_file}
developer4616dbd2022-10-11 13:18:59 +0800106 fi
107
developerb9a96602023-01-10 19:53:25 +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
developer4616dbd2022-10-11 13:18:59 +0800137 else
developerb9a96602023-01-10 19:53:25 +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
developer4616dbd2022-10-11 13:18:59 +0800149 fi
developer4616dbd2022-10-11 13:18:59 +0800150
developerb9a96602023-01-10 19:53:25 +0800151 interface="phy${phy_idx}"
152}
developer4616dbd2022-10-11 13:18:59 +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
164 if [[ ${i} == "ra"* ]]; then
165 convert_interface $i
166 cmd="${cmd} ${interface}"
167 else
168 cmd="${cmd} ${i}"
169 fi
170 fi
171done
172
173if [ "$mode" = "0" ]; then
174 killall atenl > /dev/null 2>&1
175fi
176
177do_cmd "${cmd}"