int isGW2369(void) { int brand = getRouterBrand(); if (brand == ROUTER_BOARD_GATEWORX_GW2369) return 1; return 0; }
int main(int argc, char *argv[]) { brand = getRouterBrand(); #ifndef HAVE_MI424WR #if !defined(HAVE_NOP8670) && !defined(HAVE_TONZE) if ((brand & 0x000f) == 0x000f) #endif { puts("sorry, your unit does not support resetbutton feature\n"); return 0; } #endif #ifndef HAVE_NOP8670 #ifdef HAVE_MAGICBOX init_gpio(); #endif /* * Run it under background */ switch (fork()) { case -1: DEBUG("can't fork\n"); exit(0); break; case 0: /* * child process */ DEBUG("fork ok\n"); (void)setsid(); break; default: /* * parent process should just die */ _exit(0); } /* * set the signal handler */ signal(SIGALRM, period_check); /* * set timer */ alarmtimer(NORMAL_INTERVAL, 0); /* * Most of time it goes to sleep */ while (1) pause(); return 0; #endif }
void set_gpio(int pin, int value) { if (getRouterBrand() == ROUTER_NETGEAR_WNDR4000) { gpio_control_clk_data(pin, value, WNDR4000_GPIO_EXT_CTRL_CLK, WNDR4000_GPIO_EXT_CTRL_DATA, WNDR4000_EXT_LED_MAX_SHIFTS); } else { set_gpio_normal(pin, value); } }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; 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"); int brand = getRouterBrand(); /* * network drivers */ insmod("ag7100_mod"); int s; struct ifreq ifr; 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); } #ifdef HAVE_MADWIFI_MIMO // insmod("ath_pci", "autocreate=none"); insmod("ath_mimo_pci"); #endif // eval ("ifconfig", "wifi0", "up"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; eval("/bin/tar", "-xzf", "/dev/mtdblock/2", "-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(); /* * network drivers */ detect_wireless_devices(); 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)); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); 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 start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; eval("mknod", "/dev/gpio", "c", "127", "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"); int brand = getRouterBrand(); /* * network drivers */ insmod("gemini_negmac"); #ifdef HAVE_WBD222 insmod("libata"); insmod("pata_gemini"); #endif eval("ifconfig", "eth0", "up"); #ifdef HAVE_WBD222 eval("ifconfig", "eth1", "up"); #endif 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(); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); //disable led's eval("gpio", "disable", "1"); eval("gpio", "disable", "2"); eval("gpio", "disable", "3"); eval("gpio", "disable", "5"); eval("hwclock", "-s"); return; cprintf("done\n"); }
static void watchdog(void) { int brand = getRouterBrand(); int registered = -1; int radiostate0 = -1; int oldstate0 = -1; int radiostate1 = -1; int oldstate1 = -1; int counter = 0; int radioledinitcount = 0; int fd = open("/dev/misc/watchdog", O_WRONLY); if (fd == -1) fd = open("/dev/watchdog", O_WRONLY); if (fd == -1) { return; } #ifdef HAVE_MADWIFI int cnt = getdevicecount(); #else int cnt = get_wl_instances(); #endif while (1) { write(fd, "\0", 1); fsync(fd); #ifdef HAVE_REGISTER if (!nvram_match("flash_active", "1")) { if (registered == -1) registered = isregistered_real(); if (!registered) isregistered(); //to poll } #endif /* * software wlan led control */ if (radioledinitcount < 5) { radioledinitcount++; oldstate0 = -1; oldstate1 = -1; } #ifdef HAVE_MADWIFI if (!nvram_match("flash_active", "1")) { radiostate0 = get_radiostate("ath0"); if (cnt == 2) radiostate1 = get_radiostate("ath1"); } #else wl_ioctl(get_wl_instance_name(0), WLC_GET_RADIO, &radiostate0, sizeof(int)); if (cnt == 2) wl_ioctl(get_wl_instance_name(1), WLC_GET_RADIO, &radiostate1, sizeof(int)); #endif if (radiostate0 != oldstate0) { #ifdef HAVE_MADWIFI if (radiostate0 == 1) #else if ((radiostate0 & WL_RADIO_SW_DISABLE) == 0) #endif led_control(LED_WLAN0, LED_ON); else { led_control(LED_WLAN0, LED_OFF); #ifndef HAVE_MADWIFI /* * Disable wireless will cause diag led blink, so we want to * stop it. */ if (brand == ROUTER_WRT54G) diag_led(DIAG, STOP_LED); /* * Disable wireless will cause power led off, so we want to * turn it on. */ if (brand == ROUTER_WRT54G_V8) led_control(LED_POWER, LED_ON); #endif } oldstate0 = radiostate0; } if (radiostate1 != oldstate1) { #ifdef HAVE_MADWIFI if (radiostate1 == 1) #else if ((radiostate1 & WL_RADIO_SW_DISABLE) == 0) #endif led_control(LED_WLAN1, LED_ON); else { led_control(LED_WLAN1, LED_OFF); } oldstate1 = radiostate1; } /* * end software wlan led control */ sleep(10); if (nvram_match("warn_enabled", "1")) { counter++; if (!(counter % 60)) system("notifier&"); // } } }
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 ag71xx or ag7100_mod Ethernet Driver\n"); system("insmod ag71xx || insmod ag7100_mod || insmod ag7240_mod"); char mac1[32]; char mac2[32]; char wmac[32]; FILE *fp = fopen("/dev/mtdblock/7", "rb"); if (fp) { char mactmp[6]; int copy[6]; int i; #ifdef HAVE_WNDR3700 system("swconfig dev rtl8366s set reset 1"); system("swconfig dev rtl8366s set enable_vlan 0"); system("swconfig dev rtl8366s set blinkrate 2"); system("swconfig dev rtl8366s port 1 set led 9"); system("swconfig dev rtl8366s port 2 set led 6"); system("swconfig dev rtl8366s port 5 set led 2"); system("swconfig dev rtl8366s set apply"); #ifdef HAVE_WNDR3700V2 fseek(fp, 0xff0000, SEEK_SET); #else fseek(fp, 0x7f0000, SEEK_SET); #endif fread(mactmp, 6, 1, fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fread(mactmp, 6, 1, fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fread(mactmp, 6, 1, fp); fclose(fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; sprintf(wmac, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); #elif HAVE_WZRHPAG300NH system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 0"); system("swconfig dev eth0 vlan 1 set ports \"0 1 2 3 4\""); system("swconfig dev eth0 set apply"); fseek(fp, 0x5120C, SEEK_SET); fread(mactmp, 6, 1, fp); fclose(fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; 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); // eval("gpio","enable","2"); #elif HAVE_WZRG300NH2 #ifndef HAVE_WZR300HP sysprintf("startservice bootloader_check"); #endif fseek(fp, 0x5120C, SEEK_SET); fread(mactmp, 6, 1, fp); fclose(fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; 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]); // eval("gpio","enable","13"); #ifdef HAVE_SWCONFIG system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 1"); if(nvram_match("wan_proto", "disabled") && nvram_match("fullswitch", "1")) { system("swconfig dev eth0 vlan 1 set ports \"0t 1 2 3 4 5\""); } else { system("swconfig dev eth0 vlan 1 set ports \"0t 1 3 4 5\""); system("swconfig dev eth0 vlan 2 set ports \"0t 2\""); } system("swconfig dev eth0 set apply"); #endif fprintf(stderr, "configure eth0 to %s\n", mac2); eval("ifconfig", "eth0", "hw", "ether", mac2); 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", mac2); eval("ifconfig", "vlan1", "hw", "ether", mac2); fprintf(stderr, "configure vlan2 to %s\n", mac2); eval("ifconfig", "vlan2", "hw", "ether", mac2); #elif HAVE_WZRG450 fseek(fp, 0x51002, SEEK_SET); //osprey eeprom mac location fread(mactmp, 6, 1, fp); fclose(fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; 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]); // mac1[0] |= 0x02; // add private bit // mac2[0] |= 0x02; // eval("gpio","disable","16"); #ifdef HAVE_SWCONFIG system("swconfig dev switch0 set reset 1"); system("swconfig dev switch0 set enable_vlan 1"); if(nvram_match("wan_proto", "disabled") && nvram_match("fullswitch", "1")) { system("swconfig dev switch0 vlan 1 set ports \"0t 1 2 3 4 5\""); } else { system("swconfig dev switch0 vlan 1 set ports \"0t 2 3 4 5\""); system("swconfig dev switch0 vlan 2 set ports \"0t 1\""); } system("swconfig dev switch0 set apply"); #endif fprintf(stderr, "configure eth0 to %s\n", mac2); eval("ifconfig", "eth0", "hw", "ether", mac2); 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", mac2); eval("ifconfig", "vlan1", "hw", "ether", mac2); fprintf(stderr, "configure vlan2 to %s\n", mac2); eval("ifconfig", "vlan2", "hw", "ether", mac2); #else system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 0"); system("swconfig dev eth0 vlan 1 set ports \"0 1 2 3 4\""); system("swconfig dev eth0 set apply"); fseek(fp, 0x7f120c, SEEK_SET); fread(mactmp, 6, 1, fp); fclose(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]; for (i = 0; i < 6; i++) copy[i] &= 0xff; 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); #endif } else { sprintf(mac1, "00:11:22:33:44:55"); sprintf(mac2, "00:11:22:33:44:66"); } #ifndef HAVE_WZRG450 eval("ifconfig", "eth0", "hw", "ether", mac1); eval("ifconfig", "eth0", "up"); eval("ifconfig", "eth1", "hw", "ether", mac2); eval("ifconfig", "eth1", "up"); #else eval("ifconfig", "eth0", "hw", "ether", mac2); eval("ifconfig", "eth0", "up"); #endif 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_WZRHPAG300NH // eval("ifconfig", "wifi1", "hw", "ether", wmac); setWirelessLedPhy0(1); setWirelessLedPhy1(5); #else #ifndef HAVE_WNDR3700 #ifdef HAVE_WZRG300NH2 setWirelessLedPhy0(5); #else #ifndef HAVE_WZRG450 setWirelessLedGeneric(0,6); setWirelessLedGeneric(1,6); #endif #endif #else eval("ifconfig", "wifi0", "hw", "ether", mac1); eval("ifconfig", "wifi1", "hw", "ether", wmac); setWirelessLedPhy0(5); setWirelessLedPhy1(5); #endif #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); getRouterBrand(); // restore some default settings if (!nvram_get("ath0_rxantenna")) nvram_set("ath0_rxantenna", "3"); if (!nvram_get("ath0_txantenna")) nvram_set("ath0_txantenna", "3"); if (!nvram_get("ath1_rxantenna")) nvram_set("ath1_rxantenna", "3"); if (!nvram_get("ath1_txantenna")) nvram_set("ath1_txantenna", "3"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
/* * software wlan led control */ void softcontrol_wlan_led(void) // done in watchdog.c for non-micro // builds. { #if defined(HAVE_MICRO) && !defined(HAVE_ADM5120) && !defined(HAVE_WRK54G) int brand; int radiostate0 = -1; int oldstate0 = -1; int radiostate1 = -1; int oldstate1 = -1; #ifdef HAVE_MADWIFI int cnt = getdevicecount(); #else int cnt = get_wl_instances(); #endif #ifdef HAVE_MADWIFI if (!nvram_match("flash_active", "1")) { radiostate0 = get_radiostate("ath0"); if (cnt == 2) radiostate1 = get_radiostate("ath1"); } #else wl_ioctl(get_wl_instance_name(0), WLC_GET_RADIO, &radiostate0, sizeof(int)); if (cnt == 2) wl_ioctl(get_wl_instance_name(1), WLC_GET_RADIO, &radiostate1, sizeof(int)); #endif if (radiostate0 != oldstate0) { #ifdef HAVE_MADWIFI if (radiostate0 == 1) #else if ((radiostate0 & WL_RADIO_SW_DISABLE) == 0) #endif led_control(LED_WLAN0, LED_ON); else { led_control(LED_WLAN0, LED_OFF); #ifndef HAVE_MADWIFI brand = getRouterBrand(); /* * Disable wireless will cause diag led blink, so we want to * stop it. */ if (brand == ROUTER_WRT54G) diag_led(DIAG, STOP_LED); /* * Disable wireless will cause power led off, so we want to * turn it on. */ if (brand == ROUTER_WRT54G_V8) led_control(LED_POWER, LED_ON); #endif } oldstate0 = radiostate0; } if (radiostate1 != oldstate1) { #ifdef HAVE_MADWIFI if (radiostate1 == 1) #else if ((radiostate1 & WL_RADIO_SW_DISABLE) == 0) #endif led_control(LED_WLAN1, LED_ON); else { led_control(LED_WLAN1, LED_OFF); } oldstate1 = radiostate1; } /* * end software wlan led control */ return; #endif }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; unlink("/etc/nvram/.lock"); cprintf("sysinit() proc\n"); /* * /proc */ mount("proc", "/proc", "proc", MS_MGC_VAL, NULL); system2("/etc/convert"); mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL); cprintf("sysinit() tmp\n"); /* * /tmp */ mount("ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL); mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL); eval("mount", "/etc/www.fs", "/www", "-t", "squashfs", "-o", "loop"); eval("mount", "/etc/modules.fs", "/lib/modules", "-t", "squashfs", "-o", "loop"); eval("mount", "/etc/usr.fs", "/usr", "-t", "squashfs", "-o", "loop"); mkdir("/tmp/www", 0700); eval("mount", "-o", "remount,rw", "/"); mkdir("/usr/local/nvram", 0777); unlink("/tmp/nvram/.lock"); mkdir("/tmp/nvram", 0700); eval("cp", "/etc/nvram/nvram.db", "/tmp/nvram"); // eval ("cp", "/etc/nvram/offsets.db", "/tmp/nvram"); cprintf("sysinit() var\n"); /* * /var */ mkdir("/tmp/var", 0777); mkdir("/var/lock", 0777); mkdir("/var/log", 0777); mkdir("/var/run", 0777); mkdir("/var/tmp", 0777); 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"); int brand = getRouterBrand(); // enableAfterBurner (); insmod("md5"); insmod("aes"); insmod("blowfish"); insmod("deflate"); insmod("des"); insmod("michael_mic"); insmod("cast5"); insmod("crypto_null"); system2("/etc/kendin"); insmod("ixp400th"); insmod("ixp400"); system2("cat /usr/lib/firmware/IxNpeMicrocode.dat > /dev/IxNpe"); insmod("ixp400_eth"); insmod("ocf"); insmod("cryptodev"); insmod("ixp4xx", "init_crypto=0"); eval("ifconfig", "ixp0", "0.0.0.0", "up"); eval("vconfig", "add", "ixp0", "1"); eval("vconfig", "add", "ixp0", "2"); detect_wireless_devices(); // load_drivers(); //load madwifi drivers /* * Set a sane date */ stime(&tm); return; cprintf("done\n"); }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; unlink("/etc/nvram/.lock"); cprintf("sysinit() proc\n"); /* * /proc */ mount("proc", "/proc", "proc", MS_MGC_VAL, NULL); cprintf("sysinit() tmp\n"); /* * /tmp */ mount("ramfs", "/tmp", "ramfs", MS_MGC_VAL, NULL); // fix for linux kernel 2.6 mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, NULL); // load ext2 // eval("insmod","jbd"); insmod("ext2"); #ifndef KERNEL_24 if (mount ("/dev/cf/card0/part3", "/usr/local", "ext2", MS_MGC_VAL, NULL)) #else if (mount ("/dev/discs/disc0/part3", "/usr/local", "ext2", MS_MGC_VAL, NULL)) #endif { // not created yet, create ext2 partition eval("/sbin/mkfs.ext2", "-F", "-b", "1024", "/dev/cf/card0/part3"); // mount ext2 mount("/dev/cf/card0/part3", "/usr/local", "ext2", MS_MGC_VAL, NULL); eval("/bin/tar", "-xvvjf", "/etc/local.tar.bz2", "-C", "/"); } eval("mkdir", "-p", "/usr/local/nvram"); unlink("/tmp/nvram/.lock"); eval("cp", "/etc/nvram/nvram.db", "/tmp/nvram"); eval("mount", "/usr/local", "-o", "remount,ro"); // eval ("cp", "/etc/nvram/offsets.db", "/tmp/nvram"); cprintf("sysinit() var\n"); /* * /var */ mkdir("/tmp/var", 0777); mkdir("/var/lock", 0777); mkdir("/var/log", 0777); mkdir("/var/run", 0777); mkdir("/var/tmp", 0777); 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"); int brand = getRouterBrand(); /* * insmod("md5"); insmod("aes"); insmod("blowfish"); insmod("deflate"); * insmod("des"); insmod("michael_mic"); insmod("cast5"); * insmod("crypto_null"); */ detect_wireless_devices(); /* * Set a sane date */ stime(&tm); nvram_set("use_crypto", "0"); nvram_set("wl0_ifname", "ath0"); cprintf("done\n"); return; }
char *enable_dtag_vlan(int enable) { #ifdef HAVE_WHR300HP2 return "eth2"; #endif if (getRouterBrand() != ROUTER_BOARD_ECB9750 && getRouterBrand() != ROUTER_BOARD_TECHNAXX3G) { if (enable) { #if !defined(HAVE_AR670W) && !defined(HAVE_BR6574N) && !defined(HAVE_F5D8235) sysprintf("switch reg w 14 405555"); sysprintf("switch reg w 50 7001"); sysprintf("switch reg w 90 7f7f"); sysprintf("switch reg w 98 7f2f"); sysprintf("switch reg w e4 2f"); #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 40 1007"); 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 #else sysprintf("switch reg w 40 1001"); sysprintf("switch reg w 44 1001"); sysprintf("switch reg w 48 1007"); sysprintf("switch reg w 70 ffff506f"); #endif #endif // now we got vlan7, how do we trunk now. lets find out return "eth2"; } else { #if !defined(HAVE_AR670W) && !defined(HAVE_BR6574N) && !defined(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 7f3f"); sysprintf("switch reg w e4 3f"); #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 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_BR6574N #elif HAVE_AR690W #elif HAVE_RT15N #elif HAVE_AR670W #elif HAVE_F5D8235 #else 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 eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth2", "2"); //WAN return "eth2"; #endif } } else { return "eth2"; } }
void start_mmc(void) { if (nvram_match("mmc_enable", "1")) { #ifdef HAVE_FONERA int res = insmod("mmc"); if (!res) { // device detected insmod("mbcache"); insmod("ext2"); if (mount("/dev/mmc", "/mmc", "ext2", MS_MGC_VAL, NULL)) { // device not formated eval("mkfs.ext2", "-F", "-b", "1024", "/dev/mmc"); mount("/dev/mmc", "/mmc", "ext2", MS_MGC_VAL, NULL); } } #else int res = 1; int mmc_di = 0, mmc_do = 0, mmc_clk = 0, mmc_cs = 0; char dddi[16], dddo[16], ddclk[16], ddcs[16]; if (nvram_match("mmc_gpio", "1")) // manual gpio asigments { mmc_di = strtoul(nvram_safe_get("mmc_di"), NULL, 0); mmc_do = strtoul(nvram_safe_get("mmc_do"), NULL, 0); mmc_clk = strtoul(nvram_safe_get("mmc_clk"), NULL, 0); mmc_cs = strtoul(nvram_safe_get("mmc_cs"), NULL, 0); } else // auto gpio based on router brand/model { switch (getRouterBrand()) { case ROUTER_WRT54G: if (nvram_match("boardtype", "0x0467")) // v4 or GL mmc_di = 2; else mmc_di = 5; mmc_do = 4; mmc_clk = 3; mmc_cs = 7; break; case ROUTER_ASUS_WL500GD: mmc_di = 5; mmc_do = 4; mmc_clk = 1; mmc_cs = 7; break; case ROUTER_BUFFALO_WHRG54S: mmc_di = 5; mmc_do = 6; mmc_clk = 3; mmc_cs = 7; break; case ROUTER_BUFFALO_WZRRSG54: mmc_di = 5; mmc_do = 4; mmc_clk = 3; mmc_cs = 7; break; } } /* sprintf(dddi, "DDDI=0x%X", 1 << mmc_di); sprintf(dddo, "DDDO=0x%X", 1 << mmc_do); sprintf(ddclk, "DDCLK=0x%X", 1 << mmc_clk); sprintf(ddcs, "DDCS=0x%X", 1 << mmc_cs); */ sprintf(dddi, "din=%d", mmc_di); sprintf(dddo, "dout=%d", mmc_do); sprintf(ddclk, "clk=%d", mmc_clk); sprintf(ddcs, "cs=%d", mmc_cs); if ((mmc_di + mmc_do + mmc_clk + mmc_cs) > 5) // eval only // if at // least 0, // 1, 2, 3 res = eval("insmod", "mmc", dddi, dddo, ddclk, ddcs); // eval("insmod","mmc", // "DDDI=0x04", // "DDDO=0x10", // "DDCLK=0x08", // "DDCS=0x80"); if (!res) { // device detected insmod("ext2"); if (mount("/dev/mmc/disc0/part1", "/mmc", "ext2", MS_MGC_VAL, NULL)) { // device not formated eval("mkfs.ext2", "-F", "-b", "1024", "/dev/mmc/disc0/part1"); mount("/dev/mmc/disc0/part1", "/mmc", "ext2", MS_MGC_VAL, NULL); } } #endif } }
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; if (!nvram_match("disable_watchdog", "1")) { insmod("imx2_wdt"); eval("watchdog"); } /* * Setup console */ eval("mount", "-o", "remount,rw", "/"); eval("mkdir", "-p", "/usr/local/nvram"); 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("sky2"); if (detect_ethernet_devices()) nvram_set("intel_eth", "1"); /* * 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); } eval("ifconfig", "eth0", "promisc"); eval("ifconfig", "eth1", "promisc"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); eval("hwclock", "-s"); eval("i2cset", "-f", "-y", "0", "0x20", "0", "0x0"); eval("i2cset", "-f", "-y", "0", "0x20", "11", "0x10"); char *board = nvram_safe_get("DD_BOARD"); char *board2 = nvram_safe_get("DD_BOARD2"); if (!strncmp(board, "Gateworks Ventana GW54",22) || !strncmp(board2, "Gateworks Ventana GW54",22)) sysprintf("gsp_updater -f /etc/gsc_5400_v43.txt 43"); if (!strncmp(board, "Gateworks Ventana GW53",22) || !strncmp(board2, "Gateworks Ventana GW53",22)) sysprintf("gsp_updater -f /etc/gsc_5300_v43.txt 43"); if (!strncmp(board, "Gateworks Ventana GW52",22) || !strncmp(board2, "Gateworks Ventana GW52",22)) sysprintf("gsp_updater -f /etc/gsc_5200_v43.txt 43"); if (!strncmp(board, "Gateworks Ventana GW51",22) || !strncmp(board2, "Gateworks Ventana GW51",22)) sysprintf("gsp_updater -f /etc/gsc_5100_v43.txt 43"); led_control(LED_POWER, LED_ON); led_control(LED_DIAG, LED_OFF); led_control(LED_SES, LED_OFF); led_control(LED_SES2, 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); sysprintf("echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"); return; }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; mknod("/dev/gpio",S_IFCHR|0644,makedev(127,0)); mkdir("/usr/local",0700); mkdir("/usr/local/nvram",0700); install_sdcard(); cprintf("sysinit() setup console\n"); eval("insmod", "ks8695_wdt", "wdt_time=30"); // load watchdog module with 30 seconds timeout 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(); /* * network drivers */ eval("ifconfig", "eth0", "up"); eval("ifconfig", "eth1", "up"); eval("ifconfig", "eth2", "up"); eval("ifconfig", "eth3", "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(); system2("echo 1 >/proc/sys/dev/wifi0/softled"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); //disable led's return; cprintf("done\n"); }
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) { 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) { 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; }