ltq-app-vdsl: convert init script to procd, add support for switching between atm...
[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 # 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 # G.992.1 Annex A
15 # G.992.2 Annex A
16 # G.992.3 Annex A
17 # G.992.4 Annex A
18 # G.992.5 Annex A
19 # G.993.2 Annex A/B/C
20 xtse_adsl_a="04 01 04 01 00 01 00 00"
21
22 # G.992.1 Annex B
23 # G.992.3 Annex B
24 # G.992.5 Annex B
25 # G.993.2 Annex A/B/C
26 xtse_adsl_b="10 00 10 00 00 04 00 00"
27
28 # G.992.1 Annex B
29 # G.992.3 Annex B
30 # G.992.3 Annex J
31 # G.992.5 Annex B
32 # G.992.5 Annex J
33 # G.993.2 Annex A/B/C
34 xtse_adsl_j="10 00 10 40 00 04 01 00"
35
36 xtse_vdsl="00 00 00 00 00 00 00 07"
37
38 service_triggers() {
39 procd_add_reload_trigger network
40 }
41
42 start_service() {
43 local annex
44 local firmware
45 local xtse
46 local xtse_adsl
47 local mode
48
49 config_load network
50 config_get annex dsl annex
51 config_get firmware dsl firmware
52 config_get xfer_mode dsl xfer_mode
53
54 [ -z "${xfer_mode}" ] && xfer_mode=ptm
55
56 case "${xfer_mode}" in
57 atm)
58 LOAD=ltq_atm_vr9
59 UNLOAD=ltq_ptm_vr9
60 mode=1
61 ;;
62 *)
63 LOAD=ltq_ptm_vr9
64 UNLOAD=ltq_atm_vr9
65 mode=2
66 ;;
67 esac
68
69 eval "xtse_adsl=\"\${xtse_adsl_$annex}\""
70 if [ "${xtse_adsl}" ]; then
71 xtse=$xtse_adsl
72 else
73 xtse=$xtse_vdsl
74 fi
75
76 [ -z "${firmware}" ] && firmware=/lib/firmware/vdsl.bin
77 [ -f "${firmware}" ] || {
78 echo failed to find $firmware
79 return 1
80 }
81
82 procd_open_instance
83 procd_set_param command /sbin/vdsl_cpe_control_wrapper \
84 -i `echo $xtse | sed "s/ /_/g"` \
85 -n /sbin/dsl_notify.sh \
86 -f ${firmware} \
87 -M ${mode}
88 procd_append_param env "LOAD=$LOAD" "UNLOAD=$UNLOAD"
89 procd_close_instance
90 }
91
92 stop_service() {
93 DSL_NOTIFICATION_TYPE="DSL_INTERFACE_STATUS" \
94 DSL_INTERFACE_STATUS="DOWN" \
95 /sbin/dsl_notify.sh
96 }