root/src/router/rc/watchdog.c

Revision 12410, 1.8 kB (checked in by eko, 5 months ago)

check only sw disabled radio

Line 
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <utils.h>
6 #include <wlutils.h>
7 #include <errno.h>
8 #if !defined(HAVE_MICRO) || defined(HAVE_ADM5120)
9
10 static void watchdog(void)
11 {
12         int brand = getRouterBrand();
13         int registered = -1;
14         int radiostate = -1;
15         int oldstate = -1;
16
17         int fd = open("/dev/misc/watchdog", O_WRONLY);
18
19         if (fd == -1) {
20                 return;
21         }
22         while (1) {
23                 write(fd, "\0", 1);
24                 fsync(fd);
25
26 #ifdef HAVE_REGISTER
27                 if (!nvram_match("flash_active", "1")) {
28                         if (registered == -1)
29                                 registered = isregistered_real();
30                         if (!registered)
31                                 isregistered(); //to poll
32                 }
33 #endif
34                 /*
35                  * software wlan led control
36                  */
37 #ifdef HAVE_MADWIFI
38                 if (!nvram_match("flash_active", "1")) {
39                         radiostate = get_radiostate("ath0");
40                 }
41 #else
42                 wl_ioctl(get_wdev(), WLC_GET_RADIO, &radiostate, sizeof(int));
43 #endif
44
45                 if (radiostate != oldstate) {
46 #ifdef HAVE_MADWIFI
47                         if (radiostate == 1)
48 #else
49                         if (radiostate & WL_RADIO_SW_DISABLE == 0)
50 #endif
51                                 led_control(LED_WLAN, LED_ON);
52                         else {
53                                 led_control(LED_WLAN, LED_OFF);
54 #ifndef HAVE_MADWIFI
55                                 /*
56                                  * Disable wireless will cause diag led blink, so we want to
57                                  * stop it.
58                                  */
59                                 if (brand == ROUTER_WRT54G)
60                                         diag_led(DIAG, STOP_LED);
61                                 /*
62                                  * Disable wireless will cause power led off, so we want to
63                                  * turn it on.
64                                  */
65                                 if (brand == ROUTER_WRT54G_V8)
66                                         led_control(LED_POWER, LED_ON);
67 #endif
68                         }
69
70                         oldstate = radiostate;
71                 }
72                 /*
73                  * end software wlan led control
74                  */
75
76                 sleep(10);
77         }
78 }
79
80 int watchdog_main(int argc, char *argv[])
81 {
82
83         /*
84          * Run it under background
85          */
86         switch (fork()) {
87         case -1:
88                 perror("fork failed");
89                 exit(1);
90                 break;
91         case 0:
92                 /*
93                  * child process
94                  */
95                 watchdog();
96                 exit(0);
97                 break;
98         default:
99                 /*
100                  * parent process should just die
101                  */
102                 _exit(0);
103         }
104         return 0;
105 }
106 #endif
Note: See TracBrowser for help on using the browser.