void configure_wimax(void) { char *mode = "0"; char *dev = "ofdm"; if (nvram_match("ofdm_duplex", "TDD")) mode = "0"; if (nvram_match("ofdm_duplex", "H-FDD")) mode = "1"; if (nvram_match("ofdm_mode", "disabled")) return; char width[32]; sprintf(width, "%smhz", nvram_safe_get("ofdm_width")); eval("/sub/lm_scripts/go_ss", width, "0", mode); if (!nvram_match("ofdm_mode", "sta")) { char bridged[32]; sprintf(bridged, "%s_bridged", dev); if (nvram_default_match(bridged, "1", "1")) { eval("ifconfig", dev, "0.0.0.0", "up"); br_add_interface(getBridge(dev), dev); eval("ifconfig", dev, "0.0.0.0", "up"); } else { eval("ifconfig", dev, nvram_nget("%s_ipaddr", dev), "netmask", nvram_nget("%s_netmask", dev), "up"); } } else { char bridged[32]; sprintf(bridged, "%s_bridged", dev); if (nvram_default_match(bridged, "0", "1")) { eval("ifconfig", dev, nvram_nget("%s_ipaddr", dev), "netmask", nvram_nget("%s_netmask", dev), "up"); } } }
void start_pppoeserver(void) { /* // calculate uptime for the GUI //proc/net/dev differenz = speed. interface aus datei. fp = fopen("/tmp/pppoeserver/calc-uptime.sh", "w"); fprintf(fp, "#!/bin/sh\n" "pppoe_connected=/tmp/pppoe_connected\n" //for i in `cat pppoe_connected |awk '{print $4}'` ; do sed '%i,s/`awk '{print $4}'`/neu/g' pppoe_connected > pppoe_connected.tmp ; done "for i in `cat pppoe_connected |awk '{print $4}'` ; do\n" "\tCONTIME=`grep $PEERNAME /tmp/pppoe_peer.db | awk '{print $1}'`\n" "SENT=`grep $PEERNAME /tmp/pppoe_peer.db | awk '{print $2}'`\n" "done\n" ) fclose(fp); chmod("/tmp/pppoeserver/calc-uptime.sh", 0744);*/ FILE *fp; if (nvram_default_match("pppoeserver_enabled", "1", "0")) { add_pppoe_natrule(); if (nvram_default_match("pppoeradius_enabled", "0", "0")) { mkdir("/tmp/pppoeserver", 0777); fp = fopen("/tmp/pppoeserver/pppoe-server-options", "wb"); do_pppoeconfig(fp); fprintf(fp, "chap-secrets /tmp/pppoeserver/chap-secrets\n"); fclose(fp); // parse chaps from nvram to file static char word[256]; char *next, *wordlist; char *user, *pass, *ip, *enable; wordlist = nvram_safe_get("pppoeserver_chaps"); fp = fopen("/tmp/pppoeserver/chap-secrets", "wb"); foreach(word, wordlist, next) { pass = word; user = strsep(&pass, ":"); if (!user || !pass) continue; ip = pass; pass = strsep(&ip, ":"); if (!pass || !ip) continue; enable = ip; ip = strsep(&enable, ":"); if (!ip || !enable) continue; if (!strcmp(ip, "0.0.0.0")) ip = "*"; if (!strcmp(enable, "on")) fprintf(fp, "%s * %s %s\n", user, pass, ip); }
void start_radius(char *prefix) { // wrt-radauth $IFNAME $server $port $share $override $mackey $maxun & if (nvram_nmatch("1", "%s_radauth", prefix) && nvram_nmatch("ap", "%s_mode", prefix)) { char *server = nvram_nget("%s_radius_ipaddr", prefix); char *port = nvram_nget("%s_radius_port", prefix); char *share = nvram_nget("%s_radius_key", prefix); char *ifname = nvram_nget("%s_ifname", prefix); char type[32]; sprintf(type, "%s_radmactype", prefix); char *pragma = ""; if (nvram_default_match(type, "0", "0")) pragma = "-n1 "; if (nvram_match(type, "1")) pragma = "-n2 "; if (nvram_match(type, "2")) pragma = "-n3 "; if (nvram_match(type, "3")) pragma = ""; sleep(1); // some delay is usefull sysprintf("wrt-radauth %s %s %s %s %s %s %s %s &", pragma, ifname, server, port, share, nvram_nget("%s_radius_override", prefix), nvram_nget("%s_radmacpassword", prefix), nvram_nget("%s_max_unauth_users", prefix)); } }
void stop_pptpd(void) { stop_process("pptpd", "pptp server"); stop_process("bcrelay", "pptp broadcast relay"); unlink("/tmp/pptp_connected"); if (nvram_default_match("sys_enable_jffs2", "1", "0")) system("/bin/cp /tmp/pptp_peer.db /jffs/etc/"); #ifdef HAVE_PPTP_ACCEL eval("rmmod","pptp"); #endif return; }
void start_vlantagging(void) { static char word[256]; char *next, *wordlist; wordlist = nvram_safe_get("vlan_tags"); foreach(word, wordlist, next) { char *port = word; char *tag = strsep(&port, ">"); char *prio = port; strsep(&prio, ">"); if (!tag || !port) { break; } if (!prio) prio = "0"; eval("vconfig", "set_name_type", "DEV_PLUS_VID_NO_PAD"); eval("vconfig", "add", tag, port); char vlan_name[32]; sprintf(vlan_name, "%s.%s", tag, port); eval("vconfig", "set_egress_map", vlan_name, "0", prio); char var[64]; sprintf(var, "%s_bridged", vlan_name); if (nvram_default_match(var, "1", "1")) { eval("ifconfig", vlan_name, "0.0.0.0", "up"); } else { eval("ifconfig", vlan_name, nvram_nget("%s_ipaddr", vlan_name), "netmask", nvram_nget("%s_netmask", vlan_name), "up"); } }
void start_pptpd(void) { int ret = 0, mss = 0; char *lpTemp; FILE *fp; if (!nvram_invmatch("pptpd_enable", "0")) { stop_pptpd(); return; } #ifdef HAVE_PPTP_ACCEL insmod("pptp"); #endif // cprintf("stop vpn modules\n"); // stop_vpn_modules (); // copy existing peer data to /tmp if (nvram_default_match("sys_enable_jffs2", "1", "0")) system("/bin/cp /jffs/etc/pptp_peer.db /tmp/"); // Create directory for use by pptpd daemon and its supporting files mkdir("/tmp/pptpd", 0744); cprintf("open options file\n"); // Create options file that will be unique to pptpd to avoid interference // with pppoe and pptp fp = fopen("/tmp/pptpd/options.pptpd", "w"); cprintf("adding radius plugin\n"); if (nvram_match("pptpd_radius", "1")) fprintf(fp, "plugin radius.so\nplugin radattr.so\n" "radius-config-file /tmp/pptpd/radius/radiusclient.conf\n"); cprintf("check if wan_wins = zero\n"); int nowins = 0; if (nvram_match("wan_wins", "0.0.0.0")) { nvram_set("wan_wins", ""); nowins = 1; } if (strlen(nvram_safe_get("wan_wins")) == 0) nowins = 1; cprintf("write config\n"); fprintf(fp, "lock\n" "name *\n" "nobsdcomp\n" "nodeflate\n" "auth\n" "refuse-pap\n" "refuse-eap\n" "refuse-chap\n" "refuse-mschap\n" "require-mschap-v2\n"); if (nvram_match("pptpd_forcemppe", "1")) fprintf(fp, "mppe required,stateless,no40,no56\n"); else fprintf(fp, "mppe stateless\n"); fprintf(fp, "mppc\n" //enable compression "debug\n" "logfd 2\n" "ms-ignore-domain\n" "chap-secrets /tmp/pptpd/chap-secrets\n" "ip-up-script /tmp/pptpd/ip-up\n" "ip-down-script /tmp/pptpd/ip-down\n" "proxyarp\n" "ipcp-accept-local\n" "ipcp-accept-remote\n" "lcp-echo-failure 15\n" "lcp-echo-interval 4\n" // "lcp-echo-adaptive" //disable interval "mtu %s\n" "mru %s\n", nvram_safe_get("pptpd_mtu"), nvram_safe_get("pptpd_mru")); if (!nowins) { fprintf(fp, "ms-wins %s\n", nvram_safe_get("wan_wins")); } if (strlen(nvram_safe_get("pptpd_wins1"))) { fprintf(fp, "ms-wins %s\n", nvram_safe_get("pptpd_wins1")); } if (strlen(nvram_safe_get("pptpd_wins2"))) { fprintf(fp, "ms-wins %s\n", nvram_safe_get("pptpd_wins2")); } struct dns_lists *dns_list = get_dns_list(); if (nvram_match("dnsmasq_enable", "1")) { if (nvram_invmatch("lan_ipaddr", "")) fprintf(fp, "ms-dns %s\n", nvram_safe_get("lan_ipaddr")); } else if (nvram_match("local_dns", "1")) { if (dns_list && (nvram_invmatch("lan_ipaddr", "") || strlen(dns_list->dns_server[0]) > 0 || strlen(dns_list->dns_server[1]) > 0 || strlen(dns_list->dns_server[2]) > 0)) { if (nvram_invmatch("lan_ipaddr", "")) fprintf(fp, "ms-dns %s\n", nvram_safe_get("lan_ipaddr")); if (strlen(dns_list->dns_server[0]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[0]); if (strlen(dns_list->dns_server[1]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[1]); if (strlen(dns_list->dns_server[2]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[2]); } } else { if (dns_list && (strlen(dns_list->dns_server[0]) > 0 || strlen(dns_list->dns_server[1]) > 0 || strlen(dns_list->dns_server[2]) > 0)) { if (strlen(dns_list->dns_server[0]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[0]); if (strlen(dns_list->dns_server[1]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[1]); if (strlen(dns_list->dns_server[2]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[2]); } } if (dns_list) free(dns_list); if (strlen(nvram_safe_get("pptpd_dns1"))) { fprintf(fp, "ms-dns %s\n", nvram_safe_get("pptpd_dns1")); } if (strlen(nvram_safe_get("pptpd_dns2"))) { fprintf(fp, "ms-dns %s\n", nvram_safe_get("pptpd_dns2")); } // Following is all crude and need to be revisited once testing confirms // that it does work // Should be enough for testing.. if (nvram_match("pptpd_radius", "1")) { if (nvram_get("pptpd_radserver") != NULL && nvram_get("pptpd_radpass") != NULL) { fclose(fp); mkdir("/tmp/pptpd/radius", 0744); fp = fopen("/tmp/pptpd/radius/radiusclient.conf", "w"); fprintf(fp, "auth_order radius\n" "login_tries 4\n" "login_timeout 60\n" "radius_timeout 10\n" "nologin /etc/nologin\n" "servers /tmp/pptpd/radius/servers\n" "dictionary /etc/dictionary\n" "seqfile /var/run/radius.seq\n" "mapfile /etc/port-id-map\n" "radius_retries 3\n" "authserver %s:%s\n", nvram_get("pptpd_radserver"), nvram_get("pptpd_radport") ? nvram_get("pptpd_radport") : "radius"); if (nvram_get("pptpd_radserver") != NULL && nvram_get("pptpd_acctport") != NULL) fprintf(fp, "acctserver %s:%s\n", nvram_get("pptpd_radserver"), nvram_get("pptpd_acctport") ? nvram_get("pptpd_acctport") : "radacct"); fclose(fp); fp = fopen("/tmp/pptpd/radius/servers", "w"); fprintf(fp, "%s\t%s\n", nvram_get("pptpd_radserver"), nvram_get("pptpd_radpass")); fclose(fp); } else fclose(fp); } else fclose(fp); // Create pptpd.conf options file for pptpd daemon fp = fopen("/tmp/pptpd/pptpd.conf", "w"); if (nvram_match("pptpd_bcrelay", "1")) fprintf(fp, "bcrelay %s\n", nvram_safe_get("lan_ifname")); fprintf(fp, "connections %s\nlocalip %s\n" "remoteip %s\n", nvram_safe_get("pptpd_conn"),nvram_safe_get("pptpd_lip"), nvram_safe_get("pptpd_rip")); fclose(fp); // Create ip-up and ip-down scripts that are unique to pptpd to avoid // interference with pppoe and pptp /* * adjust for tunneling overhead (mtu - 40 byte IP - 108 byte tunnel * overhead) */ if (nvram_match("mtu_enable", "1")) mss = atoi(nvram_safe_get("wan_mtu")) - 40 - 108; else mss = 1500 - 40 - 108; char bcast[32]; strcpy(bcast, nvram_safe_get("lan_ipaddr")); get_broadcast(bcast, nvram_safe_get("lan_netmask")); fp = fopen("/tmp/pptpd/ip-up", "w"); fprintf(fp, "#!/bin/sh\n" "startservice set_routes\n" // reinitialize "echo $PPPD_PID $1 $5 $6 $PEERNAME >> /tmp/pptp_connected\n" "iptables -I INPUT -i $1 -j ACCEPT\n" "iptables -I FORWARD -i $1 -j ACCEPT\n" // "iptables -I FORWARD -i $1 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu\n" "iptables -t nat -I PREROUTING -i $1 -p udp -m udp --sport 9 -j DNAT --to-destination %s\n" // rule for wake on lan over pptp tunnel "%s\n", bcast, nvram_get("pptpd_ipdown_script") ? nvram_get("pptpd_ipdown_script") : ""); // per peer shaping if (nvram_match("pptpd_radius", "1")) fprintf(fp, "IN=`grep -i RP-Upstream-Speed-Limit /var/run/radattr.$1 | awk '{print $2}'`\n" "OUT=`grep -i RP-Downstream-Speed-Limit /var/run/radattr.$1 | awk '{print $2}'`\n" "if [ ! -z $IN ] && [ $IN -gt 0 ]\n" //Speed limit !0 and !empty "then tc qdisc del root dev $1\n" "\t tc qdisc add dev $1 handle ffff: ingress\n" "\t tc filter add dev $1 parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate \"$IN\"kbit burst \"$IN\"kbit drop flowid :1\n" "fi\n" "if [ ! -z $OUT ] && [ $OUT -gt 0 ]\n" "then tc qdisc del dev $1 ingress\n" "\t tc qdisc add dev $1 root tbf rate \"$OUT\"kbit latency 50ms burst \"$OUT\"kbit\n" "fi\n"); fclose(fp); fp = fopen("/tmp/pptpd/ip-down", "w"); fprintf(fp, "#!/bin/sh\n" "grep -v $PPPD_PID /tmp/pptp_connected > /tmp/pptp_connected.tmp\n" "mv /tmp/pptp_connected.tmp /tmp/pptp_connected\n" // calc connected time and volume per peer "CONTIME=$(($CONNECT_TIME+`grep $PEERNAME /tmp/pptp_peer.db | awk '{print $3}'`))\n" "SENT=$(($BYTES_SENT+`grep $PEERNAME /tmp/pptp_peer.db | awk '{print $4}'`))\n" "RCVD=$(($BYTES_RCVD+`grep $PEERNAME /tmp/pptp_peer.db | awk '{print $5}'`))\n" "grep -v $PEERNAME /tmp/ppp_peer.db > /tmp/pptp_peer.db.tmp\n" "mv /tmp/pptp_peer.db.tmp /tmp/pptp_peer.db\n" "echo \"$PEERNAME $CONTIME $SENT $RCVD\" >> /tmp/pptp_peer.db\n" "iptables -D FORWARD -i $1 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu\n" "iptables -D INPUT -i $1 -j ACCEPT\n" "iptables -D FORWARD -i $1 -j ACCEPT\n" "iptables -t nat -D PREROUTING -i $1 -p udp -m udp --sport 9 -j DNAT --to-destination %s\n" // rule for wake on lan over pptp tunnel "%s\n", bcast, nvram_get("pptpd_ipdown_script") ? nvram_get("pptpd_ipdown_script") : ""); if (nvram_match("pptpd_radius", "1")) fprintf(fp, "tc qdisc del root dev $1\n" "tc qdisc del ingress dev $1\n"); fclose(fp); chmod("/tmp/pptpd/ip-up", 0744); chmod("/tmp/pptpd/ip-down", 0744); // Exctract chap-secrets from nvram and add the default account with // routers password lpTemp = nvram_safe_get("pptpd_auth"); fp = fopen("/tmp/pptpd/chap-secrets", "w"); // fprintf (fp, "root\t*\t%s\t*\n", nvram_safe_get ("http_passwd")); if (strlen(lpTemp) != 0) fprintf(fp, "%s\n", lpTemp); fclose(fp); chmod("/tmp/pptpd/chap-secrets", 0600); // Execute pptpd daemon ret = eval("pptpd", "-c", "/tmp/pptpd/pptpd.conf", "-o", "/tmp/pptpd/options.pptpd"); dd_syslog(LOG_INFO, "pptpd : pptp daemon successfully started\n"); return; }
static struct wifi_channels *list_channelsext(const char *ifname, int allchans) { struct ieee80211req_chaninfo chans; struct ieee80211req_chaninfo achans; const struct ieee80211_channel *c; int i; fprintf(stderr, "list channels for %s\n", ifname); if (do80211priv (ifname, IEEE80211_IOCTL_GETCHANINFO, &chans, sizeof(chans)) < 0) { fprintf(stderr, "unable to get channel information\n"); return NULL; } if (!allchans) { uint8_t active[64]; if (do80211priv (ifname, IEEE80211_IOCTL_GETCHANLIST, &active, sizeof(active)) < 0) { fprintf(stderr, "unable to get active channel list\n"); return NULL; } memset(&achans, 0, sizeof(achans)); for (i = 0; i < chans.ic_nchans; i++) { c = &chans.ic_chans[i]; if (isset(active, c->ic_ieee) || allchans) achans.ic_chans[achans.ic_nchans++] = *c; } } else achans = chans; struct wifi_channels *list = (struct wifi_channels *)safe_malloc(sizeof(struct wifi_channels) * (achans.ic_nchans + 1)); (void)memset(list, 0, (sizeof(struct wifi_channels)*((achans.ic_nchans + 1)))); char wl_mode[16]; char wl_turbo[16]; sprintf(wl_mode, "%s_net_mode", ifname); sprintf(wl_turbo, "%s_channelbw", ifname); int l = 0; int up = 0; char sb[32]; sprintf(sb, "%s_nctrlsb", ifname); if (nvram_match(sb, "upper")) up = 1; for (i = 0; i < achans.ic_nchans; i++) { #ifdef HAVE_BUFFALO if (achans.ic_chans[i].ic_flags & IEEE80211_CHAN_RADARFOUND) //filter channels with detected radar continue; #endif // filter out A channels if mode isnt A-Only or mixed if (IEEE80211_IS_CHAN_5GHZ(&achans.ic_chans[i])) { if (nvram_invmatch(wl_mode, "a-only") && nvram_invmatch(wl_mode, "mixed") && nvram_invmatch(wl_mode, "n5-only") && nvram_invmatch(wl_mode, "na-only")) { // fprintf(stderr,"5 Ghz %d is not compatible to a-only/mixed/na-only %X\n",achans.ic_chans[i].ic_freq,achans.ic_chans[i].ic_flags); continue; } if (nvram_match(wl_turbo, "40") && (nvram_match(wl_mode, "n5-only") || nvram_match(wl_mode, "mixed") || nvram_match(wl_mode, "na-only"))) { if (up && !IEEE80211_IS_CHAN_11NA_HT40PLUS (&achans.ic_chans[i])) continue; if (!up && !IEEE80211_IS_CHAN_11NA_HT40MINUS (&achans.ic_chans[i])) continue; } } // filter out B/G channels if mode isnt g-only, b-only or mixed if (IEEE80211_IS_CHAN_2GHZ(&achans.ic_chans[i])) { if (nvram_invmatch(wl_mode, "g-only") && nvram_invmatch(wl_mode, "mixed") && nvram_invmatch(wl_mode, "b-only") && nvram_invmatch(wl_mode, "n2-only") && nvram_invmatch(wl_mode, "bg-mixed") && nvram_invmatch(wl_mode, "ng-only")) { fprintf(stderr, "%s:%d\n", __func__, __LINE__); continue; } #ifdef HAVE_BUFFALO_SA if(nvram_default_match("region", "SA", "") && (!strcmp(getUEnv("region"), "AP") || !strcmp(getUEnv("region"), "US")) && achans.ic_chans[i].ic_ieee > 11 && achans.ic_chans[i].ic_ieee <= 14) continue; #endif if (nvram_match(wl_turbo, "40") && (nvram_match(wl_mode, "n2-only") || nvram_match(wl_mode, "mixed") || nvram_match(wl_mode, "ng-only"))) { if (up && !IEEE80211_IS_CHAN_11NG_HT40PLUS (&achans.ic_chans[i])) { fprintf(stderr, "%s:%d\n", __func__, __LINE__); continue; } if (!up && !IEEE80211_IS_CHAN_11NG_HT40MINUS (&achans.ic_chans[i])) { fprintf(stderr, "%s:%d\n", __func__, __LINE__); continue; } } } list[l].channel = achans.ic_chans[i].ic_ieee; list[l].freq = achans.ic_chans[i].ic_freq; list[l].noise = -95; // achans.ic_chans[i].ic_noise; l++; } list[l].freq = -1; return list; }
static void do_pppoeconfig(FILE * fp) { int nowins = 0; if (nvram_match("wan_wins", "0.0.0.0")) { nvram_set("wan_wins", ""); nowins = 1; } if (strlen(nvram_safe_get("wan_wins")) == 0) nowins = 1; // fprintf (fp, "crtscts\n"); if (nvram_default_match("pppoeserver_bsdcomp", "0", "0")) fprintf(fp, "nobsdcomp\n"); else fprintf(fp, "bsdcomp 12\n"); if (nvram_default_match("pppoeserver_deflate", "0", "0")) fprintf(fp, "nodeflate\n"); else fprintf(fp, "deflate 12\n"); if (nvram_default_match("pppoeserver_lzs", "0", "0")) fprintf(fp, "nolzs\n"); else fprintf(fp, "lzs\n"); if (nvram_default_match("pppoeserver_mppc", "0", "0")) fprintf(fp, "nomppc\n"); else fprintf(fp, "mppc\n"); if (nvram_default_match("pppoeserver_encryption", "1", "0")) fprintf(fp, "require-mppe-128\n"); else fprintf(fp, "nomppe\n"); fprintf(fp, "auth\n" // "endpoint <epdisc>\n" needed 4 ml // "multilink\n" "refuse-eap\n" // be sure using best auth methode "refuse-pap\n" // "refuse-chap\n" //erlauben??? "refuse-mschap\n" // "require-mschap-v2\n" "nopcomp\n" // no protocol field compression //"default-mru\n" "mtu %s\n" "mru %s\n" "default-asyncmap\n" "noipdefault\n" "defaultroute\n" "netmask 255.255.255.255\n" // "ip-up-script /tmp/pppoeserver/ip-up.sh\n" // "ip-down-script /tmp/pppoeserver/ip-down.sh\n" //"lcp-echo-adaptive\n" "lcp-echo-interval %s\n" "lcp-echo-failure %s\n" "idle %s\n", nvram_safe_get("pppoeserver_mtu"), nvram_safe_get("pppoeserver_mru"), nvram_safe_get("pppoeserver_lcpechoint"), nvram_safe_get("pppoeserver_lcpechofail"), nvram_safe_get("pppoeserver_idle")); if (nvram_match("pppoeserver_interface", "br0")) fprintf(fp, "proxyarp\n" "ktune\n"); else fprintf(fp, "noktune\n"); if (!nowins) { fprintf(fp, "ms-wins %s\n", nvram_safe_get("wan_wins")); } struct dns_lists *dns_list = get_dns_list(); /* if (nvram_match("dnsmasq_enable", "1")) { if (strcmp(getifip(), "")) { fprintf(fp, "ms-dns %s\n", getifip()); fprintf(fp, "ms-dns %s\n", dns_list->dns_server[0]); } } else if (nvram_match("local_dns", "1")) { if (dns_list && (strcmp(getifip(), "") || strlen(dns_list->dns_server[0]) > 0 || strlen(dns_list->dns_server[1]) > 0 || strlen(dns_list->dns_server[2]) > 0)) { if (strcmp(getifip(), "")) fprintf(fp, "ms-dns %s\n", getifip()); if (strlen(dns_list->dns_server[0]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[0]); if (strlen(dns_list->dns_server[1]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[1]); if (strlen(dns_list->dns_server[2]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[2]); } } else { if (dns_list && (strlen(dns_list->dns_server[0]) > 0 || strlen(dns_list->dns_server[1]) > 0 || strlen(dns_list->dns_server[2]) > 0)) { */ if (strlen(dns_list->dns_server[0]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[0]); if (strlen(dns_list->dns_server[1]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[1]); if (strlen(dns_list->dns_server[2]) > 0) fprintf(fp, "ms-dns %s\n", dns_list->dns_server[2]); // } // } if (dns_list) free(dns_list); }
void period_check(int sig) { FILE *fp; unsigned int val = 0; #ifdef HAVE_RADIOOFF if (initses == 1 && nvram_match("radiooff_boot_off", "1") && nvram_match("radiooff_button", "1")) { ses_mode = 1; initses = 0; } #endif // time_t t; // time(&t); // DEBUG("resetbutton: now time=%d\n", t); #if defined(HAVE_MAGICBOX) || defined(HAVE_FONERA) || defined(HAVE_WHRAG108) || defined(HAVE_GATEWORX) || defined(HAVE_STORM) || defined(HAVE_LS2) || defined(HAVE_CA8) || defined(HAVE_TW6600) || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_WP54G) || defined(HAVE_NP28G) || defined(HAVE_SOLO51) || defined(HAVE_OPENRISC) || defined(HAVE_DANUBE) || defined(HAVE_WDR4900) || defined(HAVE_VENTANA) val = getbuttonstate(); #ifdef HAVE_WRK54G if (val) val = 0; else val = 1; #endif #ifndef HAVE_ALPHA #ifdef HAVE_USR5453 if (val) val = 0; else val = 1; #endif #endif #else if (brand == ROUTER_BOARD_WCRGN) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_WHRG300N) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_HAMEA15) { val = get_gpio(0); } else if (brand == ROUTER_BOARD_ECB9750) { val = get_gpio(11) << 11; } else if (brand == ROUTER_BOARD_NEPTUNE) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_RT3352) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_WR5422) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_DIR600B) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_F5D8235) { val = get_gpio(10) << 10; } else if (brand == ROUTER_ASUS_RTN10PLUS) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_RT15N) { val = get_gpio(12) << 12; } else if (brand == ROUTER_BOARD_DIR615D) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_ESR6650) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_EAP9550) { val = get_gpio(0); } else if (brand == ROUTER_BOARD_ESR9752) { val = get_gpio(0); } else if (brand == ROUTER_BOARD_AR670W) { val = get_gpio(9) << 9; } else if (brand == ROUTER_BOARD_AR690W) { val = get_gpio(9) << 9; } else if (brand == ROUTER_BOARD_BR6574N) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_ACXNR22) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_TECHNAXX3G) { val = get_gpio(10) << 10; } else if (brand == ROUTER_WHR300HP2) { val = get_gpio(52) << 1; } else if (brand == ROUTER_BOARD_W502U) { val = get_gpio(10) << 10; } else if (brand == ROUTER_BOARD_GW2380) { val = get_gpio(240); } else if (brand == ROUTER_BOARD_GW2388) { val = get_gpio(240); } else { if ((fp = fopen(GPIO_FILE, "r"))) { #ifdef HAVE_XSCALE fscanf(fp, "%d", &val); #else if (brand == ROUTER_NETGEAR_WGR614L) //gpio 7 power led shared with reset button { set_gpio(7, 1); //disable power led val = get_gpio(7) << 7; //read and shift value set_gpio(7, 0); //enable power led } else { fread(&val, 4, 1, fp); } #endif fclose(fp); } else perror(GPIO_FILE); } #endif DEBUG("resetbutton: GPIO = 0x%x\n", val); int gpio = 0; int state = 0; #if defined(HAVE_XSCALE) || defined(HAVE_MAGICBOX) || defined(HAVE_FONERA) || defined(HAVE_WHRAG108) || defined(HAVE_GATEWORX) || defined(HAVE_STORM) || defined(HAVE_LS2) || defined(HAVE_CA8) || defined(HAVE_TW6600) || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_WP54G) || defined(HAVE_NP28G) || defined(HAVE_SOLO51) || defined(HAVE_OPENRISC) || defined(HAVE_DANUBE) || defined(HAVE_UNIWIP) || defined(HAVE_VENTANA) state = val; int sesgpio = 0xfff; int wifigpio = 0xfff; int push; int pushwifi; #ifdef HAVE_WZRG300NH sesgpio = 0x117; val |= get_gpio(23) << 23; //aoss pushbutton #elif defined(HAVE_WHR300HP2) sesgpio = 0x102; val |= get_gpio(53) << 2; //aoss pushbutton #elif defined(HAVE_NEPTUNE) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_HAMEA15) // sesgpio = 0x100; // val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_WCRGN) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_RT3352) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_WZRG300NH2) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_WMBR_G300NH) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_WZRG450) sesgpio = 0x108; val |= get_gpio(8) << 8; //aoss pushbutton #elif defined(HAVE_DIR632) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_WZRHPAG300NH) sesgpio = 0x105; val |= get_gpio(5) << 5; //aoss pushbutton #elif defined(HAVE_CARAMBOLA) sesgpio = 0xfff; #elif defined(HAVE_HORNET) sesgpio = 0x00b; val |= get_gpio(11) << 11; //aoss pushbutton #elif defined(HAVE_RB2011) // sesgpio = 0x110; // val |= get_gpio(16) << 16; //aoss pushbutton #elif defined(HAVE_WDR4300) // sesgpio = 0x110; // val |= get_gpio(16) << 16; //aoss pushbutton #elif defined(HAVE_WNDR3700V4) sesgpio = 0x10f; val |= get_gpio(15) << 15; //aoss pushbutton #elif defined(HAVE_DIR825C1) sesgpio = 0x110; val |= get_gpio(16) << 16; //aoss pushbutton #elif defined(HAVE_WASP) sesgpio = 0x00b; val |= get_gpio(11) << 11; //aoss pushbutton #elif defined(HAVE_WNR2200) // sesgpio = 0x00b; //not yet supported // val |= get_gpio(37) << 37; //aoss pushbutton #elif defined(HAVE_WNR2000) sesgpio = 0x00b; val |= get_gpio(11) << 11; //aoss pushbutton #elif defined(HAVE_WDR2543) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_WHRHPGN) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_RT10N) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_RT15N) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_F5D8235) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_WR5422) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_DIR600) sesgpio = 0x100; val |= get_gpio(0); //aoss pushbutton #elif defined(HAVE_DIR615I) sesgpio = 0x110; val |= get_gpio(16) << 16; //aoss pushbutton #elif defined(HAVE_DIR615E) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_WR1043) sesgpio = 0x107; val |= get_gpio(7) << 7; //aoss pushbutton #elif defined(HAVE_WR941) sesgpio = 0x107; val |= get_gpio(7) << 7; //aoss pushbutton #elif defined(HAVE_MR3020) sesgpio = 0xfff; #elif defined(HAVE_WR741V4) sesgpio = 0x01a; val |= get_gpio(26) << 26; //aoss pushbutton #elif defined(HAVE_WR741) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_WRT400) sesgpio = 0x103; val |= get_gpio(3) << 3; //aoss pushbutton #elif defined(HAVE_WNDR3700) sesgpio = 0x103; val |= get_gpio(3) << 3; //aoss pushbutton #elif defined(HAVE_DIR825) sesgpio = 0x108; val |= get_gpio(8) << 8; //aoss pushbutton #elif defined(HAVE_TG2521) sesgpio = 0x10c; val |= get_gpio(12) << 12; //aoss pushbutton #elif defined(HAVE_OPENRISC) sesgpio = 0x005; val |= get_gpio(5) << 5; //aoss pushbutton #endif #ifdef HAVE_WRT160NL sesgpio = 0x107; val |= get_gpio(7) << 7; //wps/ses pushbutton #endif #ifdef HAVE_TEW632BRP sesgpio = 0x10c; val |= get_gpio(12) << 12; //wps/ses pushbutton #endif #else if (brand > 0xffff) { if ((brand & 0x000ff) != 0x000ff) gpio = 1 << (brand & 0x000ff); // calculate gpio value. if ((brand & 0x00100) == 0) // check reset button polarity: 0 // normal, 1 inversed state = (val & gpio); else state = !(val & gpio); } else { if ((brand & 0x000f) != 0x000f) gpio = 1 << (brand & 0x000f); // calculate gpio value. if ((brand & 0x0010) == 0) // check reset button polarity: 0 // normal, 1 inversed state = (val & gpio); else state = !(val & gpio); } /* * 1 byte router's SES (AOSS) button gpio number and polarity; Eko * 25.nov.06 * * R R R P N N N N = 0xXX ----- - ------- | | gpio num | | | |--- SES - * AOSS button polarity (0: normal, 1 inversed) | |-------- reserved for * future use * * 0xff = button disabled / not available */ int push; int pushwifi; int sesgpio; int wifigpio = 0xfff; switch (brand) { case ROUTER_BUFFALO_WHRG54S: case ROUTER_BUFFALO_WZRRSG54: case ROUTER_BUFFALO_WLI_TX4_G54HP: sesgpio = 0x100; // gpio 0, inversed break; case ROUTER_BUFFALO_WLA2G54C: sesgpio = 0x102; // gpio 2, inversed break; case ROUTER_BUFFALO_WBR2G54S: sesgpio = 0x004; // gpio 4, normal break; case ROUTER_BUFFALO_WZR600DHP2: case ROUTER_BUFFALO_WZR900DHP: sesgpio = 0x109; // gpio 9, inversed break; case ROUTER_BUFFALO_WZR1750: sesgpio = 0x10c; // gpio 12, inversed break; case ROUTER_D1800H: sesgpio = 0x10a; // gpio 10, inversed break; #ifndef HAVE_BUFFALO case ROUTER_ASUS_WL700GE: sesgpio = 0x004; // gpio 4, normal break; case ROUTER_ASUS_RTN10PLUSD1: sesgpio = 0x114; // gpio 20, inversed break; case ROUTER_ASUS_RTN10: sesgpio = 0x102; // gpio 2, inversed break; case ROUTER_ASUS_RTN12: case ROUTER_NETGEAR_WNR2000V2: sesgpio = 0x100; // gpio 0, inversed break; case ROUTER_LINKSYS_WTR54GS: case ROUTER_NETGEAR_WNDR4000: sesgpio = 0x102; // gpio 2, inversed break; case ROUTER_WRT54G: case ROUTER_WRT54G_V8: case ROUTER_WRTSL54GS: case ROUTER_WRT150N: case ROUTER_WRT160N: case ROUTER_WRT300N: case ROUTER_WRT300NV11: case ROUTER_WRT610NV2: case ROUTER_ASKEY_RT220XD: // not soldered case ROUTER_DYNEX_DX_NRUTER: case ROUTER_LINKSYS_E4200: case ROUTER_ASUS_RTN66: sesgpio = 0x104; // gpio 4, inversed break; case ROUTER_ASUS_AC66U: sesgpio = 0x104; // gpio 4, inversed break; case ROUTER_DLINK_DIR868: case ROUTER_ASUS_AC67U: wifigpio = 0x10f; sesgpio = 0x107; // gpio 7, inversed break; case ROUTER_ASUS_AC56U: wifigpio = 0x107; // gpio 7, inversed sesgpio = 0x10f; // gpio 7, inversed break; case ROUTER_ASUS_WL500G_PRE: sesgpio = 0x004; // gpio 4, normal break; case ROUTER_ASUS_WL550GE: sesgpio = 0x00f; // gpio 15, normal break; case ROUTER_WRT310N: case ROUTER_WRT350N: case ROUTER_WRT610N: case ROUTER_ASUS_RTN16: case ROUTER_BELKIN_F7D3301: case ROUTER_BELKIN_F7D3302: case ROUTER_BELKIN_F7D4301: case ROUTER_BELKIN_F7D4302: case ROUTER_BELKIN_F5D8235V3: case ROUTER_LINKSYS_E3200: sesgpio = 0x108; // gpio 8, inversed break; case ROUTER_ASUS_WL500W: sesgpio = 0x007; // gpio 7, normal break; case ROUTER_DLINK_DIR330: sesgpio = 0x107; // gpio 7, inversed break; case ROUTER_ASUS_WL520GUGC: case ROUTER_ASUS_WL500G_PRE_V2: sesgpio = 0x103; // gpio 3, inversed break; case ROUTER_WAP54G_V3: sesgpio = 0x10e; // gpio 14, inversed break; case ROUTER_NETGEAR_WNDR3300: sesgpio = 0x101; // gpio 1, inversed break; case ROUTER_WRT54G_V81: case ROUTER_DLINK_DIR320: case ROUTER_WRT600N: case ROUTER_NETGEAR_WNDR3400: case ROUTER_NETGEAR_WNR3500L: sesgpio = 0x106; // gpio 6, inversed break; case ROUTER_WRT320N: case ROUTER_WRT160NV3: case ROUTER_NETGEAR_WNDR4500: case ROUTER_NETGEAR_WNDR4500V2: case ROUTER_NETGEAR_R6300: sesgpio = 0x104; wifigpio = 0x105; break; case ROUTER_NETGEAR_R6250: sesgpio = 0x104; wifigpio = 0x105; break; case ROUTER_NETGEAR_R6300V2: sesgpio = 0x104; wifigpio = 0x105; break; case ROUTER_NETGEAR_R7000: sesgpio = 0x104; wifigpio = 0x105; break; case ROUTER_WRT310NV2: sesgpio = 0x105; // gpio 5, inversed break; case ROUTER_LINKSYS_E800: case ROUTER_LINKSYS_E900: case ROUTER_LINKSYS_E1000V2: case ROUTER_LINKSYS_E1500: case ROUTER_LINKSYS_E1550: case ROUTER_LINKSYS_E2500: sesgpio = 0x109; // gpio 9, inversed break; case ROUTER_LINKSYS_EA6500: sesgpio = 0x104; // gpio 4, inversed break; #endif default: sesgpio = 0xfff; // gpio unknown, disabled wifigpio = 0xfff; // gpio unknown, disabled } #endif push = 1 << (sesgpio & 0x0ff); // calculate push value from ses gpio pushwifi = 1 << (wifigpio & 0x0ff); // calculate push value from ses gpio // // // // pin no. /* * The value is zero during button-pushed. */ if (state && nvram_match("resetbutton_enable", "1")) { DEBUG("resetbutton: mode=%d, count=%d\n", mode, count); if (mode == 0) { /* * We detect button pushed first time */ alarmtimer(0, URGENT_INTERVAL); mode = 1; } { /* Whenever it is pushed steady */ if (++count > RESET_WAIT_COUNT) { if (check_action() != ACT_IDLE) { // Don't execute during upgrading fprintf(stderr, "resetbutton: nothing to do...\n"); alarmtimer(0, 0); /* Stop the timer alarm */ return; } if ((brand & 0x000f) != 0x000f) { printf("resetbutton: factory default.\n"); dd_syslog(LOG_DEBUG, "Reset button: restoring factory defaults now!\n"); #if !defined(HAVE_XSCALE) && !defined(HAVE_MAGICBOX) && !defined(HAVE_FONERA) && !defined(HAVE_WHRAG108) && !defined(HAVE_GATEWORX) && !defined(HAVE_LS2) && !defined(HAVE_CA8) && !defined(HAVE_TW6600) && !defined(HAVE_LS5) && !defined(HAVE_LSX) && !defined(HAVE_SOLO51) led_control(LED_DIAG, LED_ON); #elif defined(HAVE_WHRHPGN) || defined(HAVE_WZRG300NH) || defined(HAVE_WZRHPAG300NH) || defined(HAVE_WZRG450) led_control(LED_DIAG, LED_ON); #endif ACTION("ACT_HW_RESTORE"); alarmtimer(0, 0); /* Stop the timer alarm */ #ifdef HAVE_X86 eval("mount", "/usr/local", "-o", "remount,rw"); eval("rm", "-f", "/tmp/nvram/*"); // delete nvram // database eval("rm", "-f", "/tmp/nvram/.lock"); // delete // nvram // database eval("rm", "-f", "/usr/local/nvram/*"); // delete // nvram // database eval("mount", "/usr/local", "-o", "remount,ro"); #elif HAVE_RB500 eval("rm", "-f", "/tmp/nvram/*"); // delete nvram // database eval("rm", "-f", "/tmp/nvram/.lock"); // delete // nvram // database eval("rm", "-f", "/etc/nvram/*"); // delete nvram // database #elif HAVE_MAGICBOX eval("rm", "-f", "/tmp/nvram/*"); // delete nvram // database eval("rm", "-f", "/tmp/nvram/.lock"); // delete // nvram // database eval("erase", "nvram"); #else #ifdef HAVE_BUFFALO_SA int region_sa = 0; if (nvram_default_match("region", "SA", "")) region_sa = 1; #endif nvram_set("sv_restore_defaults", "1"); nvram_commit(); eval("killall", "ledtool"); // stop blinking on // nvram_commit #if !defined(HAVE_XSCALE) && !defined(HAVE_MAGICBOX) && !defined(HAVE_FONERA) && !defined(HAVE_WHRAG108) && !defined(HAVE_GATEWORX) && !defined(HAVE_LS2) && !defined(HAVE_CA8) && !defined(HAVE_TW6600) && !defined(HAVE_LS5) && !defined(HAVE_LSX) && !defined(HAVE_SOLO51) led_control(LED_DIAG, LED_ON); // turn diag led on, // so we know reset // was pressed and // we're restoring // defaults. #elif defined(HAVE_WHRHPGN) || defined(HAVE_WZRG300NH) || defined(HAVE_WZRHPAG300NH) || defined(HAVE_WZRG450) led_control(LED_DIAG, LED_ON); #endif #ifdef HAVE_BUFFALO_SA nvram_set("sv_restore_defaults", "1"); if (region_sa) nvram_set("region", "SA"); nvram_commit(); #endif #endif // nvram_set ("sv_restore_defaults", "1"); // nvram_commit (); kill(1, SIGTERM); } } } } else if ((sesgpio != 0xfff) && (((sesgpio & 0x100) == 0 && (val & push)) || ((sesgpio & 0x100) == 0x100 && !(val & push)))) { runStartup("/etc/config", ".sesbutton"); runStartup("/jffs/etc/config", ".sesbutton"); // if available runStartup("/mmc/etc/config", ".sesbutton"); // if available runStartup("/tmp/etc/config", ".sesbutton"); // if available if (nvram_match("radiooff_button", "1")) { led_control(LED_SES, LED_FLASH); // when pressed, blink white switch (ses_mode) { case 1: // SES (AOSS) led #ifdef HAVE_RADIOOFF #ifndef HAVE_BUFFALO dd_syslog(LOG_DEBUG, "SES / AOSS / EZ-setup button: turning radio(s) on\n"); #else dd_syslog(LOG_DEBUG, "AOSS button: turning radio(s) on\n"); #endif #ifndef HAVE_ERC sysprintf("startservice radio_on"); #endif #endif ses_mode = 0; break; case 2: // (AOSS) led #ifdef HAVE_RADIOOFF #ifndef HAVE_BUFFALO dd_syslog(LOG_DEBUG, "SES / AOSS / EZ-setup button: turning radio(s) off\n"); #else dd_syslog(LOG_DEBUG, "AOSS button: turning radio(s) off\n"); #endif #ifndef HAVE_ERC sysprintf("startservice radio_off"); #endif #endif ses_mode = 1; break; } } #ifdef HAVE_AOSS else if (nvram_match("radiooff_button", "2")) { sysprintf("startservice aoss"); } #else #endif } else if ((wifigpio != 0xfff) && (((wifigpio & 0x100) == 0 && (val & pushwifi)) || ((wifigpio & 0x100) == 0x100 && !(val & pushwifi)))) { led_control(LED_WLAN, LED_FLASH); // when pressed, blink white switch (wifi_mode) { case 1: dd_syslog(LOG_DEBUG, "Wifi button: turning radio(s) on\n"); sysprintf("startservice radio_on"); wifi_mode = 0; break; case 0: // (AOSS) led dd_syslog(LOG_DEBUG, "Wifi button: turning radio(s) off\n"); sysprintf("startservice radio_off"); wifi_mode = 1; break; } } else { /* * Although it's unpushed now, it had ever been pushed */ if (mode == 1) { if (check_action() != ACT_IDLE) { // Don't execute during upgrading fprintf(stderr, "resetbutton: nothing to do...\n"); alarmtimer(0, 0); /* Stop the timer alarm */ return; } service_restart(); } } }