kernel: update linux 3.2 to 3.2.12
[openwrt.git] / package / ltq-dsl-app / files / dsl_control
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
3 START=99
4
5 . /lib/functions.sh
6
7 EXTRA_COMMANDS="status lucistat"
8 EXTRA_HELP=" status Get DSL status information
9 lucistat Get status information if lua friendly format"
10
11 SERVICE_DAEMONIZE=1
12 SERVICE_WRITE_PID=1
13
14 #
15 # Basic functions to send CLI commands to the dsl_cpe_control daemon
16 #
17 dsl_cmd() {
18 pkill -0 dsl_cpe_control && (
19 echo "$@" > /tmp/pipe/dsl_cpe0_cmd
20 cat /tmp/pipe/dsl_cpe0_ack
21 )
22 }
23 dsl_val() {
24 echo $(expr "$1" : '.*'$2'=\([-\.[:alnum:]]*\).*')
25 }
26
27 #
28 # Simple divide by 10 routine to cope with one decimal place
29 #
30 dbt() {
31 local a=$(expr $1 / 10)
32 local b=$(expr $1 % 10)
33 echo "${a}.${b}"
34 }
35 #
36 # Take a number and convert to k or meg
37 #
38 scale() {
39 local val=$1
40 local a
41 local b
42
43 if [ "$val" -gt 1000000 ]; then
44 a=$(expr $val / 1000)
45 b=$(expr $a % 1000)
46 a=$(expr $a / 1000)
47 printf "%d.%03d Mb" ${a} ${b}
48 elif [ "$val" -gt 1000 ]; then
49 a=$(expr $val / 1000)
50 printf "%d Kb" ${a}
51 else
52 echo "${val} b"
53 fi
54 }
55
56 #
57 # Read the data rates for both directions
58 #
59 data_rates() {
60 local csg
61 local dru
62 local drd
63 local sdru
64 local sdrd
65
66 csg=$(dsl_cmd g997csg 0 1)
67 drd=$(dsl_val "$csg" ActualDataRate)
68
69 csg=$(dsl_cmd g997csg 0 0)
70 dru=$(dsl_val "$csg" ActualDataRate)
71
72 [ -z "$drd" ] && drd=0
73 [ -z "$dru" ] && dru=0
74
75 sdrd=$(scale $drd)
76 sdru=$(scale $dru)
77
78 if [ "$action" = "lucistat" ]; then
79 echo "dsl.data_rate_down=$drd"
80 echo "dsl.data_rate_up=$dru"
81 echo "dsl.data_rate_down_s=\"$sdrd\""
82 echo "dsl.data_rate_up_s=\"$sdru\""
83 else
84 echo "Data Rate: ${sdrd}/s / ${sdru}/s"
85 fi
86 }
87
88 #
89 # Chipset
90 #
91 chipset() {
92 local vig
93 local cs
94 local csv
95
96 vig=$(dsl_cmd vig)
97 cs=$(dsl_val "$vig" DSL_ChipSetType)
98 csv=$(dsl_val "$vig" DSL_ChipSetHWVersion)
99
100 if [ "$action" = "lucistat" ]; then
101 echo "dsl.chipset=\"${cs} ${csv}\""
102 else
103 echo "Chipset: ${cs} ${csv}"
104 fi
105 }
106
107 #
108 # Work out how long the line has been up
109 #
110 line_uptime() {
111 local ccsg
112 local et
113 local etr
114 local d
115 local h
116 local m
117 local s
118 local rc=""
119
120 ccsg=$(dsl_cmd pmccsg 0 0 0)
121 et=$(dsl_val "$ccsg" nElapsedTime)
122
123 [ -z "$et" ] && et=0
124
125 if [ "$action" = "lucistat" ]; then
126 echo "dsl.line_uptime=${et}"
127 return
128 fi
129
130 d=$(expr $et / 86400)
131 etr=$(expr $et % 86400)
132 h=$(expr $etr / 3600)
133 etr=$(expr $etr % 3600)
134 m=$(expr $etr / 60)
135 s=$(expr $etr % 60)
136
137
138 [ "${d}${h}${m}${s}" -ne 0 ] && rc="${s}s"
139 [ "${d}${h}${m}" -ne 0 ] && rc="${m}m ${rc}"
140 [ "${d}${h}" -ne 0 ] && rc="${h}h ${rc}"
141 [ "${d}" -ne 0 ] && rc="${d}d ${rc}"
142
143 [ -z "$rc" ] && rc="down"
144 echo "Line Uptime: ${rc}"
145 }
146
147 #
148 # Get noise and attenuation figures
149 #
150 line_data() {
151 local lsg
152 local latnu
153 local latnd
154 local snru
155 local snrd
156
157 lsg=$(dsl_cmd g997lsg 1 1)
158 latnd=$(dsl_val "$lsg" LATN)
159 snrd=$(dsl_val "$lsg" SNR)
160
161 lsg=$(dsl_cmd g997lsg 0 1)
162 latnu=$(dsl_val "$lsg" LATN)
163 snru=$(dsl_val "$lsg" SNR)
164
165 [ -z "$latnd" ] && latnd=0
166 [ -z "$latnu" ] && latnu=0
167 [ -z "$snrd" ] && snrd=0
168 [ -z "$snru" ] && snru=0
169
170 latnd=$(dbt $latnd)
171 latnu=$(dbt $latnu)
172 snrd=$(dbt $snrd)
173 snru=$(dbt $snru)
174
175 if [ "$action" = "lucistat" ]; then
176 echo "dsl.line_attenuation_down=$latnd"
177 echo "dsl.line_attenuation_up=$latnu"
178 echo "dsl.noise_margin_down=$snrd"
179 echo "dsl.noise_margin_up=$snru"
180 else
181 echo "Line Attenuation: ${latnd}dB / ${latnu}dB"
182 echo "Noise Margin: ${snrd}dB / ${snru}dB"
183 fi
184 }
185
186 #
187 # Is the line up? Or what state is it in?
188 #
189 line_state() {
190 local lsg=$(dsl_cmd lsg)
191 local ls=$(dsl_val "$lsg" nLineState);
192 local s;
193
194 case "$ls" in
195 "0x0") s="not initialized" ;;
196 "0x1") s="exception" ;;
197 "0x10") s="not updated" ;;
198 "0xff") s="idle request" ;;
199 "0x100") s="idle" ;;
200 "0x1ff") s="silent request" ;;
201 "0x200") s="silent" ;;
202 "0x300") s="handshake" ;;
203 "0x380") s="full_init" ;;
204 "0x400") s="discovery" ;;
205 "0x500") s="training" ;;
206 "0x600") s="analysis" ;;
207 "0x700") s="exchange" ;;
208 "0x800") s="showtime_no_sync" ;;
209 "0x801") s="showtime_tc_sync" ;;
210 "0x900") s="fastretrain" ;;
211 "0xa00") s="lowpower_l2" ;;
212 "0xb00") s="loopdiagnostic active" ;;
213 "0xb10") s="loopdiagnostic data exchange" ;;
214 "0xb20") s="loopdiagnostic data request" ;;
215 "0xc00") s="loopdiagnostic complete" ;;
216 "0x1000000") s="test" ;;
217 "0xd00") s="resync" ;;
218 "0x3c0") s="short init entry" ;;
219 "") s="not running daemon"; ls="0xfff" ;;
220 *) s="unknown" ;;
221 esac
222
223 if [ $action = "lucistat" ]; then
224 echo "dsl.line_state_num=$ls"
225 echo "dsl.line_state_detail=\"$s\""
226 if [ "$ls" = "0x801" ]; then
227 echo "dsl.line_state=\"UP\""
228 else
229 echo "dsl.line_state=\"DOWN\""
230 fi
231 else
232 if [ "$ls" = "0x801" ]; then
233 echo "Line State: UP [$ls: $s]"
234 else
235 echo "Line State: DOWN [$ls: $s]"
236 fi
237 fi
238 }
239
240 #
241 # Main status routine
242 #
243 status() {
244 chipset
245 line_state
246 data_rates
247 line_data
248 line_uptime
249 }
250
251 #
252 # Luci (lua) compatible version that's easy to parse
253 #
254 lucistat() {
255 echo "local dsl={}"
256 status
257 echo "return dsl"
258 }
259
260
261 annex_b=10_00_10_00_00_04_00_00
262 annex_bdmt=10_00_00_00_00_00_00_00
263 annex_b2=00_00_10_00_00_00_00_00
264 annex_b2p=00_00_00_00_00_04_00_00
265 annex_a=04_01_04_00_00_01_00_00
266 annex_at1=01_00_00_00_00_00_00_00
267 annex_alite=00_01_00_00_00_00_00_00
268 annex_admt=04_00_00_00_00_00_00_00
269 annex_a2=00_00_04_00_00_00_00_00
270 annex_a2p=00_00_00_00_00_01_00_00
271 annex_l=00_00_00_00_04_00_00_00
272 annex_m=00_00_00_00_40_00_04_00
273 annex_m2=00_00_00_00_40_00_00_00
274 annex_m2p=00_00_00_00_00_00_04_00
275
276 #
277 # Simple start routine
278 #
279 start() {
280 local annex
281 local xtu
282 config_load network
283 config_get annex atm annex
284
285 # get xtu
286 eval "xtu=\"\${annex_$annex}\""
287
288 # check for invalid annex mode
289 [ -n "${annex}" -a -z "${xtu}" ] &&
290 echo "unknown annex mode $annex"
291
292 # start CPE dsl daemon in the background
293 service_start /sbin/dsl_cpe_control -i${xtu} \
294 -n /sbin/dsl_notify.sh \
295 -f /lib/firmware/ModemHWE.bin
296 }
297
298 #
299 # For stop we want to simulate the notification call for when
300 # the line goes down, so that we can stop the ppp link before
301 # we die.
302 #
303 stop() {
304 DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
305 DSL_INTERFACE_STATUS="DOWN" \
306 /sbin/dsl_notify.sh
307
308 service_stop /sbin/dsl_cpe_control
309 }
310
This page took 0.073937 seconds and 5 git commands to generate.