1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
7 EXTRA_COMMANDS="status lucistat"
8 EXTRA_HELP=" status Get DSL status information
9 lucistat Get status information if lua friendly format"
15 # Basic functions to send CLI commands to the dsl_cpe_control daemon
18 killall -0 dsl_cpe_control && (
19 echo "$@" > /tmp/pipe/dsl_cpe0_cmd
20 cat /tmp/pipe/dsl_cpe0_ack
24 echo $(expr "$1" : '.*'$2'=\([-\.[:alnum:]]*\).*')
28 # Simple divide by 10 routine to cope with one decimal place
31 local a=$(expr $1 / 10)
32 local b=$(expr $1 % 10)
36 # Take a number and convert to k or meg
43 if [ "$val" -gt 1000000 ]; then
47 printf "%d.%03d Mb" ${a} ${b}
48 elif [ "$val" -gt 1000 ]; then
57 # Read the data rates for both directions
66 csg=$(dsl_cmd g997csg 0 1)
67 drd=$(dsl_val "$csg" ActualDataRate)
69 csg=$(dsl_cmd g997csg 0 0)
70 dru=$(dsl_val "$csg" ActualDataRate)
72 [ -z "$drd" ] && drd=0
73 [ -z "$dru" ] && dru=0
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\""
84 echo "Data Rate: ${sdrd}/s / ${sdru}/s"
97 cs=$(dsl_val "$vig" DSL_ChipSetType)
98 csv=$(dsl_val "$vig" DSL_ChipSetHWVersion)
100 if [ "$action" = "lucistat" ]; then
101 echo "dsl.chipset=\"${cs} ${csv}\""
103 echo "Chipset: ${cs} ${csv}"
108 # Work out how long the line has been up
120 ccsg=$(dsl_cmd pmccsg 0 0 0)
121 et=$(dsl_val "$ccsg" nElapsedTime)
125 if [ "$action" = "lucistat" ]; then
126 echo "dsl.line_uptime=${et}"
130 d=$(expr $et / 86400)
131 etr=$(expr $et % 86400)
132 h=$(expr $etr / 3600)
133 etr=$(expr $etr % 3600)
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}"
143 [ -z "$rc" ] && rc="down"
144 echo "Line Uptime: ${rc}"
148 # Get noise and attenuation figures
157 lsg=$(dsl_cmd g997lsg 1 1)
158 latnd=$(dsl_val "$lsg" LATN)
159 snrd=$(dsl_val "$lsg" SNR)
161 lsg=$(dsl_cmd g997lsg 0 1)
162 latnu=$(dsl_val "$lsg" LATN)
163 snru=$(dsl_val "$lsg" SNR)
165 [ -z "$latnd" ] && latnd=0
166 [ -z "$latnu" ] && latnu=0
167 [ -z "$snrd" ] && snrd=0
168 [ -z "$snru" ] && snru=0
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"
181 echo "Line Attenuation: ${latnd}dB / ${latnu}dB"
182 echo "Noise Margin: ${snrd}dB / ${snru}dB"
187 # Is the line up? Or what state is it in?
190 local lsg=$(dsl_cmd lsg)
191 local ls=$(dsl_val "$lsg" nLineState);
195 "0x0") s="not initialized" ;;
196 "0x1") s="exception" ;;
197 "0x10") s="not updated" ;;
198 "0xff") s="idle request" ;;
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" ;;
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\""
229 echo "dsl.line_state=\"DOWN\""
232 if [ "$ls" = "0x801" ]; then
233 echo "Line State: UP [$ls: $s]"
235 echo "Line State: DOWN [$ls: $s]"
241 # Main status routine
252 # Luci (lua) compatible version that's easy to parse
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
277 # Simple start routine
284 config_get annex adsl annex
285 config_get fwannex adsl fwannex
288 eval "xtu=\"\${annex_$annex}\""
290 # check for invalid annex mode
291 [ -n "${annex}" -a -z "${xtu}" ] &&
292 echo "unknown annex mode $annex"
294 # check for invalid fw annex mode
295 [[ "$fwannex" != "a" && "$fwannex" != "b" ]] &&
296 echo "invalid fwannex: $fwannex"
298 # start CPE dsl daemon in the background
299 service_start /sbin/dsl_cpe_control -i${xtu} \
300 -n /sbin/dsl_notify.sh \
301 -f /lib/firmware/dsl-fw-${fwannex}.bin
305 # For stop we want to simulate the notification call for when
306 # the line goes down, so that we can stop the ppp link before
310 DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
311 DSL_INTERFACE_STATUS="DOWN" \
314 service_stop /sbin/dsl_cpe_control