Exemplo n.º 1
0
Arquivo: wpa.c Projeto: rogerhu/dd-wrt
static void convert_wds(int instance)
{
	char wds_mac[254];
	char buf[254];

	if (nvram_nmatch("", "wl%d_wds", instance))	// For Router, accept 
		// all WDS link
		strcpy(wds_mac, "*");
	else			// For AP, assign remote WDS MAC
		strcpy(wds_mac, nvram_nget("wl%d_wds", instance));

	/*
	 * For WPA-PSK mode, we want to convert wl_wds_mac to wl0_wds0 ...
	 * wl0_wds255 
	 */
	if (nvram_nmatch("psk", "wl%d_security_mode", instance)
	    || nvram_nmatch("psk2", "wl%d_security_mode", instance)) {
		int i = 0;
		int j;
		char mac[254];
		char *next;

		foreach(mac, wds_mac, next) {
			snprintf(buf, sizeof(buf), "%s,auto,%s,%s,%s,%s",
				 mac, nvram_nget("wl%d_crypto", instance), nvram_nget("wl%d_security_mode", instance), nvram_nget("wl%d_ssid", instance), nvram_nget("wl%d_wpa_psk", instance));
			nvram_nset(buf, "wl%d_wds%d", instance, i);
			i++;
		}
Exemplo n.º 2
0
void configure_wimax(void)
{
	char *mode = "0";
	char *dev = "ofdm";

	if (nvram_match("ofdm_duplex", "TDD"))
		mode = "0";
	if (nvram_match("ofdm_duplex", "H-FDD"))
		mode = "1";
	if (nvram_match("ofdm_mode", "disabled"))
		return;
	char width[32];

	sprintf(width, "%smhz", nvram_safe_get("ofdm_width"));
	eval("/sub/lm_scripts/go_ss", width, "0", mode);
	if (!nvram_match("ofdm_mode", "sta")) {
		char bridged[32];

		sprintf(bridged, "%s_bridged", dev);
		if (nvram_default_match(bridged, "1", "1")) {
			eval("ifconfig", dev, "0.0.0.0", "up");
			br_add_interface(getBridge(dev), dev);
			eval("ifconfig", dev, "0.0.0.0", "up");
		} else {
			eval("ifconfig", dev, nvram_nget("%s_ipaddr", dev), "netmask", nvram_nget("%s_netmask", dev), "up");
		}
	} else {
		char bridged[32];

		sprintf(bridged, "%s_bridged", dev);
		if (nvram_default_match(bridged, "0", "1")) {
			eval("ifconfig", dev, nvram_nget("%s_ipaddr", dev), "netmask", nvram_nget("%s_netmask", dev), "up");
		}
	}
}
Exemplo n.º 3
0
static char *getifip(void)
{
	if (nvram_match("pppoeserver_interface", "br0"))
		return nvram_safe_get("lan_ipaddr");
	else
		return nvram_nget("%s_ipaddr", nvram_safe_get("pppoeserver_interface"));
}
Exemplo n.º 4
0
Arquivo: wpa.c Projeto: rogerhu/dd-wrt
void start_radius(char *prefix)
{

	// wrt-radauth $IFNAME $server $port $share $override $mackey $maxun &

	if (nvram_nmatch("1", "%s_radauth", prefix)
	    && nvram_nmatch("ap", "%s_mode", prefix)) {
		char *server = nvram_nget("%s_radius_ipaddr", prefix);
		char *port = nvram_nget("%s_radius_port", prefix);
		char *share = nvram_nget("%s_radius_key", prefix);
		char *ifname = nvram_nget("%s_ifname", prefix);
		char type[32];

		sprintf(type, "%s_radmactype", prefix);
		char *pragma = "";

		if (nvram_default_match(type, "0", "0"))
			pragma = "-n1 ";
		if (nvram_match(type, "1"))
			pragma = "-n2 ";
		if (nvram_match(type, "2"))
			pragma = "-n3 ";
		if (nvram_match(type, "3"))
			pragma = "";
		sleep(1);	// some delay is usefull
		sysprintf("wrt-radauth %s %s %s %s %s %s %s %s &", pragma,
			  ifname, server, port, share, nvram_nget("%s_radius_override", prefix), nvram_nget("%s_radmacpassword", prefix), nvram_nget("%s_max_unauth_users", prefix));
	}

}
Exemplo n.º 5
0
void start_vlantagging(void)
{
	static char word[256];
	char *next, *wordlist;

	wordlist = nvram_safe_get("vlan_tags");
	foreach(word, wordlist, next) {

		char *port = word;
		char *tag = strsep(&port, ">");
		char *prio = port;
		strsep(&prio, ">");

		if (!tag || !port) {
			break;
		}
		if (!prio)
			prio = "0";
		eval("vconfig", "set_name_type", "DEV_PLUS_VID_NO_PAD");
		eval("vconfig", "add", tag, port);
		char vlan_name[32];

		sprintf(vlan_name, "%s.%s", tag, port);
		eval("vconfig", "set_egress_map", vlan_name, "0", prio);

		char var[64];

		sprintf(var, "%s_bridged", vlan_name);
		if (nvram_default_match(var, "1", "1")) {
			eval("ifconfig", vlan_name, "0.0.0.0", "up");
		} else {
			eval("ifconfig", vlan_name,
			     nvram_nget("%s_ipaddr", vlan_name), "netmask",
			     nvram_nget("%s_netmask", vlan_name), "up");
		}
	}
Exemplo n.º 6
0
void ej_active_wireless(webs_t wp, int argc, char_t ** argv)
{
	int cnt = 0;
	int c = get_wl_instances();
	int i;

	for (i = 0; i < c; i++) {
		char wlif[32];

		sprintf(wlif, "wl%d", i);
		cnt = ej_active_wireless_if(wp, argc, argv, get_wl_instance_name(i), wlif, cnt);
		char *next;
		char var[80];
		char *vifs = nvram_nget("wl%d_vifs", i);

		if (vifs == NULL)
			return;

		foreach(var, vifs, next) {
			cnt = ej_active_wireless_if(wp, argc, argv, var, var, cnt);
		}
	}
Exemplo n.º 7
0
int svqos_set_ports(void)
{
#ifndef HAVE_XSCALE
#ifndef HAVE_MAGICBOX
#ifndef HAVE_RB600
#ifndef HAVE_FONERA
#ifndef HAVE_RT2880
#ifndef HAVE_LS2
#ifndef HAVE_LS5
#ifndef HAVE_WHRAG108
#ifndef HAVE_CA8
#ifndef HAVE_SOLO51
#ifndef HAVE_X86
#ifndef HAVE_LAGUNA
#ifndef HAVE_VENTANA
#ifndef HAVE_TW6600
#ifndef HAVE_PB42
#ifndef HAVE_LSX
#ifndef HAVE_DANUBE
#ifndef HAVE_STORM
#ifndef HAVE_OPENRISC
#ifndef HAVE_ADM5120
	if (nvram_match("portprio_support", "1")) {
		int loop = 1;
		char nvram_var[32] = {
			0
		}, *level;

		svqos_reset_ports();

		for (loop = 1; loop < 5; loop++) {
			snprintf(nvram_var, 31, "svqos_port%dbw", loop);

			if (strcmp("0", nvram_safe_get(nvram_var)))
				writevaproc(nvram_safe_get(nvram_var), "/proc/switch/eth0/port/%d/bandwidth", loop);
			else
				writevaproc("0", "/proc/switch/eth0/port/%d/enable", loop);

			writevaproc("1", "/proc/switch/eth0/port/%d/prio-enable", loop);
			level = nvram_nget("svqos_port%dprio", loop);
			char lvl[32];
			sprintf(lvl, "%d", atoi(level) / 10 - 1);
			writevaproc(lvl, "/proc/switch/eth0/port/%d/prio", loop);
		}
	}
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif

	return 0;
}
Exemplo n.º 8
0
void setupSupplicant(char *prefix)
{
	char akm[16];

	sprintf(akm, "%s_akm", prefix);
	char wmode[16];

	sprintf(wmode, "%s_mode", prefix);
	if (nvram_match(akm, "8021X")) {
		char fstr[32];
		char psk[64];
		char ath[64];

		sprintf(fstr, "/tmp/%s_wpa_supplicant.conf", prefix);
		FILE *fp = fopen(fstr, "wb");

		fprintf(fp, "ap_scan=1\n");
		fprintf(fp, "fast_reauth=1\n");
		fprintf(fp, "eapol_version=1\n");
		fprintf(fp, "network={\n");
		sprintf(psk, "%s_ssid", prefix);
		fprintf(fp, "\tssid=\"%s\"\n", nvram_safe_get(psk));
		fprintf(fp, "\tscan_ssid=1\n");
		if (nvram_prefix_match("8021xtype", prefix, "tls")) {
// -> added habeIchVergessen
			char *keyExchng = nvram_nget("%s_tls8021xkeyxchng", prefix);
			char *wpaOpts[40];
			if (strlen(keyExchng)==0)
			    nvram_nset("wep","%s_tls8021xkeyxchng", prefix);
			sprintf(wpaOpts, "");
			keyExchng = nvram_nget("%s_tls8021xkeyxchng", prefix);
			if (strcmp("wpa2", keyExchng) == 0)
				sprintf(wpaOpts, "\tpairwise=CCMP\n\tgroup=CCMP\n");
			if (strcmp("wpa2mixed", keyExchng) == 0)
                         	sprintf(wpaOpts, "\tpairwise=CCMP TKIP\n\tgroup=CCMP TKIP\n");
			if (strcmp("wpa", keyExchng) == 0)
                        	sprintf(wpaOpts, "\tpairwise=TKIP\n\tgroup=TKIP\n");
			fprintf(fp, "\tkey_mgmt=%s\n%s", (strlen(wpaOpts) == 0 ? "IEEE8021X" : "WPA-EAP"), wpaOpts);
// <- added habeIchVergessen
			fprintf(fp, "\teap=TLS\n");
			fprintf(fp, "\tidentity=\"%s\"\n",
				nvram_prefix_get("tls8021xuser", prefix));
			sprintf(psk, "/tmp/%s", prefix);
			mkdir(psk);
			sprintf(psk, "/tmp/%s/ca.pem", prefix);
			sprintf(ath, "%s_tls8021xca", prefix);
			write_nvram(psk, ath);
			sprintf(psk, "/tmp/%s/user.pem", prefix);
			sprintf(ath, "%s_tls8021xpem", prefix);
			write_nvram(psk, ath);

			sprintf(psk, "/tmp/%s/user.prv", prefix);
			sprintf(ath, "%s_tls8021xprv", prefix);
			write_nvram(psk, ath);
			fprintf(fp, "\tca_cert=/tmp/%s/ca.pem\n", prefix);
			fprintf(fp, "\tclient_cert=/tmp/%s/user.pem\n", prefix);
			fprintf(fp, "\tprivate_key=/tmp/%s/user.prv\n", prefix);
			fprintf(fp, "\tprivate_key_passwd=\"%s\"\n",
				nvram_prefix_get("tls8021xpasswd", prefix));
			fprintf(fp, "\teapol_flags=3\n");
			if (strlen(nvram_nget("%s_tls8021xphase2", prefix)) > 0) {
				fprintf(fp, "\tphase2=\"%s\"\n",
					nvram_nget("%s_tls8021xphase2",
						   prefix));
			}
			if (strlen(nvram_nget("%s_tls8021xanon", prefix)) > 0) {
				fprintf(fp, "\tanonymous_identity=\"%s\"\n",
					nvram_nget("%s_tls8021xanon", prefix));
			}
			if (strlen(nvram_nget("%s_tls8021xaddopt", prefix)) > 0) {
				sprintf(ath, "%s_tls8021xaddopt", prefix);
				fprintf(fp, "\t");	// tab
				fwritenvram(ath, fp);
				fprintf(fp, "\n");	// extra new line at the end
			}
		}
		if (nvram_prefix_match("8021xtype", prefix, "peap")) {
			fprintf(fp, "\tkey_mgmt=WPA-EAP\n");
			fprintf(fp, "\teap=PEAP\n");
			fprintf(fp, "\tpairwise=CCMP TKIP\n");
			fprintf(fp, "\tgroup=CCMP TKIP\n");
			fprintf(fp, "\tphase1=\"peapver=0\"\n");
			fprintf(fp, "\tidentity=\"%s\"\n",
				nvram_prefix_get("peap8021xuser", prefix));
			fprintf(fp, "\tpassword=\"%s\"\n",
				nvram_prefix_get("peap8021xpasswd", prefix));
			sprintf(psk, "/tmp/%s", prefix);
			mkdir(psk);
			sprintf(psk, "/tmp/%s/ca.pem", prefix);
			sprintf(ath, "%s_peap8021xca", prefix);
			if (!nvram_match(ath, "")) {
				write_nvram(psk, ath);
				fprintf(fp, "\tca_cert=\"/tmp/%s/ca.pem\"\n",
					prefix);
			}
			if (strlen(nvram_nget("%s_peap8021xphase2", prefix)) >
			    0) {
				fprintf(fp, "\tphase2=\"%s\"\n",
					nvram_nget("%s_peap8021xphase2",
						   prefix));
			}
			if (strlen(nvram_nget("%s_peap8021xanon", prefix)) > 0) {
				fprintf(fp, "\tanonymous_identity=\"%s\"\n",
					nvram_nget("%s_peap8021xanon", prefix));
			}
			if (strlen(nvram_nget("%s_peap8021xaddopt", prefix)) >
			    0) {
				sprintf(ath, "%s_peap8021xaddopt", prefix);
				fprintf(fp, "\t");	// tab
				fwritenvram(ath, fp);
				fprintf(fp, "\n");	// extra new line at the end
			}
		}
		if (nvram_prefix_match("8021xtype", prefix, "ttls")) {
			fprintf(fp, "\tkey_mgmt=WPA-EAP\n");
			fprintf(fp, "\teap=TTLS\n");
			fprintf(fp, "\tpairwise=CCMP TKIP\n");
			fprintf(fp, "\tgroup=CCMP TKIP\n");
			fprintf(fp, "\tidentity=\"%s\"\n",
				nvram_prefix_get("ttls8021xuser", prefix));
			fprintf(fp, "\tpassword=\"%s\"\n",
				nvram_prefix_get("ttls8021xpasswd", prefix));
			if (strlen(nvram_nget("%s_ttls8021xca", prefix)) > 0) {
				sprintf(psk, "/tmp/%s", prefix);
				mkdir(psk);
				sprintf(psk, "/tmp/%s/ca.pem", prefix);
				sprintf(ath, "%s_ttls8021xca", prefix);
				write_nvram(psk, ath);
				fprintf(fp, "\tca_cert=\"/tmp/%s/ca.pem\"\n",
					prefix);
			}
			if (strlen(nvram_nget("%s_ttls8021xphase2", prefix)) >
			    0) {
				fprintf(fp, "\tphase2=\"%s\"\n",
					nvram_nget("%s_ttls8021xphase2",
						   prefix));
			}
			if (strlen(nvram_nget("%s_ttls8021xanon", prefix)) > 0) {
				fprintf(fp, "\tanonymous_identity=\"%s\"\n",
					nvram_nget("%s_ttls8021xanon", prefix));
			}
			if (strlen(nvram_nget("%s_ttls8021xaddopt", prefix)) >
			    0) {
				sprintf(ath, "%s_ttls8021xaddopt", prefix);
				fprintf(fp, "\t");	// tab
				fwritenvram(ath, fp);
				fprintf(fp, "\n");	// extra new line at the end
			}
		}
		if (nvram_prefix_match("8021xtype", prefix, "leap")) {
			fprintf(fp, "\tkey_mgmt=WPA-EAP\n");
			fprintf(fp, "\teap=LEAP\n");
			fprintf(fp, "\tauth_alg=LEAP\n");
			fprintf(fp, "\tproto=WPA RSN\n");
			fprintf(fp, "\tpairwise=CCMP TKIP\n");
			fprintf(fp, "\tgroup=CCMP TKIP\n");
			fprintf(fp, "\tidentity=\"%s\"\n",
				nvram_prefix_get("leap8021xuser", prefix));
			fprintf(fp, "\tpassword=\"%s\"\n",
				nvram_prefix_get("leap8021xpasswd", prefix));
			if (strlen(nvram_nget("%s_leap8021xphase2", prefix)) >
			    0) {
				fprintf(fp, "\tphase2=\"%s\"\n",
					nvram_nget("%s_leap8021xphase2",
						   prefix));
			}
			if (strlen(nvram_nget("%s_leap8021xanon", prefix)) > 0) {
				fprintf(fp, "\tanonymous_identity=\"%s\"\n",
					nvram_nget("%s_leap8021xanon", prefix));
			}
			if (strlen(nvram_nget("%s_leap8021xaddopt", prefix)) >
			    0) {
				sprintf(ath, "%s_leap8021xaddopt", prefix);
				fprintf(fp, "\t");	// tab
				fwritenvram(ath, fp);
				fprintf(fp, "\n");	// extra new line at the end
			}
		}
		fprintf(fp, "}\n");
		fclose(fp);
		sprintf(psk, "-i%s", getRADev(prefix));

		char bvar[32];

		sprintf(bvar, "%s_bridged", prefix);
		if (nvram_match(bvar, "1")
		    && (nvram_match(wmode, "wdssta")
			|| nvram_match(wmode, "wet")))
			eval("wpa_supplicant", "-b",
			     nvram_safe_get("lan_ifname"), "-B", "-Dralink",
			     psk, "-c", fstr);
		else
			eval("wpa_supplicant", "-B", "-Dralink", psk, "-c",
			     fstr);
	}

}
Exemplo n.º 9
0
void setupSupplicant(char *prefix)
{
	char akm[16];

	sprintf(akm, "%s_akm", prefix);
	char wmode[16];

	sprintf(wmode, "%s_mode", prefix);
	if (nvram_match(akm, "wep")) {
		char key[16];
		int cnt = 1;
		int i;
		char bul[8];

		for (i = 1; i < 5; i++) {
			sprintf(key, "%s_key%d", prefix, i);
			char *athkey = nvram_safe_get(key);

			if (athkey != NULL && strlen(athkey) > 0) {
				sprintf(bul, "[%d]", cnt++);
				eval("iwconfig", prefix, "key", bul, athkey);	// setup wep
				// encryption 
				// key
			}
		}
		sprintf(key, "%s_key", prefix);
		sprintf(bul, "[%s]", nvram_safe_get(key));
		eval("iwconfig", prefix, "key", bul);
		// eval ("iwpriv", prefix, "authmode", "2");
	} else if (nvram_match(akm, "psk") || nvram_match(akm, "psk2") || nvram_match(akm, "psk psk2")) {
		char fstr[64];
		char psk[16];

		sprintf(fstr, "/tmp/%s_wpa_supplicant.conf", prefix);
		FILE *fp = fopen(fstr, "wb");

#ifdef HAVE_MAKSAT
		fprintf(fp, "ap_scan=1\n");
#elif HAVE_NEWMEDIA
		fprintf(fp, "ap_scan=1\n");
#else
		fprintf(fp, "ap_scan=2\n");
#endif
		fprintf(fp, "fast_reauth=1\n");
		fprintf(fp, "eapol_version=1\n");
		// fprintf (fp, "ctrl_interface_group=0\n");
		// fprintf (fp, "ctrl_interface=/var/run/wpa_supplicant\n");

		fprintf(fp, "network={\n");
		sprintf(psk, "%s_ssid", prefix);
		fprintf(fp, "\tssid=\"%s\"\n", nvram_safe_get(psk));
		// fprintf (fp, "\tmode=0\n");
		fprintf(fp, "\tscan_ssid=1\n");
		fprintf(fp, "\tkey_mgmt=WPA-PSK\n");

		sprintf(psk, "%s_crypto", prefix);
		if (nvram_match(psk, "aes")) {
#if 1
			fprintf(fp, "\tpairwise=CCMP\n");
			fprintf(fp, "\tgroup=CCMP TKIP\n");
#else
			fprintf(fp, "\tpairwise=CCMP\n");
			fprintf(fp, "\tgroup=CCMP\n");
#endif
		}
		if (nvram_match(psk, "tkip")) {
			fprintf(fp, "\tpairwise=TKIP\n");
			fprintf(fp, "\tgroup=TKIP\n");
		}
		if (nvram_match(psk, "tkip+aes")) {
			fprintf(fp, "\tpairwise=CCMP TKIP\n");
			fprintf(fp, "\tgroup=CCMP TKIP\n");
		}
		if (nvram_match(akm, "psk"))
			fprintf(fp, "\tproto=WPA\n");
		if (nvram_match(akm, "psk2"))
			fprintf(fp, "\tproto=RSN\n");
		if (nvram_match(akm, "psk psk2"))
			fprintf(fp, "\tproto=WPA RSN\n");

		sprintf(psk, "%s_wpa_psk", prefix);
		fprintf(fp, "\tpsk=\"%s\"\n", nvram_safe_get(psk));
		fprintf(fp, "}\n");
		fclose(fp);
		if (!strcmp(prefix, "wl0"))
			sprintf(psk, "-i%s", nvram_safe_get("wl0_ifname"));
		else if (!strcmp(prefix, "wl1"))
			sprintf(psk, "-i%s", nvram_safe_get("wl1_ifname"));
		else
			sprintf(psk, "-i%s", prefix);

		if (nvram_match(wmode, "wdssta") || nvram_match(wmode, "wet"))
			eval("wpa_supplicant", "-b", getBridge(prefix), "-B", "-Dwext", psk, "-c", fstr);
		else
			eval("wpa_supplicant", "-B", "-Dwext", psk, "-c", fstr);
	} else if (nvram_match(akm, "8021X")) {
		char fstr[32];
		char psk[64];
		char ath[64];

		sprintf(fstr, "/tmp/%s_wpa_supplicant.conf", prefix);
		FILE *fp = fopen(fstr, "wb");

		fprintf(fp, "ap_scan=1\n");
		fprintf(fp, "fast_reauth=1\n");
		fprintf(fp, "eapol_version=1\n");
		// fprintf (fp, "ctrl_interface_group=0\n");
		// fprintf (fp, "ctrl_interface=/var/run/wpa_supplicant\n");
		fprintf(fp, "network={\n");
		sprintf(psk, "%s_ssid", prefix);
		fprintf(fp, "\tssid=\"%s\"\n", nvram_safe_get(psk));
		fprintf(fp, "\tscan_ssid=1\n");
		if (nvram_prefix_match("8021xtype", prefix, "tls")) {
// -> added habeIchVergessen
			char *keyExchng = nvram_nget("%s_tls8021xkeyxchng", prefix);
			char *wpaOpts[40];
			if (strlen(keyExchng) == 0)
				nvram_nset("wep", "%s_tls8021xkeyxchng", prefix);
			sprintf(wpaOpts, "");
			keyExchng = nvram_nget("%s_tls8021xkeyxchng", prefix);
			if (strcmp("wpa2", keyExchng) == 0)
				sprintf(wpaOpts, "\tpairwise=CCMP\n\tgroup=CCMP\n");
			if (strcmp("wpa2mixed", keyExchng) == 0)
				sprintf(wpaOpts, "\tpairwise=CCMP TKIP\n\tgroup=CCMP TKIP\n");
			if (strcmp("wpa", keyExchng) == 0)
				sprintf(wpaOpts, "\tpairwise=TKIP\n\tgroup=TKIP\n");
			fprintf(fp, "\tkey_mgmt=%s\n%s", (strlen(wpaOpts) == 0 ? "IEEE8021X" : "WPA-EAP"), wpaOpts);
// <- added habeIchVergessen
			fprintf(fp, "\teap=TLS\n");
			fprintf(fp, "\tidentity=\"%s\"\n", nvram_prefix_get("tls8021xuser", prefix));
			sprintf(psk, "/tmp/%s", prefix);
			mkdir(psk, 0700);
			sprintf(psk, "/tmp/%s/ca.pem", prefix);
			sprintf(ath, "%s_tls8021xca", prefix);
			write_nvram(psk, ath);
			sprintf(psk, "/tmp/%s/user.pem", prefix);
			sprintf(ath, "%s_tls8021xpem", prefix);
			write_nvram(psk, ath);

			sprintf(psk, "/tmp/%s/user.prv", prefix);
			sprintf(ath, "%s_tls8021xprv", prefix);
			write_nvram(psk, ath);
			fprintf(fp, "\tca_cert=/tmp/%s/ca.pem\n", prefix);
			fprintf(fp, "\tclient_cert=/tmp/%s/user.pem\n", prefix);
			fprintf(fp, "\tprivate_key=/tmp/%s/user.prv\n", prefix);
			fprintf(fp, "\tprivate_key_passwd=\"%s\"\n", nvram_prefix_get("tls8021xpasswd", prefix));
			fprintf(fp, "\teapol_flags=3\n");
			if (strlen(nvram_nget("%s_tls8021xphase2", prefix)) > 0) {
				fprintf(fp, "\tphase2=\"%s\"\n", nvram_nget("%s_tls8021xphase2", prefix));
			}
			if (strlen(nvram_nget("%s_tls8021xanon", prefix)) > 0) {
				fprintf(fp, "\tanonymous_identity=\"%s\"\n", nvram_nget("%s_tls8021xanon", prefix));
			}
			if (strlen(nvram_nget("%s_tls8021xaddopt", prefix)) > 0) {
				sprintf(ath, "%s_tls8021xaddopt", prefix);
				fprintf(fp, "\t");	// tab
				fwritenvram(ath, fp);
				fprintf(fp, "\n");	// extra new line at the end
			}
		}
		if (nvram_prefix_match("8021xtype", prefix, "peap")) {
			fprintf(fp, "\tkey_mgmt=WPA-EAP\n");
			fprintf(fp, "\teap=PEAP\n");
			fprintf(fp, "\tpairwise=CCMP TKIP\n");
			fprintf(fp, "\tgroup=CCMP TKIP\n");
			fprintf(fp, "\tphase1=\"peapver=0\"\n");
			fprintf(fp, "\tidentity=\"%s\"\n", nvram_prefix_get("peap8021xuser", prefix));
			fprintf(fp, "\tpassword=\"%s\"\n", nvram_prefix_get("peap8021xpasswd", prefix));
			sprintf(psk, "/tmp/%s", prefix);
			mkdir(psk, 0700);
			sprintf(psk, "/tmp/%s/ca.pem", prefix);
			sprintf(ath, "%s_peap8021xca", prefix);
			if (!nvram_match(ath, "")) {
				write_nvram(psk, ath);
				fprintf(fp, "\tca_cert=\"/tmp/%s/ca.pem\"\n", prefix);
			}
			if (strlen(nvram_nget("%s_peap8021xphase2", prefix)) > 0) {
				fprintf(fp, "\tphase2=\"%s\"\n", nvram_nget("%s_peap8021xphase2", prefix));
			}
			if (strlen(nvram_nget("%s_peap8021xanon", prefix)) > 0) {
				fprintf(fp, "\tanonymous_identity=\"%s\"\n", nvram_nget("%s_peap8021xanon", prefix));
			}
			if (strlen(nvram_nget("%s_peap8021xaddopt", prefix)) > 0) {
				sprintf(ath, "%s_peap8021xaddopt", prefix);
				fprintf(fp, "\t");	// tab
				fwritenvram(ath, fp);
				fprintf(fp, "\n");	// extra new line at the end
			}
		}
		if (nvram_prefix_match("8021xtype", prefix, "ttls")) {
			fprintf(fp, "\tkey_mgmt=WPA-EAP\n");
			fprintf(fp, "\teap=TTLS\n");
			fprintf(fp, "\tpairwise=CCMP TKIP\n");
			fprintf(fp, "\tgroup=CCMP TKIP\n");
			fprintf(fp, "\tidentity=\"%s\"\n", nvram_prefix_get("ttls8021xuser", prefix));
			fprintf(fp, "\tpassword=\"%s\"\n", nvram_prefix_get("ttls8021xpasswd", prefix));
			if (strlen(nvram_nget("%s_ttls8021xca", prefix)) > 0) {
				sprintf(psk, "/tmp/%s", prefix);
				mkdir(psk, 0700);
				sprintf(psk, "/tmp/%s/ca.pem", prefix);
				sprintf(ath, "%s_ttls8021xca", prefix);
				write_nvram(psk, ath);
				fprintf(fp, "\tca_cert=\"/tmp/%s/ca.pem\"\n", prefix);
			}
			if (strlen(nvram_nget("%s_ttls8021xphase2", prefix)) > 0) {
				fprintf(fp, "\tphase2=\"%s\"\n", nvram_nget("%s_ttls8021xphase2", prefix));
			}
			if (strlen(nvram_nget("%s_ttls8021xanon", prefix)) > 0) {
				fprintf(fp, "\tanonymous_identity=\"%s\"\n", nvram_nget("%s_ttls8021xanon", prefix));
			}
			if (strlen(nvram_nget("%s_ttls8021xaddopt", prefix)) > 0) {
				sprintf(ath, "%s_ttls8021xaddopt", prefix);
				fprintf(fp, "\t");	// tab
				fwritenvram(ath, fp);
				fprintf(fp, "\n");	// extra new line at the end
			}
		}
		if (nvram_prefix_match("8021xtype", prefix, "leap")) {
			fprintf(fp, "\tkey_mgmt=WPA-EAP\n");
			fprintf(fp, "\teap=LEAP\n");
			fprintf(fp, "\tauth_alg=LEAP\n");
			fprintf(fp, "\tproto=WPA RSN\n");
			fprintf(fp, "\tpairwise=CCMP TKIP\n");
			fprintf(fp, "\tgroup=CCMP TKIP\n");
			fprintf(fp, "\tidentity=\"%s\"\n", nvram_prefix_get("leap8021xuser", prefix));
			fprintf(fp, "\tpassword=\"%s\"\n", nvram_prefix_get("leap8021xpasswd", prefix));
			if (strlen(nvram_nget("%s_leap8021xphase2", prefix)) > 0) {
				fprintf(fp, "\tphase2=\"%s\"\n", nvram_nget("%s_leap8021xphase2", prefix));
			}
			if (strlen(nvram_nget("%s_leap8021xanon", prefix)) > 0) {
				fprintf(fp, "\tanonymous_identity=\"%s\"\n", nvram_nget("%s_leap8021xanon", prefix));
			}
			if (strlen(nvram_nget("%s_leap8021xaddopt", prefix)) > 0) {
				sprintf(ath, "%s_leap8021xaddopt", prefix);
				fprintf(fp, "\t");	// tab
				fwritenvram(ath, fp);
				fprintf(fp, "\n");	// extra new line at the end
			}
		}

		fprintf(fp, "}\n");
		fclose(fp);
		if (!strcmp(prefix, "wl0"))
			sprintf(psk, "-i%s", nvram_safe_get("wl0_ifname"));
		else if (!strcmp(prefix, "wl1"))
			sprintf(psk, "-i%s", nvram_safe_get("wl1_ifname"));
		else
			sprintf(psk, "-i%s", prefix);

		char bvar[32];

		sprintf(bvar, "%s_bridged", prefix);
		if (nvram_match(bvar, "1")
		    && (nvram_match(wmode, "wdssta")
			|| nvram_match(wmode, "wet")))
			eval("wpa_supplicant", "-b", nvram_safe_get("lan_ifname"), "-B", "-Dwext", psk, "-c", fstr);
		else
			eval("wpa_supplicant", "-B", "-Dwext", psk, "-c", fstr);
	} else {
		eval("iwconfig", prefix, "key", "off");
		// eval ("iwpriv", prefix, "authmode", "0");
	}

}
Exemplo n.º 10
0
void start_dnsmasq(void)
{
	FILE *fp;
	struct dns_lists *dns_list = NULL;
	int ret;
	int i;

	if (nvram_match("dhcp_dnsmasq", "1")
	    && nvram_match("lan_proto", "dhcp")
	    && nvram_match("dnsmasq_enable", "0")) {
		nvram_set("dnsmasq_enable", "1");
		nvram_commit();
	}

	if (!nvram_invmatch("dnsmasq_enable", "0")) {
		stop_dnsmasq();
		return;
	}

	usejffs = 0;

	if (nvram_match("dhcpd_usejffs", "1")) {
		if (!(fp = fopen("/jffs/dnsmasq.leases", "a"))) {
			usejffs = 0;
		} else {
			fclose(fp);
			usejffs = 1;
		}
	}

	/*
	 * Write configuration file based on current information 
	 */
	if (!(fp = fopen("/tmp/dnsmasq.conf", "w"))) {
		perror("/tmp/dnsmasq.conf");
		return;
	}
//    fprintf(fp, "bind-interfaces\n");
	if (nvram_match("chilli_enable", "1")) {
		if (canlan())
			fprintf(fp, "interface=%s", get_wdev());
		else
			fprintf(fp, "interface=%s,", get_wdev());
	} else if (nvram_match("pptpd_enable", "1")) {
		if (canlan())
			fprintf(fp, "listen-address=%s,%s", "127.0.0.1",
				nvram_safe_get("lan_ipaddr"));
		else
			fprintf(fp, "listen-address=%s", "127.0.0.1");
	} else {
		if (canlan())
			fprintf(fp, "interface=%s",
				nvram_safe_get("lan_ifname"));
		else
			fprintf(fp, "interface=");
	}
	int mdhcpcount = 0;

	if (nvram_get("mdhcpd_count") != NULL) {
		mdhcpcount = atoi(nvram_safe_get("mdhcpd_count"));
		for (i = 0; i < mdhcpcount; i++) {
			if (strlen(nvram_nget("%s_ipaddr", getmdhcp(0, i))) == 0
			    || strlen(nvram_nget("%s_netmask", getmdhcp(0, i)))
			    == 0)
				continue;
			if (canlan() || i > 0) {
				if (nvram_match("pptpd_enable", "1"))
					fprintf(fp, ",%s",
						nvram_nget("%s_ipaddr",
							   getmdhcp(0, i)));
				else
					fprintf(fp, ",%s", getmdhcp(0, i));
			} else {
				if (nvram_match("pptpd_enable", "1"))
					fprintf(fp, "%s",
						nvram_nget("%s_ipaddr",
							   getmdhcp(0, i)));
				else
					fprintf(fp, "%s", getmdhcp(0, i));

			}
		}
	}
	fprintf(fp, "\n");

	fprintf(fp, "resolv-file=/tmp/resolv.dnsmasq\n" "all-servers\n"); //

	/*
	 * Domain 
	 */
	if (nvram_match("dhcp_domain", "wan")) {
		if (nvram_invmatch("wan_domain", ""))
			fprintf(fp, "domain=%s\n",
				nvram_safe_get("wan_domain"));
		else if (nvram_invmatch("wan_get_domain", ""))
			fprintf(fp, "domain=%s\n",
				nvram_safe_get("wan_get_domain"));
	} else {
		if (nvram_invmatch("lan_domain", ""))
			fprintf(fp, "domain=%s\n",
				nvram_safe_get("lan_domain"));
	}

	/*
	 * DD-WRT use dnsmasq as DHCP replacement 
	 */

	//bs mod
	if (hasdhcp()) {
		/*
		 * DHCP leasefile 
		 */
		if (nvram_match("dhcpd_usenvram", "1")) {
			fprintf(fp, "leasefile-ro\n");
			fprintf(fp, "dhcp-script=%s\n", "/etc/lease_update.sh");
		} else {
			if (usejffs)
				fprintf(fp,
					"dhcp-leasefile=/jffs/dnsmasq.leases\n");
			else
				fprintf(fp,
					"dhcp-leasefile=/tmp/dnsmasq.leases\n");
		}

		int dhcp_max = 0;

		if (landhcp())
			dhcp_max +=
			    atoi(nvram_safe_get("dhcp_num")) +
			    atoi(nvram_safe_get("static_leasenum"));
		for (i = 0; i < mdhcpcount; i++) {
			if (strlen(nvram_nget("%s_ipaddr", getmdhcp(0, i))) == 0
			    || strlen(nvram_nget("%s_netmask", getmdhcp(0, i)))
			    == 0)
				continue;
			dhcp_max += atoi(getmdhcp(3, i));
		}
		fprintf(fp, "dhcp-lease-max=%d\n", dhcp_max);
		if (landhcp())
			fprintf(fp, "dhcp-option=lan,3,%s\n",
				nvram_safe_get("lan_ipaddr"));
		for (i = 0; i < mdhcpcount; i++) {
			if (strlen(nvram_nget("%s_ipaddr", getmdhcp(0, i))) == 0
			    || strlen(nvram_nget("%s_netmask", getmdhcp(0, i)))
			    == 0)
				continue;
			fprintf(fp, "dhcp-option=%s,3,", getmdhcp(0, i));
			fprintf(fp, "%s\n",
				nvram_nget("%s_ipaddr", getmdhcp(0, i)));
		}
		if (nvram_invmatch("wan_wins", "")
		    && nvram_invmatch("wan_wins", "0.0.0.0"))
			fprintf(fp, "dhcp-option=44,%s\n",
				nvram_safe_get("wan_wins"));

		if (nvram_match("dns_dnsmasq", "0")) {
			dns_list = get_dns_list();

			if (dns_list
			    && (strlen(dns_list->dns_server[0]) > 0
				|| strlen(dns_list->dns_server[1]) > 0
				|| strlen(dns_list->dns_server[2]) > 0)) {

				fprintf(fp, "dhcp-option=6");

				if (strlen(dns_list->dns_server[0]) > 0)
					fprintf(fp, ",%s",
						dns_list->dns_server[0]);

				if (strlen(dns_list->dns_server[1]) > 0)
					fprintf(fp, ",%s",
						dns_list->dns_server[1]);

				if (strlen(dns_list->dns_server[2]) > 0)
					fprintf(fp, ",%s",
						dns_list->dns_server[2]);

				fprintf(fp, "\n");
			}

			if (dns_list)
				free(dns_list);
		}

		if (nvram_match("auth_dnsmasq", "1"))
			fprintf(fp, "dhcp-authoritative\n");
		if (landhcp()) {
			fprintf(fp, "dhcp-range=lan,");
			fprintf(fp, "%d.%d.%d.%s,",
				get_single_ip(nvram_safe_get("lan_ipaddr"), 0),
				get_single_ip(nvram_safe_get("lan_ipaddr"), 1),
				get_single_ip(nvram_safe_get("lan_ipaddr"), 2),
				nvram_safe_get("dhcp_start"));
			if (nvram_match("dhcp_num", "0")) {
				fprintf(fp, "static,");
			} else {
				fprintf(fp, "%d.%d.%d.%d,",
					get_single_ip(nvram_safe_get
						      ("lan_ipaddr"), 0),
					get_single_ip(nvram_safe_get
						      ("lan_ipaddr"), 1),
					get_single_ip(nvram_safe_get
						      ("lan_ipaddr"), 2),
					atoi(nvram_safe_get("dhcp_start")) +
					atoi(nvram_safe_get("dhcp_num")) - 1);
			}
			fprintf(fp, "%s,", nvram_safe_get("lan_netmask"));
			fprintf(fp, "%sm\n", nvram_safe_get("dhcp_lease"));
		}

		for (i = 0; i < mdhcpcount; i++) {
			if (strcmp(getmdhcp(1, i), "On"))
				continue;
			if (strlen(nvram_nget("%s_ipaddr", getmdhcp(0, i))) == 0
			    || strlen(nvram_nget("%s_netmask", getmdhcp(0, i)))
			    == 0)
				continue;
			fprintf(fp, "dhcp-range=%s,", getmdhcp(0, i));
			fprintf(fp, "%d.%d.%d.",
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      0),
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      1),
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      2));
			fprintf(fp, "%s,", getmdhcp(2, i));
			fprintf(fp, "%d.%d.%d.",
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      0),
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      1),
				get_single_ip(nvram_nget
					      ("%s_ipaddr", getmdhcp(0, i)),
					      2));
			int end = atoi(getmdhcp(2, i));

			end += atoi(getmdhcp(3, i));
			fprintf(fp, "%d,", end);
			fprintf(fp, "%s,",
				nvram_nget("%s_netmask", getmdhcp(0, i)));
			fprintf(fp, "%sm\n", getmdhcp(4, i));
		}

		int leasenum = atoi(nvram_safe_get("static_leasenum"));

		if (leasenum > 0) {
			char *lease = nvram_safe_get("static_leases");
			char *leasebuf = (char *)malloc(strlen(lease) + 1);
			char *cp = leasebuf;

			strcpy(leasebuf, lease);
			for (i = 0; i < leasenum; i++) {
				char *mac = strsep(&leasebuf, "=");
				char *host = strsep(&leasebuf, "=");
				char *ip = strsep(&leasebuf, "=");
				char *time = strsep(&leasebuf, " ");

				if (mac == NULL || host == NULL || ip == NULL)
					continue;
				if (!time || strlen(time) == 0)
					fprintf(fp,
						"dhcp-host=%s,%s,%s,infinite\n",
						mac, host, ip);
				else
					fprintf(fp, "dhcp-host=%s,%s,%s,%sm\n",
						mac, host, ip, time);

				addHost(host, ip);
			}
			free(cp);
		}
	}
	/* stop dns rebinding for private addresses */
	if (nvram_match("dnsmasq_no_dns_rebind", "1")) {
		fprintf(fp, "stop-dns-rebind\n");
	}
	/*
	 * Additional options 
	 */
	if (nvram_invmatch("dnsmasq_options", "")) {
		fwritenvram("dnsmasq_options", fp);
	}
	fclose(fp);

	dns_to_resolv();

	chmod("/etc/lease_update.sh", 0700);
	ret = eval("dnsmasq", "--conf-file=/tmp/dnsmasq.conf");
	dd_syslog(LOG_INFO, "dnsmasq : dnsmasq daemon successfully started\n");

	cprintf("done\n");
	return;
}
Exemplo n.º 11
0
void start_setup_vlans(void)
{
#if defined(HAVE_RB500) || defined(HAVE_XSCALE) || defined(HAVE_LAGUNA) || defined(HAVE_MAGICBOX) || defined(HAVE_RB600) || defined(HAVE_FONERA) || defined(HAVE_WHRAG108) || defined(HAVE_LS2) || defined(HAVE_CA8) || defined(HAVE_TW6600) || defined(HAVE_PB42) || defined(HAVE_LS5) || defined(HAVE_LSX) || defined(HAVE_DANUBE) || defined(HAVE_STORM) || defined(HAVE_ADM5120) || defined(HAVE_RT2880) || defined(HAVE_SOLO51) || defined(HAVE_OPENRISC) || defined(HAVE_NORTHSTAR)
	return;
#else
	/*
	 * VLAN #16 is just a convieniant way of storing tagging info.  There is
	 * no VLAN #16 
	 */

	if (!nvram_get("port5vlans") || nvram_match("vlans", "0"))
		return;		// for some reason VLANs are not set up, and
	// we don't want to disable everything!

	if (nvram_match("wan_vdsl", "1") && !nvram_match("fromvdsl", "1")) {
		nvram_set("vdsl_state", "0");
		enable_dtag_vlan(1);
		return;
	}

	int i, j, ret = 0, tmp, workaround = 0, found;
	char *vlans, *next, vlan[4], buff[70], buff2[16];
	FILE *fp;
	char portsettings[16][64];
	char tagged[16];
	unsigned char mac[20];;
	struct ifreq ifr;
	int s;
	char *phy = getPhyDev();

	s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
	strcpy(mac, nvram_safe_get("et0macaddr"));

	int vlanmap[6] = { 0, 1, 2, 3, 4, 5 };	// 0=wan; 1,2,3,4=lan;
	// 5=internal 

	if (nvram_match("vlan1ports", "0 5")) {
		vlanmap[0] = 0;
		vlanmap[5] = 5;
		if (nvram_match("vlan0ports", "4 3 2 1 5*")) {
			vlanmap[1] = 4;
			vlanmap[2] = 3;
			vlanmap[3] = 2;
			vlanmap[4] = 1;
		} else if (nvram_match("vlan0ports", "4 1 2 3 5*")) {
			vlanmap[1] = 4;
			vlanmap[2] = 1;
			vlanmap[3] = 2;
			vlanmap[4] = 3;
		} else		// nvram_match ("vlan0ports", "1 2 3 4 5*")
			// nothing to do
		{
		}
	} else if (nvram_match("vlan1ports", "4 5")) {
		vlanmap[0] = 4;
		vlanmap[5] = 5;
		if (nvram_match("vlan0ports", "0 1 2 3 5*")) {
			vlanmap[1] = 0;
			vlanmap[2] = 1;
			vlanmap[3] = 2;
			vlanmap[4] = 3;
		} else		// nvram_match ("vlan0ports", "3 2 1 0 5*")
		{
			vlanmap[1] = 3;
			vlanmap[2] = 2;
			vlanmap[3] = 1;
			vlanmap[4] = 0;
		}
	} else if (nvram_match("vlan1ports", "1 5")) {	// Linksys WTR54GS
		vlanmap[5] = 5;
		vlanmap[0] = 1;
		vlanmap[1] = 0;
	} else if (nvram_match("vlan2ports", "0 8")) {
		vlanmap[0] = 0;
		vlanmap[5] = 8;
		if (nvram_match("vlan1ports", "4 3 2 1 8*")) {
			vlanmap[1] = 4;
			vlanmap[2] = 3;
			vlanmap[3] = 2;
			vlanmap[4] = 1;
		}
	} else if (nvram_match("vlan2ports", "4 8")) {
		vlanmap[0] = 4;
		vlanmap[5] = 8;
		if (nvram_match("vlan1ports", "0 1 2 3 8*")) {
			vlanmap[1] = 0;
			vlanmap[2] = 1;
			vlanmap[3] = 2;
			vlanmap[4] = 3;
		} else		// "3 2 1 0 8*"
		{
			vlanmap[1] = 3;
			vlanmap[2] = 2;
			vlanmap[3] = 1;
			vlanmap[4] = 0;
		}
	} else if (nvram_match("vlan1ports", "4 8")) {
		vlanmap[0] = 4;
		vlanmap[5] = 8;
		if (nvram_match("vlan2ports", "0 1 2 3 8*")) {
			vlanmap[1] = 0;
			vlanmap[2] = 1;
			vlanmap[3] = 2;
			vlanmap[4] = 3;
		}
	} else if (nvram_match("vlan2ports", "4 5")) {
		vlanmap[0] = 4;
		vlanmap[5] = 5;
		if (nvram_match("vlan1ports", "0 1 2 3 5*")) {
			vlanmap[1] = 0;
			vlanmap[2] = 1;
			vlanmap[3] = 2;
			vlanmap[4] = 3;
		} else		// nvram_match ("vlan1ports", "3 2 1 0 5*")
		{
			vlanmap[1] = 3;
			vlanmap[2] = 2;
			vlanmap[3] = 1;
			vlanmap[4] = 0;
		}

	}
	// else ....

	int ast = 0;
	char *asttemp;
	char *lanifnames = nvram_safe_get("lan_ifnames");

	if (strstr(lanifnames, "vlan1") && !strstr(lanifnames, "vlan0"))
		asttemp = nvram_safe_get("vlan1ports");
	else if (strstr(lanifnames, "vlan2") && !strstr(lanifnames, "vlan0")
		 && !strstr(lanifnames, "vlan1"))
		asttemp = nvram_safe_get("vlan2ports");
	else
		asttemp = nvram_safe_get("vlan0ports");

	if (strstr(asttemp, "5*") || strstr(asttemp, "8*"))
		ast = 1;

	memset(&portsettings[0][0], 0, 16 * 64);
	memset(&tagged[0], 0, 16);
	for (i = 0; i < 6; i++) {
		vlans = nvram_nget("port%dvlans", i);
		int use = vlanmap[i];

		if (vlans) {
			int lastvlan = 0;
			int portmask = 3;
			int mask = 0;

			foreach(vlan, vlans, next) {
				tmp = atoi(vlan);
				if (tmp < 16) {
					lastvlan = tmp;
					if (i == 5) {
						snprintf(buff, 9, "%d", tmp);
						eval("vconfig", "set_name_type",
						     "VLAN_PLUS_VID_NO_PAD");
						eval("vconfig", "add", phy,
						     buff);
						snprintf(buff, 9, "vlan%d",
							 tmp);
						if (strcmp
						    (nvram_safe_get
						     ("wan_ifname"), buff)) {
							if (strlen
							    (nvram_nget
							     ("%s_ipaddr",
							      buff)) > 0)
								eval("ifconfig",
								     buff,
								     nvram_nget
								     ("%s_ipaddr",
								      buff),
								     "netmask",
								     nvram_nget
								     ("%s_netmask",
								      buff),
								     "up");
							else
								eval("ifconfig",
								     buff,
								     "0.0.0.0",
								     "up");
						}
					}

					sprintf((char *)&portsettings[tmp][0],
						"%s %d",
						(char *)&portsettings[tmp][0],
						use);
				} else {
					if (tmp == 16)	// vlan tagged
						tagged[use] = 1;
					if (tmp == 17)	// no auto negotiate
						mask |= 4;
					if (tmp == 18)	// no full speed
						mask |= 1;
					if (tmp == 19)	// no full duplex
						mask |= 2;
					if (tmp == 20)	// disabled
						mask |= 8;
					if (tmp == 21)	// no gigabit
						mask |= 16;

				}
			}
			if (mask & 8 && use < 5) {
				writevaproc("0",
					    "/proc/switch/%s/port/%d/enable",
					    phy, use);
			} else {
				writevaproc("1",
					    "/proc/switch/%s/port/%d/enable",
					    phy, use);
			}
			if (use < 5) {
				snprintf(buff, 69,
					 "/proc/switch/%s/port/%d/media", phy,
					 use);
				if ((fp = fopen(buff, "r+"))) {
					if ((mask & 4) == 4) {
						if (!(mask & 16)) {
							if (mask & 2)
								fputs("1000HD",
								      fp);
							else
								fputs("1000FD",
								      fp);

						} else {
							switch (mask & 3) {
							case 0:
								fputs("100FD",
								      fp);
								break;
							case 1:
								fputs("10FD",
								      fp);
								break;
							case 2:
								fputs("100HD",
								      fp);
								break;
							case 3:
								fputs("10HD",
								      fp);
								break;
							}
						}
					} else {
						fprintf(stderr,
							"set port %d to AUTO\n",
							use);
						fputs("AUTO", fp);
					}
					fclose(fp);
				}
			}

		}
	}
Exemplo n.º 12
0
/*
 * configure vlan interface(s) based on nvram settings 
 */
void start_config_vlan(void)
{
	int s;
	struct ifreq ifr;
	int i, j;
	char ea[ETHER_ADDR_LEN];
	char *phy = getPhyDev();

	// configure ports
	writevaproc("1", "/proc/switch/%s/reset", phy);
	writevaproc("1", "/proc/switch/%s/enable_vlan", phy);
	for (i = 0; i < 16; i++) {
		char vlanb[16];

		sprintf(vlanb, "vlan%dports", i);
		if (nvram_get(vlanb) == NULL || nvram_match(vlanb, ""))
			continue;
		writevaproc(nvram_safe_get(vlanb),
			    "/proc/switch/%s/vlan/%d/ports", phy, i);
	}

	/*
	 * set vlan i/f name to style "vlan<ID>" 
	 */

	eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD");

	/*
	 * create vlan interfaces 
	 */
	if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
		return;

	for (i = 0; i < MAX_VLAN_GROUPS; i++) {
		char vlan_id[16];
		char *hwname, *hwaddr;

		if (!(hwname = nvram_nget("vlan%dhwname", i))) {
			continue;
		}
		if (!(hwaddr = nvram_nget("%smacaddr", hwname))) {
			continue;
		}
		if (strlen(hwname) == 0 || strlen(hwaddr) == 0) {
			continue;
		}
		ether_atoe(hwaddr, ea);
		for (j = 1; j <= MAX_DEV_IFINDEX; j++) {
			ifr.ifr_ifindex = j;
			if (ioctl(s, SIOCGIFNAME, &ifr)) {
				continue;
			}
			if (ioctl(s, SIOCGIFHWADDR, &ifr)) {
				continue;
			}
			if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
				continue;
			}
			if (!bcmp(ifr.ifr_hwaddr.sa_data, ea, ETHER_ADDR_LEN)) {
				break;
			}
		}
		if (j > MAX_DEV_IFINDEX) {
			continue;
		}
		if (ioctl(s, SIOCGIFFLAGS, &ifr))
			continue;
		if (!(ifr.ifr_flags & IFF_UP))
			eval("ifconfig", ifr.ifr_name, "0.0.0.0", "up");
		snprintf(vlan_id, sizeof(vlan_id), "%d", i);
		eval("vconfig", "add", ifr.ifr_name, vlan_id);
	}

	close(s);

	return;
}
Exemplo n.º 13
0
void readWL(wiviz_cfg * cfg)
{
	int ap, i;
	wiviz_host *host, *sta;
	uchar mac[6];
	wlc_ssid_t ssid;
	channel_info_t channel;
	maclist_t *macs;
	sta_rssi_t starssi;
	char buf[32];

	get_mac(wl_dev, mac);
	printf("AP mac: ");
#ifdef NEED_PRINTF
	print_mac(mac, "\n");
#endif
	if (!nonzeromac(mac))
		return;
#ifdef HAVE_RT2880
	if (nvram_match("ap", "wl0_oldmode"))
		ap = 1;
#else
	if (nvram_nmatch("ap", "%s_mode", wl_dev))
		ap = 1;
	if (nvram_nmatch("wdsap", "%s_mode", wl_dev))
		ap = 1;
#endif
//      wl_ioctl(wl_dev, WLC_GET_AP, &ap, 4);
	if (ap) {
		host = gotHost(cfg, mac, typeAP);
		host->isSelf = 1;
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880)
#ifdef HAVE_RT2880
		strcpy(host->apInfo->ssid, nvram_safe_get("wl0_ssid"));
		host->apInfo->ssidlen = strlen(host->apInfo->ssid);
		ether_atoe(nvram_safe_get("wl0_hwaddr"), buf);
		memcpy(host->apInfo->bssid, buf, 6);
#else
		strcpy(host->apInfo->ssid, nvram_nget("%s_ssid", wl_dev));
		host->apInfo->ssidlen = strlen(host->apInfo->ssid);
		ether_atoe(nvram_nget("%s_hwaddr", wl_dev), buf);
		memcpy(host->apInfo->bssid, buf, 6);
#endif
#else
		wl_ioctl(wl_dev, WLC_GET_BSSID, host->apInfo->bssid, 6);
		wl_ioctl(wl_dev, WLC_GET_SSID, &ssid, sizeof(wlc_ssid_t));
		memcpy(host->apInfo->ssid, ssid.SSID, 32);
		host->apInfo->ssidlen = ssid.SSID_len;
#endif
		host->RSSI = 0;
#ifdef HAVE_MADWIFI
		host->apInfo->channel = wifi_getchannel(wl_dev);
#elif HAVE_RT2880
		host->apInfo->channel = atoi(nvram_safe_get("wl0_channel"));
#else
		wl_ioctl(wl_dev, WLC_GET_CHANNEL, &channel, sizeof(channel_info_t));
		host->apInfo->channel = channel.hw_channel;
#endif

		macs = (maclist_t *) malloc(4 + MAX_STA_COUNT * sizeof(ether_addr_t));
		macs->count = MAX_STA_COUNT;
		int code = getassoclist(wl_dev, macs);
		printf("code :%d\n", code);
		if (code > 0) {
			for (i = 0; i < macs->count; i++) {
				sta = gotHost(cfg, (char *)&macs->ea[i], typeSta);
#ifdef HAVE_MADWIFI
				sta->RSSI = -getRssi(wl_dev, macs->ea) * 100;
#elif HAVE_RT2880
				sta->RSSI = -getRssi(wl_dev, macs->ea) * 100;	// needs to be solved                            
#else
				memcpy(starssi.mac, &macs->ea[i], 6);
				starssi.RSSI = 3000;
				starssi.zero_ex_forty_one = 0x41;
				if (wl_ioctl(wl_dev, WLC_GET_RSSI, &starssi, 12) < 0)
					printf("rssifail\n");
				sta->RSSI = -starssi.RSSI * 100;
#endif
				sta->staInfo->state = ssAssociated;
				memcpy(sta->staInfo->connectedBSSID, host->apInfo->bssid, 6);
			}
		}
	} else {
		host = gotHost(cfg, mac, typeSta);
		host->isSelf = 1;
		host->RSSI = 0;
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880)
		if (getassoclist(wl_dev, macs) > -1) {
			if (macs->count > 0) {
				host->staInfo->state = ssUnassociated;
			} else {
				host->staInfo->state = ssAssociated;
			}
		} else {
			host->staInfo->state = ssUnassociated;

		}

#else
		if (wl_ioctl(wl_dev, WLC_GET_BSSID, &host->staInfo->connectedBSSID, 6) < 0) {
			host->staInfo->state = ssUnassociated;
		} else {
			host->staInfo->state = ssAssociated;
		}
#endif
	}
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880)
	cfg->curChannel = wifi_getchannel(wl_dev);

#else
	if (wl_ioctl(wl_dev, WLC_GET_CHANNEL, &channel, sizeof(channel_info_t)) >= 0) {
		cfg->curChannel = channel.hw_channel;
		printf("Current channel is %i\n", cfg->curChannel);
	}
#endif
}
Exemplo n.º 14
0
int main(int argc, char **argv)
{
	char *dev;
	int oldMonitor, newMonitor;
	u_char packet[4096];
	int pktlen;
	wiviz_cfg cfg;
	int i;
	int defaultHopSeq[] = { 1, 3, 6, 8, 11 };
	int s, one;
	memset(&cfg, 0, sizeof(cfg));
#ifdef HAVE_RT2880
	wl_dev = "ra0";
#elif HAVE_MADWIFI
	wl_dev = nvram_safe_get("wifi_display");
#else
	char tmp[32];
	sprintf(tmp, "%s_ifname", nvram_safe_get("wifi_display"));
	wl_dev = nvram_safe_get(tmp);
#endif
	if (argc > 1)
		if (!strcmp(argv[1], "terminate")) {
#ifdef HAVE_MADWIFI
			// return to original channel
#ifdef HAVE_ATH9K
			if (!is_ath9k(wl_dev))
#endif
			{
				sysprintf("iwconfig %s channel %sM", get_monitor(), nvram_nget("%s_channel", nvram_safe_get("wifi_display")));
				sleep(1);
				sysprintf("ifconfig %s down", get_monitor());
				if (is_ar5008(nvram_safe_get("wifi_display"))) {
					sysprintf("80211n_wlanconfig %s destroy", get_monitor());
				} else {
					sysprintf("wlanconfig %s destroy", get_monitor());
				}
			}
#elif HAVE_RT2880
			nvram_set("wl0_mode", nvram_safe_get("wl0_oldmode"));
			sysprintf("startservice configurewifi");
			if (nvram_match("wl0_mode", "sta") || nvram_match("wl0_mode", "apsta")) {
				sysprintf("startstop wan");
			}
#else
			oldMonitor = 0;
			wl_ioctl(wl_dev, WLC_SET_MONITOR, &oldMonitor, 4);
#endif
			return 0;
		}

	global_cfg = &cfg;
	signal(SIGUSR1, &signal_handler);
	signal(SIGUSR2, &signal_handler);

	printf("Wi-Viz 2 infogathering daemon by Nathan True\n");
	printf("http://wiviz.natetrue.com\n");

	memset(&cfg, 0, sizeof(wiviz_cfg));
	cfg.numHosts = 0;
	cfg.lastKeepAlive = time(NULL);
	cfg.channelHopping = 0;
	cfg.channelDwellTime = 1000;
	cfg.channelHopSeqLen = 5;
	memcpy(cfg.channelHopSeq, defaultHopSeq, sizeof(defaultHopSeq));

#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880)
	wl_ioctl(wl_dev, WLC_GET_MAGIC, &i, 4);
	if (i != WLC_IOCTL_MAGIC) {
		printf("Wireless magic not correct, not querying wl for info %X!=%X\n", i, WLC_IOCTL_MAGIC);
		cfg.readFromWl = 0;
	} else {
		cfg.readFromWl = 1;
		wl_ioctl(wl_dev, WLC_GET_MONITOR, &oldMonitor, 4);
		newMonitor = 1;
		wl_ioctl(wl_dev, WLC_SET_MONITOR, &newMonitor, 4);
	}

#elif HAVE_RT2880
	nvram_set("wl0_oldmode", nvram_safe_get("wl0_mode"));
	nvram_set("wl0_mode", "sta");
	if (!nvram_match("wl0_oldmode", "sta"))
		sysprintf("startservice configurewifi");
	sysprintf("iwconfig ra0 mode monitor");
	cfg.readFromWl = 1;
#else
#ifdef HAVE_ATH9K
	if (!is_ath9k(nvram_safe_get("wifi_display")))
#endif
	{
		if (is_ar5008(nvram_safe_get("wifi_display"))) {
			sysprintf("80211n_wlanconfig %s create wlandev %s wlanmode monitor", get_monitor(), getWifi(nvram_safe_get("wifi_display")));
		} else {
			sysprintf("wlanconfig %s create wlandev %s wlanmode monitor", get_monitor(), getWifi(nvram_safe_get("wifi_display")));
		}
		sysprintf("ifconfig %s up", get_monitor());
	}
	cfg.readFromWl = 1;
#endif
	reloadConfig();

#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880)
	s = openMonitorSocket(get_monitor());	// for testing we use ath0
#else

	if (nvram_match("wifi_display", "wl1"))
		s = openMonitorSocket("prism1");
	else
		s = openMonitorSocket("prism0");
#endif
	if (s == -1)
		return;
	one = 1;
	ioctl(s, FIONBIO, (char *)&one);

	if (cfg.readFromWl) {
		readWL(&cfg);
	}
#ifdef WIVIZ_GPS
	gps_init(&cfg);
#endif

	while (!stop) {
#ifdef WIVIZ_GPS
		gps_tick();
#else
		if (time(NULL) - cfg.lastKeepAlive > 30)
			stop = 1;
#endif
		pktlen = recv(s, packet, 4096, 0);
		if (pktlen <= 0)
			continue;
		dealWithPacket(&cfg, pktlen, packet);
	}

	signal_handler(SIGUSR1);

	if (cfg.channelHopperPID)
		kill(cfg.channelHopperPID, SIGKILL);

#ifndef WIVIZ_GPS
	for (i = 0; i < MAX_HOSTS; i++) {
		print_host(stderr, cfg.hosts + i);
		if (cfg.hosts[i].occupied)
			printf("\n");
		if (cfg.hosts[i].apInfo)
			free(cfg.hosts[i].apInfo);
		if (cfg.hosts[i].staInfo)
			free(cfg.hosts[i].staInfo);
	}
#endif
	close(s);
	return 0;
}