af05aceded0f618190a9080cb9ff34b77957cb7c
[openwrt.git] / target / linux / ramips / base-files / etc / diag.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2010 OpenWrt.org
4 #
5 #
6
7 . /lib/ramips.sh
8
9 status_led=""
10
11 led_set_attr() {
12         [ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
13 }
14
15 status_led_set_timer() {
16         led_set_attr $status_led "trigger" "timer"
17         led_set_attr $status_led "delay_on" "$1"
18         led_set_attr $status_led "delay_off" "$2"
19 }
20
21 status_led_on() {
22         led_set_attr $status_led "trigger" "none"
23         led_set_attr $status_led "brightness" 255
24 }
25
26 status_led_off() {
27         led_set_attr $status_led "trigger" "none"
28         led_set_attr $status_led "brightness" 0
29 }
30
31 get_status_led() {
32         case $(ramips_board_name) in
33         3g-6200n)
34                 status_led="edimax:green:power"
35                 ;;
36         argus-atp52b)
37                 status_led="argus-atp52b:green:run"
38                 ;;
39         dir-300-b1 | dir-600-b1 | dir-600-b2 | dir-615-h1 | dir-615-d | dir-620-a1)
40                 status_led="d-link:green:status"
41                 ;;
42         dir-645)
43                 status_led="d-link:green:wps"
44                 ;;
45         dap-1350)
46                 status_led="d-link:blue:power"
47                 ;;
48         esr-9753)
49                 status_led="esr-9753:orange:power"
50                 ;;
51         f5d8235-v2)
52                 status_led="f5d8235v2:blue:router"
53                 ;;
54         fonera20n)
55                 status_led="fonera20n:green:power"
56                 ;;
57         rt-n13u)
58                 status_led="rt-n13u:power"
59                 ;;
60         all0239-3g|\
61         hw550-3g)
62                 status_led="hw550-3g:green:status"
63                 ;;
64         mofi3500-3gn)
65                 status_led="mofi3500-3gn:green:status"
66                 ;;
67         nbg-419n)
68                 status_led="nbg-419n:green:power"
69                 ;;
70         nw718)
71                 status_led="nw718:amber:cpu"
72                 ;;
73         omni-emb)
74                 status_led="emb:green:status"
75                 ;;
76         psr-680w)
77                 status_led="psr-680w:red:wan"
78                 ;;
79         pwh2004)
80                 status_led="pwh2004:green:power"
81                 ;;
82         rt-n15)
83                 status_led="rt-n15:blue:power"
84                 ;;
85         rt-n10-plus)
86                 status_led="asus:green:wps"
87                 ;;
88         rt-n56u | wl-330n | wl-330n3g)
89                 status_led="asus:blue:power"
90                 ;;
91         sl-r7205)
92                 status_led="sl-r7205:green:status"
93                 ;;
94         tew-691gr|\
95         tew-692gr)
96                 status_led="trendnet:green:wps"
97                 ;;
98         v11st-fe)
99                 status_led="v11st-fe:green:status"
100                 ;;
101         v22rw-2x2)
102                 status_led="v22rw-2x2:green:security"
103                 ;;
104         w306r-v20)
105                 status_led="w306r-v20:green:sys"
106                 ;;
107         w502u)
108                 status_led="alfa:blue:wps"
109                 ;;
110         wcr-150gn)
111                 status_led="wcr150gn:amber:power"
112                 ;;
113         whr-g300n)
114                 status_led="whr-g300n:green:router"
115                 ;;
116         wli-tx4-ag300n)
117                 status_led="buffalo:blue:power"
118                 ;;
119         wl-351)
120                 status_led="wl-351:amber:power"
121                 ;;
122         wr512-3gn)
123                 status_led="wr512:green:wps"
124                 ;;
125         mzk-w300nh2)
126                 status_led="mzkw300nh2:green:power"
127                 ;;
128         ur-336un)
129                 status_led="ur336:green:wps"
130                 ;;
131         xdxrn502j)
132                 status_led="xdxrn502j:green:power"
133                 ;;
134         esac
135 }
136
137 set_state() {
138         get_status_led
139
140         case "$1" in
141         preinit)
142                 insmod leds-gpio
143                 status_led_set_timer 200 200
144                 ;;
145         failsafe)
146                 status_led_set_timer 50 50
147                 ;;
148         done)
149                 status_led_on
150                 ;;
151         esac
152 }