blob: 1c24083b5c98450b3f1200e13ce70e2255057627 [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"
12
13function do_cmd() {
14 case ${work_mode} in
15 "RUN")
16 eval "$1"
17 ;;
18 "PRINT")
19 echo "$1"
20 ;;
21 "DEBUG")
22 eval "$1"
23 echo "$1"
24 ;;
25 esac
26}
27
28function record_config() {
29 local tmp_file=$3
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 local tmp_file=$2
43 if [ ! -f ${tmp_file} ]; then
44 echo ""
45 return
46 fi
47
48 if grep -q $1 ${tmp_file}; then
49 echo "$(cat ${tmp_file} | grep $1 | sed s/=/' '/g | cut -d " " -f 2)"
50 else
51 echo ""
52 fi
53}
54
55function convert_interface {
56 local start_idx_7986=$(get_config "STARTIDX" ${ated_file})
57 local eeprom_file=/sys/kernel/debug/ieee80211/phy0/mt76/eeprom
58 if [ -z "${start_idx_7986}" ]; then
59 if [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7916")" ]; then
60 start_idx_7986="2"
61 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7915")" ]; then
62 start_idx_7986="1"
63 elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7986")" ]; then
64 start_idx_7986="0"
65 else
66 echo "Interface conversion failed!"
67 echo "Please use ated -i <phy0/phy1/..> ... or configure the sku of your board manually by the following commands"
68 echo "For AX6000: echo STARTIDX=0 >> ${ated_file}"
69 echo "For AX7800: echo STARTIDX=2 >> ${ated_file}"
70 echo "For AX8400: echo STARTIDX=1 >> ${ated_file}"
71 return 0
72 fi
73 record_config "STARTIDX" ${start_idx_7986} ${ated_file}
74 fi
75
76 if [[ $1 == "raix"* ]]; then
77 interface="phy1"
78 phy_idx=1
79 elif [[ $1 == "rai"* ]]; then
80 interface="phy0"
81 phy_idx=0
82 elif [[ $1 == "rax"* ]]; then
83 phy_idx=$((start_idx_7986+1))
84 interface="phy${phy_idx}"
85 else
86 phy_idx=$start_idx_7986
87 interface="phy${phy_idx}"
88 fi
89}
90
developer3abe1ad2022-01-24 11:13:32 +080091
92for i in "$@"
93do
94 if [ "$i" = "-c" ]; then
95 cmd="${cmd} -c"
96 mode="1"
97 add_quote="1"
98 elif [ "${add_quote}" = "1" ]; then
99 cmd="${cmd} \"${i}\""
100 add_quote="0"
101 else
developer679a6aa2022-09-07 09:52:41 +0800102 if [[ ${i} == "ra"* ]]; then
103 convert_interface $i
104 cmd="${cmd} ${interface}"
105 else
106 cmd="${cmd} ${i}"
developer9b7cdad2022-03-10 14:24:55 +0800107 fi
developer3abe1ad2022-01-24 11:13:32 +0800108 fi
109done
110
111if [ "$mode" = "0" ]; then
developer461cb542022-04-29 18:17:44 +0800112 killall atenl > /dev/null 2>&1
developer3abe1ad2022-01-24 11:13:32 +0800113fi
114
developer679a6aa2022-09-07 09:52:41 +0800115do_cmd "${cmd}"