ipq40xx: only include ath10k-board-qca4019 for the generic subtarget
[openwrt/staging/chunkeey.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 dslstat() {
8 ubus call dsl metrics
9 }
10
11 extra_command "dslstat" "Get DSL status information"
12
13 #
14 # ITU-T G.997.1 (06/2012) - Section 7.3.1.1.1 (xTU transmission system enabling (XTSE))
15 # ITU-T G.997.1 Amendment 2 (04/2013) - Section 2.1 - (Vectoring mode enable (VECTORMODE_ENABLE))
16 #
17 # G.992.1 Annex A
18 # G.992.2 Annex A
19 # G.992.3 Annex A / L-US1 / L_US-2 / M
20 # G.992.5 Annex A / M
21 # G.993.2 Annex A/B/C
22 # G.993.5 Annex A/B/C
23 xtse_xdsl_a="05_01_04_00_4C_01_04_07"
24
25 # G.992.1 Annex B
26 # G.992.3 Annex B
27 # G.992.5 Annex B
28 # G.993.2 Annex A/B/C
29 # G.993.5 Annex A/B/C
30 xtse_xdsl_b="10_00_10_00_00_04_00_07"
31
32 # G.992.1 Annex B
33 # G.992.3 Annex B
34 # G.992.3 Annex J
35 # G.992.5 Annex B
36 # G.992.5 Annex J
37 # G.993.2 Annex A/B/C
38 # G.993.5 Annex A/B/C
39 xtse_xdsl_j="10_00_10_40_00_04_01_07"
40
41 # G.992.1 Annex B
42 xtse_xdsl_bdmt="10_00_00_00_00_00_00_00"
43
44 # G.992.3 Annex B
45 xtse_xdsl_b2="00_00_10_00_00_00_00_00"
46
47 # G.992.5 Annex B
48 xtse_xdsl_b2p="00_00_00_00_00_04_00_00"
49
50 # ANSI T1.413
51 xtse_xdsl_at1="01_00_00_00_00_00_00_00"
52
53 # G.992.2 Annex A
54 xtse_xdsl_alite="00_01_00_00_00_00_00_00"
55
56 # G.992.1 Annex A
57 xtse_xdsl_admt="04_00_00_00_00_00_00_00"
58
59 # G.992.3 Annex A
60 xtse_xdsl_a2="00_00_04_00_00_00_00_00"
61
62 # G.992.5 Annex A
63 xtse_xdsl_a2p="00_00_00_00_00_01_00_00"
64
65 # G.992.3 Annex L
66 xtse_xdsl_l="00_00_00_00_0C_00_00_00"
67
68 # G.992.3 Annex M
69 # G.992.5 Annex M
70 xtse_xdsl_m="00_00_00_00_40_00_04_00"
71
72 # G.992.3 Annex M
73 xtse_xdsl_m2="00_00_00_00_40_00_00_00"
74
75 # G.992.5 Annex M
76 xtse_xdsl_m2p="00_00_00_00_00_00_04_00"
77
78 #
79 # ITU-T G.994.1 (06/2012) - Table 2 (Mandatory carrier sets)
80 #
81
82 # A43
83 tone_adsl_a="0x142" # A43C + J43 + A43
84 tone_vdsl_a="0x142" # A43C + J43 + A43
85
86 # A43 + V43
87 tone_adsl_av="0x142" # A43C + J43 + A43
88 tone_vdsl_av="0x146" # A43C + J43 + A43 + V43
89
90 # B43
91 tone_adsl_b="0x81" # B43 + B43c
92 tone_vdsl_b="0x1" # B43
93
94 # B43 + V43
95 tone_adsl_bv="0x81" # B43 + B43c
96 tone_vdsl_bv="0x5" # B43 + V43
97
98 # create DSL autoboot script. Used for SNR margin tweak and to set MAC address for vectoring error reports
99 autoboot_script() {
100 echo "[WaitForConfiguration]={
101 locs 0 $1
102 dsmmcs $2
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 get_macaddr() {
171 local name
172 config_get name $1 name
173 [ "$name" = "dsl0" ] && config_get $2 $1 macaddr
174 }
175
176 service_triggers() {
177 procd_add_reload_trigger network
178 }
179
180 start_service() {
181 local annex
182 local firmware
183 local tone
184 local tone_adsl
185 local tone_vdsl
186 local xtse
187 local xfer_mode
188 local line_mode
189 local tc_layer
190 local mode
191 local lowlevel
192 local snr
193 local macaddr
194
195 config_load network
196 config_get tone dsl tone
197 config_get annex dsl annex
198 config_get firmware dsl firmware
199 config_get xfer_mode dsl xfer_mode
200 config_get line_mode dsl line_mode
201 config_get snr dsl ds_snr_offset
202 config_foreach get_macaddr device macaddr
203
204 eval "xtse=\"\${xtse_xdsl_$annex}\""
205
206 case "${xfer_mode}" in
207 atm)
208 tc_layer="-T1:0x1:0x1_1:0x1:0x1"
209 ;;
210 ptm)
211 tc_layer="-T2:0x1:0x1_2:0x1:0x1"
212 ;;
213 esac
214
215 case "${line_mode}" in
216 adsl)
217 mode="-M1"
218
219 # mask out VDSL bits when ADSL is requested
220 xtse="${xtse%_*}_00"
221 ;;
222 vdsl)
223 mode="-M2"
224
225 # mask out ADSL bits when VDSL is requested
226 xtse="00_00_00_00_00_00_00_${xtse##*_}"
227 ;;
228 esac
229
230 local annexgpio="/sys/class/gpio/annex"
231 if [ -d "${annexgpio}a" ] && [ -d "${annexgpio}b" ]; then
232 case "${annex}" in
233 a*|l*|m*)
234 echo 1 > "${annexgpio}a/value"
235 echo 0 > "${annexgpio}b/value"
236 ;;
237 b*|j*)
238 echo 0 > "${annexgpio}a/value"
239 echo 1 > "${annexgpio}b/value"
240 ;;
241 esac
242 fi
243
244 if [ -z "${firmware}" ]; then
245 # search for the firmware provided by dsl-vrx200-firmware-xdsl-*
246 if grep -qE "system type.*: (VR9|xRX200)" /proc/cpuinfo; then
247 case "${annex}" in
248 a*|l*|m*)
249 if [ -f "/lib/firmware/lantiq-vrx200-a.bin" ]; then
250 firmware="/lib/firmware/lantiq-vrx200-a.bin"
251 elif [ -f "/tmp/lantiq-vrx200-a.bin" ]; then
252 firmware="/tmp/lantiq-vrx200-a.bin"
253 elif [ -f "/lib/firmware/lantiq-vrx200-b.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-b-to-a.bspatch" ]; then
254 bspatch /lib/firmware/lantiq-vrx200-b.bin \
255 /tmp/lantiq-vrx200-a.bin \
256 /lib/firmware/lantiq-vrx200-b-to-a.bspatch
257 firmware="/tmp/lantiq-vrx200-a.bin"
258 else
259 echo "firmware for annex a not found"
260 return 1
261 fi
262 ;;
263 b*|j*)
264 if [ -f "/lib/firmware/vr9_dsl_fw_annex_b.bin" ]; then
265 firmware="/lib/firmware/vr9_dsl_fw_annex_b.bin"
266 elif [ -f "/lib/firmware/lantiq-vrx200-b.bin" ]; then
267 firmware="/lib/firmware/lantiq-vrx200-b.bin"
268 elif [ -f "/tmp/lantiq-vrx200-b.bin" ]; then
269 firmware="/tmp/lantiq-vrx200-b.bin"
270 elif [ -f "/lib/firmware/lantiq-vrx200-a.bin" ] && [ -f "/lib/firmware/lantiq-vrx200-a-to-b.bspatch" ]; then
271 bspatch /lib/firmware/lantiq-vrx200-a.bin \
272 /tmp/lantiq-vrx200-b.bin \
273 /lib/firmware/lantiq-vrx200-a-to-b.bspatch
274 firmware="/tmp/lantiq-vrx200-b.bin"
275 else
276 echo "firmware for annex b not found"
277 return 1
278 fi
279 ;;
280 *)
281 echo "annex type not supported use a or b"
282 return 1
283 ;;
284 esac
285 fi
286 fi
287
288 [ -z "${firmware}" ] && firmware=/lib/firmware/vdsl.bin
289 [ -f "${firmware}" ] || {
290 echo failed to find $firmware
291 return 1
292 }
293
294 eval "tone_adsl=\"\${tone_adsl_$tone}\""
295 eval "tone_vdsl=\"\${tone_vdsl_$tone}\""
296 [ -n "${tone_adsl}" ] && [ -n "${tone_vdsl}" ] && {
297 lowlevel_cfg "${tone_adsl}" "${tone_vdsl}"
298 lowlevel="-l /tmp/lowlevel.cfg"
299 }
300
301 [ -z "${snr}" ] && snr=0
302 [ -z "${macaddr}" ] && macaddr="00:00:00:00:00:00"
303 autoboot_script "$snr" "$macaddr"
304 autoboot="-a /tmp/dsl.scr -A /tmp/dsl.scr"
305
306 procd_open_instance
307 procd_set_param command /sbin/vdsl_cpe_control \
308 -i$xtse \
309 -n /sbin/dsl_notify.sh \
310 -f ${firmware} \
311 $lowlevel \
312 ${mode} \
313 ${tc_layer} \
314 $autoboot
315 procd_close_instance
316 }
317
318 stop_service() {
319 DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
320 DSL_INTERFACE_STATUS="DOWN" \
321 /sbin/dsl_notify.sh
322 }