dsl_control 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2012 OpenWrt.org
  3. # needs to start before the atm layer which starts at 50
  4. START=48
  5. USE_PROCD=1
  6. EXTRA_COMMANDS="status lucistat"
  7. EXTRA_HELP=" status Get DSL status information
  8. lucistat Get status information if lua friendly format"
  9. [ -f /lib/functions/lantiq_dsl.sh ] && . /lib/functions/lantiq_dsl.sh
  10. #
  11. # ITU-T G.997.1 (06/2012) - Section 7.3.1.1.1 (xTU transmission system enabling (XTSE))
  12. # ITU-T G.997.1 Amendment 2 (04/2013) - Section 2.1 - (Vectoring mode enable (VECTORMODE_ENABLE))
  13. #
  14. # G.992.1 Annex A
  15. # G.992.2 Annex A
  16. # G.992.3 Annex A / L-US1 / L_US-2 / M
  17. # G.992.5 Annex A / M
  18. # G.993.2 Annex A/B/C
  19. # G.993.5 Annex A/B/C
  20. xtse_xdsl_a="05_01_04_00_4C_01_04_07"
  21. # G.992.1 Annex B
  22. # G.992.3 Annex B
  23. # G.992.5 Annex B
  24. # G.993.2 Annex A/B/C
  25. # G.993.5 Annex A/B/C
  26. xtse_xdsl_b="10_00_10_00_00_04_00_07"
  27. # G.992.1 Annex B
  28. # G.992.3 Annex B
  29. # G.992.3 Annex J
  30. # G.992.5 Annex B
  31. # G.992.5 Annex J
  32. # G.993.2 Annex A/B/C
  33. # G.993.5 Annex A/B/C
  34. xtse_xdsl_j="10_00_10_40_00_04_01_07"
  35. # G.992.1 Annex B
  36. xtse_xdsl_bdmt="10_00_00_00_00_00_00_00"
  37. # G.992.3 Annex B
  38. xtse_xdsl_b2="00_00_10_00_00_00_00_00"
  39. # G.992.5 Annex B
  40. xtse_xdsl_b2p="00_00_00_00_00_04_00_00"
  41. # ANSI T1.413
  42. xtse_xdsl_at1="01_00_00_00_00_00_00_00"
  43. # G.992.2 Annex A
  44. xtse_xdsl_alite="00_01_00_00_00_00_00_00"
  45. # G.992.1 Annex A
  46. xtse_xdsl_admt="04_00_00_00_00_00_00_00"
  47. # G.992.3 Annex A
  48. xtse_xdsl_a2="00_00_04_00_00_00_00_00"
  49. # G.992.5 Annex A
  50. xtse_xdsl_a2p="00_00_00_00_00_01_00_00"
  51. # G.992.3 Annex L
  52. xtse_xdsl_l="00_00_00_00_0C_00_00_00"
  53. # G.992.3 Annex M
  54. # G.992.5 Annex M
  55. xtse_xdsl_m="00_00_00_00_40_00_04_00"
  56. # G.992.3 Annex M
  57. xtse_xdsl_m2="00_00_00_00_40_00_00_00"
  58. # G.992.5 Annex M
  59. xtse_xdsl_m2p="00_00_00_00_00_00_04_00"
  60. #
  61. # ITU-T G.994.1 (06/2012) - Table 2 (Mandatory carrier sets)
  62. #
  63. # A43
  64. tone_adsl_a="0x142" # A43C + J43 + A43
  65. tone_vdsl_a="0x142" # A43C + J43 + A43
  66. # A43 + V43
  67. tone_adsl_av="0x142" # A43C + J43 + A43
  68. tone_vdsl_av="0x146" # A43C + J43 + A43 + V43
  69. # B43
  70. tone_adsl_b="0x81" # B43 + B43c
  71. tone_vdsl_b="0x1" # B43
  72. # B43 + V43
  73. tone_adsl_bv="0x81" # B43 + B43c
  74. tone_vdsl_bv="0x5" # B43 + V43
  75. # create ADSL autoboot script. Used for SNR margin tweak
  76. autoboot_script() {
  77. echo "[WaitForConfiguration]={
  78. locs 0 $1
  79. }
  80. [WaitForLinkActivate]={
  81. }
  82. [WaitForRestart]={
  83. }
  84. [Common]={
  85. }" > /tmp/dsl.scr
  86. }
  87. lowlevel_cfg() {
  88. echo "# VRX Low Level Configuration File
  89. #
  90. # Parameters must be separated by tabs or spaces.
  91. # Empty lines and comments will be ignored.
  92. #
  93. # nFilter
  94. #
  95. # NA = -1
  96. # OFF = 0
  97. # ISDN = 1
  98. # POTS = 2
  99. # POTS_2 = 3
  100. # POTS_3 = 4
  101. #
  102. # (dec)
  103. -1
  104. # nHsToneGroupMode nHsToneGroup_A nHsToneGroup_V nHsToneGroup_AV
  105. #
  106. # NA = -1 NA = -1 see see
  107. # AUTO = 0 VDSL2_B43 = 0x0001 nHsToneGroup_A nHsToneGroup_A
  108. # MANUAL = 1 VDSL2_A43 = 0x0002
  109. # VDSL2_V43 = 0x0004
  110. # VDSL1_V43P = 0x0008
  111. # VDSL1_V43I = 0x0010
  112. # ADSL1_C43 = 0x0020
  113. # ADSL2_J43 = 0x0040
  114. # ADSL2_B43C = 0x0080
  115. # ADSL2_A43C = 0x0100
  116. #
  117. # (dec) (hex) (hex) (hex)
  118. 1 $1 $2 0x0
  119. # nBaseAddr nIrqNum
  120. #
  121. # (hex) (dec)
  122. 0x1e116000 63
  123. # nUtopiaPhyAdr nUtopiaBusWidth nPosPhyParity
  124. # default(16b) = 0 NA = -1
  125. # 8-bit = 1 ODD = 0
  126. # 16-bit = 2
  127. #
  128. #
  129. # (hex) (dec) (dec)
  130. 0xFF 0 0
  131. # bNtrEnable
  132. #
  133. # (dec)
  134. 0" > /tmp/lowlevel.cfg
  135. }
  136. service_triggers() {
  137. procd_add_reload_trigger network
  138. }
  139. start_service() {
  140. local annex
  141. local firmware
  142. local tone
  143. local tone_adsl
  144. local tone_vdsl
  145. local xtse
  146. local xfer_mode
  147. local line_mode
  148. local mode
  149. local lowlevel
  150. local snr
  151. config_load network
  152. config_get tone dsl tone
  153. config_get annex dsl annex
  154. config_get firmware dsl firmware
  155. config_get xfer_mode dsl xfer_mode
  156. config_get line_mode dsl line_mode
  157. config_get snr dsl ds_snr_offset
  158. eval "xtse=\"\${xtse_xdsl_$annex}\""
  159. [ -z "${xfer_mode}" ] && xfer_mode=ptm
  160. case "${xfer_mode}" in
  161. atm)
  162. LOAD=ltq_atm_vr9
  163. UNLOAD=ltq_ptm_vr9
  164. # in most cases atm is used on top of adsl
  165. [ -z "${line_mode}" ] && line_mode=adsl
  166. ;;
  167. *)
  168. LOAD=ltq_ptm_vr9
  169. UNLOAD=ltq_atm_vr9
  170. # in most cases ptm is used on top of vdsl
  171. [ -z "${line_mode}" ] && line_mode=vdsl
  172. ;;
  173. esac
  174. case "${line_mode}" in
  175. adsl)
  176. mode=1
  177. # mask out VDSL bits when ATM is requested
  178. xtse="${xtse%_*}_00"
  179. ;;
  180. *)
  181. mode=2
  182. ;;
  183. esac
  184. if [ -z "${firmware}" ]; then
  185. # search for the firmware provided by dsl-vrx200-firmware-xdsl-*
  186. if grep -qE "system type.*: (VR9|xRX200)" /proc/cpuinfo; then
  187. case "${annex}" in
  188. a*|l*|m*)
  189. if [ -f "/lib/firmware/lantiq-vrx200-a.bin" ]; then
  190. firmware="/lib/firmware/lantiq-vrx200-a.bin"
  191. elif [ -f "/tmp/lantiq-vrx200-a.bin" ]; then
  192. firmware="/tmp/lantiq-vrx200-a.bin"
  193. elif [ -f "/lib/firmware/lantiq-vrx200-b.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-b-to-a.bspatch" ]; then
  194. bspatch /lib/firmware/lantiq-vrx200-b.bin \
  195. /tmp/lantiq-vrx200-a.bin \
  196. /lib/firmware/lantiq-vrx200-b-to-a.bspatch
  197. firmware="/tmp/lantiq-vrx200-a.bin"
  198. else
  199. echo "firmware for annex a not found"
  200. return 1
  201. fi
  202. ;;
  203. b*|j*)
  204. if [ -f "/lib/firmware/lantiq-vrx200-b.bin" ]; then
  205. firmware="/lib/firmware/lantiq-vrx200-b.bin"
  206. elif [ -f "/tmp/lantiq-vrx200-b.bin" ]; then
  207. firmware="/tmp/lantiq-vrx200-b.bin"
  208. elif [ -f "/lib/firmware/lantiq-vrx200-a.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-a-to-b.bspatch" ]; then
  209. bspatch /lib/firmware/lantiq-vrx200-a.bin \
  210. /tmp/lantiq-vrx200-b.bin \
  211. /lib/firmware/lantiq-vrx200-a-to-b.bspatch
  212. firmware="/tmp/lantiq-vrx200-b.bin"
  213. else
  214. echo "firmware for annex b not found"
  215. return 1
  216. fi
  217. ;;
  218. *)
  219. echo "annex type not supported use a or b"
  220. return 1
  221. ;;
  222. esac
  223. fi
  224. fi
  225. [ -z "${firmware}" ] && firmware=/lib/firmware/vdsl.bin
  226. [ -f "${firmware}" ] || {
  227. echo failed to find $firmware
  228. return 1
  229. }
  230. eval "tone_adsl=\"\${tone_adsl_$tone}\""
  231. eval "tone_vdsl=\"\${tone_vdsl_$tone}\""
  232. [ -n "${tone_adsl}" ] && [ -n "${tone_vdsl}" ] && {
  233. lowlevel_cfg "${tone_adsl}" "${tone_vdsl}"
  234. lowlevel="-l /tmp/lowlevel.cfg"
  235. }
  236. [ -z "${snr}" ] || {
  237. # for SNR offset setting
  238. autoboot_script "$snr"
  239. autoboot="-a /tmp/dsl.scr -A /tmp/dsl.scr"
  240. }
  241. procd_open_instance
  242. procd_set_param command /sbin/vdsl_cpe_control_wrapper \
  243. -i$xtse \
  244. -n /sbin/dsl_notify.sh \
  245. -f ${firmware} \
  246. $lowlevel \
  247. -M ${mode} \
  248. $autoboot
  249. procd_append_param env "LOAD=$LOAD" "UNLOAD=$UNLOAD"
  250. procd_close_instance
  251. }
  252. stop_service() {
  253. # do not use dsl_cmd to not block when this is locked up by some other proess
  254. echo quit > /tmp/pipe/dsl_cpe0_cmd
  255. DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
  256. DSL_INTERFACE_STATUS="DOWN" \
  257. /sbin/dsl_notify.sh
  258. }