void config_switch_dsl() { int stbport; dbG("config ethernet switch IC\n"); if (is_routing_enabled()) { stbport = atoi(nvram_safe_get("switch_stb_x")); if (stbport < 0 || stbport > 6) stbport = 0; dbG("STB port: %d\n", stbport); #ifdef RTCONFIG_DUALWAN if (stbport == 0) { if (get_dualwan_secondary()==WANS_DUALWAN_IF_LAN) { config_switch_dsl_set_lan(); } else { if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN) { config_switch_dsl_set_lan(); } else { config_switch_dsl_set_dsl(); } } } else { if (get_dualwan_secondary()==WANS_DUALWAN_IF_LAN) { config_switch_dsl_set_lan_iptv(stbport); } else { if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN) { config_switch_dsl_set_lan_iptv(stbport); } else { config_switch_dsl_set_dsl(); } } } #else if (stbport == 0) { config_switch_dsl_set_dsl(); } else { config_switch_dsl_set_iptv(stbport); } #endif } }
void config_switch_dsl_set_lan() { // ethernet wan port = high-byte // iptv port = low-byte // DSLWAN , ethernet WAN , no IPTV if (nvram_match("wans_lanport","1")) { // 0x100 dbG("wan port = lan1\n"); eval("rtkswitch", "8", "256"); } else if (nvram_match("wans_lanport","2")) { // 0x200 dbG("wan port = lan2\n"); eval("rtkswitch", "8", "512"); } else if (nvram_match("wans_lanport","3")) { // 0x300 dbG("wan port = lan3\n"); eval("rtkswitch", "8", "768"); } else { // 0x400 dbG("wan port = lan4\n"); eval("rtkswitch", "8", "1024"); } }
void config_switch_dsl_set_lan_iptv(int stbport) { // ethernet wan port = high-byte // iptv port = low-byte char param_buf[32]; // ethernet WAN , has IPTV if (nvram_match("wans_lanport","1")) { // 0x100 dbG("wan port = lan1\n"); sprintf(param_buf, "%d", 0x100 + stbport); eval("rtkswitch", "8", param_buf); } else if (nvram_match("wans_lanport","2")) { // 0x200 dbG("wan port = lan2\n"); sprintf(param_buf, "%d", 0x200 + stbport); eval("rtkswitch", "8", param_buf); } else if (nvram_match("wans_lanport","3")) { // 0x300 dbG("wan port = lan3\n"); sprintf(param_buf, "%d", 0x300 + stbport); eval("rtkswitch", "8", param_buf); } else { // 0x400 dbG("wan port = lan4\n"); sprintf(param_buf, "%d", 0x400 + stbport); eval("rtkswitch", "8", param_buf); } }
void config_switch_dsl_set_lan() { int wans_lanport = nvram_get_int("wans_lanport"); if(wans_lanport < 1 || wans_lanport > 4) return; switch(wans_lanport) { case 1: dbG("wan port = lan1\n"); eval("et", "robowr", "0x34", "0x12", "0x04"); eval("et", "robowr", "0x05", "0x83", "0x0422"); break; case 2: dbG("wan port = lan2\n"); eval("et", "robowr", "0x34", "0x14", "0x04"); eval("et", "robowr", "0x05", "0x83", "0x0824"); break; case 3: dbG("wan port = lan3\n"); eval("et", "robowr", "0x34", "0x16", "0x04"); eval("et", "robowr", "0x05", "0x83", "0x1028"); break; case 4: dbG("wan port = lan4\n"); eval("et", "robowr", "0x34", "0x18", "0x04"); eval("et", "robowr", "0x05", "0x83", "0x2030"); break; } eval("et", "robowr", "0x05", "0x81", "0x0004"); eval("et", "robowr", "0x05", "0x80", "0x0000"); eval("et", "robowr", "0x05", "0x80", "0x0080"); }
int is_wps_stopped(void) { int status, ret = 1; status = getWscStatus(); if (status != 1) count = 0; else count++; // dbG("wps status: %d, count: %d\n", status, count); switch (status) { case 1: /* Idle */ if (count < 5) ret = 0; break; case 34: /* Configured */ dbG("\nWPS Configured\n"); break; case 0x109: /* PBC_SESSION_OVERLAP */ dbG("\nWPS PBC SESSION OVERLAP\n"); break; case 2: /* Failed */ if (!g_isEnrollee) { dbG("\nWPS Failed\n"); break; } default: ret = 0; break; } return ret; // TODO: handle enrollee }
void check_radio_time(const char *radio_time_name) { char *radio_time = nvram_get(radio_time_name); char starttime[5], endtime[5]; memset(starttime, 0, 5); memset(endtime, 0, 5); if ((!radio_time) || strlen(radio_time) != 8) goto err; strncpy(starttime, radio_time, 4); strncpy(endtime, radio_time + 4, 4); // dbG("%s starttime: %s\n", radio_time_name, starttime); // dbG("%s endtime: %s\n", radio_time_name, endtime); if (atoi(starttime) >= atoi(endtime)) goto err; return; err: dbG("fix %s as 00002359\n", radio_time_name); nvram_set(radio_time_name, "00002359"); }
// a workaround handler, can be removed after bug found void init_dsl_before_start_wan(void) { // eth2 could not start up in original initialize routine // it must put eth2 start-up code here dbG("enable eth2 and power up all LAN ports\n"); eval("ifconfig", "eth2", "up"); eval("rtkswitch", "14"); eval("brctl", "addif", "br0", "eth2.2"); }
int get_tx_power_qtn(void) { const struct txpower_ac_qtn_s *p_to_table; int txpower = 80; p_to_table = &txpower_list_qtn_rtac87u[0]; txpower = nvram_get_int("wl1_txpower"); for (p_to_table; p_to_table->min != 0; ++p_to_table) { if (txpower >= p_to_table->min && txpower <= p_to_table->max) { dbG("txpoewr between: min:[%d] to max:[%d]\n", p_to_table->min, p_to_table->max); return p_to_table->pwr; } } if ( p_to_table->min == 0 ) dbG("no correct power offset!\n"); /* default max power */ return 23; }
int runtime_config_qtn(int unit, int subunit) { int ret; if (!rpc_qtn_ready()) { dbG("qcsapi error\n"); return -1; } if ( unit == 1 && subunit == -1 ){ dbG("Global QTN settings\n"); if(nvram_get_int("wl1_itxbf") == 1 || nvram_get_int("wl1_txbf") == 1){ dbG("[bf] set_bf_on\n"); qcsapi_wifi_run_script("router_command.sh", "set_bf_on"); ret = qcsapi_config_update_parameter(WIFINAME, "bf", "1"); if (ret < 0) dbG("qcsapi error\n"); }else{ dbG("[bf] set_bf_off\n"); qcsapi_wifi_run_script("router_command.sh", "set_bf_off"); ret = qcsapi_config_update_parameter(WIFINAME, "bf", "0"); if (ret < 0) dbG("qcsapi error\n"); } gen_stateless_conf(); } rpc_parse_nvram_from_httpd(unit, subunit); return 1; }
void check_2nd_jffs(void) { char s[256]; int size; int part; struct statfs sf; _dprintf("2nd jffs2: %s\n", SECOND_JFFS2_PARTITION); if (!mtd_getinfo(SECOND_JFFS2_PARTITION, &part, &size)) { _dprintf("Can not get 2nd jffs2 information!"); return; } mount_2nd_jffs2(); if(access("/asus_jffs/bootcfg.tgz", R_OK ) != -1 ) { logmessage("qtn", "bootcfg.tgz exists"); system("rm -f /tmp/bootcfg.tgz"); } else { logmessage("qtn", "bootcfg.tgz does not exist"); sprintf(s, MTD_BLKDEV(%d), part); umount("/asus_jffs"); if (mount(s, SECOND_JFFS2_PATH , JFFS_NAME, MS_NOATIME, "") != 0) { logmessage("qtn", "cannot store bootcfg.tgz"); }else{ system("cp /tmp/bootcfg.tgz /asus_jffs"); system("rm -f /tmp/bootcfg.tgz"); logmessage("qtn", "backup bootcfg.tgz ok"); } } if (umount(SECOND_JFFS2_PATH)){ dbG("umount asus_jffs failed\n"); }else{ dbG("umount asus_jffs ok\n"); } // format_mount_2nd_jffs2(); }
void cpu_usage_minotor() { cpu_timer = (cpu_timer + 1) % 6; if (cpu_timer) return; #if 0 unsigned int usage = get_cpu_usage(); #else unsigned int usage = cpu_main(0, NULL, 0); #endif if (usage > 99) high_cpu_usage_count++; else high_cpu_usage_count = 0; if (high_cpu_usage_count > 30) { dbG("reboot for high CPU load !!!\n"); dbG("reboot for high CPU load !!!\n"); dbG("reboot for high CPU load !!!\n"); sys_exit(); } }
int start_nodfs_scan_qtn(void) { int qcsapi_retval; int pick_flags = 0; logmessage("dfs", "start dfs scan\n"); pick_flags = IEEE80211_PICK_CLEAREST; pick_flags |= IEEE80211_PICK_NONDFS; if (!rpc_qtn_ready()) { dbG("5 GHz radio is not ready\n"); return -1; } qcsapi_retval = qcsapi_wifi_start_scan_ext(WIFINAME, pick_flags); if (qcsapi_retval >= 0) { logmessage("nodfs_scan", "complete"); }else{ logmessage("nodfs_scan", "scan not complete"); } return 1; }
static void ipv6aide_check(int sig) { char tmp[64]; char *p = NULL; char *q, *r; if (get_ipv6_service() != IPV6_NATIVE_DHCP) goto END; p = nvram_safe_get("ipv6_gw_addr"); if (strlen(p)) { eval("route", "-A", "inet6", "add", "2000::/3", "gw", p, "dev", (char*)get_wan6face()); goto END; } r = strdup(ipv6_gateway_address()); if (!r) return; memset(tmp, 0, sizeof(tmp)); q = tmp; p = strtok_r(r, " ", &q); if (!p || !strlen(p) || !strlen(q)) { alarmtimer(NORMAL_PERIOD, 0); return; } dbG("ipv6 gateway: %s (dev %s)\n", p, q); eval("route", "-A", "inet6", "add", "2000::/3", "gw", p, "dev", q); free(r); END: ipv6aide_exit(sig); }
static void ipv6aide_check(int sig) { char tmp[64]; char *p = NULL; char *q; if (get_ipv6_service() != IPV6_NATIVE_DHCP) goto END; memset(tmp, 0, sizeof(tmp)); q = tmp; p = strtok_r(ipv6_gateway_address(), " ", &q); if (!p || !strlen(p) || !strlen(q)) { alarmtimer(NORMAL_PERIOD, 0); return; } dbG("ipv6 gateway: %s (dev %s)\n", p, q); eval("route", "-A", "inet6", "add", "2000::/3", "gw", p, "dev", q); END: ipv6aide_exit(sig); }
static void check_wl_rate(const char *ifname) { int rate = 0; char rate_buf[32]; sprintf(rate_buf, "0 Mbps"); if (wl_ioctl(ifname, WLC_GET_RATE, &rate, sizeof(int))) { dbG("can not get rate info of %s\n", ifname); goto ERROR; } else { rate = dtoh32(rate); if ((rate == -1) || (rate == 0)) sprintf(rate_buf, "auto"); else sprintf(rate_buf, "%d%s Mbps", (rate / 2), (rate & 1) ? ".5" : ""); } ERROR: logmessage(LOGNAME, "wl interface %s data rate: %s", ifname, rate_buf); }
int start_ap_qtn(void) { int ret; int qcsapi_retval; unsigned int iter; char ssid[65]; if (!rpc_qtn_ready()) { dbG("5 GHz radio is not ready\n"); return -1; } logmessage("start_ap", "AP is running..."); #if 0 qcsapi_retval = qcsapi_wifi_reload_in_mode(WIFINAME, qcsapi_access_point); if (qcsapi_retval >= 0) { fprintf(stderr, "reload to AP mode successfuly\n" ); } else { fprintf(stderr, "reload to AP mode failed\n" ); } #endif sprintf(ssid, "%s", nvram_safe_get("wl1_ssid")); ret = qcsapi_wifi_set_SSID(WIFINAME, ssid); // check security char auth[8]; char crypto[16]; char beacon[] = "WPAand11i"; char encryption[] = "TKIPandAESEncryption"; char key[65]; uint32_t index = 0; strncpy(auth, nvram_safe_get("wl1_auth_mode_x"), sizeof(auth)); strncpy(crypto, nvram_safe_get("wl1_crypto"), sizeof(crypto)); strncpy(key, nvram_safe_get("wl1_wpa_psk"), sizeof(key)); if(!strcmp(auth, "psk2") && !strcmp(crypto, "aes")){ memcpy(beacon, "11i", strlen("11i") + 1); memcpy(encryption, "AESEncryption", strlen("AESEncryption") + 1); } else if(!strcmp(auth, "pskpsk2") && !strcmp(crypto, "aes") ){ memcpy(beacon, "WPAand11i", strlen("WPAand11i") + 1); memcpy(encryption, "AESEncryption", strlen("AESEncryption") + 1); } else if(!strcmp(auth, "pskpsk2") && !strcmp(crypto, "tkip+aes") ){ memcpy(beacon, "WPAand11i", strlen("WPAand11i") + 1); memcpy(encryption, "TKIPandAESEncryption", strlen("TKIPandAESEncryption") + 1); } else{ logmessage("start_ap", "No security in use\n"); memcpy(beacon, "Basic", strlen("Basic") + 1); } logmessage("start_ap", "ssid=%s, auth=%s, crypto=%s, encryption=%s, key=%s\n", ssid, auth, crypto, encryption, key); if(!strcmp(auth, "open")){ if(qcsapi_wifi_set_WPA_authentication_mode(WIFINAME, "NONE") < 0) logmessage("start_ap", "fail to setup a open-none ap\n"); if(qcsapi_wifi_set_beacon_type(WIFINAME, beacon) < 0) logmessage("start_ap", "fail to setup beacon type in ap\n"); } else{ if(qcsapi_wifi_set_beacon_type(WIFINAME, beacon) < 0) logmessage("start_ap", "fail to setup beacon type in ap\n"); if(qcsapi_wifi_set_WPA_authentication_mode(WIFINAME, "PSKAuthentication") < 0) logmessage("start_ap", "fail to setup authentiocation type in ap\n"); if(qcsapi_wifi_set_key_passphrase(WIFINAME, index, key) < 0) logmessage("start_ap", "fail to set key in ap\n"); if(qcsapi_wifi_set_WPA_encryption_modes(WIFINAME, encryption) < 0) logmessage("start_ap", "fail to set encryption mode in ap\n"); } logmessage("start_ap", "start_ap done!\n"); return 1; }
int is_wps_stopped(void) { int i, ret = 1; char status[16], tmp[128], prefix[] = "wlXXXXXXXXXX_", word[256], *next, ifnames[128]; int wps_band = nvram_get_int("wps_band"), multiband = get_wps_multiband(); i = 0; strcpy(ifnames, nvram_safe_get("wl_ifnames")); foreach (word, ifnames, next) { if (i >= MAX_NR_WL_IF) break; if (!multiband && wps_band != i) { ++i; continue; } snprintf(prefix, sizeof(prefix), "wl%d_", i); if (!__need_to_start_wps_band(prefix) || nvram_match(strcat_r(prefix, "radio", tmp), "0")) { ret = 0; ++i; continue; } #ifdef RTCONFIG_WPS_ENROLLEE if (nvram_match("wps_enrollee", "1")) strcpy(status, getWscStatus_enrollee(i)); else #endif strcpy(status, getWscStatus(i)); //dbG("band %d wps status: %s\n", i, status); if (!strcmp(status, "Success") #ifdef RTCONFIG_WPS_ENROLLEE || !strcmp(status, "COMPLETED") #endif ) { dbG("\nWPS %s\n", status); #ifdef RTCONFIG_WPS_LED nvram_set("wps_success", "1"); #endif #if (defined(RTCONFIG_WPS_ENROLLEE) && defined(RTCONFIG_WIFI_CLONE)) if (nvram_match("wps_enrollee", "1")) { nvram_set("wps_e_success", "1"); #if defined(PLN12) set_wifiled(4); #endif wifi_clone(i); } #endif ret = 1; } else if (!strcmp(status, "Failed") #ifdef RTCONFIG_WPS_ENROLLEE || !strcmp(status, "INACTIVE") #endif ) { dbG("\nWPS %s\n", status); ret = 1; } else ret = 0; if (ret) break; ++i; } return ret; }
void config_switch() { int model; int stbport; int controlrate_unknown_unicast; int controlrate_unknown_multicast; int controlrate_multicast; int controlrate_broadcast; dbG("link down all ports\n"); eval("rtkswitch", "17"); // link down all ports if (config_switch_for_first_time) config_switch_for_first_time = 0; else { dbG("software reset\n"); eval("rtkswitch", "27"); // software reset } #if defined(RTN14U) || defined(RTAC52U) system("rtkswitch 8 0"); //Barton add #endif if (is_routing_enabled()) { char parm_buf[] = "XXX"; stbport = atoi(nvram_safe_get("switch_stb_x")); if (stbport < 0 || stbport > 6) stbport = 0; dbG("STB port: %d\n", stbport); /* stbport: unifi_malaysia=1 otherwise * ---------------------------------------------- * 0: LLLLW LLLLW * 1: LLLTW LLLWW * 2: LLTLW LLWLW * 3: LTLLW LWLLW * 4: TLLLW WLLLW * 5: TTLLW WWLLW * 6: LLTTW LLWWW */ if(!nvram_match("switch_wantag", "none")&&!nvram_match("switch_wantag", ""))//2012.03 Yau modify { char tmp[128]; int voip_port = 0; int vlan_val;/* VID and PRIO */ // voip_port = atoi(nvram_safe_get("voip_port")); voip_port = 3; if (voip_port < 0 || voip_port > 4) voip_port = 0; /* Fixed Ports Now*/ stbport = 4; voip_port = 3; sprintf(tmp, "rtkswitch 29 %d", voip_port); system(tmp); if(!strncmp(nvram_safe_get("switch_wantag"), "unifi", 5))/* Added for Unifi. Cherry Cho modified in 2011/6/28.*/ { if(strstr(nvram_safe_get("switch_wantag"), "home")) { system("rtkswitch 38 1");/* IPTV: P0 */ /* Internet */ system("rtkswitch 36 500"); system("rtkswitch 37 0"); system("rtkswitch 39 0x02000210"); /* IPTV */ system("rtkswitch 36 600"); system("rtkswitch 37 0"); system("rtkswitch 39 0x00010011"); } else/* No IPTV. Business package */ { /* Internet */ system("rtkswitch 38 0"); system("rtkswitch 36 500"); system("rtkswitch 37 0"); system("rtkswitch 39 0x02000210"); } } else if(!strncmp(nvram_safe_get("switch_wantag"), "singtel", 7))/* Added for SingTel's exStream issues. Cherry Cho modified in 2011/7/19. */ { if(strstr(nvram_safe_get("switch_wantag"), "mio"))/* Connect Singtel MIO box to P3 */ { system("rtkswitch 40 1"); system("rtkswitch 38 3");/* IPTV: P0 VoIP: P1 */ /* Internet */ system("rtkswitch 36 10"); system("rtkswitch 37 0"); system("rtkswitch 39 0x02000210"); /* VoIP */ system("rtkswitch 36 30"); system("rtkswitch 37 4"); system("rtkswitch 39 0x00000012");//VoIP Port: P1 tag } else//Connect user's own ATA to lan port and use VoIP by Singtel WAN side VoIP gateway at voip.singtel.com { system("rtkswitch 38 1");/* IPTV: P0 */ /* Internet */ system("rtkswitch 36 10"); system("rtkswitch 37 0"); system("rtkswitch 39 0x02000210"); } /* IPTV */ system("rtkswitch 36 20"); system("rtkswitch 37 4"); system("rtkswitch 39 0x00010011"); } else if(!strcmp(nvram_safe_get("switch_wantag"), "m1_fiber"))//VoIP: P1 tag. Cherry Cho added in 2012/1/13. { system("rtkswitch 40 1"); system("rtkswitch 38 2");/* VoIP: P1 2 = 0x10 */ /* Internet */ system("rtkswitch 36 1103"); system("rtkswitch 37 1"); system("rtkswitch 39 0x02000210"); /* VoIP */ system("rtkswitch 36 1107"); system("rtkswitch 37 1"); system("rtkswitch 39 0x00000012");//VoIP Port: P1 tag } else if(!strcmp(nvram_safe_get("switch_wantag"), "maxis_fiber"))//VoIP: P1 tag. Cherry Cho added in 2012/11/6. { system("rtkswitch 40 1"); system("rtkswitch 38 2");/* VoIP: P1 2 = 0x10 */ /* Internet */ system("rtkswitch 36 621"); system("rtkswitch 37 0"); system("rtkswitch 39 0x02000210"); /* VoIP */ system("rtkswitch 36 821"); system("rtkswitch 37 0"); system("rtkswitch 39 0x00000012");//VoIP Port: P1 tag system("rtkswitch 36 822"); system("rtkswitch 37 0"); system("rtkswitch 39 0x00000012");//VoIP Port: P1 tag } else if(!strcmp(nvram_safe_get("switch_wantag"), "maxis_fiber_sp"))//VoIP: P1 tag. Cherry Cho added in 2012/11/6. { system("rtkswitch 40 1"); system("rtkswitch 38 2");/* VoIP: P1 2 = 0x10 */ /* Internet */ system("rtkswitch 36 11"); system("rtkswitch 37 0"); system("rtkswitch 39 0x02000210"); /* VoIP */ system("rtkswitch 36 14"); system("rtkswitch 37 0"); system("rtkswitch 39 0x00000012");//VoIP Port: P1 tag } else/* Cherry Cho added in 2011/7/11. */ { /* Initialize VLAN and set Port Isolation */ if(strcmp(nvram_safe_get("switch_wan1tagid"), "") && strcmp(nvram_safe_get("switch_wan2tagid"), "")) system("rtkswitch 38 3");// 3 = 0x11 IPTV: P0 VoIP: P1 else if(strcmp(nvram_safe_get("switch_wan1tagid"), "")) system("rtkswitch 38 1");// 1 = 0x01 IPTV: P0 else if(strcmp(nvram_safe_get("switch_wan2tagid"), "")) system("rtkswitch 38 2");// 2 = 0x10 VoIP: P1 else system("rtkswitch 38 0");//No IPTV and VoIP ports /*++ Get and set Vlan Information */ if(strcmp(nvram_safe_get("switch_wan0tagid"), "") != 0) // Internet on WAN (port 4) { vlan_val = atoi(nvram_safe_get("switch_wan0tagid")); if((vlan_val >= 2) && (vlan_val <= 4094)) { sprintf(tmp, "rtkswitch 36 %d", vlan_val); system(tmp); } if(strcmp(nvram_safe_get("switch_wan0prio"), "") != 0) { vlan_val = atoi(nvram_safe_get("switch_wan0prio")); if((vlan_val >= 0) && (vlan_val <= 7)) { sprintf(tmp, "rtkswitch 37 %d", vlan_val); system(tmp); } else system("rtkswitch 37 0"); } system("rtkswitch 39 0x02000210"); } if(strcmp(nvram_safe_get("switch_wan1tagid"), "") != 0) // IPTV on LAN4 (port 0) { vlan_val = atoi(nvram_safe_get("switch_wan1tagid")); if((vlan_val >= 2) && (vlan_val <= 4094)) { sprintf(tmp, "rtkswitch 36 %d", vlan_val); system(tmp); } if(strcmp(nvram_safe_get("switch_wan1prio"), "") != 0) { vlan_val = atoi(nvram_safe_get("switch_wan1prio")); if((vlan_val >= 0) && (vlan_val <= 7)) { sprintf(tmp, "rtkswitch 37 %d", vlan_val); system(tmp); } else system("rtkswitch 37 0"); } if(!strcmp(nvram_safe_get("switch_wan1tagid"), nvram_safe_get("switch_wan2tagid"))) system("rtkswitch 39 0x00030013"); //IPTV=VOIP else system("rtkswitch 39 0x00010011");//IPTV Port: P0 untag 65553 = 0x10 011 } if(strcmp(nvram_safe_get("switch_wan2tagid"), "") != 0) // VoIP on LAN3 (port 1) { vlan_val = atoi(nvram_safe_get("switch_wan2tagid")); if((vlan_val >= 2) && (vlan_val <= 4094)) { sprintf(tmp, "rtkswitch 36 %d", vlan_val); system(tmp); } if(strcmp(nvram_safe_get("switch_wan2prio"), "") != 0) { vlan_val = atoi(nvram_safe_get("switch_wan2prio")); if((vlan_val >= 0) && (vlan_val <= 7)) { sprintf(tmp, "rtkswitch 37 %d", vlan_val); system(tmp); } else system("rtkswitch 37 0"); } if(!strcmp(nvram_safe_get("switch_wan1tagid"), nvram_safe_get("switch_wan2tagid"))) system("rtkswitch 39 0x00030013"); //IPTV=VOIP else system("rtkswitch 39 0x00020012");//VoIP Port: P1 untag } } } else { sprintf(parm_buf, "%d", stbport); if (stbport) eval("rtkswitch", "8", parm_buf); } /* unknown unicast storm control */ if (!nvram_get("switch_ctrlrate_unknown_unicast")) controlrate_unknown_unicast = 0; else controlrate_unknown_unicast = atoi(nvram_get("switch_ctrlrate_unknown_unicast")); if (controlrate_unknown_unicast < 0 || controlrate_unknown_unicast > 1024) controlrate_unknown_unicast = 0; if (controlrate_unknown_unicast) { sprintf(parm_buf, "%d", controlrate_unknown_unicast); eval("rtkswitch", "22", parm_buf); } /* unknown multicast storm control */ if (!nvram_get("switch_ctrlrate_unknown_multicast")) controlrate_unknown_multicast = 0; else controlrate_unknown_multicast = atoi(nvram_get("switch_ctrlrate_unknown_multicast")); if (controlrate_unknown_multicast < 0 || controlrate_unknown_multicast > 1024) controlrate_unknown_multicast = 0; if (controlrate_unknown_multicast) { sprintf(parm_buf, "%d", controlrate_unknown_multicast); eval("rtkswitch", "23", parm_buf); } /* multicast storm control */ if (!nvram_get("switch_ctrlrate_multicast")) controlrate_multicast = 0; else controlrate_multicast = atoi(nvram_get("switch_ctrlrate_multicast")); if (controlrate_multicast < 0 || controlrate_multicast > 1024) controlrate_multicast = 0; if (controlrate_multicast) { sprintf(parm_buf, "%d", controlrate_multicast); eval("rtkswitch", "24", parm_buf); } /* broadcast storm control */ if (!nvram_get("switch_ctrlrate_broadcast")) controlrate_broadcast = 0; else controlrate_broadcast = atoi(nvram_get("switch_ctrlrate_broadcast")); if (controlrate_broadcast < 0 || controlrate_broadcast > 1024) controlrate_broadcast = 0; if (controlrate_broadcast) { sprintf(parm_buf, "%d", controlrate_broadcast); eval("rtkswitch", "25", parm_buf); } } else if (is_apmode_enabled()) { model = get_model(); if (model == MODEL_RTN65U || model == MODEL_RTN36U3) eval("rtkswitch", "8", "100"); } #ifdef RTCONFIG_DSL dbG("link up all ports\n"); eval("rtkswitch", "16"); // link up all ports #else dbG("link up wan port(s)\n"); eval("rtkswitch", "114"); // link up wan port(s) #endif }
int qtn_monitor_main(int argc, char *argv[]) { FILE *fp; sigset_t sigs_to_catch; int ret, retval = 0; time_t start_time = uptime(); /* write pid */ if ((fp = fopen("/var/run/qtn_monitor.pid", "w")) != NULL) { fprintf(fp, "%d", getpid()); fclose(fp); } /* set the signal handler */ sigemptyset(&sigs_to_catch); sigaddset(&sigs_to_catch, SIGTERM); sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL); signal(SIGTERM, qtn_monitor_exit); QTN_RESET: ret = rpc_qcsapi_init(1); if (ret < 0) { dbG("rpc_qcsapi_init error, return: %d\n", ret); retval = -1; goto ERROR; } #if 0 /* replaced by STATELESS, send configuration from brcm to qtn */ else if (nvram_get_int("qtn_restore_defaults")) { nvram_unset("qtn_restore_defaults"); rpc_qcsapi_restore_default_config(0); dbG("Restaring Qcsapi init...\n"); sleep(15); goto QTN_RESET; } #endif #if 0 if(nvram_get_int("sw_mode") == SW_MODE_AP && nvram_get_int("wlc_psta") == 1 && nvram_get_int("wlc_band") == 1){ dbG("[sw_mode] start QTN PSTA mode\n"); start_psta_qtn(); } #endif ret = qcsapi_init(); if (ret < 0) { dbG("Qcsapi qcsapi_init error, return: %d\n", ret); retval = -1; goto ERROR; } else dbG("Qcsapi qcsapi init takes %ld seconds\n", uptime() - start_time); dbG("defer lanport_ctrl(1)\n"); lanport_ctrl(1); eval("ifconfig", "br0:1", "down"); #if defined(RTCONFIG_JFFS2ND_BACKUP) check_2nd_jffs(); #endif nvram_set("qtn_ready", "1"); if(nvram_get_int("AllLED") == 0) setAllLedOff(); // dbG("[QTN] update router_command.sh from brcm to qtn\n"); // qcsapi_wifi_run_script("set_test_mode", "update_router_command"); #if 1 /* STATELESS */ if(nvram_get_int("sw_mode") == SW_MODE_AP && nvram_get_int("wlc_psta") == 1 && nvram_get_int("wlc_band") == 1){ dbG("[sw_mode] skip start_psta_qtn, QTN will run scripts automatically\n"); // start_psta_qtn(); }else{ dbG("[***] rpc_parse_nvram_from_httpd\n"); rpc_parse_nvram_from_httpd(1,-1); /* wifi0 */ rpc_parse_nvram_from_httpd(1,1); /* wifi1 */ rpc_parse_nvram_from_httpd(1,2); /* wifi2 */ rpc_parse_nvram_from_httpd(1,3); /* wifi3 */ dbG("[sw_mode] skip start_ap_qtn, QTN will run scripts automatically\n"); // start_ap_qtn(); qcsapi_mac_addr wl_mac_addr; ret = rpc_qcsapi_interface_get_mac_addr(WIFINAME, &wl_mac_addr); if (ret < 0) dbG("rpc_qcsapi_interface_get_mac_addr, return: %d\n", ret); else { nvram_set("1:macaddr", wl_ether_etoa((struct ether_addr *) &wl_mac_addr)); nvram_set("wl1_hwaddr", wl_ether_etoa((struct ether_addr *) &wl_mac_addr)); } rpc_update_wdslist(); if(nvram_get_int("wps_enable") == 1){ ret = rpc_qcsapi_wifi_disable_wps(WIFINAME, 0); if (ret < 0) dbG("rpc_qcsapi_wifi_disable_wps %s error, return: %d\n", WIFINAME, ret); ret = qcsapi_wps_set_ap_pin(WIFINAME, nvram_safe_get("wps_device_pin")); if (ret < 0) dbG("qcsapi_wps_set_ap_pin %s error, return: %d\n", WIFINAME, ret); ret = qcsapi_wps_registrar_set_pp_devname(WIFINAME, 0, (const char *) get_productid()); if (ret < 0) dbG("qcsapi_wps_registrar_set_pp_devname %s error, return: %d\n", WIFINAME, ret); }else{ ret = rpc_qcsapi_wifi_disable_wps(WIFINAME, 1); if (ret < 0) dbG("rpc_qcsapi_wifi_disable_wps %s error, return: %d\n", WIFINAME, ret); } rpc_set_radio(1, 0, nvram_get_int("wl1_radio")); } #endif if(nvram_get_int("wl1_80211h") == 1){ dbG("[80211h] set_80211h_on\n"); qcsapi_wifi_run_script("router_command.sh", "80211h_on"); }else{ dbG("[80211h] set_80211h_off\n"); qcsapi_wifi_run_script("router_command.sh", "80211h_off"); } if(nvram_get_int("sw_mode") == SW_MODE_ROUTER || (nvram_get_int("sw_mode") == SW_MODE_AP && nvram_get_int("wlc_psta") == 0)){ if(nvram_get_int("wl1_chanspec") == 0){ if (nvram_match("1:ccode", "EU")){ if(nvram_get_int("acs_dfs") != 1){ dbG("[dfs] start nodfs scanning and selection\n"); start_nodfs_scan_qtn(); } }else{ /* all country except EU */ dbG("[dfs] start nodfs scanning and selection\n"); start_nodfs_scan_qtn(); } } } if(nvram_get_int("sw_mode") == SW_MODE_AP && nvram_get_int("wlc_psta") == 1 && nvram_get_int("wlc_band") == 0){ ret = qcsapi_wifi_reload_in_mode(WIFINAME, qcsapi_station); if (ret < 0) dbG("qtn reload_in_mode STA fail\n"); } if(nvram_get_int("QTNTELNETSRV") == 1 && nvram_get_int("sw_mode") == SW_MODE_ROUTER){ dbG("[QTNT] enable telnet server\n"); qcsapi_wifi_run_script("router_command.sh", "enable_telnet_srv 1"); } dbG("[dbg] qtn_monitor startup\n"); ERROR: remove("/var/run/qtn_monitor.pid"); if (nvram_get_int("led_disable") == 1) { setAllLedOff_qtn(); // qcsapi_wifi_run_script("router_command.sh", "wifi_led_off"); // qcsapi_led_set(1, 0); } return retval; }
void rpc_parse_nvram_from_httpd(int unit, int subunit) { int ret = 0; if (!rpc_qtn_ready()) return; if (unit == 1 && subunit == -1){ rpc_qcsapi_set_SSID(WIFINAME, nvram_safe_get("wl1_ssid")); rpc_qcsapi_set_SSID_broadcast(WIFINAME, nvram_safe_get("wl1_closed")); rpc_qcsapi_set_vht(nvram_safe_get("wl1_nmode_x")); rpc_qcsapi_set_bw(nvram_safe_get("wl1_bw")); rpc_qcsapi_set_channel(nvram_safe_get("wl1_chanspec")); rpc_qcsapi_set_beacon_type(WIFINAME, nvram_safe_get("wl1_auth_mode_x")); rpc_qcsapi_set_WPA_encryption_modes(WIFINAME, nvram_safe_get("wl1_crypto")); rpc_qcsapi_set_key_passphrase(WIFINAME, nvram_safe_get("wl1_wpa_psk")); rpc_qcsapi_set_dtim(nvram_safe_get("wl1_dtim")); rpc_qcsapi_set_beacon_interval(nvram_safe_get("wl1_bcn")); rpc_set_radio(1, 0, nvram_get_int("wl1_radio")); rpc_update_macmode(nvram_safe_get("wl1_macmode")); rpc_update_wlmaclist(); rpc_update_wdslist(); rpc_update_wdslist(); rpc_update_wds_psk(nvram_safe_get("wl1_wds_psk")); rpc_update_ap_isolate(WIFINAME, atoi(nvram_safe_get("wl1_ap_isolate"))); if(nvram_get_int("wps_enable") == 1){ ret = rpc_qcsapi_wifi_disable_wps(WIFINAME, 0); if (ret < 0) dbG("rpc_qcsapi_wifi_disable_wps %s error, return: %d\n", WIFINAME, ret); ret = qcsapi_wps_set_ap_pin(WIFINAME, nvram_safe_get("wps_device_pin")); if (ret < 0) dbG("qcsapi_wps_set_ap_pin %s error, return: %d\n", WIFINAME, ret); ret = qcsapi_wps_registrar_set_pp_devname(WIFINAME, 0, (const char *) get_productid()); if (ret < 0) dbG("qcsapi_wps_registrar_set_pp_devname %s error, return: %d\n", WIFINAME, ret); }else{ ret = rpc_qcsapi_wifi_disable_wps(WIFINAME, 1); if (ret < 0) dbG("rpc_qcsapi_wifi_disable_wps %s error, return: %d\n", WIFINAME, ret); } ret = qcsapi_wps_upnp_enable(WIFINAME, 0); if (ret < 0) dbG("disable WPS UPnP %s error, return: %d\n", WIFINAME, ret); if(nvram_get_int("sw_mode") == SW_MODE_ROUTER || (nvram_get_int("sw_mode") == SW_MODE_AP && nvram_get_int("wlc_psta") == 1)){ if(nvram_get_int("wl1_mumimo") == 1){ dbG("mu-mimo: enable MU-MIMO\n"); ret = qcsapi_wifi_set_enable_mu(WIFINAME, 1); }else{ dbG("mu-mimo: disable MU-MIMO\n"); qcsapi_wifi_set_enable_mu(WIFINAME, 0); } if (ret < 0) dbG("enable_mu %s error, return: %d\n", WIFINAME, ret); } #ifdef RTCONFIG_IPV6 if (get_ipv6_service() == IPV6_DISABLED) qcsapi_wifi_run_script("router_command.sh", "ipv6_off wifi0"); else qcsapi_wifi_run_script("router_command.sh", "ipv6_on wifi0"); #endif }else if (unit == 1 && subunit == 1){ if(nvram_get_int("wl1.1_bss_enabled") == 1){ rpc_update_mbss("wl1.1_ssid", nvram_safe_get("wl1.1_ssid")); rpc_update_mbss("wl1.1_bss_enabled", nvram_safe_get("wl1.1_bss_enabled")); rpc_update_mbss("wl1.1_wpa_psk", nvram_safe_get("wl1.1_wpa_psk")); rpc_update_mbss("wl1.1_wpa_gtk_rekey", nvram_safe_get("wl1.1_wpa_gtk_rekey")); rpc_update_mbss("wl1.1_auth_mode_x", nvram_safe_get("wl1.1_auth_mode_x")); rpc_update_mbss("wl1.1_mbss", nvram_safe_get("wl1.1_mbss")); if(nvram_get_int("sw_mode") == SW_MODE_ROUTER){ if(nvram_match("wl1.1_lanaccess", "off") && !nvram_match("wl1.1_lanaccess", "")){ dbG("[lanaccess] wifi1 lanaccess off\n"); // libqcsapi_client/qtn/qtn_vlan.h // QVLAN_VID_ALL: 0xffff qcsapi_wifi_vlan_config("wifi0", e_qcsapi_vlan_enable, 0xffff /* QVLAN_VID_ALL */); qcsapi_wifi_vlan_config("wifi1", e_qcsapi_vlan_add, 4000 /* vid */); }else{ qcsapi_wifi_vlan_config("wifi1", e_qcsapi_vlan_del, 4000 /* vid */); } } #ifdef RTCONFIG_IPV6 if (get_ipv6_service() == IPV6_DISABLED) qcsapi_wifi_run_script("router_command.sh", "ipv6_off wifi1"); else qcsapi_wifi_run_script("router_command.sh", "ipv6_on wifi1"); #endif } else{ qcsapi_wifi_remove_bss(wl_vifname_qtn(unit, subunit)); } }else if (unit == 1 && subunit == 2){ if(nvram_get_int("wl1.2_bss_enabled") == 1){ rpc_update_mbss("wl1.2_ssid", nvram_safe_get("wl1.2_ssid")); rpc_update_mbss("wl1.2_bss_enabled", nvram_safe_get("wl1.2_bss_enabled")); rpc_update_mbss("wl1.2_wpa_psk", nvram_safe_get("wl1.2_wpa_psk")); rpc_update_mbss("wl1.2_wpa_gtk_rekey", nvram_safe_get("wl1.2_wpa_gtk_rekey")); rpc_update_mbss("wl1.2_auth_mode_x", nvram_safe_get("wl1.2_auth_mode_x")); rpc_update_mbss("wl1.2_mbss", nvram_safe_get("wl1.2_mbss")); if(nvram_get_int("sw_mode") == SW_MODE_ROUTER){ if(nvram_match("wl1.2_lanaccess", "off") && !nvram_match("wl1.2_lanaccess", "")){ dbG("[lanaccess] wifi2 lanaccess off\n"); // libqcsapi_client/qtn/qtn_vlan.h // QVLAN_VID_ALL: 0xffff qcsapi_wifi_vlan_config("wifi0", e_qcsapi_vlan_enable, 0xffff /* QVLAN_VID_ALL */); qcsapi_wifi_vlan_config("wifi2", e_qcsapi_vlan_add, 4001 /* vid */); }else{ qcsapi_wifi_vlan_config("wifi1", e_qcsapi_vlan_del, 4001 /* vid */); } } #ifdef RTCONFIG_IPV6 if (get_ipv6_service() == IPV6_DISABLED) qcsapi_wifi_run_script("router_command.sh", "ipv6_off wifi2"); else qcsapi_wifi_run_script("router_command.sh", "ipv6_on wifi2"); #endif } else{ qcsapi_wifi_remove_bss(wl_vifname_qtn(unit, subunit)); } }else if (unit == 1 && subunit == 3){ if(nvram_get_int("wl1.3_bss_enabled") == 1){ rpc_update_mbss("wl1.3_ssid", nvram_safe_get("wl1.3_ssid")); rpc_update_mbss("wl1.3_bss_enabled", nvram_safe_get("wl1.3_bss_enabled")); rpc_update_mbss("wl1.3_wpa_psk", nvram_safe_get("wl1.3_wpa_psk")); rpc_update_mbss("wl1.3_wpa_gtk_rekey", nvram_safe_get("wl1.3_wpa_gtk_rekey")); rpc_update_mbss("wl1.3_auth_mode_x", nvram_safe_get("wl1.3_auth_mode_x")); rpc_update_mbss("wl1.3_mbss", nvram_safe_get("wl1.3_mbss")); if(nvram_get_int("sw_mode") == SW_MODE_ROUTER){ if(nvram_match("wl1.3_lanaccess", "off") && !nvram_match("wl1.3_lanaccess", "")){ dbG("[lanaccess] wifi3 lanaccess off\n"); // libqcsapi_client/qtn/qtn_vlan.h // QVLAN_VID_ALL: 0xffff qcsapi_wifi_vlan_config("wifi0", e_qcsapi_vlan_enable, 0xffff /* QVLAN_VID_ALL */); qcsapi_wifi_vlan_config("wifi3", e_qcsapi_vlan_add, 4002 /* vid */); }else{ qcsapi_wifi_vlan_config("wifi1", e_qcsapi_vlan_del, 4002 /* vid */); } } #ifdef RTCONFIG_IPV6 if (get_ipv6_service() == IPV6_DISABLED) qcsapi_wifi_run_script("router_command.sh", "ipv6_off wifi3"); else qcsapi_wifi_run_script("router_command.sh", "ipv6_on wifi3"); #endif } else{ qcsapi_wifi_remove_bss(wl_vifname_qtn(unit, subunit)); } } if(nvram_get_int("sw_mode") == SW_MODE_ROUTER){ create_mbssid_vlan(); } /* disable UPNP */ qcsapi_wps_upnp_enable(WIFINAME, 0); // rpc_show_config(); }
void rpc_parse_nvram_from_httpd(int unit, int subunit) { if (!rpc_qtn_ready()) return; if (unit == 1 && subunit == -1){ rpc_qcsapi_set_SSID(WIFINAME, nvram_safe_get("wl1_ssid")); rpc_qcsapi_set_SSID_broadcast(WIFINAME, nvram_safe_get("wl1_closed")); rpc_qcsapi_set_vht(nvram_safe_get("wl1_nmode_x")); rpc_qcsapi_set_bw(nvram_safe_get("wl1_bw")); rpc_qcsapi_set_channel(nvram_safe_get("wl1_chanspec")); rpc_qcsapi_set_beacon_type(WIFINAME, nvram_safe_get("wl1_auth_mode_x")); rpc_qcsapi_set_WPA_encryption_modes(WIFINAME, nvram_safe_get("wl1_crypto")); rpc_qcsapi_set_key_passphrase(WIFINAME, nvram_safe_get("wl1_wpa_psk")); rpc_qcsapi_set_dtim(nvram_safe_get("wl1_dtim")); rpc_qcsapi_set_beacon_interval(nvram_safe_get("wl1_bcn")); rpc_set_radio(1, 0, nvram_get_int("wl1_radio")); rpc_update_macmode(nvram_safe_get("wl1_macmode")); rpc_update_wlmaclist(); rpc_update_wdslist(); rpc_update_wdslist(); rpc_update_wds_psk(nvram_safe_get("wl1_wds_psk")); rpc_update_ap_isolate(WIFINAME, atoi(nvram_safe_get("wl1_ap_isolate"))); if(nvram_get_int("wl1_80211h") == 1){ dbG("[80211h] set_80211h_on\n"); qcsapi_wifi_run_script("router_command.sh", "80211h_on"); }else{ dbG("[80211h] set_80211h_off\n"); qcsapi_wifi_run_script("router_command.sh", "80211h_off"); } if(nvram_get_int("sw_mode") == SW_MODE_ROUTER || (nvram_get_int("sw_mode") == SW_MODE_AP && nvram_get_int("wlc_psta") == 0)){ if(nvram_get_int("wl1_chanspec") == 0){ if (nvram_match("1:ccode", "EU")){ if(nvram_get_int("acs_dfs") != 1){ dbG("[dfs] start nodfs scanning and selection\n"); start_nodfs_scan_qtn(); } }else{ /* all country except EU */ dbG("[dfs] start nodfs scanning and selection\n"); start_nodfs_scan_qtn(); } } } }else if (unit == 1 && subunit == 1){ if(nvram_get_int("wl1.1_bss_enabled") == 1){ rpc_update_mbss("wl1.1_ssid", nvram_safe_get("wl1.1_ssid")); rpc_update_mbss("wl1.1_bss_enabled", nvram_safe_get("wl1.1_bss_enabled")); rpc_update_mbss("wl1.1_wpa_psk", nvram_safe_get("wl1.1_wpa_psk")); rpc_update_mbss("wl1.1_wpa_gtk_rekey", nvram_safe_get("wl1.1_wpa_gtk_rekey")); rpc_update_mbss("wl1.1_auth_mode_x", nvram_safe_get("wl1.1_auth_mode_x")); rpc_update_mbss("wl1.1_mbss", nvram_safe_get("wl1.1_mbss")); } else{ qcsapi_wifi_remove_bss(wl_vifname_qtn(unit, subunit)); } }else if (unit == 1 && subunit == 2){ if(nvram_get_int("wl1.2_bss_enabled") == 1){ rpc_update_mbss("wl1.2_ssid", nvram_safe_get("wl1.2_ssid")); rpc_update_mbss("wl1.2_bss_enabled", nvram_safe_get("wl1.2_bss_enabled")); rpc_update_mbss("wl1.2_wpa_psk", nvram_safe_get("wl1.2_wpa_psk")); rpc_update_mbss("wl1.2_wpa_gtk_rekey", nvram_safe_get("wl1.2_wpa_gtk_rekey")); rpc_update_mbss("wl1.2_auth_mode_x", nvram_safe_get("wl1.2_auth_mode_x")); rpc_update_mbss("wl1.2_mbss", nvram_safe_get("wl1.2_mbss")); } else{ qcsapi_wifi_remove_bss(wl_vifname_qtn(unit, subunit)); } }else if (unit == 1 && subunit == 3){ if(nvram_get_int("wl1.3_bss_enabled") == 1){ rpc_update_mbss("wl1.3_ssid", nvram_safe_get("wl1.3_ssid")); rpc_update_mbss("wl1.3_bss_enabled", nvram_safe_get("wl1.3_bss_enabled")); rpc_update_mbss("wl1.3_wpa_psk", nvram_safe_get("wl1.3_wpa_psk")); rpc_update_mbss("wl1.3_wpa_gtk_rekey", nvram_safe_get("wl1.3_wpa_gtk_rekey")); rpc_update_mbss("wl1.3_auth_mode_x", nvram_safe_get("wl1.3_auth_mode_x")); rpc_update_mbss("wl1.3_mbss", nvram_safe_get("wl1.3_mbss")); } else{ qcsapi_wifi_remove_bss(wl_vifname_qtn(unit, subunit)); } } // rpc_show_config(); }
void init_switch_dsl() { // vlan1 => LAN PORT // vlan2 => WAN to modem , send packet to modem , used on modem driver // vlan3 => IPTV port // vlan4 => WAN to Ethernet this is ethernet WAN ifname int stbport; int enable_dsl_wan_dsl_if = 0; int enable_dsl_wan_eth_if = 0; int enable_dsl_wan_iptv_if = 0; #ifdef RTCONFIG_DUALWAN if (get_dualwan_secondary()==WANS_DUALWAN_IF_NONE) { if (get_dualwan_primary()==WANS_DUALWAN_IF_DSL) { enable_dsl_wan_dsl_if = 1; } else if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN) { enable_dsl_wan_eth_if = 1; } } else { if (get_dualwan_primary()==WANS_DUALWAN_IF_DSL) { enable_dsl_wan_dsl_if = 1; } else if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN) { enable_dsl_wan_eth_if = 1; } if (get_dualwan_secondary()==WANS_DUALWAN_IF_DSL) { enable_dsl_wan_dsl_if = 1; } else if (get_dualwan_secondary()==WANS_DUALWAN_IF_LAN) { enable_dsl_wan_eth_if = 1; } } #else enable_dsl_wan_dsl_if = 1; #endif if (is_routing_enabled()) { stbport = atoi(nvram_safe_get("switch_stb_x")); if (stbport < 0 || stbport > 6) stbport = 0; dbG("STB port: %d\n", stbport); if (stbport > 0) { enable_dsl_wan_iptv_if = 1; } } eval("ifconfig", "eth0", "up"); // vlan2 = WAN eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "2"); eval("ifconfig", "vlan2", "up"); if (enable_dsl_wan_dsl_if) { // DSL WAN MODE eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "100"); eval("ifconfig", "vlan100", "up"); eval("ifconfig", "vlan100", "hw", "ether", nvram_safe_get("et0macaddr")); } if (enable_dsl_wan_eth_if) { // vlan4 = ethenet WAN eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "4"); eval("ifconfig", "vlan4", "up"); // ethernet WAN , it needs to use another MAC address eval("ifconfig", "vlan4", "hw", "ether", nvram_safe_get("et1macaddr")); } if (enable_dsl_wan_iptv_if) { // vlan3 = IPTV eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "3"); eval("ifconfig", "vlan3", "up"); // bypass , no need to have another MAC address } }
int start_wps_method(void) { int wps_band; int wps_action; // int wps_method; char *wps_sta_pin; char prefix[]="wlXXXXXX_", tmp[100]; char buf[256] = "SET "; int len = 4; if(getpid()!=1) { notify_rc("start_wps_method"); return 0; } wps_band = nvram_get_int("wps_band"); snprintf(prefix, sizeof(prefix), "wl%d_", wps_band); wps_action = nvram_get_int("wps_action"); // wps_method = nvram_get_int("wps_method"); // useless wps_sta_pin = nvram_safe_get("wps_sta_pin"); if(strlen(wps_sta_pin) && strcmp(wps_sta_pin, "00000000") && (wl_wpsPincheck(wps_sta_pin) == 0)) len += sprintf(buf + len, "wps_method=%d ", WPS_UI_METHOD_PIN); else len += sprintf(buf + len, "wps_method=%d ", WPS_UI_METHOD_PBC); if(nvram_match("wps_version2", "enabled") && strlen(nvram_safe_get("wps_autho_sta_mac"))) len += sprintf(buf + len, "wps_autho_sta_mac=%s ", nvram_safe_get("wps_autho_sta_mac")); if(strlen(wps_sta_pin)) len += sprintf(buf + len, "wps_sta_pin=%s ", wps_sta_pin); else len += sprintf(buf + len, "wps_sta_pin=00000000 "); // len += sprintf(buf + len, "wps_action=%d ", wps_action); len += sprintf(buf + len, "wps_action=%d ", WPS_UI_ACT_ADDENROLLEE); len += sprintf(buf + len, "wps_config_command=%d ", WPS_UI_CMD_START); nvram_set("wps_proc_status", "0"); len += sprintf(buf + len, "wps_pbc_method=%d ", WPS_UI_PBC_SW); len += sprintf(buf + len, "wps_ifname=%s ", nvram_safe_get(strcat_r(prefix, "ifname", tmp))); dbG("wps env buffer: %s\n", buf); // nvram_unset("wps_sta_devname"); // nvram_unset("wps_sta_mac"); // nvram_unset("wps_pinfail"); // nvram_unset("wps_pinfail_mac"); // nvram_unset("wps_pinfail_name"); // nvram_unset("wps_pinfail_state"); set_wps_env(buf); sprintf(tmp, "%lu", uptime()); nvram_set("wps_uptime", tmp); return 0; }
void rpc_parse_nvram_from_httpd(int unit, int subunit) { if (!rpc_qtn_ready()) return; if (unit == 1 && subunit == -1){ rpc_qcsapi_set_SSID(WIFINAME, nvram_safe_get("wl1_ssid")); rpc_qcsapi_set_SSID_broadcast(WIFINAME, nvram_safe_get("wl1_closed")); rpc_qcsapi_set_vht(nvram_safe_get("wl1_nmode_x")); rpc_qcsapi_set_bw(nvram_safe_get("wl1_bw")); rpc_qcsapi_set_channel(nvram_safe_get("wl1_chanspec")); rpc_qcsapi_set_beacon_type(WIFINAME, nvram_safe_get("wl1_auth_mode_x")); rpc_qcsapi_set_WPA_encryption_modes(WIFINAME, nvram_safe_get("wl1_crypto")); rpc_qcsapi_set_key_passphrase(WIFINAME, nvram_safe_get("wl1_wpa_psk")); rpc_qcsapi_set_dtim(nvram_safe_get("wl1_dtim")); rpc_qcsapi_set_beacon_interval(nvram_safe_get("wl1_bcn")); rpc_set_radio(1, 0, nvram_get_int("wl1_radio")); rpc_update_macmode(nvram_safe_get("wl1_macmode")); rpc_update_wlmaclist(); rpc_update_wdslist(); rpc_update_wdslist(); rpc_update_wds_psk(nvram_safe_get("wl1_wds_psk")); rpc_update_ap_isolate(WIFINAME, atoi(nvram_safe_get("wl1_ap_isolate"))); }else if (unit == 1 && subunit == 1){ if(nvram_get_int("wl1.1_bss_enabled") == 1){ rpc_update_mbss("wl1.1_ssid", nvram_safe_get("wl1.1_ssid")); rpc_update_mbss("wl1.1_bss_enabled", nvram_safe_get("wl1.1_bss_enabled")); rpc_update_mbss("wl1.1_wpa_psk", nvram_safe_get("wl1.1_wpa_psk")); rpc_update_mbss("wl1.1_wpa_gtk_rekey", nvram_safe_get("wl1.1_wpa_gtk_rekey")); rpc_update_mbss("wl1.1_auth_mode_x", nvram_safe_get("wl1.1_auth_mode_x")); rpc_update_mbss("wl1.1_mbss", nvram_safe_get("wl1.1_mbss")); if(nvram_get_int("sw_mode") == SW_MODE_ROUTER){ if(nvram_match("wl1.1_lanaccess", "off") && !nvram_match("wl1.1_lanaccess", "")){ dbG("[lanaccess] wifi1 lanaccess off\n"); // libqcsapi_client/qtn/qtn_vlan.h // QVLAN_VID_ALL: 0xffff qcsapi_wifi_vlan_config("wifi0", e_qcsapi_vlan_enable, 0xffff /* QVLAN_VID_ALL */, 0); qcsapi_wifi_vlan_config("wifi1", e_qcsapi_vlan_bind, 4000 /* vid */, 0); }else{ qcsapi_wifi_vlan_config("wifi1", e_qcsapi_vlan_unbind, 4000 /* vid */, 0); } } } else{ qcsapi_wifi_remove_bss(wl_vifname_qtn(unit, subunit)); } }else if (unit == 1 && subunit == 2){ if(nvram_get_int("wl1.2_bss_enabled") == 1){ rpc_update_mbss("wl1.2_ssid", nvram_safe_get("wl1.2_ssid")); rpc_update_mbss("wl1.2_bss_enabled", nvram_safe_get("wl1.2_bss_enabled")); rpc_update_mbss("wl1.2_wpa_psk", nvram_safe_get("wl1.2_wpa_psk")); rpc_update_mbss("wl1.2_wpa_gtk_rekey", nvram_safe_get("wl1.2_wpa_gtk_rekey")); rpc_update_mbss("wl1.2_auth_mode_x", nvram_safe_get("wl1.2_auth_mode_x")); rpc_update_mbss("wl1.2_mbss", nvram_safe_get("wl1.2_mbss")); if(nvram_get_int("sw_mode") == SW_MODE_ROUTER){ if(nvram_match("wl1.2_lanaccess", "off") && !nvram_match("wl1.2_lanaccess", "")){ dbG("[lanaccess] wifi2 lanaccess off\n"); // libqcsapi_client/qtn/qtn_vlan.h // QVLAN_VID_ALL: 0xffff qcsapi_wifi_vlan_config("wifi0", e_qcsapi_vlan_enable, 0xffff /* QVLAN_VID_ALL */, 0); qcsapi_wifi_vlan_config("wifi2", e_qcsapi_vlan_bind, 4001 /* vid */, 0); }else{ qcsapi_wifi_vlan_config("wifi1", e_qcsapi_vlan_unbind, 4001 /* vid */, 0); } } } else{ qcsapi_wifi_remove_bss(wl_vifname_qtn(unit, subunit)); } }else if (unit == 1 && subunit == 3){ if(nvram_get_int("wl1.3_bss_enabled") == 1){ rpc_update_mbss("wl1.3_ssid", nvram_safe_get("wl1.3_ssid")); rpc_update_mbss("wl1.3_bss_enabled", nvram_safe_get("wl1.3_bss_enabled")); rpc_update_mbss("wl1.3_wpa_psk", nvram_safe_get("wl1.3_wpa_psk")); rpc_update_mbss("wl1.3_wpa_gtk_rekey", nvram_safe_get("wl1.3_wpa_gtk_rekey")); rpc_update_mbss("wl1.3_auth_mode_x", nvram_safe_get("wl1.3_auth_mode_x")); rpc_update_mbss("wl1.3_mbss", nvram_safe_get("wl1.3_mbss")); if(nvram_get_int("sw_mode") == SW_MODE_ROUTER){ if(nvram_match("wl1.3_lanaccess", "off") && !nvram_match("wl1.3_lanaccess", "")){ dbG("[lanaccess] wifi3 lanaccess off\n"); // libqcsapi_client/qtn/qtn_vlan.h // QVLAN_VID_ALL: 0xffff qcsapi_wifi_vlan_config("wifi0", e_qcsapi_vlan_enable, 0xffff /* QVLAN_VID_ALL */, 0); qcsapi_wifi_vlan_config("wifi3", e_qcsapi_vlan_bind, 4002 /* vid */, 0); }else{ qcsapi_wifi_vlan_config("wifi1", e_qcsapi_vlan_unbind, 4002 /* vid */, 0); } } } else{ qcsapi_wifi_remove_bss(wl_vifname_qtn(unit, subunit)); } } if(nvram_get_int("sw_mode") == SW_MODE_ROUTER){ create_mbssid_vlan(); } // rpc_show_config(); }
void init_switch_dsl() { // DSLTODO // Eth2 => SoC RGMII 0 => Because we use VLAN, we do not use this interface directly // Eth2.1 => WAN to modem , send packet to modem , used on modem driver // Eth2.2 => LAN PORT // Eth 2.1.50 => for stats, ethernet driver modify modem packets to this VLAN ID // Eth 2.1.51 => bridge for Ethernet and modem, ethernet driver modify modem packet to VLAN ID (51) // and then bridge eth2.2 and eth2.1.51. thus, PC could control modem from LAN port // Eth2.3 => IPTV port // Eth2.4 => WAN to Ethernet this is ethernet WAN ifname int stbport; int enable_dsl_wan_dsl_if = 0; int enable_dsl_wan_eth_if = 0; int enable_dsl_wan_iptv_if = 0; eval("ifconfig", "eth2", "up"); // eth2.1 = WAN eval("vconfig", "add", "eth2", "1"); eval("ifconfig", "eth2.1", "up"); // eth2.2 = LAN eval("vconfig", "add", "eth2", "2"); eval("ifconfig", "eth2.2", "up"); // eth2.3 = IPTV #ifdef RTCONFIG_DUALWAN if (get_dualwan_secondary()==WANS_DUALWAN_IF_NONE) { if (get_dualwan_primary()==WANS_DUALWAN_IF_DSL) { enable_dsl_wan_dsl_if = 1; } else if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN) { enable_dsl_wan_eth_if = 1; } } else { if (get_dualwan_primary()==WANS_DUALWAN_IF_DSL) { enable_dsl_wan_dsl_if = 1; } else if (get_dualwan_primary()==WANS_DUALWAN_IF_LAN) { enable_dsl_wan_eth_if = 1; } if (get_dualwan_secondary()==WANS_DUALWAN_IF_DSL) { enable_dsl_wan_dsl_if = 1; } else if (get_dualwan_secondary()==WANS_DUALWAN_IF_LAN) { enable_dsl_wan_eth_if = 1; } } #else enable_dsl_wan_dsl_if = 1; #endif if (is_routing_enabled()) { stbport = atoi(nvram_safe_get("switch_stb_x")); if (stbport < 0 || stbport > 6) stbport = 0; dbG("STB port: %d\n", stbport); if (stbport > 0) { enable_dsl_wan_iptv_if = 1; } } if (enable_dsl_wan_dsl_if) { // DSL WAN MODE eval("vconfig", "add", "eth2.1", "1"); eval("ifconfig", "eth2.1.1", "up"); eval("ifconfig", "eth2.1", "hw", "ether", nvram_safe_get("et0macaddr")); } if (enable_dsl_wan_eth_if) { // eth2.4 = ethenet WAN eval("vconfig", "add", "eth2", "4"); eval("ifconfig", "eth2.4", "up"); // ethernet WAN , it needs to use another MAC address eval("ifconfig", "eth2.4", "hw", "ether", nvram_safe_get("et1macaddr")); } if (enable_dsl_wan_iptv_if) { // eth2.3 = IPTV eval("vconfig", "add", "eth2", "3"); eval("ifconfig", "eth2.3", "up"); // bypass , no need to have another MAC address } // for a dummy interface from trendchip // this is only for stats viewing , non-necessary // do not power up dummay interface. If so, it will send packet out eval("vconfig", "add", "eth2.1", "50"); eval("vconfig", "add", "eth2.1", "51"); }
int start_psta_qtn(void) { static qcsapi_SSID array_ssids[10 /* MAX_SSID_LIST_SIZE */]; int qcsapi_retval; unsigned int iter; qcsapi_unsigned_int sizeof_list = 2 /* DEFAULT_SSID_LIST_SIZE */ ; char *list_ssids[10 /* MAX_SSID_LIST_SIZE */ + 1]; int ret; if (!rpc_qtn_ready()) { dbG("5 GHz radio is not ready\n"); return -1; } logmessage("start_psta", "media bridge is running..."); qcsapi_retval = qcsapi_wifi_reload_in_mode(WIFINAME, qcsapi_station); if (qcsapi_retval >= 0) { fprintf(stderr, "reload to STA mode successfuly\n" ); } else { fprintf(stderr, "reload to STA mode failed\n" ); } for (iter = 0; iter < sizeof_list; iter++) { list_ssids[iter] = array_ssids[iter]; *(list_ssids[iter]) = '\0'; } qcsapi_retval = qcsapi_SSID_get_SSID_list(WIFINAME, sizeof_list, &list_ssids[0]); if (qcsapi_retval >= 0) { for (iter = 0; iter < sizeof_list; iter++) { if ((list_ssids[iter] == NULL) || strlen(list_ssids[iter]) < 1) { break; } fprintf(stderr, "remove [%s]\n", list_ssids[iter]); qcsapi_SSID_remove_SSID(WIFINAME, array_ssids[iter]); } } // verify ssid, if not exists, create new one char ssid[33]; strncpy(ssid, nvram_safe_get("wlc_ssid"), sizeof(ssid)); logmessage("start_psta", "verify ssid [%s]", ssid); if(qcsapi_SSID_verify_SSID(WIFINAME, ssid) < 0){ logmessage("start_psta", "Not such SSID in sta mode\n"); if(qcsapi_SSID_create_SSID(WIFINAME, ssid) < 0) logmessage("start_psta", "fail to create SSID in sta mode\n"); } // check security char auth[8]; char crypto[16]; char beacon[] = "WPAand11i"; char encryption[] = "TKIPandAESEncryption"; char key[65]; uint32_t index = 0; strncpy(auth, nvram_safe_get("wlc_auth_mode"), sizeof(auth)); strncpy(crypto, nvram_safe_get("wlc_crypto"), sizeof(crypto)); strncpy(key, nvram_safe_get("wlc_wpa_psk"), sizeof(key)); if(!strcmp(auth, "psk2") && !strcmp(crypto, "aes")){ memcpy(beacon, "11i", strlen("11i") + 1); memcpy(encryption, "AESEncryption", strlen("AESEncryption") + 1); } else if(!strcmp(auth, "pskpsk2") && !strcmp(crypto, "aes") ){ memcpy(beacon, "WPAand11i", strlen("WPAand11i") + 1); memcpy(encryption, "AESEncryption", strlen("AESEncryption") + 1); } else if(!strcmp(auth, "pskpsk2") && !strcmp(crypto, "tkip+aes") ){ memcpy(beacon, "WPAand11i", strlen("WPAand11i") + 1); memcpy(encryption, "TKIPandAESEncryption", strlen("TKIPandAESEncryption") + 1); } else{ logmessage("start_psta", "not support such authentication & encryption\n"); } logmessage("start_psta", "ssid=%s, auth=%s, crypto=%s, encryption=%s, key=%s\n", ssid, auth, crypto, encryption, key); if(!strcmp(auth, "open")){ if(qcsapi_SSID_set_authentication_mode(WIFINAME, ssid, "NONE") < 0) logmessage("start_psta", "fail to setup a open-none sta\n"); } else{ if(qcsapi_SSID_set_protocol(WIFINAME, ssid, beacon) < 0) logmessage("start_psta", "fail to setup protocol in sta\n"); if(qcsapi_SSID_set_authentication_mode(WIFINAME, ssid, "PSKAuthentication") < 0) logmessage("start_psta", "fail to setup authentiocation type in sta\n"); if(qcsapi_SSID_set_key_passphrase(WIFINAME, ssid, index, key) < 0) logmessage("start_psta", "fail to set key in sta\n"); } // eval("wpa_cli", "reconfigure"); ret = qcsapi_wifi_run_script("router_command.sh", "wpa_cli_reconfigure"); if (ret < 0) { fprintf(stderr, "[psta] router_command.sh: wpa_cli_reconfigure error\n"); return -1; } logmessage("start_psta", "start_psta done!\n"); return 1; }
void config_switch_dsl_set_dsl() { // DSL WAN , no IPTV , USB also goes here dbG("wan port = dsl\n"); eval("rtkswitch", "8", "0"); }
int wlcscan_core_qtn(char *ofile, char *ifname) { int i; int scanstatus = -1; uint32_t count; qcsapi_ap_properties params; char buff[256]; FILE *fp_apscan; if (!rpc_qtn_ready()) { dbG("5 GHz radio is not ready\n"); return -1; } logmessage("wlcscan", "start wlcscan scan\n"); /* clean APSCAN_INFO */ lock_qtn_apscan = file_lock("sitesurvey"); if((fp_apscan = fopen(ofile, "a")) != NULL){ fclose(fp_apscan); } file_unlock(lock_qtn_apscan); // start scan AP // if(qcsapi_wifi_start_scan(ifname)){ if(qcsapi_wifi_start_scan_ext(ifname, IEEE80211_PICK_ALL | IEEE80211_PICK_NOPICK_BG)){ dbg("fail to start AP scan\n"); return 0; } fprintf(stderr, "ok to start AP scan\n"); // loop for check scan status while(1){ if(qcsapi_wifi_get_scan_status(ifname, &scanstatus) < 0){ dbg("scan error occurs\n"); return 0; } // if scanstatus = 0 , no scan is running if(scanstatus == 0) break; else{ dbg("scan is running...\n"); sleep(1); } } // check AP scan if(qcsapi_wifi_get_results_AP_scan(ifname, &count) < 0){ dbg("fail to get AP scan results, ifname=%s, count=%d\n", ifname, (int)count); return 0; } if((int)count > 0){ if((fp_apscan = fopen(ofile, "a")) == NULL){ dbg("fail to write to [%s]\n", ofile); return 0; } else{ // for loop for(i = 0; i < (int)count; i++){ // get properties of AP if(!qcsapi_wifi_get_properties_AP(ifname, (uint32_t)i, ¶ms)){ show_ap_properties((uint32_t)i, ¶ms, buff); fprintf(fp_apscan, "%s", buff); } else{ dbg("fail to get AP properties\n"); fclose(fp_apscan); } if (i == (int)count - 1){ fprintf(fp_apscan, "\n"); }else{ fprintf(fp_apscan, "\n"); } } // for loop } } fclose(fp_apscan); return 1; }