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