developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 1 | #!/bin/ash |
| 2 | # This script is used for wrapping atenl daemon to ated |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame^] | 3 | # 0 is normal mode, 1 is used for doing specific commands such as "sync eeprom all" |
developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 4 | |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame^] | 5 | work_mode="RUN" # RUN/PRINT/DEBUG |
developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 6 | mode="0" |
| 7 | add_quote="0" |
| 8 | cmd="atenl" |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame^] | 9 | interface="" |
| 10 | phy_idx=0 |
| 11 | ated_file="/tmp/interface" |
| 12 | |
| 13 | function 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 | |
| 28 | function 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 | |
| 41 | function 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 | |
| 55 | function 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 | |
developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 91 | |
| 92 | for i in "$@" |
| 93 | do |
| 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 |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame^] | 102 | if [[ ${i} == "ra"* ]]; then |
| 103 | convert_interface $i |
| 104 | cmd="${cmd} ${interface}" |
| 105 | else |
| 106 | cmd="${cmd} ${i}" |
developer | 9b7cdad | 2022-03-10 14:24:55 +0800 | [diff] [blame] | 107 | fi |
developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 108 | fi |
| 109 | done |
| 110 | |
| 111 | if [ "$mode" = "0" ]; then |
developer | 461cb54 | 2022-04-29 18:17:44 +0800 | [diff] [blame] | 112 | killall atenl > /dev/null 2>&1 |
developer | 3abe1ad | 2022-01-24 11:13:32 +0800 | [diff] [blame] | 113 | fi |
| 114 | |
developer | 679a6aa | 2022-09-07 09:52:41 +0800 | [diff] [blame^] | 115 | do_cmd "${cmd}" |