int check_wanup(void) { int up = 0; int proto; char buf1[64]; char buf2[64]; const char *name; int f; struct ifreq ifr; proto = get_wan_proto(); if (proto == WP_DISABLED) return 0; if ((proto == WP_PPTP) || (proto == WP_L2TP) || (proto == WP_PPPOE) || (proto == WP_HEARTBEAT)) { if (f_read_string("/tmp/ppp/link", buf1, sizeof(buf1)) > 0) { if (proto == WP_HEARTBEAT) { // contains pid of bpalogin if (strcmp(psname(atoi(buf1), buf2, sizeof(buf2)), "bpalogin") == 0) { up = 1; } } else { // contains the base name of a file in /var/run/ containing pid of a daemon snprintf(buf2, sizeof(buf2), "/var/run/%s.pid", buf1); if (f_read_string(buf2, buf1, sizeof(buf1)) > 0) { name = psname(atoi(buf1), buf2, sizeof(buf2)); if (proto == WP_PPPOE) { if (strcmp(name, "pppoecd") == 0) up = 1; } else { if (strcmp(name, "pppd") == 0) up = 1; } } } if (!up) { unlink("/tmp/ppp/link"); cprintf("required daemon not found, assuming link is dead\n"); } } } else if (!nvram_match("wan_ipaddr", "0.0.0.0")) { up = 1; } if ((up) && ((f = socket(AF_INET, SOCK_DGRAM, 0)) >= 0)) { strlcpy(ifr.ifr_name, nvram_safe_get("wan_iface"), sizeof(ifr.ifr_name)); if (ioctl(f, SIOCGIFFLAGS, &ifr) < 0) up = 0; close(f); if ((ifr.ifr_flags & IFF_UP) == 0) up = 0; } return up; }
uint32_t get_gpio(uint32_t gpio) { char path[PATH_MAX], value[10]; sprintf(path, "%s/gpio%d/value", GPIOLIB_DIR, gpio); f_read_string(path, value, sizeof(value)); return atoi(value); }
int ppid(int pid) { char buf[512]; char path[64]; int ppid = 0; buf[0] = 0; sprintf(path, "/proc/%d/stat", pid); if ((f_read_string(path, buf, sizeof(buf)) > 4)) sscanf(buf, "%*d %*s %*c %d", &ppid); return ppid; }
static unsigned int read_ct_timeout(const char *type, const char *name) { char buf[128]; unsigned int val = 0; char v[16]; sprintf(buf, "/proc/sys/net/ipv4/netfilter/ip_conntrack_%s_timeout%s%s", type, (name && name[0]) ? "_" : "", name ? name : ""); if (f_read_string(buf, v, sizeof(v)) > 0) val = atoi(v); return val; }
int resmsg_fread(const char *fname) { char s[256]; char *p; f_read_string(fname, s, sizeof(s)); if ((p = strchr(s, '\n')) != NULL) *p = 0; if (s[0]) { resmsg_set(s); return 1; } return 0; }
char *psname(int pid, char *buffer, int maxlen) { char buf[512]; char path[64]; char *p; if (maxlen <= 0) return NULL; *buffer = 0; sprintf(path, "/proc/%d/stat", pid); if ((f_read_string(path, buf, sizeof(buf)) > 4) && ((p = strrchr(buf, ')')) != NULL)) { *p = 0; if (((p = strchr(buf, '(')) != NULL) && (atoi(buf) == pid)) { strlcpy(buffer, p + 1, maxlen); } } return buffer; }
uint32_t gpio_dir(uint32_t gpio, int dir) { char path[PATH_MAX], v[10], *dir_str = "in"; if (dir == GPIO_DIR_OUT) { dir_str = "out"; /* output, low voltage */ *v = '\0'; sprintf(path, "%s/gpio%d/value", GPIOLIB_DIR, gpio); if (f_read_string(path, v, sizeof(v)) > 0 && atoi(v) == 1) dir_str = "high"; /* output, high voltage */ } __export_gpio(gpio); sprintf(path, "%s/gpio%d/direction", GPIOLIB_DIR, gpio); f_write_string(path, dir_str, 0, 0); return 0; }
int main(int argc, char **argv) { char *base; int f; /* Make sure std* are valid since several functions attempt to close these handles. If nvram_*() runs first, nvram=0, nvram gets closed. - zzz */ if ((f = open("/dev/null", O_RDWR)) < 0) { } else if(f < 3) { dup(f); dup(f); } else { close(f); } base = strrchr(argv[0], '/'); base = base ? base + 1 : argv[0]; #if 0 if (strcmp(base, "rc") == 0) { if (argc < 2) return 1; if (strcmp(argv[1], "start") == 0) return kill(1, SIGUSR2); if (strcmp(argv[1], "stop") == 0) return kill(1, SIGINT); if (strcmp(argv[1], "restart") == 0) return kill(1, SIGHUP); ++argv; --argc; base = argv[0]; } #endif #ifdef RTCONFIG_RALINK if(getpid() != 1) { #endif #if defined(DEBUG_NOISY) if (nvram_match("debug_logrc", "1")) { int i; cprintf("[rc %d] ", getpid()); for (i = 0; i < argc; ++i) { cprintf("%s ", argv[i]); } cprintf("\n"); } #endif #if defined(DEBUG_NOISY) if (nvram_match("debug_ovrc", "1")) { char tmp[256]; char *a[32]; realpath(argv[0], tmp); if ((strncmp(tmp, "/tmp/", 5) != 0) && (argc < 32)) { sprintf(tmp, "%s%s", "/tmp/", base); if (f_exists(tmp)) { cprintf("[rc] override: %s\n", tmp); memcpy(a, argv, argc * sizeof(a[0])); a[argc] = 0; a[0] = tmp; execvp(tmp, a); exit(0); } } } #endif #ifdef RTCONFIG_RALINK } #endif const applets_t *a; for (a = applets; a->name; ++a) { if (strcmp(base, a->name) == 0) { openlog(base, LOG_PID, LOG_USER); return a->main(argc, argv); } } if(!strcmp(base, "restart_wireless")){ printf("restart wireless...\n"); restart_wireless(); return 0; } else if(!strcmp(base, "nvram_erase")){ erase_nvram(); return 0; } #ifdef RTCONFIG_USB else if(!strcmp(base, "get_apps_name")){ if(argc != 2){ printf("Usage: get_apps_name [File name]\n"); return 0; } return get_apps_name(argv[1]); } else if(!strcmp(base, "asus_sd")){ if(argc != 3){ printf("Usage: asus_sd [device_name] [action]\n"); return 0; } return asus_sd(argv[1], argv[2]); } else if(!strcmp(base, "asus_lp")){ if(argc != 3){ printf("Usage: asus_lp [device_name] [action]\n"); return 0; } return asus_lp(argv[1], argv[2]); } else if(!strcmp(base, "asus_sg")){ if(argc != 3){ printf("Usage: asus_sg [device_name] [action]\n"); return 0; } return asus_sg(argv[1], argv[2]); } else if(!strcmp(base, "asus_sr")){ if(argc != 3){ printf("Usage: asus_sr [device_name] [action]\n"); return 0; } return asus_sr(argv[1], argv[2]); } else if(!strcmp(base, "asus_tty")){ if(argc != 3){ printf("Usage: asus_tty [device_name] [action]\n"); return 0; } return asus_tty(argv[1], argv[2]); } else if(!strcmp(base, "asus_usbbcm")){ if(argc != 3){ printf("Usage: asus_usbbcm [device_name] [action]\n"); return 0; } return asus_usbbcm(argv[1], argv[2]); } else if(!strcmp(base, "asus_usb_interface")){ if(argc != 3){ printf("Usage: asus_usb_interface [device_name] [action]\n"); return 0; } return asus_usb_interface(argv[1], argv[2]); } else if (!strcmp(base, "usb_notify")) { #if defined(RTCONFIG_APP_PREINSTALLED) || defined(RTCONFIG_APP_NETINSTALLED) usb_notify(); #endif return 0; } #if defined(RTCONFIG_APP_PREINSTALLED) || defined(RTCONFIG_APP_NETINSTALLED) else if(!strcmp(base, "run_app_script")){ if(argc != 3){ printf("Usage: run_app_script [Package name | allpkg] [APP action]\n"); return 0; } if(!strcmp(argv[1], "allpkg")) return run_app_script(NULL, argv[2]); else return run_app_script(argv[1], argv[2]); } else if (!strcmp(base, "chk_app_state")) { #define PID_FILE "/var/run/chk_app_state.pid" FILE *fp; char chk_value[4]; if(f_read_string(PID_FILE, chk_value, 4) > 0 && atoi(chk_value) != getpid()){ _dprintf("Already running!\n"); return 0; } if((fp = fopen(PID_FILE, "w")) == NULL){ _dprintf("Can't open the pid file!\n"); return 0; } fprintf(fp, "%d", getpid()); fclose(fp); memset(chk_value, 0, 4); strncpy(chk_value, nvram_safe_get("apps_state_switch"), 4); if(strcmp(chk_value, "")){ if(atoi(chk_value) != APPS_SWITCH_FINISHED && !pids("app_switch.sh")){ _dprintf("Don't have the switch script.\n"); nvram_set("apps_state_switch", ""); } unlink(PID_FILE); return 0; } memset(chk_value, 0, 4); strncpy(chk_value, nvram_safe_get("apps_state_install"), 4); if(strcmp(chk_value, "")){ if(atoi(chk_value) != APPS_INSTALL_FINISHED && !pids("app_install.sh")){ _dprintf("Don't have the install script.\n"); nvram_set("apps_state_install", ""); } unlink(PID_FILE); return 0; } memset(chk_value, 0, 4); strncpy(chk_value, nvram_safe_get("apps_state_upgrade"), 4); if(strcmp(chk_value, "")){ if(atoi(chk_value) != APPS_UPGRADE_FINISHED && !pids("app_upgrade.sh")){ _dprintf("Don't have the upgrade script.\n"); nvram_set("apps_state_upgrade", ""); } unlink(PID_FILE); return 0; } memset(chk_value, 0, 4); strncpy(chk_value, nvram_safe_get("apps_state_enable"), 4); if(strcmp(chk_value, "")){ if(atoi(chk_value) != APPS_ENABLE_FINISHED && !pids("app_set_enabled.sh")){ _dprintf("Don't have the enable script.\n"); nvram_set("apps_state_enable", ""); } unlink(PID_FILE); return 0; } unlink(PID_FILE); return 0; } #endif #endif else if(!strcmp(base, "ATE")) { if( argc == 2 || argc == 3 || argc == 4) { asus_ate_command(argv[1], argv[2], argv[3]); } else printf("ATE_ERROR\n"); return 0; } #if defined(RTCONFIG_RALINK) else if (!strcmp(base, "FWRITE")) { if (argc == 3) return FWRITE(argv[1], argv[2]); else return 0; } else if (!strcmp(base, "FREAD")) { if (argc == 3) { unsigned int addr; int len; addr = strtoul(argv[1], NULL, 16); if(argv[2][0] == '0' && argv[2][1] == 'x') len = (int) strtoul(argv[2], NULL, 16); else len = (int) strtoul(argv[2], NULL, 10); if(len > 0) return FREAD(addr, len); } printf("ATE_ERROR\n"); return 0; } else if (!strcmp(base, "asuscfe_5g")) { if (argc == 2) return asuscfe(argv[1], WIF_5G); else return EINVAL; } else if (!strcmp(base, "asuscfe_2g")) { if (argc == 2) return asuscfe(argv[1], WIF_2G); else return EINVAL; } else if (!strcmp(base, "stainfo_2g")) { return stainfo(0); } else if (!strcmp(base, "stainfo_5g")) { return stainfo(1); } #ifdef RTCONFIG_DSL else if(!strcmp(base, "gen_ralink_config")){ if(argc != 3){ printf("Usage: gen_ralink_config [band] [is_iNIC]\n"); return 0; } return gen_ralink_config(atoi(argv[1]), atoi(argv[2])); } #endif #endif else if(!strcmp(base, "run_telnetd")) { run_telnetd(); return 0; } #if defined(RTCONFIG_PPTPD) || defined(RTCONFIG_ACCEL_PPTPD) else if(!strcmp(base, "run_pptpd")) { start_pptpd(); return 0; } #endif #ifdef RTCONFIG_PARENTALCTRL else if(!strcmp(base, "pc")) { pc_main(argc, argv); return 0; } #endif #ifdef CONFIG_BCMWL5 else if (!strcmp(base, "wlcscan")) { return wlcscan_main(); } #endif #ifdef RTCONFIG_WIRELESSREPEATER else if (!strcmp(base, "wlcconnect")) { return wlcconnect_main(); } else if (!strcmp(base, "setup_dnsmq")) { if(argc != 2) return 0; return setup_dnsmq(atoi(argv[1])); } #endif else if (!strcmp(base, "add_multi_routes")) { return add_multi_routes(); } else if (!strcmp(base, "led_ctrl")) { if (argc != 3) return 0; return(led_control(atoi(argv[1]), atoi(argv[2]))); } #ifdef RTCONFIG_BCMARM /* mtd-erase2 [device] */ else if (!strcmp(base, "mtd-erase2")) { if (argv[1] && ((!strcmp(argv[1], "boot")) || (!strcmp(argv[1], "linux")) || (!strcmp(argv[1], "linux2")) || (!strcmp(argv[1], "rootfs")) || (!strcmp(argv[1], "rootfs2")) || (!strcmp(argv[1], "nvram")))) { return mtd_erase(argv[1]); } else { fprintf(stderr, "usage: mtd-erase2 [device]\n"); return EINVAL; } } /* mtd-write2 [path] [device] */ else if (!strcmp(base, "mtd-write2")) { if (argc >= 3) return mtd_write(argv[1], argv[2]); else { fprintf(stderr, "usage: mtd-write2 [path] [device]\n"); return EINVAL; } } #endif else if (!strcmp(base, "free_caches")) { int c; unsigned int test_num; char *set_value = NULL; int clean_time = 1; int threshold = 0; if(argc){ while((c = getopt(argc, argv, "c:w:t:")) != -1){ switch(c){ case 'c': // set the clean-cache mode: 0~3. test_num = strtol(optarg, NULL, 10); if(test_num == LONG_MIN || test_num == LONG_MAX){ _dprintf("ERROR: unknown value %s...\n", optarg); return 0; } if(test_num < 0 || test_num > 3){ _dprintf("ERROR: the value %s was over the range...\n", optarg); return 0; } set_value = optarg; break; case 'w': // set the waited time for cleaning. test_num = strtol(optarg, NULL, 10); if(test_num < 0 || test_num == LONG_MIN || test_num == LONG_MAX){ _dprintf("ERROR: unknown value %s...\n", optarg); return 0; } clean_time = test_num; break; case 't': // set the waited time for cleaning. test_num = strtol(optarg, NULL, 10); if(test_num < 0 || test_num == LONG_MIN || test_num == LONG_MAX){ _dprintf("ERROR: unknown value %s...\n", optarg); return 0; } threshold = test_num; break; default: fprintf(stderr, "Usage: free_caches [ -c clean_mode ] [ -w clean_time ] [ -t threshold ]\n"); break; } } } if(!set_value) set_value = FREE_MEM_PAGE; free_caches(set_value, clean_time, threshold); return 0; } printf("Unknown applet: %s\n", base); return 0; }
void setup_conntrack(void) { unsigned int v[10]; char p[128] = {0}; char buf[70]; int i; char *pch; // p = nvram_safe_get("ct_tcp_timeout"); tcapi_get("SysInfo_Entry", "ct_tcp_timeout", p); if (sscanf(p, "%u%u%u%u%u%u%u%u%u%u", &v[0], &v[1], &v[2], &v[3], &v[4], &v[5], &v[6], &v[7], &v[8], &v[9]) == 10) { // lightly verify write_tcp_timeout("established", v[1]); write_tcp_timeout("syn_sent", v[2]); write_tcp_timeout("syn_recv", v[3]); write_tcp_timeout("fin_wait", v[4]); write_tcp_timeout("time_wait", v[5]); write_tcp_timeout("close", v[6]); write_tcp_timeout("close_wait", v[7]); write_tcp_timeout("last_ack", v[8]); } else { v[1] = read_tcp_timeout("established"); v[2] = read_tcp_timeout("syn_sent"); v[3] = read_tcp_timeout("syn_recv"); v[4] = read_tcp_timeout("fin_wait"); v[5] = read_tcp_timeout("time_wait"); v[6] = read_tcp_timeout("close"); v[7] = read_tcp_timeout("close_wait"); v[8] = read_tcp_timeout("last_ack"); sprintf(buf, "0 %u %u %u %u %u %u %u %u 0", v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8]); // nvram_set("ct_tcp_timeout", buf); tcapi_set("SysInfo_Entry", "ct_tcp_timeout", buf); } setup_udp_timeout(FALSE); // p = nvram_safe_get("ct_timeout"); tcapi_get("SysInfo_Entry", "ct_timeout", p); if (sscanf(p, "%u%u", &v[0], &v[1]) == 2) { // write_ct_timeout("generic", NULL, v[0]); write_ct_timeout("icmp", NULL, v[1]); } else { v[0] = read_ct_timeout("generic", NULL); v[1] = read_ct_timeout("icmp", NULL); sprintf(buf, "%u %u", v[0], v[1]); // nvram_set("ct_timeout", buf); tcapi_set("SysInfo_Entry", "ct_timeout", buf); } #ifdef LINUX26 // p = nvram_safe_get("ct_hashsize"); tcapi_get("SysInfo_Entry", "ct_hashsize", p); i = atoi(p); if (i >= 127) { f_write_string("/sys/module/nf_conntrack/parameters/hashsize", p, 0, 0); } else if (f_read_string("/sys/module/nf_conntrack/parameters/hashsize", buf, sizeof(buf)) > 0) { if (atoi(buf) > 0) {//nvram_set("ct_hashsize", buf); pch = strchr(buf, '\n'); if(pch != NULL) memset(pch, 0, 1); tcapi_set("SysInfo_Entry", "ct_hashsize", buf); } } #endif // p = nvram_safe_get("ct_max"); tcapi_get("SysInfo_Entry", "ct_max", p); i = atoi(p); if (i >= 128) { f_write_string("/proc/sys/net/ipv4/netfilter/ip_conntrack_max", p, 0, 0); } else if (f_read_string("/proc/sys/net/ipv4/netfilter/ip_conntrack_max", buf, sizeof(buf)) > 0) { if (atoi(buf) > 0) {//nvram_set("ct_max", buf); pch = strchr(buf, '\n'); if(pch != NULL) memset(pch, 0, 1); tcapi_set("SysInfo_Entry", "ct_max", buf); } } //if (!nvram_match("nf_rtsp", "0")) { // ct_modprobe("rtsp"); //} //else { // ct_modprobe_r("rtsp"); //} // if (!nvram_match("nf_h323", "0")) { // ct_modprobe("h323"); // } // else { // ct_modprobe_r("h323"); // } // #ifdef LINUX26 // if (!nvram_match("nf_sip", "0")) { // ct_modprobe("sip"); // } // else { // ct_modprobe_r("sip"); // } // #endif // !!TB - FTP Server // #ifdef RTCONFIG_FTP // i = nvram_get_int("ftp_port"); // if (nvram_match("ftp_enable", "1") && (i > 0) && (i != 21)) // { // char ports[32]; // sprintf(ports, "ports=21,%d", i); // ct_modprobe("ftp", ports); // } // else // #endif // if (!nvram_match("nf_ftp", "0") // #ifdef RTCONFIG_FTP // || nvram_match("ftp_enable", "1") // !!TB - FTP Server // #endif // ) { // ct_modprobe("ftp"); // } // else { // ct_modprobe_r("ftp"); // } // if (!nvram_match("nf_pptp", "0")) { // ct_modprobe("proto_gre"); // ct_modprobe("pptp"); // } // else { // ct_modprobe_r("pptp"); // ct_modprobe_r("proto_gre"); // } }
int check_wanup(void) { int up = 0; int proto; char buf1[64]; char buf2[64]; const char *name; int f; struct ifreq ifr; proto = get_wan_proto(); if (proto == WP_DISABLED) { if (nvram_match("boardrev", "0x11")) { // Ovislink 1600GL - led "connected" off led(LED_WHITE,LED_OFF); } if (nvram_match("boardtype", "0x052b") && nvram_match("boardrev", "0x1204")) { //rt-n15u wan led off led(LED_WHITE,LED_OFF); } return 0; } if ((proto == WP_PPTP) || (proto == WP_L2TP) || (proto == WP_PPPOE) || (proto == WP_PPP3G)) { if (f_read_string("/tmp/ppp/link", buf1, sizeof(buf1)) > 0) { // contains the base name of a file in /var/run/ containing pid of a daemon snprintf(buf2, sizeof(buf2), "/var/run/%s.pid", buf1); if (f_read_string(buf2, buf1, sizeof(buf1)) > 0) { name = psname(atoi(buf1), buf2, sizeof(buf2)); if (strcmp(name, "pppd") == 0) up = 1; } else { _dprintf("%s: error reading %s\n", __FUNCTION__, buf2); } if (!up) { unlink("/tmp/ppp/link"); _x_dprintf("required daemon not found, assuming link is dead\n"); } } else { _x_dprintf("%s: error reading %s\n", __FUNCTION__, "/tmp/ppp/link"); } } else if (!nvram_match("wan_ipaddr", "0.0.0.0")) { up = 1; } else { _x_dprintf("%s: default !up\n", __FUNCTION__); } if ((up) && ((f = socket(AF_INET, SOCK_DGRAM, 0)) >= 0)) { strlcpy(ifr.ifr_name, nvram_safe_get("wan_iface"), sizeof(ifr.ifr_name)); if (ioctl(f, SIOCGIFFLAGS, &ifr) < 0) { up = 0; _x_dprintf("%s: SIOCGIFFLAGS\n", __FUNCTION__); } close(f); if ((ifr.ifr_flags & IFF_UP) == 0) { up = 0; _x_dprintf("%s: !IFF_UP\n", __FUNCTION__); } } if (nvram_match("boardrev", "0x11")) { // Ovislink 1600GL - led "connected" on led(LED_WHITE,up); } if (nvram_match("boardtype", "0x052b") && nvram_match("boardrev", "0x1204")) { //rt-n15u wan led on led(LED_WHITE,up); } return up; }
int do_led(int which, int mode) { // WLAN DIAG WHITE AMBER DMZ AOSS BRIDG MYST/USB 5G // ----- ----- ----- ----- ----- ----- ----- ----- -- static int wrt54g[] = { 255, 1, 2, 3, 7, 255, 255, 255, 255}; static int wrtsl[] = { 255, 1, 5, 7, 0, 255, 255, 255, 255}; static int whrg54[] = { 2, 7, 255, 255, 255, 6, 1, 3 , 255}; static int wbr2g54[] = { 255, -1, 255, 255, 255, -6, 255, 255, 255}; static int wzrg54[] = { 2, 7, 255, 255, 255, 6, 255, 255, 255}; static int wr850g1[] = { 7, 3, 255, 255, 255, 255, 255, 255, 255}; static int wr850g2[] = { 0, 1, 255, 255, 255, 255, 255, 255, 255}; static int wtr54gs[] = { 1, -1, 255, 255, 255, 255, 255, 255, 255}; static int dir320[] = { -99, 1, 4, 3, 255, 255, 255, -5, 255}; static int h618b[] = { 255, -1, 255, 255, 255, -5, -3, -4, 255}; static int wl1600gl[] = { 1, -5, 0, 255, 255, 2, 255, 255, 255}; static int wrt310nv1[] = { 255, 1, 9, 3, 255, 255, 255, 255, 255}; static int wrt160nv1[] = { 255, 1, 5, 3, 255, 255, 255, 255, 255}; #ifdef CONFIG_BCMWL5 static int wnr3500[] = { 255, 255, 2, 255, 255, -1, 255, 255, 255}; static int wnr2000v2[] = { 255, 255, 255, 255, 255, -7, 255, 255, 255}; static int f7d[] = { 255, 255, 255, 255, 12, 13, 255, 14, 255}; static int wrt160nv3[] = { 255, 1, 4, 2, 255, 255, 255, 255, 255}; static int e900[] = { 255, -6, 8, 255, 255, 255, 255, 255, 255}; static int e1000v2[] = { 255, -6, 8, 7, 255, 255, 255, 255, 255}; static int e3200[] = { 255, -3, 255, 255, 255, 255, 255, 255, 255}; static int wrt320n[] = { 255, 2, 3, 4, 255, 255, 255, 255, 255}; static int wrt610nv2[] = { 255, 5, 3, 0, 255, 255, 255, -7, 255}; static int e4200[] = { 255, 5, -3, 255, 255, 255, 255, 255, 255}; static int rtn10u[] = { 255, 255, 255, 255, 255, -7, 255, -8, 255}; static int rtn10p[] = { 255, -6, 255, 255, 255, -7, 255, 255, 255}; static int rtn12b1[] = { -5, 255, 255, 255, 255, 255, 255, 225, 255}; static int rtn15u[] = { 1, 255, 3, 255, 255, 255, 255, -9, 255}; static int rtn53[] = { 0, -17, 255, 255, 255, 255, 255, 255, 255}; static int rtn66u[] = { 255, -12, 255, 255, 255, 255, 255, 15, 13}; static int w1800r[] = { 255, -13, 255, 255, 255, 255, 255, -12, -5}; static int l600n[] = { 255, 255, 255, 255, 255, -7, 255, -8, -5}; static int dir620c1[] = { -6, -8, 255, 255, 255, -7, 255, 255, -5}; static int wndr3700v3[] = { 255, 255, 2, 255, 255, -1, 255, 255, 255}; static int d1800h[] = { -12, -13, 8, 255, 255, -10, 255, 15, 255, 11}; static int tdn6[] = { 255, -6, 8, 255, 255, 255, 255, 255, 255, 255}; #endif char s[16]; int n; int b = 255, c = 255; int ret = 255; if ((which < 0) || (which >= LED_COUNT)) return ret; switch (nvram_match("led_override", "1") ? MODEL_UNKNOWN : get_model()) { case MODEL_WRT54G: if (check_hw_type() == HW_BCM4702) { // G v1.x if ((which != LED_DIAG) && (which != LED_DMZ)) return ret; b = (which == LED_DMZ) ? 1 : 4; if (mode != LED_PROBE) { if (f_read_string("/proc/sys/diag", s, sizeof(s)) > 0) { n = atoi(s); sprintf(s, "%u", mode ? (n | b) : (n & ~b)); f_write_string("/proc/sys/diag", s, 0, 0); } } return b; } switch (which) { case LED_AMBER: case LED_WHITE: if (!supports(SUP_WHAM_LED)) return ret; break; } b = wrt54g[which]; break; case MODEL_WTR54GS: b = wtr54gs[which]; break; case MODEL_WRTSL54GS: b = wrtsl[which]; break; case MODEL_WHRG54S: case MODEL_WHRHPG54: case MODEL_WHRG125: b = whrg54[which]; break; case MODEL_WZRG54: case MODEL_WZRHPG54: case MODEL_WZRRSG54: case MODEL_WZRRSG54HP: case MODEL_WVRG54NF: case MODEL_WHR2A54G54: case MODEL_WHR3AG54: case MODEL_WZRG108: b = wzrg54[which]; break; /* case MODEL_WHR2A54G54: if (which != LED_DIAG) return ret; b = 7; break; */ case MODEL_WBRG54: if (which != LED_DIAG) return ret; b = 7; break; case MODEL_WBR2G54: b = wbr2g54[which]; break; case MODEL_WR850GV1: b = wr850g1[which]; break; case MODEL_WR850GV2: case MODEL_WR100: b = wr850g2[which]; break; case MODEL_WL500GP: if (which != LED_DIAG) return ret; b = -1; // power light break; case MODEL_WL500W: if (which != LED_DIAG) return ret; b = -5; // power light break; case MODEL_DIR320: b = dir320[which]; break; case MODEL_H618B: b = h618b[which]; break; case MODEL_WL1600GL: b = wl1600gl[which]; break; case MODEL_WL500GPv2: case MODEL_WL500GD: case MODEL_WL520GU: case MODEL_WL330GE: if (which != LED_DIAG) return ret; b = -99; // Invert power light as diag indicator break; #ifdef CONFIG_BCMWL5 case MODEL_RTN12: if (which != LED_DIAG) return ret; b = -2; // power light break; case MODEL_RTN10: case MODEL_RTN16: if (which != LED_DIAG) return ret; b = -1; // power light break; case MODEL_RTN15U: b = rtn15u[which]; break; case MODEL_RTN53: case MODEL_RTN53A1: b = rtn53[which]; break; case MODEL_RTN66U: b = rtn66u[which]; break; case MODEL_W1800R: b = w1800r[which]; break; case MODEL_D1800H: if (which == LED_DIAG) { // power led gpio: 0x02 - white, 0x13 - red b = (mode) ? 13 : 2; c = (mode) ? 2 : 13; } else b = d1800h[which]; break; case MODEL_WNDR3700v3: b = wndr3700v3[which]; break; case MODEL_WNR3500L: case MODEL_WNR3500LV2: if (which == LED_DIAG) { // power led gpio: 0x03 - green, 0x07 - amber b = (mode) ? 7 : 3; c = (mode) ? 3 : 7; } else b = wnr3500[which]; break; case MODEL_WNR2000v2: if (which == LED_DIAG) { // power led gpio: 0x01 - green, 0x02 - amber b = (mode) ? 2 : 1; c = (mode) ? 1 : 2; } else b = wnr2000v2[which]; break; case MODEL_F7D3301: case MODEL_F7D3302: case MODEL_F7D4301: case MODEL_F7D4302: case MODEL_F5D8235v3: if (which == LED_DIAG) { // power led gpio: 10 - green, 11 - red b = (mode) ? 11 : -10; c = (mode) ? -10 : 11; } else b = f7d[which]; break; case MODEL_E1000v2: b = e1000v2[which]; break; case MODEL_E900: case MODEL_E1500: case MODEL_E1550: case MODEL_E2500: b = e900[which]; break; case MODEL_E3200: b = e3200[which]; break; case MODEL_WRT160Nv3: b = wrt160nv3[which]; break; case MODEL_WRT320N: b = wrt320n[which]; break; case MODEL_WRT610Nv2: b = wrt610nv2[which]; break; case MODEL_E4200: b = e4200[which]; break; case MODEL_RTN10U: b = rtn10u[which]; break; case MODEL_RTN10P: b = rtn10p[which]; break; case MODEL_RTN12B1: b = rtn12b1[which]; break; case MODEL_L600N: b = l600n[which]; break; case MODEL_DIR620C1: b = dir620c1[which]; case MODEL_TDN60: //bwq518 case MODEL_TDN6: b = tdn6[which]; break; #endif /* case MODEL_RT390W: break; */ case MODEL_MN700: if (which != LED_DIAG) return ret; b = 6; break; case MODEL_WLA2G54L: if (which != LED_DIAG) return ret; b = 1; break; case MODEL_WRT300N: if (which != LED_DIAG) return ret; b = 1; break; case MODEL_WRT310Nv1: b = wrt310nv1[which]; break; case MODEL_WRT160Nv1: b = wrt160nv1[which]; break; default: sprintf(s, "led_%s", led_names[which]); if (nvget_gpio(s, &b, &n)) { if ((mode != LED_PROBE) && (n)) mode = !mode; ret = (n) ? b : ((b) ? -b : -99); goto SET; } return ret; } ret = b; if (b < 0) { if (b == -99) b = 0; // -0 substitute else b = -b; } else if (mode != LED_PROBE) { mode = !mode; } SET: if (b < 16) { if (mode != LED_PROBE) { gpio_write(1 << b, mode); if (c < 0) { if (c == -99) c = 0; else c = -c; } else mode = !mode; if (c < 16) gpio_write(1 << c, mode); } } return ret; }