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