818990e57418d4d2ef12e8755264c31b6a934f24
[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_07"
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_07"
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_07"
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 # create ADSL autoboot script. Used for SNR margin tweak
100 autoboot_script() {
101 echo "[WaitForConfiguration]={
102 locs 0 $1
103 }
104
105 [WaitForLinkActivate]={
106 }
107
108 [WaitForRestart]={
109 }
110
111 [Common]={
112 }" > /tmp/dsl.scr
113 }
114
115 lowlevel_cfg() {
116 echo "# VRX Low Level Configuration File
117 #
118 # Parameters must be separated by tabs or spaces.
119 # Empty lines and comments will be ignored.
120 #
121
122 # nFilter
123 #
124 # NA = -1
125 # OFF = 0
126 # ISDN = 1
127 # POTS = 2
128 # POTS_2 = 3
129 # POTS_3 = 4
130 #
131 # (dec)
132 -1
133
134 # nHsToneGroupMode nHsToneGroup_A nHsToneGroup_V nHsToneGroup_AV
135 #
136 # NA = -1 NA = -1 see see
137 # AUTO = 0 VDSL2_B43 = 0x0001 nHsToneGroup_A nHsToneGroup_A
138 # MANUAL = 1 VDSL2_A43 = 0x0002
139 # VDSL2_V43 = 0x0004
140 # VDSL1_V43P = 0x0008
141 # VDSL1_V43I = 0x0010
142 # ADSL1_C43 = 0x0020
143 # ADSL2_J43 = 0x0040
144 # ADSL2_B43C = 0x0080
145 # ADSL2_A43C = 0x0100
146 #
147 # (dec) (hex) (hex) (hex)
148 1 $1 $2 0x0
149
150 # nBaseAddr nIrqNum
151 #
152 # (hex) (dec)
153 0x1e116000 63
154
155 # nUtopiaPhyAdr nUtopiaBusWidth nPosPhyParity
156 # default(16b) = 0 NA = -1
157 # 8-bit = 1 ODD = 0
158 # 16-bit = 2
159 #
160 #
161 # (hex) (dec) (dec)
162 0xFF 0 0
163
164 # bNtrEnable
165 #
166 # (dec)
167 0" > /tmp/lowlevel.cfg
168 }
169
170 service_triggers() {
171 procd_add_reload_trigger network
172 }
173
174 start_service() {
175 local annex
176 local firmware
177 local tone
178 local tone_adsl
179 local tone_vdsl
180 local xtse
181 local xfer_mode
182 local line_mode
183 local tc_layer
184 local mode
185 local lowlevel
186 local snr
187
188 config_load network
189 config_get tone dsl tone
190 config_get annex dsl annex
191 config_get firmware dsl firmware
192 config_get xfer_mode dsl xfer_mode
193 config_get line_mode dsl line_mode
194 config_get snr dsl ds_snr_offset
195
196 eval "xtse=\"\${xtse_xdsl_$annex}\""
197
198 case "${xfer_mode}" in
199 atm)
200 tc_layer="-T1:0x1:0x1_1:0x1:0x1"
201 ;;
202 ptm)
203 tc_layer="-T2:0x1:0x1_2:0x1:0x1"
204 ;;
205 esac
206
207 case "${line_mode}" in
208 adsl)
209 mode="-M1"
210
211 # mask out VDSL bits when ADSL is requested
212 xtse="${xtse%_*}_00"
213 ;;
214 vdsl)
215 mode="-M2"
216
217 # mask out ADSL bits when VDSL is requested
218 xtse="00_00_00_00_00_00_00_${xtse##*_}"
219 ;;
220 esac
221
222 local annexgpio="/sys/class/gpio/annex"
223 if [ -d "${annexgpio}a" ] && [ -d "${annexgpio}b" ]; then
224 case "${annex}" in
225 a*|l*|m*)
226 echo 1 > "${annexgpio}a/value"
227 echo 0 > "${annexgpio}b/value"
228 ;;
229 b*|j*)
230 echo 0 > "${annexgpio}a/value"
231 echo 1 > "${annexgpio}b/value"
232 ;;
233 esac
234 fi
235
236 if [ -z "${firmware}" ]; then
237 # search for the firmware provided by dsl-vrx200-firmware-xdsl-*
238 if grep -qE "system type.*: (VR9|xRX200)" /proc/cpuinfo; then
239 case "${annex}" in
240 a*|l*|m*)
241 if [ -f "/lib/firmware/lantiq-vrx200-a.bin" ]; then
242 firmware="/lib/firmware/lantiq-vrx200-a.bin"
243 elif [ -f "/tmp/lantiq-vrx200-a.bin" ]; then
244 firmware="/tmp/lantiq-vrx200-a.bin"
245 elif [ -f "/lib/firmware/lantiq-vrx200-b.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-b-to-a.bspatch" ]; then
246 bspatch /lib/firmware/lantiq-vrx200-b.bin \
247 /tmp/lantiq-vrx200-a.bin \
248 /lib/firmware/lantiq-vrx200-b-to-a.bspatch
249 firmware="/tmp/lantiq-vrx200-a.bin"
250 else
251 echo "firmware for annex a not found"
252 return 1
253 fi
254 ;;
255 b*|j*)
256 if [ -f "/lib/firmware/lantiq-vrx200-b.bin" ]; then
257 firmware="/lib/firmware/lantiq-vrx200-b.bin"
258 elif [ -f "/tmp/lantiq-vrx200-b.bin" ]; then
259 firmware="/tmp/lantiq-vrx200-b.bin"
260 elif [ -f "/lib/firmware/lantiq-vrx200-a.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-a-to-b.bspatch" ]; then
261 bspatch /lib/firmware/lantiq-vrx200-a.bin \
262 /tmp/lantiq-vrx200-b.bin \
263 /lib/firmware/lantiq-vrx200-a-to-b.bspatch
264 firmware="/tmp/lantiq-vrx200-b.bin"
265 else
266 echo "firmware for annex b not found"
267 return 1
268 fi
269 ;;
270 *)
271 echo "annex type not supported use a or b"
272 return 1
273 ;;
274 esac
275 fi
276 fi
277
278 [ -z "${firmware}" ] && firmware=/lib/firmware/vdsl.bin
279 [ -f "${firmware}" ] || {
280 echo failed to find $firmware
281 return 1
282 }
283
284 eval "tone_adsl=\"\${tone_adsl_$tone}\""
285 eval "tone_vdsl=\"\${tone_vdsl_$tone}\""
286 [ -n "${tone_adsl}" ] && [ -n "${tone_vdsl}" ] && {
287 lowlevel_cfg "${tone_adsl}" "${tone_vdsl}"
288 lowlevel="-l /tmp/lowlevel.cfg"
289 }
290
291 [ -z "${snr}" ] || {
292 # for SNR offset setting
293 autoboot_script "$snr"
294 autoboot="-a /tmp/dsl.scr -A /tmp/dsl.scr"
295 }
296
297 procd_open_instance
298 procd_set_param command /sbin/vdsl_cpe_control \
299 -i$xtse \
300 -n /sbin/dsl_notify.sh \
301 -f ${firmware} \
302 $lowlevel \
303 ${mode} \
304 ${tc_layer} \
305 $autoboot
306 procd_close_instance
307 }
308
309 stop_service() {
310 # do not use dsl_cmd to not block when this is locked up by some other proess
311 echo quit > /tmp/pipe/dsl_cpe0_cmd
312 DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
313 DSL_INTERFACE_STATUS="DOWN" \
314 /sbin/dsl_notify.sh
315 }