// only ralink solution can reload it dynamically void reinit_hwnat() { // only happened when hwnat=1 // only loaded when unloaded, and unloaded when loaded // in restart_firewall for fw_pt_l2tp/fw_pt_ipsec // in restart_qos for qos_enable // in restart_wireless for wlx_mrate_x if (nvram_get_int("hwnat")) { if (is_nat_enabled() && !nvram_get_int("qos_enable") /*&&*/ /* TODO: consider RTCONFIG_DUALWAN case */ // !nvram_match("wan0_proto", "l2tp") && // !nvram_match("wan0_proto", "pptp") && /*(nvram_match("wl0_radio", "0") || !nvram_get_int("wl0_mrate_x")) && (nvram_match("wl1_radio", "0") || !nvram_get_int("wl1_mrate_x"))*/) { if (!is_module_loaded("hw_nat")) { #if 0 system("echo 2 > /proc/sys/net/ipv4/conf/default/force_igmp_version"); system("echo 2 > /proc/sys/net/ipv4/conf/all/force_igmp_version"); #endif modprobe("hw_nat"); sleep(1); } } else if (is_module_loaded("hw_nat")) { modprobe_r("hw_nat"); sleep(1); #if 0 system("echo 0 > /proc/sys/net/ipv4/conf/default/force_igmp_version"); system("echo 0 > /proc/sys/net/ipv4/conf/all/force_igmp_version"); #endif } } }
void stop_jffs2(int stop) { struct statfs sf; #if defined(RTCONFIG_PSISTLOG) || defined(RTCONFIG_JFFS2LOG) int restart_syslogd = 0; #endif if (!wait_action_idle(10)) return; if ((statfs("/jffs", &sf) == 0) && (sf.f_type != 0x73717368) && (sf.f_type != 0x71736873)) { // is mounted run_userfile("/jffs", ".autostop", "/jffs", 5); run_nvscript("script_autostop", "/jffs", 5); } #if defined(RTCONFIG_PSISTLOG) || defined(RTCONFIG_JFFS2LOG) if (!stop && !strncmp(get_syslog_fname(0), "/jffs/", 6)) { restart_syslogd = 1; stop_syslogd(); eval("cp", "/jffs/syslog.log", "/jffs/syslog.log-1", "/tmp"); } #endif notice_set("jffs", "Stopped"); if (umount("/jffs")) umount2("/jffs", MNT_DETACH); else modprobe_r(JFFS_NAME); #if defined(RTCONFIG_PSISTLOG) || defined(RTCONFIG_JFFS2LOG) if (restart_syslogd) start_syslogd(); #endif }
void fini_wl(void) { if (is_module_loaded("hw_nat")) modprobe_r("hw_nat"); #if defined (RTCONFIG_WLMODULE_RT3352_INIC_MII) if (is_module_loaded("iNIC_mii")) modprobe_r("iNIC_mii"); #endif #if defined (RTCONFIG_WLMODULE_RT3090_AP) if (is_module_loaded("RTPCI_ap")) { modprobe_r("RTPCI_ap"); } #endif if (is_module_loaded("rt2860v2_ap")) modprobe_r("rt2860v2_ap"); }
void stop_jffs2(void) { struct statfs sf; if (!wait_action_idle(10)) return; if ((statfs("/jffs", &sf) == 0) && (sf.f_type != 0x71736873)) { // is mounted run_userfile("/jffs", ".autostop", "/jffs", 5); run_nvscript("script_autostop", "/jffs", 5); } notice_set("jffs", "Stopped"); umount2("/jffs", MNT_DETACH); modprobe_r(JFFS_NAME); }
// only ralink solution can reload it dynamically void reinit_hwnat() { // only happened when hwnat=1 // only loaded when unloaded, and unloaded when loaded // in restart_firewall for fw_pt_l2tp/fw_pt_ipsec // in restart_qos for qos_enable // in restart_wireless for wlx_mrate_x if (nvram_get_int("hwnat")) { if (is_nat_enabled() && !nvram_get_int("qos_enable") /*&&*/ /* TODO: consider RTCONFIG_DUALWAN case */ // !nvram_match("wan0_proto", "l2tp") && // !nvram_match("wan0_proto", "pptp") && /*(nvram_match("wl0_radio", "0") || !nvram_get_int("wl0_mrate_x")) && (nvram_match("wl1_radio", "0") || !nvram_get_int("wl1_mrate_x"))*/) { #if !defined(RTCONFIG_DUALWAN) #if defined(RTN65U) || defined(RTN56U) char primary[] = "wan1_primaryXXXXXX"; sprintf(primary, "wan%d_primary", WAN_UNIT_SECOND); if (nvram_match(primary, "1")) { _dprintf("%s: don't install hardware NAT driver if 3G is enabled!\n", __func__); return; } #endif #endif if (!module_loaded("hw_nat")) { #if 0 system("echo 2 > /proc/sys/net/ipv4/conf/default/force_igmp_version"); system("echo 2 > /proc/sys/net/ipv4/conf/all/force_igmp_version"); #endif modprobe("hw_nat"); sleep(1); } } else if (module_loaded("hw_nat")) { modprobe_r("hw_nat"); sleep(1); #if 0 system("echo 0 > /proc/sys/net/ipv4/conf/default/force_igmp_version"); system("echo 0 > /proc/sys/net/ipv4/conf/all/force_igmp_version"); #endif } } }
int asus_ate_command(const char *command, const char *value, const char *value2) { _dprintf("===[ATE %s %s]===\n", command, value); #ifdef RTCONFIG_QTN if(!nvram_match("qtn_ready", "1")){ _dprintf("ATE Error: wireless 5G not ready\n"); return 0; } #endif /*** ATE Set function ***/ if(!strcmp(command, "Set_StartATEMode")) { nvram_set("asus_mfg", "1"); if(nvram_match("asus_mfg", "1")) { puts("1"); #ifdef RTCONFIG_FANCTRL stop_phy_tempsense(); #endif stop_wpsaide(); stop_wps(); #ifdef RTCONFIG_BCMWL6 stop_igmp_proxy(); #ifdef RTCONFIG_HSPOT stop_hspotap(); #endif stop_acsd(); #ifdef BCM_BSD stop_bsd(); #endif #ifdef BCM_SSD stop_ssd(); #endif #endif stop_upnp(); stop_lltd(); stop_rstats(); stop_wanduck(); stop_logger(); stop_wanduck(); stop_dnsmasq(0); stop_ots(); stop_networkmap(); #ifdef RTCONFIG_USB stop_usbled(); #ifdef RTCONFIG_USB_PRINTER stop_lpd(); stop_u2ec(); #endif #endif platform_start_ate_mode(); } else puts("ATE_ERROR"); return 0; } else if (!strcmp(command, "Set_AllLedOn")) { return setAllLedOn(); } else if (!strcmp(command, "Set_AllLedOn2")) { return setAllLedOn2(); } else if (!strcmp(command, "Set_AllLedOff")) { return setAllLedOff(); } else if (!strcmp(command, "Set_AllLedOn_Half")) { puts("ATE_ERROR"); //Need to implement for EA-N66U return EINVAL; } #ifdef RTCONFIG_BCMARM else if (!strcmp(command, "Set_AteModeLedOn")) { return setATEModeLedOn(); } #endif else if (!strcmp(command, "Set_MacAddr_2G")) { if( !setMAC_2G(value) ) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Set_MacAddr_5G")) { #ifdef RTCONFIG_QTN if( !setMAC_5G_qtn(value)) #else if( !setMAC_5G(value)) #endif { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } #ifdef RTAC3200 else if (!strcmp(command, "Set_MacAddr_5G_2")) { if( !setMAC_5G_2(value)) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } #endif #endif /* RTCONFIG_HAS_5G */ #if defined(RTN14U) else if (!strcmp(command, "eeprom")) { if ( !eeprom_upgrade(value, 1)) return EINVAL; return 0; } else if (!strcmp(command, "eeover")) { if ( !eeprom_upgrade(value, 0)) return EINVAL; return 0; } #endif #if defined(RTCONFIG_NEW_REGULATION_DOMAIN) else if (!strcmp(command, "Set_RegSpec")) { if (setRegSpec(value) < 0) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } getRegSpec(); return 0; } else if (!strcmp(command, "Set_RegulationDomain_2G")) { if (setRegDomain_2G(value) == -1) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } getRegDomain_2G(); return 0; } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Set_RegulationDomain_5G")) { if (setRegDomain_5G(value) == -1) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } getRegDomain_5G(); return 0; } #endif /* RTCONFIG_HAS_5G */ #else /* ! RTCONFIG_NEW_REGULATION_DOMAIN */ else if (!strcmp(command, "Set_RegulationDomain_2G")) { if ( !setCountryCode_2G(value)) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } #ifdef RTCONFIG_QCA if ((value2==NULL) || strcmp(value2,"noctl")) setCTL(value); #endif return 0; } #endif /* RTCONFIG_NEW_REGULATION_DOMAIN */ #ifdef CONFIG_BCMWL5 else if (!strcmp(command, "Set_RegulationDomain_5G")) { #ifdef RTCONFIG_QTN if ( !setCountryCode_5G_qtn(value)) #else if ( !setCountryCode_5G(value)) #endif { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } else if (!strcmp(command, "Set_Regrev_2G")) { if( !setRegrev_2G(value) ) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } else if (!strcmp(command, "Set_Regrev_5G")) { #ifdef RTCONFIG_QTN if( !setRegrev_5G_qtn(value)) #else if( !setRegrev_5G(value)) #endif { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } else if (!strcmp(command, "Set_Commit")) { setCommit(); return 0; } #endif #if defined(RTN14U) else if (!strcmp(command, "pkt_flood")) { if (nvram_invmatch("asus_mfg", "0")) { #if 0 // TBD struct sockaddr_ll dev,dev2; int fd,fd2,do_flag=3; unsigned char buffer[1514]; fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); dev.sll_family = AF_PACKET; dev.sll_protocol = htons(ETH_P_ALL); dev.sll_ifindex = 4; // LAN bind( fd, (struct sockaddr *) &dev, sizeof(dev)); fd2 = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); dev2.sll_family = AF_PACKET; dev2.sll_protocol = htons(ETH_P_ALL); dev2.sll_ifindex = 5; // WAN bind( fd2, (struct sockaddr *) &dev2, sizeof(dev2)); if (value) { if(strcmp(value,"WAN")==0) do_flag = 2; else if(strcmp(value,"LAN")==0) do_flag = 1; } memset(buffer,0xff,6); FRead(buffer+6, OFFSET_MAC_ADDR_2G, 6); memset(buffer+12,0x55,1502); while(1) { if (do_flag & 1) send( fd, buffer, 1514, 0); if (do_flag & 2) send( fd2, buffer, 1514, 0); } #endif } return 0; } #endif else if (!strcmp(command, "Set_SerialNumber")) { if(!setSN(value)) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } #ifdef RTCONFIG_ODMPID else if (!strcmp(command, "Set_ModelName")) { if(!setMN(value)) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } #endif else if (!strcmp(command, "Set_PINCode")) { if (!setPIN(value)) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } else if (!strcmp(command, "Set_40M_Channel_2G")) { if(!set40M_Channel_2G((char*)value)) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Set_40M_Channel_5G")) { if(!set40M_Channel_5G((char*)value)) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } #endif /* RTCONFIG_HAS_5G */ else if (!strcmp(command, "Set_RestoreDefault")) { nvram_set("restore_defaults", "1"); ResetDefault(); nvram_set(ASUS_STOP_COMMIT, "1"); return 0; } else if (!strcmp(command, "Set_Eject")) { if( !Ej_device(value)) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } #ifdef RTCONFIG_FANCTRL else if (!strcmp(command, "Set_FanOn")) { setFanOn(); return 0; } else if (!strcmp(command, "Set_FanOff")) { setFanOff(); return 0; } #endif #ifdef CONFIG_BCMWL5 else if (!strcmp(command, "Set_WaitTime")) { if( !setWaitTime(value) ) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } else if (!strcmp(command, "Set_WiFi_2G")) { if( !setWiFi2G(value) ) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Set_WiFi_5G")) { if( !setWiFi5G(value) ) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } #endif /* RTCONFIG_HAS_5G */ #endif #ifdef RTCONFIG_RALINK else if (!strcmp(command, "Set_DevFlags")) { if( Set_Device_Flags(value) < 0 ) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } return 0; } else if (!strcmp(command, "Set_WanToLan")) { set_wantolan(); modprobe_r("hw_nat"); modprobe("hw_nat"); system("killall -9 wanduck"); system("killall -9 udhcpc"); return 0; } #if defined(RTAC1200HP) || defined(RTN56UB1) else if (!strcmp(command, "Set_FixChannel")) { FWrite("1", OFFSET_FIX_CHANNEL, 1); puts("1"); return 0; } else if (!strcmp(command, "Set_FreeChannel")) { FWrite("0", OFFSET_FIX_CHANNEL, 1); nvram_set("wl0_channel","0"); nvram_set("wl1_channel","0"); nvram_set("lan_stp","1"); nvram_commit(); puts("1"); return 0; } #endif #endif else if (!strcmp(command, "Set_XSetting")) { if(value == NULL || strcmp(value, "1")) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } else { nvram_set("x_Setting", "1"); puts(nvram_get("x_Setting")); } return 0; } /*** ATE Get functions ***/ else if (!strcmp(command, "Get_FWVersion")) { char fwver[12]; sprintf(fwver, "%s.%s", nvram_safe_get("firmver"), nvram_safe_get("buildno")); puts(fwver); return 0; } else if (!strcmp(command, "Get_BootLoaderVersion")) { getBootVer(); return 0; } else if (!strcmp(command, "Get_ResetButtonStatus")) { puts(nvram_safe_get("btn_rst")); return 0; } else if (!strcmp(command, "Get_WpsButtonStatus")) { puts(nvram_safe_get("btn_ez")); return 0; } #ifdef RT4GAC55U else if (!strcmp(command, "Get_LteButtonStatus")) { puts(nvram_safe_get("btn_lte")); return 0; } #endif #ifdef RTCONFIG_WIFI_TOG_BTN else if (!strcmp(command, "Get_WirelessButtonStatus")) { puts(nvram_safe_get("btn_wifi_toggle")); return 0; } #endif else if (!strcmp(command, "Get_SWMode")) { puts(nvram_safe_get("sw_mode")); return 0; } else if (!strcmp(command, "Get_MacAddr_2G")) { getMAC_2G(); return 0; } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Get_MacAddr_5G")) { #ifdef RTCONFIG_QTN getMAC_5G_qtn(); #else getMAC_5G(); #endif return 0; } #ifdef RTAC3200 else if (!strcmp(command, "Get_MacAddr_5G_2")) { getMAC_5G_2(); return 0; } #endif #endif /* RTCONFIG_HAS_5G */ else if (!strcmp(command, "Get_Usb2p0_Port1_Infor")) { Get_USB_Port_Info("1"); return 0; } else if (!strcmp(command, "Get_Usb2p0_Port1_Folder")) { Get_USB_Port_Folder("1"); return 0; } else if (!strcmp(command, "Get_Usb2p0_Port2_Infor")) { Get_USB_Port_Info("2"); return 0; } else if (!strcmp(command, "Get_Usb2p0_Port2_Folder")) { Get_USB_Port_Folder("2"); return 0; } else if (!strcmp(command, "Get_SD_Infor")) { Get_SD_Card_Info(); return 0; } else if (!strcmp(command, "Get_SD_Folder")) { Get_SD_Card_Folder(); return 0; } #if defined(RTCONFIG_NEW_REGULATION_DOMAIN) else if (!strcmp(command, "Get_RegSpec")) { getRegSpec(); return 0; } else if (!strcmp(command, "Get_RegulationDomain_2G")) { getRegDomain_2G(); return 0; } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Get_RegulationDomain_5G")) { getRegDomain_5G(); return 0; } #endif /* RTCONFIG_HAS_5G */ #else /* ! RTCONFIG_NEW_REGULATION_DOMAIN */ else if (!strcmp(command, "Get_RegulationDomain_2G")) { getCountryCode_2G(); return 0; } #endif /* ! RTCONFIG_NEW_REGULATION_DOMAIN */ #ifdef CONFIG_BCMWL5 else if (!strcmp(command, "Get_RegulationDomain_5G")) { #ifdef RTCONFIG_QTN getCountryCode_5G_qtn(); #else getCountryCode_5G(); #endif return 0; } else if (!strcmp(command, "Get_Regrev_2G")) { getRegrev_2G(); return 0; } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Get_Regrev_5G")) { #ifdef RTCONFIG_QTN getRegrev_5G_qtn(); #else getRegrev_5G(); #endif return 0; } #endif /* RTCONFIG_HAS_5G */ #endif else if (!strcmp(command, "Get_SerialNumber")) { getSN(); return 0; } #ifdef RTCONFIG_ODMPID else if (!strcmp(command, "Get_ModelName")) { getMN(); return 0; } #endif else if (!strcmp(command, "Get_PINCode")) { getPIN(); return 0; } else if (!strcmp(command, "Get_WanLanStatus")) { if( !GetPhyStatus()) puts("ATE_ERROR"); return 0; } else if (!strcmp(command, "Get_FwReadyStatus")) { puts(nvram_safe_get("success_start_service")); return 0; } else if (!strcmp(command, "Get_Build_Info")) { puts(nvram_safe_get("buildinfo")); return 0; } #ifdef RTCONFIG_RALINK else if (!strcmp(command, "Get_RSSI_2G")) { getrssi(0); return 0; } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Get_RSSI_5G")) { getrssi(1); return 0; } #endif /* RTCONFIG_HAS_5G */ #endif else if (!strcmp(command, "Get_ChannelList_2G")) { if(!Get_ChannelList_2G()) puts("ATE_ERROR"); return 0; } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Get_ChannelList_5G")) { #ifdef RTCONFIG_QTN if (!Get_ChannelList_5G_qtn()) #else if (!Get_ChannelList_5G()) #endif puts("ATE_ERROR"); return 0; } #ifdef RTAC3200 else if (!strcmp(command, "Get_ChannelList_5G_2")) { if (!Get_ChannelList_5G_2()) puts("ATE_ERROR"); return 0; } #endif #endif /* RTCONFIG_HAS_5G */ #if defined(RTCONFIG_USB_XHCI) else if (!strcmp(command, "Get_Usb3p0_Port1_Infor")) { if (!Get_USB3_Port_Info("1")) puts("ATE_ERROR"); return 0; } else if (!strcmp(command, "Get_Usb3p0_Port2_Infor")) { if (!Get_USB3_Port_Info("2")) puts("ATE_ERROR"); return 0; } else if (!strcmp(command, "Get_Usb3p0_Port3_Infor")) { puts("ATE_ERROR"); //Need to implement return 0; } else if (!strcmp(command, "Get_Usb3p0_Port1_Folder")) { if (!Get_USB3_Port_Folder("1")) puts("ATE_ERROR"); return 0; } else if (!strcmp(command, "Get_Usb3p0_Port2_Folder")) { if (!Get_USB3_Port_Folder("2")) puts("ATE_ERROR"); return 0; } else if (!strcmp(command, "Get_Usb3p0_Port3_Folder")) { puts("ATE_ERROR"); //Need to implement return EINVAL; } else if (!strcmp(command, "Get_Usb3p0_Port1_DataRate")) { if (!Get_USB3_Port_DataRate("1")) puts("ATE_ERROR"); return 0; } else if (!strcmp(command, "Get_Usb3p0_Port2_DataRate")) { if (!Get_USB3_Port_DataRate("2")) puts("ATE_ERROR"); return 0; } else if (!strcmp(command, "Get_Usb3p0_Port3_DataRate")) { puts("ATE_ERROR"); //Need to implement return EINVAL; } #endif /* RTCONFIG_USB_XHCI */ else if (!strcmp(command, "Get_fail_ret")) { Get_fail_ret(); return 0; } else if (!strcmp(command, "Get_fail_reboot_log")) { Get_fail_reboot_log(); return 0; } else if (!strcmp(command, "Get_fail_dev_log")) { Get_fail_dev_log(); return 0; } #ifdef RTCONFIG_RALINK #if !defined(RTN14U) && !defined(RTAC52U) && !defined(RTAC51U) && !defined(RTN11P) && !defined(RTN54U) && !defined(RTAC1200HP) && !defined(RTN56UB1) && !defined(RTAC54U) else if (!strcmp(command, "Ra_FWRITE")) { return FWRITE(value, value2); } else if (!strcmp(command, "Ra_Asuscfe_2G")) { return asuscfe(value, WIF_2G); } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Ra_Asuscfe_5G")) { return asuscfe(value, WIF_5G); } #endif /* RTCONFIG_HAS_5G */ else if (!strcmp(command, "Set_SwitchPort_LEDs")) { if(Set_SwitchPort_LEDs(value, value2) < 0) { puts("ATE_ERROR"); return EINVAL; } return 0; } #endif #endif #ifdef RTCONFIG_WIRELESS_SWITCH else if (!strcmp(command, "Get_WifiSwStatus")) { puts(nvram_safe_get("btn_wifi_sw")); return 0; } #endif #ifdef RTCONFIG_WIFI_TOG_BTN else if (!strcmp(command, "Get_WifiButtonStatus")) { puts(nvram_safe_get("btn_wifi_toggle")); return 0; } #endif #ifdef RTCONFIG_TURBO else if (!strcmp(command, "Get_Turbo")) { puts(nvram_safe_get("btn_turbo")); return 0; } #endif #ifdef RTCONFIG_LED_BTN else if (!strcmp(command, "Get_LedButtonStatus")) { puts(nvram_safe_get("btn_led")); return 0; } #endif #ifdef RTCONFIG_QTN else if (!strcmp(command, "Enable_Qtn_TelnetSrv")) { enable_qtn_telnetsrv(1); puts("1"); return 0; } else if (!strcmp(command, "Disable_Qtn_TelnetSrv")) { enable_qtn_telnetsrv(0); puts("1"); return 0; } else if (!strcmp(command, "Get_Qtn_TelnetSrv_Status")) { getstatus_qtn_telnetsrv(); return 0; } else if (!strcmp(command, "Del_Qtn_Cal_Files")) { del_qtn_cal_files(); puts("1"); return 0; } #endif #ifdef CONFIG_BCMWL5 else if (!strcmp(command, "Get_WiFiStatus_2G")) { if(!getWiFiStatus("2G")) puts("ATE_ERROR_INCORRECT_PARAMETER"); return 0; } else if (!strcmp(command, "Get_WiFiStatus_5G")) { if(!getWiFiStatus("5G")) puts("ATE_ERROR_INCORRECT_PARAMETER"); return 0; } #else else if (!strcmp(command, "Get_WiFiStatus_2G")) { if(get_radio(0, 0)) puts("1"); else puts("0"); return 0; } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Get_WiFiStatus_5G")) { if(get_radio(1, 0)) puts("1"); else puts("0"); return 0; } #endif /* RTCONFIG_HAS_5G */ #endif else if (!strcmp(command, "Set_WiFiStatus_2G")) { int act = !strcmp(value, "on"); if(!strcmp(value, "on") && !strcmp(value, "off")) puts("ATE_UNSUPPORT"); set_radio(act, 0, 0); if(get_radio(0, 0)){ if(act) puts("success=on"); else puts("ATE_ERROR_INCORRECT_PARAMETER"); } else{ if(!act) puts("success=off"); else puts("ATE_ERROR_INCORRECT_PARAMETER"); } return 0; } #if defined(RTCONFIG_HAS_5G) else if (!strcmp(command, "Set_WiFiStatus_5G")) { int act = !strcmp(value, "on"); if(!strcmp(value, "on") && !strcmp(value, "off")) puts("ATE_UNSUPPORT"); set_radio(act, 1, 0); if(get_radio(1, 0)){ if(act) puts("success=on"); else puts("ATE_ERROR_INCORRECT_PARAMETER"); } else{ if(!act) puts("success=off"); else puts("ATE_ERROR_INCORRECT_PARAMETER"); } return 0; } #endif /* RTCONFIG_HAS_5G */ else if (!strcmp(command, "Get_ATEVersion")) { puts(nvram_safe_get("Ate_version")); return 0; } else if (!strcmp(command, "Get_XSetting")) { puts(nvram_safe_get("x_Setting")); return 0; } else if (!strcmp(command, "Get_WaitTime")) { puts(nvram_safe_get("wait_time")); return 0; } else if (!strcmp(command, "Get_ExtendNo")) { puts(nvram_safe_get("extendno")); return 0; } #ifdef RTCONFIG_RALINK else if (!strcmp(command, "Get_DevFlags")) { if( Get_Device_Flags() < 0) { puts("ATE_ERROR"); return EINVAL; } return 0; } #endif #ifdef RTCONFIG_QCA /* else if (!strcmp(command, "Set_ART2")) { // temp solution system("killall rstats"); system("killall udhcpc"); system("killall wanduck"); system("killall networkmap"); system("killall -9 hostapd"); system("ifconfig ath0 down"); system("ifconfig ath1 down"); system("killall -9 hostapd"); system("brctl delif br0 ath0"); system("brctl delif br0 ath1"); system("wlanconfig ath0 destroy"); system("wlanconfig ath1 destroy"); system("ifconfig wifi0 down"); system("ifconfig wifi1 down"); modprobe_r("umac"); modprobe_r("ath_dfs"); modprobe_r("ath_dev"); modprobe_r("ath_rate_atheros"); modprobe_r("ath_spectral"); modprobe_r("ath_hal"); modprobe_r("adf"); modprobe_r("asf"); modprobe("art"); system("nart.out -port 2390 -console &"); system("nart.out -port 2391 -console &"); return 0; } */ else if (!strncmp(command, "Get_EEPROM_", 11)) { unsigned char buffer[2560]; unsigned short len; int lret; char *pt; len=sizeof(buffer); pt = (char*) command + 11; if (!strcmp(pt, "2G")) lret=getEEPROM(&buffer[0], &len, pt); else if (!strcmp(pt, "5G")) lret=getEEPROM(&buffer[0], &len, pt); else if (!strcmp(pt, "CAL_2G")) lret=getEEPROM(&buffer[0], &len, pt); else if (!strcmp(pt, "CAL_5G")) lret=getEEPROM(&buffer[0], &len, pt); else { puts("ATE_UNSUPPORT"); return EINVAL; } if ( !lret ) hexdump(&buffer[0], len); return 0; } else if (!strcmp(command, "Get_CalCompare")) { unsigned char buffer[2560], buffer2[2560]; unsigned short len, len2; int lret=0, cret=0; len=sizeof(buffer); len2=sizeof(buffer2); lret+=getEEPROM(&buffer[0], &len, "2G"); lret+=getEEPROM(&buffer2[0], &len2, "CAL_2G"); if (lret) return EINVAL; if ((len!=len2) || (memcmp(&buffer[0],&buffer2[0],len)!=0)) { puts("2G EEPROM different!"); cret++; } len=sizeof(buffer); len2=sizeof(buffer2); lret+=getEEPROM(&buffer[0], &len, "5G"); lret+=getEEPROM(&buffer2[0], &len2, "CAL_5G"); if (lret) return EINVAL; if ((len!=len2) || (memcmp(&buffer[0],&buffer2[0],len)!=0)) { puts("5G EEPROM different!"); cret++; } if (!cret) puts("1"); else puts("0"); return 0; } #ifdef RTCONFIG_ATEUSB3_FORCE else if (!strcmp(command, "Set_ForceUSB3")) { if (setForceU3(value) < 0) { puts("ATE_ERROR_INCORRECT_PARAMETER"); return EINVAL; } getForceU3(); return 0; } else if (!strcmp(command, "Get_ForceUSB3")) { getForceU3(); return 0; } #endif #endif /* RTCONFIG_QCA */ #ifdef RT4GAC55U else if(!strcmp(command, "Get_GobiSimCard")) { char line[128]; if (!Gobi_SimCardReady(Gobi_SimCard(line, sizeof(line)))) { puts("FAIL"); return EINVAL; } puts("PASS"); } else if(!strcmp(command, "Get_GobiIMEI")) { char line[128]; const char *IMEI = Gobi_IMEI(line, sizeof(line)); if (IMEI == NULL) { puts("FAIL"); return EINVAL; } puts(IMEI); } else if(!strcmp(command, "Get_GobiConnectISP")) { char line[128]; const char *ISP = Gobi_ConnectISP(line, sizeof(line)); if (ISP == NULL) { puts("FAIL"); return EINVAL; } puts(ISP); } else if(!strcmp(command, "Get_GobiConnectStatus")) { const char *status = Gobi_ConnectStatus_Str(Gobi_ConnectStatus_Int()); if (status == NULL) { puts("FAIL"); return EINVAL; } puts(status); } else if(!strcmp(command, "Get_GobiSignal_Percent")) { int percent = Gobi_SignalQuality_Percent(Gobi_SignalQuality_Int()); if (percent < 0) { puts("FAIL"); return EINVAL; } printf("%d\n", percent); } else if(!strcmp(command, "Get_GobiSignal_dbm")) { int dbm = Gobi_SignalLevel_Int(); if (dbm >= 0) { puts("FAIL"); return EINVAL; } printf("%d dBm\n", dbm); } else if(!strcmp(command, "Get_GobiVersion")) { char line[128]; if (Gobi_Version(line, sizeof(line)) == NULL) { puts("FAIL"); return EINVAL; } printf("%s\n", line); } #endif /* RT4GAC55U */ else { puts("ATE_UNSUPPORT"); return EINVAL; } return 0; }
void start_qos(void) { int i; char *buf, *g, *p, *qos; unsigned int rate; unsigned int ceil; unsigned int bw; unsigned int incomingBandwidthInKilobitsPerSecond; unsigned int mtu; unsigned int r2q; unsigned int qosDefaultClassId; unsigned int overhead; FILE *f; int x; int inuse; char s[256]; int first; char burst_root[32]; char burst_leaf[32]; qosDefaultClassId = (nvram_get_int("qos_default") + 1) * 10; incomingBandwidthInKilobitsPerSecond = strtoul(nvram_safe_get("qos_ibw"), NULL, 10); // move me? x = nvram_get_int("ne_vegas"); #ifdef LINUX26 if (x) { char alpha[10], beta[10], gamma[10]; sprintf(alpha, "alpha=%d", nvram_get_int("ne_valpha")); sprintf(beta, "beta=%d", nvram_get_int("ne_vbeta")); sprintf(gamma, "gamma=%d", nvram_get_int("ne_vgamma")); modprobe("tcp_vegas", alpha, beta, gamma); f_write_string("/proc/sys/net/ipv4/tcp_congestion_control", "vegas", 0, 0); } else { modprobe_r("tcp_vegas"); f_write_string("/proc/sys/net/ipv4/tcp_congestion_control", "cubic", FW_NEWLINE, 0); } #else f_write_string("/proc/sys/net/ipv4/tcp_vegas_cong_avoid", x ? "1" : "0", 0, 0); if (x) { f_write_string("/proc/sys/net/ipv4/tcp_vegas_alpha", nvram_safe_get("ne_valpha"), 0, 0); f_write_string("/proc/sys/net/ipv4/tcp_vegas_beta", nvram_safe_get("ne_vbeta"), 0, 0); f_write_string("/proc/sys/net/ipv4/tcp_vegas_gamma", nvram_safe_get("ne_vgamma"), 0, 0); } #endif if (!nvram_get_int("qos_enable")) return; if ((f = fopen(qosfn, "w")) == NULL) return; i = nvram_get_int("qos_burst0"); if (i > 0) sprintf(burst_root, "burst %dk", i); else burst_root[0] = 0; i = nvram_get_int("qos_burst1"); if (i > 0) sprintf(burst_leaf, "burst %dk", i); else burst_leaf[0] = 0; mtu = strtoul(nvram_safe_get("wan_mtu"), NULL, 10); bw = strtoul(nvram_safe_get("qos_obw"), NULL, 10); overhead = strtoul(nvram_safe_get("atm_overhead"), NULL, 10); r2q = 10; if ((bw * 1000) / (8 * r2q) < mtu) { r2q = (bw * 1000) / (8 * mtu); if (r2q < 1) r2q = 1; } else if ((bw * 1000) / (8 * r2q) > 60000) { r2q = (bw * 1000) / (8 * 60000) + 1; } x = nvram_get_int("qos_pfifo"); if (x == 1) { qos = "pfifo limit 256"; } else if (x == 2) { qos = "codel"; } else if (x == 3) { qos = "fq_codel"; } else { qos = "sfq perturb 10"; } if (overhead == 0) { fprintf(f, "#!/bin/sh\n" "WAN_DEV=%s\n" "IMQ_DEV=%s\n" "TQA=\"tc qdisc add dev $WAN_DEV\"\n" "TCA=\"tc class add dev $WAN_DEV\"\n" "TFA=\"tc filter add dev $WAN_DEV\"\n" "TQA_IMQ=\"tc qdisc add dev $IMQ_DEV\"\n" "TCA_IMQ=\"tc class add dev $IMQ_DEV\"\n" "TFA_IMQ=\"tc filter add dev $IMQ_DEV\"\n" "Q=\"%s\"\n" "\n" "case \"$1\" in\n" "start)\n" "\ttc qdisc del dev $WAN_DEV root 2>/dev/null\n" "\t$TQA root handle 1: htb default %u r2q %u\n" "\t$TCA parent 1: classid 1:1 htb rate %ukbit ceil %ukbit %s\n", get_wanface(), qosImqDeviceString, qos, qosDefaultClassId, r2q, bw, bw, burst_root); } else { fprintf(f, "#!/bin/sh\n" "WAN_DEV=%s\n" "IMQ_DEV=%s\n" "TQA=\"tc qdisc add dev $WAN_DEV\"\n" "TCA=\"tc class add dev $WAN_DEV\"\n" "TFA=\"tc filter add dev $WAN_DEV\"\n" "TQA_IMQ=\"tc qdisc add dev $IMQ_DEV\"\n" "TCA_IMQ=\"tc class add dev $IMQ_DEV\"\n" "TFA_IMQ=\"tc filter add dev $IMQ_DEV\"\n" "Q=\"%s\"\n" "\n" "case \"$1\" in\n" "start)\n" "\ttc qdisc del dev $WAN_DEV root 2>/dev/null\n" "\t$TQA root handle 1: htb default %u r2q %u\n" "\t$TCA parent 1: classid 1:1 htb rate %ukbit ceil %ukbit %s overhead %u linklayer atm\n", get_wanface(), qosImqDeviceString, qos, qosDefaultClassId, r2q, bw, bw, burst_root, overhead); } inuse = nvram_get_int("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; // check if we've got a percentage definition in the form of "rate-ceiling" if ((sscanf(p, "%u-%u", &rate, &ceil) != 2) || (rate < 1)) continue; // 0=off if (ceil > 0) sprintf(s, "ceil %ukbit ", calc(bw, ceil)); else s[0] = 0; x = (i + 1) * 10; if (overhead == 0) { 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: $Q\n" "\t$TFA parent 1: prio %d handle %d fw flowid 1:%d\n", i, rate, ceil, x, calc(bw, rate), s, burst_leaf, i+1, mtu, x, x, x, i + 1, x); } else { fprintf(f, "# egress %d: %u-%u%%\n" "\t$TCA parent 1:1 classid 1:%d htb rate %ukbit %s %s prio %d quantum %u overhead %u linklayer atm\n" "\t$TQA parent 1:%d handle %d: $Q\n" "\t$TFA parent 1: prio %d handle %d fw flowid 1:%d\n", i, rate, ceil, x, calc(bw, rate), s, burst_leaf, i+1, mtu, overhead, x, x, x, i + 1, x); } } free(buf); // "\t$TFA parent 1: prio 10 protocol ip u32 match ip tos 0x10 0xff flowid :10\n" // TOS EF -> Highest /* 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); } */ /* if (nvram_get_int("qos_ack")) { 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 0xff80 at 2 " // total length (0-127) "match u8 0x10 0xff at 33 " // ACK only "flowid 1:10\n"); } if (nvram_get_int("qos_syn")) { // 10000 = ACK // 00010 = SYN 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 0xff80 at 2 " // total length (0-127) "match u8 0x02 0xff at 33 " // SYN only "flowid 1:10\n" "\n" "\t$TFA parent 1: prio 16 protocol ip u32 " "match ip protocol 6 0xff " // TCP "match u8 0x05 0x0f at 0 " // IP header length "match u16 0x0000 0xff80 at 2 " // total length (0-127) "match u8 0x12 0xff at 33 " // SYN,ACK "flowid 1:10\n"); } if (nvram_get_int("qos_fin")) { // 10000 = ACK // 00001 = FIN 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 u8 0x11 0xff at 33 " // ACK,FIN "flowid 1:10\n" "\n" "\t$TFA parent 1: prio 18 protocol ip u32 " "match ip protocol 6 0xff " // TCP "match u8 0x05 0x0f at 0 " // IP header length "match u8 0x01 0xff at 33 " // FIN "flowid 1:10\n"); } if (nvram_get_int("qos_rst")) { // 10000 = ACK // 00100 = RST 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 u8 0x14 0xff at 33 " // ACK,RST "flowid 1:10\n" "\n" "\t$TFA parent 1: prio 20 protocol ip u32 " "match ip protocol 6 0xff " // TCP "match u8 0x05 0x0f at 0 " // IP header length "match u8 0x04 0xff at 33 " // RST "flowid 1:10\n"); } if (nvram_get_int("qos_icmp")) { fputs("\n\t$TFA parent 1: prio 13 protocol ip u32 match ip protocol 1 0xff flowid 1:10\n", f); } */ /* 10000 = ACK 00100 = RST 00010 = SYN 00001 = FIN */ if (nvram_get_int("qos_ack")) { fprintf(f, "\n" "\t$TFA parent 1: prio 14 u32 " "match ip protocol 6 0xff " // TCP "match u8 0x05 0x0f at 0 " // IP header length // "match u16 0x0000 0xff80 at 2 " // total length (0-127) "match u16 0x0000 0xffc0 at 2 " // total length (0-63) "match u8 0x10 0xff at 33 " // ACK only "flowid 1:10\n"); } if (nvram_get_int("qos_syn")) { fprintf(f, "\n" "\t$TFA parent 1: prio 15 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_get_int("qos_fin")) { fprintf(f, "\n" "\t$TFA parent 1: prio 17 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_get_int("qos_rst")) { fprintf(f, "\n" "\t$TFA parent 1: prio 19 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_get_int("qos_icmp")) { fputs("\n\t$TFA parent 1: prio 13 u32 match ip protocol 1 0xff flowid 1:10\n", f); } //// //// INCOMING TRAFFIC SHAPING //// first = 1; overhead = strtoul(nvram_safe_get("atm_overhead"), NULL, 10); 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; } // check if we've got a percentage definition in the form of "rate-ceiling" if ((sscanf(p, "%u-%u", &rate, &ceil) != 2) || (rate < 1)) { continue; // 0=off } // class ID unsigned int classid = ((unsigned int)i + 1) * 10; // priority unsigned int priority = (unsigned int)i + 1; //prios 1-10 - Toastman // rate in kb/s unsigned int rateInKilobitsPerSecond = calc(incomingBandwidthInKilobitsPerSecond, rate); // ceiling in kb/s unsigned int ceilingInKilobitsPerSecond = calc(incomingBandwidthInKilobitsPerSecond, ceil); // burst rate (2% of the classes' rate) - don't know if we should use this //Commented out KDB 20130531 - produces compiler warning about being unused! // unsigned int burstRateInBitsPerSecond = // (rateInKilobitsPerSecond * 1000) / 50; r2q = 10; if ((incomingBandwidthInKilobitsPerSecond * 1000) / (8 * r2q) < mtu) { r2q = (incomingBandwidthInKilobitsPerSecond * 1000) / (8 * mtu); if (r2q < 1) r2q = 1; } else if ((incomingBandwidthInKilobitsPerSecond * 1000) / (8 * r2q) > 60000) { r2q = (incomingBandwidthInKilobitsPerSecond * 1000) / (8 * 60000) + 1; } if (first) { first = 0; fprintf(f, "\n" "\ttc qdisc del dev $I ingress 2>/dev/null\n" "\t$TQA handle ffff: ingress\n"); if (overhead == 0) { fprintf(f, "\n" "\tip link set $IMQ_DEV up\n" "\ttc qdisc del dev $IMQ_DEV 2>/dev/null\n" "\t$TQA_IMQ handle 1: root htb default %u r2q %u\n" "\t$TCA_IMQ parent 1: classid 1:1 htb rate %ukbit ceil %ukbit\n", qosDefaultClassId, r2q, incomingBandwidthInKilobitsPerSecond, incomingBandwidthInKilobitsPerSecond); } else { fprintf(f, "\n" "\tip link set $IMQ_DEV up\n" "\ttc qdisc del dev $IMQ_DEV 2>/dev/null\n" "\t$TQA_IMQ handle 1: root htb default %u r2q %u\n" "\t$TCA_IMQ parent 1: classid 1:1 htb rate %ukbit ceil %ukbit overhead %u linklayer atm\n", qosDefaultClassId, r2q, incomingBandwidthInKilobitsPerSecond, incomingBandwidthInKilobitsPerSecond, overhead); } fprintf(f, "\n" "\t$TFA parent ffff: prio 10 u32 match ip %s action mirred egress redirect dev $IMQ_DEV\n", (nvram_get_int("qos_udp") == 1) ? "protocol 6 0xff" : "dst 0.0.0.0/0"); } fprintf( f, "\n" "\t# class id %u: rate %ukbit ceil %ukbit\n", classid, rateInKilobitsPerSecond, ceilingInKilobitsPerSecond); if (overhead == 0) { fprintf( f, "\t$TCA_IMQ parent 1:1 classid 1:%u htb rate %ukbit ceil %ukbit prio %u quantum %u\n", classid, rateInKilobitsPerSecond, ceilingInKilobitsPerSecond, priority, mtu); } else { fprintf( f, "\t$TCA_IMQ parent 1:1 classid 1:%u htb rate %ukbit ceil %ukbit prio %u quantum %u overhead %u linklayer atm\n", classid, rateInKilobitsPerSecond, ceilingInKilobitsPerSecond, priority, mtu, overhead); } fprintf( f, "\t$TQA_IMQ parent 1:%u handle %u: $Q\n", classid, classid); fprintf( f, "\t$TFA_IMQ parent 1: prio %u handle %u fw flowid 1:%u \n", classid, priority, classid); } free(buf); //// write commands which adds rule to forward traffic to IMQ device fputs( "\n" "\t# set up the IMQ device (otherwise this won't work) to limit the incoming data\n" "\tip link set $IMQ_DEV up\n", f); fprintf(f, "\t;;\n" "stop)\n" "\tip link set $IMQ_DEV down\n" "\ttc qdisc del dev $WAN_DEV root 2>/dev/null\n" "\ttc qdisc del dev $IMQ_DEV root 2>/dev/null\n" "\ttc filter del dev $WAN_DEV parent ffff: prio 10 u32 match ip %s action mirred egress redirect dev $IMQ_DEV 2>/dev/null\n" "\t;;\n" "*)\n" "\techo \"...\"\n" "\techo \"... OUTGOING QDISCS AND CLASSES FOR $WAN_DEV\"\n" "\techo \"...\"\n" "\ttc -s -d qdisc ls dev $WAN_DEV\n" "\techo\n" "\ttc -s -d class ls dev $WAN_DEV\n" "\techo\n" "\techo \"...\"\n" "\techo \"... INCOMING QDISCS AND CLASSES FOR $WAN_DEV (routed through $IMQ_DEV)\"\n" "\techo \"...\"\n" "\ttc -s -d qdisc ls dev $IMQ_DEV\n" "\techo\n" "\ttc -s -d class ls dev $IMQ_DEV\n" "\techo\n" "esac\n", (nvram_get_int("qos_udp") == 1) ? "protocol 6 0xff" : "dst 0.0.0.0/0"); fclose(f); chmod(qosfn, 0700); eval((char *)qosfn, "start"); }
// used for various testing static int rctest_main(int argc, char *argv[]) { int on; if (argc < 3) { _dprintf("test what?\n"); } else if (strcmp(argv[1], "rc_service")==0) { notify_rc(argv[2]); } else if(strcmp(argv[1], "get_phy_status")==0) { int mask; mask = atoi(argv[2]); TRACE_PT("debug for phy_status %x\n", get_phy_status(mask)); } else if(strcmp(argv[1], "get_phy_speed")==0) { int mask; mask = atoi(argv[2]); TRACE_PT("debug for phy_speed %x\n", get_phy_speed(mask)); } else if(strcmp(argv[1], "set_phy_ctrl")==0) { int mask, ctrl; mask = atoi(argv[2]); ctrl = atoi(argv[3]); TRACE_PT("debug for phy_speed %x\n", set_phy_ctrl(mask, ctrl)); } else if(strcmp(argv[1], "handle_notifications")==0) { handle_notifications(); } else if(strcmp(argv[1], "check_action")==0) { _dprintf("check: %d\n", check_action()); } else if(strcmp(argv[1], "nvramhex")==0) { int i; char *nv; nv = nvram_safe_get(argv[2]); _dprintf("nvram %s(%d): ", nv, strlen(nv)); for(i=0;i<strlen(nv);i++) { _dprintf(" %x", (unsigned char)*(nv+i)); } _dprintf("\n"); } else { on = atoi(argv[2]); _dprintf("%s %d\n", argv[1], on); if (strcmp(argv[1], "vlan") == 0) { if(on) start_vlan(); else stop_vlan(); } else if (strcmp(argv[1], "lan") == 0) { if(on) start_lan(); else stop_lan(); } else if (strcmp(argv[1], "wl") == 0) { if(on) { start_wl(); lanaccess_wl(); } } else if (strcmp(argv[1], "wan") == 0) { if(on) start_wan(); else stop_wan(); } else if (strcmp(argv[1], "firewall") == 0) { //if(on) start_firewall(); //else stop_firewall(); } else if (strcmp(argv[1], "watchdog") == 0) { if(on) start_watchdog(); else stop_watchdog(); } #ifdef RTCONFIG_FANCTRL else if (strcmp(argv[1], "phy_tempsense") == 0) { if(on) start_phy_tempsense(); else stop_phy_tempsense(); } #endif #ifdef RTCONFIG_BCMWL6 #ifdef RTCONFIG_PROXYSTA else if (strcmp(argv[1], "psta_monitor") == 0) { if(on) start_psta_monitor(); else stop_psta_monitor(); } #endif #endif else if (strcmp(argv[1], "qos") == 0) {//qos test if(on){ #ifdef RTCONFIG_RALINK if (module_loaded("hw_nat")) { modprobe_r("hw_nat"); sleep(1); #if 0 system("echo 0 > /proc/sys/net/ipv4/conf/default/force_igmp_version"); system("echo 0 > /proc/sys/net/ipv4/conf/all/force_igmp_version"); #endif } #endif add_iQosRules(get_wan_ifname(0)); start_iQos(); } else { #ifdef RTCONFIG_RALINK if (nvram_get_int("hwnat") && /* TODO: consider RTCONFIG_DUALWAN case */ // !nvram_match("wan0_proto", "l2tp") && // !nvram_match("wan0_proto", "pptp") && // !(nvram_get_int("fw_pt_l2tp") || nvram_get_int("fw_pt_ipsec") && // (nvram_match("wl0_radio", "0") || nvram_get_int("wl0_mrate_x")) && // (nvram_match("wl1_radio", "0") || nvram_get_int("wl1_mrate_x")) && !module_loaded("hw_nat")) { #if 0 system("echo 2 > /proc/sys/net/ipv4/conf/default/force_igmp_version"); system("echo 2 > /proc/sys/net/ipv4/conf/all/force_igmp_version"); #endif modprobe("hw_nat"); sleep(1); } #endif stop_iQos(); del_iQosRules(); } } #ifdef RTCONFIG_WEBDAV else if (strcmp(argv[1], "webdav") == 0) { if(on) start_webdav(); } #endif else if (strcmp(argv[1], "gpiow") == 0) { if(argc>=4) set_gpio(atoi(argv[2]), atoi(argv[3])); } else if (strcmp(argv[1], "gpior") == 0) { _dprintf("%d\n", get_gpio(atoi(argv[2]))); } else if (strcmp(argv[1], "gpiod") == 0) { if(argc>=4) gpio_dir(atoi(argv[2]), atoi(argv[3])); } else if (strcmp(argv[1], "init_switch") == 0) { init_switch(on); } else if (strcmp(argv[1], "set_action") == 0) { set_action(on); } else if (strcmp(argv[1], "pwr_usb") == 0) { set_pwr_usb(atoi(argv[2])); _dprintf("done.\n"); } else { printf("what?\n"); } } return 0; }
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"); 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_conntrack(void) { unsigned int v[10]; const char *p; int i; p = nvram_safe_get("ct_tcp_timeout"); if (sscanf(p, "%u%u%u%u%u%u%u%u%u%u", &v[0], &v[1], &v[2], &v[3], &v[4], &v[5], &v[6], &v[7], &v[8], &v[9]) == 10) { // lightly verify f_write_string("/proc/sys/net/ipv4/ip_conntrack_tcp_timeouts", p, 0, 0); } p = nvram_safe_get("ct_udp_timeout"); if (sscanf(p, "%u%u", &v[0], &v[1]) == 2) { f_write_string("/proc/sys/net/ipv4/ip_conntrack_udp_timeouts", p, 0, 0); } p = nvram_safe_get("ct_max"); i = atoi(p); if ((i >= 128) && (i <= 65535)) { f_write_string("/proc/sys/net/ipv4/ip_conntrack_max", p, 0, 0); } if (!nvram_match("nf_pptp", "0")) { modprobe("ip_conntrack_proto_gre"); modprobe("ip_nat_proto_gre"); modprobe("ip_conntrack_pptp"); modprobe("ip_nat_pptp"); } else { modprobe_r("ip_nat_pptp"); modprobe_r("ip_conntrack_pptp"); modprobe_r("ip_nat_proto_gre"); modprobe_r("ip_conntrack_proto_gre"); } if (!nvram_match("nf_h323", "0")) { modprobe("ip_conntrack_h323"); modprobe("ip_nat_h323"); } else { modprobe_r("ip_nat_h323"); modprobe_r("ip_conntrack_h323"); } if (!nvram_match("nf_rtsp", "0")) { modprobe("ip_conntrack_rtsp"); modprobe("ip_nat_rtsp"); } else { modprobe_r("ip_nat_rtsp"); modprobe_r("ip_conntrack_rtsp"); } if (!nvram_match("nf_ftp", "0")) { modprobe("ip_conntrack_ftp"); modprobe("ip_nat_ftp"); } else { modprobe_r("ip_nat_ftp"); modprobe_r("ip_conntrack_ftp"); } }
// used for various testing static int rctest_main(int argc, char *argv[]) { int on; if (argc < 2) { _dprintf("test what?\n"); } else if (strcmp(argv[1], "rc_service")==0) { notify_rc(argv[2]); } else if(strcmp(argv[1], "get_phy_status")==0) { int mask; mask = atoi(argv[2]); TRACE_PT("debug for phy_status %x\n", get_phy_status(mask)); } else if(strcmp(argv[1], "get_phy_speed")==0) { int mask; mask = atoi(argv[2]); TRACE_PT("debug for phy_speed %x\n", get_phy_speed(mask)); } else if(strcmp(argv[1], "set_phy_ctrl")==0) { int mask, ctrl; mask = atoi(argv[2]); ctrl = atoi(argv[3]); TRACE_PT("debug for phy_speed %x\n", set_phy_ctrl(mask, ctrl)); } else if(strcmp(argv[1], "handle_notifications")==0) { handle_notifications(); } else if(strcmp(argv[1], "check_action")==0) { _dprintf("check: %d\n", check_action()); } else if(strcmp(argv[1], "nvramhex")==0) { int i; char *nv; nv = nvram_safe_get(argv[2]); _dprintf("nvram %s(%d): ", nv, strlen(nv)); for(i=0;i<strlen(nv);i++) { _dprintf(" %x", (unsigned char)*(nv+i)); } _dprintf("\n"); } else { on = atoi(argv[2]); _dprintf("%s %d\n", argv[1], on); if (strcmp(argv[1], "vlan") == 0) { if(on) start_vlan(); else stop_vlan(); } else if (strcmp(argv[1], "lan") == 0) { if(on) start_lan(); else stop_lan(); } else if (strcmp(argv[1], "wl") == 0) { if(on) { start_wl(); lanaccess_wl(); } } else if (strcmp(argv[1], "wan") == 0) { if(on) start_wan(); else stop_wan(); } else if (strcmp(argv[1], "wan_port") == 0) { if(on) start_wan_port(); else stop_wan_port(); } else if (strcmp(argv[1], "firewall") == 0) { //if(on) start_firewall(); //else stop_firewall(); } else if (strcmp(argv[1], "watchdog") == 0) { if(on) start_watchdog(); else stop_watchdog(); } #if ! (defined(RTCONFIG_QCA) || defined(RTCONFIG_RALINK)) else if (strcmp(argv[1], "watchdog02") == 0) { if(on) start_watchdog02(); else stop_watchdog02(); } #endif /* ! (RTCONFIG_QCA || RTCONFIG_RALINK) */ else if (strcmp(argv[1], "sw_devled") == 0) { if(on) start_sw_devled(); else stop_sw_devled(); } #ifdef RTCONFIG_FANCTRL else if (strcmp(argv[1], "phy_tempsense") == 0) { if(on) start_phy_tempsense(); else stop_phy_tempsense(); } #endif #ifdef RTCONFIG_BCMWL6 #ifdef RTCONFIG_PROXYSTA else if (strcmp(argv[1], "psta_monitor") == 0) { if(on) start_psta_monitor(); else stop_psta_monitor(); } #endif #endif #ifdef RTCONFIG_IPERF else if (strcmp(argv[1], "monitor") == 0) { if(on) start_monitor(); else stop_monitor(); } #endif else if (strcmp(argv[1], "qos") == 0) {//qos test if(on){ #ifdef RTCONFIG_RALINK if (module_loaded("hw_nat")) { modprobe_r("hw_nat"); sleep(1); #if 0 f_write_string("/proc/sys/net/ipv4/conf/default/force_igmp_version", "0", 0, 0); f_write_string("/proc/sys/net/ipv4/conf/all/force_igmp_version", "0", 0, 0); #endif } #endif add_iQosRules(get_wan_ifname(wan_primary_ifunit())); #ifdef RTCONFIG_BWDPI if(nvram_get_int("qos_type") == 1) { start_dpi_engine_service(); // force to rebuild firewall to avoid some loopback issue if (nvram_match("fw_nat_loopback", "2")) start_firewall(wan_primary_ifunit(), 0); } else #endif start_iQos(); } else { #ifdef RTCONFIG_RALINK if (nvram_get_int("hwnat") && /* TODO: consider RTCONFIG_DUALWAN case */ // !nvram_match("wan0_proto", "l2tp") && // !nvram_match("wan0_proto", "pptp") && // !(nvram_get_int("fw_pt_l2tp") || nvram_get_int("fw_pt_ipsec") && // (nvram_match("wl0_radio", "0") || nvram_get_int("wl0_mrate_x")) && // (nvram_match("wl1_radio", "0") || nvram_get_int("wl1_mrate_x")) && !module_loaded("hw_nat")) { #if 0 f_write_string("/proc/sys/net/ipv4/conf/default/force_igmp_version", "2", 0, 0); f_write_string("/proc/sys/net/ipv4/conf/all/force_igmp_version", "2", 0, 0); #endif #if defined(RTN14U) || defined(RTAC52U) || defined(RTAC51U) || defined(RTN11P) || defined(RTN300) || defined(RTN54U) || defined(RTAC1200HP) || defined(RTN56UB1) || defined(RTAC54U) || defined(RTN56UB2) if (!(!nvram_match("switch_wantag", "none")&&!nvram_match("switch_wantag", ""))) #endif { modprobe("hw_nat"); sleep(1); } } #endif #ifdef RTCONFIG_BWDPI if(nvram_get_int("qos_type") == 1){ stop_dpi_engine_service(1); } else #endif stop_iQos(); del_iQosRules(); } } #ifdef RTCONFIG_WEBDAV else if (strcmp(argv[1], "webdav") == 0) { if(on) start_webdav(); } #endif #ifdef RTCONFIG_TUNNEL else if (strcmp(argv[1], "mastiff") == 0) { if(on) start_mastiff(); } #endif else if (strcmp(argv[1], "gpiow") == 0) { if(argc>=4) set_gpio(atoi(argv[2]), atoi(argv[3])); } else if (strcmp(argv[1], "gpior") == 0) { printf("%d\n", get_gpio(atoi(argv[2]))); } else if (strcmp(argv[1], "gpiod") == 0) { if(argc>=4) gpio_dir(atoi(argv[2]), atoi(argv[3])); } else if (strcmp(argv[1], "init_switch") == 0) { init_switch(); } else if (strcmp(argv[1], "set_action") == 0) { set_action(on); } else if (strcmp(argv[1], "pwr_usb") == 0) { set_pwr_usb(atoi(argv[2])); _dprintf("done.\n"); } else if (strcmp(argv[1], "enc_chk") == 0) { unsigned char enc_buf[ENC_WORDS_LEN]; unsigned char dec_buf[DATA_WORDS_LEN + 1]; _dprintf("get enc str:[%s]\n", enc_str(argv[2], (char *) enc_buf)); _dprintf("get dec str:[%s]\n", dec_str((char *) enc_buf, (char *) dec_buf)); _dprintf("done(%d)\n", strcmp(argv[2], (const char *) dec_buf)); } #ifdef RTCONFIG_BCMFA else if (strcmp(argv[1], "fa_rev") == 0) { _dprintf("(%d) done.\n", get_fa_rev()); } else if (strcmp(argv[1], "fa_dump") == 0) { _dprintf("(%d) done.\n", get_fa_dump()); } #endif else { printf("what?\n"); } } return 0; }