예제 #1
0
#ifdef RTCONFIG_BCM_7114
if (nvram_get_int("wlc_psta") == 3)
				nvram_set(strcat_r(prefix, "mode", tmp), "wet");
			else
#endif
			nvram_set(strcat_r(prefix, "mode", tmp), "psta");
예제 #2
0
static int ipv4_route_table_array(webs_t wp)
{
    FILE *fp;
    char tmp[100], prefix[] = "wanXXXXXXXXXX_";
    char buf[256], *dev, *sflags, *str;
    struct in_addr dest, gateway, mask;
    int flags, ref, use, metric;
    int unit, ret = 0;

    fp = fopen("/proc/net/route", "r");
    if (fp == NULL) {
        ret += websWrite(wp, "[]];\n");
        return ret;
    }

    while ((str = fgets(buf, sizeof(buf), fp)) != NULL) {
        dev = strsep(&str, " \t");
        if (!str || dev == str)
            continue;
        if (sscanf(str, "%x%x%x%d%u%d%x", &dest.s_addr, &gateway.s_addr,
                   &flags, &ref, &use, &metric, &mask.s_addr) != 7)
            continue;

        /* Parse flags, reuse buf */
        sflags = str;
        if (flags & RTF_UP)
            *str++ = 'U';
        if (flags & RTF_GATEWAY)
            *str++ = 'G';
        if (flags & RTF_HOST)
            *str++ = 'H';
        *str++ = '\0';

        /* Skip interfaces here */
        if (strcmp(dev, "lo") == 0)
            continue;

        /* Replace known interfaces with LAN/WAN/MAN */
        if (nvram_match("lan_ifname", dev)) /* br0, wl0, etc */
            dev = "LAN";
        else {
            /* Tricky, it's better to move wan_ifunit/wanx_ifunit to shared instead */
            for (unit = WAN_UNIT_FIRST; unit < WAN_UNIT_MAX; unit++) {
                snprintf(prefix, sizeof(prefix), "wan%d_", unit);
                if (nvram_match(strcat_r(prefix, "pppoe_ifname", tmp), dev)) {
                    dev = "WAN";
                    break;
                }
                if (nvram_match(strcat_r(prefix, "ifname", tmp), dev)) {
                    char *wan_proto = nvram_safe_get(strcat_r(prefix, "proto", tmp));
                    dev = (strcmp(wan_proto, "dhcp") == 0 ||
                           strcmp(wan_proto, "static") == 0 ) ? "WAN" : "MAN";
                    break;
                }
            }
        }

        ret += websWrite(wp, "[\"%s\",",  dest.s_addr == INADDR_ANY ? "default" : inet_ntoa(dest));
        ret += websWrite(wp, "\"%s\", ", gateway.s_addr == INADDR_ANY ? "*" : inet_ntoa(gateway));
        ret += websWrite(wp, "\"%s\", \"%s\", \"%d\", \"%d\", \"%d\", \"%s\"],\n",
                         inet_ntoa(mask), sflags, metric, ref, use, dev);

    }
    fclose(fp);

    return ret;
}
예제 #3
0
/*
 * Called when link comes up
 */
int
ipup_main(int argc, char **argv)
{
	FILE *fp;
	char *wan_ifname = safe_getenv("IFNAME");
	char *wan_linkname = safe_getenv("LINKNAME");
	char tmp[100], prefix[] = "wanXXXXXXXXXX_";
	char buf[256], *value;
	int unit;

	_dprintf("%s():: %s\n", __FUNCTION__, argv[0]);

	/* Get unit from LINKNAME: ppp[UNIT] */
	if ((unit = ppp_linkunit(wan_linkname)) < 0)
		return 0;

	_dprintf("%s: unit=%d ifname=%s\n", __FUNCTION__, unit, wan_ifname);
	snprintf(prefix, sizeof(prefix), "wan%d_", unit);

	/* Stop triggering demand connection */
	if (nvram_get_int(strcat_r(prefix, "pppoe_demand", tmp)))
		nvram_set_int(strcat_r(prefix, "pppoe_demand", tmp), 1);

#ifdef RTCONFIG_USB_MODEM
	// wanX_ifname is used for device for USB Modem
	if ((value = getenv("DEVICE")) &&
	    (isSerialNode(value) || isACMNode(value)))
		nvram_set(strcat_r(prefix, "ifname", tmp), value);
#endif

	/* Touch connection file */
	if (!(fp = fopen(strcat_r("/tmp/ppp/link.", wan_ifname, tmp), "a"))) {
		perror(tmp);
		return errno;
	}
	fclose(fp);

	if ((value = getenv("IPLOCAL"))) {
		if (nvram_invmatch(strcat_r(prefix, "ipaddr", tmp), value))
			ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL);
		_ifconfig(wan_ifname, IFUP, value, "255.255.255.255", getenv("IPREMOTE"));
		nvram_set(strcat_r(prefix, "ipaddr", tmp), value);
		nvram_set(strcat_r(prefix, "netmask", tmp), "255.255.255.255");
	}

	if ((value = getenv("IPREMOTE")))
		nvram_set(strcat_r(prefix, "gateway", tmp), value);

	strcpy(buf, "");
	if ((value = getenv("DNS1")))
		sprintf(buf, "%s", value);
	if ((value = getenv("DNS2")))
		sprintf(buf + strlen(buf), "%s%s", strlen(buf) ? " " : "", value);

	/* empty DNS means they either were not requested or peer refused to send them.
	 * lift up underlying xdns value instead, keeping "dns" filled */
	if (strlen(buf) == 0)
		sprintf(buf, "%s", nvram_safe_get(strcat_r(prefix, "xdns", tmp)));

	nvram_set(strcat_r(prefix, "dns", tmp), buf);

	wan_up(wan_ifname);

	_dprintf("%s:: done\n", __FUNCTION__);
	return 0;
}
예제 #4
0
if (nvram_match(strcat_r(prefix, "enable", tmp), "0")) {
		update_wan_state(prefix, WAN_STATE_DISABLED, 0);
		return;
	}
#ifdef RTCONFIG_USB_MODEM
	else if(nvram_get_int("usb_modem_act_scanning") != 0){
_dprintf("start_wan_if: USB modem is scanning...\n");
		update_wan_state(prefix, WAN_STATE_STOPPED, WAN_STOPPED_REASON_USBSCAN);
		return;
	}
#endif
예제 #5
0
#ifdef RTCONFIG_WIRELESSREPEATER
if (nvram_get_int("sw_mode") == SW_MODE_REPEATER)
			{
				snprintf(prefix, sizeof(prefix), "wl%d.1_", nvram_get_int("wlc_band"));
				strncpy(ssid_g, nvram_safe_get(strcat_r(prefix, "ssid", tmp)), 32);
			}
			else
#endif
#ifdef RTCONFIG_BCMWL6
#ifdef RTCONFIG_PROXYSTA
			if (is_psta(nvram_get_int("wlc_band")) || is_psr(nvram_get_int("wlc_band")))
			{
				snprintf(prefix, sizeof(prefix), "wl%d_", 1 - nvram_get_int("wlc_band"));
				strncpy(ssid_g, nvram_safe_get(strcat_r(prefix, "ssid", tmp)), 32);
			}
			else
#endif
#endif
		     strncpy(ssid_g, nvram_safe_get("wl0_ssid"), 32);
예제 #6
0
파일: psta_monitor.c 프로젝트: gygy/asuswrt
static char *
wl_get_scan_results(int unit)
{
	int ret, retry_times = 0;
	wl_scan_params_t *params;
	wl_scan_results_t *list = (wl_scan_results_t*)scan_result;
	int params_size = WL_SCAN_PARAMS_FIXED_SIZE + NUMCHANS * sizeof(uint16);
	wlc_ssid_t wst = {0, ""};
	int org_scan_time = 20, scan_time = 40;
	char tmp[NVRAM_BUFSIZE], prefix[] = "wlXXXXXXXXXX_";
	char *ifname = NULL;

	snprintf(prefix, sizeof(prefix), "wl%d_", unit);
	wst.SSID_len = strlen(nvram_safe_get(strcat_r(prefix, "ssid", tmp)));
	if (wst.SSID_len <= MAX_SSID_LEN)
		memcpy(wst.SSID, nvram_safe_get(strcat_r(prefix, "ssid", tmp)), wst.SSID_len);
	else
		wst.SSID_len = 0;

	params = (wl_scan_params_t*)malloc(params_size);
	if (params == NULL) {
		return NULL;
	}

	memset(params, 0, params_size);
	params->ssid = wst;
	params->bss_type = DOT11_BSSTYPE_ANY;
	memcpy(&params->bssid, &ether_bcast, ETHER_ADDR_LEN);
	params->scan_type = -1;
	params->nprobes = -1;
	params->active_time = -1;
	params->passive_time = -1;
	params->home_time = -1;
	params->channel_num = 0;

	ifname = nvram_safe_get(strcat_r(prefix, "ifname", tmp));
	/* extend scan channel time to get more AP probe resp */
	wl_ioctl(ifname, WLC_GET_SCAN_CHANNEL_TIME, &org_scan_time, sizeof(org_scan_time));
	if (org_scan_time < scan_time)
		wl_ioctl(ifname, WLC_SET_SCAN_CHANNEL_TIME, &scan_time,	sizeof(scan_time));

retry:
	ret = wl_ioctl(ifname, WLC_SCAN, params, params_size);
	if (ret < 0) {
		if (retry_times++ < WLC_SCAN_RETRY_TIMES) {
			if (psta_debug)
			dbg("set scan command failed, retry %d\n", retry_times);
			sleep(1);
			goto retry;
		}
	}

	sleep(2);

	list->buflen = WLC_DUMP_BUF_LEN;
	ret = wl_ioctl(ifname, WLC_SCAN_RESULTS, scan_result, WLC_DUMP_BUF_LEN);
	if (ret < 0 && retry_times++ < WLC_SCAN_RETRY_TIMES) {
		if (psta_debug)
		dbg("get scan result failed, retry %d\n", retry_times);
		sleep(1);
		goto retry;
	}

	free(params);

	/* restore original scan channel time */
	wl_ioctl(ifname, WLC_SET_SCAN_CHANNEL_TIME, &org_scan_time, sizeof(org_scan_time));

	if (ret < 0)
		return NULL;

	return scan_result;
}
예제 #7
0
int wanlink_hook_dsl(int eid, webs_t wp, int argc, char_t **argv){
// DSLTODO : dummy code
	char tmp[100], prefix[] = "wanXXXXXXXXXX_";
	int wan_state = -1, wan_sbstate = -1, wan_auxstate = -1;
	int unit, status = 0;
	char *statusstr[2] = { "Disconnected", "Connected" };
	char *wan_proto, *type;
	char *ip = "0.0.0.0";
	char *netmask = "0.0.0.0";
	char *gateway = "0.0.0.0";
	unsigned int lease = 0, expires = 0;
	char *xtype = "";
	char *xip = "0.0.0.0";
	char *xnetmask = "0.0.0.0";
	char *xgateway = "0.0.0.0";
	unsigned int xlease = 0, xexpires = 0;

	status = 1;

	type = nvram_safe_get(nvram_safe_get("dsl_proto"));

	if(status != 0){
		ip = nvram_safe_get(strcat_r(prefix, "ipaddr", tmp));
		netmask = nvram_safe_get(strcat_r(prefix, "netmask", tmp));
		gateway = nvram_safe_get(strcat_r(prefix, "gateway", tmp));
		lease = nvram_get_int(strcat_r(prefix, "lease", tmp));
		if (lease > 0)
			expires = nvram_get_int(strcat_r(prefix, "expires", tmp)) - uptime();
	}

	websWrite(wp, "function wanlink_status() { return %d;}\n", status);
	websWrite(wp, "function wanlink_statusstr() { return '%s';}\n", statusstr[status]);
	websWrite(wp, "function wanlink_type() { return '%s';}\n", type);
	websWrite(wp, "function wanlink_ipaddr() { return '%s';}\n", ip);
	websWrite(wp, "function wanlink_netmask() { return '%s';}\n", netmask);
	websWrite(wp, "function wanlink_gateway() { return '%s';}\n", gateway);
	websWrite(wp, "function wanlink_dns() { return '%s';}\n", nvram_safe_get(strcat_r(prefix, "dns", tmp)));
	websWrite(wp, "function wanlink_lease() { return %d;}\n", lease);
	websWrite(wp, "function wanlink_expires() { return %d;}\n", expires);
	websWrite(wp, "function is_private_subnet() { return '%d';}\n", is_private_subnet(nvram_safe_get(strcat_r(prefix, "ipaddr", tmp))));

/* TODO: implement WANX */
//	if (strcmp(wan_proto, "pppoe") == 0 ||
//	    strcmp(wan_proto, "pptp") == 0 ||
//	    strcmp(wan_proto, "l2tp") == 0) {
//		int dhcpenable = nvram_get_int(strcat_r(prefix, "dhcpenable_x", tmp));
//		xtype = (dhcpenable == 0) ? "static" :
//			(strcmp(wan_proto, "pppoe") == 0 && nvram_match(strcat_r(prefix, "vpndhcp", tmp), "0")) ? "" : /* zeroconf */
//			"dhcp";
//		xip = nvram_safe_get(strcat_r(prefix, "xipaddr", tmp));
//		xnetmask = nvram_safe_get(strcat_r(prefix, "xnetmask", tmp));
//		xgateway = nvram_safe_get(strcat_r(prefix, "xgateway", tmp));
//		xlease = nvram_get_int(strcat_r(prefix, "xlease", tmp));
//		if (xlease > 0)
//			xexpires = nvram_get_int(strcat_r(prefix, "xexpires", tmp)) - uptime();
//	}

	websWrite(wp, "function wanlink_xtype() { return '%s';}\n", xtype);
	websWrite(wp, "function wanlink_xipaddr() { return '%s';}\n", xip);
	websWrite(wp, "function wanlink_xnetmask() { return '%s';}\n", xnetmask);
	websWrite(wp, "function wanlink_xgateway() { return '%s';}\n", xgateway);
	websWrite(wp, "function wanlink_xdns() { return '%s';}\n", nvram_safe_get(strcat_r(prefix, "xdns", tmp)));
	websWrite(wp, "function wanlink_xlease() { return %d;}\n", xlease);
	websWrite(wp, "function wanlink_xexpires() { return %d;}\n", xexpires);

	return 0;
}
예제 #8
0
파일: rc.c 프로젝트: Einheri/wl500g
static void
restore_defaults(void)
{
	struct nvram_tuple generic[] = {
		{ "lan_ifname", "br0", 0 },
		{ "lan_ifnames", "eth0 eth2 eth3 eth4", 0 },
		{ "wan_ifname", "eth1", 0 },
		{ "wan_ifnames", "eth1", 0 },
		{ 0, 0, 0 }
	};
	struct nvram_tuple vlan[] = {
		{ "lan_ifname", "br0", 0 },
		{ "lan_ifnames", "vlan0 eth1 eth2 eth3", 0 },
		{ "wan_ifname", "vlan1", 0 },
		{ "wan_ifnames", "vlan1", 0 },
		{ 0, 0, 0 }
	};
	struct nvram_tuple dyna[] = {
		{ "lan_ifname", "br0", 0 },
		{ "lan_ifnames", "", 0 },
		{ "wan_ifname", "", 0 },
		{ "wan_ifnames", "", 0 },
		/* default with vlans disabled */
		{ "wan_nat_x", "0", 0},
		{ "wan_route_x", "IP_Bridged", 0},
		{ 0, 0, 0 }
	};


	struct nvram_tuple *linux_overrides;
	struct nvram_tuple *t, *u;
	int restore_defaults, i;
	uint boardflags;
	char *landevs, *wandevs;
	char lan_ifnames[128], wan_ifnames[128];
	char wan_ifname[32], *next;
	int len;
	int ap = 0;

	/* Restore defaults if told to or OS has changed */
	restore_defaults = !nvram_match("restore_defaults", "0") || nvram_invmatch("os_name", "linux");

	if (restore_defaults)
		cprintf("Restoring defaults...");

	/* Delete dynamically generated variables */
	if (restore_defaults) {
		char tmp[100], prefix[sizeof("wlXXXXXXXXXX_")];
		for (i = 0; i < MAX_NVPARSE; i++) {
			del_forward_port(i);
			del_autofw_port(i);
			snprintf(prefix, sizeof(prefix), "wl%d_", i);
			for (t = router_defaults; t->name; t ++) {
				if (!strncmp(t->name, "wl_", 3))
					nvram_unset(strcat_r(prefix, &t->name[3], tmp));
			}
			snprintf(prefix, sizeof(prefix), "wan%d_", i);
			for (t = router_defaults; t->name; t ++) {
				if (!strncmp(t->name, "wan_", 4))
					nvram_unset(strcat_r(prefix, &t->name[4], tmp));
			}
		}
	}

	/* 
	 * Build bridged i/f name list and wan i/f name list from lan device name list
	 * and wan device name list. Both lan device list "landevs" and wan device list
	 * "wandevs" must exist in order to preceed.
	 */
	if ((landevs = nvram_get("landevs")) && (wandevs = nvram_get("wandevs"))) {
		/* build bridged i/f list based on nvram variable "landevs" */
		len = sizeof(lan_ifnames);
		if (!build_ifnames(landevs, lan_ifnames, &len) && len)
			dyna[1].value = lan_ifnames;
		else
			goto canned_config;
		/* build wan i/f list based on nvram variable "wandevs" */
		len = sizeof(wan_ifnames);
		if (!build_ifnames(wandevs, wan_ifnames, &len) && len) {
			dyna[3].value = wan_ifnames;
			foreach (wan_ifname, wan_ifnames, next) {
				dyna[2].value = wan_ifname;
				break;
			}
예제 #9
0
int 
start_wps_method(void)
{
	int wps_band;
	int wps_action;
//	int wps_method;
	char *wps_sta_pin;
	char prefix[]="wlXXXXXX_", tmp[100];
	char buf[256] = "SET ";
	int len = 4;

	if(getpid()!=1) {
		notify_rc("start_wps_method");
		return 0;
	}

	wps_band = nvram_get_int("wps_band");
	snprintf(prefix, sizeof(prefix), "wl%d_", wps_band);
	wps_action = nvram_get_int("wps_action");
//	wps_method = nvram_get_int("wps_method"); // useless
	wps_sta_pin = nvram_safe_get("wps_sta_pin");

	if(strlen(wps_sta_pin) && strcmp(wps_sta_pin, "00000000") && (wl_wpsPincheck(wps_sta_pin) == 0))
		len += sprintf(buf + len, "wps_method=%d ", WPS_UI_METHOD_PIN);	
	else
		len += sprintf(buf + len, "wps_method=%d ", WPS_UI_METHOD_PBC);
	
	if(nvram_match("wps_version2", "enabled") && strlen(nvram_safe_get("wps_autho_sta_mac")))
		len += sprintf(buf + len, "wps_autho_sta_mac=%s ", nvram_safe_get("wps_autho_sta_mac"));

	if(strlen(wps_sta_pin))
		len += sprintf(buf + len, "wps_sta_pin=%s ", wps_sta_pin);
	else
		len += sprintf(buf + len, "wps_sta_pin=00000000 ");

//	len += sprintf(buf + len, "wps_action=%d ", wps_action);
	len += sprintf(buf + len, "wps_action=%d ", WPS_UI_ACT_ADDENROLLEE);

	len += sprintf(buf + len, "wps_config_command=%d ", WPS_UI_CMD_START);

	nvram_set("wps_proc_status", "0");

	len += sprintf(buf + len, "wps_pbc_method=%d ", WPS_UI_PBC_SW);
	len += sprintf(buf + len, "wps_ifname=%s ", nvram_safe_get(strcat_r(prefix, "ifname", tmp)));

	dbG("wps env buffer: %s\n", buf);

//	nvram_unset("wps_sta_devname");
//	nvram_unset("wps_sta_mac");
//	nvram_unset("wps_pinfail");
//	nvram_unset("wps_pinfail_mac");
//	nvram_unset("wps_pinfail_name");
//	nvram_unset("wps_pinfail_state");

	set_wps_env(buf);

	sprintf(tmp, "%lu", uptime());
	nvram_set("wps_uptime", tmp);

	return 0;
}
예제 #10
0
int
wps_set_wsec(int ess_id, char *wps_ifname, void *credential, int mode)
{
	char prefix[] = "lanXXXXXXXXX_";
	int instance;
	char *value;
	char *oob = NULL;

	char tmp[100];
	char *wlnames = wps_ifname;
	char *next = NULL;
	char ifname[IFNAMSIZ];

	if (wps_ifname == NULL || credential == NULL) {
		TUTRACE((TUTRACE_ERR, "wps_set_wsec: Invaild argument\n"));
		return -1;
	}
#ifdef WPS_PLC
	if (strcmp(nvram_safe_get("wps_pbc_apsta"), "enabled") == 0 &&
		strcmp(wps_ifname, wps_safe_get_conf("wps_pbc_sta_ifname")) == 0) {
		char *ap_ifname = wps_safe_get_conf("wps_pbc_ap_ifname");

		/* Set wsec to ap interface */

		value = wps_get_conf("wps_pbc_ap_index");
		if (value == NULL) {
			TUTRACE((TUTRACE_ERR, "wps_set_wsec: Cannot get UPnP instance\n"));
			return -1;
		}

		instance = atoi(value);
		if (instance == 0)
			strcpy(prefix, "lan_");
		else
			sprintf(prefix, "lan%d_", instance);
		wps_osl_set_conf(strcat_r(prefix, "wps_oob", tmp),
			"disabled");

		wps_osl_set_conf(strcat_r(prefix, "wps_reg", tmp),
			"enabled");
		TUTRACE((TUTRACE_INFO, "built-in registrar enabled\n"));

		wlnames = ap_ifname;
		TUTRACE((TUTRACE_INFO, "WPS STA (%s) has finished WPS process "
			"and now is setting security to AP (%s).\n", wps_ifname, ap_ifname));
	}
	else
#endif
	if (!wps_is_wps_sta(wps_ifname)) {
		sprintf(tmp, "ess%d_ap_index", ess_id);
		value = wps_get_conf(tmp);
		if (value == NULL) {
			TUTRACE((TUTRACE_ERR, "wps_set_wsec: Cannot get UPnP instance\n"));
			return -1;
		}

		instance = atoi(value);
		if (instance == 0)
			strcpy(prefix, "lan_");
		else
			sprintf(prefix, "lan%d_", instance);

		/* Default OOB set to enabled */
		oob = nvram_get(strcat_r(prefix, "wps_oob", tmp));
		if (!oob)
			oob = "enabled";

		/* Check wether OOB is true */
		if (!strcmp(oob, "enabled")) {
			/* OOB mode, apply to all wl if */
			sprintf(tmp, "ess%d_wlnames", ess_id);
			wlnames = wps_safe_get_conf(tmp);

			TUTRACE((TUTRACE_INFO,
				"wps_set_wsec: OOB set config\n"));
		}

		/* Set OOB and built-in reg (Per-ESS) */
		if (mode == EModeApProxyRegistrar) {
			wps_osl_set_conf(strcat_r(prefix, "wps_oob", tmp),
				"disabled");
			TUTRACE((TUTRACE_INFO, "OOB state configed\n"));

			wps_osl_set_conf(strcat_r(prefix, "wps_reg", tmp),
				"enabled");
			TUTRACE((TUTRACE_INFO, "built-in registrar enabled\n"));
		} else if (mode == EModeUnconfAp) {
			wps_osl_set_conf(strcat_r(prefix, "wps_oob", tmp),
				"disabled");
			TUTRACE((TUTRACE_INFO, "OOB state configed\n"));
		}
	}
	else {
		/* STA ess interfaces */
		if (osifname_to_nvifname(wlnames, prefix, sizeof(prefix)) == 0) {
			strcat(prefix, "_");
			wps_osl_set_conf(strcat_r(prefix, "wps_oob", tmp), "disabled");
		}
		else {
			TUTRACE((TUTRACE_INFO, "Clear OOB: convert to nvname failed!\n"));
		}
	}

	/* Apply the wsec */
	foreach(ifname, wlnames, next) {
		set_wsec(ifname, credential, mode);
		TUTRACE((TUTRACE_INFO, "wps_set_wsec: Set config to %s\n", ifname));
	}
예제 #11
0
/*
 * bound: This argument is used when udhcpc moves from an unbound, to
 * a bound state. All of the paramaters are set in enviromental
 * variables, The script should configure the interface, and set any
 * other relavent parameters (default gateway, dns server, etc).
*/
static int
bound(void)
{
	char *lan_ifname = safe_getenv("interface");
	char *value;
	char tmp[100], prefix[] = "lanXXXXXXXXXX_";

	snprintf(prefix, sizeof(prefix), "lan_");
	
	if ((value = getenv("ip")))
		nvram_set(strcat_r(prefix, "ipaddr", tmp), value);
	if ((value = getenv("subnet")))
		nvram_set(strcat_r(prefix, "netmask", tmp), value);
        if ((value = getenv("router")))
		nvram_set(strcat_r(prefix, "gateway", tmp), value);
	if ((value = getenv("dns")))
		nvram_set(strcat_r(prefix, "dns", tmp), value);
	if ((value = getenv("wins")))
		nvram_set(strcat_r(prefix, "wins", tmp), value);
	if ((value = getenv("hostname")))
		sethostname(value, strlen(value) + 1);
	if ((value = getenv("domain")))
		nvram_set(strcat_r(prefix, "domain", tmp), value);
	if ((value = getenv("lease"))) {
		nvram_set(strcat_r(prefix, "lease", tmp), value);
		expires(lan_ifname, atoi(value));
	}

	ifconfig(lan_ifname, IFUP,
		 nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)),
		 nvram_safe_get(strcat_r(prefix, "netmask", tmp)));

	lan_up(lan_ifname);

	logmessage("dhcp client", "%s IP : %s from %s", 
		udhcpstate, 
		nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), 
		nvram_safe_get(strcat_r(prefix, "gateway", tmp)));

	//wanmessage("");

	dprintf("done\n");
	return 0;
}
예제 #12
0
static int
set_wsec(char *ifname, void *credential, int mode)
{
	char tmp[128];
	unsigned char psk_mode = 0;
	WpsEnrCred *cred = (WpsEnrCred *)credential;
	char prefix[] = "wlXXXXXXXXXX_";
	bool b_wps_version2 = false;
	char *value;

	value = nvram_get("wps_version2");
	if (value && !strcmp(value, "enabled"))
		b_wps_version2 = true;

	/* empty credential check */
	if (cred->ssidLen == 0) {
		TUTRACE((TUTRACE_INFO, "Ignore apply new credential because ssid is empty\n"));
		return 0;
	}

	TUTRACE((TUTRACE_INFO,
		"nvram set key = %s keyMgmt = %s ssid = %s(b_configured)\n",
		cred->nwKey, cred->keyMgmt, cred->ssid));

	/* convert os name to wl name */
	if (osifname_to_nvifname(ifname, prefix, sizeof(prefix)) != 0) {
		TUTRACE((TUTRACE_INFO, "Convert to nvname failed\n"));
		return 0;
	}
	strcat(prefix, "_");

	/* Check credential */
	if (findstr(cred->keyMgmt, "WPA-PSK"))
		psk_mode |= 1;
	if (findstr(cred->keyMgmt, "WPA2-PSK"))
		psk_mode |= 2;

	/* for version 2, force psk2 if psk1 is on */
	if (b_wps_version2 && (psk_mode & 1)) {
		psk_mode |= 2;
	}

	switch (psk_mode) {
	case 1:
		wps_osl_set_conf(strcat_r(prefix, "akm", tmp), "psk ");
		wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "psk");
		break;
	case 2:
		wps_osl_set_conf(strcat_r(prefix, "akm", tmp), "psk2 ");
		wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "psk2");
		break;
	case 3:
		wps_osl_set_conf(strcat_r(prefix, "akm", tmp), "psk psk2 ");
		wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "pskpsk2");
		break;
	default:
		wps_osl_set_conf(strcat_r(prefix, "akm", tmp), "");
		wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "open");
		break;
	}

	if (findstr(cred->keyMgmt, "SHARED"))
	{
		wps_osl_set_conf(strcat_r(prefix, "auth", tmp), "1");
		wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "shared");
	}
	else
		wps_osl_set_conf(strcat_r(prefix, "auth", tmp), "0");

	/* set SSID */
	wps_osl_set_conf(strcat_r(prefix, "ssid", tmp), cred->ssid);
	if (psk_mode)
	{
		wps_osl_set_conf(strcat_r(prefix, "wep", tmp), "disabled");
		wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "0");
	}

	/* for version 2, force aes if tkip is on */
	if (b_wps_version2 && (cred->encrType & WPS_ENCRTYPE_TKIP)) {
		cred->encrType |= WPS_ENCRTYPE_AES;
	}

	/* set Encr type */
	if (cred->encrType == WPS_ENCRTYPE_NONE)
	{
		wps_osl_set_conf(strcat_r(prefix, "wep", tmp), "disabled");
		wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "0");
	}
	else if (cred->encrType == WPS_ENCRTYPE_WEP)
		wps_osl_set_conf(strcat_r(prefix, "wep", tmp), "enabled");
	else if (cred->encrType == WPS_ENCRTYPE_TKIP)
		wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "tkip");
	else if (cred->encrType == WPS_ENCRTYPE_AES)
		wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "aes");
	else if (cred->encrType == (WPS_ENCRTYPE_TKIP | WPS_ENCRTYPE_AES))
		wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "tkip+aes");
	else
		wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "tkip");

	if (cred->encrType == WPS_ENCRTYPE_WEP) {
		char buf[16] = {0};
		sprintf(buf, "%d", cred->wepIndex);
		wps_osl_set_conf(strcat_r(prefix, "key", tmp), buf);
		sprintf(buf, "key%d", cred->wepIndex);
		set_wep_key(strcat_r(prefix, buf, tmp), cred->nwKey, cred->nwKeyLen);
		if ((cred->nwKeyLen == 5) || (cred->nwKeyLen == 10))
			wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "1");
		else
			wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "2");
	}
	else {
		/* set key */
		if (cred->nwKeyLen < 64) {
			wps_osl_set_conf(strcat_r(prefix, "wpa_psk", tmp), cred->nwKey);
		}
		else {
			char temp_key[65] = {0};
			memcpy(temp_key, cred->nwKey, 64);
			temp_key[64] = 0;
			wps_osl_set_conf(strcat_r(prefix, "wpa_psk", tmp), temp_key);
		}
	}

	/* Disable nmode for WEP and TKIP for TGN spec */
	switch (cred->encrType) {
	case WPS_ENCRTYPE_WEP:
	case WPS_ENCRTYPE_TKIP:
		wps_osl_set_conf(strcat_r(prefix, "nmode", tmp), "0");
		break;
	default:
		wps_osl_set_conf(strcat_r(prefix, "nmode", tmp), "-1");
		break;
	}

	nvram_set("w_Setting", "1");

	return 1;
}
예제 #13
0
파일: wpa.c 프로젝트: rogerhu/dd-wrt
void start_nas_notify(char *ifname)
{
	char *argv[] = { "nas4not", "lan", ifname, "up",
		NULL,		/* role */
		NULL,		/* crypto */
		NULL,		/* auth */
		NULL,		/* passphrase */
		NULL,		/* ssid */
		NULL
	};
	char *str = NULL;
	char tmp[100], prefix[] = "wlXXXXXXXXXX_", pidfile[] = "/tmp/nas.wlXXXXXXXlan.pid";
	int unit;
	char remote[ETHER_ADDR_LEN];
	char ssid[48], pass[80], auth[16], crypto[16], role[8];
	int i;

	/*
	 * the wireless interface must be configured to run NAS 
	 */
	wl_ioctl(ifname, WLC_GET_INSTANCE, &unit, sizeof(unit));
	snprintf(prefix, sizeof(prefix), "wl%d_", unit);
	snprintf(pidfile, sizeof(pidfile), "/tmp/nas.wl%dlan.pid", unit);

	if (!(str = file2str(pidfile)))	// no pidfile means no nas was run (required)
	{
		return;
	}
	free(str);
	sleep(3);
	/*
	 * find WDS link configuration 
	 */
	wl_ioctl(ifname, WLC_WDS_GET_REMOTE_HWADDR, remote, ETHER_ADDR_LEN);
	for (i = 0; i < MAX_NVPARSE; i++) {
		char mac[ETHER_ADDR_STR_LEN];
		uint8 ea[ETHER_ADDR_LEN];

		if (get_wds_wsec(unit, i, mac, role, crypto, auth, ssid, pass)
		    && ether_atoe(mac, ea)
		    && !bcmp(ea, remote, ETHER_ADDR_LEN)) {
			argv[4] = role;
			argv[5] = crypto;
			argv[6] = auth;
			argv[7] = pass;
			argv[8] = ssid;
			break;
		}
	}

	/*
	 * did not find WDS link configuration, use wireless' 
	 */
	if (i == MAX_NVPARSE) {
		/*
		 * role 
		 */
		argv[4] = "auto";
		/*
		 * crypto 
		 */
		argv[5] = nvram_safe_get(strcat_r(prefix, "crypto", tmp));
		/*
		 * auth mode 
		 */
		argv[6] = nvram_safe_get(strcat_r(prefix, "akm", tmp));
		/*
		 * passphrase 
		 */
		argv[7] = nvram_safe_get(strcat_r(prefix, "wpa_psk", tmp));
		/*
		 * ssid 
		 */
		argv[8] = nvram_safe_get(strcat_r(prefix, "ssid", tmp));
	}
	int pid;

	_evalpid(argv, ">/dev/console", 0, &pid);
}
예제 #14
0
/*
 * Called when link comes up
 */
int
ipup_main(int argc, char **argv)
{
	FILE *fp;
	char *wan_ifname = safe_getenv("IFNAME");
	char *wan_linkname = safe_getenv("LINKNAME");
	char tmp[100], prefix[] = "wanXXXXXXXXXX_";
	char buf[256], *value;
	int unit;

	_dprintf("%s():: %s\n", __FUNCTION__, argv[0]);

	/* Get unit from LINKNAME: ppp[UNIT] */
	if ((unit = ppp_linkunit(wan_linkname)) < 0)
		return 0;

	_dprintf("%s: unit=%d ifname=%s\n", __FUNCTION__, unit, wan_ifname);
	snprintf(prefix, sizeof(prefix), "wan%d_", unit);

	/* Stop triggering demand connection */
	if (nvram_get_int(strcat_r(prefix, "pppoe_demand", tmp)))
		nvram_set_int(strcat_r(prefix, "pppoe_demand", tmp), 1);

#ifdef RTCONFIG_USB_MODEM
	// wanX_ifname is used for device for USB Modem
	if ((value = getenv("DEVICE")) &&
	    (isSerialNode(value) || isACMNode(value)))
		nvram_set(strcat_r(prefix, "ifname", tmp), value);
#endif

	/* Touch connection file */
	if (!(fp = fopen(strcat_r("/tmp/ppp/link.", wan_ifname, tmp), "a"))) {
		perror(tmp);
		return errno;
	}
	fclose(fp);

	if ((value = getenv("IPLOCAL"))) {
		if (nvram_invmatch(strcat_r(prefix, "ipaddr", tmp), value))
			ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL);
		_ifconfig(wan_ifname, IFUP, value, "255.255.255.255", getenv("IPREMOTE"));
		nvram_set(strcat_r(prefix, "ipaddr", tmp), value);
		nvram_set(strcat_r(prefix, "netmask", tmp), "255.255.255.255");
	}

	if ((value = getenv("IPREMOTE")))
		nvram_set(strcat_r(prefix, "gateway", tmp), value);

#ifdef RTCONFIG_DSL
	/* Paul add 2013/1/23, only for Auto DNS and 3G/4G */
	if (!nvram_match(strcat_r(prefix, "dnsenable_x", tmp), "0")) {
#endif
		strcpy(buf, "");
		if ((value = getenv("DNS1")))
			sprintf(buf, "%s", value);
		if ((value = getenv("DNS2")))
			sprintf(buf + strlen(buf), "%s%s", strlen(buf) ? " " : "", value);

		/* set PPP DNS, no DNS/usepeerdns forces update_resolvconf use xdns value */
		nvram_set(strcat_r(prefix, "dns", tmp), buf);
#ifdef RTCONFIG_DSL
	}
#endif

	wan_up(wan_ifname);

	_dprintf("%s:: done\n", __FUNCTION__);
	return 0;
}
예제 #15
0
파일: auth.c 프로젝트: gonzopancho/asuswrt
static int
start_wpa_supplicant(int unit, int restart)
{
	FILE *fp;
	char tmp[100];
	char prefix[] = "wanXXXXXXXXXX_";
	char options[sizeof("/etc/wpa_supplicantXXXXXXXXXX.conf")];
	char pidfile[sizeof("/var/run/wpa_supplicantXXXXXXXXXX.pid")];
	char *wpa_argv[] = {"/usr/sbin/wpa_supplicant",
		"-B", "-W",
		"-i", NULL,	/* interface */
		"-D", "wired",
		"-c", options,
		"-P", pidfile,
		NULL
	};
	char *cli_argv[] = {"/usr/sbin/wpa_cli",
		"-B",
		"-i", NULL,	/* interface */
		"-a", "/tmp/wpa_cli",
		NULL};
	int ret;

	snprintf(prefix, sizeof(prefix), "wan%d_", unit);
	snprintf(options, sizeof(options), "/etc/wpa_supplicant%d.conf", unit);
	snprintf(pidfile, sizeof(pidfile), "/var/run/wpa_supplicant%d.pid", unit);

	if (restart && pids("wpa_supplicant"))
		return kill_pidfile_s(pidfile, SIGUSR2);

	/* Get interface */
	wpa_argv[4] = nvram_safe_get(strcat_r(prefix, "ifname", tmp));
	cli_argv[3] = wpa_argv[4];

	/* Get driver, wired default */
#ifndef RTCONFIG_RALINK /* Both BCM 5.x and 6.x */
	if (get_switch() == SWITCH_BCM5325)
		wpa_argv[6] = "roboswitch";
#endif

	/* Generate options file */
	if ((fp = fopen(options, "w")) == NULL) {
		perror(options);
		return -1;
	}
	fprintf(fp,
		"ctrl_interface=/var/run/wpa_supplicant\n"
		"ap_scan=0\n"
		"fast_reauth=1\n"
		"network={\n"
		"	key_mgmt=IEEE8021X\n"
		"	eap=MD5\n"
		"	identity=\"%s\"\n"
		"	password=\"%s\"\n"
		"	eapol_flags=0\n"
		"}\n",
		nvram_safe_get(strcat_r(prefix, "pppoe_username", tmp)),
		nvram_safe_get(strcat_r(prefix, "pppoe_passwd", tmp)));
	fclose(fp);

	/* Start supplicant & monitor */
	ret = _eval(wpa_argv, NULL, 0, NULL);
	if (ret == 0)
		_eval(cli_argv, NULL, 0, NULL);

	return 0;
}
예제 #16
0
int start_timemachine()
{
	int ret = 0;
	char cnid_path[80];
	char backup_path[80];
	//char token_path[80];
	char test_log[100];
	char *mount_point_name;

	char prefix[] = "usb_pathXXXXXXXXXXXXXXXXX_", tmp[100];
	char usb1_vid[8], usb1_pid[8], usb1_serial[64];
	char usb2_vid[8], usb2_pid[8], usb2_serial[64];

	snprintf(prefix, sizeof(prefix), "usb_path%s", "1");
	memset(usb1_vid, 0, 8);
	strncpy(usb1_vid, nvram_safe_get(strcat_r(prefix, "_vid", tmp)), 8);
	memset(usb1_pid, 0, 8);
	strncpy(usb1_pid, nvram_safe_get(strcat_r(prefix, "_pid", tmp)), 8);
	memset(usb1_serial, 0, 64);
	strncpy(usb1_serial, nvram_safe_get(strcat_r(prefix, "_serial", tmp)), 8);

	snprintf(prefix, sizeof(prefix), "usb_path%s", "2");
	memset(usb2_vid, 0, 8);
	strncpy(usb2_vid, nvram_safe_get(strcat_r(prefix, "_vid", tmp)), 8);
	memset(usb2_pid, 0, 8);
	strncpy(usb2_pid, nvram_safe_get(strcat_r(prefix, "_pid", tmp)), 8);
	memset(usb2_serial, 0, 64);
	strncpy(usb2_serial, nvram_safe_get(strcat_r(prefix, "_serial", tmp)), 8);

	//clear_timemachine_tokeninfo();
	//find_tokenfile_partition();

	if(!nvram_match("timemachine_enable", "1"))
		return -1;

	if(nvram_safe_get("tm_device_name") == NULL)
	{
		_dprintf("Timemachine: no device name to backup\n");
		logmessage("Timemachine", "no device name to backup");
		return -1;
	}
#if 1
	if(nvram_match("tm_ui_setting", "1")){
		logmessage("Timemachine", "User select disk start TimeMachine");
		mount_point_name = find_mountpoint(nvram_safe_get("tm_device_name"));
		nvram_set("tm_ui_setting", "0");
	}else{
	//check mountpoint exchange or not
	if(!nvram_match("tm_usb_path_vid", "")
		&& (nvram_match("tm_usb_path_vid",usb1_vid)) 
		&& (nvram_match("tm_usb_path_pid",usb1_pid)) 
		&& (nvram_match("tm_usb_path_serial",usb1_serial)))
	{
		sprintf(test_log, "Time Machine interface1 change %s -> %s", nvram_safe_get("tm_device_name"),nvram_safe_get("tm_partition_num"));
		mount_point_name = find_mountpoint(nvram_safe_get("tm_device_name"));
		logmessage("Timemachine", test_log);
	}
	else if(!nvram_match("tm_usb_path_vid", "")
		&& (nvram_match("tm_usb_path_vid",usb2_vid)) 
		&& (nvram_match("tm_usb_path_pid",usb2_pid))
		&& (nvram_match("tm_usb_path_serial",usb2_serial)))
	{
		sprintf(test_log, "tm_device_name interface2 change %s -> %s", nvram_safe_get("tm_device_name"),nvram_safe_get("tm_partition_num"));
		mount_point_name = find_mountpoint(nvram_safe_get("tm_device_name"));
		logmessage("Timemachine", test_log);
	}else{
		logmessage("Timemachine", "No disk to auto start TimeMachine");
		mount_point_name = find_mountpoint(nvram_safe_get("tm_device_name"));
	}
	}
#endif

	if(mount_point_name == NULL)
	{
		_dprintf("Timemachine: can not find the correct mount point name\n");
		logmessage("Timemachine", "can not find the correct mount point name");
		return -1;
	}

	if(!check_if_dir_exist(mount_point_name))
	{
		_dprintf("Timemachine: mount point name doesn't exist\n");
		logmessage("Timemachine", "mount point name doesn't exist");
		return -1;
	}

	// Create directory for use by afpd daemon and configuration file
	//if(!check_if_dir_exist(AFP_LOCK_PATH)) mkdir(AFP_LOCK_PATH, 0777);
	//if(!check_if_dir_exist(AFP_CONFIG_PATH)) mkdir(AFP_CONFIG_PATH, 0777);
	mkdir_if_none(AFP_LOCK_PATH);
	mkdir_if_none(AFP_CONFIG_PATH);

	// Create directory for use by avahi daemon and configuration file
	//if(!check_if_dir_exist(AVAHI_CONFIG_PATH)) mkdir(AVAHI_CONFIG_PATH, 0777);
	//if(!check_if_dir_exist(AVAHI_SERVICES_PATH)) mkdir(AVAHI_SERVICES_PATH, 0777);
	mkdir_if_none(AVAHI_CONFIG_PATH);
	mkdir_if_none(AVAHI_SERVICES_PATH);

	// Create directory for use by cnid_metad and cnid_dbd daemon
	sprintf(cnid_path, "%s/%s", mount_point_name, CNID_DIR_NAME);
	sprintf(backup_path, "%s", mount_point_name);

	//Create token file
	//sprintf(token_path, "%s/%s", mount_point_name, TIMEMACHINE_TOKEN_FILE);
	//if(!check_if_file_exist(token_path))
	//	ret = generate_timemachine_token_file(token_path);

	//if(!check_if_dir_exist(cnid_path)) mkdir(cnid_path, 0777);
	//if(!check_if_dir_exist(backup_path)) mkdir(backup_path, 0777);
	mkdir_if_none(cnid_path);
	//mkdir_if_none(backup_path);

	ret = generate_afp_config(mount_point_name);
	start_afpd();
	start_cnid_metad();
	restart_mdns();

	logmessage("Timemachine", "daemon is started");

	return ret;
}
예제 #17
0
파일: psta_monitor.c 프로젝트: gygy/asuswrt
static void
psta_keepalive(int ex)
{
	char tmp[NVRAM_BUFSIZE], prefix[] = "wlXXXXXXXXXX_";
	char *name = NULL;
	struct maclist *mac_list = NULL;
	int mac_list_size, i, unit;
	int psta = 0;
	struct ether_addr bssid;
	unsigned char bssid_null[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
	char macaddr[18];
	char band_var[16];

	sprintf(band_var, "wlc_band%s", ex?"_ex":"");
	unit = nvram_get_int(band_var);
	snprintf(prefix, sizeof(prefix), "wl%d_", unit);

	if (!nvram_match(strcat_r(prefix, "mode", tmp), "psta"))
		goto PSTA_ERR;

	name = nvram_safe_get(strcat_r(prefix, "ifname", tmp));

	if (wl_ioctl(name, WLC_GET_BSSID, &bssid, ETHER_ADDR_LEN) != 0)
		goto PSTA_ERR;
	else if (!memcmp(&bssid, bssid_null, 6))
		goto PSTA_ERR;

	/* buffers and length */
	mac_list_size = sizeof(mac_list->count) + MAX_STA_COUNT * sizeof(struct ether_addr);
	mac_list = malloc(mac_list_size);

	if (!mac_list)
		goto PSTA_ERR;

	/* query wl for authenticated sta list */
	strcpy((char*)mac_list, "authe_sta_list");
	if (wl_ioctl(name, WLC_GET_VAR, mac_list, mac_list_size)) {
		free(mac_list);
		goto PSTA_ERR;
	}

	/* query sta_info for each STA and output one table row each */
	if (mac_list->count)
	{
		if (nvram_match(strcat_r(prefix, "akm", tmp), ""))
			psta = 1;
		else
		for (i = 0; i < mac_list->count; i++) {
			if (wl_autho(name, &mac_list->ea[i]))
			{
				psta = 1;
				break;
			}
		}
	}

PSTA_ERR:
	if (psta)
	{
		count_bss_down = 0;
		ether_etoa((const unsigned char *) &bssid, macaddr);
		if (psta_debug) dbg("psta send keepalive nulldata to %s\n", macaddr);
		eval("wl", "-i", name, "send_nulldata", macaddr);
#ifdef PSTA_DEBUG
		count = (count + 1) % 10;
		if (!count) check_wl_rate(name);
#endif
	}
	else
	{
		if (psta_debug) dbg("psta disconnected\n");
		if (++count_bss_down > 9)
		{
			count_bss_down = 0;
			if (wl_scan(unit))
			{
				eval("wlconf", name, "down");
				eval("wlconf", name, "up");
				eval("wlconf", name, "start");
			}
		}
		else
		{
			eval("wl", "-i", name, "bss", "down");
			eval("wl", "-i", name, "down");
			eval("wl", "-i", name, "up");
			eval("wl", "-i", name, "bss", "up");
		}
	}

	if (mac_list) free(mac_list);
}
예제 #18
0
파일: vpnc.c 프로젝트: gonzopancho/asuswrt
int
start_vpnc(void)
{
	FILE *fp;
	char options[80];
	char *pppd_argv[] = { "/usr/sbin/pppd", "file", options, NULL};
	char tmp[100], prefix[] = "vpnc_", wan_prefix[] = "wanXXXXXXXXXX_";
	char buf[256];	/* although maximum length of pppoe_username/pppoe_passwd is 64. pppd accepts up to 256 characters. */
	mode_t mask;
	int ret = 0;

//	_dprintf("%s: unit=%d.\n", __FUNCTION__, unit);

//	snprintf(prefix, sizeof(prefix), "vpn%d_", unit);
	snprintf(wan_prefix, sizeof(wan_prefix), "wan%d_", wan_primary_ifunit());

	if (nvram_match(strcat_r(wan_prefix, "proto", tmp), "pptp") || nvram_match(strcat_r(wan_prefix, "proto", tmp), "l2tp"))
		return 0;

	if (nvram_match(strcat_r(prefix, "proto", tmp), "pptp"))
		sprintf(options, "/tmp/ppp/vpnc_options.pptp");
	else if (nvram_match(strcat_r(prefix, "proto", tmp), "l2tp"))
		sprintf(options, "/tmp/ppp/vpnc_options.l2tp");
	else
		return 0;

	update_vpnc_state(prefix, WAN_STATE_INITIALIZING, 0);

	mask = umask(0000);

	/* Generate options file */
	if (!(fp = fopen(options, "w"))) {
		perror(options);
		umask(mask);
		return -1;
	}

	umask(mask);

	/* do not authenticate peer and do not use eap */
	fprintf(fp, "noauth\n");
	fprintf(fp, "refuse-eap\n");
	handle_special_char_for_vpnclient(buf, sizeof(buf), nvram_safe_get(strcat_r(prefix, "pppoe_username", tmp)));
	fprintf(fp, "user '%s'\n", buf);
	handle_special_char_for_vpnclient(buf, sizeof(buf), nvram_safe_get(strcat_r(prefix, "pppoe_passwd", tmp)));
	fprintf(fp, "password '%s'\n", buf);

	if (nvram_match(strcat_r(prefix, "proto", tmp), "pptp")) {
		fprintf(fp, "plugin pptp.so\n");
		fprintf(fp, "pptp_server '%s'\n",
			nvram_invmatch(strcat_r(prefix, "heartbeat_x", tmp), "") ?
			nvram_safe_get(strcat_r(prefix, "heartbeat_x", tmp)) :
			nvram_safe_get(strcat_r(prefix, "gateway_x", tmp)));
		fprintf(fp, "vpnc 1\n");
		/* see KB Q189595 -- historyless & mtu */
		fprintf(fp, "nomppe-stateful mtu 1400\n");
		if (nvram_match(strcat_r(prefix, "pptp_options_x", tmp), "-mppc")) {
			fprintf(fp, "nomppe nomppc\n");
		} else
		if (nvram_match(strcat_r(prefix, "pptp_options_x", tmp), "+mppe-40")) {
			fprintf(fp, "nomppe-56\n"
                                    "nomppe-128\n"
				    "require-mppe\n"
				    "require-mppe-40\n");
		} else
		if (nvram_match(strcat_r(prefix, "pptp_options_x", tmp), "+mppe-56")) {
			fprintf(fp, "nomppe-40\n"
				    "nomppe-128\n"
				    "require-mppe\n"
				    "require-mppe-56\n");
		} else
		if (nvram_match(strcat_r(prefix, "pptp_options_x", tmp), "+mppe-128")) {
			fprintf(fp, "nomppe-40\n"
				    "nomppe-56\n"
				    "require-mppe\n"
				    "require-mppe-128\n");
		}
	} else {
		fprintf(fp, "nomppe nomppc\n");
	}

	if (nvram_invmatch(strcat_r(prefix, "proto", tmp), "l2tp")) {
		ret = nvram_get_int(strcat_r(prefix, "pppoe_idletime", tmp));
		if (ret && nvram_get_int(strcat_r(prefix, "pppoe_demand", tmp))) {
			fprintf(fp, "idle %d ", ret);
			if (nvram_invmatch(strcat_r(prefix, "pppoe_txonly_x", tmp), "0"))
				fprintf(fp, "tx_only ");
			fprintf(fp, "demand\n");
		}
		fprintf(fp, "persist\n");
	}

	fprintf(fp, "holdoff %d\n", nvram_get_int(strcat_r(prefix, "pppoe_holdoff", tmp)) ? : 10);
	fprintf(fp, "maxfail %d\n", nvram_get_int(strcat_r(prefix, "pppoe_maxfail", tmp)));

	if (nvram_invmatch(strcat_r(prefix, "dnsenable_x", tmp), "0"))
		fprintf(fp, "usepeerdns\n");

	fprintf(fp, "ipcp-accept-remote ipcp-accept-local noipdefault\n");
	fprintf(fp, "ktune\n");

	/* pppoe set these options automatically */
	/* looks like pptp also likes them */
	fprintf(fp, "default-asyncmap nopcomp noaccomp\n");

	/* pppoe disables "vj bsdcomp deflate" automagically */
	/* ccp should still be enabled - mppe/mppc requires this */
	fprintf(fp, "novj nobsdcomp nodeflate\n");

	/* echo failures */
	fprintf(fp, "lcp-echo-interval 6\n");
	fprintf(fp, "lcp-echo-failure 10\n");

	/* pptp has Echo Request/Reply, l2tp has Hello packets */
	if (nvram_match(strcat_r(prefix, "proto", tmp), "pptp") ||
	    nvram_match(strcat_r(prefix, "proto", tmp), "l2tp"))
		fprintf(fp, "lcp-echo-adaptive\n");

	fprintf(fp, "unit %d\n", vpnc_unit);
	fprintf(fp, "linkname vpn%d\n", vpnc_unit);
	fprintf(fp, "ip-up-script %s\n", "/tmp/ppp/vpnc-ip-up");
	fprintf(fp, "ip-down-script %s\n", "/tmp/ppp/vpnc-ip-down");
	fprintf(fp, "ip-pre-up-script %s\n", "/tmp/ppp/vpnc-ip-pre-up");
	fprintf(fp, "auth-fail-script %s\n", "/tmp/ppp/vpnc-auth-fail");

#ifdef RTCONFIG_IPV6
	switch (get_ipv6_service()) {
		case IPV6_NATIVE:
		case IPV6_NATIVE_DHCP:
		case IPV6_MANUAL:
			fprintf(fp, "+ipv6\n");
			break;
        }
#endif

	/* user specific options */
	fprintf(fp, "%s\n",
		nvram_safe_get(strcat_r(prefix, "pppoe_options_x", tmp)));

	fclose(fp);

	/* shut down previous instance if any */
	stop_vpnc();

	if (nvram_match(strcat_r(prefix, "proto", tmp), "l2tp"))
	{
		if (!(fp = fopen("/tmp/l2tp.conf", "w"))) {
			perror(options);
			return -1;
		}

		fprintf(fp, "# automagically generated\n"
			"global\n\n"
			"load-handler \"sync-pppd.so\"\n"
			"load-handler \"cmd.so\"\n\n"
			"section sync-pppd\n\n"
			"lac-pppd-opts \"file %s\"\n\n"
			"section peer\n"
			"port 1701\n"
			"peername %s\n"
			"vpnc 1\n"
			"hostname %s\n"
			"lac-handler sync-pppd\n"
			"persist yes\n"
			"maxfail %d\n"
			"holdoff %d\n"
			"hide-avps no\n"
			"section cmd\n\n",
			options,
                        nvram_invmatch(strcat_r(prefix, "heartbeat_x", tmp), "") ?
                                nvram_safe_get(strcat_r(prefix, "heartbeat_x", tmp)) :
                                nvram_safe_get(strcat_r(prefix, "gateway_x", tmp)),
			nvram_invmatch(strcat_r(prefix, "hostname", tmp), "") ?
				nvram_safe_get(strcat_r(prefix, "hostname", tmp)) : "localhost",
			nvram_get_int(strcat_r(prefix, "pppoe_maxfail", tmp))  ? : 32767,
			nvram_get_int(strcat_r(prefix, "pppoe_holdoff", tmp)) ? : 10);

		fclose(fp);

		/* launch l2tp */
		eval("/usr/sbin/l2tpd");

		ret = 3;
		do {
			_dprintf("%s: wait l2tpd up at %d seconds...\n", __FUNCTION__, ret);
			usleep(1000*1000);
		} while (!pids("l2tpd") && ret--);

		/* start-session */
		ret = eval("/usr/sbin/l2tp-control", "start-session 0.0.0.0");

		/* pppd sync nodetach noaccomp nobsdcomp nodeflate */
		/* nopcomp novj novjccomp file /tmp/ppp/options.l2tp */

	} else
예제 #19
0
static int
bound(void)	// udhcpc bound here, also call wanup
{
	char *wan_ifname = safe_getenv("interface");
	char *value;
	char tmp[100], prefix[] = "wanXXXXXXXXXX_";
	int unit;

	if ((unit = wan_ifunit(wan_ifname)) < 0) 
		strcpy(prefix, "wanx_");
	else
		snprintf(prefix, sizeof(prefix), "wan%d_", unit);

	if ((value = getenv("ip")))
		nvram_set(strcat_r(prefix, "ipaddr", tmp), trim_r(value));
	if ((value = getenv("subnet")))
		nvram_set(strcat_r(prefix, "netmask", tmp), trim_r(value));
        if ((value = getenv("router")))
		nvram_set(strcat_r(prefix, "gateway", tmp), trim_r(value));
	if ((value = getenv("dns")))
		nvram_set(strcat_r(prefix, "dns", tmp), trim_r(value));
	if ((value = getenv("wins")))
		nvram_set(strcat_r(prefix, "wins", tmp), trim_r(value));

	nvram_set(strcat_r(prefix, "routes", tmp), getenv("routes"));
	nvram_set(strcat_r(prefix, "msroutes", tmp), getenv("msroutes"));
#if 0
	if ((value = getenv("hostname")))
		sethostname(trim_r(value), strlen(value) + 1);
#endif
	if ((value = getenv("domain")))
		nvram_set(strcat_r(prefix, "domain", tmp), trim_r(value));
	if ((value = getenv("lease"))) {
		nvram_set(strcat_r(prefix, "lease", tmp), trim_r(value));
		expires(wan_ifname, atoi(value));
	}

	ifconfig(wan_ifname, IFUP,
		 nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)),
		 nvram_safe_get(strcat_r(prefix, "netmask", tmp)));

	spinlock_lock(SPINLOCK_DHCPRenew);
	nvram_set("dhcp_renew", "0");	// for detectWAN
	spinlock_unlock(SPINLOCK_DHCPRenew);

	wan_up(wan_ifname);

	logmessage("dhcp client", "%s IP: %s from %s (prefix: %s)", 
		udhcpstate, 
		nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), 
		nvram_safe_get(strcat_r(prefix, "gateway", tmp)), prefix);

	wanmessage("");
	dprintf("done\n");
	return 0;
}
예제 #20
0
static uint32
wpssta_reg_config_init(wpssta_wksp_t *sta_wksp, char *ifname, char *bssid, char oob)
{
	DevInfo info;
	char *value, *next;
	int auth = 0;
	char mac[6];
	char ssid[MAX_SSID_LEN + 1] = {0};
	char psk[MAX_USER_KEY_LEN + 1] = {0};
	char akmstr[32];
	char key[8];
	unsigned int akm = 0;
	unsigned int wsec = 0;
	int wep_index = 0;			/* wep key index */
	char *wep_key = NULL;			/* user-supplied wep key */
	char dev_akm[64] = {0};
	char dev_crypto[64] = {0};
	char prefix[] = "wlXXXXXXXXXX_";
	char tmp[100];
	uint32 ret;

	/* TBD, is going to use osname only */
	sprintf(prefix, "%s_", ifname);

	/* fill in device specific info. */
	memset((char *)(&info), 0, sizeof(info));

	info.version = WPS_VERSION;

	/* MAC addr */
	wps_osl_get_mac(mac);
	memcpy(info.macAddr, mac, 6);

	memcpy(info.uuid, wps_get_uuid(), SIZE_16_BYTES);
	strcpy(info.deviceName, "Broadcom Registrar");
	info.primDeviceCategory = WPS_DEVICE_TYPE_CAT_NW_INFRA;
	info.primDeviceOui = 0x0050F204;
	info.primDeviceSubCategory = WPS_DEVICE_TYPE_SUB_CAT_NW_GATEWAY;
	strcpy(info.manufacturer, "Broadcom");
	strcpy(info.modelName, "WPS Wireless Registrar");
	strcpy(info.modelNumber, "1234");
	strcpy(info.serialNumber, "5678");

	if (b_wps_version2) {
		info.configMethods = (WPS_CONFMET_VIRT_PBC | WPS_CONFMET_PHY_PBC |
			WPS_CONFMET_VIRT_DISPLAY);
	}
	else {
		info.configMethods = WPS_CONFMET_PBC | WPS_CONFMET_DISPLAY;
	}

	/* WSC 2.0, WPS-PSK and SHARED are deprecated.
	 * When both the Registrar and the Enrollee are using protocol version 2.0
	 * or newer, this variable can use the value 0x0022 to indicate mixed mode
	 * operation (both WPA-Personal and WPA2-Personal enabled)
	 */
	if (b_wps_version2) {
		info.authTypeFlags = (uint16)(WPS_AUTHTYPE_OPEN | WPS_AUTHTYPE_WPAPSK |
			WPS_AUTHTYPE_WPA2PSK);
	}
	else {
		info.authTypeFlags = (uint16)(WPS_AUTHTYPE_OPEN | WPS_AUTHTYPE_WPAPSK |
			WPS_AUTHTYPE_SHARED | WPS_AUTHTYPE_WPA2PSK);
	}

	/* ENCR_TYPE_FLAGS */
	/*
	 * WSC 2.0, deprecated WEP. TKIP can only be advertised on the AP when
	 * Mixed Mode is enabled (Encryption Type is 0x000c)
	 */
	if (b_wps_version2) {
		info.encrTypeFlags = (uint16)(WPS_ENCRTYPE_NONE | WPS_ENCRTYPE_TKIP |
			WPS_ENCRTYPE_AES);
	}
	else {
		info.encrTypeFlags = (uint16)(WPS_ENCRTYPE_NONE | WPS_ENCRTYPE_WEP |
			WPS_ENCRTYPE_TKIP | WPS_ENCRTYPE_AES);
	}

	info.connTypeFlags = WPS_CONNTYPE_ESS;
	info.rfBand = WPS_RFBAND_24GHZ;
	info.osVersion = 0x80000000;
	info.featureId = 0x80000000;
	/* WSC 2.0 */
	if (b_wps_version2) {
		value = wps_get_conf("wps_version2_num");
		info.version2 = (uint8)(strtoul(value, NULL, 16));
		info.settingsDelayTime = WPS_SETTING_DELAY_TIME_ROUTER;
		info.b_reqToEnroll = FALSE;
		info.b_nwKeyShareable = FALSE;
	}

	if (sta_wksp->configap == true) {
		/*
		 * Before check oob mode, we have to
		 * get ssid, akm, wep, crypto and mgmt key from config.
		 * because oob mode might change the settings.
		 */
		value = wps_safe_get_conf(strcat_r(prefix, "ssid", tmp));
		strncpy(ssid, value, MAX_SSID_LEN);

		value = wps_safe_get_conf(strcat_r(prefix, "akm", tmp));
		foreach(akmstr, value, next) {
			if (!strcmp(akmstr, "psk"))
				akm |= WPA_AUTH_PSK;

			if (!strcmp(akmstr, "psk2"))
				akm |= WPA2_AUTH_PSK;
		}

		value = wps_safe_get_conf(strcat_r(prefix, "wep", tmp));
		wsec = !strcmp(value, "enabled") ? WEP_ENABLED : 0;

		value = wps_safe_get_conf(strcat_r(prefix, "crypto", tmp));
		if (WPS_WLAKM_PSK(akm) || WPS_WLAKM_PSK2(akm)) {
			if (!strcmp(value, "tkip"))
				wsec |= TKIP_ENABLED;
			else if (!strcmp(value, "aes"))
				wsec |= AES_ENABLED;
			else if (!strcmp(value, "tkip+aes"))
				wsec |= TKIP_ENABLED|AES_ENABLED;

			/* Set PSK key */
			value = wps_safe_get_conf(strcat_r(prefix, "wpa_psk", tmp));
			strncpy(psk, value, MAX_USER_KEY_LEN);
			psk[MAX_USER_KEY_LEN] = 0;
		}

		if (wsec & WEP_ENABLED) {
			/* Key index */
			value = wps_safe_get_conf(strcat_r(prefix, "key", tmp));
			wep_index = (int)strtoul(value, NULL, 0);

			/* Key */
			sprintf(key, "key%s", value);
			wep_key = wps_safe_get_conf(strcat_r(prefix, key, tmp));
		}

		/* Caution: wps_oob will over-write akm and wsec */
		if (oob) {
			/* Generate random ssid and key */
			if (wps_gen_ssid(ssid, sizeof(ssid),
				wps_get_conf("wps_random_ssid_prefix"),
				wps_safe_get_conf("wl0_hwaddr")) == FALSE ||
			    wps_gen_key(psk, sizeof(psk)) == FALSE)
				return WPS_ERR_SYSTEM;

			/* Open */
			auth = 0;

			/* PSK, PSK2 */
			akm = WPA_AUTH_PSK | WPA2_AUTH_PSK;
			wsec = AES_ENABLED;
		}

		/*
		 * Let the user have a chance to override the credential.
		 */
		if (WPS_WLAKM_BOTH(akm))
			strcpy(dev_akm, "WPA-PSK WPA2-PSK");
		else if (WPS_WLAKM_PSK(akm))
			strcpy(dev_akm, "WPA-PSK");
		else if (WPS_WLAKM_PSK2(akm))
			strcpy(dev_akm, "WPA2-PSK");
		else
			dev_akm[0] = 0;

		/* Encryption algorithm */
		if (WPS_WLENCR_BOTH(wsec))
			strcpy(dev_crypto, "AES+TKIP");
		else if (WPS_WLENCR_TKIP(wsec))
			strcpy(dev_crypto, "TKIP");
		else if (WPS_WLENCR_AES(wsec))
			strcpy(dev_crypto, "AES");
		else
			dev_crypto[0] = 0;

		/* Do customization, and check credentials again */
		wpssta_update_custom_cred(ssid, psk, dev_akm, dev_crypto, oob,
			b_wps_version2);

		/*
		 * After doing customized credentials modification,
		 * fill ssid, psk, akm and crypto to ap_deviceinfo
		 */
		strcpy(info.ssid, ssid);

		/* Parsing return amk and crypto */
		if (strlen(dev_akm)) {
			if (!strcmp(dev_akm, "WPA-PSK WPA2-PSK"))
				akm = WPA_AUTH_PSK | WPA2_AUTH_PSK;
			else if (!strcmp(dev_akm, "WPA-PSK"))
				akm = WPA_AUTH_PSK;
			else if (!strcmp(dev_akm, "WPA2-PSK"))
				akm = WPA2_AUTH_PSK;
		}
		if (strlen(dev_crypto)) {
			if (!strcmp(dev_crypto, "AES+TKIP"))
				wsec = AES_ENABLED | TKIP_ENABLED;
			else if (!strcmp(dev_crypto, "AES"))
				wsec = AES_ENABLED;
			else if (!strcmp(dev_crypto, "TKIP"))
				wsec = TKIP_ENABLED;
		}

		/* KEY MGMT */
		/* WSC 2.0, deprecated SHARED */
		if (auth) {
			strcpy(info.keyMgmt, "SHARED");
			if (b_wps_version2 && !oob) {
				TUTRACE((TUTRACE_INFO,
					"wpssta_readConfigure: Error in configuration,"
					"Authentication type is Shared, violate WSC 2.0\n"));
				return MC_ERR_CFGFILE_CONTENT;
			}
		}
		else {
			if (WPS_WLAKM_BOTH(akm))
				strcpy(info.keyMgmt, "WPA-PSK WPA2-PSK");
			else if (WPS_WLAKM_PSK(akm))
				strcpy(info.keyMgmt, "WPA-PSK");
			else if (WPS_WLAKM_PSK2(akm))
				strcpy(info.keyMgmt, "WPA2-PSK");
			else
				info.keyMgmt[0] = 0;
		}

		/* WEP index */
		info.wep = (wsec & WEP_ENABLED) ? 1 : 0;

		/* Set crypto algorithm */
		info.crypto = 0;
		if (wsec & TKIP_ENABLED)
			info.crypto |= WPS_ENCRTYPE_TKIP;
		if (wsec & AES_ENABLED)
			info.crypto |= WPS_ENCRTYPE_AES;

		if (info.crypto == 0)
			info.crypto = WPS_ENCRTYPE_TKIP;

		/* WSC 2.0 */
		if (b_wps_version2) {			/* Version 2 */
			value = wps_get_conf("wps_version2_num");
			info.version2 = (uint8)(strtoul(value, NULL, 16));

			/* Setting Delay Time */
			info.settingsDelayTime = WPS_SETTING_DELAY_TIME_ROUTER;
		}
		ret = wps_enr_reg_config_init(&info, psk, strlen(psk), bssid);

	} /* configap == true */
예제 #21
0
int ej_get_DSL_WAN_list(int eid, webs_t wp, int argc, char_t **argv){
	char buf[MAX_LINE_SIZE];
	char buf2[MAX_LINE_SIZE];
	char prefix[]="dslXXXXXX_", tmp[100];
	int unit;
	int j;
	int firstItem;

	if(nvram_match("dsltmp_transmode", "atm")) {
		char *display_items[] = {"dsl_enable", "dsl_vpi", "dsl_vci","dsl_proto", "dsl_encap", 
			"dsl_svc_cat", "dsl_pcr","dsl_scr","dsl_mbs",
#ifdef RTCONFIG_DSL_TCLINUX
			"dsl_dot1q", "dsl_vid", "dsl_dot1p",
#endif
			NULL};

		for ( unit = 0; unit<8; unit++ ) {
			snprintf(prefix, sizeof(prefix), "dsl%d_", unit);

			firstItem = 1;
			websWrite(wp, "[");
			for ( j = 0; display_items[j] != NULL; j++ ) {
				if(firstItem == 1) {
					firstItem = 0;
				}
				else {
					websWrite(wp, ", ");
				}
				strcpy(buf,nvram_safe_get(strcat_r(prefix, &display_items[j][4], tmp)));
				if (strcmp(buf,"")==0) {
					strcpy(buf2,"\"0\"");
				}
				else {
					sprintf(buf2,"\"%s\"",buf);
				}
				websWrite(wp, "%s", buf2);
			}
			if (unit != 7) {
				websWrite(wp, "], ");
			}
			else {
				websWrite(wp, "]");
			}
		}
	}
	else {	//ptm
		char *display_items[] = {"dsl_enable", "dsl_proto", "dsl_dot1q", "dsl_vid", "dsl_dot1p", NULL};

		for ( unit = 0; unit<8; unit++ ) {
			if(unit)
				snprintf(prefix, sizeof(prefix), "dsl8.%d_", unit);
			else
				snprintf(prefix, sizeof(prefix), "dsl8_");

			firstItem = 1;
			websWrite(wp, "[");
			for ( j = 0; display_items[j] != NULL; j++ ) {
				if(firstItem == 1) {
					firstItem = 0;
				}
				else {
					websWrite(wp, ", ");
				}
				strcpy(buf,nvram_safe_get(strcat_r(prefix, &display_items[j][4], tmp)));
				if (strcmp(buf,"")==0) {
					strcpy(buf2,"\"0\"");
				}
				else {
					sprintf(buf2,"\"%s\"",buf);
				}
				websWrite(wp, "%s", buf2);
			}
			if (unit != 7) {
				websWrite(wp, "], ");
			}
			else {
				websWrite(wp, "]");
			}
		}
	}

	return 0;
}
예제 #22
0
#ifdef RTCONFIG_AP_CARRIER_DETECTION
if(nvram_match("JP_CS","1"))
#else	
	if (nvram_match(strcat_r(prefix, "country_code", tmp), "JP"))
#endif	   
	{
		fprintf(fp, "RDRegion=%s\n", "JAP");
		fprintf(fp, "CarrierDetect=%d\n", 1);
	}
	else
#endif
	{
#ifdef RTCONFIG_RALINK_DFS		
		fprintf(fp, "RDRegion=%s\n",nvram_get("reg_spec"));
#else		
		fprintf(fp, "RDRegion=\n");
#endif		
		fprintf(fp, "CarrierDetect=%d\n", 0);
	}