int getRssi_11n(char *ifname, unsigned char *mac) { unsigned char *buf = safe_malloc(24 * 1024); memset(buf, 0, 1024 * 24); unsigned char *cp; int len; struct iwreq iwr; int s; char nb[32]; sprintf(nb, "%s_bias", ifname); s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { fprintf(stderr, "socket(SOCK_DRAGM)\n"); free(buf); return 0; } (void)memset(&iwr, 0, sizeof(iwr)); (void)strncpy(iwr.ifr_name, ifname, sizeof(iwr.ifr_name)); iwr.u.data.pointer = (void *)buf; iwr.u.data.length = 1024 * 24; if (ioctl(s, IEEE80211_IOCTL_STA_INFO, &iwr) < 0) { close(s); free(buf); return 0; } len = iwr.u.data.length; if (len < sizeof(struct ieee80211req_sta_info)) { close(s); free(buf); return 0; } cp = buf; char maccmp[6]; memset(maccmp, 0, 6); do { struct ieee80211req_sta_info *si; si = (struct ieee80211req_sta_info *)cp; if (!memcmp(&si->isi_macaddr[0], mac, 6)) { close(s); int rssi = si->isi_noise + si->isi_rssi; free(buf); return rssi + atoi(nvram_default_get(nb, "0")); } if (!memcmp(&si->isi_macaddr[0], mac, 6)) break; cp += si->isi_len; len -= si->isi_len; } while (len >= sizeof(struct ieee80211req_sta_info)); close(s); free(buf); return 0; }
int br_add_bridge(const char *brname) { dd_syslog(LOG_INFO, "bridge added successfully\n"); char ipaddr[32]; char brmcast[32]; sprintf(brmcast, "%s_mcast", brname); sprintf(ipaddr, "%s_ipaddr", brname); char netmask[32]; sprintf(netmask, "%s_netmask", brname); int ret = eval("brctl", "addbr", brname); #ifdef HAVE_80211AC eval("emf", "add", "bridge", brname); eval("igs", "add", "bridge", brname); #endif if (nvram_get(ipaddr) && nvram_get(netmask) && !nvram_match(ipaddr, "0.0.0.0") && !nvram_match(netmask, "0.0.0.0")) { eval("ifconfig", brname, nvram_safe_get(ipaddr), "netmask", nvram_safe_get(netmask), "mtu", getBridgeMTU(brname), "up"); } else eval("ifconfig", brname, "mtu", getBridgeMTU(brname)); char *mcast = nvram_default_get(brmcast, "0"); sysprintf("echo %s > /sys/devices/virtual/net/%s/bridge/multicast_snooping", mcast, brname); return ret; }
struct samba3_user *getsamba3users(void) { struct samba3_user *list, *current; int count, entry_count; json_t *json; json_error_t error; const char *key; json_t *iterator, *entry, *value; char username[64],password[64]; int type; // first create dummy entry list = getsamba3user("", "", 0); current = list; //json = json_loads( "[{\"user\":\"peter\",\"pass\":\"test\"},{\"user\":\"chris\",\"pass\":\"test\"}]", &error ); json = json_loads( nvram_default_get( "samba3_users", "[]"), 0, &error); if( !json ) { fprintf( stderr, "[JASON] ERROR\n"); } else { entry_count = json_array_size(json); for( count = 0; count < entry_count; count++ ) { entry = json_array_get( json, count ); iterator = json_object_iter(entry); // reset username[0] = 0; password[0] = 0; while(iterator) { key = json_object_iter_key(iterator); value = json_object_iter_value(iterator); /* use key and value ... */ if( !strcmp( key, "user" ) ) { strncpy( username, json_string_value( value ),sizeof(username)-1); } else if( !strcmp( key, "pass" ) ) { strncpy( password, json_string_value( value ),sizeof(password)-1); } else if( !strcmp( key, "type" ) ) { type = json_integer_value( value ); } iterator = json_object_iter_next(entry, iterator); } if( username[0] != 0 ) { current->next = getsamba3user(username, password, type); current = current->next; } } json_array_clear(json); } return list; }
int ej_active_wireless_if_ath9k(webs_t wp, int argc, char_t ** argv, char *ifname, int cnt, int turbo, int macmask) { char mac[32]; struct mac80211_info *mac80211_info; struct wifi_client_info *wc; char nb[32]; int bias, qual, it; int co = 0; sprintf(nb, "%s_bias", ifname); bias = atoi(nvram_default_get(nb, "0")); // sprintf(it, "inactivity_time", ifname); // it = atoi(nvram_default_get("inacttime", "300000")); mac80211_info = mac80211_assoclist(ifname); for (wc = mac80211_info->wci; wc; wc = wc->next) { strncpy(mac, wc->mac, 31); if (nvram_match("maskmac", "1") && macmask) { mac[0] = 'x'; mac[1] = 'x'; mac[3] = 'x'; mac[4] = 'x'; mac[6] = 'x'; mac[7] = 'x'; mac[9] = 'x'; mac[10] = 'x'; } qual = wc->signal * 124 + 11600; qual /= 10; // if (wc->inactive_time < it) { if (cnt) websWrite(wp, ","); websWrite(wp, "'%s','%s','%s','%dM','%dM','%d','%d','%d','%d'", mac, wc->ifname, UPTIME(wc->uptime), wc->txrate / 10, wc->rxrate / 10, wc->signal + bias, wc->noise + bias, wc->signal - wc->noise, qual); cnt++; // } } free_wifi_clients(mac80211_info->wci); free(mac80211_info); return cnt; }
struct dlna_share *getdlnashares(void) { struct dlna_share *list, *current; int count, entry_count; json_t *json; json_error_t error; const char *key; json_t *iterator, *entry, *value; char mp[64], types; // first create dummy entry list = getdlnashare("", 0); current = list; // json = json_loads( "[{\"mp\":\"/jffs\",\"label\":\"testshare\",\"perms\":\"rw\",\"public\":0},{\"mp\":\"/mnt\",\"label\":\"othertest\",\"perms\":\"ro\",\"public\":1},{\"label\":\"blah\"}]", &error ); json = json_loads(nvram_default_get("dlna_shares", "[]"), 0, &error); if (!json) { fprintf(stderr, "[JASON] ERROR\n"); } else { entry_count = json_array_size(json); for (count = 0; count < entry_count; count++) { entry = json_array_get(json, count); iterator = json_object_iter(entry); // reset mp[0] = 0; types = 0; while (iterator) { key = json_object_iter_key(iterator); value = json_object_iter_value(iterator); /* use key and value ... */ if (!strcmp(key, "mp")) { strncpy(mp, json_string_value(value), sizeof(mp) - 1); } else if (!strcmp(key, "types")) { types = json_integer_value(value); } iterator = json_object_iter_next(entry, iterator); } if (mp[0] != 0) { current->next = getdlnashare(mp, types); current = current->next; } } json_array_clear(json); } return list; }
#ifdef RTCONFIG_WIRELESSREPEATER if(nvram_get_int("sw_mode") == SW_MODE_REPEATER && nvram_get_int("wlc_state") != WLC_STATE_CONNECTED) fprintf(fp, "nameserver %s\n", nvram_default_get("lan_ipaddr")); else #endif { foreach(word, lan_dns, next) { if (!strcmp(word, lan_gateway)) dup_dns = 1; fprintf(fp, "nameserver %s\n", word); } }
void hotspotsys_config(void) { FILE *fp; char *next; char var[64]; char *dnslist; int i; md5_ctx_t MD; if (strlen(nvram_safe_get("hotss_remotekey")) != 12) { unsigned char hash[32]; char *et0 = nvram_safe_get("et0macaddr"); md5_begin(&MD); md5_hash(et0, 17, &MD); md5_end((unsigned char *)hash, &MD); char idkey[16]; int i; for (i = 0; i < 6; i++) sprintf(&idkey[2 * i], "%02d", (hash[i] + hash[i + 1]) % 100); idkey[12] = '\0'; nvram_set("hotss_remotekey", idkey); nvram_commit(); char sendid[256]; sprintf(sendid, "/usr/bin/wget http://tech.hotspotsystem.com/up.php?mac=`nvram get wl0_hwaddr|sed s/:/-/g`\\&operator=%s\\&location=%s\\&remotekey=%s", nvram_get("hotss_operatorid"), nvram_get("hotss_locationid"), nvram_get("hotss_remotekey")); system2(sendid); } if (!(fp = fopen("/tmp/chilli/hotss.conf", "w"))) { perror("/tmp/chilli/hotss.conf"); return; } fprintf(fp, "ipup /tmp/chilli/ip-up.sh\n"); fprintf(fp, "ipdown /tmp/chilli/ip-down.sh\n"); fprintf(fp, "radiusserver1 radius.hotspotsystem.com\n"); fprintf(fp, "radiusserver2 radius2.hotspotsystem.com\n"); fprintf(fp, "radiussecret hotsys123\n"); fprintf(fp, "dhcpif %s\n", nvram_safe_get("hotss_interface")); if (nvram_invmatch("hotss_net", "")) fprintf(fp, "net %s\n", nvram_get("hotss_net")); char *uamdomain = "customer.hotspotsystem.com"; if (!nvram_match("hotss_customuam", "")) { uamdomain = nvram_safe_get("hotss_customuam"); } fprintf(fp, "uamserver %s://%s/customer/hotspotlogin.php\n", nvram_default_get("hotss_customuamproto", "https"), uamdomain); if (nvram_invmatch("wan_get_dns", "0.0.0.0") && nvram_invmatch("wan_get_dns", "")) { dnslist = nvram_safe_get("wan_get_dns"); i = 1; foreach(var, dnslist, next) { if (i > 2) break; fprintf(fp, "dns%d %s\n", i, var); i++; } } else if (nvram_invmatch("wan_dns", "0.0.0.0")
#ifdef RTCONFIG_WIRELESSREPEATER if(nvram_get_int("sw_mode") == SW_MODE_REPEATER && nvram_get_int("wlc_state") != WLC_STATE_CONNECTED){ dhcp_lease = atoi(nvram_default_get("dhcp_lease")); } else #endif { dhcp_lease = nvram_get_int("dhcp_lease"); }
void start_l2tp(int status) { int ret; FILE *fp; char *l2tp_argv[] = { "xl2tpd", NULL }; char username[80], passwd[80]; // stop_dhcpc(); #ifdef HAVE_PPPOE stop_pppoe(); #endif #ifdef HAVE_PPTP stop_pptp(); #endif stop_l2tp(); snprintf(username, sizeof(username), "%s", nvram_safe_get("ppp_username")); snprintf(passwd, sizeof(passwd), "%s", nvram_safe_get("ppp_passwd")); if (status != REDIAL) { insmod("ipv6"); insmod("l2tp_core"); insmod("l2tp_netlink"); insmod("l2tp_ppp"); mkdir("/tmp/ppp", 0777); mkdir("/var/run/xl2tpd", 0777); mkdir("/tmp/xl2tpd", 0777); symlink("/sbin/rc", "/tmp/ppp/ip-up"); symlink("/sbin/rc", "/tmp/ppp/ip-down"); symlink("/dev/null", "/tmp/ppp/connect-errors"); /* * Generate L2TP configuration file */ if (!(fp = fopen("/tmp/xl2tpd/xl2tpd.conf", "w"))) { perror("/tmp/xl2tpd/xl2tpd.conf"); return; } /*[global] port = 1701 ;auth file = /etc/xl2tpd/xl2tp-secrets [lac fbnl2tpserver] lns = 10.64.1.237 require chap = yes refuse pap = yes require authentication = yes ; Name should be the same as the username in the PPP authentication! name = dani ppp debug = yes pppoptfile = /etc/xl2tpd/options.l2tp length bit = yes */ fprintf(fp, "[global]\n"); // Global section fprintf(fp, "port = 1701\n"); // Bind address fprintf(fp, "[lac %s]\n", nvram_safe_get("l2tp_server_name")); fprintf(fp, "lns = %s\n", nvram_safe_get("l2tp_server_name")); fprintf(fp, "require chap = %s\n", nvram_default_get("l2tp_req_chap", "yes")); fprintf(fp, "refuse pap = %s\n", nvram_default_get("l2tp_ref_pap", "yes")); fprintf(fp, "redial = yes\n"); fprintf(fp, "redial timeout = 15\n"); fprintf(fp, "require authentication = %s\n", nvram_default_get("l2tp_req_auth", "yes")); fprintf(fp, "name = %s\n", username); fprintf(fp, "pppoptfile = /tmp/ppp/options\n"); fprintf(fp, "length bit = yes\n"); fclose(fp); /* * Generate options file */ if (!(fp = fopen("/tmp/ppp/options", "w"))) { perror("/tmp/ppp/options"); return; } if (nvram_match("mtu_enable", "1")) { if (atoi(nvram_safe_get("wan_mtu")) > 0) { fprintf(fp, "mtu %s\n", nvram_safe_get("wan_mtu")); fprintf(fp, "mru %s\n", nvram_safe_get("wan_mtu")); } } fprintf(fp, "defaultroute\n"); // Add a default route to the // system routing tables, // using the peer as the // gateway fprintf(fp, "usepeerdns\n"); // Ask the peer for up to 2 DNS // server addresses // fprintf(fp, "pty 'pptp %s // --nolaunchpppd'\n",nvram_safe_get("pptp_server_ip")); fprintf(fp, "user '%s'\n", username); // fprintf(fp, "persist\n"); // Do not exit after a connection is // terminated. if (nvram_match("ppp_demand", "1")) { // demand mode fprintf(fp, "idle %d\n", nvram_match("ppp_demand", "1") ? atoi(nvram_safe_get("ppp_idletime")) * 60 : 0); // fprintf(fp, "demand\n"); // Dial on demand // fprintf(fp, "persist\n"); // Do not exit after a connection is // terminated. // fprintf(fp, "%s:%s\n",PPP_PSEUDO_IP,PPP_PSEUDO_GW); // <local // IP>:<remote IP> fprintf(fp, "ipcp-accept-remote\n"); fprintf(fp, "ipcp-accept-local\n"); fprintf(fp, "connect true\n"); fprintf(fp, "noipdefault\n"); // Disables the default // behaviour when no local IP // address is specified fprintf(fp, "ktune\n"); // Set /proc/sys/net/ipv4/ip_dynaddr // to 1 in demand mode if the local // address changes } else { // keepalive mode start_redial(); } fprintf(fp, "default-asyncmap\n"); // Disable asyncmap fprintf(fp, "crtscts\n"); // Disable protocol field compression // negotiation fprintf(fp, "nopcomp\n"); // Disable protocol field compression fprintf(fp, "refuse-eap\n"); // Disable protocol field compression fprintf(fp, "noaccomp\n"); // Disable Address/Control // compression fprintf(fp, "noccp\n"); // Disable CCP (Compression Control // Protocol) fprintf(fp, "novj\n"); // Disable Van Jacobson style TCP/IP // header compression fprintf(fp, "nobsdcomp\n"); // Disables BSD-Compress compression fprintf(fp, "nodeflate\n"); // Disables Deflate compression fprintf(fp, "lcp-echo-interval 0\n"); // Don't send an LCP // echo-request frame to the // peer fprintf(fp, "lock\n"); fprintf(fp, "noauth\n"); // fprintf(fp, "debug\n"); fclose(fp); /* * Generate pap-secrets file */ if (!(fp = fopen("/tmp/ppp/pap-secrets", "w"))) { perror("/tmp/ppp/pap-secrets"); return; } fprintf(fp, "\"%s\" * \"%s\" *\n", username, passwd); fclose(fp); chmod("/tmp/ppp/pap-secrets", 0600); /* * Generate chap-secrets file */ if (!(fp = fopen("/tmp/ppp/chap-secrets", "w"))) { perror("/tmp/ppp/chap-secrets"); return; } fprintf(fp, "\"%s\" * \"%s\" *\n", username, passwd); fclose(fp); chmod("/tmp/ppp/chap-secrets", 0600); /* * Enable Forwarding */ if ((fp = fopen("/proc/sys/net/ipv4/ip_forward", "r+"))) { fputc('1', fp); fclose(fp); } else perror("/proc/sys/net/ipv4/ip_forward"); } /* * Bring up WAN interface */ // ifconfig(nvram_safe_get("wan_ifname"), IFUP, // nvram_safe_get("wan_ipaddr"), nvram_safe_get("wan_netmask")); ret = _evalpid(l2tp_argv, NULL, 0, NULL); sleep(1); if (nvram_match("ppp_demand", "1")) { /* * Trigger Connect On Demand if user press Connect button in Status * page */ if (nvram_match("action_service", "start_l2tp")) { start_force_to_dial(); nvram_unset("action_service"); } /* * Trigger Connect On Demand if user ping pptp server */ else eval("listen", nvram_safe_get("lan_ifname")); } else { sysprintf("echo \"c %s\" > /var/run/xl2tpd/l2tp-control", nvram_safe_get("l2tp_server_name")); } cprintf("done\n"); return; }
int ej_active_wireless_if_11n(webs_t wp, int argc, char_t ** argv, char *ifname, int cnt, int turbo, int macmask) { unsigned char *cp; int s, len; struct iwreq iwr; char nb[32]; sprintf(nb, "%s_bias", ifname); int bias = atoi(nvram_default_get(nb, "0")); if (!ifexists(ifname)) { printf("IOCTL_STA_INFO ifresolv %s failed!\n", ifname); return cnt; } int state = 0; state = get_radiostate(ifname); if (state == 0 || state == -1) { printf("IOCTL_STA_INFO radio %s not enabled!\n", ifname); return cnt; } s = getsocket(); if (s < 0) { fprintf(stderr, "socket(SOCK_DRAGM)\n"); return cnt; } (void)memset(&iwr, 0, sizeof(struct iwreq)); (void)strncpy(iwr.ifr_name, ifname, sizeof(iwr.ifr_name)); iwr.u.data.pointer = (void *)&madbuf[0]; iwr.u.data.length = 24 * 1024; if (ioctl(s, IEEE80211_IOCTL_STA_INFO, &iwr) < 0) { fprintf(stderr, "IOCTL_STA_INFO for %s failed!\n", ifname); closesocket(); return cnt; } len = iwr.u.data.length; if (len < sizeof(struct ieee80211req_sta_info)) { // fprintf(stderr,"IOCTL_STA_INFO len<struct %s failed!\n",ifname); closesocket(); return cnt; } cp = madbuf; int bufcount = 0; do { struct ieee80211req_sta_info *si; uint8_t *vp; si = (struct ieee80211req_sta_info *)cp; vp = (u_int8_t *)(si + 1); if (cnt) websWrite(wp, ","); cnt++; char mac[32]; strncpy(mac, ieee80211_ntoa(si->isi_macaddr), 31); if (nvram_match("maskmac", "1") && macmask) { mac[0] = 'x'; mac[1] = 'x'; mac[3] = 'x'; mac[4] = 'x'; mac[6] = 'x'; mac[7] = 'x'; mac[9] = 'x'; mac[10] = 'x'; } if (si->isi_noise == 0) { si->isi_noise = -95; } int qual = (si->isi_noise + si->isi_rssi) * 124 + 11600; qual /= 10; int rxrate = si->isi_rxrateKbps / 1000; int txrate = si->isi_txrateKbps / 1000; if (!rxrate) rxrate = si->isi_rates[si->isi_rxrate] & IEEE80211_RATE_VAL; if (!txrate) txrate = si->isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL; char rx[32]; char tx[32]; if (rxrate) sprintf(rx, "%3dM", rxrate); else sprintf(rx, "N/A"); if (txrate) sprintf(tx, "%3dM", txrate); else sprintf(tx, "N/A"); websWrite(wp, "'%s','%s','%s','%s','%s','%d','%d','%d','%d'", mac, ifname, UPTIME(si->isi_uptime), tx, rx, si->isi_noise + si->isi_rssi + bias, si->isi_noise + bias, si->isi_rssi, qual); bufcount += si->isi_len; cp += si->isi_len; len -= si->isi_len; } while (len >= sizeof(struct ieee80211req_sta_info) && bufcount < (sizeof(madbuf) - sizeof(struct ieee80211req_sta_info))); closesocket(); return cnt; }
void start_overclock(void) // hidden feature. must be called with // "startservice overlock". then reboot the // unit { long len; long i; #ifdef HAVE_ALPHA FILE *in = fopen("/dev/mtdblock/0", "rb"); #elif HAVE_CA8 FILE *in = fopen("/dev/mtdblock/2", "rb"); // zLoader Board Data #else FILE *in = fopen("/dev/mtdblock/0", "rb"); #endif FILE *out = fopen("/tmp/boot", "wb"); fseek(in, 0, SEEK_END); len = ftell(in); fseek(in, 0, SEEK_SET); for (i = 0; i < len; i++) putc(getc(in), out); fclose(in); fclose(out); int clk = atoi(nvram_default_get("cpuclk", "180")); in = fopen("/tmp/boot", "r+b"); fseek(in, 0xe64b, SEEK_SET); int zmul = getc(in); fseek(in, 0x61b, SEEK_SET); int microvipermul = getc(in); fseek(in, 0xcb, SEEK_SET); int vipermul = getc(in); fseek(in, 0x1e3, SEEK_SET); int div = getc(in); fseek(in, 0x1ef, SEEK_SET); int mul = getc(in); fseek(in, 0x17, SEEK_SET); int dir300div = getc(in); fseek(in, 0x23, SEEK_SET); int dir300mul = getc(in); fseek(in, 0x47, SEEK_SET); int dir300div2 = getc(in); fseek(in, 0x53, SEEK_SET); int dir300mul2 = getc(in); fseek(in, 0x93, SEEK_SET); int dir300div3 = getc(in); fseek(in, 0x9f, SEEK_SET); int dir300mul3 = getc(in); fseek(in, 0x5e3, SEEK_SET); int dir300div4 = getc(in); fseek(in, 0x5ef, SEEK_SET); int dir300mul4 = getc(in); fseek(in, 0x75f, SEEK_SET); int dir300div5 = getc(in); fseek(in, 0x76b, SEEK_SET); int dir300mul5 = getc(in); fseek(in, 0x763, SEEK_SET); int dir300div6 = getc(in); fseek(in, 0x76f, SEEK_SET); int dir300mul6 = getc(in); //asus rt-g32 fseek(in, 0x8f, SEEK_SET); int dir300div7 = getc(in); fseek(in, 0x9b, SEEK_SET); int dir300mul7 = getc(in); fseek(in, 0xdb, SEEK_SET); int isalfa1 = getc(in); int isalfa = 0; if (isalfa1 == 0x6c) isalfa = 1; int dir300 = 0; int dir3002 = 0; int dir3003 = 0; int dir3004 = 0; int dir3005 = 0; int dir3006 = 0; int dir3007 = 0; if (dir300div == 0x3 && dir300mul == 0x5c) { dir300 = 1; div = dir300div; mul = dir300mul; } if (dir300div == 0x1 && (dir300mul == 0x28 || dir300mul == 0x2c || dir300mul == 0x30)) { dir300 = 1; div = dir300div; mul = dir300mul; } if (dir300div2 == 0x3 && dir300mul2 == 0x5c) { dir3002 = 1; div = dir300div2; mul = dir300mul2; } if (dir300div2 == 0x1 && (dir300mul2 == 0x28 || dir300mul2 == 0x2c || dir300mul2 == 0x30)) { dir3002 = 1; div = dir300div2; mul = dir300mul2; } if (dir300div3 == 0x3 && dir300mul3 == 0x5c) { dir3003 = 1; div = dir300div3; mul = dir300mul3; } if (dir300div3 == 0x1 && (dir300mul3 == 0x28 || dir300mul3 == 0x2c || dir300mul3 == 0x30)) { dir3003 = 1; div = dir300div3; mul = dir300mul3; } if (dir300div4 == 0x3 && dir300mul4 == 0x5c) { dir3004 = 1; div = dir300div4; mul = dir300mul4; } if (dir300div4 == 0x1 && (dir300mul4 == 0x28 || dir300mul4 == 0x2c || dir300mul4 == 0x30)) { dir3004 = 1; div = dir300div4; mul = dir300mul4; } if (dir300div5 == 0x3 && dir300mul5 == 0x5c) { dir3005 = 1; div = dir300div5; mul = dir300mul5; } if (dir300div5 == 0x1 && (dir300mul5 == 0x28 || dir300mul5 == 0x2c || dir300mul5 == 0x30)) { dir3005 = 1; div = dir300div5; mul = dir300mul5; } if (dir300div6 == 0x3 && dir300mul6 == 0x5c) { dir3006 = 1; div = dir300div6; mul = dir300mul6; } if (dir300div6 == 0x1 && (dir300mul6 == 0x28 || dir300mul6 == 0x2c || dir300mul6 == 0x30)) { dir3006 = 1; div = dir300div6; mul = dir300mul6; } if (dir300div7 == 0x3 && dir300mul7 == 0x5c) { dir3007 = 1; div = dir300div7; mul = dir300mul7; } if (dir300div7 == 0x1 && (dir300mul7 == 0x28 || dir300mul7 == 0x2c || dir300mul7 == 0x30)) { dir3007 = 1; div = dir300div7; mul = dir300mul7; } if (div == 0x3 && mul == 0x5c) { fprintf(stderr, "ap51/ap61/ap65 (ar2315/ar2316/ar2317/ar2318) found\n"); if (dir300) fseek(in, 0x17, SEEK_SET); else if (dir3002) fseek(in, 0x47, SEEK_SET); else if (dir3003) fseek(in, 0x93, SEEK_SET); else if (dir3004) fseek(in, 0x5e3, SEEK_SET); else if (dir3005) fseek(in, 0x75f, SEEK_SET); else if (dir3006) fseek(in, 0x763, SEEK_SET); else if (dir3007) fseek(in, 0x8f, SEEK_SET); else fseek(in, 0x1e3, SEEK_SET); putc(0x1, in); if (dir300) fseek(in, 0x23, SEEK_SET); else if (dir3002) fseek(in, 0x53, SEEK_SET); else if (dir3003) fseek(in, 0x9f, SEEK_SET); else if (dir3004) fseek(in, 0x5ef, SEEK_SET); else if (dir3005) fseek(in, 0x76b, SEEK_SET); else if (dir3006) fseek(in, 0x76f, SEEK_SET); else if (dir3007) fseek(in, 0x9b, SEEK_SET); else fseek(in, 0x1ef, SEEK_SET); if (clk == 200) { if (mul == 0x2c) { fixclk(in, 220, 200); } else if (mul == 0x30) { fixclk(in, 240, 200); } else fixclk(in, 184, 200); putc(0x28, in); // 0x2c for 220 mhz 0x30 for 240 mhz } else if (clk == 220) { if (mul == 0x28) { fixclk(in, 200, 220); } else if (mul == 0x30) { fixclk(in, 240, 220); } else fixclk(in, 184, 220); putc(0x2c, in); // 0x2c for 220 mhz 0x30 for 240 mhz } else if (clk == 240) { if (mul == 0x28) { fixclk(in, 200, 240); } else if (mul == 0x2c) { fixclk(in, 220, 240); } else fixclk(in, 184, 240); putc(0x30, in); // 0x2c for 220 mhz 0x30 for 240 mhz } else { fixclk(in, 184, 200); nvram_set("cpuclk", "200"); nvram_commit(); clk = atoi(nvram_default_get("cpuclk", "180")); putc(0x28, in); // 0x2c for 220 mhz 0x30 for 240 mhz } fclose(in); eval("mtd", "-f", "write", "/tmp/boot", "RedBoot"); } else if (div == 0x1 && (mul == 0x28 || mul == 0x2c || mul == 0x30)) { fprintf(stderr, "ap51/ap61/ap65 (ar2315/ar2316/ar2317/ar2318) found\n"); if (clk == 200 && mul == 0x28) { fprintf(stderr, "board already clocked to 200mhz\n"); fclose(in); return; } if (clk == 220 && mul == 0x2c) { fprintf(stderr, "board already clocked to 220mhz\n"); fclose(in); return; } if (clk == 240 && mul == 0x30) { fprintf(stderr, "board already clocked to 240mhz\n"); fclose(in); return; } if (dir300) fseek(in, 0x17, SEEK_SET); else if (dir3002) fseek(in, 0x47, SEEK_SET); else if (dir3003) fseek(in, 0x93, SEEK_SET); else if (dir3004) fseek(in, 0x5e3, SEEK_SET); else if (dir3005) fseek(in, 0x75f, SEEK_SET); else if (dir3006) fseek(in, 0x763, SEEK_SET); else if (dir3007) fseek(in, 0x8f, SEEK_SET); else fseek(in, 0x1e3, SEEK_SET); if (clk == 184) putc(0x3, in); // set divisor 5 = 40/5 = 8 mhz base which // allows 184 clock setting else putc(0x1, in); if (dir300) fseek(in, 0x23, SEEK_SET); else if (dir3002) fseek(in, 0x57, SEEK_SET); else if (dir3003) fseek(in, 0x9f, SEEK_SET); else if (dir3004) fseek(in, 0x5ef, SEEK_SET); else if (dir3005) fseek(in, 0x76b, SEEK_SET); else if (dir3006) fseek(in, 0x76f, SEEK_SET); else if (dir3007) fseek(in, 0x9b, SEEK_SET); else fseek(in, 0x1ef, SEEK_SET); if (clk == 184) { if (mul == 0x28) { fixclk(in, 200, 184); } else if (mul == 0x2c) { fixclk(in, 220, 184); } else if (mul == 0x30) { fixclk(in, 240, 184); } putc(0x5c, in); // 0x2c for 220 mhz 0x30 for 240 mhz } else if (clk == 200) { if (mul == 0x2c) { fixclk(in, 220, 200); } else if (mul == 0x30) { fixclk(in, 240, 200); } else fixclk(in, 184, 200); putc(0x28, in); // 0x2c for 220 mhz 0x30 for 240 mhz } else if (clk == 220) { if (mul == 0x28) { fixclk(in, 200, 220); } else if (mul == 0x30) { fixclk(in, 240, 220); } else fixclk(in, 184, 220); putc(0x2c, in); // 0x2c for 220 mhz 0x30 for 240 mhz } else if (clk == 240) { if (mul == 0x28) { fixclk(in, 200, 240); } else if (mul == 0x2c) { fixclk(in, 220, 240); } else fixclk(in, 184, 240); putc(0x30, in); // 0x2c for 220 mhz 0x30 for 240 mhz } else { fixclk(in, 184, 200); nvram_set("cpuclk", "200"); nvram_commit(); clk = atoi(nvram_default_get("cpuclk", "180")); putc(0x28, in); // 0x2c for 220 mhz 0x30 for 240 mhz } fclose(in); eval("mtd", "-f", "write", "/tmp/boot", "RedBoot"); } else if (vipermul == 0x9 || vipermul == 0xa || vipermul == 0xb || vipermul == 0xc || vipermul == 0x17) { if (vipermul == 0x17) { fprintf(stderr, "weired alfa clocksetting found\n"); fseek(in, 0xce, SEEK_SET); if (getc(in) == 0x32) { if (getc(in) == 0x45) { fprintf(stderr, "correct clock setting\n"); fseek(in, 0xcb, SEEK_SET); putc(0x9, in); fseek(in, 0xce, SEEK_SET); putc(0x12, in); putc(0x45, in); // fseek( in, 0xe4, SEEK_SET ); // putc( 0x0, in ); // nop out scratch register // putc( 0x0, in ); vipermul = 0x9; } else exit(1); } else exit(1); } fprintf(stderr, "viper (ar2313) found\n"); if (clk == 180 && vipermul == 0x9) { fprintf(stderr, "board already clocked to 180mhz\n"); fclose(in); return; } if (clk == 200 && vipermul == 0xa) { fprintf(stderr, "board already clocked to 200mhz\n"); fclose(in); return; } if (clk == 220 && vipermul == 0xb) { fprintf(stderr, "board already clocked to 220mhz\n"); fclose(in); return; } if (clk == 240 && vipermul == 0xc) { fprintf(stderr, "board already clocked to 240mhz\n"); fclose(in); return; } fseek(in, 0xcb, SEEK_SET); if (clk == 180) putc(0x9, in); // 0x2c for 220 mhz 0x30 for 240 mhz else if (clk == 200) putc(0xa, in); // 0x2c for 220 mhz 0x30 for 240 mhz else if (clk == 220) putc(0xb, in); // 0x2c for 220 mhz 0x30 for 240 mhz else if (clk == 240) putc(0xc, in); // 0x2c for 220 mhz 0x30 for 240 mhz else { nvram_set("cpuclk", "220"); clk = atoi(nvram_default_get("cpuclk", "180")); nvram_commit(); putc(0xb, in); // 0x2c for 220 mhz 0x30 for 240 mhz } if (isalfa) { fprintf(stderr, "correct scratch register for alfa ap48\n"); int realclock = clk * 1000000; fseek(in, 0xde, SEEK_SET); putc((realclock >> 24) & 0xff, in); putc((realclock >> 16) & 0xff, in); fseek(in, 0xe2, SEEK_SET); putc((realclock >> 8) & 0xff, in); putc(realclock & 0xff, in); } fclose(in); eval("mtd", "-f", "write", "/tmp/boot", "RedBoot"); } else if (microvipermul == 0x9 || microvipermul == 0xa || microvipermul == 0xb || microvipermul == 0xc || microvipermul == 0x17) {
void start_freeradius(void) { int ret = 0; pid_t pid; char *radiusd_argv[] = { "radiusd", "-d", "/jffs/etc/freeradius", NULL }; FILE *fp = NULL; stop_freeradius(); nvram_default_get("radius_country", "DE"); nvram_default_get("radius_state", "Saxony"); nvram_default_get("radius_locality", "none"); nvram_default_get("radius_expiration", "365"); nvram_default_get("radius_passphrase", "changeme"); nvram_default_get("radius_organisation", "DD-WRT"); nvram_default_get("radius_email", "*****@*****.**"); nvram_default_get("radius_common", "DD-WRT FreeRadius Certificate"); nvram_default_get("radius_port", "1812"); nvram_default_get("radius_enabled", "0"); if (!nvram_match("radius_enabled", "1")) return; #ifndef HAVE_OPENRISC #ifndef HAVE_VENTANA #if !defined(HAVE_RB600) || defined(HAVE_WDR4900) #ifdef HAVE_X86 system("mount --bind /usr/local /jffs"); #else if (!nvram_match("jffs_mounted", "1")) return; //jffs is a requirement for radius and must be mounted at this point here #endif #endif #endif #endif prep(); sysprintf("sed \"s/port = 0/port = %s/g\" /etc/freeradius/radiusd.conf > /jffs/etc/freeradius/radiusd.conf", nvram_safe_get("radius_port")); sysprintf("sed \"s/private_key_password = whatever/private_key_password = %s/g\" /etc/freeradius/eap.conf > /jffs/etc/freeradius/eap.conf", nvram_safe_get("radius_passphrase")); if (!f_exists("/jffs/etc/freeradius/certs/server.pem")) { //prepare certificates start_gen_radius_cert(); } int i; /* generate clients */ { struct radiusclientdb *db = loadradiusclientdb(); if (db) { fp = fopen("/jffs/etc/freeradius/clients.conf", "wb"); system("touch /jffs/etc/freeradius/clients.manual"); fprintf(fp, "$INCLUDE clients.manual\n"); for (i = 0; i < db->usercount; i++) { if (!db->users[i].clientsize) continue; if (!db->users[i].client || !strlen(db->users[i].client)) continue; fprintf(fp, "client %s {\n" "\tsecret = %s\n" "\tshortname = DD-WRT-RADIUS\n}\n", db->users[i].client, db->users[i].passwd); } fclose(fp); freeradiusclientdb(db); } } /* now generate users */ { struct radiusdb *db = loadradiusdb(); if (db) { fp = fopen("/jffs/etc/freeradius/users", "wb"); system("touch /jffs/etc/freeradius/users.manual"); fprintf(fp, "$INCLUDE users.manual\n"); fprintf(fp, "DEFAULT FreeRADIUS-Proxied-To == 127.0.0.1\n" "\tSession-Timeout := 3600,\n" "\tUser-Name := \"%%{User-Name}\",\n" "\tAcct-Interim-Interval := 300,\n" "\tFall-Through = Yes\n\n"); time_t tm; struct tm tm_time; for (i = 0; i < db->usercount; i++) { if (!db->users[i].usersize) continue; if (!db->users[i].user || !strlen(db->users[i].user)) continue; if (!db->users[i].enabled) continue; fprintf(fp, "%s Cleartext-Password := \"%s\"", db->users[i].user, db->users[i].passwd); if (db->users[i].expiration) { tm = db->users[i].expiration * 24 * 60 * 60; memcpy(&tm_time, localtime(&tm), sizeof(tm_time)); char datebuf[128]; strftime(datebuf, sizeof(datebuf), "%d %b %Y", &tm_time); fprintf(fp, ", Expiration == \"%s\"\n", datebuf); } else fprintf(fp, "\n"); if (db->users[i].downstream) { fprintf(fp, "\tWISPr-Bandwidth-Max-Down := %d,\n", db->users[i].downstream * 1024); fprintf(fp, "\tRP-Downstream-Speed-Limit := %d", db->users[i].downstream); } if (db->users[i].upstream) { if (db->users[i].downstream) fprintf(fp, ",\n"); fprintf(fp, "\tWISPr-Bandwidth-Max-Up := %d,\n", db->users[i].upstream * 1024); fprintf(fp, "\tRP-Upstream-Speed-Limit := %d", db->users[i].upstream); } fprintf(fp, "\n"); } fclose(fp); freeradiusdb(db); } } ret = _evalpid(radiusd_argv, NULL, 0, &pid); dd_syslog(LOG_INFO, "radiusd : FreeRadius daemon successfully started\n"); return; }