lantiq_dsl.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2012-2014 OpenWrt.org
  3. if [ "$( which vdsl_cpe_control )" ]; then
  4. XDSL_CTRL=vdsl_cpe_control
  5. else
  6. XDSL_CTRL=dsl_cpe_control
  7. fi
  8. #
  9. # Basic functions to send CLI commands to the vdsl_cpe_control daemon
  10. #
  11. dsl_cmd() {
  12. killall -0 ${XDSL_CTRL} && (
  13. echo "$@" > /tmp/pipe/dsl_cpe0_cmd
  14. cat /tmp/pipe/dsl_cpe0_ack
  15. )
  16. }
  17. dsl_val() {
  18. echo $(expr "$1" : '.*'$2'=\([-\.[:alnum:]]*\).*')
  19. }
  20. #
  21. # Simple divide by 10 routine to cope with one decimal place
  22. #
  23. dbt() {
  24. local a=$(expr $1 / 10)
  25. local b=$(expr $1 % 10)
  26. echo "${a}.${b}"
  27. }
  28. #
  29. # Take a number and convert to k or meg
  30. #
  31. scale() {
  32. local val=$1
  33. local a
  34. local b
  35. if [ "$val" -gt 1000000 ]; then
  36. a=$(expr $val / 1000)
  37. b=$(expr $a % 1000)
  38. a=$(expr $a / 1000)
  39. printf "%d.%03d Mb" ${a} ${b}
  40. elif [ "$val" -gt 1000 ]; then
  41. a=$(expr $val / 1000)
  42. printf "%d Kb" ${a}
  43. else
  44. echo "${val} b"
  45. fi
  46. }
  47. #
  48. # Read the data rates for both directions
  49. #
  50. data_rates() {
  51. local csg
  52. local dru
  53. local drd
  54. local sdru
  55. local sdrd
  56. csg=$(dsl_cmd g997csg 0 1)
  57. drd=$(dsl_val "$csg" ActualDataRate)
  58. csg=$(dsl_cmd g997csg 0 0)
  59. dru=$(dsl_val "$csg" ActualDataRate)
  60. [ -z "$drd" ] && drd=0
  61. [ -z "$dru" ] && dru=0
  62. sdrd=$(scale $drd)
  63. sdru=$(scale $dru)
  64. if [ "$action" = "lucistat" ]; then
  65. echo "dsl.data_rate_down=$drd"
  66. echo "dsl.data_rate_up=$dru"
  67. echo "dsl.data_rate_down_s=\"$sdrd\""
  68. echo "dsl.data_rate_up_s=\"$sdru\""
  69. else
  70. echo "Data Rate: ${sdrd}/s / ${sdru}/s"
  71. fi
  72. }
  73. #
  74. # Chipset
  75. #
  76. chipset() {
  77. local vig
  78. local cs
  79. local csv
  80. vig=$(dsl_cmd vig)
  81. cs=$(dsl_val "$vig" DSL_ChipSetType)
  82. csv=$(dsl_val "$vig" DSL_ChipSetHWVersion)
  83. if [ "$action" = "lucistat" ]; then
  84. echo "dsl.chipset=\"${cs} ${csv}\""
  85. else
  86. echo "Chipset: ${cs} ${csv}"
  87. fi
  88. }
  89. #
  90. # Work out how long the line has been up
  91. #
  92. line_uptime() {
  93. local ccsg
  94. local et
  95. local etr
  96. local d
  97. local h
  98. local m
  99. local s
  100. local rc=""
  101. ccsg=$(dsl_cmd pmccsg 0 0 0)
  102. et=$(dsl_val "$ccsg" nElapsedTime)
  103. [ -z "$et" ] && et=0
  104. if [ "$action" = "lucistat" ]; then
  105. echo "dsl.line_uptime=${et}"
  106. return
  107. fi
  108. d=$(expr $et / 86400)
  109. etr=$(expr $et % 86400)
  110. h=$(expr $etr / 3600)
  111. etr=$(expr $etr % 3600)
  112. m=$(expr $etr / 60)
  113. s=$(expr $etr % 60)
  114. [ "${d}${h}${m}${s}" -ne 0 ] && rc="${s}s"
  115. [ "${d}${h}${m}" -ne 0 ] && rc="${m}m ${rc}"
  116. [ "${d}${h}" -ne 0 ] && rc="${h}h ${rc}"
  117. [ "${d}" -ne 0 ] && rc="${d}d ${rc}"
  118. [ -z "$rc" ] && rc="down"
  119. echo "Line Uptime: ${rc}"
  120. }
  121. #
  122. # Get noise and attenuation figures
  123. #
  124. line_data() {
  125. local lsg
  126. local latnu
  127. local latnd
  128. local snru
  129. local snrd
  130. lsg=$(dsl_cmd g997lsg 1 1)
  131. latnd=$(dsl_val "$lsg" LATN)
  132. snrd=$(dsl_val "$lsg" SNR)
  133. lsg=$(dsl_cmd g997lsg 0 1)
  134. latnu=$(dsl_val "$lsg" LATN)
  135. snru=$(dsl_val "$lsg" SNR)
  136. [ -z "$latnd" ] && latnd=0
  137. [ -z "$latnu" ] && latnu=0
  138. [ -z "$snrd" ] && snrd=0
  139. [ -z "$snru" ] && snru=0
  140. latnd=$(dbt $latnd)
  141. latnu=$(dbt $latnu)
  142. snrd=$(dbt $snrd)
  143. snru=$(dbt $snru)
  144. if [ "$action" = "lucistat" ]; then
  145. echo "dsl.line_attenuation_down=$latnd"
  146. echo "dsl.line_attenuation_up=$latnu"
  147. echo "dsl.noise_margin_down=$snrd"
  148. echo "dsl.noise_margin_up=$snru"
  149. else
  150. echo "Line Attenuation: ${latnd}dB / ${latnu}dB"
  151. echo "Noise Margin: ${snrd}dB / ${snru}dB"
  152. fi
  153. }
  154. #
  155. # Is the line up? Or what state is it in?
  156. #
  157. line_state() {
  158. local lsg=$(dsl_cmd lsg)
  159. local ls=$(dsl_val "$lsg" nLineState);
  160. local s;
  161. case "$ls" in
  162. "0x0") s="not initialized" ;;
  163. "0x1") s="exception" ;;
  164. "0x10") s="not updated" ;;
  165. "0xff") s="idle request" ;;
  166. "0x100") s="idle" ;;
  167. "0x1ff") s="silent request" ;;
  168. "0x200") s="silent" ;;
  169. "0x300") s="handshake" ;;
  170. "0x380") s="full_init" ;;
  171. "0x400") s="discovery" ;;
  172. "0x500") s="training" ;;
  173. "0x600") s="analysis" ;;
  174. "0x700") s="exchange" ;;
  175. "0x800") s="showtime_no_sync" ;;
  176. "0x801") s="showtime_tc_sync" ;;
  177. "0x900") s="fastretrain" ;;
  178. "0xa00") s="lowpower_l2" ;;
  179. "0xb00") s="loopdiagnostic active" ;;
  180. "0xb10") s="loopdiagnostic data exchange" ;;
  181. "0xb20") s="loopdiagnostic data request" ;;
  182. "0xc00") s="loopdiagnostic complete" ;;
  183. "0x1000000") s="test" ;;
  184. "0xd00") s="resync" ;;
  185. "0x3c0") s="short init entry" ;;
  186. "") s="not running daemon"; ls="0xfff" ;;
  187. *) s="unknown" ;;
  188. esac
  189. if [ "$action" = "lucistat" ]; then
  190. echo "dsl.line_state_num=$ls"
  191. echo "dsl.line_state_detail=\"$s\""
  192. if [ "$ls" = "0x801" ]; then
  193. echo "dsl.line_state=\"UP\""
  194. else
  195. echo "dsl.line_state=\"DOWN\""
  196. fi
  197. else
  198. if [ "$ls" = "0x801" ]; then
  199. echo "Line State: UP [$ls: $s]"
  200. else
  201. echo "Line State: DOWN [$ls: $s]"
  202. fi
  203. fi
  204. }
  205. status() {
  206. chipset
  207. line_state
  208. data_rates
  209. line_data
  210. line_uptime
  211. }
  212. lucistat() {
  213. echo "local dsl={}"
  214. status
  215. echo "return dsl"
  216. }