void ez_event_long(void) { int ez_action = nvram_get_int("ez_action_long"); switch (ez_action) { case 7: case 8: alarmtimer(0, 0); LED_CONTROL(LED_POWER, LED_OFF); break; default: alarmtimer(NORMAL_PERIOD, 0); LED_CONTROL(LED_POWER, LED_ON); break; } switch (ez_action) { case 1: // WiFi 2.4GHz force ON/OFF trigger ez_action_force_toggle_wifi24(); break; case 2: // WiFi 5GHz force ON/OFF trigger ez_action_force_toggle_wifi5(); break; case 3: // WiFi 2.4 and 5GHz force ON/OFF trigger ez_action_force_toggle_wifi24(); ez_action_force_toggle_wifi5(); break; case 4: // Safe removal all USB ez_action_usb_saferemoval(); break; case 5: // WAN down ez_action_wan_down(); break; case 6: // WAN reconnect ez_action_wan_reconnect(); break; case 7: // Router reboot sys_exit(); break; case 8: // Router shutdown prepare ez_action_shutdown(); break; case 9: // WAN up/down toggle ez_action_wan_toggle(); break; case 10: // Run user script (/opt/bin/on_wps.sh 2) ez_action_user_script(2); break; case 11: // Front LED toggle ez_action_led_toggle(); break; } }
static void catch_sig(int sig) { if (sig == SIGTERM) { alarmtimer(0, 0); remove("/var/run/watchdog.pid"); exit(0); } else if (sig == SIGHUP) { setenv_tz(); ntpc_timer = -1; // want call now } else if (sig == SIGUSR1) { int wd_notify_id = nvram_get_int("wd_notify_id"); if (wd_notify_id == WD_NOTIFY_ID_WIFI2) { update_svc_status_wifi24(); } else if (wd_notify_id == WD_NOTIFY_ID_WIFI5) { update_svc_status_wifi5(); } } else if (sig == SIGUSR2) { nmap_timer = 1; } }
int ipv6aide_main(int argc, char *argv[]) { FILE *fp; sigset_t sigs_to_catch; /* write pid */ if ((fp=fopen("/var/run/ipv6aide.pid", "w")) != NULL) { fprintf(fp, "%d", getpid()); fclose(fp); } up = uptime(); sigemptyset(&sigs_to_catch); sigaddset(&sigs_to_catch, SIGTERM); sigaddset(&sigs_to_catch, SIGALRM); sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL); signal(SIGTERM, ipv6aide_exit); signal(SIGALRM, ipv6aide_check); alarmtimer(NORMAL_PERIOD, 0); /* listen for replies */ while (1) { pause(); } return 0; }
int inicd_main(int argc, char *argv[]) { FILE *fp; signal(SIGPIPE, SIG_IGN); signal(SIGUSR1, SIG_IGN); signal(SIGUSR2, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGTERM, catch_sig_inicd); signal(SIGALRM, catch_sig_inicd); if (daemon(0, 0) < 0) { perror("daemon"); exit(errno); } /* write pid */ if ((fp = fopen("/var/run/inicd.pid", "w")) != NULL) { fprintf(fp, "%d", getpid()); fclose(fp); } /* set timer 10s */ alarmtimer(10, 0); /* Most of time it goes to sleep */ while (1) { pause(); } return 0; }
static void wpsfix_check(int sig) { int unit; time_t now = uptime(); if (nvram_match("wps_band", "0")) unit = 0; else unit = 1; if (((now - up) >= 600) && !wl_WscConfigured(unit)) { stop_wsc(); nvram_set("wps_sta_pin", "00000000"); nvram_set("wps_enable", "0"); nvram_set("wl_wps_mode", "disabled"); nvram_set("wl0_wps_mode", "disabled"); nvram_set("wl1_wps_mode", "disabled"); wpsfix_exit(sig); } else alarmtimer(60, 0); }
static void ipv6aide_exit(int sig) { alarmtimer(0, 0); remove("/var/run/ipv6aide.pid"); exit(0); }
static void blink(int sig) { // dbG("\n\n\nreceive SIGUSR1 to usbled\n\n\n"); alarmtimer(0, USBLED_URGENT_PERIOD); usb_busy = 1; }
static void wpsfix_exit(int sig) { alarmtimer(0, 0); remove("/var/run/wpsfix.pid"); exit(0); }
void lostpeer(void) { int save_errno = errno; alarmtimer(0); if (connected) { if (cout != NULL) { (void)shutdown(fileno(cout), SHUT_RDWR); (void)fclose(cout); cout = NULL; } if (data >= 0) { (void)shutdown(data, SHUT_RDWR); (void)close(data); data = -1; } connected = 0; } pswitch(1); if (connected) { if (cout != NULL) { (void)shutdown(fileno(cout), SHUT_RDWR); (void)fclose(cout); cout = NULL; } connected = 0; } proxflag = 0; pswitch(0); errno = save_errno; }
void intr(void) { alarmtimer(0); longjmp(toplevel, 1); }
int main(int argc, char *argv[]) { brand = getRouterBrand(); #ifndef HAVE_MI424WR #if !defined(HAVE_NOP8670) && !defined(HAVE_TONZE) if ((brand & 0x000f) == 0x000f) #endif { puts("sorry, your unit does not support resetbutton feature\n"); return 0; } #endif #ifndef HAVE_NOP8670 #ifdef HAVE_MAGICBOX init_gpio(); #endif /* * Run it under background */ switch (fork()) { case -1: DEBUG("can't fork\n"); exit(0); break; case 0: /* * child process */ DEBUG("fork ok\n"); (void)setsid(); break; default: /* * parent process should just die */ _exit(0); } /* * set the signal handler */ signal(SIGALRM, period_check); /* * set timer */ alarmtimer(NORMAL_INTERVAL, 0); /* * Most of time it goes to sleep */ while (1) pause(); return 0; #endif }
/* ARGSUSED */ void abortfile(int signo) { alarmtimer(0); fputs("\nfile fetch aborted.\n", ttyout); (void)fflush(ttyout); longjmp(httpabort, 1); }
static void psta_monitor_exit(int sig) { if (sig == SIGTERM) { alarmtimer(0, 0); remove("/var/run/psta_monitor.pid"); exit(0); } }
static void catch_sig_inicd(int sig) { if (sig == SIGTERM) { alarmtimer(0, 0); remove("/var/run/inicd.pid"); exit(0); } else if (sig == SIGALRM) { check_inic_radio(); } }
static void no_blink(int sig) { // dbG("\n\n\nreceive SIGUSR2 in usbled\n\n\n"); alarmtimer(USBLED_NORMAL_PERIOD, 0); status_usb = -1; #ifdef LED_USB3 if(model==MODEL_RTAC56U || model==MODEL_RTAC68U) { got_usb2 = -1; got_usb3 = -1; } #endif usb_busy = 0; }
void service_restart(void) { DEBUG("resetbutton: restart\n"); /* * Stop the timer alarm */ alarmtimer(0, 0); /* * Reset the Diagnostic LED */ diag_led(DIAG, START_LED); /* call from service.c */ /* * Restart all of services */ eval("rc", "restart"); }
int watchdog_main(int argc, char *argv[]) { FILE *fp; sigset_t sigs_to_catch; /* set the signal handler */ sigemptyset(&sigs_to_catch); sigaddset(&sigs_to_catch, SIGHUP); sigaddset(&sigs_to_catch, SIGTERM); sigaddset(&sigs_to_catch, SIGUSR1); sigaddset(&sigs_to_catch, SIGUSR2); sigaddset(&sigs_to_catch, SIGALRM); sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL); signal(SIGPIPE, SIG_IGN); signal(SIGHUP, catch_sig); signal(SIGTERM, catch_sig); signal(SIGUSR1, catch_sig); signal(SIGUSR2, catch_sig); signal(SIGALRM, watchdog); if (daemon(0, 0) < 0) { perror("daemon"); exit(errno); } nvram_set_int("wd_notify_id", 0); /* write pid */ if ((fp = fopen("/var/run/watchdog.pid", "w")) != NULL) { fprintf(fp, "%d", getpid()); fclose(fp); } /* set timer */ alarmtimer(NORMAL_PERIOD, 0); /* Most of time it goes to sleep */ while (1) { pause(); } return 0; }
void ez_event_short(void) { int ez_action = nvram_get_int("ez_action_short"); alarmtimer(NORMAL_PERIOD, 0); LED_CONTROL(LED_POWER, LED_ON); switch (ez_action) { case 1: // WiFi radio ON/OFF trigger ez_action_toggle_wifi24(); ez_action_toggle_wifi5(); break; case 2: // WiFi 2.4GHz force ON/OFF trigger ez_action_force_toggle_wifi24(); break; case 3: // WiFi 5GHz force ON/OFF trigger ez_action_force_toggle_wifi5(); break; case 4: // WiFi 2.4 and 5GHz force ON/OFF trigger ez_action_force_toggle_wifi24(); ez_action_force_toggle_wifi5(); break; case 5: // Safe removal all USB ez_action_usb_saferemoval(); break; case 6: // WAN down ez_action_wan_down(); break; case 7: // WAN reconnect ez_action_wan_reconnect(); break; case 8: // WAN up/down toggle ez_action_wan_toggle(); break; case 9: // Run user script (/opt/bin/on_wps.sh 1) ez_action_user_script(1); break; case 10: // Front LED toggle ez_action_led_toggle(); break; } }
int usbled_main(int argc, char *argv[]) { FILE *fp; sigset_t sigs_to_catch; model = get_model(); /* write pid */ if ((fp = fopen("/var/run/usbled.pid", "w")) != NULL) { fprintf(fp, "%d", getpid()); fclose(fp); } usb_busy = 0; /* set the signal handler */ sigemptyset(&sigs_to_catch); sigaddset(&sigs_to_catch, SIGALRM); sigaddset(&sigs_to_catch, SIGTERM); sigaddset(&sigs_to_catch, SIGUSR1); sigaddset(&sigs_to_catch, SIGUSR2); #ifdef RTCONFIG_USBEJECT sigaddset(&sigs_to_catch, SIGTSTP); #endif sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL); signal(SIGALRM, usbled); signal(SIGTERM, usbled_exit); signal(SIGUSR1, blink); signal(SIGUSR2, no_blink); #ifdef RTCONFIG_USBEJECT signal(SIGTSTP, reset_status); #endif alarmtimer(USBLED_NORMAL_PERIOD, 0); /* Most of time it goes to sleep */ while (1) { pause(); } return 0; }
static void usbled_exit(int sig) { alarmtimer(0, 0); status_usb = 0; #ifdef LED_USB3 if(model==MODEL_RTAC56U || model==MODEL_RTAC68U) { got_usb2 = 0; got_usb3 = 0; } #endif usb_busy = 0; led_control(LED_USB, LED_OFF); #ifdef LED_USB3 if(model==MODEL_RTAC56U || model==MODEL_RTAC68U) led_control(LED_USB3, LED_OFF); #endif remove("/var/run/usbled.pid"); exit(0); }
int wpsfix_main(int argc, char *argv[]) { FILE *fp; /* write pid */ if ((fp=fopen("/var/run/wpsfix.pid", "w"))!=NULL) { fprintf(fp, "%d", getpid()); fclose(fp); } up = uptime(); signal(SIGTERM, wpsfix_exit); signal(SIGALRM, wpsfix_check); alarmtimer(60, 0); /* listen for replies */ while (1) { pause(); } }
int ipv6aide_main(int argc, char *argv[]) { FILE *fp; /* write pid */ if ((fp=fopen("/var/run/ipv6aide.pid", "w")) != NULL) { fprintf(fp, "%d", getpid()); fclose(fp); } up = uptime(); signal(SIGTERM, ipv6aide_exit); signal(SIGALRM, ipv6aide_check); alarmtimer(NORMAL_PERIOD, 0); /* listen for replies */ while (1) { pause(); } }
static void ipv6aide_check(int sig) { char tmp[64]; char *p = NULL; char *q, *r; if (get_ipv6_service() != IPV6_NATIVE_DHCP) goto END; p = nvram_safe_get("ipv6_gw_addr"); if (strlen(p)) { eval("route", "-A", "inet6", "add", "2000::/3", "gw", p, "dev", (char*)get_wan6face()); goto END; } r = strdup(ipv6_gateway_address()); if (!r) return; memset(tmp, 0, sizeof(tmp)); q = tmp; p = strtok_r(r, " ", &q); if (!p || !strlen(p) || !strlen(q)) { alarmtimer(NORMAL_PERIOD, 0); return; } dbG("ipv6 gateway: %s (dev %s)\n", p, q); eval("route", "-A", "inet6", "add", "2000::/3", "gw", p, "dev", q); free(r); END: ipv6aide_exit(sig); }
static void ipv6aide_check(int sig) { char tmp[64]; char *p = NULL; char *q; if (get_ipv6_service() != IPV6_NATIVE_DHCP) goto END; memset(tmp, 0, sizeof(tmp)); q = tmp; p = strtok_r(ipv6_gateway_address(), " ", &q); if (!p || !strlen(p) || !strlen(q)) { alarmtimer(NORMAL_PERIOD, 0); return; } dbG("ipv6 gateway: %s (dev %s)\n", p, q); eval("route", "-A", "inet6", "add", "2000::/3", "gw", p, "dev", q); END: ipv6aide_exit(sig); }
static void catch_sig(int sig) { if (sig == SIGUSR1) { dbg("[watchdog] Catch SIGUSR1 for rc_service\n"); if (nvram_get("rc_service")) service_handle(); } else if (sig == SIGUSR2) { // dbg("[watchdog] Catch Reset to Default Signal 2\n"); } else if (sig == SIGTSTP && !nvram_match("sw_mode_ex", "3")) { if (nvram_match("wps_oob_flag", "1")) { #if defined (W7_LOGO) || defined (WIFI_LOGO) if (nvram_match("wps_band", "0")) if (nvram_match("wl_radio_x", "0")) return; else if (nvram_match("rt_radio_x", "0")) return; #else #if 0 if (nvram_match("wl_radio_x", "0") || nvram_match("rt_radio_x", "0")) #else if (nvram_match("wl_radio_x", "0") && nvram_match("rt_radio_x", "0")) #endif return; #endif #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) nvram_set("wps_triggered", "1"); // psp fix count_to_stop_wps = 0; #endif nvram_set("wps_oob_flag", "0"); wsc_timeout = 0; btn_pressed_setup = BTNSETUP_NONE; btn_count_setup = 0; LED_CONTROL(LED_POWER, LED_ON); alarmtimer(NORMAL_PERIOD, 0); #if defined (W7_LOGO) || defined (WIFI_LOGO) if (nvram_match("wps_band", "0")) wps_oob(); else wps_oob_2g(); #else wps_oob_both(); #endif WscStatus_old = -1; WscStatus_old_2g = -1; } else if (nvram_match("wps_start_flag", "3") || nvram_match("wps_start_flag", "4")) // let the SW push button be the same as the HW push button { #if defined (W7_LOGO) || defined (WIFI_LOGO) if (nvram_match("wps_band", "0")) if (nvram_match("wl_radio_x", "0")) return; else if (nvram_match("rt_radio_x", "0")) return; #else #if 0 if (nvram_match("wl_radio_x", "0") || nvram_match("rt_radio_x", "0")) #else if (nvram_match("wl_radio_x", "0") && nvram_match("rt_radio_x", "0")) #endif return; #endif // if (nvram_match("wl_radio_x", "1")) stop_wsc(); // if (nvram_match("rt_radio_x", "1")) stop_wsc_2g(); nvram_set("wps_enable", "0"); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) nvram_set("wps_triggered", "1"); // psp fix count_to_stop_wps = 0; if (nvram_match("wps_start_flag", "3")) nvram_set("wps_band", "1"); else nvram_set("wps_band", "0"); #endif nvram_set("wps_start_flag", "0"); alarmtimer(NORMAL_PERIOD, 0); btn_pressed_setup = BTNSETUP_START; btn_count_setup = 0; btn_count_setup_second = 0; #if defined (W7_LOGO) || defined (WIFI_LOGO) if (nvram_match("wps_band", "0")) start_wsc_pbc(); else start_wsc_pbc_2g(); #else #if 0 start_wsc_pbc_both(); #else if (nvram_match("wps_band", "1")) start_wsc_pbc_2g(); else start_wsc_pbc(); #endif #endif WscStatus_old = -1; WscStatus_old_2g = -1; wsc_timeout = 120*20; alarmtimer(0, RUSHURGENT_PERIOD); } else if (nvram_match("wps_enable", "0")) { #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) nvram_set("wps_triggered", "1"); // psp fix count_to_stop_wps = 0; #endif wsc_timeout = 1; btn_pressed_setup = BTNSETUP_NONE; btn_count_setup = 0; LED_CONTROL(LED_POWER, LED_ON); alarmtimer(NORMAL_PERIOD, 0); // if (nvram_match("wps_band", "0")) // if (nvram_match("wl_radio_x", "1")) stop_wsc(); // else // if (nvram_match("rt_radio_x", "1")) stop_wsc_2g(); } else if (nvram_match("wps_start_flag", "1")) { if (nvram_match("wps_band", "0")) if (nvram_match("wl_radio_x", "0")) return; else if (nvram_match("rt_radio_x", "0")) return; #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) nvram_set("wps_triggered", "1"); // psp fix count_to_stop_wps = 15; #endif nvram_set("wps_start_flag", "0"); wsc_timeout = 1; btn_pressed_setup = BTNSETUP_NONE; btn_count_setup = 0; LED_CONTROL(LED_POWER, LED_ON); alarmtimer(NORMAL_PERIOD, 0); WscStatus_old = -1; WscStatus_old_2g = -1; if (nvram_match("wps_band", "0")) start_wsc(); else start_wsc_2g(); } else if (nvram_match("wps_start_flag", "2")) { if (nvram_match("wps_mode", "1")) { if (nvram_match("wps_band", "0")) if (nvram_match("wl_radio_x", "0")) return; else if (nvram_match("rt_radio_x", "0")) return; } else { #if defined (W7_LOGO) || defined (WIFI_LOGO) if (nvram_match("wps_band", "0")) if (nvram_match("wl_radio_x", "0")) return; else if (nvram_match("rt_radio_x", "0")) return; #else #if 0 if (nvram_match("wl_radio_x", "0") || nvram_match("rt_radio_x", "0")) #else if (nvram_match("wl_radio_x", "0") && nvram_match("rt_radio_x", "0")) #endif return; #endif } #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) nvram_set("wps_triggered", "1"); // psp fix count_to_stop_wps = 0; #endif nvram_set("wps_start_flag", "0"); alarmtimer(NORMAL_PERIOD, 0); btn_pressed_setup = BTNSETUP_START; btn_count_setup = 0; if (nvram_match("wps_mode", "1")) { if (nvram_match("wps_pin_web", "")) { if (nvram_match("wps_band", "0")) wps_pin("0"); else wps_pin_2g("0"); } else { if (nvram_match("wps_band", "0")) wps_pin(nvram_safe_get("wps_pin_web")); else wps_pin_2g(nvram_safe_get("wps_pin_web")); } } else { #if defined (W7_LOGO) || defined (WIFI_LOGO) if (nvram_match("wps_band", "0")) wps_pbc(); else wps_pbc_2g(); #else #if 0 wps_pbc_both(); #else nvram_set("wps_band", "1"); wps_pbc_2g(); #endif #endif } WscStatus_old = -1; WscStatus_old_2g = -1; wsc_timeout = 120*20; alarmtimer(0, RUSHURGENT_PERIOD); } } else if (sig == SIGTTIN) { wsc_user_commit(); } }
void period_check(int sig) { FILE *fp; unsigned int val = 0; #ifdef HAVE_RADIOOFF if (initses == 1 && nvram_match("radiooff_boot_off", "1") && nvram_match("radiooff_button", "1")) { ses_mode = 1; initses = 0; } #endif // time_t t; // time(&t); // DEBUG("resetbutton: now time=%d\n", t); #if defined(HAVE_MAGICBOX) || defined(HAVE_FONERA) || defined(HAVE_WHRAG108) || defined(HAVE_GATEWORX) || defined(HAVE_STORM) || defined(HAVE_LS2) || defined(HAVE_CA8) || defined(HAVE_TW6600) || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_WP54G) || defined(HAVE_NP28G) || defined(HAVE_SOLO51) || defined(HAVE_OPENRISC) || defined(HAVE_DANUBE) || defined(HAVE_WDR4900) || defined(HAVE_VENTANA) val = getbuttonstate(); #ifdef HAVE_WRK54G if (val) val = 0; else val = 1; #endif #ifndef HAVE_ALPHA #ifdef HAVE_USR5453 if (val) val = 0; else val = 1; #endif #endif #else if (brand == ROUTER_BOARD_WCRGN) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_WHRG300N) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_HAMEA15) { val = get_gpio(0); } else if (brand == ROUTER_BOARD_ECB9750) { val = get_gpio(11) << 11; } else if (brand == ROUTER_BOARD_NEPTUNE) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_RT3352) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_WR5422) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_DIR600B) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_F5D8235) { val = get_gpio(10) << 10; } else if (brand == ROUTER_ASUS_RTN10PLUS) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_RT15N) { val = get_gpio(12) << 12; } else if (brand == ROUTER_BOARD_DIR615D) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_ESR6650) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_EAP9550) { val = get_gpio(0); } else if (brand == ROUTER_BOARD_ESR9752) { val = get_gpio(0); } else if (brand == ROUTER_BOARD_AR670W) { val = get_gpio(9) << 9; } else if (brand == ROUTER_BOARD_AR690W) { val = get_gpio(9) << 9; } else if (brand == ROUTER_BOARD_BR6574N) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_ACXNR22) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_TECHNAXX3G) { val = get_gpio(10) << 10; } else if (brand == ROUTER_WHR300HP2) { val = get_gpio(52) << 1; } else if (brand == ROUTER_BOARD_W502U) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_GW2380) { val = get_gpio(240); } else if (brand == ROUTER_BOARD_GW2388) { val = get_gpio(240); } else { if ((fp = fopen(GPIO_FILE, "r"))) { #ifdef HAVE_XSCALE fscanf(fp, "%d", &val); #else if (brand == ROUTER_NETGEAR_WGR614L) //gpio 7 power led shared with reset button { set_gpio(7, 1); //disable power led val = get_gpio(7) << 7; //read and shift value set_gpio(7, 0); //enable power led } else { fread(&val, 4, 1, fp); } #endif fclose(fp); } else perror(GPIO_FILE); } #endif DEBUG("resetbutton: GPIO = 0x%x\n", val); int gpio = 0; int state = 0; #if defined(HAVE_XSCALE) || defined(HAVE_MAGICBOX) || defined(HAVE_FONERA) || defined(HAVE_WHRAG108) || defined(HAVE_GATEWORX) || defined(HAVE_STORM) || defined(HAVE_LS2) || defined(HAVE_CA8) || defined(HAVE_TW6600) || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_WP54G) || defined(HAVE_NP28G) || defined(HAVE_SOLO51) || defined(HAVE_OPENRISC) || defined(HAVE_DANUBE) || defined(HAVE_UNIWIP) || defined(HAVE_VENTANA) state = val; int sesgpio = 0xfff; int wifigpio = 0xfff; int push; int pushwifi; #ifdef HAVE_WZRG300NH sesgpio = 0x117; val |= get_gpio(23) << 23; //aoss pushbutton #elif defined(HAVE_WHR300HP2) sesgpio = 0x102; val |= get_gpio(53) << 2; //aoss pushbutton #elif defined(HAVE_NEPTUNE) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_HAMEA15) // sesgpio = 0x100; // val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_WCRGN) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_RT3352) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_WZRG300NH2) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_WMBR_G300NH) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_WZRG450) sesgpio = 0x108; val |= get_gpio(8) << 8; //aoss pushbutton #elif defined(HAVE_DIR632) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_WZRHPAG300NH) sesgpio = 0x105; val |= get_gpio(5) << 5; //aoss pushbutton #elif defined(HAVE_CARAMBOLA) sesgpio = 0xfff; #elif defined(HAVE_HORNET) sesgpio = 0x00b; val |= get_gpio(11) << 11; //aoss pushbutton #elif defined(HAVE_RB2011) // sesgpio = 0x110; // val |= get_gpio(16) << 16; //aoss pushbutton #elif defined(HAVE_WDR4300) // sesgpio = 0x110; // val |= get_gpio(16) << 16; //aoss pushbutton #elif defined(HAVE_WNDR3700V4) sesgpio = 0x10f; val |= get_gpio(15) << 15; //aoss pushbutton #elif defined(HAVE_DIR825C1) sesgpio = 0x110; val |= get_gpio(16) << 16; //aoss pushbutton #elif defined(HAVE_WASP) sesgpio = 0x00b; val |= get_gpio(11) << 11; //aoss pushbutton #elif defined(HAVE_WNR2200) // sesgpio = 0x00b; //not yet supported // val |= get_gpio(37) << 37; //aoss pushbutton #elif defined(HAVE_WNR2000) sesgpio = 0x00b; val |= get_gpio(11) << 11; //aoss pushbutton #elif defined(HAVE_WDR2543) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_WHRHPGN) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_RT10N) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_RT15N) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_F5D8235) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_WR5422) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_DIR600) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_DIR615I) sesgpio = 0x110; val |= get_gpio(16) << 16; //aoss pushbutton #elif defined(HAVE_DIR615E) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_WR1043) sesgpio = 0x107; val |= get_gpio(7) << 7; //aoss pushbutton #elif defined(HAVE_WR941) sesgpio = 0x107; val |= get_gpio(7) << 7; //aoss pushbutton #elif defined(HAVE_MR3020) sesgpio = 0xfff; #elif defined(HAVE_WR741V4) sesgpio = 0x01a; val |= get_gpio(26) << 26; //aoss pushbutton #elif defined(HAVE_WR741) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_WRT400) sesgpio = 0x103; val |= get_gpio(3) << 3; //aoss pushbutton #elif defined(HAVE_WNDR3700) sesgpio = 0x103; val |= get_gpio(3) << 3; //aoss pushbutton #elif defined(HAVE_DIR825) sesgpio = 0x108; val |= get_gpio(8) << 8; //aoss pushbutton #elif defined(HAVE_TG2521) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_OPENRISC) sesgpio = 0x005; val |= get_gpio(5) << 5; //aoss pushbutton #endif #ifdef HAVE_WRT160NL sesgpio = 0x107; val |= get_gpio(7) << 7; //wps/ses pushbutton #endif #ifdef HAVE_TEW632BRP sesgpio = 0x10c; val |= get_gpio(12) << 12; //wps/ses pushbutton #endif #else if (brand > 0xffff) { if ((brand & 0x000ff) != 0x000ff) gpio = 1 << (brand & 0x000ff); // calculate gpio value. if ((brand & 0x00100) == 0) // check reset button polarity: 0 // normal, 1 inversed state = (val & gpio); else state = !(val & gpio); } else { if ((brand & 0x000f) != 0x000f) gpio = 1 << (brand & 0x000f); // calculate gpio value. if ((brand & 0x0010) == 0) // check reset button polarity: 0 // normal, 1 inversed state = (val & gpio); else state = !(val & gpio); } /* * 1 byte router's SES (AOSS) button gpio number and polarity; Eko * 25.nov.06 * * R R R P N N N N = 0xXX ----- - ------- | | gpio num | | | |--- SES - * AOSS button polarity (0: normal, 1 inversed) | |-------- reserved for * future use * * 0xff = button disabled / not available */ int push; int pushwifi; int sesgpio; int wifigpio = 0xfff; switch (brand) { case ROUTER_BUFFALO_WHRG54S: case ROUTER_BUFFALO_WZRRSG54: case ROUTER_BUFFALO_WLI_TX4_G54HP: sesgpio = 0x100; // gpio 0, inversed break; case ROUTER_BUFFALO_WLA2G54C: sesgpio = 0x102; // gpio 2, inversed break; case ROUTER_BUFFALO_WBR2G54S: sesgpio = 0x004; // gpio 4, normal break; case ROUTER_BUFFALO_WZR600DHP2: case ROUTER_BUFFALO_WZR900DHP: sesgpio = 0x109; // gpio 9, inversed break; case ROUTER_BUFFALO_WZR1750: sesgpio = 0x10c; // gpio 12, inversed break; case ROUTER_D1800H: sesgpio = 0x10a; // gpio 10, inversed break; #ifndef HAVE_BUFFALO case ROUTER_ASUS_WL700GE: sesgpio = 0x004; // gpio 4, normal break; case ROUTER_ASUS_RTN10PLUSD1: sesgpio = 0x114; // gpio 20, inversed break; case ROUTER_ASUS_RTN10: sesgpio = 0x102; // gpio 2, inversed break; case ROUTER_ASUS_RTN12: case ROUTER_NETGEAR_WNR2000V2: sesgpio = 0x100; // gpio 0, inversed break; case ROUTER_LINKSYS_WTR54GS: case ROUTER_NETGEAR_WNDR4000: sesgpio = 0x102; // gpio 2, inversed break; case ROUTER_WRT54G: case ROUTER_WRT54G_V8: case ROUTER_WRTSL54GS: case ROUTER_WRT150N: case ROUTER_WRT160N: case ROUTER_WRT300N: case ROUTER_WRT300NV11: case ROUTER_WRT610NV2: case ROUTER_ASKEY_RT220XD: // not soldered case ROUTER_DYNEX_DX_NRUTER: case ROUTER_LINKSYS_E4200: case ROUTER_ASUS_RTN66: sesgpio = 0x104; // gpio 4, inversed break; case ROUTER_ASUS_AC66U: sesgpio = 0x104; // gpio 4, inversed break; case ROUTER_DLINK_DIR868: case ROUTER_ASUS_AC67U: wifigpio = 0x10f; sesgpio = 0x107; // gpio 7, inversed break; case ROUTER_ASUS_AC56U: wifigpio = 0x107; // gpio 7, inversed sesgpio = 0x10f; // gpio 7, inversed break; case ROUTER_ASUS_WL500G_PRE: sesgpio = 0x004; // gpio 4, normal break; case ROUTER_ASUS_WL550GE: sesgpio = 0x00f; // gpio 15, normal break; case ROUTER_WRT310N: case ROUTER_WRT350N: case ROUTER_WRT610N: case ROUTER_ASUS_RTN16: case ROUTER_BELKIN_F7D3301: case ROUTER_BELKIN_F7D3302: case ROUTER_BELKIN_F7D4301: case ROUTER_BELKIN_F7D4302: case ROUTER_BELKIN_F5D8235V3: case ROUTER_LINKSYS_E3200: sesgpio = 0x108; // gpio 8, inversed break; case ROUTER_ASUS_WL500W: sesgpio = 0x007; // gpio 7, normal break; case ROUTER_DLINK_DIR330: sesgpio = 0x107; // gpio 7, inversed break; case ROUTER_ASUS_WL520GUGC: case ROUTER_ASUS_WL500G_PRE_V2: sesgpio = 0x103; // gpio 3, inversed break; case ROUTER_WAP54G_V3: sesgpio = 0x10e; // gpio 14, inversed break; case ROUTER_NETGEAR_WNDR3300: sesgpio = 0x101; // gpio 1, inversed break; case ROUTER_WRT54G_V81: case ROUTER_DLINK_DIR320: case ROUTER_WRT600N: case ROUTER_NETGEAR_WNDR3400: case ROUTER_NETGEAR_WNR3500L: sesgpio = 0x106; // gpio 6, inversed break; case ROUTER_WRT320N: case ROUTER_WRT160NV3: case ROUTER_NETGEAR_WNDR4500: case ROUTER_NETGEAR_WNDR4500V2: case ROUTER_NETGEAR_R6300: sesgpio = 0x104; wifigpio = 0x105; break; case ROUTER_NETGEAR_R6250: sesgpio = 0x104; wifigpio = 0x105; break; case ROUTER_NETGEAR_R6300V2: sesgpio = 0x104; wifigpio = 0x105; break; case ROUTER_NETGEAR_R7000: sesgpio = 0x104; wifigpio = 0x105; break; case ROUTER_WRT310NV2: sesgpio = 0x105; // gpio 5, inversed break; case ROUTER_LINKSYS_E800: case ROUTER_LINKSYS_E900: case ROUTER_LINKSYS_E1000V2: case ROUTER_LINKSYS_E1500: case ROUTER_LINKSYS_E1550: case ROUTER_LINKSYS_E2500: sesgpio = 0x109; // gpio 9, inversed break; case ROUTER_LINKSYS_EA6500: sesgpio = 0x104; // gpio 4, inversed break; #endif default: sesgpio = 0xfff; // gpio unknown, disabled wifigpio = 0xfff; // gpio unknown, disabled } #endif push = 1 << (sesgpio & 0x0ff); // calculate push value from ses gpio pushwifi = 1 << (wifigpio & 0x0ff); // calculate push value from ses gpio // // // // pin no. /* * The value is zero during button-pushed. */ if (state && nvram_match("resetbutton_enable", "1")) { DEBUG("resetbutton: mode=%d, count=%d\n", mode, count); if (mode == 0) { /* * We detect button pushed first time */ alarmtimer(0, URGENT_INTERVAL); mode = 1; } { /* Whenever it is pushed steady */ if (++count > RESET_WAIT_COUNT) { if (check_action() != ACT_IDLE) { // Don't execute during upgrading fprintf(stderr, "resetbutton: nothing to do...\n"); alarmtimer(0, 0); /* Stop the timer alarm */ return; } if ((brand & 0x000f) != 0x000f) { printf("resetbutton: factory default.\n"); dd_syslog(LOG_DEBUG, "Reset button: restoring factory defaults now!\n"); #if !defined(HAVE_XSCALE) && !defined(HAVE_MAGICBOX) && !defined(HAVE_FONERA) && !defined(HAVE_WHRAG108) && !defined(HAVE_GATEWORX) && !defined(HAVE_LS2) && !defined(HAVE_CA8) && !defined(HAVE_TW6600) && !defined(HAVE_LS5) && !defined(HAVE_LSX) && !defined(HAVE_SOLO51) led_control(LED_DIAG, LED_ON); #elif defined(HAVE_WHRHPGN) || defined(HAVE_WZRG300NH) || defined(HAVE_WZRHPAG300NH) || defined(HAVE_WZRG450) led_control(LED_DIAG, LED_ON); #endif ACTION("ACT_HW_RESTORE"); alarmtimer(0, 0); /* Stop the timer alarm */ #ifdef HAVE_X86 eval("mount", "/usr/local", "-o", "remount,rw"); eval("rm", "-f", "/tmp/nvram/*"); // delete nvram // database eval("rm", "-f", "/tmp/nvram/.lock"); // delete // nvram // database eval("rm", "-f", "/usr/local/nvram/*"); // delete // nvram // database eval("mount", "/usr/local", "-o", "remount,ro"); #elif HAVE_RB500 eval("rm", "-f", "/tmp/nvram/*"); // delete nvram // database eval("rm", "-f", "/tmp/nvram/.lock"); // delete // nvram // database eval("rm", "-f", "/etc/nvram/*"); // delete nvram // database #elif HAVE_MAGICBOX eval("rm", "-f", "/tmp/nvram/*"); // delete nvram // database eval("rm", "-f", "/tmp/nvram/.lock"); // delete // nvram // database eval("erase", "nvram"); #else #ifdef HAVE_BUFFALO_SA int region_sa = 0; if (nvram_default_match("region", "SA", "")) region_sa = 1; #endif nvram_set("sv_restore_defaults", "1"); nvram_commit(); eval("killall", "ledtool"); // stop blinking on // nvram_commit #if !defined(HAVE_XSCALE) && !defined(HAVE_MAGICBOX) && !defined(HAVE_FONERA) && !defined(HAVE_WHRAG108) && !defined(HAVE_GATEWORX) && !defined(HAVE_LS2) && !defined(HAVE_CA8) && !defined(HAVE_TW6600) && !defined(HAVE_LS5) && !defined(HAVE_LSX) && !defined(HAVE_SOLO51) led_control(LED_DIAG, LED_ON); // turn diag led on, // so we know reset // was pressed and // we're restoring // defaults. #elif defined(HAVE_WHRHPGN) || defined(HAVE_WZRG300NH) || defined(HAVE_WZRHPAG300NH) || defined(HAVE_WZRG450) led_control(LED_DIAG, LED_ON); #endif #ifdef HAVE_BUFFALO_SA nvram_set("sv_restore_defaults", "1"); if (region_sa) nvram_set("region", "SA"); nvram_commit(); #endif #endif // nvram_set ("sv_restore_defaults", "1"); // nvram_commit (); kill(1, SIGTERM); } } } } else if ((sesgpio != 0xfff) && (((sesgpio & 0x100) == 0 && (val & push)) || ((sesgpio & 0x100) == 0x100 && !(val & push)))) { runStartup("/etc/config", ".sesbutton"); runStartup("/jffs/etc/config", ".sesbutton"); // if available runStartup("/mmc/etc/config", ".sesbutton"); // if available runStartup("/tmp/etc/config", ".sesbutton"); // if available if (nvram_match("radiooff_button", "1")) { led_control(LED_SES, LED_FLASH); // when pressed, blink white switch (ses_mode) { case 1: // SES (AOSS) led #ifdef HAVE_RADIOOFF #ifndef HAVE_BUFFALO dd_syslog(LOG_DEBUG, "SES / AOSS / EZ-setup button: turning radio(s) on\n"); #else dd_syslog(LOG_DEBUG, "AOSS button: turning radio(s) on\n"); #endif #ifndef HAVE_ERC sysprintf("startservice radio_on"); #endif #endif ses_mode = 0; break; case 2: // (AOSS) led #ifdef HAVE_RADIOOFF #ifndef HAVE_BUFFALO dd_syslog(LOG_DEBUG, "SES / AOSS / EZ-setup button: turning radio(s) off\n"); #else dd_syslog(LOG_DEBUG, "AOSS button: turning radio(s) off\n"); #endif #ifndef HAVE_ERC sysprintf("startservice radio_off"); #endif #endif ses_mode = 1; break; } } #ifdef HAVE_AOSS else if (nvram_match("radiooff_button", "2")) { sysprintf("startservice aoss"); } #else #endif } else if ((wifigpio != 0xfff) && (((wifigpio & 0x100) == 0 && (val & pushwifi)) || ((wifigpio & 0x100) == 0x100 && !(val & pushwifi)))) { led_control(LED_WLAN, LED_FLASH); // when pressed, blink white switch (wifi_mode) { case 1: dd_syslog(LOG_DEBUG, "Wifi button: turning radio(s) on\n"); sysprintf("startservice radio_on"); wifi_mode = 0; break; case 0: // (AOSS) led dd_syslog(LOG_DEBUG, "Wifi button: turning radio(s) off\n"); sysprintf("startservice radio_off"); wifi_mode = 1; break; } } else { /* * Although it's unpushed now, it had ever been pushed */ if (mode == 1) { if (check_action() != ACT_IDLE) { // Don't execute during upgrading fprintf(stderr, "resetbutton: nothing to do...\n"); alarmtimer(0, 0); /* Stop the timer alarm */ return; } service_restart(); } } }
void btn_check(void) { #ifdef BTN_SETUP if (btn_pressed_setup == BTNSETUP_NONE) { #endif #ifdef SR3 if (!ralink_gpio_read_bit(BTN_RESET)) // reset button is on low phase #else if (0) #endif { /*--------------- Add BTN_RST MFG test ------------------------*/ if (!nvram_match("asus_mfg", "0")) { nvram_set("btn_rst", "1"); } else { if (!btn_pressed) { btn_pressed = 1; btn_count = 0; alarmtimer(0, URGENT_PERIOD); } else { /* Whenever it is pushed steady */ if (++btn_count > RESET_WAIT_COUNT) { dbg("You can release RESET button now!\n"); btn_pressed = 2; } if (btn_pressed == 2) { /* 0123456789 */ /* 0011100111 */ if ((btn_count % 10) < 1 || ((btn_count % 10) > 4 && (btn_count % 10) < 7)) LED_CONTROL(LED_POWER, LED_OFF); else LED_CONTROL(LED_POWER, LED_ON); } } } // end BTN_RST MFG test } else { if (btn_pressed == 1) { btn_count = 0; btn_pressed = 0; LED_CONTROL(LED_POWER, LED_ON); alarmtimer(NORMAL_PERIOD, 0); } else if (btn_pressed == 2) { LED_CONTROL(LED_POWER, LED_OFF); alarmtimer(0, 0); system("erase /dev/mtd1"); // kill(1, SIGTERM); sys_exit(); } } #ifdef BTN_SETUP } if (btn_pressed != 0) return; if (btn_pressed_setup < BTNSETUP_START) { if (!ralink_gpio_read_bit(BTN_WPS) && !no_need_to_start_wps(0)) { /* Add BTN_EZ MFG test */ if (!nvram_match("asus_mfg", "0")) { nvram_set("btn_ez", "1"); } else { if (btn_pressed_setup == BTNSETUP_NONE) { btn_pressed_setup = BTNSETUP_DETECT; btn_count_setup = 0; alarmtimer(0, RUSHURGENT_PERIOD); } else { /* Whenever it is pushed steady */ if (++btn_count_setup > SETUP_WAIT_COUNT) { if (!nvram_match("sw_mode_ex", "3")) { stop_wsc(); stop_wsc_2g(); nvram_set("wps_enable", "0"); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) nvram_set("wps_triggered", "1"); // psp fix #endif btn_pressed_setup = BTNSETUP_START; btn_count_setup = 0; btn_count_setup_second = 0; #if defined (W7_LOGO) || defined (WIFI_LOGO) if (nvram_match("wps_band", "0")) start_wsc_pbc(); else start_wsc_pbc_2g(); #else #if 0 start_wsc_pbc_both(); #else nvram_set("wps_band", "1"); start_wsc_pbc_2g(); #endif #endif WscStatus_old = -1; WscStatus_old_2g = -1; wsc_timeout = 120*20; } } } } // end BTN_EZ MFG test } else if (btn_pressed_setup == BTNSETUP_DETECT) { btn_pressed_setup = BTNSETUP_NONE; btn_count_setup = 0; LED_CONTROL(LED_POWER, LED_ON); alarmtimer(NORMAL_PERIOD, 0); } } else { if (!ralink_gpio_read_bit(BTN_WPS) && !no_need_to_start_wps(0)) { /* Whenever it is pushed steady, again... */ if (++btn_count_setup_second > SETUP_WAIT_COUNT) { if (!nvram_match("sw_mode_ex", "3")) { stop_wsc(); stop_wsc_2g(); nvram_set("wps_enable", "0"); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) nvram_set("wps_triggered", "1"); // psp fix #endif dbg("pushed again...\n"); btn_pressed_setup = BTNSETUP_START; btn_count_setup_second = 0; #if defined (W7_LOGO) || defined (WIFI_LOGO) if (nvram_match("wps_band", "0")) start_wsc_pbc(); else start_wsc_pbc_2g(); #else #if 0 start_wsc_pbc_both(); #else nvram_set("wps_band", "1"); start_wsc_pbc_2g(); #endif #endif WscStatus_old = -1; WscStatus_old_2g = -1; wsc_timeout = 120*20; } #if 0 else { dbg("pushed again... do nothing...\n"); /* btn_pressed_setup = BTNSETUP_START; btn_count_setup_second = 0; sta_wps_pbc(); wsc_timeout = 120*20; */ } #endif } } struct _WSC_CONFIGURED_VALUE wsc_value; int int_stop_wps_led = 0; int WscStatus = -1; int WscStatus_2g = -1; if (nvram_match("wps_mode", "1")) // PIN { if (nvram_match("wps_band", "0")) WscStatus = getWscStatus(); else WscStatus = getWscStatus_2g(); } else // PBC { WscStatus = getWscStatus(); WscStatus_2g = getWscStatus_2g(); } if (WscStatus_old != WscStatus) { WscStatus_old = WscStatus; dbg("WscStatus: %d\n", WscStatus); } if (nvram_match("wps_mode", "2") && WscStatus_old_2g != WscStatus_2g) { WscStatus_old_2g = WscStatus_2g; dbg("WscStatus_2g: %d\n", WscStatus_2g); } if (WscStatus == 2 || WscStatus_2g == 2)// Wsc Process failed { if (g_isEnrollee) ; // go on monitoring else { int_stop_wps_led = 1; dbg("%s", "Error occured. Is the PIN correct?\n"); } } // Driver 1.9 supports AP PBC Session Overlapping Detection. if (WscStatus == 0x109 /* PBC_SESSION_OVERLAP */ || WscStatus_2g == 0x109) { dbg("PBC_SESSION_OVERLAP\n"); int_stop_wps_led = 1; } if (nvram_match("wps_mode", "1")) // PIN { if (WscStatus == 34 /* Configured*/) { /* dbg("getWscProfile()\n"); getWscProfile(WIF, &wsc_value, sizeof(WSC_CONFIGURED_VALUE)); */ if (!g_wsc_configured) g_wsc_configured = 1; int_stop_wps_led = 1; g_isEnrollee = 0; } } else // PBC { if (WscStatus == 34 /* Configured*/ || WscStatus_2g == 34) { if (!g_wsc_configured) g_wsc_configured = 1; int_stop_wps_led = 1; g_isEnrollee = 0; } } if (int_stop_wps_led || --wsc_timeout == 0) { if(!nvram_match("sw_mode_ex", "3")) // not AP mode { #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) nvram_set("wps_triggered", "1");// psp fix #endif wsc_timeout = 0; btn_pressed_setup = BTNSETUP_NONE; btn_count_setup = 0; LED_CONTROL(LED_POWER, LED_ON); alarmtimer(NORMAL_PERIOD, 0); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) // if (nvram_match("wps_band", "0")) stop_wsc(); // psp fix // else stop_wsc_2g(); // psp fix nvram_set("wps_enable", "0"); // psp fix #endif } return; } ++btn_count_setup; btn_count_setup = (btn_count_setup % 20); /* 0123456789 */ /* 1010101010 */ if ((btn_count_setup % 2) == 0 && (btn_count_setup > 10)) LED_CONTROL(LED_POWER, LED_ON); else LED_CONTROL(LED_POWER, LED_OFF); } #endif }
static void usbled(int sig) { usb_path1 = nvram_safe_get("usb_path1"); usb_path2 = nvram_safe_get("usb_path2"); status_usb_old = status_usb; status_usb = usb_status(); #ifdef LED_USB3 if(model==MODEL_RTAC56U || model==MODEL_RTAC68U){ got_usb2_old = got_usb2; got_usb2 = check_usb2(); got_usb3_old = got_usb3; got_usb3 = check_usb3(); } #endif if(nvram_match("asus_mfg", "1") #ifdef RTCONFIG_USBEJECT || !nvram_get_int("AllLED") #endif ) no_blink(sig); else if (!usb_busy #ifdef RTCONFIG_USBEJECT && nvram_get_int("AllLED") #endif ) { if(model==MODEL_RTAC56U || model==MODEL_RTAC68U){ if(got_usb2 != got_usb2_old){ if(got_usb2) led_control(LED_USB, LED_ON); else led_control(LED_USB, LED_OFF); } #ifdef LED_USB3 if(got_usb3 != got_usb3_old){ if(got_usb3) led_control(LED_USB3, LED_ON); else led_control(LED_USB3, LED_OFF); } #endif } else if (status_usb != status_usb_old) { if (status_usb) led_control(LED_USB, LED_ON); else led_control(LED_USB, LED_OFF); } } else #ifdef RTCONFIG_USBEJECT if (nvram_get_int("AllLED")) #endif { if (strcmp(usb_path1, "storage") && strcmp(usb_path2, "storage")) { no_blink(sig); } else { count = (count+1) % 20; /* 0123456710 */ /* 1010101010 */ if (((count % 2) == 0) && (count > 8)) led_control(LED_USB, LED_ON); else led_control(LED_USB, LED_OFF); alarmtimer(0, USBLED_URGENT_PERIOD); } } }
void progressmeter(int flag) { static off_t lastsize; off_t cursize; struct timeval now, wait; #ifndef NO_PROGRESS struct timeval td; off_t abbrevsize, bytespersec; double elapsed; int ratio, i, remaining, barlength; /* * Work variables for progress bar. * * XXX: if the format of the progress bar changes * (especially the number of characters in the * `static' portion of it), be sure to update * these appropriately. */ #endif size_t len; char buf[256]; /* workspace for progress bar */ #ifndef NO_PROGRESS #define BAROVERHEAD 45 /* non `*' portion of progress bar */ /* * stars should contain at least * sizeof(buf) - BAROVERHEAD entries */ static const char stars[] = "*****************************************************************************" "*****************************************************************************" "*****************************************************************************"; #endif if (flag == -1) { (void)gettimeofday(&start, NULL); lastupdate = start; lastsize = restart_point; } (void)gettimeofday(&now, NULL); cursize = bytes + restart_point; timersub(&now, &lastupdate, &wait); if (cursize > lastsize) { lastupdate = now; lastsize = cursize; wait.tv_sec = 0; } else { #ifndef STANDALONE_PROGRESS if (quit_time > 0 && wait.tv_sec > quit_time) { len = snprintf(buf, sizeof(buf), "\r\n%s: " "transfer aborted because stalled for %lu sec.\r\n", getprogname(), (unsigned long)wait.tv_sec); (void)write(fileno(ttyout), buf, len); (void)xsignal(SIGALRM, SIG_DFL); alarmtimer(0); siglongjmp(toplevel, 1); } #endif /* !STANDALONE_PROGRESS */ } /* * Always set the handler even if we are not the foreground process. */ #ifdef STANDALONE_PROGRESS if (progress) { #else if (quit_time > 0 || progress) { #endif /* !STANDALONE_PROGRESS */ if (flag == -1) { (void)xsignal_restart(SIGALRM, updateprogressmeter, 1); alarmtimer(1); /* set alarm timer for 1 Hz */ } else if (flag == 1) { (void)xsignal(SIGALRM, SIG_DFL); alarmtimer(0); } } #ifndef NO_PROGRESS if (!progress) return; len = 0; /* * print progress bar only if we are foreground process. */ if (! foregroundproc()) return; len += snprintf(buf + len, BUFLEFT, "\r"); if (prefix) len += snprintf(buf + len, BUFLEFT, "%s", prefix); if (filesize > 0) { ratio = (int)((double)cursize * 100.0 / (double)filesize); ratio = MAX(ratio, 0); ratio = MIN(ratio, 100); len += snprintf(buf + len, BUFLEFT, "%3d%% ", ratio); /* * calculate the length of the `*' bar, ensuring that * the number of stars won't exceed the buffer size */ barlength = MIN(sizeof(buf) - 1, ttywidth) - BAROVERHEAD; if (prefix) barlength -= (int)strlen(prefix); if (barlength > 0) { i = barlength * ratio / 100; len += snprintf(buf + len, BUFLEFT, "|%.*s%*s|", i, stars, (int)(barlength - i), ""); } } abbrevsize = cursize; for (i = 0; abbrevsize >= 100000 && i < NSUFFIXES; i++) abbrevsize >>= 10; if (i == NSUFFIXES) i--; len += snprintf(buf + len, BUFLEFT, " " LLFP("5") " %-3s ", (LLT)abbrevsize, suffixes[i]); timersub(&now, &start, &td); elapsed = td.tv_sec + (td.tv_usec / 1000000.0); bytespersec = 0; if (bytes > 0) { bytespersec = bytes; if (elapsed > 0.0) bytespersec /= elapsed; } for (i = 1; bytespersec >= 1024000 && i < NSUFFIXES; i++) bytespersec >>= 10; len += snprintf(buf + len, BUFLEFT, " " LLFP("3") ".%02d %.2sB/s ", (LLT)(bytespersec / 1024), (int)((bytespersec % 1024) * 100 / 1024), suffixes[i]); if (filesize > 0) { if (bytes <= 0 || elapsed <= 0.0 || cursize > filesize) { len += snprintf(buf + len, BUFLEFT, " --:-- ETA"); } else if (wait.tv_sec >= STALLTIME) { len += snprintf(buf + len, BUFLEFT, " - stalled -"); } else { remaining = (int) ((filesize - restart_point) / (bytes / elapsed) - elapsed); if (remaining >= 100 * SECSPERHOUR) len += snprintf(buf + len, BUFLEFT, " --:-- ETA"); else { i = remaining / SECSPERHOUR; if (i) len += snprintf(buf + len, BUFLEFT, "%2d:", i); else len += snprintf(buf + len, BUFLEFT, " "); i = remaining % SECSPERHOUR; len += snprintf(buf + len, BUFLEFT, "%02d:%02d ETA", i / 60, i % 60); } } } if (flag == 1) len += snprintf(buf + len, BUFLEFT, "\n"); (void)write(fileno(ttyout), buf, len); #endif /* !NO_PROGRESS */ } #ifndef STANDALONE_PROGRESS /* * Display transfer statistics. * Requires start to be initialised by progressmeter(-1), * direction to be defined by xfer routines, and filesize and bytes * to be updated by xfer routines * If siginfo is nonzero, an ETA is displayed, and the output goes to stderr * instead of ttyout. */ void ptransfer(int siginfo) { struct timeval now, td, wait; double elapsed; off_t bytespersec; int remaining, hh, i; size_t len; char buf[256]; /* Work variable for transfer status. */ if (!verbose && !progress && !siginfo) return; (void)gettimeofday(&now, NULL); timersub(&now, &start, &td); elapsed = td.tv_sec + (td.tv_usec / 1000000.0); bytespersec = 0; if (bytes > 0) { bytespersec = bytes; if (elapsed > 0.0) bytespersec /= elapsed; } len = 0; len += snprintf(buf + len, BUFLEFT, LLF " byte%s %s in ", (LLT)bytes, bytes == 1 ? "" : "s", direction); remaining = (int)elapsed; if (remaining > SECSPERDAY) { int days; days = remaining / SECSPERDAY; remaining %= SECSPERDAY; len += snprintf(buf + len, BUFLEFT, "%d day%s ", days, days == 1 ? "" : "s"); } hh = remaining / SECSPERHOUR; remaining %= SECSPERHOUR; if (hh) len += snprintf(buf + len, BUFLEFT, "%2d:", hh); len += snprintf(buf + len, BUFLEFT, "%02d:%02d ", remaining / 60, remaining % 60); for (i = 1; bytespersec >= 1024000 && i < NSUFFIXES; i++) bytespersec >>= 10; if (i == NSUFFIXES) i--; len += snprintf(buf + len, BUFLEFT, "(" LLF ".%02d %.2sB/s)", (LLT)(bytespersec / 1024), (int)((bytespersec % 1024) * 100 / 1024), suffixes[i]); if (siginfo && bytes > 0 && elapsed > 0.0 && filesize >= 0 && bytes + restart_point <= filesize) { remaining = (int)((filesize - restart_point) / (bytes / elapsed) - elapsed); hh = remaining / SECSPERHOUR; remaining %= SECSPERHOUR; len += snprintf(buf + len, BUFLEFT, " ETA: "); if (hh) len += snprintf(buf + len, BUFLEFT, "%2d:", hh); len += snprintf(buf + len, BUFLEFT, "%02d:%02d", remaining / 60, remaining % 60); timersub(&now, &lastupdate, &wait); if (wait.tv_sec >= STALLTIME) len += snprintf(buf + len, BUFLEFT, " (stalled)"); } len += snprintf(buf + len, BUFLEFT, "\n"); (void)write(siginfo ? STDERR_FILENO : fileno(ttyout), buf, len); } /* * SIG{INFO,QUIT} handler to print transfer stats if a transfer is in progress */ void psummary(int notused) { int oerrno = errno; if (bytes > 0) { if (fromatty) write(fileno(ttyout), "\n", 1); ptransfer(1); } errno = oerrno; }
int watchdog_main(int argc, char *argv[]) { FILE *fp; sigset_t sigs_to_catch; #ifdef REMOVE /* Run it under background */ switch (fork()) { case -1: exit(0); break; case 0: // start in a new session (void) setsid(); break; default: /* parent process should just die */ _exit(0); } #endif /* write pid */ if ((fp = fopen("/var/run/watchdog.pid", "w")) != NULL) { fprintf(fp, "%d", getpid()); fclose(fp); } doSystem("iwpriv %s set WatchdogPid=%d", WIF, getpid()); doSystem("iwpriv %s set WatchdogPid=%d", WIF2G, getpid()); /* Start GPIO function */ ra_gpio_init(); /* set the signal handler */ sigemptyset(&sigs_to_catch); sigaddset(&sigs_to_catch, SIGUSR1); sigaddset(&sigs_to_catch, SIGUSR2); sigaddset(&sigs_to_catch, SIGTSTP); sigaddset(&sigs_to_catch, SIGALRM); sigaddset(&sigs_to_catch, SIGTTIN); sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL); signal(SIGUSR1, catch_sig); signal(SIGUSR2, catch_sig); signal(SIGTSTP, catch_sig); signal(SIGALRM, watchdog); signal(SIGTTIN, catch_sig); nvram_set("btn_rst", "0"); nvram_set("btn_ez", "0"); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) // if (!pids("ots")) // start_ots(); #endif setenv("TZ", nvram_safe_get("time_zone_x"), 1); /* set timer */ alarmtimer(NORMAL_PERIOD, 0); if ( nvram_match("wan_route_x", "IP_Routed") && (nvram_match("wan0_proto", "pppoe") || nvram_match("wan0_proto", "pptp") || nvram_match("wan0_proto", "l2tp")) ) { if (nvram_match("wan0_proto", "pppoe") && nvram_match("wan0_pppoe_demand", "1") && !ppp0_as_default_route()) { // system("route add -net default gateway 10.112.112.112 netmask 0.0.0.0 dev ppp0"); preset_wan_routes("ppp0"); } eval("ping", "8.8.8.8", "-c", "3"); } /* Most of time it goes to sleep */ while (1) { pause(); } return 0; }