Example #1
0
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");
}
Example #2
0
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 ag7240_mod");
	insmod("ledtrig-netdev");

	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);
		MAC_SUB(mac);
		eval("ifconfig", "eth0", "hw", "ether", mac);
		MAC_ADD(mac);
		MAC_ADD(mac);
		fprintf(stderr, "configure eth1 to %s\n", mac);
		eval("ifconfig", "eth1", "hw", "ether", mac);
#ifndef HAVE_ATH9K
		MAC_SUB(mac);
#endif
	}

	eval("ifconfig", "eth0", "up");
	eval("ifconfig", "eth1", "up");

#ifdef HAVE_SWCONFIG

#ifdef HAVE_WDR2543
		system("swconfig dev switch0 set reset 1");
		system("swconfig dev switch0 set enable_vlan 1");
		system("swconfig dev switch0 vlan 1 set ports \"1 2 3 4 9t\"");
		system("swconfig dev switch0 vlan 2 set ports \"0 9t\"");
		system("swconfig dev switch0 set apply");
		eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");
		eval("vconfig", "add", "eth0", "1");
		eval("vconfig", "add", "eth0", "2");

#else
		system("swconfig dev eth1 set reset 1");
		system("swconfig dev eth1 set enable_vlan 0");
		system("swconfig dev eth1 vlan 1 set ports \"0 1 2 3 4\"");
		system("swconfig dev eth1 set apply");
	setEthLED(17,"eth0");
	setSwitchLED(13,0x2);
	setSwitchLED(14,0x4);
	setSwitchLED(15,0x8);
	setSwitchLED(16,0x10);
#endif

#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();
#ifndef HAVE_ATH9K
	fprintf(stderr, "configure wifi0 to %s\n", mac);
	eval("ifconfig", "wifi0", "hw", "ether", mac);
#endif
	//enable wlan led (card gpio based)
#if defined(HAVE_WR841v7) || defined(HAVE_WR842) || defined(HAVE_MR3420)
	setWirelessLedPhy0(0);
#else
	setWirelessLedPhy0(1);
#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");
}
Example #3
0
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");
}