bededb261214f72761157564923819f0321048a6
[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
7 EXTRA_COMMANDS="status lucistat"
8 EXTRA_HELP=" status Get DSL status information
9 lucistat Get status information if lua friendly format"
10
11 SERVICE_DAEMONIZE=1
12 SERVICE_WRITE_PID=1
13
14 [ -f /lib/functions/lantiq_dsl.sh ] && . /lib/functions/lantiq_dsl.sh
15 XDSL_CTRL=vdsl_cpe_control
16
17 # G.992.1 Annex A
18 # G.992.2 Annex A
19 # G.992.3 Annex A
20 # G.992.4 Annex A
21 # G.992.5 Annex A
22 # G.993.2 Annex A/B/C
23 xtse_adsl_a="04 01 04 01 00 01 00 00"
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 xtse_adsl_b="10 00 10 00 00 04 00 00"
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 xtse_adsl_j="10 00 10 40 00 04 01 00"
38
39 xtse_vdsl="00 00 00 00 00 00 00 07"
40
41 xdsl_scr() {
42 val=`echo $2 | sed "s/ / 0x/g"`
43 echo "[WaitForConfiguration]={
44 #G997XTUSEC_g997xtusecs 0x$val
45 }
46
47 [WaitForLinkActivate]={
48 }
49
50 [WaitForRestart]={
51 }
52
53 [Common]={
54 }" > /tmp/$1.scr
55 }
56
57 # A43
58 tone_adsl_a="0x142"
59 tone_vdsl_a="0x142"
60
61 # A43 + V43
62 tone_adsl_av="0x142"
63 tone_vdsl_av="0x146"
64
65 # B43
66 tone_adsl_b="0x1"
67 tone_vdsl_b="0x1"
68
69 # B43 + V43
70 tone_adsl_bv="0x1"
71 tone_vdsl_bv="0x5"
72
73 lowlevel_cfg() {
74 echo "# VRX Low Level Configuration File
75 #
76 # Parameters must be separated by tabs or spaces.
77 # Empty lines and comments will be ignored.
78 #
79
80 # nFilter
81 #
82 # NA = -1
83 # OFF = 0
84 # ISDN = 1
85 # POTS = 2
86 # POTS_2 = 3
87 # POTS_3 = 4
88 #
89 # (dec)
90 -1
91
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
108 # nBaseAddr nIrqNum
109 #
110 # (hex) (dec)
111 0x1e116000 63
112
113 # nUtopiaPhyAdr nUtopiaBusWidth nPosPhyParity
114 # default(16b) = 0 NA = -1
115 # 8-bit = 1 ODD = 0
116 # 16-bit = 2
117 #
118 #
119 # (hex) (dec) (dec)
120 0xFF 0 0
121
122 # bNtrEnable
123 #
124 # (dec)
125 0" > /tmp/lowlevel.cfg
126 }
127
128 start() {
129 local annex
130 local firmware
131 local tone
132 local tone_adsl
133 local tone_vdsl
134 local xtse
135 local xtse_adsl
136 local mode
137
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
144 [ -z "${xfer_mode}" ] && xfer_mode=ptm
145
146 case "${xfer_mode}" in
147 atm)
148 insmod ltq_atm_vr9
149 mode=1
150 ;;
151 *)
152 insmod ltq_ptm_vr9
153 mode=2
154 ;;
155 esac
156
157 eval "xtse_adsl=\"\${xtse_adsl_$annex}\""
158 if [ "${xtse_adsl}" ]; then
159 xtse=$xtse_adsl
160 else
161 xtse_adsl=$xtse_adsl_a
162 xtse=$xtse_vdsl
163 fi
164
165 eval "tone_adsl=\"\${tone_adsl_$tone}\""
166 [ -z "${tone_adsl}" ] && tone_adsl=$tone_adsl_av
167
168 eval "tone_vdsl=\"\${tone_vdsl_$tone}\""
169 [ -z "${tone_vdsl}" ] && tone_vdsl=$tone_vdsl_av
170
171 [ -z "${firmware}" ] && firmware=/lib/firmware/vdsl.bin
172 [ -f "${firmware}" ] || {
173 echo failed to find $firmware
174 return 1
175 }
176
177 xdsl_scr adsl "${xtse_adsl}"
178 xdsl_scr vdsl "${xtse_vdsl}"
179 lowlevel_cfg "${tone_adsl}" "${tone_vdsl}"
180
181 service_start /sbin/vdsl_cpe_control \
182 -i `echo $xtse | sed "s/ /_/g"` \
183 -n /sbin/dsl_notify.sh \
184 -f ${firmware} \
185 -a /tmp/adsl.scr \
186 -A /tmp/vdsl.scr \
187 -l /tmp/lowlevel.cfg \
188 -M ${mode}
189 }
190
191 stop() {
192 DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
193 DSL_INTERFACE_STATUS="DOWN" \
194 /sbin/dsl_notify.sh
195
196 service_stop /sbin/vdsl_cpe_control
197 }