dsl_control 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. lowlevel_cfg() {
  76. echo "# VRX Low Level Configuration File
  77. #
  78. # Parameters must be separated by tabs or spaces.
  79. # Empty lines and comments will be ignored.
  80. #
  81. # nFilter
  82. #
  83. # NA = -1
  84. # OFF = 0
  85. # ISDN = 1
  86. # POTS = 2
  87. # POTS_2 = 3
  88. # POTS_3 = 4
  89. #
  90. # (dec)
  91. -1
  92. # nHsToneGroupMode nHsToneGroup_A nHsToneGroup_V nHsToneGroup_AV
  93. #
  94. # NA = -1 NA = -1 see see
  95. # AUTO = 0 VDSL2_B43 = 0x0001 nHsToneGroup_A nHsToneGroup_A
  96. # MANUAL = 1 VDSL2_A43 = 0x0002
  97. # VDSL2_V43 = 0x0004
  98. # VDSL1_V43P = 0x0008
  99. # VDSL1_V43I = 0x0010
  100. # ADSL1_C43 = 0x0020
  101. # ADSL2_J43 = 0x0040
  102. # ADSL2_B43C = 0x0080
  103. # ADSL2_A43C = 0x0100
  104. #
  105. # (dec) (hex) (hex) (hex)
  106. 1 $1 $2 0x0
  107. # nBaseAddr nIrqNum
  108. #
  109. # (hex) (dec)
  110. 0x1e116000 63
  111. # nUtopiaPhyAdr nUtopiaBusWidth nPosPhyParity
  112. # default(16b) = 0 NA = -1
  113. # 8-bit = 1 ODD = 0
  114. # 16-bit = 2
  115. #
  116. #
  117. # (hex) (dec) (dec)
  118. 0xFF 0 0
  119. # bNtrEnable
  120. #
  121. # (dec)
  122. 0" > /tmp/lowlevel.cfg
  123. }
  124. service_triggers() {
  125. procd_add_reload_trigger network
  126. }
  127. start_service() {
  128. local annex
  129. local firmware
  130. local tone
  131. local tone_adsl
  132. local tone_vdsl
  133. local xtse
  134. local xfer_mode
  135. local line_mode
  136. local mode
  137. local lowlevel
  138. config_load network
  139. config_get tone dsl tone
  140. config_get annex dsl annex
  141. config_get firmware dsl firmware
  142. config_get xfer_mode dsl xfer_mode
  143. config_get line_mode dsl line_mode
  144. eval "xtse=\"\${xtse_xdsl_$annex}\""
  145. [ -z "${xfer_mode}" ] && xfer_mode=ptm
  146. case "${xfer_mode}" in
  147. atm)
  148. LOAD=ltq_atm_vr9
  149. UNLOAD=ltq_ptm_vr9
  150. # in most cases atm is used on top of adsl
  151. [ -z "${line_mode}" ] && line_mode=adsl
  152. ;;
  153. *)
  154. LOAD=ltq_ptm_vr9
  155. UNLOAD=ltq_atm_vr9
  156. # in most cases ptm is used on top of vdsl
  157. [ -z "${line_mode}" ] && line_mode=vdsl
  158. ;;
  159. esac
  160. case "${line_mode}" in
  161. adsl)
  162. mode=1
  163. # mask out VDSL bits when ATM is requested
  164. xtse="${xtse%_*}_00"
  165. ;;
  166. *)
  167. mode=2
  168. ;;
  169. esac
  170. if [ -z "${firmware}" ]; then
  171. # search for the firmware provided by dsl-vrx200-firmware-xdsl-*
  172. if grep -qE "system type.*: (VR9|xRX200)" /proc/cpuinfo; then
  173. case "${annex}" in
  174. a*|l*|m*)
  175. if [ -f "/lib/firmware/lantiq-vrx200-a.bin" ]; then
  176. firmware="/lib/firmware/lantiq-vrx200-a.bin"
  177. elif [ -f "/tmp/lantiq-vrx200-a.bin" ]; then
  178. firmware="/tmp/lantiq-vrx200-a.bin"
  179. elif [ -f "/lib/firmware/lantiq-vrx200-b.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-b-to-a.bspatch" ]; then
  180. bspatch /lib/firmware/lantiq-vrx200-b.bin \
  181. /tmp/lantiq-vrx200-a.bin \
  182. /lib/firmware/lantiq-vrx200-b-to-a.bspatch
  183. firmware="/tmp/lantiq-vrx200-a.bin"
  184. else
  185. echo "firmware for annex a not found"
  186. return 1
  187. fi
  188. ;;
  189. b*|j*)
  190. if [ -f "/lib/firmware/lantiq-vrx200-b.bin" ]; then
  191. firmware="/lib/firmware/lantiq-vrx200-b.bin"
  192. elif [ -f "/tmp/lantiq-vrx200-b.bin" ]; then
  193. firmware="/tmp/lantiq-vrx200-b.bin"
  194. elif [ -f "/lib/firmware/lantiq-vrx200-a.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-a-to-b.bspatch" ]; then
  195. bspatch /lib/firmware/lantiq-vrx200-a.bin \
  196. /tmp/lantiq-vrx200-b.bin \
  197. /lib/firmware/lantiq-vrx200-a-to-b.bspatch
  198. firmware="/tmp/lantiq-vrx200-b.bin"
  199. else
  200. echo "firmware for annex b not found"
  201. return 1
  202. fi
  203. ;;
  204. *)
  205. echo "annex type not supported use a or b"
  206. return 1
  207. ;;
  208. esac
  209. fi
  210. fi
  211. [ -z "${firmware}" ] && firmware=/lib/firmware/vdsl.bin
  212. [ -f "${firmware}" ] || {
  213. echo failed to find $firmware
  214. return 1
  215. }
  216. eval "tone_adsl=\"\${tone_adsl_$tone}\""
  217. eval "tone_vdsl=\"\${tone_vdsl_$tone}\""
  218. [ -n "${tone_adsl}" ] && [ -n "${tone_vdsl}" ] && {
  219. lowlevel_cfg "${tone_adsl}" "${tone_vdsl}"
  220. lowlevel="-l /tmp/lowlevel.cfg"
  221. }
  222. procd_open_instance
  223. procd_set_param command /sbin/vdsl_cpe_control_wrapper \
  224. -i$xtse \
  225. -n /sbin/dsl_notify.sh \
  226. -f ${firmware} \
  227. $lowlevel \
  228. -M ${mode}
  229. procd_append_param env "LOAD=$LOAD" "UNLOAD=$UNLOAD"
  230. procd_close_instance
  231. }
  232. stop_service() {
  233. # do not use dsl_cmd to not block when this is locked up by some other proess
  234. echo quit > /tmp/pipe/dsl_cpe0_cmd
  235. DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
  236. DSL_INTERFACE_STATUS="DOWN" \
  237. /sbin/dsl_notify.sh
  238. }