void myproc(){ //printf(1,"\n%d\n",writeproc("tmp",O_CREATE|O_RDWR)); int i=0; while(i<2){ sleep(100); printf(1,"%d",i); i++; } //sleep(400); writeproc("tmp",O_CREATE|O_RDWR); //readproc("tmp",O_RDONLY); while(1){ sleep(100); printf(1,"%d",i); i++; } //readproc("tmp",O_RDONLY); printf(1,"\n quitting!!!!!!\n"); exit(); }
void myproc(){ //printf(1,"\n%d\n",writeproc("tmp",O_CREATE|O_RDWR)); int child=fork(); if(child >= 0) // fork was successful { if(child == 0) // child process { printf(1,"Child Process %d.\n",child); int i=0; while(1){ sleep(100); printf(1,"%d",i); i++; } } else //Parent process { printf(1,"Parent process %d.\n",child); sleep(400); writeproc("tmp",O_CREATE|O_RDWR); kill(child); //if(kill(child)==0){ //printf(1,"kill succeed! .\n"); readproc("tmp",O_RDONLY); //} //else{ //printf(1,"kill failed .\n"); //} } } else // fork failed { printf(1,"\n Fork failed, quitting!!!!!!\n"); exit(); } //readproc("tmp",O_RDONLY); printf(1,"\n quitting!!!!!!\n"); exit(); }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; mknod("/dev/mmc", S_IFBLK | 0660, makedev(126, 0)); mknod("/dev/mmc0", S_IFBLK | 0660, makedev(126, 1)); mknod("/dev/mmc1", S_IFBLK | 0660, makedev(126, 2)); mknod("/dev/mmc2", S_IFBLK | 0660, makedev(126, 3)); mknod("/dev/mmc3", S_IFBLK | 0660, makedev(126, 4)); mknod("/dev/gpio", S_IFCHR | 0644, makedev(252, 0)); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * load some netfilter stuff */ // eval( "watchdog" ); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ra0"); insmod("rt2860v2_ap"); insmod("RTPCI_ap"); insmod("raeth"); #ifdef HAVE_WHR300HP2 insmod("rt2880_wdt"); FILE *in = fopen("/dev/mtdblock/2", "rb"); unsigned char mac[32]; if (in != NULL) { fseek(in, 4, SEEK_SET); fread(mac, 6, 1, in); fclose(in); unsigned int copy[6]; int i; for (i = 0; i < 6; i++) copy[i] = mac[i] & 0xff; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fprintf(stderr,"configure mac address to %s\n",mac); if (!strcmp(mac, "ff:ff:ff:ff:ff:ff")) eval("ifconfig", "eth0", "hw", "ether", "00:11:22:33:44:55"); else eval("ifconfig", "eth0", "hw", "ether", mac); } /* system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 1"); system("swconfig dev eth0 vlan 1 set ports \"0 1 2 3 6t\""); system("swconfig dev eth0 vlan 2 set ports \"4 6t\""); system("swconfig dev eth0 set apply");*/ //LAN/WAN ports as security mode sysprintf("switch reg w 2004 ff0003"); sysprintf("switch reg w 2104 ff0003"); sysprintf("switch reg w 2204 ff0003"); sysprintf("switch reg w 2304 ff0003"); sysprintf("switch reg w 2404 ff0003"); sysprintf("switch reg w 2504 ff0003"); //LAN/WAN ports as transparent port sysprintf("switch reg w 2010 810000c0"); sysprintf("switch reg w 2110 810000c0"); sysprintf("switch reg w 2210 810000c0"); sysprintf("switch reg w 2310 810000c0"); sysprintf("switch reg w 2410 810000c0"); sysprintf("switch reg w 2510 810000c0"); //set CPU/P7 port as user port sysprintf("switch reg w 2610 81000000"); sysprintf("switch reg w 2710 81000000"); sysprintf("switch reg w 2604 20ff0003");// #port6, Egress VLAN Tag Attribution=tagged sysprintf("switch reg w 2704 20ff0003");// #port7, Egress VLAN Tag Attribution=tagged sysprintf("switch reg w 2014 10001"); sysprintf("switch reg w 2114 10001"); sysprintf("switch reg w 2214 10001"); sysprintf("switch reg w 2314 10001"); sysprintf("switch reg w 2414 10002"); sysprintf("switch reg w 2514 10001"); //VLAN member port sysprintf("switch vlan set 0 1 11110111"); sysprintf("switch vlan set 1 2 00001011"); sysprintf("switch clear"); eval("ifconfig", "eth0", "up"); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "1"); //LAN eval("vconfig", "add", "eth0", "2"); //WAN struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } #else #if defined(HAVE_DIR600) && !defined(HAVE_ALL02310N) writeproc("/proc/rt3052/mii/ctrl", "write 0 0 0x3300"); writeproc("/proc/rt3052/mii/ctrl", "write 1 0 0x3300"); writeproc("/proc/rt3052/mii/ctrl", "write 2 0 0x3300"); writeproc("/proc/rt3052/mii/ctrl", "write 3 0 0x3300"); #endif #if defined(HAVE_RT10N) || defined(HAVE_F5D8235) || defined(HAVE_RT15N) || defined(HAVE_WCRGN) && !defined(HAVE_HAMEA15) FILE *in = fopen("/dev/mtdblock/2", "rb"); unsigned char mac[32]; if (in != NULL) { fseek(in, 4, SEEK_SET); fread(mac, 6, 1, in); fclose(in); unsigned int copy[6]; int i; for (i = 0; i < 6; i++) copy[i] = mac[i] & 0xff; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); if (!strcmp(mac, "ff:ff:ff:ff:ff:ff")) eval("ifconfig", "eth2", "hw", "ether", "00:11:22:33:44:55"); else eval("ifconfig", "eth2", "hw", "ether", mac); } #endif #ifdef HAVE_HAMEA15 FILE *in = fopen("/dev/mtdblock/1", "rb"); if (in != NULL) { unsigned char *config = malloc(65536); memset(config, 0, 65536); fread(config, 65536, 1, in); int len = strlen("WAN_MAC_ADDR="); int i; for (i = 0; i < 65535 - (len + 18); i++) { if (!strncmp(&config[i], "WAN_MAC_ADDR=", len)) { char *mac = &config[i + len]; if (mac[0] == '"') mac++; mac[17] = 0; eval("ifconfig", "eth2", "hw", "ether", mac); nvram_set("et0macaddr_safe", mac); nvram_set("et0macaddr", mac); break; } } free(config); fclose(in); } #endif #if (defined(HAVE_DIR600) || defined(HAVE_AR670W) || defined(HAVE_EAP9550) || defined(HAVE_AR690W)) && !defined(HAVE_ALL02310N) FILE *in = fopen("/dev/mtdblock/1", "rb"); if (in != NULL) { unsigned char *config = malloc(65536); memset(config, 0, 65536); fread(config, 65536, 1, in); #if defined(HAVE_AR670W) || defined(HAVE_AR690W) int len = strlen("lanmac="); #else int len = strlen("ethaddr="); #endif int i; for (i = 0; i < 65535 - (18 + len); i++) { #if defined(HAVE_AR670W) || defined(HAVE_AR690W) if (!strncmp(&config[i], "lanmac=", 7)) #else if (!strncmp(&config[i], "ethaddr=", 8)) #endif { char *mac = &config[i + len]; if (mac[0] == '"') mac++; mac[17] = 0; eval("ifconfig", "eth2", "hw", "ether", mac); nvram_set("et0macaddr_safe", mac); nvram_set("et0macaddr", mac); break; } } free(config); fclose(in); } #endif /* switch config */ if (getRouterBrand() != ROUTER_BOARD_ECB9750 && getRouterBrand() != ROUTER_BOARD_TECHNAXX3G) // lets load { eval("ifconfig", "eth2", "up"); #ifndef HAVE_EAP9550 eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth2", "1"); //LAN eval("vconfig", "add", "eth2", "2"); //WAN #ifdef HAVE_RT10N MAC_ADD(mac); eval("ifconfig", "vlan2", "hw", "ether", mac); #endif #endif #if defined(HAVE_ALLNET11N) || defined(HAVE_ESR6650) || defined(HAVE_WR5422) || defined(HAVE_RT10N) || \ defined(HAVE_ACXNR22) || defined(HAVE_W502U) || defined(HAVE_ESR9752) || defined(HAVE_ALL02310N) sysprintf("switch reg w 14 405555"); sysprintf("switch reg w 50 2001"); sysprintf("switch reg w 90 7f7f"); sysprintf("switch reg w 98 7f3f"); sysprintf("switch reg w e4 3f"); sysprintf("switch reg w 40 1002"); sysprintf("switch reg w 44 1001"); sysprintf("switch reg w 48 1001"); sysprintf("switch reg w 70 ffff417e"); #ifdef HAVE_ESR9752 sysprintf("switch reg w c8 3f502b28"); #endif #elif HAVE_AR670W sysprintf("mii_mgr -s -p 29 -r 23 -v 0x07c2"); sysprintf("mii_mgr -s -p 29 -r 22 -v 0x8420"); sysprintf("mii_mgr -s -p 29 -r 24 -v 0x1"); sysprintf("mii_mgr -s -p 29 -r 25 -v 0x1"); sysprintf("mii_mgr -s -p 29 -r 26 -v 0x1"); sysprintf("mii_mgr -s -p 29 -r 27 -v 0x1"); sysprintf("mii_mgr -s -p 29 -r 28 -v 0x2"); sysprintf("mii_mgr -s -p 30 -r 9 -v 0x1089"); sysprintf("mii_mgr -s -p 30 -r 1 -v 0x2f00"); sysprintf("mii_mgr -s -p 30 -r 2 -v 0x0030"); #elif HAVE_AR690W #elif HAVE_RT15N #elif HAVE_BR6574N #elif HAVE_F5D8235 sysprintf("switch reg w 14 405555"); sysprintf("switch reg w 50 2001"); sysprintf("switch reg w 90 7f7f"); sysprintf("switch reg w 98 7f40"); sysprintf("switch reg w e4 20"); sysprintf("switch reg w 40 1001"); sysprintf("switch reg w 44 1001"); sysprintf("switch reg w 48 1001"); sysprintf("switch reg w 4c 1"); sysprintf("switch reg w 70 ffffffff"); #elif HAVE_EAP9550 sysprintf("switch reg w 14 5555"); sysprintf("switch reg w 40 1001"); sysprintf("switch reg w 44 1001"); sysprintf("switch reg w 48 1001"); sysprintf("switch reg w 4c 1"); sysprintf("switch reg w 50 2001"); sysprintf("switch reg w 70 ffffffff"); sysprintf("switch reg w 90 7f7f"); sysprintf("switch reg w 98 7f7f"); sysprintf("switch reg w e4 7f"); #else sysprintf("switch reg w 14 405555"); sysprintf("switch reg w 50 2001"); sysprintf("switch reg w 90 7f7f"); sysprintf("switch reg w 98 7f3f"); sysprintf("switch reg w e4 3f"); sysprintf("switch reg w 40 1001"); sysprintf("switch reg w 44 1001"); sysprintf("switch reg w 48 1002"); sysprintf("switch reg w 70 ffff506f"); #endif } struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth2", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } #endif led_control(LED_POWER, LED_ON); led_control(LED_SES, LED_OFF); led_control(LED_SES2, LED_OFF); led_control(LED_DIAG, LED_OFF); led_control(LED_BRIDGE, LED_OFF); led_control(LED_WLAN0, LED_OFF); led_control(LED_WLAN1, LED_OFF); led_control(LED_CONNECTED, LED_OFF); #ifdef HAVE_WCRGN set_gpio(0,1); set_gpio(10,1); #endif if (!nvram_match("disable_watchdog", "1")) { eval("watchdog"); } return; }
void start_sysinit(void) { time_t tm = 0; eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/"); FILE *in = fopen("/tmp/nvram/nvram.db", "rb"); if (in != NULL) { fclose(in); eval("/usr/sbin/convertnvram"); eval("/sbin/mtd", "erase", "nvram"); nvram_commit(); } if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * network drivers */ #ifdef HAVE_HOTPLUG2 insmod("ar231x"); #else insmod("ar2313"); #endif detect_wireless_devices(); int s; struct ifreq ifr; if (getRouterBrand() == ROUTER_BOARD_RDAT81) { writeproc("/proc/sys/dev/wifi0/ledpin","7"); writeproc("/proc/sys/dev/wifi0/softled","1"); writeproc("/proc/sys/dev/wifi1/ledpin","5"); writeproc("/proc/sys/dev/wifi1/softled","1"); } if (getRouterBrand() == ROUTER_BOARD_RCAA01) { insmod("mvswitch"); // eval("ifconfig", "eth0", "up", "promisc"); // required for vlan config eval("/sbin/vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("/sbin/vconfig", "add", "eth0", "0"); eval("/sbin/vconfig", "add", "eth0", "1"); if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); char macaddr[32]; strcpy(macaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr. sa_data, eabuf)); nvram_set("et0macaddr", macaddr); // MAC_ADD( macaddr ); ether_atoe(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data); strncpy(ifr.ifr_name, "vlan1", IFNAMSIZ); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } writeproc("/proc/sys/dev/wifi0/ledpin","4"); writeproc("/proc/sys/dev/wifi0/softled","1"); writeproc("/proc/sys/dev/wifi1/ledpin","5"); writeproc("/proc/sys/dev/wifi1/softled","1"); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); char macaddr[32]; strcpy(macaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", macaddr); nvram_set("et0macaddr_safe", macaddr); close(s); } /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
void svqos_reset_ports(void) { #ifndef HAVE_XSCALE #ifndef HAVE_MAGICBOX #ifndef HAVE_RB600 #ifndef HAVE_FONERA #ifndef HAVE_RT2880 #ifndef HAVE_LS2 #ifndef HAVE_SOLO51 #ifndef HAVE_LS5 #ifndef HAVE_X86 #ifndef HAVE_WHRAG108 #ifndef HAVE_CA8 #ifndef HAVE_PB42 #ifndef HAVE_LSX #ifndef HAVE_DANUBE #ifndef HAVE_STORM #ifndef HAVE_LAGUNA #ifndef HAVE_VENTANA #ifndef HAVE_OPENRISC #ifndef HAVE_ADM5120 #ifndef HAVE_TW6600 if (nvram_match("portprio_support", "1")) { writeproc("/proc/switch/eth0/port/1/enable", "1"); writeproc("/proc/switch/eth0/port/2/enable", "1"); writeproc("/proc/switch/eth0/port/3/enable", "1"); writeproc("/proc/switch/eth0/port/4/enable", "1"); writeproc("/proc/switch/eth0/port/1/prio-enable", "0"); writeproc("/proc/switch/eth0/port/2/prio-enable", "0"); writeproc("/proc/switch/eth0/port/3/prio-enable", "0"); writeproc("/proc/switch/eth0/port/4/prio-enable", "0"); writeproc("/proc/switch/eth0/port/1/media", "AUTO"); writeproc("/proc/switch/eth0/port/2/media", "AUTO"); writeproc("/proc/switch/eth0/port/3/media", "AUTO"); writeproc("/proc/switch/eth0/port/4/media", "AUTO"); writeproc("/proc/switch/eth0/port/1/bandwidth", "FULL"); writeproc("/proc/switch/eth0/port/2/bandwidth", "FULL"); writeproc("/proc/switch/eth0/port/3/bandwidth", "FULL"); writeproc("/proc/switch/eth0/port/4/bandwidth", "FULL"); } #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; cprintf("sysinit() proc\n"); /* * /proc */ mknod("/dev/mmc",S_IFBLK|0660,makedev(126,0)); mknod("/dev/mmc0",S_IFBLK|0660,makedev(126,1)); mknod("/dev/mmc1",S_IFBLK|0660,makedev(126,2)); mknod("/dev/mmc2",S_IFBLK|0660,makedev(126,3)); mknod("/dev/mmc3",S_IFBLK|0660,makedev(126,4)); mkdir("/dev/mtd",0700); mknod("/dev/mtd/0",S_IFCHR|0644,makedev(90,0)); mknod("/dev/mtd/0ro",S_IFCHR|0644,makedev(90,1)); mknod("/dev/mtd/1",S_IFCHR|0644,makedev(90,2)); mknod("/dev/mtd/1ro",S_IFCHR|0644,makedev(90,3)); mknod("/dev/mtd/2",S_IFCHR|0644,makedev(90,4)); mknod("/dev/mtd/2ro",S_IFCHR|0644,makedev(90,5)); mknod("/dev/mtd/3",S_IFCHR|0644,makedev(90,6)); mknod("/dev/mtd/3ro",S_IFCHR|0644,makedev(90,7)); mknod("/dev/mtd/4",S_IFCHR|0644,makedev(90,8)); mknod("/dev/mtd/4ro",S_IFCHR|0644,makedev(90,9)); cprintf("sysinit() setup console\n"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * load some netfilter stuff */ #ifndef HAVE_WP54G #ifndef HAVE_NP28G insmod("nf_conntrack_ftp"); insmod("nf_conntrack_irc"); insmod("nf_conntrack_netbios_ns"); insmod("nf_conntrack_pptp"); insmod("nf_conntrack_proto_gre"); insmod("nf_conntrack_proto_udplite"); insmod("nf_conntrack_tftp"); insmod("xt_CLASSIFY"); insmod("xt_MARK"); insmod("xt_TCPMSS"); insmod("xt_length"); insmod("xt_limit"); insmod("xt_multiport"); insmod("xt_pkttype"); insmod("xt_state"); insmod("xt_tcpmss"); insmod("xt_u32"); insmod("iptable_filter"); insmod("iptable_mangle"); insmod("nf_nat"); insmod("iptable_nat"); insmod("nf_nat_ftp"); insmod("nf_nat_irc"); insmod("nf_nat_pptp"); insmod("nf_nat_proto_gre"); insmod("nf_nat_tftp"); insmod("ipt_LOG"); insmod("ipt_MASQUERADE"); insmod("ipt_REDIRECT"); insmod("ipt_REJECT"); insmod("ipt_ULOG"); insmod("ipt_TRIGGER"); insmod("ipt_iprange"); insmod("ipt_ipp2p"); insmod("ipt_layer7"); insmod("ipt_webstr"); // ppp drivers insmod("slhc"); insmod("ppp_generic"); insmod("ppp_async"); insmod("ppp_synctty"); insmod("ppp_mppe_mppc"); insmod("pppox"); insmod("pppoe"); #endif #endif insmod("adm5120_wdt"); insmod("adm5120sw"); if (getRouterBrand() != ROUTER_BOARD_WP54G && getRouterBrand() != ROUTER_BOARD_NP28G) { unsigned char mac[6]; char eabuf[32]; char mtdpath[32]; memset(mac, 0, 6); FILE *fp; int mtd = getMTD("boot"); int foundmac = 0; sprintf(mtdpath, "/dev/mtdblock/%d", mtd); fp = fopen(mtdpath, "rb"); if (fp != NULL) { //check for osbridge fseek(fp, 0xff90 - 2, SEEK_SET); unsigned char os[32]; fread(os, 32, 1, fp); if (strcmp(os, "OSBRiDGE 5XLi") == 0) { foundmac = 1; fprintf(stderr, "found OSBRiDGE 5XLi\n"); nvram_set("DD_BOARD", "OSBRiDGE 5LXi"); fseek(fp, 0xff82, SEEK_SET); fread(os, 12, 1, fp); int i; int count = 0; if (memcmp(os, "0050fc488130", 12) == 0) { //force change mac fclose(fp); start_change_mac(); sys_reboot(); } for (i = 0; i < 6; i++) { mac[i] = toNumeric(os[count++]) * 16; mac[i] |= toNumeric(os[count++]); } struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *)ifr.ifr_hwaddr. sa_data, mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); close(s); } } if (!foundmac) { int s = searchfor(fp, "mgmc", 0x20000 - 5); if (s != -1) { fread(mac, 6, 1, fp); struct ifreq ifr; int s; foundmac = 1; fprintf(stderr, "found Tonze-AP120\n"); if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *) ifr.ifr_hwaddr.sa_data, mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *) ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", ether_etoa((unsigned char *) ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } } } if (foundmac == 0) { fprintf(stderr, "error: no valid mac address found for eth0\n"); } fclose(fp); } } else { struct mylo_board_params params; char mtdpath[32]; FILE *fp; int mtd = getMTD("boot"); int foundmac = 0; struct ifreq ifr; int s; char eabuf[32]; sprintf(mtdpath, "/dev/mtdblock/%d", mtd); fp = fopen(mtdpath, "rb"); if (fp != NULL) { fseek(fp, 0xf800, SEEK_SET); fread(¶ms, sizeof(params), 1, fp); fclose(fp); if (params.magic == 0x20021103) { fprintf(stderr, "Found compex board magic!\n"); if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *)ifr.ifr_hwaddr. sa_data, params.addr[0].mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth1", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *)ifr.ifr_hwaddr. sa_data, params.addr[1].mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); close(s); } } } } /* * network drivers */ detect_wireless_devices(); if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); #ifdef HAVE_WP54G writeproc("/proc/sys/dev/wifi0/ledpin","6"); writeproc("/proc/sys/dev/wifi0/softled","1"); #endif /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; }
int svqos_iptables(void) { char *qos_pkts = nvram_safe_get("svqos_pkts"); char *qos_svcs = nvram_safe_get("svqos_svcs"); char name[32], type[32], data[32], level[32], pkt_filter[4]; char *wshaper_dev = nvram_get("wshaper_dev"); char *wan_dev = get_wanface(); char nullmask[24]; strcpy(nullmask, qos_nfmark(0)); insmod("ipt_mark"); insmod("xt_mark"); insmod("ipt_CONNMARK"); insmod("xt_CONNMARK"); insmod("ipt_mac"); insmod("xt_mac"); #if !(defined(ARCH_broadcom) && !defined(HAVE_BCMMODERN)) // if kernel version later then 2.4, overwrite all old tc filter sysprintf("tc filter del dev %s pref %d", wan_dev, 1); sysprintf("tc filter del dev %s pref %d", wan_dev, 3); sysprintf("tc filter del dev %s pref %d", wan_dev, 5); sysprintf("tc filter del dev %s pref %d", wan_dev, 8); sysprintf("tc filter del dev %s pref %d", wan_dev, 9); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", wan_dev, get_tcfmark(100), 100); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", wan_dev, get_tcfmark(10), 10); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", wan_dev, get_tcfmark(20), 20); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", wan_dev, get_tcfmark(30), 30); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", wan_dev, get_tcfmark(40), 40); sysprintf("tc filter del dev %s pref %d", "imq0", 1); sysprintf("tc filter del dev %s pref %d", "imq0", 3); sysprintf("tc filter del dev %s pref %d", "imq0", 5); sysprintf("tc filter del dev %s pref %d", "imq0", 8); sysprintf("tc filter del dev %s pref %d", "imq0", 9); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq0", get_tcfmark(100), 100); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq0", get_tcfmark(10), 10); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq0", get_tcfmark(20), 20); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq0", get_tcfmark(30), 30); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq0", get_tcfmark(40), 40); if (nvram_match("wshaper_dev", "LAN")) { sysprintf("tc filter del dev %s pref %d", "imq1", 1); sysprintf("tc filter del dev %s pref %d", "imq1", 3); sysprintf("tc filter del dev %s pref %d", "imq1", 5); sysprintf("tc filter del dev %s pref %d", "imq1", 8); sysprintf("tc filter del dev %s pref %d", "imq1", 9); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq1", get_tcfmark(100), 100); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq1", get_tcfmark(10), 10); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq1", get_tcfmark(20), 20); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq1", get_tcfmark(30), 30); sysprintf("tc filter add dev %s protocol ip parent 1: u32 match mark %s flowid 1:%d", "imq1", get_tcfmark(40), 40); } #endif #ifdef HAVE_OPENDPI insmod("/lib/opendpi/xt_opendpi.ko"); #endif insmod("ipt_layer7"); insmod("xt_layer7"); // set-up mark/filter tables system2("iptables -t mangle -F SVQOS_SVCS"); system2("iptables -t mangle -X SVQOS_SVCS"); system2("iptables -t mangle -N SVQOS_SVCS"); system2("iptables -t mangle -F FILTER_OUT"); system2("iptables -t mangle -X FILTER_OUT"); system2("iptables -t mangle -N FILTER_OUT"); system2("iptables -t mangle -A FILTER_OUT -j CONNMARK --restore"); sysprintf("iptables -t mangle -A FILTER_OUT -m mark --mark %s -j SVQOS_SVCS", nullmask); system2("iptables -t mangle -F FILTER_IN"); system2("iptables -t mangle -X FILTER_IN"); system2("iptables -t mangle -N FILTER_IN"); system2("iptables -t mangle -A FILTER_IN -j CONNMARK --restore"); sysprintf("iptables -t mangle -A FILTER_IN -m mark --mark %s -j SVQOS_SVCS", nullmask); sysprintf("iptables -t mangle -D PREROUTING -j FILTER_IN"); sysprintf("iptables -t mangle -I PREROUTING -j FILTER_IN"); sysprintf("iptables -t mangle -D POSTROUTING -j FILTER_OUT"); sysprintf("iptables -t mangle -I POSTROUTING -j FILTER_OUT"); system2("iptables -t mangle -A POSTROUTING -m dscp --dscp ! 0 -j DSCP --set-dscp 0"); if (!strcmp(wshaper_dev, "WAN")) { sysprintf("iptables -t mangle -D INPUT -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -A INPUT -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -D FORWARD -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -A FORWARD -i %s -j IMQ --todev 0", wan_dev); } if (!strcmp(wshaper_dev, "LAN")) { if (!client_bridged_enabled() && nvram_invmatch("wan_proto", "disabled")) { sysprintf("iptables -t mangle -D INPUT -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -A INPUT -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -D FORWARD -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -A FORWARD -i %s -j IMQ --todev 0", wan_dev); sysprintf("iptables -t mangle -D INPUT -i ! %s -j IMQ --todev 1", wan_dev); sysprintf("iptables -t mangle -A INPUT -i ! %s -j IMQ --todev 1", wan_dev); sysprintf("iptables -t mangle -D FORWARD -i ! %s -o ! %s -j IMQ --todev 1", wan_dev, wan_dev); sysprintf("iptables -t mangle -A FORWARD -i ! %s -o ! %s -j IMQ --todev 1", wan_dev, wan_dev); } else { sysprintf("iptables -t mangle -D INPUT -j IMQ --todev 1"); sysprintf("iptables -t mangle -A INPUT -j IMQ --todev 1"); sysprintf("iptables -t mangle -D FORWARD -j IMQ --todev 1"); sysprintf("iptables -t mangle -A FORWARD -j IMQ --todev 1"); } } /* add openvpn filter rules */ #ifdef HAVE_AQOS #ifdef HAVE_OPENVPN if (nvram_invmatch("openvpn_enable", "0") || nvram_invmatch("openvpncl_enable", "0")) { char iflist[256]; static char word[256]; char *next; bool unbridged_tap = 0; insmod("xt_dscp"); insmod("xt_DSCP"); system2("iptables -t mangle -F VPN_IN"); system2("iptables -t mangle -X VPN_IN"); system2("iptables -t mangle -N VPN_IN"); system2("iptables -t mangle -A VPN_IN -j CONNMARK --save"); system2("iptables -t mangle -F VPN_OUT"); system2("iptables -t mangle -X VPN_OUT"); system2("iptables -t mangle -N VPN_OUT"); system2("iptables -t mangle -F VPN_DSCP"); system2("iptables -t mangle -X VPN_DSCP"); system2("iptables -t mangle -N VPN_DSCP"); sysprintf("iptables -t mangle -A VPN_DSCP -m dscp --dscp 10 -j MARK --set-mark %s", qos_nfmark(100)); sysprintf("iptables -t mangle -A VPN_DSCP -m dscp --dscp 1 -j MARK --set-mark %s", qos_nfmark(10)); sysprintf("iptables -t mangle -A VPN_DSCP -m dscp --dscp 2 -j MARK --set-mark %s", qos_nfmark(20)); sysprintf("iptables -t mangle -A VPN_DSCP -m dscp --dscp 3 -j MARK --set-mark %s", qos_nfmark(30)); sysprintf("iptables -t mangle -A VPN_DSCP -m dscp --dscp 4 -j MARK --set-mark %s", qos_nfmark(40)); system2("iptables -t mangle -A VPN_DSCP -m dscp --dscp ! 0 -j DSCP --set-dscp 0"); system2("iptables -t mangle -A VPN_DSCP -j RETURN"); // look for present tun-devices if (getifcount("tun")) { system2("iptables -t mangle -I PREROUTING 2 -i tun+ -j VPN_IN"); system2("iptables -t mangle -I INPUT 1 -i tun+ -j IMQ --todev 0"); system2("iptables -t mangle -I FORWARD 1 -i tun+ -j IMQ --todev 0"); system2("iptables -t mangle -I POSTROUTING 1 -o tun+ -j VPN_OUT"); } // look for present tap-devices if (getifcount("tap")) { writeproc("/proc/sys/net/bridge/bridge-nf-call-arptables", "1"); writeproc("/proc/sys/net/bridge/bridge-nf-call-ip6tables", "1"); writeproc("/proc/sys/net/bridge/bridge-nf-call-iptables", "1"); insmod("xt_physdev"); insmod("ebtables"); getIfList(iflist, "tap"); foreach(word, iflist, next) { if (is_in_bridge(word)) { sysprintf("iptables -t mangle -I PREROUTING 2 -m physdev --physdev-in %s -j VPN_IN", word); sysprintf("iptables -t mangle -I INPUT 1 -m physdev --physdev-in %s -j IMQ --todev 0", word); sysprintf("iptables -t mangle -I FORWARD 1 -m physdev --physdev-in %s -j IMQ --todev 0", word); sysprintf("iptables -t mangle -I POSTROUTING -m physdev --physdev-out %s -j VPN_OUT", word); } else unbridged_tap = 1; } if (unbridged_tap) { system2("iptables -t mangle -I PREROUTING 2 -i tap+ -j VPN_IN"); system2("iptables -t mangle -I INPUT 1 -i tap+ -j IMQ --todev 0"); system2("iptables -t mangle -I FORWARD 1 -i tap+ -j IMQ --todev 0"); system2("iptables -t mangle -I POSTROUTING 1 -o tap+ -j VPN_OUT"); } }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; if (!nvram_match("disable_watchdog", "1")) { insmod("cns3xxx_wdt"); eval("watchdog"); } /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); int brand = getRouterBrand(); //for extension board struct ifreq ifr; int s; fprintf(stderr, "try modules for ethernet adapters\n"); nvram_set("intel_eth", "0"); insmod("cns3xxx_eth"); if (detect_ethernet_devices()) nvram_set("intel_eth", "1"); //load mmc drivers insmod("mmc_core"); eval("insmod", "sdhci", "debug_quirks=1"); // workaround for mmc detection issue. // insmod("sdhci"); insmod("sdhci-pltfm"); insmod("sdhci-cns3xxx"); insmod("mmc_block"); //sata drivers insmod("scsi_mod"); insmod("scsi_wait_scan"); insmod("scsi_sd_mod"); insmod("libata"); insmod("libahci"); insmod("ahci"); insmod("cns3xxx_ahci"); /* * network drivers */ detect_wireless_devices(); if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); eval("hwclock", "-s"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2391") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2391") ) sysprintf("gsp_updater -f /etc/gsc_2391_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2389") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2389") ) sysprintf("gsp_updater -f /etc/gsc_2388_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2388") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2388") ) sysprintf("gsp_updater -f /etc/gsc_2388_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2387") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2387") ) sysprintf("gsp_updater -f /etc/gsc_2387_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2386") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2386") ) sysprintf("gsp_updater -f /etc/gsc_2386_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2384") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2384") ) sysprintf("gsp_updater -f /etc/gsc_2384_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2383") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2383") ) sysprintf("gsp_updater -f /etc/gsc_2383_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2382") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2382") ) sysprintf("gsp_updater -f /etc/gsc_2382_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2380") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2380") ) sysprintf("gsp_updater -f /etc/gsc_2380_v35.txt"); writeproc("/proc/irq/51/smp_affinity","2"); //use second core for ethernet interrupts. this should increase performance a little bit return; }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; mknod("/dev/mmc", S_IFBLK | 0660, makedev(126, 0)); mknod("/dev/mmc0", S_IFBLK | 0660, makedev(126, 1)); mknod("/dev/mmc1", S_IFBLK | 0660, makedev(126, 2)); mknod("/dev/mmc2", S_IFBLK | 0660, makedev(126, 3)); mknod("/dev/mmc3", S_IFBLK | 0660, makedev(126, 4)); eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/"); FILE *in = fopen("/tmp/nvram/nvram.db", "rb"); if (in != NULL) { fclose(in); eval("/usr/sbin/convertnvram"); eval("/sbin/mtd", "erase", "nvram"); nvram_commit(); } if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); #ifdef HAVE_RTG32 insmod("slhc"); insmod("ppp_generic"); insmod("ppp_async"); insmod("ppp_synctty"); insmod("ppp_mppe_mppc "); insmod("pppox"); insmod("pppoe"); #endif /* * network drivers */ #ifdef HAVE_HOTPLUG2 insmod("ar231x"); #else insmod("ar2313"); #endif detect_wireless_devices(); eval("ifconfig", "eth0", "up"); // wan system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 1"); #ifdef HAVE_RTG32 system("swconfig dev eth0 vlan 1 set ports \"0t 1 2 3 4\""); system("swconfig dev eth0 vlan 2 set ports \"0t 5\""); #else system("swconfig dev eth0 vlan 1 set ports \"0t 2 3 4 5\""); system("swconfig dev eth0 vlan 2 set ports \"0t 1\""); #endif system("swconfig dev eth0 set apply"); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "1"); eval("vconfig", "add", "eth0", "2"); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); char macaddr[32]; strcpy(macaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", macaddr); MAC_ADD(macaddr); ether_atoe(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data); strncpy(ifr.ifr_name, "vlan2", IFNAMSIZ); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } eval("gpio", "enable", "1"); #ifdef HAVE_RTG32 writeproc("/proc/sys/dev/wifi0/ledpin", "7"); writeproc("/proc/sys/dev/wifi0/softled", "1"); #else writeproc("/proc/sys/dev/wifi0/ledpin", "0"); writeproc("/proc/sys/dev/wifi0/softled", "1"); #endif /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/"); FILE *in = fopen("/tmp/nvram/nvram.db", "rb"); if (in != NULL) { fclose(in); eval("/usr/sbin/convertnvram"); eval("/sbin/mtd", "erase", "nvram"); nvram_commit(); } if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); int brand = getRouterBrand(); insmod("zlib_deflate"); insmod("crc-ccitt"); insmod("crypto"); insmod("crypto_algapi"); insmod("crypto_blkcipher"); insmod("crypto_hash"); insmod("crypto_wq"); insmod("aead"); insmod("arc4"); insmod("ecb"); insmod("pcompress"); insmod("rng"); insmod("sha1_generic"); insmod("chainiv"); insmod("eseqiv"); insmod("cryptomgr"); insmod("slhc"); insmod("ppp_generic"); insmod("ppp_async"); insmod("ppp_synctty"); insmod("ppp_mppe"); insmod("pppox"); insmod("pppoe"); insmod("nf_conntrack_h323"); insmod("nf_nat_h323"); insmod("nf_conntrack_sip"); insmod("nf_nat_sip"); insmod("xt_state"); insmod("xt_recent"); insmod("xt_physdev"); insmod("xt_mac"); insmod("xt_limit"); insmod("xt_layer7"); insmod("xt_dscp"); insmod("xt_connlimit"); insmod("xt_multiport"); insmod("xt_DSCP"); /* * network drivers */ #ifdef HAVE_HOTPLUG2 insmod("ar231x"); #else insmod("ar2313"); #endif detect_wireless_devices(); writeproc("/proc/sys/dev/wifi0/ledpin", "2"); writeproc("/proc/sys/dev/wifi0/softled", "1"); writeproc("/proc/sys/dev/wifi0/ledpin", "3"); writeproc("/proc/sys/dev/wifi0/softled", "1"); // eval ("ifconfig", "wifi0", "up"); // eval ("ifconfig", "wifi1", "up"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
void start_sysinit(void) { time_t tm = 0; cprintf("sysinit() setup console\n"); if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * network drivers */ #ifdef HAVE_WR1043 fprintf(stderr, "load RTL Switch Driver\n"); insmod("rtl8366rb_smi"); // insmod("swconfig"); insmod("rtl8366_smi"); insmod("rtl8366rb"); #endif fprintf(stderr, "load ag71xx or ag7100_mod Ethernet Driver\n"); system("insmod ag71xx || insmod ag7100_mod"); #ifdef HAVE_WZRG300NH system("swconfig dev rtl8366s set reset 1"); system("swconfig dev rtl8366s set enable_vlan 0"); system("swconfig dev rtl8366s set apply"); FILE *fp = fopen("/dev/mtdblock/6", "rb"); if (fp) { unsigned char buf2[256]; fseek(fp, 0x1ff120c, SEEK_SET); fread(buf2, 256, 1, fp); fclose(fp); char mac[32]; unsigned int copy[256]; int i; for (i = 0; i < 256; i++) copy[i] = buf2[i] & 0xff; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fprintf(stderr, "configure eth0 to %s\n", mac); eval("ifconfig", "eth0", "hw", "ether", mac); fprintf(stderr, "configure eth1 to %s\n", mac); eval("ifconfig", "eth1", "hw", "ether", mac); } #endif #ifdef HAVE_WR1043 FILE *fp = fopen("/dev/mtdblock/0", "rb"); char mac[32]; if (fp) { system("swconfig dev rtl8366rb set reset 1"); system("swconfig dev rtl8366rb set enable_vlan 1"); system("swconfig dev rtl8366rb vlan 1 set ports \"1 2 3 4 5t\""); system("swconfig dev rtl8366rb vlan 2 set ports \"0 5t\""); system("swconfig dev rtl8366s set apply"); unsigned char buf2[256]; fseek(fp, 0x1fc00, SEEK_SET); fread(buf2, 256, 1, fp); fclose(fp); unsigned int copy[256]; int i; for (i = 0; i < 256; i++) copy[i] = buf2[i] & 0xff; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fprintf(stderr, "configure eth0 to %s\n", mac); eval("ifconfig", "eth0", "hw", "ether", mac); eval("ifconfig", "eth0", "up"); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "1"); eval("vconfig", "add", "eth0", "2"); fprintf(stderr, "configure vlan1 to %s\n", mac); eval("ifconfig", "vlan1", "hw", "ether", mac); MAC_ADD(mac); fprintf(stderr, "configure vlan2 to %s\n", mac); eval("ifconfig", "vlan2", "hw", "ether", mac); MAC_SUB(mac); } #endif #ifdef HAVE_WA901 FILE *fp = fopen("/dev/mtdblock/0", "rb"); char mac[32]; if (fp) { unsigned char buf2[256]; fseek(fp, 0x1fc00, SEEK_SET); fread(buf2, 256, 1, fp); fclose(fp); unsigned int copy[256]; int i; for (i = 0; i < 256; i++) copy[i] = buf2[i] & 0xff; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fprintf(stderr, "configure eth0 to %s\n", mac); eval("ifconfig", "eth0", "hw", "ether", mac); eval("ifconfig", "eth0", "up"); } #elif HAVE_WR941 FILE *fp = fopen("/dev/mtdblock/0", "rb"); char mac[32]; if (fp) { unsigned char buf2[256]; fseek(fp, 0x1fc00, SEEK_SET); fread(buf2, 256, 1, fp); fclose(fp); unsigned int copy[256]; int i; for (i = 0; i < 256; i++) copy[i] = buf2[i] & 0xff; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fprintf(stderr, "configure eth0 to %s\n", mac); eval("ifconfig", "eth0", "hw", "ether", mac); eval("ifconfig", "eth0", "up"); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "0"); eval("vconfig", "add", "eth0", "1"); fprintf(stderr, "configure vlan0 to %s\n", mac); MAC_SUB(mac); eval("ifconfig", "vlan0", "hw", "ether", mac); MAC_ADD(mac); MAC_ADD(mac); fprintf(stderr, "configure vlan1 to %s\n", mac); eval("ifconfig", "vlan1", "hw", "ether", mac); MAC_SUB(mac); MAC_SUB(mac); } #endif #ifdef HAVE_WRT160NL FILE *fp = fopen("/dev/mtdblock/0", "rb"); unsigned char buf2[256]; if (fp) { #ifdef HAVE_E2100 unsigned int firstoffset = 0x3f29a; unsigned int secondoffset = 0x3f288; #else unsigned int firstoffset = 0x3f288; unsigned int secondoffset = 0x3f29a; #endif fseek(fp, firstoffset, SEEK_SET); fread(buf2, 19, 1, fp); if (buf2[0]==0xff) fseek(fp, secondoffset, SEEK_SET); fread(buf2, 19, 1, fp); fclose(fp); fprintf(stderr, "configure eth0 to %s\n", buf2); eval("ifconfig", "eth0", "hw", "ether", buf2); MAC_ADD(buf2); fprintf(stderr, "configure eth1 to %s\n", buf2); eval("ifconfig", "eth1", "hw", "ether", buf2); } #endif #ifdef HAVE_TG2521 eval("ifconfig", "eth0", "hw", "ether", "00:11:22:33:44:55"); eval("ifconfig", "eth1", "hw", "ether", "00:11:22:33:44:66"); FILE *fp = fopen("/dev/mtdblock/7", "rb"); char mac[32]; if (fp) { unsigned char buf2[256]; fseek(fp, 0x7d08c3, SEEK_SET); // mac location fread(buf2, 6, 1, fp); fclose(fp); unsigned int copy[256]; int i; for (i = 0; i < 6; i++) copy[i] = buf2[i] & 0xff; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fprintf(stderr, "configure eth0 to %s\n", mac); eval("ifconfig", "eth0", "hw", "ether", mac); MAC_ADD(mac); fprintf(stderr, "configure eth1 to %s\n", mac); eval("ifconfig", "eth1", "hw", "ether", mac); MAC_SUB(mac); } #endif #if defined(HAVE_TEW632BRP) || defined(HAVE_DIR615E) eval("ifconfig", "eth0", "hw", "ether", "00:11:22:33:44:55"); eval("ifconfig", "eth1", "hw", "ether", "00:11:22:33:44:66"); FILE *in = fopen("/dev/mtdblock/0", "rb"); char *lanmac = NULL; if (in != NULL) { fseek(in, 0x20000, SEEK_SET); unsigned char *config = malloc(65536); memset(config, 0, 65536); fread(config, 65536, 1, in); int len = sizeof("lan_mac="); int i; int haslan = 0; int haswan = 0; for (i = 0; i < 65535 - 18; i++) { if (!haslan && !strncmp(&config[i], "lan_mac=", 8)) { haslan = 1; char *mac = &config[i + 8]; if (mac[0] == '"') mac++; mac[17] = 0; lanmac = malloc(32); strcpy(lanmac, mac); eval("ifconfig", "eth0", "hw", "ether", mac); nvram_set("et0macaddr_safe", mac); nvram_set("et0macaddr", mac); if (haswan) break; } if (!haswan && !strncmp(&config[i], "wan_mac=", 8)) { haswan = 1; char *mac = &config[i + 8]; if (mac[0] == '"') mac++; mac[17] = 0; eval("ifconfig", "eth1", "hw", "ether", mac); nvram_set("et0macaddr_safe", mac); nvram_set("et0macaddr", mac); if (haslan) break; } } free(config); fclose(in); } #endif eval("ifconfig", "eth0", "up"); eval("ifconfig", "eth1", "up"); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } detect_wireless_devices(); #ifdef HAVE_WRT160NL MAC_ADD(buf2); fprintf(stderr, "configure wifi0 to %s\n", buf2); eval("ifconfig", "wifi0", "hw", "ether", buf2); led_control(LED_POWER, LED_ON); #endif #if defined(HAVE_TEW632BRP) || defined(HAVE_DIR615E) if (lanmac != NULL) { fprintf(stderr, "configure wifi0 to %s\n", lanmac); eval("ifconfig", "wifi0", "hw", "ether", lanmac); free(lanmac); } #endif #ifdef HAVE_TG2521 { fprintf(stderr, "configure wifi0 to %s\n", mac); eval("ifconfig", "wifi0", "hw", "ether", mac); } // eval("gpio", "disable", "5"); // enable usb port #endif #ifdef HAVE_WR1043 { fprintf(stderr, "configure wifi0 to %s\n", mac); eval("ifconfig", "wifi0", "hw", "ether", mac); } #endif #ifdef HAVE_WR941 { fprintf(stderr, "configure wifi0 to %s\n", mac); eval("ifconfig", "wifi0", "hw", "ether", mac); } #endif led_control(LED_POWER, LED_ON); led_control(LED_SES, LED_OFF); led_control(LED_SES2, LED_OFF); led_control(LED_DIAG, LED_OFF); led_control(LED_BRIDGE, LED_OFF); led_control(LED_WLAN0, LED_OFF); led_control(LED_WLAN1, LED_OFF); led_control(LED_CONNECTED, LED_OFF); #ifdef HAVE_RS setWirelessLed(0,2); setWirelessLed(1,2); setWirelessLed(2,2); #elif HAVE_WRT160NL setWirelessLed(0,6); writeproc("/proc/sys/dev/wifi0/ledpin","6"); writeproc("/proc/sys/dev/wifi0/softled","1"); system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 1"); system("swconfig dev eth0 vlan 1 set ports \"0 1 2 3 4 5\""); #elif HAVE_WZRG300NH setWirelessLed(0,6); #elif HAVE_TEW632BRP setWirelessLed(0,6); #elif HAVE_WR941 setWirelessLed(0,9); #elif HAVE_WR1043 setWirelessLed(0,9); #else setWirelessLed(0,2); #endif /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
void start_sysinit(void) { time_t tm = 0; if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * network drivers */ fprintf(stderr, "load ATH Ethernet Driver\n"); system("insmod ag71xx || insmod ag7100_mod"); char mac1[32]; char mac2[32]; system("swconfig dev rtl8366s set reset 1"); system("swconfig dev rtl8366s set enable_vlan 0"); system("swconfig dev rtl8366s set apply"); #ifndef HAVE_WNDR3700 FILE *fp = fopen("/dev/mtdblock/7", "rb"); if (fp) { #ifdef HAVE_WRT400 char mactmp[6]; int copy[6]; int i; fseek(fp, 0x7f120c, SEEK_SET); fread(mactmp, 6, 1, fp); for (i = 5; i >= 3; i--) if (++mactmp[i] != 0x00) break; // dont know what this is for (i = 0; i < 6; i++) copy[i] = mactmp[i]; sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); MAC_ADD(mac2); #else fseek(fp, 0x66ffa0, SEEK_SET); fread(mac1, 18, 1, fp); fseek(fp, 0x66ffb4, SEEK_SET); fread(mac2, 18, 1, fp); fclose(fp); #endif } else #endif { sprintf(mac1, "00:11:22:33:44:55"); sprintf(mac2, "00:11:22:33:44:66"); } eval("ifconfig", "eth0", "hw", "ether", mac1); eval("ifconfig", "eth1", "hw", "ether", mac2); eval("ifconfig", "eth0", "up"); eval("ifconfig", "eth1", "up"); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } detect_wireless_devices(); #ifdef HAVE_WRT400 // eval("ifconfig", "wifi0", "hw", "ether", mac1); // eval("ifconfig", "wifi1", "hw", "ether", mac1); setWirelessLedPhy0(0); setWirelessLedPhy1(0); writeproc("/proc/sys/dev/wifi0/ledpin","0"); writeproc("/proc/sys/dev/wifi0/softled","1"); writeproc("/proc/sys/dev/wifi1/ledpin","0"); writeproc("/proc/sys/dev/wifi1/softled","1"); #else #ifndef HAVE_WNDR3700 eval("ifconfig", "wifi0", "hw", "ether", mac1); eval("ifconfig", "wifi1", "hw", "ether", mac1); #endif setWirelessLedPhy0(5); setWirelessLedPhy1(5); #endif led_control(LED_POWER, LED_ON); led_control(LED_SES, LED_OFF); led_control(LED_SES2, LED_OFF); led_control(LED_DIAG, LED_OFF); led_control(LED_BRIDGE, LED_OFF); led_control(LED_WLAN0, LED_OFF); led_control(LED_WLAN1, LED_OFF); led_control(LED_CONNECTED, LED_OFF); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }