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 start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; cprintf("sysinit() proc\n"); /* * /proc */ mknod("/dev/mmc",S_IFBLK|0660,makedev(126,0)); mknod("/dev/mmc0",S_IFBLK|0660,makedev(126,1)); mknod("/dev/mmc1",S_IFBLK|0660,makedev(126,2)); mknod("/dev/mmc2",S_IFBLK|0660,makedev(126,3)); mknod("/dev/mmc3",S_IFBLK|0660,makedev(126,4)); mkdir("/dev/mtd",0700); mknod("/dev/mtd/0",S_IFCHR|0644,makedev(90,0)); mknod("/dev/mtd/0ro",S_IFCHR|0644,makedev(90,1)); mknod("/dev/mtd/1",S_IFCHR|0644,makedev(90,2)); mknod("/dev/mtd/1ro",S_IFCHR|0644,makedev(90,3)); mknod("/dev/mtd/2",S_IFCHR|0644,makedev(90,4)); mknod("/dev/mtd/2ro",S_IFCHR|0644,makedev(90,5)); mknod("/dev/mtd/3",S_IFCHR|0644,makedev(90,6)); mknod("/dev/mtd/3ro",S_IFCHR|0644,makedev(90,7)); mknod("/dev/mtd/4",S_IFCHR|0644,makedev(90,8)); mknod("/dev/mtd/4ro",S_IFCHR|0644,makedev(90,9)); cprintf("sysinit() setup console\n"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * load some netfilter stuff */ #ifndef HAVE_WP54G #ifndef HAVE_NP28G insmod("nf_conntrack_ftp"); insmod("nf_conntrack_irc"); insmod("nf_conntrack_netbios_ns"); insmod("nf_conntrack_pptp"); insmod("nf_conntrack_proto_gre"); insmod("nf_conntrack_proto_udplite"); insmod("nf_conntrack_tftp"); insmod("xt_CLASSIFY"); insmod("xt_MARK"); insmod("xt_TCPMSS"); insmod("xt_length"); insmod("xt_limit"); insmod("xt_multiport"); insmod("xt_pkttype"); insmod("xt_state"); insmod("xt_tcpmss"); insmod("xt_u32"); insmod("iptable_filter"); insmod("iptable_mangle"); insmod("nf_nat"); insmod("iptable_nat"); insmod("nf_nat_ftp"); insmod("nf_nat_irc"); insmod("nf_nat_pptp"); insmod("nf_nat_proto_gre"); insmod("nf_nat_tftp"); insmod("ipt_LOG"); insmod("ipt_MASQUERADE"); insmod("ipt_REDIRECT"); insmod("ipt_REJECT"); insmod("ipt_ULOG"); insmod("ipt_TRIGGER"); insmod("ipt_iprange"); insmod("ipt_ipp2p"); insmod("ipt_layer7"); insmod("ipt_webstr"); // ppp drivers insmod("slhc"); insmod("ppp_generic"); insmod("ppp_async"); insmod("ppp_synctty"); insmod("ppp_mppe_mppc"); insmod("pppox"); insmod("pppoe"); #endif #endif insmod("adm5120_wdt"); insmod("adm5120sw"); if (getRouterBrand() != ROUTER_BOARD_WP54G && getRouterBrand() != ROUTER_BOARD_NP28G) { unsigned char mac[6]; char eabuf[32]; char mtdpath[32]; memset(mac, 0, 6); FILE *fp; int mtd = getMTD("boot"); int foundmac = 0; sprintf(mtdpath, "/dev/mtdblock/%d", mtd); fp = fopen(mtdpath, "rb"); if (fp != NULL) { //check for osbridge fseek(fp, 0xff90 - 2, SEEK_SET); unsigned char os[32]; fread(os, 32, 1, fp); if (strcmp(os, "OSBRiDGE 5XLi") == 0) { foundmac = 1; fprintf(stderr, "found OSBRiDGE 5XLi\n"); nvram_set("DD_BOARD", "OSBRiDGE 5LXi"); fseek(fp, 0xff82, SEEK_SET); fread(os, 12, 1, fp); int i; int count = 0; if (memcmp(os, "0050fc488130", 12) == 0) { //force change mac fclose(fp); start_change_mac(); sys_reboot(); } for (i = 0; i < 6; i++) { mac[i] = toNumeric(os[count++]) * 16; mac[i] |= toNumeric(os[count++]); } struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *)ifr.ifr_hwaddr. sa_data, mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); close(s); } } if (!foundmac) { int s = searchfor(fp, "mgmc", 0x20000 - 5); if (s != -1) { fread(mac, 6, 1, fp); struct ifreq ifr; int s; foundmac = 1; fprintf(stderr, "found Tonze-AP120\n"); if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *) ifr.ifr_hwaddr.sa_data, mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *) ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", ether_etoa((unsigned char *) ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } } } if (foundmac == 0) { fprintf(stderr, "error: no valid mac address found for eth0\n"); } fclose(fp); } } else { struct mylo_board_params params; char mtdpath[32]; FILE *fp; int mtd = getMTD("boot"); int foundmac = 0; struct ifreq ifr; int s; char eabuf[32]; sprintf(mtdpath, "/dev/mtdblock/%d", mtd); fp = fopen(mtdpath, "rb"); if (fp != NULL) { fseek(fp, 0xf800, SEEK_SET); fread(¶ms, sizeof(params), 1, fp); fclose(fp); if (params.magic == 0x20021103) { fprintf(stderr, "Found compex board magic!\n"); if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *)ifr.ifr_hwaddr. sa_data, params.addr[0].mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth1", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *)ifr.ifr_hwaddr. sa_data, params.addr[1].mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); close(s); } } } } /* * network drivers */ detect_wireless_devices(); if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); #ifdef HAVE_WP54G writeproc("/proc/sys/dev/wifi0/ledpin","6"); writeproc("/proc/sys/dev/wifi0/softled","1"); #endif /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; }
int add_iQosRules(char *pcWANIF) { char *buf; char *g; char *p; char *addr_type, *addr; char *proto; char *port_type, *port; char *class_prio; char *ipp2p, *layer7; char *bcount; int class_num; int proto_num; int i; char s[256]; int inuse; int qosox_enable; unsigned long min; int bcount_enable; int method; int gum; int sticky_enable; char acClass[8]; char acByteCounter[32]; EVAL_CMD stIptCommand = { 3, { "iptables", "-t", "mangle", NULL, } }; if (pcWANIF == NULL || !nvram_match("qos_enable", "1")) return -1; printf("\n%s: %s", __FUNCTION__, pcWANIF); qosox_enable = bcount_enable = inuse = sticky_enable = 0; method = atoi(nvram_safe_get("qos_method")); // strict rule ordering gum = (method == 0) ? 0x100 : 0; if (nvram_match("qos_sticky", "0")) sticky_enable = 1; eval("iptables", "-t", "mangle", "-N", "QOSO"); eval("iptables", "-t", "mangle", "-A", "QOSO", "-j", "CONNMARK", "--restore-mark", "--mask", "0xff"); eval("iptables", "-t", "mangle", "-A", "QOSO", "-m", "connmark", "!", "--mark", "0/0xff00", "-j", "RETURN"); g = buf = strdup(nvram_safe_get("qos_orules")); while (g) { /* addr_type<addr<proto<port_type<port<<<<desc addr_type: 0 = any 1 = dest ip 2 = src ip 3 = src mac addr: ip/mac if addr_type == 1-3 proto: 0-65535 = protocol -1 = tcp or udp -2 = any protocol port_type: if proto == -1,tcp,udp: d = dest s = src x = both a = any port: port # if proto == -1,tcp,udp class_prio: 0-4, 0 being highest */ if ((p = strsep(&g, ">")) == NULL) break; i = vstrsep(p, "<", &addr_type, &addr, &proto, &port_type, &port, &ipp2p, &layer7, &bcount, &class_prio, &p); if (i == 9) { class_prio = bcount; bcount = NULL; } else if (i != 10) continue; class_num = atoi(class_prio); if ((class_num < 0) || (class_num > 4)) continue; i = 1 << class_num++; if (method == 1) class_num |= 0x200; if ((inuse & i) == 0) { inuse |= i; printf("inuse=%d\n", inuse); } /* Beginning of the Rule */ { stIptCommand.siCount = 3; stIptCommand.apCommand[stIptCommand.siCount++] = "-A"; if (qosox_enable) stIptCommand.apCommand[stIptCommand.siCount++] = "QOSOX"; //Offset 4 else stIptCommand.apCommand[stIptCommand.siCount++] = "QOSO"; } /* * protocol & ports: */ { proto_num = atoi(proto); if (proto_num > -2) { stIptCommand.apCommand[stIptCommand.siCount++] = "-p"; if (proto_num == 17) stIptCommand.apCommand[stIptCommand.siCount++] = "udp"; //Offset 6 else if (proto_num != -1) stIptCommand.apCommand[stIptCommand.siCount++] = proto; else stIptCommand.apCommand[stIptCommand.siCount++] = "tcp"; //Offset 6 if ((proto_num == 6) || (proto_num == 17) || (proto_num == -1)) { if (*port_type != 'a') { if ((*port_type == 'x') || (strchr(port, ','))) { // dst-or-src port matches, and anything with multiple lists "," use mport stIptCommand.apCommand[stIptCommand.siCount++] = "-m"; stIptCommand.apCommand[stIptCommand.siCount++] = "mport"; if (*port_type == 's') stIptCommand.apCommand[stIptCommand.siCount++] = "--sports"; else stIptCommand.apCommand[stIptCommand.siCount++] = "--dports"; } else { if (*port_type == 's') stIptCommand.apCommand[stIptCommand.siCount++] = "--sport"; else if (*port_type == 'd') stIptCommand.apCommand[stIptCommand.siCount++] = "--dport"; else stIptCommand.apCommand[stIptCommand.siCount++] = "--port"; } if (port && *port) stIptCommand.apCommand[stIptCommand.siCount++] = port; } } } } /* * MAC or IP address match: */ { if ((*addr_type == '1') || (*addr_type == '2')) { // match ip if (strchr(addr, '-') != NULL) { stIptCommand.apCommand[stIptCommand.siCount++] = "-m"; stIptCommand.apCommand[stIptCommand.siCount++] = "iprange"; if (*addr_type == '1') stIptCommand.apCommand[stIptCommand.siCount++] = "--dst-range"; else stIptCommand.apCommand[stIptCommand.siCount++] = "--src-range"; } else { if (*addr_type == '1') stIptCommand.apCommand[stIptCommand.siCount++] = "-d"; else stIptCommand.apCommand[stIptCommand.siCount++] = "-s"; } } else if (*addr_type == '3') { // match mac stIptCommand.apCommand[stIptCommand.siCount++] = "-m"; stIptCommand.apCommand[stIptCommand.siCount++] = "mac"; stIptCommand.apCommand[stIptCommand.siCount++] = "--mac-source"; } if (*addr_type != '0') stIptCommand.apCommand[stIptCommand.siCount++] = addr; } /* End of the rule */ { class_num |= gum; if (sticky_enable) class_num &= 0xFF; sprintf(acClass, "0x%x/0xFF", class_num); stIptCommand.apCommand[stIptCommand.siCount++] = "-j"; stIptCommand.apCommand[stIptCommand.siCount++] = "CONNMARK"; stIptCommand.apCommand[stIptCommand.siCount++] = "--set-mark"; stIptCommand.apCommand[stIptCommand.siCount++] = acClass; stIptCommand.apCommand[stIptCommand.siCount++] = NULL; } printcmd(&stIptCommand); _eval(stIptCommand.apCommand, NULL, 4, NULL); if (proto_num == -1) { stIptCommand.apCommand[6] = "udp"; printcmd(&stIptCommand); _eval(stIptCommand.apCommand, NULL, 4, NULL); } stIptCommand.siCount = 3; stIptCommand.apCommand[stIptCommand.siCount++] = "-A"; if(qosox_enable) stIptCommand.apCommand[stIptCommand.siCount++] = "QOSOX"; else stIptCommand.apCommand[stIptCommand.siCount++] = "QOSO"; stIptCommand.apCommand[stIptCommand.siCount++] = "-j"; stIptCommand.apCommand[stIptCommand.siCount++] = "RETURN"; stIptCommand.apCommand[stIptCommand.siCount++] = NULL; printcmd(&stIptCommand); _eval(stIptCommand.apCommand, NULL, 4, NULL); } free(buf); /* * The default class: */ { char acClass[4]; i = atoi(nvram_safe_get("qos_default")); if ((i < 0) || (i > 9)) i = 3; // "low" class_num = i + 1; if (method == 1) class_num |= 0x200; sprintf(acClass, "0x%x", class_num); eval("iptables", "-t", "mangle", "-A", qosox_enable ? "QOSOX" : "QOSO", "-j", "CONNMARK", "--set-mark", acClass); eval("iptables", "-t", "mangle", "-A", qosox_enable ? "QOSOX" : "QOSO", "-j", "RETURN"); } eval("iptables", "-t", "mangle", "-A", "FORWARD", "-o", pcWANIF, "-j", qosox_enable ? "QOSOX" : "QOSO"); /* * Ingress rules: */ { i = atoi(nvram_safe_get("qos_default")); inuse |= (1 << i) | 1; // default and highest are always built sprintf(s, "%d", inuse); nvram_set("qos_inuse", s); // create the inuse NVRAM here g = buf = strdup(nvram_safe_get("qos_irates")); for (i = 0; i < 5; i++) { if ((!g) || ((p = strsep(&g, ",")) == NULL)) continue; if ((inuse & (1 << i)) == 0) continue; if (atoi(p) > 0) {// if ibound rules are set, use the PRE-ROUTE eval("iptables", "-t", "mangle", "-A", "PREROUTING", "-i", pcWANIF, "-j", "CONNMARK", "--restore-mark", "--mask", "0xff"); break; } } free(buf); } }
/* Check for time-dependent service */ static int svc_timecheck(void) { int activeNow; #if BOARD_HAS_5G_RADIO if (get_enabled_radio_wl()) { /* Initialize */ if (nvram_match("reload_svc_wl", "1")) { nvram_set_int_temp("reload_svc_wl", 0); svcStatus[RADIO5_ACTIVE] = -1; svcStatus[GUEST5_ACTIVE] = -1; } activeNow = is_radio_allowed_wl(); if (activeNow != svcStatus[RADIO5_ACTIVE]) { svcStatus[RADIO5_ACTIVE] = activeNow; if (activeNow) notify_rc("control_wifi_radio_wl_on"); else notify_rc("control_wifi_radio_wl_off"); } if (svcStatus[RADIO5_ACTIVE] > 0) { activeNow = is_guest_allowed_wl(); if (activeNow != svcStatus[GUEST5_ACTIVE]) { svcStatus[GUEST5_ACTIVE] = activeNow; if (activeNow) notify_rc("control_wifi_guest_wl_on"); else notify_rc("control_wifi_guest_wl_off"); } } else { if (svcStatus[GUEST5_ACTIVE] >= 0) svcStatus[GUEST5_ACTIVE] = -1; } } #endif if (get_enabled_radio_rt()) { /* Initialize */ if (nvram_match("reload_svc_rt", "1")) { nvram_set_int_temp("reload_svc_rt", 0); svcStatus[RADIO2_ACTIVE] = -1; svcStatus[GUEST2_ACTIVE] = -1; } activeNow = is_radio_allowed_rt(); if (activeNow != svcStatus[RADIO2_ACTIVE]) { svcStatus[RADIO2_ACTIVE] = activeNow; if (activeNow) notify_rc("control_wifi_radio_rt_on"); else notify_rc("control_wifi_radio_rt_off"); } if (svcStatus[RADIO2_ACTIVE] > 0) { activeNow = is_guest_allowed_rt(); if (activeNow != svcStatus[GUEST2_ACTIVE]) { svcStatus[GUEST2_ACTIVE] = activeNow; if (activeNow) notify_rc("control_wifi_guest_rt_on"); else notify_rc("control_wifi_guest_rt_off"); } } else { if (svcStatus[GUEST2_ACTIVE] >= 0) svcStatus[GUEST2_ACTIVE] = -1; } } return 0; }
void start_chilli(void) { int ret = 0; char ssid[128]; if ((nvram_match("usb_enable", "1") && nvram_match("usb_storage", "1") && nvram_match("usb_automnt", "1") && nvram_match("usb_mntpoint", "jffs")) || (nvram_match("enable_jffs2", "1") && nvram_match("jffs_mounted", "1") && nvram_match("sys_enable_jffs2", "1"))) jffs = 1; stop_chilli(); //ensure that its stopped if (!strlen(nvram_safe_get("chilli_interface"))) nvram_set("chilli_interface", get_wdev()); if (!strlen(nvram_safe_get("hotss_interface"))) nvram_set("hotss_interface", get_wdev()); main_config(); #ifdef HAVE_HOTSPOT if (nvram_match("chilli_enable", "1") && nvram_match("chilli_def_enable", "0") && !nvram_match("hotss_enable", "1")) { nvram_unset("chilli_def_enable"); nvram_set("chilli_enable", "0"); return; } if (!nvram_match("chilli_enable", "1") && !nvram_match("hotss_enable", "1")) { nvram_unset("chilli_def_enable"); return; } if (nvram_match("hotss_enable", "1")) { stop_cron(); if (!nvram_match("chilli_enable", "1")) { nvram_set("chilli_enable", "1"); // to get care of firewall, network, etc. nvram_set("chilli_def_enable", "0"); } if (!nvram_match("hotss_preconfig", "1")) { nvram_set("hotss_preconfig", "1"); sprintf(ssid, "HotSpotSystem.com-%s_%s", nvram_get("hotss_operatorid"), nvram_get("hotss_locationid")); nvram_set("wl0_ssid", ssid); nvram_set("time_zone", "+00"); nvram_set("daylight_time", "1"); } hotspotsys_config(); start_cron(); } else if (nvram_match("chilli_enable", "1")) { nvram_unset("chilli_def_enable"); chilli_config(); } #else if (!nvram_match("chilli_enable", "1")) return; chilli_config(); #endif ret = killall("chilli", SIGTERM); ret = killall("chilli", SIGKILL); if (f_exists("/tmp/chilli/hotss.conf")) { #ifdef HAVE_COOVA_CHILLI putenv("CHILLISTATEDIR=/var/run/chilli1"); mkdir("/var/run/chilli1", 0700); ret = eval("chilli", "--statedir=/var/run/chilli1", "--pidfile=/var/run/chilli1/chilli.pid", "-c", "/tmp/chilli/hotss.conf"); #else ret = eval("chilli", "-c", "/tmp/chilli/hotss.conf"); #endif dd_syslog(LOG_INFO, "hotspotsystem : chilli daemon successfully started\n"); } else { #ifdef HAVE_COOVA_CHILLI putenv("CHILLISTATEDIR=/var/run/chilli1"); mkdir("/var/run/chilli1", 0700); ret = eval("chilli", "--statedir=/var/run/chilli1", "--pidfile=/var/run/chilli1/chilli.pid", "-c", "/tmp/chilli/chilli.conf"); #else ret = eval("chilli", "-c", "/tmp/chilli/chilli.conf"); #endif dd_syslog(LOG_INFO, "chilli : chilli daemon successfully started\n"); } #ifdef HAVE_TIEXTRA1 start_mchilli(); #endif cprintf("done\n"); return; }
// FILE *debugfp=NULL; int _evalpid(char *const argv[], char *path, int timeout, int *ppid) { pid_t pid; int status; int fd; int flags; int sig; // if (debugfp==NULL) // debugfp = fopen("/tmp/evallog.log","wb"); // char buf[254] = ""; #ifndef HAVE_X86 //we must disable this on x86 since nvram is not available at startup if (nvram_match("console_debug", "1")) { int i = 0; while (argv[i] != NULL) { fprintf(stderr, "%s ", argv[i++]); flog("%s ", argv[i - 1]); } fprintf(stderr, "\n"); flog("\n"); } #ifndef HAVE_SILENCE int i = 0; while (argv[i] != NULL) { fprintf(stderr, "%s ", argv[i++]); } fprintf(stderr, "\n"); #endif #endif switch (pid = fork()) { case -1: /* error */ perror("fork"); return errno; case 0: /* child */ /* * Reset signal handlers set for parent process */ for (sig = 0; sig < (_NSIG - 1); sig++) signal(sig, SIG_DFL); /* * Clean up */ ioctl(0, TIOCNOTTY, 0); close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); setsid(); /* * We want to check the board if exist UART? , add by honor * 2003-12-04 */ if ((fd = open("/dev/console", O_RDWR)) < 0) { (void)open("/dev/null", O_RDONLY); (void)open("/dev/null", O_WRONLY); (void)open("/dev/null", O_WRONLY); } else { close(fd); (void)open("/dev/console", O_RDONLY); (void)open("/dev/console", O_WRONLY); (void)open("/dev/console", O_WRONLY); } /* * Redirect stdout to <path> */ if (path) { flags = O_WRONLY | O_CREAT; if (!strncmp(path, ">>", 2)) { /* * append to <path> */ flags |= O_APPEND; path += 2; } else if (!strncmp(path, ">", 1)) { /* * overwrite <path> */ flags |= O_TRUNC; path += 1; } if ((fd = open(path, flags, 0644)) < 0) perror(path); else { dup2(fd, STDOUT_FILENO); close(fd); } } /* * execute command */ // for (i = 0; argv[i]; i++) // snprintf (buf + strlen (buf), sizeof (buf), "%s ", argv[i]); // cprintf("cmd=[%s]\n", buf); setenv("PATH", "/sbin:/bin:/usr/sbin:/usr/bin", 1); alarm(timeout); execvp(argv[0], argv); perror(argv[0]); exit(errno); default: /* parent */ if (ppid) { *ppid = pid; return 0; } else { waitpid(pid, &status, 0); if (WIFEXITED(status)) return WEXITSTATUS(status); else return status; } } }
/* the real action: - increment the forced update times counter - detect current IP - connect to an HTTP server - parse the response for IP addr - for all the names that have to be maintained - get the current DYN DNS address from DYN DNS server - compare and update if neccessary */ RC_TYPE dyn_dns_update_ip(DYN_DNS_CLIENT *p_self) { RC_TYPE rc = RC_OK; if (p_self == NULL) { return RC_INVALID_POINTER; } do { if (nvram_match("ddns_wan_ip","1")) { char new_ip_str[32]; int wan_link = check_wan_link(0); char *wan_ipaddr = NULL; if (nvram_match("wan_proto", "pptp")) { wan_ipaddr = wan_link ? nvram_safe_get("pptp_get_ip") : nvram_safe_get("wan_ipaddr"); } else if (!strcmp(nvram_safe_get("wan_proto"), "pppoe")) { wan_ipaddr = wan_link ? nvram_safe_get("wan_ipaddr") : "0.0.0.0"; } else if (!strcmp(nvram_safe_get("wan_proto"), "3g")) { wan_ipaddr = wan_link ? nvram_safe_get("wan_ipaddr") : "0.0.0.0"; } else if (nvram_match("wan_proto", "l2tp")) { wan_ipaddr = wan_link ? nvram_safe_get("l2tp_get_ip") : nvram_safe_get("wan_ipaddr"); } else if (nvram_match("wan_proto", "disabled")) { wan_ipaddr = "0.0.0.0"; } else { wan_ipaddr = nvram_safe_get("wan_ipaddr"); } if (!strcmp(wan_ipaddr,"0.0.0.0")) { DBG_PRINTF((LOG_WARNING,"W: DYNDNS: Error: device has no WAN Address\n")); rc = RC_ERROR; break; } strcpy(new_ip_str,wan_ipaddr); p_self->info.my_ip_has_changed = (strcmp(new_ip_str, p_self->info.my_ip_address.name) != 0); strcpy(p_self->info.my_ip_address.name, new_ip_str); rc = RC_OK; }else{ /*ask IP server something so he will respond and give me my IP */ rc = do_ip_server_transaction(p_self); if (rc != RC_OK) { DBG_PRINTF((LOG_WARNING,"W: DYNDNS: Error '%s' (0x%x) when talking to IP server\n", errorcode_get_name(rc), rc)); break; } if (p_self->dbg.level > 1) { DBG_PRINTF((LOG_DEBUG,"DYNDNS: IP server response: %s\n", p_self->p_work_buffer)); } /*extract my IP, check if different than previous one*/ rc = do_parse_my_ip_address(p_self); if (rc != RC_OK) { break; } } if (p_self->dbg.level > 1) { DBG_PRINTF((LOG_WARNING,"W: DYNDNS: My IP address: %s\n", p_self->info.my_ip_address.name)); } /*step through aliases list, resolve them and check if they point to my IP*/ rc = do_check_alias_update_table(p_self); if (rc != RC_OK) { break; } /*update IPs marked as not identical with my IP*/ rc = do_update_alias_table(p_self); if (rc != RC_OK) { break; } } while(0); return rc; }
int svc_timecheck(void) { int activeNow; /* if (valid_url_filter_time()) { if (nvram_match("url_enable_x", "1")) { activeNow = timecheck_item(nvram_safe_get("url_date_x"), nvram_safe_get("url_time_x")); if (activeNow != svcStatus[URLACTIVE]) { dbg("[watchdog] url filter 0: %s\n", activeNow ? "Enabled": "Disabled"); svcStatus[URLACTIVE] = activeNow; stop_dns(); start_dns(); } } if (nvram_match("url_enable_x_1", "1")) { activeNow = timecheck_item(nvram_safe_get("url_date_x"), nvram_safe_get("url_time_x_1")); if (activeNow != svcStatus[URLACTIVE1]) { dbg("[watchdog] url filter 1: %s\n", activeNow ? "Enabled": "Disabled"); svcStatus[URLACTIVE1] = activeNow; stop_dns(); start_dns(); } } } */ if (!nvram_match("wl_radio_x", "0")) { /* Initialize */ if (svcStatus[RADIOACTIVE] == -1 || nvram_match("reload_svc_wl", "1")) { if (nvram_match("reload_svc_wl", "1")) { // dbg("5G radio svc changed!\n"); nvram_set("reload_svc_wl", "0"); } check_radio_time("wl_radio_time_x"); strcpy(svcDate[RADIOACTIVE], nvram_safe_get("wl_radio_date_x")); strcpy(svcTime[RADIOACTIVE], nvram_safe_get("wl_radio_time_x")); svcStatus[RADIOACTIVE] = -2; if (!timecheck_item(svcDate[RADIOACTIVE], svcTime[RADIOACTIVE])) radio_main(0); } else { activeNow = timecheck_item(svcDate[RADIOACTIVE], svcTime[RADIOACTIVE]); if (activeNow != svcStatus[RADIOACTIVE]) { // dbg("5G radio activity status changed!\n"); svcStatus[RADIOACTIVE] = activeNow; if (activeNow) radio_main(1); else radio_main(0); } // else dbg("5G radio activity status: %d\n", activeNow); } } if (!nvram_match("rt_radio_x", "0")) { /* Initialize */ if (svcStatus[RADIO2ACTIVE] == -1 || nvram_match("reload_svc_rt", "1")) { if (nvram_match("reload_svc_rt", "1")) { // dbg("2.4G radio svc changed!\n"); nvram_set("reload_svc_rt", "0"); } check_radio_time("rt_radio_time_x"); strcpy(svcDate[RADIO2ACTIVE], nvram_safe_get("rt_radio_date_x")); strcpy(svcTime[RADIO2ACTIVE], nvram_safe_get("rt_radio_time_x")); svcStatus[RADIO2ACTIVE] = -2; if (!timecheck_item(svcDate[RADIO2ACTIVE], svcTime[RADIO2ACTIVE])) radio_main_rt(0); } else { activeNow = timecheck_item(svcDate[RADIO2ACTIVE], svcTime[RADIO2ACTIVE]); if (activeNow != svcStatus[RADIO2ACTIVE]) { // dbg("2.4G radio activity status changed!\n"); svcStatus[RADIO2ACTIVE] = activeNow; if (activeNow) radio_main_rt(1); else radio_main_rt(0); } // else dbg("2.4G radio activity status: %d\n", activeNow); } } return 0; }
static int radio_on(int idx, int unit, int subunit, void *param) { return nvram_match(wl_nvname("radio", unit, 0), "1"); }
int no_need_to_start_wps(int wps_mode) { if (wps_mode) // PIN { if (nvram_match("wps_band", "0")) { if ( nvram_match("wl_auth_mode", "shared") || nvram_match("wl_auth_mode", "wpa") || nvram_match("wl_auth_mode", "wpa2") || nvram_match("wl_auth_mode", "radius") || nvram_match("wl_radio_x", "0") || nvram_match("sw_mode_ex", "3") ) return 1; } else { if ( nvram_match("rt_auth_mode", "shared") || nvram_match("rt_auth_mode", "wpa") || nvram_match("rt_auth_mode", "wpa2") || nvram_match("rt_auth_mode", "radius") || nvram_match("rt_radio_x", "0") || nvram_match("sw_mode_ex", "3") ) return 1; } } else { #if 0 if ( nvram_match("wl_auth_mode", "shared") || nvram_match("wl_auth_mode", "wpa") || nvram_match("wl_auth_mode", "wpa2") || nvram_match("wl_auth_mode", "radius") || nvram_match("wl_radio_x", "0") || nvram_match("rt_auth_mode", "shared") || nvram_match("rt_auth_mode", "wpa") || nvram_match("rt_auth_mode", "wpa2") || nvram_match("rt_auth_mode", "radius") || nvram_match("rt_radio_x", "0") || nvram_match("sw_mode_ex", "3") ) return 1; #else if ( nvram_match("rt_auth_mode", "shared") || nvram_match("rt_auth_mode", "wpa") || nvram_match("rt_auth_mode", "wpa2") || nvram_match("rt_auth_mode", "radius") || nvram_match("rt_radio_x", "0") || nvram_match("sw_mode_ex", "3") ) return 1; #endif } return 0; }
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 }
int httpd_check_v2() { #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) time_t now = uptime(); // if (!nvram_match("wan_route_x", "IP_Routed")) // return 1; if (check_count_down) { check_count_down--; httpd_error_count = 0; return 1; } httpd_timer = (httpd_timer + 1) % 2; if (httpd_timer) return 1; if (nvram_match("v2_debug", "1")) dbg("uptime: %d\n", now); if (nvram_get("login_timestamp") && ((unsigned long)(now - strtoul(nvram_safe_get("login_timestamp"), NULL, 10)) < 60)) { if (nvram_match("v2_debug", "1")) dbg("user login within 1 minutu: %d\n", (unsigned long)(now - strtoul(nvram_safe_get("login_timestamp"), NULL, 10))); httpd_error_count = 0; return 1; } int ret = 0; FILE *fp = NULL; char line[80], cmd[128], url[80]; /* httpd will not count 127.0.0.1 */ //sprintf(url, "http://%s/httpd_check.htm", get_lan_ipaddr()); sprintf(url, "http://%s/httpd_check.htm", "127.0.0.1"); remove(DETECT_HTTPD_FILE); wget_timestamp = uptime(); memset(wget_timestampstr, 0, 32); sprintf(wget_timestampstr, "%lu", wget_timestamp); nvram_set("wget_timestamp", wget_timestampstr); /* if (nvram_get("login_timestamp") && !nvram_match("login_timestamp", "")) { httpd_error_count = 0; return 1; } else */ eval("wget", "-q", url, "-O", DETECT_HTTPD_FILE, "&"); if ((fp = fopen(DETECT_HTTPD_FILE, "r")) != NULL) { if ( fgets(line, sizeof(line), fp) != NULL ) { if (strstr(line, "ASUSTeK")) { if (nvram_match("v2_debug", "1")) dbg("httpd is alive!\n"); ret = 1; } } fclose(fp); } else { if (nvram_match("v2_debug", "1")) dbg("fopen %s error!\n", DETECT_HTTPD_FILE); if (pids("wget")) system("killall wget"); } nvram_unset("wget_timestamp"); if (!ret) { if (nvram_match("v2_debug", "1")) dbg("httpd no response!\n"); httpd_error_count++; } else httpd_error_count = 0; if (nvram_match("v2_debug", "1")) dbg("httpd_error_count: %d\n", httpd_error_count); if (httpd_error_count > 2) { dbg("httpd is so dead!!!\n"); httpd_error_count = 0; return 0; } else return 1; #else return 1; #endif }
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; }
/* wathchdog is runned in NORMAL_PERIOD, 1 seconds * check in each NORMAL_PERIOD * 1. button * * check in each NORAML_PERIOD*10 * * 1. ntptime * 2. time-dependent service * 3. http-process * 4. usb hotplug status */ void watchdog(void) { /* handle button */ btn_check(); /* if timer is set to less than 1 sec, then bypass the following */ if (itv.it_value.tv_sec == 0) return; if (nvram_match("asus_mfg", "1")) { system("rmmod hw_nat"); if (pids("ntp")) system("killall -SIGTERM ntp"); if (pids("ntpclient")) system("killall ntpclient"); if (pids("udhcpc")) system("killall -SIGTERM udhcpc"); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) if (pids("ots")) system("killall ots"); #endif stop_wanduck(); stop_logger(); stop_upnp(); // it may cause upnp cannot run stop_dhcpd(); stop_dns(); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) stop_pspfix(); #endif stop_wsc(); stop_wsc_2g(); stop_lltd(); stop_networkmap(); stop_httpd(); stop_lpd(); stop_u2ec(); kill_pidfile_s("/var/run/linkstatus_monitor.pid", SIGTERM); if (pids("detectWan")) system("killall detectWan"); #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) stop_rstats(); kill_pidfile_s("/var/run/detect_internet.pid", SIGTERM); #endif if (pids("tcpcheck")) system("killall -SIGTERM tcpcheck"); #ifdef HTTPD_CHECK if (pids("httpdcheck")) system("killall -SIGTERM httpdcheck"); #endif if (pids("traceroute")) system("killall traceroute"); if (pids("usbled")) system("killall -SIGTERM usbled"); nvram_set("asus_mfg", "2"); } #if 0 // reboot signal checking if (nvram_match("reboot", "1")) { printf("[watchdog] nvram match reboot\n"); reboot_count++; if (reboot_count >= 2) { // kill(1, SIGTERM); sys_exit(); } return; } #else if (nvram_match("reboot", "1")) return; #endif if (stop_service_type_99) return; if (!nvram_match("asus_mfg", "0")) return; watchdog_period = (watchdog_period + 1) % 10; if (watchdog_period) return; #ifdef BTN_SETUP if (btn_pressed_setup >= BTNSETUP_START) return; #endif #if (!defined(W7_LOGO) && !defined(WIFI_LOGO)) if (count_to_stop_wps > 0) { count_to_stop_wps--; if (!count_to_stop_wps) { // if (nvram_match("wl_radio_x", "1")) stop_wsc(); // psp fix // if (nvram_match("rt_radio_x", "1")) stop_wsc_2g(); // psp fix nvram_set("wps_enable", "0"); // psp fix } } #endif ddns_timer = (ddns_timer + 1) % 4320; if (nvram_match("asus_debug", "1")) mem_timer = (mem_timer + 1) % 60; if (!watchdog_count) watchdog_count++; else if (watchdog_count++ == 1) { #if 0 if (!strcmp(nvram_safe_get("rc_service"), "restart_upnp")) service_handle(); else #endif if ( nvram_match("router_disable", "0") && nvram_match("upnp_enable", "1") && nvram_match("upnp_started", "0") ) { // if (has_wan_ip()) { dbg("[watchdog] starting upnp...\n"); stop_upnp(); start_upnp(); } } } /* check for time-dependent services */ svc_timecheck(); /* http server check */ httpd_processcheck(); u2ec_processcheck(); media_processcheck(); #if 0 samba_processcheck(); #endif pppd_processcheck(); if (nvram_match("wan_route_x", "IP_Routed")) nm_processcheck(); cpu_usage_minotor(); dm_block_chk(); if (nvram_match("asus_debug", "1") && !mem_timer) { print_num_of_connections(); dbg("Hardware NAT: %s\n", is_hwnat_loaded() ? "Enabled": "Disabled"); dbg("Software QoS: %s\n", nvram_match("qos_enable", "1") ? "Enabled": "Disabled"); dbg("pppd running: %s\n", pids("pppd") ? "Yes": "No"); #if 0 dbg("CPU usage: %d%%\n", get_cpu_usage()); #else dbg("CPU usage: %d%%\n", cpu_main(0, NULL, 0)); #endif system("free"); system("date"); print_uptime(); } #ifdef CDMA /* CDMA_DOWN = 99, none * CDMA_DOWN = 1, currently down * CDMA_DOWN = 2, currently up * CDMA_DOWN = 0, currently trying to connect */ if (nvram_match("cdma_down", "1")) { logmessage("CDMA client", "cdma is down(%d)!", cdma_down); cdma_down++; cdma_connec t = 0; if (cdma_down == 2) { printf("[watchdog] stop wan\n"); stop_wan(); start_wan(); } else if (cdma_down >= 12) /* 2 minutes timeout for retry */ { cdma_down = 0; } } else if (nvram_match("cdma_down", "0")) { logmessage("CDMA client", "cdma try connect(%d)!", cdma_connect); cdma_down = 0; cdma_connect++; if (cdma_connect > 12) /* 2 minitues timeout for connecting */ { nvram_set("cdma_down", "1"); } } else { cdma_down = 0; cdma_connect = 0; } #endif if (nvram_match("wan_route_x", "IP_Routed")) { if (!is_phyconnected() || !has_wan_ip()) return; /* sync time to ntp server if necessary */ if (!nvram_match("wan_dns_t", "") && !nvram_match("wan_gateway_t", "")) { ntp_timesync(); } if ( nvram_match("ddns_enable_x", "1") && (!nvram_match("ddns_updated", "1") || !ddns_timer) ) { logmessage("RT-N56U", "[start ddns] watchdog"); start_ddns(); } if (!ddns_timer) { stop_networkmap(); start_networkmap(); } } else { if (/*!nvram_match("lan_dns_t", "") && */!nvram_match("lan_gateway_t", "")) ntp_timesync(); } }
/* Tc */ int start_iQos(void) { int i; char *buf, *g, *p; unsigned int rate; unsigned int ceil; unsigned int bw; unsigned int mtu; FILE *f; int x; int inuse; char s[256]; int first; char burst_root[32]; char burst_leaf[32]; char *protocol; // judge interface by get_wan_ifname // add Qos iptable rules in mangle table, // move it to firewall - mangle_setting // add_iQosRules(get_wan_ifname(0)); // iptables start //wireless_tc(); /* Wireless tc */ if (!nvram_match("qos_enable", "1")) return -1; if ((f = fopen(qosfn, "w")) == NULL) return -2; fprintf(stderr, "[qos] tc START!\n"); /* qos_burst */ i = atoi(nvram_safe_get("qos_burst0")); if (i > 0) sprintf(burst_root, "burst %dk", i); else burst_root[0] = 0; i = atoi(nvram_safe_get("qos_burst1")); if (i > 0) sprintf(burst_leaf, "burst %dk", i); else burst_leaf[0] = 0; /* Egress OBW -- set the HTB shaper (Classful Qdisc) * the BW is set here for each class */ mtu = strtoul(nvram_safe_get("wan_mtu"), NULL, 10); bw = strtoul(nvram_safe_get("qos_obw"), NULL, 10); /* WAN */ fprintf(f, "#!/bin/sh\n" "#LAN/WAN\n" "I=%s\n" "SFQ=\"sfq perturb 10\"\n" "TQA=\"tc qdisc add dev $I\"\n" "TCA=\"tc class add dev $I\"\n" "TFA=\"tc filter add dev $I\"\n" "case \"$1\" in\n" "start)\n" "#LAN/WAN\n" "\ttc qdisc del dev $I root 2>/dev/null\n" "\t$TQA root handle 1: htb default %u\n" "# upload 1:1\n" "\t$TCA parent 1: classid 1:1 htb rate %ukbit ceil %ukbit %s\n", get_wan_ifname(0), // judge WAN interface (atoi(nvram_safe_get("qos_default")) + 1) * 10, bw, bw, burst_root); /* LAN protocol: 802.1q */ #ifdef RTCONFIG_RALINK if (get_model() == MODEL_RTN56U) protocol = strdup("ip"); else #endif protocol = strdup("802.1q"); fprintf(f, "# download 1:2\n" "\t$TCA parent 1: classid 1:2 htb rate 1000000kbit ceil 1000000kbit burst 10000 cburst 10000\n" "# 1:60 ALL Download\n" "\t$TCA parent 1:2 classid 1:60 htb rate 1000000kbit ceil 1000000kbit burst 10000 cburst 10000 prio 6\n" "\t$TQA parent 1:60 handle 60: pfifo\n" "\t$TFA parent 1: prio 60 protocol %s handle 6 fw flowid 1:60\n", protocol ); inuse = atoi(nvram_safe_get("qos_inuse")); g = buf = strdup(nvram_safe_get("qos_orates")); for (i = 0; i < 5; ++i) { // 0~4 , 0:highest, 4:lowest if ((!g) || ((p = strsep(&g, ",")) == NULL)) break; if ((inuse & (1 << i)) == 0){ fprintf(stderr, "[qos] egress %d doesn't create, inuse=%d\n", i, inuse ); continue; } else fprintf(stderr, "[qos] egress %d creates\n", i); if ((sscanf(p, "%u-%u", &rate, &ceil) != 2) || (rate < 1)) continue; if (ceil > 0) sprintf(s, "ceil %ukbit ", calc(bw, ceil)); else s[0] = 0; x = (i + 1) * 10; fprintf(f, "# egress %d: %u-%u%%\n" "\t$TCA parent 1:1 classid 1:%d htb rate %ukbit %s %s prio %d quantum %u\n" "\t$TQA parent 1:%d handle %d: $SFQ\n" "\t$TFA parent 1: prio %d protocol ip handle %d fw flowid 1:%d\n", i, rate, ceil, x, calc(bw, rate), s, burst_leaf, (i >= 6) ? 7 : (i + 1), mtu, x, x, x, i + 1, x); } free(buf); /* 10000 = ACK 00100 = RST 00010 = SYN 00001 = FIN */ if (nvram_match("qos_ack", "on")) { fprintf(f, "\n" "\t$TFA parent 1: prio 14 protocol ip u32 " "match ip protocol 6 0xff " // TCP "match u8 0x05 0x0f at 0 " // IP header length "match u16 0x0000 0xffc0 at 2 " // total length (0-63) "match u8 0x10 0xff at 33 " // ACK only "flowid 1:10\n"); } if (nvram_match("qos_syn", "on")) { fprintf(f, "\n" "\t$TFA parent 1: prio 15 protocol ip u32 " "match ip protocol 6 0xff " // TCP "match u8 0x05 0x0f at 0 " // IP header length "match u16 0x0000 0xffc0 at 2 " // total length (0-63) "match u8 0x02 0x02 at 33 " // SYN,* "flowid 1:10\n"); } if (nvram_match("qos_fin", "on")) { fprintf(f, "\n" "\t$TFA parent 1: prio 17 protocol ip u32 " "match ip protocol 6 0xff " // TCP "match u8 0x05 0x0f at 0 " // IP header length "match u16 0x0000 0xffc0 at 2 " // total length (0-63) "match u8 0x01 0x01 at 33 " // FIN,* "flowid 1:10\n"); } if (nvram_match("qos_rst", "on")) { fprintf(f, "\n" "\t$TFA parent 1: prio 19 protocol ip u32 " "match ip protocol 6 0xff " // TCP "match u8 0x05 0x0f at 0 " // IP header length "match u16 0x0000 0xffc0 at 2 " // total length (0-63) "match u8 0x04 0x04 at 33 " // RST,* "flowid 1:10\n"); } if (nvram_match("qos_icmp", "on")) { fputs("\n\t$TFA parent 1: prio 13 protocol ip u32 match ip protocol 1 0xff flowid 1:10\n", f); } // ingress first = 1; bw = strtoul(nvram_safe_get("qos_ibw"), NULL, 10); if (bw > 0) { g = buf = strdup(nvram_safe_get("qos_irates")); for (i = 0; i < 5; ++i) { // 0~4 , 0:highest, 4:lowest if ((!g) || ((p = strsep(&g, ",")) == NULL)) break; if ((inuse & (1 << i)) == 0) continue; if ((rate = atoi(p)) < 1) continue; // 0 = off if (first) { first = 0; fprintf(f, "\n" "\ttc qdisc del dev $I ingress 2>/dev/null\n" "\t$TQA handle ffff: ingress\n"); } // rate in kb/s unsigned int u = calc(bw, rate); // burst rate unsigned int v = u / 25; if (v < 50) v = 50; x = i + 1; fprintf(f, "# ingress %d: %u%%\n" "\t$TFA parent ffff: prio %d protocol ip handle %d" " fw police rate %ukbit burst %ukbit drop flowid ffff:%d\n", i, rate, x, x, u, v, x); } } free(buf); fputs( "\t;;\n" "stop)\n" "\ttc qdisc del dev $I root 2>/dev/null\n" "\ttc qdisc del dev $I ingress 2>/dev/null\n" "\t;;\n" "*)\n" "\ttc -s -d class ls dev $I\n" "\techo\n" "\ttc -s -d qdisc ls dev $I\n" "esac\n", f); fclose(f); chmod(qosfn, 0700); eval((char *)qosfn, "start"); fprintf(stderr,"[qos] tc done!\n"); }
int rcheck_main(int argc, char *argv[]) { char buf[256]; char *p; int sched_begin; int sched_end; int sched_dow; time_t now; struct tm *tms; int now_dow; int now_mins; int n; int nrule; char comp; int insch; unsigned long long activated; int count; int radio; int r; #ifdef TCONFIG_IPV6 int r6; #endif #ifdef LINUX26 int ipt_active; #endif if (!nvram_contains_word("log_events", "acre")) { setlogmask(LOG_MASK(LOG_EMERG)); // can't set to 0 } simple_lock("restrictions"); now = time(0); if (now < Y2K) { if (!nvram_match("rrules_timewarn", "1")) { nvram_set("rrules_timewarn", "1"); syslog(LOG_INFO, "Time not yet set. Only \"all day, everyday\" restrictions will be activated."); } now_mins = now_dow = 0; } else { tms = localtime(&now); now_dow = 1 << tms->tm_wday; now_mins = (tms->tm_hour * 60) + tms->tm_min; } #ifdef LINUX26 ipt_active = 0; #endif activated = strtoull(nvram_safe_get("rrules_activated"), NULL, 16); count = 0; radio = foreach_wif(0, NULL, radio_on) ? -1 : -2; for (nrule = 0; nrule < MAX_NRULES; ++nrule) { sprintf(buf, "rrule%d", nrule); if ((p = nvram_get(buf)) == NULL) continue; if (sscanf(p, "%d|%d|%d|%d|%c", &n, &sched_begin, &sched_end, &sched_dow, &comp) != 5) continue; if (n == 0) continue; ++count; if (now < Y2K) { if ((sched_begin >= 0) || (sched_end >= 0) || (sched_dow != 0x7F)) continue; insch = 1; } else { insch = in_sched(now_mins, now_dow, sched_begin, sched_end, sched_dow); } #ifdef LINUX26 if ((insch) && (comp != '~')) ++ipt_active; #endif n = 1 << nrule; if ((insch) == ((activated & n) != 0)) { continue; } syslog(LOG_INFO, "%sctivating rule %d", insch ? "A" : "Dea", nrule); if (comp == '~') { if ((radio != 0) && (radio != -2)) radio = !insch; } else { sprintf(buf, "r%s%02d", (comp != '|') ? "dev" : "res", nrule); r = eval("iptables", "-D", "restrict", "-j", buf); if (insch) { // ignore error above (if any) r = eval("iptables", "-A", "restrict", "-j", buf); } #ifdef TCONFIG_IPV6 r6 = eval("ip6tables", "-D", "restrict", "-j", buf); if (ipv6_enabled()) { if (insch) { // ignore error above (if any) r6 = eval("ip6tables", "-A", "restrict", "-j", buf); } r |= r6; } #endif if (r != 0) { syslog(LOG_ERR, "Iptables: %sactivating chain \"%s\" failed. Retrying in 15 minutes.", insch ? "" : "de", buf); continue; } } if (insch) activated |= n; else activated &= ~n; } sprintf(buf, "%llx", activated); nvram_set("rrules_activated", buf); if (count > 0) { if ((argc != 2) || (strcmp(argv[1], "--cron") != 0)) { eval("cru", "a", "rcheck", "*/15 * * * * rcheck --cron"); } } else { unsched_restrictions(); } if (radio >= 0) { nvram_set("rrules_radio", radio ? "0" : "1"); #if 1 // changed for dual radio support _dprintf("%s: radio = %d\n", __FUNCTION__, radio); eval("radio", radio ? "on" : "off"); #else if (get_radio() != radio) { _dprintf("%s: radio = %d\n", __FUNCTION__, radio); eval("radio", radio ? "on" : "off"); } else { _dprintf("%s: no radio change = %d\n", __FUNCTION__, radio); } #endif } #ifdef LINUX26 allow_fastnat("restrictions", (ipt_active == 0)); try_enabling_fastnat(); #endif simple_unlock("restrictions"); return 0; }
int add_iQosRules(char *pcWANIF) { FILE *fn; #ifdef RTCONFIG_IPV6 FILE *fn_ipv6; #endif char *buf; char *g; char *p; char *desc, *addr, *port, *prio, *transferred, *proto; int class_num; int down_class_num=6; // for download class_num = 0x6 / 0x106 int proto_num; int i, inuse; char q_inuse[32]; // for inuse char dport[192], saddr[192], conn[256], end[256]; int method; int gum; int sticky_enable; const char *chain; int v4v6_ok; if (pcWANIF == NULL || !nvram_match("qos_enable", "1")) return -1; if ((fn = fopen(mangle_fn, "w")) == NULL) return -2; #ifdef RTCONFIG_IPV6 if (ipv6_enabled() && (fn_ipv6 = fopen(mangle_fn_ipv6, "w")) == NULL) return -3; #endif inuse = sticky_enable = 0; if (nvram_match("qos_sticky", "0")) sticky_enable = 1; del_iQosRules(); // flush all rules in mangle table fprintf(stderr, "[qos] iptables START\n"); fprintf(fn, "*mangle\n" ":PREROUTING ACCEPT [0:0]\n" ":OUTPUT ACCEPT [0:0]\n" ":QOSO - [0:0]\n" "-A QOSO -j CONNMARK --restore-mark --mask 0xff\n" "-A QOSO -m connmark ! --mark 0/0xff00 -j RETURN\n" ); #ifdef RTCONFIG_IPV6 if (ipv6_enabled()) fprintf(fn_ipv6, "*mangle\n" ":PREROUTING ACCEPT [0:0]\n" ":OUTPUT ACCEPT [0:0]\n" ":QOSO - [0:0]\n" "-A QOSO -j CONNMARK --restore-mark --mask 0xff\n" "-A QOSO -m connmark ! --mark 0/0xff00 -j RETURN\n" ); #endif g = buf = strdup(nvram_safe_get("qos_rulelist")); while (g) { /* ASUSWRT qos_rulelist : desc>addr>port>proto>transferred>prio addr : source ip or mac port : dest port proto : tcp, udp, tcp/udp, any , (icmp, igmp) transferred : min:max prio : 0-4, 0 is the highest */ if ((p = strsep(&g, "<")) == NULL) break; if((vstrsep(p, ">", &desc, &addr, &port, &proto, &transferred, &prio)) != 6) continue; class_num = atoi(prio); if ((class_num < 0) || (class_num > 4)) continue; i = 1 << class_num; ++class_num; //if (method == 1) class_num |= 0x200; if ((inuse & i) == 0) { inuse |= i; fprintf(stderr, "[qos] iptable creates, inuse=%d\n", inuse); } v4v6_ok = IPT_V4; #ifdef RTCONFIG_IPV6 if (ipv6_enabled()) v4v6_ok |= IPT_V6; #endif /* Beginning of the Rule */ /* if transferred != NULL, class_num must bt 0x1~0x6, not 0x101~0x106 0x1~0x6 : keep tracing this connection. 0x101~0x106 : connection will be considered as marked connection, won't detect again. */ #if 0 if(strcmp(transferred, "") != 0 ) method = 1; else method = atoi(nvram_safe_get("qos_method")); // strict rule ordering gum = (method == 0) ? 0x100 : 0; #else method = 1; gum = 0; #endif class_num |= gum; down_class_num |= gum; // for download chain = "QOSO"; // chain name sprintf(end , " -j CONNMARK --set-return 0x%x/0xFF\n", class_num); // CONNMARK string /*************************************************/ /* addr */ /* src mac or src ip */ /*************************************************/ char tmp[20]; char *tmp_addr, *q_ip, *q_mac; sprintf(tmp, "%s", addr); tmp_addr = tmp; q_ip = strsep(&tmp_addr, ":"); q_mac = tmp_addr; if(strcmp(addr, "") == 0 ) sprintf(saddr, "%s", addr); // src addr else{ if (q_mac == NULL){ sprintf(saddr, "-s %s", addr); // src addr v4v6_ok &= ipt_addr_compact(addr, v4v6_ok, (v4v6_ok==IPT_V4)); if (!v4v6_ok) continue; } else{ sprintf(saddr, "-m mac --mac-source %s", addr); // src mac } } //fprintf(stderr, "[qos] tmp=%s, ip=%s, mac=%s, addr=%s\n", tmp, q_ip, q_mac, addr ); // tmp test /*************************************************/ /* port */ /* single port or multi-ports */ /*************************************************/ char *tmp_port, *q_port, *q_leave; sprintf(tmp, "%s", port); tmp_port = tmp; q_port = strsep(&tmp_port, ","); q_leave = tmp_port; if(strcmp(port, "") == 0 ){ sprintf(dport, ""); } else{ if(q_leave != NULL) sprintf(dport, "-m multiport --dport %s", port); // multi port else sprintf(dport, "--dport %s", port); // single port } //fprintf(stderr, "[qos] tmp=%s, q_port=%s, q_leave=%s, port=%s\n", tmp, q_port, q_leave, port ); // tmp test /*************************************************/ /* transferred */ /* --connbytes min:max */ /* --connbytes-dir (original/reply/both) */ /* --connbytes-mode (packets/bytes/avgpkt) */ /*************************************************/ char *tmp_trans, *q_min, *q_max; long min, max ; sprintf(tmp, "%s", transferred); tmp_trans = tmp; q_min = strsep(&tmp_trans, "~"); q_max = tmp_trans; if (strcmp(transferred,"") == 0){ sprintf(conn, ""); } else{ sprintf(tmp, "%s", q_min); min = atol(tmp); if(strcmp(q_max,"") == 0) // q_max == NULL sprintf(conn, "-m connbytes --connbytes %ld:%s --connbytes-dir both --connbytes-mode bytes", min*1024, q_max); else{// q_max != NULL sprintf(tmp, "%s", q_max); max = atol(tmp); sprintf(conn, "-m connbytes --connbytes %ld:%ld --connbytes-dir both --connbytes-mode bytes", min*1024, max*1024-1); } } //fprintf(stderr, "[qos] tmp=%s, transferred=%s, min=%ld, max=%ld, q_max=%s, conn=%s\n", tmp, transferred, min*1024, max*1024-1, q_max, conn ); // tmp test /*************************************************/ /* proto */ /* tcp, udp, tcp/udp, any, (icmp, igmp) */ /*************************************************/ if(strcmp(proto, "tcp") == 0 ) { if (v4v6_ok & IPT_V4) fprintf(fn, "-A %s -p %s %s %s %s %s", chain, "tcp", dport, saddr, conn, end); #ifdef RTCONFIG_IPV6 if (ipv6_enabled() && (v4v6_ok & IPT_V6)) fprintf(fn_ipv6, "-A %s -p %s %s %s %s %s", chain, "tcp", dport, saddr, conn, end); #endif } else if(strcmp(proto, "udp") == 0 ) { if (v4v6_ok & IPT_V4) fprintf(fn, "-A %s -p %s %s %s %s %s", chain, "udp", dport, saddr, conn, end); #ifdef RTCONFIG_IPV6 if (ipv6_enabled() && (v4v6_ok & IPT_V6)) fprintf(fn_ipv6, "-A %s -p %s %s %s %s %s", chain, "udp", dport, saddr, conn, end); #endif } //else if(strcmp(proto, "icmp") == 0 || strcmp(proto, "igmp") == 0 ) else if(strcmp(proto, "any") == 0) { if (v4v6_ok & IPT_V4) fprintf(fn, "-A %s %s %s %s", chain, saddr, conn, end); #ifdef RTCONFIG_IPV6 if (ipv6_enabled() && (v4v6_ok & IPT_V6)) fprintf(fn_ipv6, "-A %s %s %s %s", chain, saddr, conn, end); #endif } else if(strcmp(proto, "tcp/udp") == 0 ){ if (v4v6_ok & IPT_V4) { fprintf(fn, "-A %s -p %s %s %s %s %s", chain, "tcp", dport, saddr, conn, end); fprintf(fn, "-A %s -p %s %s %s %s %s", chain, "udp", dport, saddr, conn, end); } #ifdef RTCONFIG_IPV6 if (ipv6_enabled() && (v4v6_ok & IPT_V6)) { fprintf(fn_ipv6, "-A %s -p %s %s %s %s %s", chain, "tcp", dport, saddr, conn, end); fprintf(fn_ipv6, "-A %s -p %s %s %s %s %s", chain, "udp", dport, saddr, conn, end); } #endif } else fprintf(stderr, "[qos] proto doesn't exist!!\n"); //fprintf(stderr,"[qos] -A %s -p %s %s %s %s %s", chain, "tcp", port, saddr, conn, end); //tmp test } free(buf); /* lan_addr for iptables use (LAN download) */ char *a, *b, *c, *d; char lan_addr[20]; g = buf = strdup(nvram_safe_get("lan_ipaddr")); if((vstrsep(g, ".", &a, &b, &c, &d)) != 4){ fprintf(stderr,"[qos] lan_ipaddr doesn't exist!!\n"); } else{ //fprintf(stderr,"[qos] lan_ipaddr exist!!\n"); sprintf(lan_addr, "%s.%s.%s.0/24", a, b, c); fprintf(stderr,"[qos] lan_addr=%s\n", lan_addr); } free(buf); //fprintf(stderr, "[qos] down_class_num=%x\n", down_class_num); /* The default class */ i = nvram_get_int("qos_default"); if ((i < 0) || (i > 4)) i = 3; // "lowest" class_num = i + 1; fprintf(fn, "-A QOSO -d %s -j CONNMARK --set-return 0x%x/0xFF\n" // for download (LAN or wireless) "-A POSTROUTING -o br0 -j QOSO\n" // for download, interface br0 "-A QOSO -j CONNMARK --set-return 0x%x\n" "-A FORWARD -o %s -j QOSO\n" "-A OUTPUT -o %s -j QOSO\n", lan_addr, down_class_num, class_num, pcWANIF, pcWANIF); #ifdef RTCONFIG_IPV6 if (ipv6_enabled() && *wan6face) { fprintf(fn_ipv6, "-A QOSO -d %s -j CONNMARK --set-return 0x%x/0xFF\n" // for download (LAN or wireless) "-A POSTROUTING -o br0 -j QOSO\n" // for download, interface br0 "-A QOSO -j CONNMARK --set-return 0x%x\n" "-A FORWARD -o %s -j QOSO\n" "-A OUTPUT -o %s -j QOSO\n", lan_addr, down_class_num, class_num, wan6face, wan6face); } #endif inuse |= (1 << i) | 1; // default and highest are always built sprintf(q_inuse, "%d", inuse); nvram_set("qos_inuse", q_inuse); fprintf(stderr, "[qos] qos_inuse=%d\n", inuse); /* Ingress rules */ g = buf = strdup(nvram_safe_get("qos_irates")); for (i = 0; i < 10; ++i) { if ((!g) || ((p = strsep(&g, ",")) == NULL)) continue; if ((inuse & (1 << i)) == 0) continue; if (atoi(p) > 0) { fprintf(fn, "-A PREROUTING -i %s -j CONNMARK --restore-mark --mask 0xff\n", pcWANIF); #ifdef RTCONFIG_IPV6 if (ipv6_enabled() && *wan6face) fprintf(fn_ipv6, "-A PREROUTING -i %s -j CONNMARK --restore-mark --mask 0xff\n", wan6face); #endif break; } } free(buf); fprintf(fn, "COMMIT\n"); fclose(fn); chmod(mangle_fn, 0700); eval("iptables-restore", "/tmp/mangle_rules"); #ifdef RTCONFIG_IPV6 if (ipv6_enabled()) { fprintf(fn_ipv6, "COMMIT\n"); fclose(fn_ipv6); chmod(mangle_fn_ipv6, 0700); eval("ip6tables-restore", "/tmp/mangle_rules_ipv6"); } #endif fprintf(stderr, "[qos] iptables DONE!\n"); }
void start_mmc(void) { if (nvram_match("mmc_enable", "1")) { #ifdef HAVE_FONERA int res = insmod("mmc"); if (!res) { // device detected insmod("mbcache"); insmod("ext2"); if (mount("/dev/mmc", "/mmc", "ext2", MS_MGC_VAL, NULL)) { // device not formated eval("mkfs.ext2", "-F", "-b", "1024", "/dev/mmc"); mount("/dev/mmc", "/mmc", "ext2", MS_MGC_VAL, NULL); } } #else int res = 1; int mmc_di = 0, mmc_do = 0, mmc_clk = 0, mmc_cs = 0; char dddi[16], dddo[16], ddclk[16], ddcs[16]; if (nvram_match("mmc_gpio", "1")) // manual gpio asigments { mmc_di = strtoul(nvram_safe_get("mmc_di"), NULL, 0); mmc_do = strtoul(nvram_safe_get("mmc_do"), NULL, 0); mmc_clk = strtoul(nvram_safe_get("mmc_clk"), NULL, 0); mmc_cs = strtoul(nvram_safe_get("mmc_cs"), NULL, 0); } else // auto gpio based on router brand/model { switch (getRouterBrand()) { case ROUTER_WRT54G: if (nvram_match("boardtype", "0x0467")) // v4 or GL mmc_di = 2; else mmc_di = 5; mmc_do = 4; mmc_clk = 3; mmc_cs = 7; break; case ROUTER_ASUS_WL500GD: mmc_di = 5; mmc_do = 4; mmc_clk = 1; mmc_cs = 7; break; case ROUTER_BUFFALO_WHRG54S: mmc_di = 5; mmc_do = 6; mmc_clk = 3; mmc_cs = 7; break; case ROUTER_BUFFALO_WZRRSG54: mmc_di = 5; mmc_do = 4; mmc_clk = 3; mmc_cs = 7; break; } } /* sprintf(dddi, "DDDI=0x%X", 1 << mmc_di); sprintf(dddo, "DDDO=0x%X", 1 << mmc_do); sprintf(ddclk, "DDCLK=0x%X", 1 << mmc_clk); sprintf(ddcs, "DDCS=0x%X", 1 << mmc_cs); */ sprintf(dddi, "din=%d", mmc_di); sprintf(dddo, "dout=%d", mmc_do); sprintf(ddclk, "clk=%d", mmc_clk); sprintf(ddcs, "cs=%d", mmc_cs); if ((mmc_di + mmc_do + mmc_clk + mmc_cs) > 5) // eval only // if at // least 0, // 1, 2, 3 res = eval("insmod", "mmc", dddi, dddo, ddclk, ddcs); // eval("insmod","mmc", // "DDDI=0x04", // "DDDO=0x10", // "DDCLK=0x08", // "DDCS=0x80"); if (!res) { // device detected insmod("ext2"); if (mount("/dev/mmc/disc0/part1", "/mmc", "ext2", MS_MGC_VAL, NULL)) { // device not formated eval("mkfs.ext2", "-F", "-b", "1024", "/dev/mmc/disc0/part1"); mount("/dev/mmc/disc0/part1", "/mmc", "ext2", MS_MGC_VAL, NULL); } } #endif } }
static int ipv4_route_table_array(webs_t wp) { FILE *fp; char tmp[100], prefix[] = "wanXXXXXXXXXX_"; char buf[256], *dev, *sflags, *str; struct in_addr dest, gateway, mask; int flags, ref, use, metric; int unit, ret = 0; fp = fopen("/proc/net/route", "r"); if (fp == NULL) { ret += websWrite(wp, "[]];\n"); return ret; } while ((str = fgets(buf, sizeof(buf), fp)) != NULL) { dev = strsep(&str, " \t"); if (!str || dev == str) continue; if (sscanf(str, "%x%x%x%d%u%d%x", &dest.s_addr, &gateway.s_addr, &flags, &ref, &use, &metric, &mask.s_addr) != 7) continue; /* Parse flags, reuse buf */ sflags = str; if (flags & RTF_UP) *str++ = 'U'; if (flags & RTF_GATEWAY) *str++ = 'G'; if (flags & RTF_HOST) *str++ = 'H'; *str++ = '\0'; /* Skip interfaces here */ if (strcmp(dev, "lo") == 0) continue; /* Replace known interfaces with LAN/WAN/MAN */ if (nvram_match("lan_ifname", dev)) /* br0, wl0, etc */ dev = "LAN"; else { /* Tricky, it's better to move wan_ifunit/wanx_ifunit to shared instead */ for (unit = WAN_UNIT_FIRST; unit < WAN_UNIT_MAX; unit++) { snprintf(prefix, sizeof(prefix), "wan%d_", unit); if (nvram_match(strcat_r(prefix, "pppoe_ifname", tmp), dev)) { dev = "WAN"; break; } if (nvram_match(strcat_r(prefix, "ifname", tmp), dev)) { char *wan_proto = nvram_safe_get(strcat_r(prefix, "proto", tmp)); dev = (strcmp(wan_proto, "dhcp") == 0 || strcmp(wan_proto, "static") == 0 ) ? "WAN" : "MAN"; break; } } } ret += websWrite(wp, "[\"%s\",", dest.s_addr == INADDR_ANY ? "default" : inet_ntoa(dest)); ret += websWrite(wp, "\"%s\", ", gateway.s_addr == INADDR_ANY ? "*" : inet_ntoa(gateway)); ret += websWrite(wp, "\"%s\", \"%s\", \"%d\", \"%d\", \"%d\", \"%s\"],\n", inet_ntoa(mask), sflags, metric, ref, use, dev); } fclose(fp); return ret; }
static void save(int quick) { int i; int n; int b; char hgz[256]; char tmp[256]; char bak[256]; char bkp[256]; time_t now; struct tm *tms; static int lastbak = -1; _dprintf("%s: quick=%d\n", __FUNCTION__, quick); f_write("/var/lib/misc/cstats-stime", &save_utime, sizeof(save_utime), 0, 0); n = save_history_from_tree(history_fn); _dprintf("%s: saved %d records from tree on file %s\n", __FUNCTION__, n, history_fn); _dprintf("%s: write source=%s\n", __FUNCTION__, save_path); f_write_string(source_fn, save_path, 0, 0); if (quick) { return; } sprintf(hgz, "%s.gz", history_fn); if (save_path[0] != 0) { strcpy(tmp, save_path); strcat(tmp, ".tmp"); for (i = 15; i > 0; --i) { if (!wait_action_idle(10)) { _dprintf("%s: busy, not saving\n", __FUNCTION__); } else { _dprintf("%s: cp %s %s\n", __FUNCTION__, hgz, tmp); if (eval("cp", hgz, tmp) == 0) { _dprintf("%s: copy ok\n", __FUNCTION__); if (!nvram_match("rstats_bak", "0")) { now = time(0); tms = localtime(&now); if (lastbak != tms->tm_yday) { strcpy(bak, save_path); n = strlen(bak); if ((n > 3) && (strcmp(bak + (n - 3), ".gz") == 0)) n -= 3; // sprintf(bak + n, "_%d.bak", ((tms->tm_yday / 7) % 3) + 1); // if (eval("cp", save_path, bak) == 0) lastbak = tms->tm_yday; strcpy(bkp, bak); for (b = HI_BACK-1; b > 0; --b) { sprintf(bkp + n, "_%d.bak", b + 1); sprintf(bak + n, "_%d.bak", b); rename(bak, bkp); } if (eval("cp", "-p", save_path, bak) == 0) lastbak = tms->tm_yday; } } _dprintf("%s: rename %s %s\n", __FUNCTION__, tmp, save_path); if (rename(tmp, save_path) == 0) { _dprintf("%s: rename ok\n", __FUNCTION__); break; } } } // might not be ready sleep(3); if (gotterm) break; } } }
void start_jffs2(void) { if (!nvram_match("jffs2_on", "1")) { notice_set("jffs", ""); return; } int format = 0; char s[256]; int size; int part; const char *p; struct statfs sf; if (!wait_action_idle(10)) return; if (!mtd_getinfo("jffs2", &part, &size)) return; if (nvram_match("jffs2_format", "1")) { nvram_set("jffs2_format", "0"); nvram_commit_x(); if (!mtd_erase("jffs2")) { error("formatting"); return; } format = 1; } sprintf(s, "%d", size); p = nvram_get("jffs2_size"); if ((p == NULL) || (strcmp(p, s) != 0)) { if (format) { nvram_set("jffs2_size", s); nvram_commit_x(); } else if ((p != NULL) && (*p != 0)) { error("verifying known size of"); return; } } if ((statfs("/jffs", &sf) == 0) && (sf.f_type != 0x73717368 /* squashfs */)) { // already mounted notice_set("jffs", format ? "Formatted" : "Loaded"); return; } if (!mtd_unlock("jffs2")) { error("unlocking"); return; } modprobe(JFFS_NAME); sprintf(s, MTD_BLKDEV(%d), part); if (mount(s, "/jffs", JFFS_NAME, MS_NOATIME, "") != 0) { modprobe_r(JFFS_NAME); error("mounting"); return; } #ifdef TEST_INTEGRITY int test; if (format) { if (f_write("/jffs/.tomato_do_not_erase", &size, sizeof(size), 0, 0) != sizeof(size)) { stop_jffs2(); error("setting integrity test for"); return; } } if ((f_read("/jffs/.tomato_do_not_erase", &test, sizeof(test)) != sizeof(test)) || (test != size)) { stop_jffs2(); error("testing integrity of"); return; } #endif notice_set("jffs", format ? "Formatted" : "Loaded"); if (((p = nvram_get("jffs2_exec")) != NULL) && (*p != 0)) { chdir("/jffs"); system(p); chdir("/"); } run_userfile("/jffs", ".autorun", "/jffs", 3); }
void setup_bcom(int skfd, char *ifname) { int val = 0; char buf[8192]; char wbuf[80]; char *v; if (bcom_ioctl(skfd, ifname, WLC_GET_MAGIC, &val, sizeof(val)) < 0) return; nvram_set(wl_var("ifname"), ifname); stop_bcom(skfd, ifname); /* Set Country */ strncpy(buf, nvram_safe_get(wl_var("country_code")), 4); buf[3] = 0; bcom_ioctl(skfd, ifname, WLC_SET_COUNTRY, buf, 4); /* Set up afterburner */ val = ABO_AUTO; if (nvram_enabled(wl_var("afterburner"))) val = ABO_ON; if (nvram_disabled(wl_var("afterburner"))) val = ABO_OFF; bcom_set_val(skfd, ifname, "afterburner_override", &val, sizeof(val)); /* Set other options */ val = nvram_enabled(wl_var("lazywds")); bcom_ioctl(skfd, ifname, WLC_SET_LAZYWDS, &val, sizeof(val)); if (v = nvram_get(wl_var("frag"))) { val = atoi(v); bcom_ioctl(skfd, ifname, WLC_SET_FRAG, &val, sizeof(val)); } if (v = nvram_get(wl_var("dtim"))) { val = atoi(v); bcom_ioctl(skfd, ifname, WLC_SET_DTIMPRD, &val, sizeof(val)); } if (v = nvram_get(wl_var("bcn"))) { val = atoi(v); bcom_ioctl(skfd, ifname, WLC_SET_BCNPRD, &val, sizeof(val)); } if (v = nvram_get(wl_var("rts"))) { val = atoi(v); bcom_ioctl(skfd, ifname, WLC_SET_RTS, &val, sizeof(val)); } if (v = nvram_get(wl_var("antdiv"))) { val = atoi(v); bcom_ioctl(skfd, ifname, WLC_SET_ANTDIV, &val, sizeof(val)); } if (v = nvram_get(wl_var("txant"))) { val = atoi(v); bcom_ioctl(skfd, ifname, WLC_SET_TXANT, &val, sizeof(val)); } val = nvram_enabled(wl_var("closed")); bcom_ioctl(skfd, ifname, WLC_SET_CLOSED, &val, sizeof(val)); val = nvram_enabled(wl_var("ap_isolate")); bcom_set_int(skfd, ifname, "ap_isolate", val); val = nvram_enabled(wl_var("frameburst")); bcom_ioctl(skfd, ifname, WLC_SET_FAKEFRAG, &val, sizeof(val)); /* Set up MAC list */ if (nvram_match(wl_var("macmode"), "allow")) val = WLC_MACMODE_ALLOW; else if (nvram_match(wl_var("macmode"), "deny")) val = WLC_MACMODE_DENY; else val = WLC_MACMODE_DISABLED; if ((val != WLC_MACMODE_DISABLED) && (v = nvram_get(wl_var("maclist")))) { struct maclist *mac_list; struct ether_addr *addr; char *next; memset(buf, 0, 8192); mac_list = (struct maclist *) buf; addr = mac_list->ea; foreach(wbuf, v, next) { if (ether_atoe(wbuf, addr->ether_addr_octet)) { mac_list->count++; addr++; } } bcom_ioctl(skfd, ifname, WLC_SET_MACLIST, buf, sizeof(buf)); } else {
void main_config(void) { char *chillinet; int log_level = 0; FILE *fp; log_level = atoi(nvram_safe_get("log_level")); mkdir("/tmp/chilli", 0700); if (!(fp = fopen("/tmp/chilli/ip-up.sh", "w"))) { perror("/tmp/chilli/ip-up.sh"); return; } if (log_level >= 1) sprintf(log_drop, "%s", "logdrop"); else sprintf(log_drop, "%s", "DROP"); if (log_level >= 2) sprintf(log_accept, "%s", "logaccept"); else sprintf(log_accept, "%s", TARG_PASS); if (log_level >= 1) sprintf(log_reject, "%s", "logreject"); else sprintf(log_reject, "%s", TARG_RST); if (nvram_match("hotss_enable", "1")) { if (strlen(nvram_safe_get("hotss_net")) > 0) chillinet = nvram_safe_get("hotss_net"); else chillinet = "192.168.182.0/24"; } if (nvram_match("chilli_enable", "1") && nvram_match("hotss_enable", "0")) { if (strlen(nvram_safe_get("chilli_net")) > 0) chillinet = nvram_safe_get("chilli_net"); else chillinet = "192.168.182.0/24"; } /* if we have a gw traffic will go there. but if we dont have any gw we might use chilli on a local network only also we need to allow traffic in/outgoing to chilli*/ fprintf(fp, "#!/bin/sh\n"); fprintf(fp, "iptables -D INPUT -i tun0 -j %s\n", log_accept); fprintf(fp, "iptables -D FORWARD -i tun0 -j %s\n", log_accept); fprintf(fp, "iptables -D FORWARD -o tun0 -j %s\n", log_accept); fprintf(fp, "iptables -I INPUT -i tun0 -j %s\n", log_accept); fprintf(fp, "iptables -I FORWARD -i tun0 -j %s\n", log_accept); fprintf(fp, "iptables -I FORWARD -o tun0 -j %s\n", log_accept); // secure chilli interface, only usefull if ! br0 if (nvram_match("chilli_enable", "1") && nvram_match("hotss_enable", "0") && nvram_invmatch("chilli_interface", "br0")) { fprintf(fp, "iptables -t nat -D PREROUTING -i %s ! -s %s -j %s\n", nvram_safe_get("chilli_interface"), chillinet, log_drop); fprintf(fp, "iptables -t nat -I PREROUTING -i %s ! -s %s -j %s\n", nvram_safe_get("chilli_interface"), chillinet, log_drop); } if (nvram_match("chilli_enable", "1") && nvram_match("hotss_enable", "1") && nvram_invmatch("hotss_interface", "br0")) { fprintf(fp, "iptables -t nat -D PREROUTING -i %s ! -s %s -j %s\n", nvram_safe_get("hotss_interface"), chillinet, log_drop); fprintf(fp, "iptables -t nat -I PREROUTING -i %s ! -s %s -j %s\n", nvram_safe_get("hotss_interface"), chillinet, log_drop); } // MASQUERADE chilli/hotss if (nvram_match("wan_proto", "disabled")) { fprintf(fp, "iptables -D FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu\n"); fprintf(fp, "iptables -t nat -D POSTROUTING -s %s -j MASQUERADE\n", chillinet); fprintf(fp, "iptables -I FORWARD 1 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu\n"); // clamp when fw clamping is off fprintf(fp, "iptables -t nat -I POSTROUTING -s %s -j MASQUERADE\n", chillinet); } else { fprintf(fp, "iptables -t nat -D POSTROUTING -o %s -s %s -j SNAT --to-source=%s\n", nvram_safe_get("wan_iface"), chillinet, get_wan_ipaddr()); fprintf(fp, "iptables -t nat -I POSTROUTING -o %s -s %s -j SNAT --to-source=%s\n", nvram_safe_get("wan_iface"), chillinet, get_wan_ipaddr()); } // enable Reverse Path Filtering to prevent double outgoing packages if (nvram_match("chilli_enable", "1") && nvram_match("hotss_enable", "0")) { fprintf(fp, "echo 1 > /proc/sys/net/ipv4/conf/%s/rp_filter\n", nvram_safe_get("chilli_interface")); } if (nvram_match("chilli_enable", "1") && nvram_match("hotss_enable", "1")) { fprintf(fp, "echo 1 > /proc/sys/net/ipv4/conf/%s/rp_filter\n", nvram_safe_get("hotss_interface")); } fclose(fp); if (!(fp = fopen("/tmp/chilli/ip-down.sh", "w"))) { perror("/tmp/chilli/ip-down.sh"); return; } fprintf(fp, "#!/bin/sh\n"); fprintf(fp, "iptables -D INPUT -i tun0 -j %s\n", log_accept); fprintf(fp, "iptables -D FORWARD -i tun0 -j %s\n", log_accept); fprintf(fp, "iptables -D FORWARD -o tun0 -j %s\n", log_accept); if (nvram_match("chilli_enable", "1") && nvram_match("hotss_enable", "0") && nvram_invmatch("chilli_interface", "br0")) fprintf(fp, "iptables -t nat -D PREROUTING -i %s ! -s %s -j %s\n", nvram_safe_get("chilli_interface"), chillinet, log_drop); if (nvram_match("chilli_enable", "1") && nvram_match("hotss_enable", "1") && nvram_invmatch("hotss_interface", "br0")) fprintf(fp, "iptables -t nat -D PREROUTING -i %s ! -s %s -j %s\n", nvram_safe_get("hotss_interface"), chillinet, log_drop); if (nvram_match("wan_proto", "disabled")) { fprintf(fp, "iptables -D FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu\n"); fprintf(fp, "iptables -t nat -D POSTROUTING -s %s -j MASQUERADE\n", chillinet); } else fprintf(fp, "iptables -t nat -D POSTROUTING -o %s -s %s -j SNAT --to-source=%s\n", nvram_safe_get("wan_iface"), chillinet, get_wan_ipaddr()); fclose(fp); chmod("/tmp/chilli/ip-up.sh", 0700); chmod("/tmp/chilli/ip-down.sh", 0700); // use usb/jffs for connection scripts if available if (jffs == 1) { mkdir("/jffs/etc", 0700); mkdir("/jffs/etc/chilli", 0700); if (!(fp = fopen("/jffs/etc/chilli/con-up.sh", "r"))) { // dont overwrite fp = fopen("/jffs/etc/chilli/con-up.sh", "w"); if (fp == NULL) return; fprintf(fp, "#!/bin/sh\n"); fclose(fp); } if (!(fp = fopen("/jffs/etc/chilli/con-down.sh", "r"))) { fp = fopen("/jffs/etc/chilli/con-down.sh", "w"); if (fp == NULL) return; fprintf(fp, "#!/bin/sh\n"); fclose(fp); } chmod("/jffs/etc/chilli/con-up.sh", 0700); chmod("/jffs/etc/chilli/con-down.sh", 0700); } }
int nvram_enabled(char *name) { return (nvram_match(name, "1") || nvram_match(name, "on") || nvram_match(name, "enabled") || nvram_match(name, "true") || nvram_match(name, "yes") ? 1 : 0); }
int ej_active_wireless_if_11n(webs_t wp, int argc, char_t ** argv, char *ifname, int cnt, int turbo, int macmask) { unsigned char *cp; int s, len; struct iwreq iwr; char nb[32]; sprintf(nb, "%s_bias", ifname); int bias = atoi(nvram_default_get(nb, "0")); if (!ifexists(ifname)) { printf("IOCTL_STA_INFO ifresolv %s failed!\n", ifname); return cnt; } int state = 0; state = get_radiostate(ifname); if (state == 0 || state == -1) { printf("IOCTL_STA_INFO radio %s not enabled!\n", ifname); return cnt; } s = getsocket(); if (s < 0) { fprintf(stderr, "socket(SOCK_DRAGM)\n"); return cnt; } (void)memset(&iwr, 0, sizeof(struct iwreq)); (void)strncpy(iwr.ifr_name, ifname, sizeof(iwr.ifr_name)); iwr.u.data.pointer = (void *)&madbuf[0]; iwr.u.data.length = 24 * 1024; if (ioctl(s, IEEE80211_IOCTL_STA_INFO, &iwr) < 0) { fprintf(stderr, "IOCTL_STA_INFO for %s failed!\n", ifname); closesocket(); return cnt; } len = iwr.u.data.length; if (len < sizeof(struct ieee80211req_sta_info)) { // fprintf(stderr,"IOCTL_STA_INFO len<struct %s failed!\n",ifname); closesocket(); return cnt; } cp = madbuf; int bufcount = 0; do { struct ieee80211req_sta_info *si; uint8_t *vp; si = (struct ieee80211req_sta_info *)cp; vp = (u_int8_t *)(si + 1); if (cnt) websWrite(wp, ","); cnt++; char mac[32]; strncpy(mac, ieee80211_ntoa(si->isi_macaddr), 31); if (nvram_match("maskmac", "1") && macmask) { mac[0] = 'x'; mac[1] = 'x'; mac[3] = 'x'; mac[4] = 'x'; mac[6] = 'x'; mac[7] = 'x'; mac[9] = 'x'; mac[10] = 'x'; } if (si->isi_noise == 0) { si->isi_noise = -95; } int qual = (si->isi_noise + si->isi_rssi) * 124 + 11600; qual /= 10; int rxrate = si->isi_rxrateKbps / 1000; int txrate = si->isi_txrateKbps / 1000; if (!rxrate) rxrate = si->isi_rates[si->isi_rxrate] & IEEE80211_RATE_VAL; if (!txrate) txrate = si->isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL; char rx[32]; char tx[32]; if (rxrate) sprintf(rx, "%3dM", rxrate); else sprintf(rx, "N/A"); if (txrate) sprintf(tx, "%3dM", txrate); else sprintf(tx, "N/A"); websWrite(wp, "'%s','%s','%s','%s','%s','%d','%d','%d','%d'", mac, ifname, UPTIME(si->isi_uptime), tx, rx, si->isi_noise + si->isi_rssi + bias, si->isi_noise + bias, si->isi_rssi, qual); bufcount += si->isi_len; cp += si->isi_len; len -= si->isi_len; } while (len >= sizeof(struct ieee80211req_sta_info) && bufcount < (sizeof(madbuf) - sizeof(struct ieee80211req_sta_info))); closesocket(); return cnt; }
int nvram_disabled(char *name) { return (nvram_match(name, "0") || nvram_match(name, "off") || nvram_match(name, "disabled") || nvram_match(name, "false") || nvram_match(name, "no") ? 1 : 0); }
/* Tc */ int start_iQos(void) { int i; char *buf, *g, *p; unsigned int rate; unsigned int ceil; unsigned int bw; unsigned int mtu; FILE *f; int x; int inuse; char s[256]; int first; char burst_root[32]; char burst_leaf[32]; if (!nvram_match("qos_enable", "1")) return; if ((f = fopen(qosfn, "w")) == NULL) return; i = atoi(nvram_safe_get("qos_burst0")); if (i > 0) sprintf(burst_root, "burst %dk", i); else burst_root[0] = 0; i = atoi(nvram_safe_get("qos_burst1")); if (i > 0) sprintf(burst_leaf, "burst %dk", i); else burst_leaf[0] = 0; /* Egress OBW -- set the HTB shaper (Classful Qdisc) * the BW is set here for each class */ mtu = strtoul(nvram_safe_get("wan_mtu"), NULL, 10); bw = strtoul(nvram_safe_get("qos_obw"), NULL, 10); fprintf(f, "#!/bin/sh\n" "I=%s\n" "SFQ=\"sfq perturb 10\"\n" "TQA=\"tc qdisc add dev $I\"\n" "TCA=\"tc class add dev $I\"\n" "TFA=\"tc filter add dev $I\"\n" "\n" "case \"$1\" in\n" "start)\n" "\ttc qdisc del dev $I root 2>/dev/null\n" "\t$TQA root handle 1: htb default %u\n" "\t$TCA parent 1: classid 1:1 htb rate %ukbit ceil %ukbit %s\n", nvram_safe_get("wan_ifname"), (atoi(nvram_safe_get("qos_default")) + 1) * 10, bw, bw, burst_root); inuse = atoi(nvram_safe_get("qos_inuse")); g = buf = strdup(nvram_safe_get("qos_orates")); for (i = 0; i < 10; ++i) { if ((!g) || ((p = strsep(&g, ",")) == NULL)) break; if ((inuse & (1 << i)) == 0) continue; if ((sscanf(p, "%u-%u", &rate, &ceil) != 2) || (rate < 1)) continue; if (ceil > 0) sprintf(s, "ceil %ukbit ", calc(bw, ceil)); else s[0] = 0; x = (i + 1) * 10; fprintf(f, "# egress %d: %u-%u%%\n" "\t$TCA parent 1:1 classid 1:%d htb rate %ukbit %s %s prio %d quantum %u\n" "\t$TQA parent 1:%d handle %d: $SFQ\n" "\t$TFA parent 1: prio %d protocol ip handle %d fw flowid 1:%d\n", i, rate, ceil, x, calc(bw, rate), s, burst_leaf, (i >= 6) ? 7 : (i + 1), mtu, x, x, x, i + 1, x); } free(buf); if (nvram_match("qos_ack", "1")) { fprintf(f, "\n" "\t$TFA parent 1: prio 15 protocol ip u32 " "match ip protocol 6 0xff " // TCP "match u8 0x05 0x0f at 0 " // IP header length "match u16 0x0000 0xffc0 at 2 " // total length(0-63) "match u8 0x10 0xff at 33 " // ACK only "flowid 1:10\n"); } if (nvram_match("qos_icmp", "1")) { fputs("\n\t$TFA parent 1: prio 14 protocol ip u32 match" "ip protocol 1 0xff flowid 1:10\n", f); fputs("\n\t$TFA parent 1: prio 14 protocol ip u32 match" "ip protocol 1 0xff flowid 1:10\n", stderr); } // ingress first = 1; bw = strtoul(nvram_safe_get("qos_ibw"), NULL, 10); if (bw > 0) { g = buf = strdup(nvram_safe_get("qos_irates")); for (i = 0; i < 10; ++i) { if ((!g) || ((p = strsep(&g, ",")) == NULL)) break; if ((inuse & (1 << i)) == 0) continue; if ((rate = atoi(p)) < 1) continue; // 0 = off if (first) { first = 0; fprintf(f, "\n" "\ttc qdisc del dev $I ingress 2>/dev/null\n" "\t$TQA handle ffff: ingress\n"); } // rate in kb/s unsigned int u = calc(bw, rate); // burst rate unsigned int v = u / 25; if (v < 50) v = 50; x = i + 1; fprintf(f, "# ingress %d: %u%%\n" "\t$TFA parent ffff: prio %d protocol ip handle %d" " fw police rate %ukbit burst %ukbit drop flowid ffff:%d\n", i, rate, x, x, u, v, x); } } free(buf); fputs( "\t;;\n" "stop)\n" "\ttc qdisc del dev $I root 2>/dev/null\n" "\ttc qdisc del dev $I ingress 2>/dev/null\n" "\t;;\n" "*)\n" "\ttc -s -d qdisc ls dev $I\n" "\techo\n" "\ttc -s -d class ls dev $I\n" "esac\n", f); fclose(f); chmod(qosfn, 0700); eval((char *)qosfn, "start"); }
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(); } } }
int svqos_set_ports(void) { #ifndef HAVE_XSCALE #ifndef HAVE_MAGICBOX #ifndef HAVE_RB600 #ifndef HAVE_FONERA #ifndef HAVE_RT2880 #ifndef HAVE_LS2 #ifndef HAVE_LS5 #ifndef HAVE_WHRAG108 #ifndef HAVE_CA8 #ifndef HAVE_SOLO51 #ifndef HAVE_X86 #ifndef HAVE_LAGUNA #ifndef HAVE_VENTANA #ifndef HAVE_TW6600 #ifndef HAVE_PB42 #ifndef HAVE_LSX #ifndef HAVE_DANUBE #ifndef HAVE_STORM #ifndef HAVE_OPENRISC #ifndef HAVE_ADM5120 if (nvram_match("portprio_support", "1")) { int loop = 1; char nvram_var[32] = { 0 }, *level; svqos_reset_ports(); for (loop = 1; loop < 5; loop++) { snprintf(nvram_var, 31, "svqos_port%dbw", loop); if (strcmp("0", nvram_safe_get(nvram_var))) writevaproc(nvram_safe_get(nvram_var), "/proc/switch/eth0/port/%d/bandwidth", loop); else writevaproc("0", "/proc/switch/eth0/port/%d/enable", loop); writevaproc("1", "/proc/switch/eth0/port/%d/prio-enable", loop); level = nvram_nget("svqos_port%dprio", loop); char lvl[32]; sprintf(lvl, "%d", atoi(level) / 10 - 1); writevaproc(lvl, "/proc/switch/eth0/port/%d/prio", loop); } } #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif return 0; }
void ej_get_firmware_version(webs_t wp, int argc, char_t ** argv) { #if defined(HAVE_ESPOD) || defined(HAVE_ONNET) || defined(HAVE_IMMERSIVE) || defined(HAVE_HDWIFI) char *p; char string[32], date[16]; sprintf(string, CYBERTAN_VERSION); p = strtok(string, "("); if (p != NULL) { p = strtok(NULL, ")"); if (p != NULL) { sprintf(date, "%s", p); } } #endif #ifdef HAVE_BUFFALO websWrite(wp, "%s%s %s%s", CYBERTAN_VERSION, MINOR_VERSION, nvram_safe_get("dist_type"), DIST_OPT); #else #ifdef HAVE_REGISTER if (isregistered() && !isregistered_real()) { websWrite(wp, "Click here to ACTIVATE %d Hour Trial", getTrialCount()); } else #endif { #ifdef HAVE_WIKINGS #ifdef HAVE_SUB3 #define V "ExcelMed" #elif HAVE_SUB6 #define V "ExcelMin" #else #define V "Excellent" #endif websWrite(wp, "Excel Networks (%s series) V 2.10", V); #undef V #elif HAVE_ESPOD #ifdef HAVE_SUB3 #define V "A600" #elif HAVE_SUB6 #define V "A1000" #else #define V "MIMO" #endif if (argc == 2) { websWrite(wp, "ESPOD v1.0611 (%s) / ESPOD %s Series", date, V); } else { websWrite(wp, "ESPOD v1.0611 (%s)</a><div>\");document.write(\"<div class=\\\"info\\\">Device: ESPOD %s Series<a>", date, V); } #undef V #elif HAVE_CARLSONWIRELESS websWrite(wp, "Carlson Wireless v5.3 (%s)", SVN_REVISION); #elif HAVE_IMMERSIVE if (argc == 2) { websWrite(wp, "Build date %s", date); } else { websWrite(wp, "SUPPORT %s (%s)", SVN_REVISION, date); } #elif HAVE_HDWIFI if (argc == 2) { websWrite(wp, "Build date %s", date); } else { websWrite(wp, "HDWIFI r%s (%s)", SVN_REVISION, date); } #elif HAVE_IPR websWrite(wp, "IPR-CP v1.0 (%s)", SVN_REVISION); #elif HAVE_ONNET_BLANK websWrite(wp, "Enterprise AP (%s)", date); #elif HAVE_ONNET if (nvram_match("DD_BOARD", "Atheros Hornet")) { websWrite(wp, "OTAi 9331 (%s)", date); } else if (nvram_match("DD_BOARD", "Compex WPE72")) { websWrite(wp, "OTAi 724 (%s)", date); } else if (nvram_match("DD_BOARD", "ACCTON AC622")) { if (iscpe()) { websWrite(wp, "OTAi 724S (%s)", date); } else { websWrite(wp, "OTAi 724AP (%s)", date); } } else if (nvram_match("DD_BOARD", "ACCTON AC722")) { if (iscpe()) { websWrite(wp, "OTAi 724S (%s)", date); } else { websWrite(wp, "OTAi 724AP (%s)", date); } } else if (nvram_match("DD_BOARD", "Compex WP546")) { websWrite(wp, "OTAi 724S (%s)", date); } else { websWrite(wp, "OTAi %s (%s)", nvram_get("DD_BOARD"), date); } #elif HAVE_KORENRON websWrite(wp, "KORENRON %s %s%s", MINOR_VERSION, nvram_safe_get("dist_type"), DIST_OPT); #elif HAVE_SANSFIL websWrite(wp, "SANSFIL %s %s%s", MINOR_VERSION, nvram_safe_get("dist_type"), DIST_OPT); #else websWrite(wp, "%s%s %s%s", CYBERTAN_VERSION, MINOR_VERSION, nvram_safe_get("dist_type"), DIST_OPT); #endif } #endif }