0f1f535f2d163b23ab6b9c7160ad01ca78cddfc3
[openwrt.git] / package / network / config / ltq-vdsl-app / files / dsl_notify.sh
1 #!/bin/sh
2 #
3 # This script is called by dsl_cpe_control whenever there is a DSL event,
4 # we only actually care about the DSL_INTERFACE_STATUS events as these
5 # tell us the line has either come up or gone down.
6 #
7 # The rest of the code is basically the same at the atm hotplug code
8 #
9
10 [ "$DSL_NOTIFICATION_TYPE" = "DSL_INTERFACE_STATUS" ] || exit 0
11
12 . /usr/share/libubox/jshn.sh
13 . /lib/functions.sh
14 . /lib/functions/leds.sh
15
16 include /lib/network
17 scan_interfaces
18
19 logger "Found no matching interface for DSL notification ($DSL_INTERFACE_STATUS)"
20
21 local default
22 config_load system
23 config_get default led_adsl default
24 if [ "$default" != 1 ]; then
25         case "$DSL_INTERFACE_STATUS" in
26           "HANDSHAKE")  led_timer adsl 500 500;;
27           "TRAINING")   led_timer adsl 200 200;;
28           "UP")         led_on adsl;;
29           *)            led_off adsl
30         esac
31 fi
32
33 local interfaces=`ubus list network.interface.\* | cut -d"." -f3`
34 local ifc
35 for ifc in $interfaces; do
36
37         local up
38         json_load "$(ifstatus $ifc)"
39         json_get_var up up
40
41         local auto
42         config_get_bool auto "$ifc" auto 1
43
44         local proto
45         json_get_var proto proto
46
47         if [ "$DSL_INTERFACE_STATUS" = "UP" ]; then
48                 if [ "$proto" = "pppoa" ] && [ "$up" != 1 ] && [ "$auto" = 1 ]; then
49                         ( sleep 1; ifup "$ifc" ) &
50                 fi
51         else
52                 if [ "$proto" = "pppoa" ] && [ "$up" = 1 ] && [ "$auto" = 1 ]; then
53                         ( sleep 1; ifdown "$ifc" ) &
54                 else
55                         json_get_var autostart autostart
56                         if [ "$proto" = "pppoa" ] && [ "$up" != 1 ] && [ "$autostart" = 1 ]; then
57                                 ( sleep 1; ifdown "$ifc" ) &
58                         fi
59                 fi
60         fi
61 done
62
63