1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
5 EXTRA_COMMANDS="status lucistat"
6 EXTRA_HELP=" status Get DSL status information
7 lucistat Get status information if lua friendly format"
13 # Basic functions to send CLI commands to the dsl_cpe_control daemon
16 pkill -0 dsl_cpe_control && (
17 echo "$@" > /tmp/pipe/dsl_cpe0_cmd
18 cat /tmp/pipe/dsl_cpe0_ack
22 echo $(expr "$1" : '.*'$2'=\([-\.[:alnum:]]*\).*')
26 # Simple divide by 10 routine to cope with one decimal place
29 local a=$(expr $1 / 10)
30 local b=$(expr $1 % 10)
34 # Take a number and convert to k or meg
41 if [ "$val" -gt 1000000 ]; then
45 printf "%d.%03d Mb" ${a} ${b}
46 elif [ "$val" -gt 1000 ]; then
55 # Read the data rates for both directions
64 csg=$(dsl_cmd g997csg 0 1)
65 drd=$(dsl_val "$csg" ActualDataRate)
67 csg=$(dsl_cmd g997csg 0 0)
68 dru=$(dsl_val "$csg" ActualDataRate)
70 [ -z "$drd" ] && drd=0
71 [ -z "$dru" ] && dru=0
76 if [ "$action" = "lucistat" ]; then
77 echo "dsl.data_rate_down=$drd"
78 echo "dsl.data_rate_up=$dru"
79 echo "dsl.data_rate_down_s=\"$sdrd\""
80 echo "dsl.data_rate_up_s=\"$sdru\""
82 echo "Data Rate: ${sdrd}/s / ${sdru}/s"
95 cs=$(dsl_val "$vig" DSL_ChipSetType)
96 csv=$(dsl_val "$vig" DSL_ChipSetHWVersion)
98 if [ "$action" = "lucistat" ]; then
99 echo "dsl.chipset=\"${cs} ${csv}\""
101 echo "Chipset: ${cs} ${csv}"
106 # Work out how long the line has been up
118 ccsg=$(dsl_cmd pmccsg 0 0 0)
119 et=$(dsl_val "$ccsg" nElapsedTime)
123 if [ "$action" = "lucistat" ]; then
124 echo "dsl.line_uptime=${et}"
128 d=$(expr $et / 86400)
129 etr=$(expr $et % 86400)
130 h=$(expr $etr / 3600)
131 etr=$(expr $etr % 3600)
136 [ "${d}${h}${m}${s}" -ne 0 ] && rc="${s}s"
137 [ "${d}${h}${m}" -ne 0 ] && rc="${m}m ${rc}"
138 [ "${d}${h}" -ne 0 ] && rc="${h}h ${rc}"
139 [ "${d}" -ne 0 ] && rc="${d}d ${rc}"
141 [ -z "$rc" ] && rc="down"
142 echo "Line Uptime: ${rc}"
146 # Get noise and attenuation figures
155 lsg=$(dsl_cmd g997lsg 1 1)
156 latnd=$(dsl_val "$lsg" LATN)
157 snrd=$(dsl_val "$lsg" SNR)
159 lsg=$(dsl_cmd g997lsg 0 1)
160 latnu=$(dsl_val "$lsg" LATN)
161 snru=$(dsl_val "$lsg" SNR)
163 [ -z "$latnd" ] && latnd=0
164 [ -z "$latnu" ] && latnu=0
165 [ -z "$snrd" ] && snrd=0
166 [ -z "$snru" ] && snru=0
173 if [ "$action" = "lucistat" ]; then
174 echo "dsl.line_attenuation_down=$latnd"
175 echo "dsl.line_attenuation_up=$latnu"
176 echo "dsl.noise_margin_down=$snrd"
177 echo "dsl.noise_margin_up=$snru"
179 echo "Line Attenuation: ${latnd}dB / ${latnu}dB"
180 echo "Noise Margin: ${snrd}dB / ${snru}dB"
185 # Is the line up? Or what state is it in?
188 local lsg=$(dsl_cmd lsg)
189 local ls=$(dsl_val "$lsg" nLineState);
193 "0x0") s="not initialized" ;;
194 "0x1") s="exception" ;;
195 "0x10") s="not updated" ;;
196 "0xff") s="idle request" ;;
198 "0x1ff") s="silent request" ;;
199 "0x200") s="silent" ;;
200 "0x300") s="handshake" ;;
201 "0x380") s="full_init" ;;
202 "0x400") s="discovery" ;;
203 "0x500") s="training" ;;
204 "0x600") s="analysis" ;;
205 "0x700") s="exchange" ;;
206 "0x800") s="showtime_no_sync" ;;
207 "0x801") s="showtime_tc_sync" ;;
208 "0x900") s="fastretrain" ;;
209 "0xa00") s="lowpower_l2" ;;
210 "0xb00") s="loopdiagnostic active" ;;
211 "0xb10") s="loopdiagnostic data exchange" ;;
212 "0xb20") s="loopdiagnostic data request" ;;
213 "0xc00") s="loopdiagnostic complete" ;;
214 "0x1000000") s="test" ;;
215 "0xd00") s="resync" ;;
216 "0x3c0") s="short init entry" ;;
217 "") s="not running daemon"; ls="0xfff" ;;
221 if [ $action = "lucistat" ]; then
222 echo "dsl.line_state_num=$ls"
223 echo "dsl.line_state_detail=\"$s\""
224 if [ "$ls" = "0x801" ]; then
225 echo "dsl.line_state=\"UP\""
227 echo "dsl.line_state=\"DOWN\""
230 if [ "$ls" = "0x801" ]; then
231 echo "Line State: UP [$ls: $s]"
233 echo "Line State: DOWN [$ls: $s]"
239 # Main status routine
250 # Luci (lua) compatible version that's easy to parse
259 # Simple start routine
262 # start CPE dsl daemon in the background
263 service_start /sbin/dsl_cpe_control -i \
264 -n /sbin/dsl_notify.sh \
265 -f /lib/firmware/ModemHWE.bin
269 # For stop we want to simulate the notification call for when
270 # the line goes down, so that we can stop the ppp link before
274 DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
275 DSL_INTERFACE_STATUS="DOWN" \
278 service_stop /sbin/dsl_cpe_control