/*
 * Get IOCTL given the parameter buffer.
 */
static int
ioctl_get(int cmd, void *buf, int len)
{
    return wl_ioctl(cmd, buf, len, FALSE);
}
/*
 * Set IOCTL given the parameter buffer.
 */
static int
ioctl_set(int cmd, void *buf, int len)
{
    return wl_ioctl(cmd, buf, len, TRUE);
}
Exemple #3
0
static int wlcompat_ioctl(struct net_device *dev,
			 struct iw_request_info *info,
			 union iwreq_data *wrqu,
			 char *extra)
{
	switch (info->cmd) {
		case SIOCGIWNAME:
			strcpy(wrqu->name, "IEEE 802.11-DS");
			break;
		case SIOCGIWFREQ:
		{
			channel_info_t ci;

			if (wl_ioctl(dev,WLC_GET_CHANNEL, &ci, sizeof(ci)) < 0)
				return -EINVAL;

			wrqu->freq.m = ci.target_channel;
			wrqu->freq.e = 0;
			break;
		}
		case SIOCSIWFREQ:
		{
			if (wrqu->freq.m == -1) {
				wrqu->freq.m = 0;
				if (wl_ioctl(dev, WLC_SET_CHANNEL, &wrqu->freq.m, sizeof(int)) < 0)
					return -EINVAL;
			} else {
				if (wrqu->freq.e == 1) {
					int channel = 0;
					int f = wrqu->freq.m / 100000;
					while ((channel < NUM_CHANNELS + 1) && (f != channel_frequency[channel]))
						channel++;
					
					if (channel == NUM_CHANNELS) // channel not found
						return -EINVAL;

					wrqu->freq.e = 0;
					wrqu->freq.m = channel + 1;
				}
				if ((wrqu->freq.e == 0) && (wrqu->freq.m < 1000)) {
					if (wl_ioctl(dev, WLC_SET_CHANNEL, &wrqu->freq.m, sizeof(int)) < 0)
						return -EINVAL;
				} else {
					return -EINVAL;
				}
			}
			break;
		}
		case SIOCSIWAP:
		{
			int ap = 0;
			
			if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
				return -EINVAL;

			if (wl_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap)) < 0)
				return -EINVAL;
			
			if (wl_ioctl(dev, (ap ? WLC_SET_BSSID : WLC_REASSOC), wrqu->ap_addr.sa_data, 6) < 0)
				return -EINVAL;

			break;
		}
		case SIOCGIWAP:
		{
			wrqu->ap_addr.sa_family = ARPHRD_ETHER;
			if (wl_ioctl(dev,WLC_GET_BSSID,wrqu->ap_addr.sa_data,6) < 0)
				return -EINVAL;
			break;
		}
		case SIOCGIWESSID:
		{
			wlc_ssid_t ssid;
			
			if (wl_ioctl(dev,WLC_GET_SSID, &ssid, sizeof(wlc_ssid_t)) < 0)
				return -EINVAL;

			wrqu->essid.flags = wrqu->data.flags = 1;
			wrqu->essid.length = wrqu->data.length = ssid.SSID_len + 1;
			memcpy(extra,ssid.SSID,ssid.SSID_len + 1);
			break;
		}
		case SIOCSIWESSID:
		{
			wlc_ssid_t ssid;
			memset(&ssid, 0, sizeof(ssid));
			ssid.SSID_len = strlen(extra);
			if (ssid.SSID_len > WLC_ESSID_MAX_SIZE)
				ssid.SSID_len = WLC_ESSID_MAX_SIZE;
			memcpy(ssid.SSID, extra, ssid.SSID_len);
			if (wl_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(ssid)) < 0)
				return -EINVAL;
			break;
		}
		case SIOCGIWRTS:
		{
			if (wl_ioctl(dev,WLC_GET_RTS,&(wrqu->rts.value),sizeof(int)) < 0) 
				return -EINVAL;
			break;
		}
		case SIOCSIWRTS:
		{
			if (wl_ioctl(dev,WLC_SET_RTS,&(wrqu->rts.value),sizeof(int)) < 0) 
				return -EINVAL;
			break;
		}
		case SIOCGIWFRAG:
		{
			if (wl_ioctl(dev,WLC_GET_FRAG,&(wrqu->frag.value),sizeof(int)) < 0)
				return -EINVAL;
			break;
		}
		case SIOCSIWFRAG:
		{
			if (wl_ioctl(dev,WLC_SET_FRAG,&(wrqu->frag.value),sizeof(int)) < 0)
				return -EINVAL;
			break;
		}
		case SIOCGIWTXPOW:
		{
			int radio;

			wl_ioctl(dev, WLC_GET_RADIO, &radio, sizeof(int));
			
			if (wl_get_val(dev, "qtxpower", &(wrqu->txpower.value), sizeof(int)) < 0)
				return -EINVAL;
			
			wrqu->txpower.value &= ~WL_TXPWR_OVERRIDE;
			wrqu->txpower.value /= 4;
				
			wrqu->txpower.fixed = 0;
			wrqu->txpower.disabled = radio;
			wrqu->txpower.flags = IW_TXPOW_DBM;
			break;
		}
		case SIOCSIWTXPOW:
		{
			/* This is weird: WLC_SET_RADIO with 1 as argument disables the radio */
			int radio = wrqu->txpower.disabled;

			wl_ioctl(dev, WLC_SET_RADIO, &radio, sizeof(int));
			
			if (!wrqu->txpower.disabled && (wrqu->txpower.value > 0)) {
				int value;
				
				if (wl_get_val(dev, "qtxpower", &value, sizeof(int)) < 0)
					return -EINVAL;
				
				value &= WL_TXPWR_OVERRIDE;
				wrqu->txpower.value *= 4;
				wrqu->txpower.value |= value;
				
				if (wrqu->txpower.flags != IW_TXPOW_DBM)
					return -EINVAL;
				
				if (wrqu->txpower.value > 0)
					if (wl_set_val(dev, "qtxpower", &(wrqu->txpower.value), sizeof(int)) < 0)
						return -EINVAL;
			}
			break;
		}
		case SIOCSIWENCODE:
		{
			int val = 0, wep = 1, wrestrict = 1;
			int index = (wrqu->data.flags & IW_ENCODE_INDEX) - 1;

			if (index < 0)
				index = get_primary_key(dev);
			
			if (wrqu->data.flags & IW_ENCODE_DISABLED) {
				wep = 0;
				if (wl_ioctl(dev, WLC_SET_WSEC, &wep, sizeof(val)) < 0)
					return -EINVAL;
				return 0;
			}

			if (wl_ioctl(dev, WLC_SET_WSEC, &wep, sizeof(val)) < 0)
				return -EINVAL;

			if (wrqu->data.flags & IW_ENCODE_OPEN)
				wrestrict = 0;
			
			if (wrqu->data.pointer && (wrqu->data.length > 0) && (wrqu->data.length <= 16)) {
				wl_wsec_key_t key;
				memset(&key, 0, sizeof(key));

				key.flags = WL_PRIMARY_KEY;
				key.len = wrqu->data.length;
				key.index = index;
				memcpy(key.data, wrqu->data.pointer, wrqu->data.length);

				if (wl_ioctl(dev, WLC_SET_KEY, &key, sizeof(key)) < 0)
					return -EINVAL;
			}

			if (index >= 0)
				wl_ioctl(dev, WLC_SET_KEY_PRIMARY, &index, sizeof(index));
			
			if (wrestrict >= 0)
				wl_ioctl(dev, WLC_SET_WEP_RESTRICT, &wrestrict, sizeof(wrestrict));

			break;
		}
		case SIOCGIWENCODE:
		{
			int val;
			
			if (wl_ioctl(dev, WLC_GET_WEP, &val, sizeof(val)) < 0)
				return -EINVAL;
			

			if (val > 0) {
				int key = get_primary_key(dev);
				
				wrqu->data.flags = IW_ENCODE_ENABLED;
				if (key-- > 0) {
					int *info_addr; 
					wkey *wep_key;
					
					info_addr = (int *) dev->priv;
					wep_key = (wkey *) ((*info_addr) + 0x2752 + (key * 0x110));
					
					wrqu->data.flags |= key + 1;
					wrqu->data.length = wep_key->len;

					memset(extra, 0, 16);
					memcpy(extra, wep_key->data, 16);
				} else {
					wrqu->data.flags |= IW_ENCODE_NOKEY;
				}
			} else {
				wrqu->data.flags = IW_ENCODE_DISABLED;
			}
			
			break;
		}
		case SIOCGIWRANGE:
		{
			return wlcompat_ioctl_getiwrange(dev, extra);
			break;
		}
		case SIOCSIWMODE:
		{
			int ap = -1, infra = -1, passive = 0, wet = 0;
			
			switch (wrqu->mode) {
				case IW_MODE_MONITOR:
					passive = 1;
					break;
				case IW_MODE_ADHOC:
					infra = 0;
					ap = 0;
					break;
				case IW_MODE_MASTER:
					infra = 1;
					ap = 1;
					break;
				case IW_MODE_INFRA:
					infra = 1;
					ap = 0;
					break;
				case IW_MODE_REPEAT:
					infra = 1;
					ap = 0;
					wet = 1;
					break;
					
				default:
					return -EINVAL;
			}
			
			wl_ioctl(dev, WLC_SET_PASSIVE, &passive, sizeof(passive));
			wl_ioctl(dev, WLC_SET_MONITOR, &passive, sizeof(passive));
			wl_ioctl(dev, WLC_SET_WET, &wet, sizeof(wet));
			if (ap >= 0) 
				wl_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap));
			if (infra >= 0)
				wl_ioctl(dev, WLC_SET_INFRA, &infra, sizeof(infra));

			break;
						
		}
		case SIOCGIWMODE:
		{
			int ap, infra, wet, passive;

			if (wl_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap)) < 0)
				return -EINVAL;
			if (wl_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra)) < 0)
				return -EINVAL;
			if (wl_ioctl(dev, WLC_GET_PASSIVE, &passive, sizeof(passive)) < 0)
				return -EINVAL;
			if (wl_ioctl(dev, WLC_GET_WET, &wet, sizeof(wet)) < 0)
				return -EINVAL;

			if (passive) {
				wrqu->mode = IW_MODE_MONITOR;
			} else if (!infra) {
				wrqu->mode = IW_MODE_ADHOC;
			} else {
				if (ap) {
					wrqu->mode = IW_MODE_MASTER;
				} else {
					if (wet) {
						wrqu->mode = IW_MODE_REPEAT;
					} else {
						wrqu->mode = IW_MODE_INFRA;
					}
				}
			}
			break;
		}
		default:
		{
			if (info->cmd >= SIOCIWFIRSTPRIV)
				return wlcompat_private_ioctl(dev, info, wrqu, extra);

			return -EINVAL;
		}
	}
	
	return 0;
}
Exemple #4
0
static int wlcompat_private_ioctl(struct net_device *dev,
			 struct iw_request_info *info,
			 union iwreq_data *wrqu,
			 char *extra)
{
	int *value = (int *) wrqu->name;

	switch (info->cmd) {
		case WLCOMPAT_SET_MONITOR:
		{
			if (wl_ioctl(dev, WLC_SET_MONITOR, value, sizeof(int)) < 0)
				return -EINVAL;

			break;
		}
		case WLCOMPAT_GET_MONITOR:
		{
			if (wl_ioctl(dev, WLC_GET_MONITOR, extra, sizeof(int)) < 0)
				return -EINVAL;

			break;
		}
		case WLCOMPAT_SET_TXPWR_LIMIT:
		{
			int val;
			

			if (wl_get_val(dev, "qtxpower", &val, sizeof(int)) < 0)
				return -EINVAL;
			
			if (*extra > 0)
				val |= WL_TXPWR_OVERRIDE;
			else
				val &= ~WL_TXPWR_OVERRIDE;
			
			if (wl_set_val(dev, "qtxpower", &val, sizeof(int)) < 0)
				return -EINVAL;
			
			break;
		}
		case WLCOMPAT_GET_TXPWR_LIMIT:
		{
			if (wl_get_val(dev, "qtxpower", value, sizeof(int)) < 0)
				return -EINVAL;

			*value = ((*value & WL_TXPWR_OVERRIDE) == WL_TXPWR_OVERRIDE ? 1 : 0);

			break;
		}
		case WLCOMPAT_SET_ANTDIV:
		{
			if (wl_ioctl(dev, WLC_SET_ANTDIV, value, sizeof(int)) < 0)
				return -EINVAL;

			break;
		}
		case WLCOMPAT_GET_ANTDIV:
		{
			if (wl_ioctl(dev, WLC_GET_ANTDIV, extra, sizeof(int)) < 0)
				return -EINVAL;

			break;
		}
		case WLCOMPAT_SET_TXANT:
		{
			if (wl_ioctl(dev, WLC_SET_TXANT, value, sizeof(int)) < 0)
				return -EINVAL;

			break;
		}
		case WLCOMPAT_GET_TXANT:
		{
			if (wl_ioctl(dev, WLC_GET_TXANT, extra, sizeof(int)) < 0)
				return -EINVAL;

			break;
		}
		default:
		{
			return -EINVAL;
		}
			
	}
	return 0;
}
Exemple #5
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;
}
Exemple #6
0
static int wlcompat_get_scan(struct net_device *dev,
			 struct iw_request_info *info,
			 union iwreq_data *wrqu,
			 char *extra)
{
	wl_scan_results_t *results = (wl_scan_results_t *) buf;
	wl_bss_info_t *bss_info;
	char *info_ptr;
	char *current_ev = extra;
	char *current_val;
	char *end_buf = extra + IW_SCAN_MAX_DATA;
	struct iw_event iwe;
	int i, j;

	if (wl_ioctl(dev, WLC_SCAN_RESULTS, buf, WLC_IOCTL_MAXLEN) < 0)
		return -EAGAIN;
	
	bss_info = &(results->bss_info[0]);
	info_ptr = (char *) bss_info;
	for (i = 0; i < results->count; i++) {

		/* send the cell address (must be sent first) */
		iwe.cmd = SIOCGIWAP;
		iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
		memcpy(&iwe.u.ap_addr.sa_data, &bss_info->BSSID, sizeof(bss_info->BSSID));
		current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
		
		/* send the ESSID */
		iwe.cmd = SIOCGIWESSID;
		iwe.u.data.length = bss_info->SSID_len;
		if (iwe.u.data.length > IW_ESSID_MAX_SIZE)
			iwe.u.data.length = IW_ESSID_MAX_SIZE;
		iwe.u.data.flags = 1;
		current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss_info->SSID);

		/* send frequency/channel info */
		iwe.cmd = SIOCGIWFREQ;
		iwe.u.freq.e = 0;
		iwe.u.freq.m = bss_info->channel;
		current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);

		/* add quality statistics */
		iwe.cmd = IWEVQUAL;
		iwe.u.qual.level = bss_info->RSSI;
		iwe.u.qual.noise = bss_info->phy_noise;
		iwe.u.qual.qual = 0;
		current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
	
		/* send rate information */
		iwe.cmd = SIOCGIWRATE;
		current_val = current_ev + IW_EV_LCP_LEN;
		iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
		
		for(j = 0 ; j < bss_info->rateset.count ; j++) {
			iwe.u.bitrate.value = ((bss_info->rateset.rates[j] & 0x7f) * 500000);
			current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
		}
		if((current_val - current_ev) > IW_EV_LCP_LEN)
			current_ev = current_val;

		info_ptr += sizeof(wl_bss_info_t);
		if (bss_info->ie_length % 4)
			info_ptr += bss_info->ie_length + 4 - (bss_info->ie_length % 4);
		else
			info_ptr += bss_info->ie_length;
		bss_info = (wl_bss_info_t *) info_ptr;
	}
	
	wrqu->data.length = (current_ev - extra);
	wrqu->data.flags = 0;

	return 0;
}
Exemple #7
0
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);
}
Exemple #8
0
static void watchdog(void)
{
	int brand = getRouterBrand();
	int registered = -1;
	int radiostate0 = -1;
	int oldstate0 = -1;
	int radiostate1 = -1;
	int oldstate1 = -1;
	int counter = 0;
	int radioledinitcount = 0;
	int fd = open("/dev/misc/watchdog", O_WRONLY);
	if (fd == -1)
		fd = open("/dev/watchdog", O_WRONLY);

	if (fd == -1) {
		return;
	}
#ifdef HAVE_MADWIFI
	int cnt = getdevicecount();
#else
	int cnt = get_wl_instances();
#endif

	while (1) {
		write(fd, "\0", 1);
		fsync(fd);

#ifdef HAVE_REGISTER
		if (!nvram_match("flash_active", "1")) {
			if (registered == -1)
				registered = isregistered_real();
			if (!registered)
				isregistered();	//to poll
		}
#endif
		/* 
		 * software wlan led control 
		 */
		if (radioledinitcount < 5) {
			radioledinitcount++;
			oldstate0 = -1;
			oldstate1 = -1;
		}
#ifdef HAVE_MADWIFI
		if (!nvram_match("flash_active", "1")) {
			radiostate0 = get_radiostate("ath0");
			if (cnt == 2)
				radiostate1 = get_radiostate("ath1");
		}
#else
		wl_ioctl(get_wl_instance_name(0), WLC_GET_RADIO, &radiostate0, sizeof(int));
		if (cnt == 2)
			wl_ioctl(get_wl_instance_name(1), WLC_GET_RADIO, &radiostate1, sizeof(int));
#endif

		if (radiostate0 != oldstate0) {
#ifdef HAVE_MADWIFI
			if (radiostate0 == 1)
#else
			if ((radiostate0 & WL_RADIO_SW_DISABLE) == 0)
#endif
				led_control(LED_WLAN0, LED_ON);
			else {
				led_control(LED_WLAN0, LED_OFF);
#ifndef HAVE_MADWIFI
				/* 
				 * Disable wireless will cause diag led blink, so we want to
				 * stop it. 
				 */
				if (brand == ROUTER_WRT54G)
					diag_led(DIAG, STOP_LED);
				/* 
				 * Disable wireless will cause power led off, so we want to
				 * turn it on. 
				 */
				if (brand == ROUTER_WRT54G_V8)
					led_control(LED_POWER, LED_ON);
#endif
			}

			oldstate0 = radiostate0;
		}

		if (radiostate1 != oldstate1) {
#ifdef HAVE_MADWIFI
			if (radiostate1 == 1)
#else
			if ((radiostate1 & WL_RADIO_SW_DISABLE) == 0)
#endif
				led_control(LED_WLAN1, LED_ON);
			else {
				led_control(LED_WLAN1, LED_OFF);
			}

			oldstate1 = radiostate1;
		}
		/* 
		 * end software wlan led control 
		 */

		sleep(10);
		if (nvram_match("warn_enabled", "1")) {
			counter++;
			if (!(counter % 60))
				system("notifier&");	// 
		}
	}
}
Exemple #9
0
int
wl_set(void *wl, int cmd, void *buf, int len)
{
	return wl_ioctl(wl, cmd, buf, len, TRUE);
}
Exemple #10
0
int site_survey_main(int argc, char *argv[])
{
	char tmp[32];
	sprintf(tmp, "%s_ifname", nvram_safe_get("wifi_display"));
	char *name = nvram_safe_get(tmp);

	unsigned char buf[10000];
	wl_scan_results_t *scan_res = (wl_scan_results_t *) buf;
	wl_bss_info_t *bss_info;
	unsigned char mac[20];
	int i;
	char *dev = name;

	unlink(SITE_SURVEY_DB);
	int ap = 0, oldap = 0;
	wl_scan_params_t params;

	memset(&params, 0, sizeof(params));

	/*
	 * use defaults (same parameters as wl scan) 
	 */

	memset(&params.bssid, 0xff, sizeof(params.bssid));
	if (argc > 1) {
		params.ssid.SSID_len = strlen(argv[1]);
		strcpy(params.ssid.SSID, argv[1]);
	}
	params.bss_type = DOT11_BSSTYPE_ANY;
	params.scan_type = 0;
	params.nprobes = -1;
	params.active_time = -1;
	params.passive_time = -1;
	params.home_time = -1;
	params.channel_num = 0;

	/*
	 * can only scan in STA mode 
	 */
	if (wl_ioctl(dev, WLC_SCAN, &params, 64) < 0) {
		fprintf(stderr, "scan failed\n");
		return -1;
	}
	int count = 10;
	int ret = 0;
	while ((count--) > 0)	//scan for max 5 seconds
	{
		usleep(500 * 1000);

		bzero(buf, sizeof(buf));
		scan_res->buflen = sizeof(buf);
		ret = wl_ioctl(dev, WLC_SCAN_RESULTS, buf, WLC_IOCTL_MAXLEN);
		if (!ret)
			break;
	}
	if (ret < 0) {
		fprintf(stderr, "scan failed with errorcode %d\n", ret);
	}

	fprintf(stderr, "buflen=[%d] version=[%d] count=[%d]\n", scan_res->buflen, scan_res->version, scan_res->count);

	if (scan_res->count == 0) {
		cprintf("Can't find any wireless device\n");
		goto endss;
	}

	bss_info = &scan_res->bss_info[0];
	for (i = 0; i < scan_res->count; i++) {
		strcpy(site_survey_lists[i].SSID, bss_info->SSID);
		strcpy(site_survey_lists[i].BSSID, ether_etoa(bss_info->BSSID.octet, mac));
#ifndef HAVE_RB500
		site_survey_lists[i].channel = bss_info->chanspec & 0xff;
#endif
		site_survey_lists[i].frequency = ieee80211_ieee2mhz(site_survey_lists[i].channel);
#ifdef WL_CHANSPEC_BW_80
		switch (bss_info->chanspec & 0x3800) {
		case WL_CHANSPEC_BW_80:
			site_survey_lists[i].channel |= 0x1000;
			break;
		case WL_CHANSPEC_BW_8080:
			site_survey_lists[i].channel |= 0x1100;
			break;
		case WL_CHANSPEC_BW_160:
			site_survey_lists[i].channel |= 0x1200;
			break;
		}
#endif

		site_survey_lists[i].RSSI = bss_info->RSSI;
		site_survey_lists[i].phy_noise = bss_info->phy_noise;
		site_survey_lists[i].beacon_period = bss_info->beacon_period;
		site_survey_lists[i].capability = bss_info->capability;
		site_survey_lists[i].rate_count = get_mcs_max(bss_info->basic_mcs);
		if (!site_survey_lists[i].rate_count)
			site_survey_lists[i].rate_count = get_legacy(bss_info->rateset.rates, bss_info->rateset.count);

		site_survey_lists[i].dtim_period = bss_info->dtim_period;
		strcpy(site_survey_lists[i].ENCINFO, getEncInfo(bss_info));

		bss_info = (wl_bss_info_t *) ((uint32) bss_info + bss_info->length);
	}
	write_site_survey();
	open_site_survey();
	// modded by ascott and fractal, may 17th, 2012 to show "hidden" SSIDS
	for (i = 0; i < SITE_SURVEY_NUM && site_survey_lists[i].BSSID[0]; i++) {
		if (site_survey_lists[i].SSID[0] == 0) {
			strcpy(site_survey_lists[i].SSID, "hidden");
		}
		fprintf(stderr,
			"[%2d] SSID[%20s] BSSID[%s] channel[%2d] frequency[%4d] rssi[%d] noise[%d] beacon[%d] cap[%x] dtim[%d] rate[%d] enc[%s]\n",
			i, site_survey_lists[i].SSID,
			site_survey_lists[i].BSSID,
			site_survey_lists[i].channel & 0xff,
			site_survey_lists[i].frequency,
			site_survey_lists[i].RSSI,
			site_survey_lists[i].phy_noise,
			site_survey_lists[i].beacon_period, site_survey_lists[i].capability, site_survey_lists[i].dtim_period, site_survey_lists[i].rate_count, site_survey_lists[i].ENCINFO);
	}

endss:

	C_led(0);
	eval("wl", "-i", name, "up");
	return 0;
}
Exemple #11
0
int
wl_get(void *wl, int cmd, void *buf, int len)
{
	return wl_ioctl(wl, cmd, buf, len, FALSE);
}
Exemple #12
0
		/* 
		 * software wlan led control 
		 */
void softcontrol_wlan_led(void)	// done in watchdog.c for non-micro
					// builds.
{
#if defined(HAVE_MICRO) && !defined(HAVE_ADM5120) && !defined(HAVE_WRK54G)
	int brand;
	int radiostate0 = -1;
	int oldstate0 = -1;
	int radiostate1 = -1;
	int oldstate1 = -1;

#ifdef HAVE_MADWIFI
	int cnt = getdevicecount();
#else
	int cnt = get_wl_instances();
#endif

#ifdef HAVE_MADWIFI
	if (!nvram_match("flash_active", "1")) {
		radiostate0 = get_radiostate("ath0");
		if (cnt == 2)
			radiostate1 = get_radiostate("ath1");
	}
#else
	wl_ioctl(get_wl_instance_name(0), WLC_GET_RADIO, &radiostate0, sizeof(int));
	if (cnt == 2)
		wl_ioctl(get_wl_instance_name(1), WLC_GET_RADIO, &radiostate1, sizeof(int));
#endif

	if (radiostate0 != oldstate0) {
#ifdef HAVE_MADWIFI
		if (radiostate0 == 1)
#else
		if ((radiostate0 & WL_RADIO_SW_DISABLE) == 0)
#endif
			led_control(LED_WLAN0, LED_ON);
		else {
			led_control(LED_WLAN0, LED_OFF);
#ifndef HAVE_MADWIFI
			brand = getRouterBrand();
			/*
			 * Disable wireless will cause diag led blink, so we want to
			 * stop it. 
			 */
			if (brand == ROUTER_WRT54G)
				diag_led(DIAG, STOP_LED);
			/* 
			 * Disable wireless will cause power led off, so we want to
			 * turn it on. 
			 */
			if (brand == ROUTER_WRT54G_V8)
				led_control(LED_POWER, LED_ON);
#endif
		}

		oldstate0 = radiostate0;
	}

	if (radiostate1 != oldstate1) {
#ifdef HAVE_MADWIFI
		if (radiostate1 == 1)
#else
		if ((radiostate1 & WL_RADIO_SW_DISABLE) == 0)
#endif
			led_control(LED_WLAN1, LED_ON);
		else {
			led_control(LED_WLAN1, LED_OFF);
		}

		oldstate1 = radiostate1;
	}
	/* 
	 * end software wlan led control 
	 */
	return;

#endif
}
Exemple #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
}
int wext_get_scanlist(const char *ifname, char *buf, int *len)
{
	//-----------------
	int retval = 0;		//返回值
	int i = 0;			
	int apCount = 0;	// 搜索到的AP数量
	char data[8192];	// *未知
	char ssid_str[256];	// ssid 名字?
	char header[128];	// *未知
	struct iwreq wrq;	// 创建ioctl
	SSA *ssap;			// SITE_SURVEY 数组
	char tmp[128];		// *未知 (好像没用)
	char prefix[] = "wlXXXXXXXXXX_"	// *未知
	memset(data, 0x00, 255);
	strcpy(data, "SiteSurvey=1");	// *应该是发出的指令
	wrq.u.data.length = strlen(data) + 1;
	wrq.u.data.pointer = data;
	wrq.u.data.flags = 0;
	
	if (wl_ioctl(ifname, RTPRIV_IOCTL_SET, &wrq) < 0)	// iwpriv ra0 set SiteSurvey=1
	{
		spinlock_unlock(0);			// 是专为防止多处理器并发而引入的一种锁。
		dbg("Site Survey fails\n");
		return 0;
	}
	
	spinlock_unlock(SPINLOCK_SiteSurvey);	// 是专为防止多处理器并发而引入的一种锁。
	sleep(5);
	
	memset(data, 0, 8192);
	strcpy(data, "");
	wrq.u.data.length = sizeof(data);
	wrq.u.data.pointer = data;
	wrq.u.data.flags = 0;
	if (wl_ioctl(ifname, RTPRIV_IOCTL_GSITESURVEY, &wrq) < 0) // iwpriv ra0 get_site_survey
	{
		dbg("errors in getting site survey result\n");
		return 0;
	}
	memset(header, 0, sizeof(header));
	if (wrq.u.data.length > 0)
	{
		// 这里应该是已经得到了扫描的结果
		ssap=(SSA *)(wrq.u.data.pointer+strlen(header)+1);
		int len = strlen(wrq.u.data.pointer+strlen(header))-1;
		char *sp, *op;
 		op = sp = wrq.u.data.pointer+strlen(header)+1;
		while (*sp && ((len - (sp-op)) >= 0))
		{
			// 这一部分应该是RT-41U 用于显示字符串的部分,应该是可以删除掉这部分代码的吧。
			ssap->SiteSurvey[i].channel[3] = '\0';
			ssap->SiteSurvey[i].ssid[32] = '\0';
			ssap->SiteSurvey[i].bssid[17] = '\0';
			ssap->SiteSurvey[i].encryption[8] = '\0';
			ssap->SiteSurvey[i].authmode[15] = '\0';
			ssap->SiteSurvey[i].signal[8] = '\0';
			ssap->SiteSurvey[i].wmode[7] = '\0';
			sp+=strlen(header);
			apCount=++i;
		}
		
		if (apCount)
		{
			retval += websWrite(wp, "[");
			for (i = 0; i < apCount; i++)
			{
				dbg("%-4s%-33s%-18s%-9s%-16s%-9s%-8s\n",
					ssap->SiteSurvey[i].channel,
					(char*)ssap->SiteSurvey[i].ssid,
					ssap->SiteSurvey[i].bssid,
					ssap->SiteSurvey[i].encryption,
					ssap->SiteSurvey[i].authmode,
					ssap->SiteSurvey[i].signal,
					ssap->SiteSurvey[i].wmode
				);
				
				memset(ssid_str, 0, sizeof(ssid_str));
				char_to_ascii(ssid_str, trim_r(ssap->SiteSurvey[i].ssid));
			}
		}
	}
	//------------------

	return -1;
}
/* Main server module common for all transports
 * This module will do the initial transport setups.
 * Then it receives the command from client in CDC format
 * and transmits the response back to the client.
 * In the case of socket, it receives the command from the client
 * and sends the response directly to the client via TCP socket.
 *
 * In the case of serial & wifi , it receives the command from the driver
 * and sends the response to the driver.
 */
int
remote_server_exec(int argc, char **argv, void *wl)
{
	int err;
	int transport_descriptor;
	char *async_cmd_flag = NULL;
	int skip;
	int download_flag = 0;
#if defined(LINUX) || defined(vxworks) || defined(OLYMPIC_RWL)
	char old_intf_name[IFNAMSIZ];
#endif
#ifdef WIN32
	char shell_fname[MAX_SHELL_FILE_LENGTH];
	DWORD dwlen;
#endif
#ifdef RWL_DONGLE
	int uart_enable = 1;
	/* To set dongle flag when dongle server starts */
	if ((err = rwl_var_setbuf(wl, dongleset, &uart_enable,
		sizeof(int))) < 0) {
			DPRINT_INFO(OUTPUT, "Unable to send to wl driver,error=%d\n", err);
	}
#endif
	if (rwl_iovar_check (wl) < 0) {
		DPRINT_ERR(ERR, "wl_server: RWL_WIFI/RWL_DONGLE not defined ");
		DPRINT_ERR(ERR, "Or In-Dongle mode enabled\n");
		exit(0);
	}
	/* Initialise for all the transports - socket, serial, and wifi
	 * In Socket transport, main socket handler will be returned.
	 */
	if ((transport_descriptor = rwl_transport_setup(argc, argv)) < 0)
		return BCME_ERROR;

#ifdef RWL_WIFI
	remote_wifi_ser_init_cmds(wl);
#endif
	/* Create a directory /tmp/RWL for the shell response files */
	if (rwl_create_dir() < 0)
		return BCME_ERROR;


#ifdef RWLASD
	/* DUT initialization function */
	wfa_dut_init(&trafficBuf, &respBuf, &parmsVal, &xcCmdBuf, &toutvalp);
#endif

#if defined(LINUX) || defined(vxworks)
	/* Copy old interface name to restore it */
	store_old_interface(wl, old_intf_name);
#endif /* defined(LINUX) || defined(vxworks) */

	while (1) {
		uchar *buf_ptr = NULL;
#ifdef VISTA_SERVER
		int index;
		char *vista_buf[MAX_VISTA_ARGC];
#endif
#if defined (RWL_SERIAL) || /*(RWL_WICED_SOCKET)*/ (RWL_SOCKET)
		g_rwl_hndle = transport_descriptor;
#else
		g_rwl_hndle = -1;
#endif
#if defined (RWL_SOCKET)
        /* Close the main handle for serial pipe  */
        if (NULL == rwl_open_pipe(0, argv[0], 0, 0))
        {
            continue;
        }
#endif
#ifdef RWL_DONGLE
		if (set_ctrlc) {
			uart_enable = 0;
			if ((err = rwl_var_setbuf(wl, dongleset, &uart_enable,
				sizeof(int))) < 0) {
				DPRINT_INFO(OUTPUT, "Unable to send to wl driver,error=%d\n", err);
			}
			set_ctrlc = 0;
			exit(0);
		}
#endif /* RWL_DONGLE */

		/* Receive the CDC header */
		if ((remote_rx_header(wl, transport_descriptor)) == BCME_ERROR) {
			DPRINT_DBG(OUTPUT, "\n Waiting for client to transmit command\n");
			continue;
		}

		DPRINT_INFO(OUTPUT, "REC : cmd %d\t msg len %d  msg flag %d\t msg status %d\n",
		            g_rem_ptr->msg.cmd, g_rem_ptr->msg.len,
		            g_rem_ptr->msg.flags, g_rem_ptr->msg.status);

#ifdef RWL_WIFI
		/* send the response to remote if it is findserver cmd, this is specific to wifi */
		if (g_rem_ptr->msg.flags & REMOTE_FINDSERVER_IOCTL) {
			remote_wifi_response(wl);
			continue;
		}
#endif /* RWL_WIFI */

		/*
		 * Allocate buffer only if there is a response message expected.
		 * Some commands such as up/down do not output anything.
		 */
		if (g_rem_ptr->msg.len) {
			if ((buf_ptr = malloc(g_rem_ptr->msg.len)) == NULL) {
				DPRINT_ERR(ERR, "malloc of %d bytes failed\n", g_rem_ptr->msg.len);
				continue;
			}
		}

		/* Receive the data */
		if ((err = remote_rx_data(buf_ptr)) == BCME_ERROR) {
			if (buf_ptr)
				free(buf_ptr);
			continue;
		}

		/* Process RWL negotiate commands */
		if (g_rem_ptr->msg.flags & REMOTE_NEGOTIATE_CMD) {
			if (g_rem_ptr->msg.cmd == NEGOTIATE_GET_OS) {
				if (g_rem_ptr->msg.len >= sizeof(int)) {
#if defined(LINUX)
					*(int*)buf_ptr = LINUX_OS;
#elif defined(VISTA_SERVER)
					*(int*)buf_ptr = WINVISTA_OS;
#elif defined(WIN32)
					*(int*)buf_ptr = WIN32_OS;
#elif defined(MACOSX)
					*(int*)buf_ptr = MAC_OSX;
#else
					*(int*)buf_ptr = UNKNOWN_OS;
#endif
					g_rem_ptr->msg.len = sizeof(int);

					DPRINT_INFO(OUTPUT, "RESP : os type %d\n", *(int*)buf_ptr);
					if (remote_tx_response(wl, buf_ptr, 0) < 0)
						DPRINT_ERR(ERR, "\nReturn results failed\n");
				}
			}
#ifdef RWL_SOCKET
			close_sock_handle(g_rwl_hndle);
#endif /* RWL_SOCKET */
			if (buf_ptr)
				free(buf_ptr);
			continue;
		}

		/* Process command */
		if (g_rem_ptr->msg.flags & REMOTE_SHELL_CMD) {
			/* Get the response length first and get the response buffer in case of
			 * synchronous shell commands and the buf_ptr will have the response file
			 * name. In case of asynchronous shell commands, buf_ptr
			 * will be get updated by the remote_shell_execute function.
			 */
			need_speedy_response = 1;
#ifndef WIN32
			if (buf_ptr) {
				async_cmd_flag = strstr((char*)buf_ptr, "%");
			}
			if ((err = remote_shell_execute((char*)buf_ptr, wl)) > 0) {
				if (async_cmd_flag)
					g_rem_ptr->msg.len = err;
			}
			/* Sync shell command: No need to send response from here */
			else {
#ifdef RWL_SOCKET
				/* Transmitted to client. Then close the handle &
				 * get the new handle for next transmission & reception.
				 */
				close_sock_handle(g_rwl_hndle);
#endif /* RWL_SOCKET */
				continue;
			}
#else
			if ((err = remote_shell_execute((char*)buf_ptr, wl)) != SUCCESS) {
				DPRINT_ERR(ERR, "Error in executing shell command\n");
				if (buf_ptr)
					free(buf_ptr);
#ifdef RWL_SOCKET
				/* Transmitted to client. Then close the handle &
				 * get the new handle for next transmission & reception.
				 */
				close_sock_handle(g_rwl_hndle);
#endif /* RWL_SOCKET */
				continue;
			}
			/* Get the response from the temporary file */
			if ((err = remote_shell_get_resp(shell_fname, wl)) != SUCCESS) {
				DPRINT_ERR(ERR, "Error in executing shell command\n");
			}
			if (buf_ptr)
				free(buf_ptr);
#ifdef RWL_SOCKET
			/* Transmitted to client. Then close the handle &
			 * get the new handle for next transmission & reception.
			 */
			close_sock_handle(g_rwl_hndle);
#endif /* RWL_SOCKET */
			continue;
#endif	/* WIN32 */
		} /* REMOTE_SHELL_CMD */

#ifdef RWLASD
		if (g_rem_ptr->msg.flags & REMOTE_ASD_CMD) {
			if ((err = remote_asd_exec(buf_ptr, (int *)&g_rem_ptr->msg.len)) < 0) {
				DPRINT_ERR(ERR, "Error in executing asd command\n");
			}
		} /* REMOTE_ASD_CMD */
#endif

/*
 * added to take care of OID base problem for cross OS RWL cleint server
 * In case of LX Server and WIN32 client OID base need to be removed
 * In case of WIN32 server and LX client OID base need to be added
 */
		if (!(g_rem_ptr->msg.flags & REMOTE_ASD_CMD)) {
#if defined(LINUX) || defined(vxworks)
		if (g_rem_ptr->msg.cmd > MAX_IOVAR)
			g_rem_ptr->msg.cmd -= WL_OID_BASE;
#endif
#if defined(WIN32)
		if (g_rem_ptr->msg.cmd < MAX_IOVAR)
			g_rem_ptr->msg.cmd += WL_OID_BASE;
#endif
		}
#ifdef VISTA_SERVER
		if (g_rem_ptr->msg.flags & REMOTE_VISTA_CMD) {
			vista_buf[0] = strtok(buf_ptr, " \t\n");
			for (index = 1; (vista_buf[index] = strtok(NULL, " \t\n")) != NULL;
				index++);
			if ((err = remote_vista_exec(wl, vista_buf)) < 0) {
				DPRINT_ERR(ERR, "Error in executing vista command\n");
			}
			memcpy(buf_ptr, vista_buf[0], strlen(vista_buf[0]));
			g_rem_ptr->msg.len = strlen(vista_buf[0]);
		} /* REMOTE_VISTA_CMD */
#endif /* VISTA_SERVER */

#ifndef OLYMPIC_RWL
#if defined(LINUX) || defined(vxworks)
#ifndef RWL_DONGLE
		if (g_rem_ptr->msg.flags & REMOTE_GET_IOCTL ||
			g_rem_ptr->msg.flags & REMOTE_SET_IOCTL) {
			if (strlen(g_rem_ptr->intf_name) != 0) {
#if defined(LINUX)
				struct ifreq ifr;
				/* validate the interface */
				memset(&ifr, 0, sizeof(ifr));
				if (g_rem_ptr->intf_name)
					strncpy(ifr.ifr_name, g_rem_ptr->intf_name, IFNAMSIZ);

				if (wl_check((void *)&ifr)) {
					DPRINT_ERR(ERR, "%s: wl driver adapter not found\n",
						g_rem_ptr->intf_name);
					/* Signal end of command output */
					g_rem_ptr->msg.len = 0;
					remote_tx_response(wl, NULL, BCME_NODEVICE);
					if (buf_ptr)
						free(buf_ptr);
#ifdef RWL_SOCKET
					close_sock_handle(g_rwl_hndle);
#endif
					continue;
				}
#endif /* LINUX */
#if defined(vxworks)
				if (wl_check((void *)g_rem_ptr->intf_name)) {
					DPRINT_ERR(ERR, "%s: wl driver adapter not found\n",
						g_rem_ptr->intf_name);
					/* Signal end of command output */
					g_rem_ptr->msg.len = 0;
					remote_tx_response(wl, NULL, BCME_NODEVICE);
					if (buf_ptr)
						free(buf_ptr);
#ifdef RWL_SOCKET
					close_sock_handle(g_rwl_hndle);
#endif
					continue;
				}
#endif /* vxworks */

				if (set_interface(wl, g_rem_ptr->intf_name) == BCME_OK)
					DPRINT_DBG(OUTPUT, "\n %s Interface will be used \n",
						(char *)wl);
			}
		}
#endif /* ifndef RWL_DONGLE */
#endif /* defined(LINUX) || defined(vxworks) */
#endif /* ifndef OLYMPIC_RWL */
		if (g_rem_ptr->msg.flags & REMOTE_SET_IOCTL ||
			g_rem_ptr->msg.flags & RDHD_SET_IOCTL) {
#ifdef WIN32
#if defined (RWL_DONGLE) || defined (RWL_WIFI)
			/* For commands with msg length as zero initialize the buffer to null */
			if (g_rem_ptr->msg.len == 0)
				buf_ptr = NULL;
#endif
#else
			if (g_rem_ptr->msg.len == 0)
				buf_ptr = NULL;
#endif /* WIN32 */

#if defined(LINUX) || defined(TARGETOS_symbian) || defined(TARGETOS_nucleus) || defined(MACOSX) || defined(TARGET_wiced)
#ifdef OLYMPIC_RWL
			set_interface(wl, old_intf_name);
#endif
#if defined( TARGET_wiced )
		    set_interface(wl, g_rem_ptr->intf_name);
#endif
			if (g_rem_ptr->msg.flags & REMOTE_SET_IOCTL) {
				if (g_rem_ptr->msg.cmd == WLC_SET_VAR && buf_ptr &&
				    !strncmp((const char *)buf_ptr,
					     "init", g_rem_ptr->msg.len)) {
					DPRINT_INFO(OUTPUT, "REC : init command\n");
					err = 0;
				} else if (g_rem_ptr->msg.cmd == WLC_SET_VAR && buf_ptr &&
				   !strncmp((const char *)buf_ptr,
					    "download", g_rem_ptr->msg.len)) {
					DPRINT_INFO(OUTPUT, "REC : download command\n");
					download_flag =  download_flag? 0: 1;
					if (download_flag) {
						DPRINT_INFO(OUTPUT, "download started\n");
						start_download( );
					} else {
						DPRINT_INFO(OUTPUT, "download completed\n");
						finish_download( );
					}
					err = 0;
				} else if (g_rem_ptr->msg.cmd == WLC_SET_VAR && buf_ptr &&
					!strncmp((const char *)buf_ptr,
						"membytes", g_rem_ptr->msg.len)) {
					DPRINT_INFO(OUTPUT, "REC : membytes command\n");
					skip = strlen("membytes ");
					uint32_t address = *((uint32_t*)(buf_ptr + skip));
					skip += sizeof(uint32_t);
                    uint32_t len = *((uint32_t*)(buf_ptr + skip));
                    skip += sizeof(uint32_t);
                    if ( len != g_rem_ptr->msg.len - skip )
                    {
                        DPRINT_ERR(ERR, "Length does not match\n");
                    }
					membytes_write( address, buf_ptr + skip, g_rem_ptr->msg.len - skip );
					err = 0;
				} else {

					err = wl_ioctl(wl, g_rem_ptr->msg.cmd,
					       (void *)buf_ptr, g_rem_ptr->msg.len, TRUE);
					DPRINT_INFO(OUTPUT, "SEND : cmd %d\t msg len %d\n",
					    g_rem_ptr->msg.cmd, g_rem_ptr->msg.len);
					DPRINT_INFO(OUTPUT, "error code: %d\n", err);
				}
			}
#if defined(LINUX)
			if (err == BCME_IOCTL_ERROR) {
				if (rwl_var_getbuf(wl, "bcmerrorstr", NULL, 0, (void**)&errstr)) {
					DPRINT_ERR(ERR, "Error in executing wl_ioctl\r\n");
				} else {
					DPRINT_ERR(ERR, "%s\n", errstr);
				}
				DPRINT_ERR(ERR, "Setting Default Interface1 \n");
				set_interface(wl, old_intf_name);
			}

			if (g_rem_ptr->msg.flags & RDHD_SET_IOCTL) {
				err = dhd_ioctl(wl, g_rem_ptr->msg.cmd,
				(void *)buf_ptr, g_rem_ptr->msg.len, TRUE);
			}
#endif /* LINUX */

#elif vxworks
			if ((err = wl_ioctl_vx(wl, g_rem_ptr->msg.cmd, (void *)buf_ptr,
				g_rem_ptr->msg.len)) != 0) {
				DPRINT_ERR(ERR, "Error in executing wl_ioctl_vx\n");
			}

			if (err == BCME_IOCTL_ERROR) {
				DPRINT_ERR(ERR, "Error in executing wl_ioctl\n");
				DPRINT_ERR(ERR, "Setting Default Interface \n");
				set_interface(wl, old_intf_name);
			}
#elif WIN32
			dwlen = g_rem_ptr->msg.len;
			if (g_rem_ptr->msg.flags & RDHD_SET_IOCTL) {
				g_rem_ptr->msg.cmd = g_rem_ptr->msg.cmd
					- WL_OID_BASE + OID_DHD_IOCTLS;
			}

			err = (int)ir_setinformation(wl, g_rem_ptr->msg.cmd,
			                       buf_ptr, &dwlen);
#endif /* LINUX TARGETOS_symbian MACOSX */
			g_rem_ptr->msg.flags = REMOTE_SET_IOCTL;

		} /* RDHD/REMOTE_SET_IOCTL */

		if (g_rem_ptr->msg.flags & REMOTE_GET_IOCTL ||
			g_rem_ptr->msg.flags & RDHD_GET_IOCTL) {
#if defined(LINUX) || defined(TARGETOS_symbian) || defined(TARGETOS_nucleus) || defined(MACOSX) || defined(TARGET_wiced)
			if (g_rem_ptr->msg.cmd == WLC_GET_VAR && buf_ptr &&
				strncmp((const char *)buf_ptr, "exit", g_rem_ptr->msg.len) == 0) {
					/* exit command from remote client terminates server */
					free(buf_ptr);
					break;
			}
#if defined( TARGET_wiced )
            set_interface(wl, g_rem_ptr->intf_name);
#endif
			if (g_rem_ptr->msg.flags & REMOTE_GET_IOCTL)
				err = wl_ioctl(wl, g_rem_ptr->msg.cmd, (void *)buf_ptr,
					g_rem_ptr->msg.len, FALSE);
#if defined (LINUX)
			if (err == BCME_IOCTL_ERROR) {
				if (rwl_var_getbuf(wl, "bcmerrorstr", NULL, 0, (void**)&errstr)) {
					DPRINT_ERR(ERR,
						"REMOTE_GET_IOCTL::Error in executing wl_ioctl\n");
				} else {
					DPRINT_ERR(ERR, "%s\n", errstr);
				}
				DPRINT_ERR(ERR, "Setting Default Interface \n");
				set_interface(wl, old_intf_name);
			}

			if (g_rem_ptr->msg.flags & RDHD_GET_IOCTL)
				err = dhd_ioctl(wl, g_rem_ptr->msg.cmd, (void *)buf_ptr,
					g_rem_ptr->msg.len, FALSE);
#endif /* LINUX */
#elif vxworks
			if ((err = wl_ioctl_vx(wl, g_rem_ptr->msg.cmd, (void *)buf_ptr,
				g_rem_ptr->msg.len)) != 0) {
				DPRINT_ERR(ERR, "Error in executing wl_ioctl_vx\n");
			}

			if (err == BCME_IOCTL_ERROR) {
				DPRINT_ERR(ERR, "Error in executing wl_ioctl_vx\n");
				DPRINT_ERR(ERR, "Setting Default Interface \n");
				set_interface(wl, old_intf_name);
			}
#elif WIN32
			if (g_rem_ptr->msg.cmd == (WL_OID_BASE + WLC_GET_VAR) &&
				strncmp(buf_ptr, "exit", g_rem_ptr->msg.len) == 0) {
					/* exit command from remote client terminates server */
					if (buf_ptr) {
						free(buf_ptr);
					}
					break;
			}

			dwlen = g_rem_ptr->msg.len;
			if (g_rem_ptr->msg.flags & RDHD_GET_IOCTL) {
				g_rem_ptr->msg.cmd = g_rem_ptr->msg.cmd -
					WL_OID_BASE + OID_DHD_IOCTLS;
				}

			err = (int)ir_queryinformation(wl,
			g_rem_ptr->msg.cmd, buf_ptr, &dwlen);

#endif /* defined(LINUX) || defined(TARGETOS_symbian) || defined(TARGETOS_nucleus) */
			g_rem_ptr->msg.flags = REMOTE_GET_IOCTL;
		} /* REMOTE_GET_IOCTL */
		DPRINT_INFO(OUTPUT, "RESP : cmd %d\t msg len %d\n",
		g_rem_ptr->msg.cmd, g_rem_ptr->msg.len);
#if defined(LINUX) || defined(vxworks)
		/* setting back default interface  */
		set_interface(wl, old_intf_name);
#endif /*  defined(LINUX) || defined(vxworks) */
		/* Transmit the response results */

		if (0 == err)
		{
		    if (remote_tx_response(wl, buf_ptr, err) < 0)
		    {
		       DPRINT_ERR(ERR, "\nReturn results failed\n");
		    }
		}

#ifdef RWL_SOCKET
		if (g_rem_ptr->msg.flags != REMOTE_SHELL_CMD)
		/* Transmitted to client. Then close the handle & get the new handle
		 * for next transmission & reception. In case of shell commands this
		 * should be closed in respective shellproc files.
		 */
		close_sock_handle(g_rwl_hndle);
#endif /* RWL_SOCKET */

		if (buf_ptr)
		{
			free(buf_ptr);
		}
	} /* end of while */
#if defined (RWL_SOCKET)
	/* Close the main handle for socket */
	close_sock_handle(transport_descriptor);
#endif
#if defined(RWL_SERIAL) /*|| defined (RWL_WICED_SOCKET)*/
	/* Close the main handle for serial pipe  */
	rwl_close_pipe(remote_type, (void*)&transport_descriptor);
#endif

#ifdef RWLASD
	wfa_dut_deinit();
#endif

	return err;
}
Exemple #16
0
static int get_wl_clients(int idx, int unit, int subunit, void *param)
{
	char *comma = param;
	int i;
	char *p;
	char buf[32];
#if 1
	char *wlif;
	scb_val_t rssi;
	sta_info_t sti;
	int cmd;
	struct maclist *mlist;
	int mlsize;
	char ifname[16];

	mlsize = sizeof(struct maclist) + (255 * sizeof(struct ether_addr));
	if ((mlist = malloc(mlsize)) != NULL) {
//		wlif = nvram_safe_get(wl_nvname("ifname", unit, 0));
		wlif = nvram_safe_get(wl_nvname("ifname", unit, subunit)); // AB multiSSID
		cmd = WLC_GET_ASSOCLIST;
		while (1) {
			mlist->count = 255;
			if (wl_ioctl(wlif, cmd, mlist, mlsize) == 0) {
				for (i = 0; i < mlist->count; ++i) {
					rssi.ea = mlist->ea[i];
					rssi.val = 0;
					if (wl_ioctl(wlif, WLC_GET_RSSI, &rssi, sizeof(rssi)) != 0) continue;

					// sta_info0<mac>
					memset(&sti, 0, sizeof(sti));
					strcpy((char *)&sti, "sta_info");
					memcpy((char *)&sti + 9, rssi.ea.octet, 6);
					if (wl_ioctl(wlif, WLC_GET_VAR, &sti, sizeof(sti)) != 0) continue;

					p = wlif;
					if (sti.flags & WL_STA_WDS) {
						if (cmd != WLC_GET_WDSLIST) continue;
						if ((sti.flags & WL_WDS_LINKUP) == 0) continue;
						if (get_wds_ifname(&rssi.ea, ifname)) p = ifname;
					}

					web_printf("%c['%s','%s',%d,%u,%u,%u,%d]",
						*comma,
						p,
						ether_etoa(rssi.ea.octet, buf),
						rssi.val,
						sti.tx_rate, sti.rx_rate, sti.in, unit);
					*comma = ',';
				}
			}
			if (cmd == WLC_GET_WDSLIST) break;
			cmd = WLC_GET_WDSLIST;
		}
		free(mlist);
	}
#else
	char *wlif;
	scb_val_t rssi;
	sta_info_t sti;
	int j;
	struct maclist *mlist;
	int mlsize;
	char ifname[16];

	mlsize = sizeof(struct maclist) + (127 * sizeof(struct ether_addr));
	if ((mlist = malloc(mlsize)) != NULL) {
		for (j = 0; j < 2; ++j) {
			wlif = nvram_safe_get("wl0_ifname");
			strcpy((char *)mlist, j ? "autho_sta_list" : "authe_sta_list");
			if (wl_ioctl(wlif, WLC_GET_VAR, mlist, mlsize) == 0) {
				for (i = 0; i < mlist->count; ++i) {
					rssi.ea = mlist->ea[i];
					rssi.val = 0;
					if (wl_ioctl(wlif, WLC_GET_RSSI, &rssi, sizeof(rssi)) != 0) continue;

					// sta_info0<mac>
					memset(&sti, 0, sizeof(sti));
					strcpy((char *)&sti, "sta_info");
					memcpy((char *)&sti + 9, rssi.ea.octet, 6);
					if (wl_ioctl(wlif, WLC_GET_VAR, &sti, sizeof(sti)) != 0) continue;

					p = wlif;
					if (sti.flags & WL_STA_WDS) {
						if ((sti.flags & WL_WDS_LINKUP) == 0) continue;
						if (get_wds_ifname(&rssi.ea, ifname)) p = ifname;
					}

					web_printf("%c['%s','%s',%d]",
						*comma,
						p,
						ether_etoa(rssi.ea.octet, buf),
						rssi.val);
					*comma = ',';
				}
			}
		}
		free(mlist);
	}
#endif

	return 0;
}
Exemple #17
0
static int
build_ifnames(char *type, char *names, int *size)
{
	char name[32], *next;
	int len = 0;
	int s;

	/* open a raw scoket for ioctl */
	if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
       		return -1;

	/*
	 * go thru all device names (wl<N> il<N> et<N> vlan<N>) and interfaces to 
	 * build an interface name list in which each i/f name coresponds to a device
	 * name in device name list. Interface/device name matching rule is device
	 * type dependant:
	 *
	 *	wl:	by unit # provided by the driver, for example, if eth1 is wireless
	 *		i/f and its unit # is 0, then it will be in the i/f name list if
	 *		wl0 is in the device name list.
	 *	il/et:	by mac address, for example, if et0's mac address is identical to
	 *		that of eth2's, then eth2 will be in the i/f name list if et0 is 
	 *		in the device name list.
	 *	vlan:	by name, for example, vlan0 will be in the i/f name list if vlan0
	 *		is in the device name list.
	 */
	foreach (name, type, next) {
		struct ifreq ifr;
		int i, unit;
		char var[32], *mac, ea[ETHER_ADDR_LEN];
		
		/* vlan: add it to interface name list */
		if (!strncmp(name, "vlan", 4)) {
			/* append interface name to list */
			len += snprintf(&names[len], *size - len, "%s ", name);
			continue;
		}

		/* others: proceed only when rules are met */
		for (i = 1; i <= DEV_NUMIFS; i ++) {
			/* ignore i/f that is not ethernet */
			ifr.ifr_ifindex = i;
			if (ioctl(s, SIOCGIFNAME, &ifr))
				continue;
			if (ioctl(s, SIOCGIFHWADDR, &ifr))
				continue;
			if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER)
				continue;
			if (!strncmp(ifr.ifr_name, "vlan", 4))
				continue;
			/* wl: use unit # to identify wl */
			if (!strncmp(name, "wl", 2)) {
				if (wl_probe(ifr.ifr_name) ||
				    wl_ioctl(ifr.ifr_name, WLC_GET_INSTANCE, &unit, sizeof(unit)) ||
				    unit != atoi(&name[2]))
					continue;
			}
			/* et/il: use mac addr to identify et/il */
			else if (!strncmp(name, "et", 2) || !strncmp(name, "il", 2)) {
				snprintf(var, sizeof(var), "%smacaddr", name);
				if (!(mac = nvram_get(var)) || !ether_atoe(mac, ea) ||
				    memcmp(ea, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN))
					continue;

				// add by Chen-I to filter out wl interface here
				if (!wl_probe(ifr.ifr_name))
					continue;

			}
			/* mac address: compare value */
			else if (ether_atoe(name, ea) && !memcmp(ea, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN))
				;
			/* others: ignore */
			else
				continue;

			/* append interface name to list */
			len += snprintf(&names[len], *size - len, "%s ", ifr.ifr_name);
		}
	}
	
	close(s);

	*size = len;
	return 0;
}	
Exemple #18
0
int wl_get_channel(const char *ifname, int *buf)
{
	return wl_ioctl(ifname, WLC_GET_CHANNEL, buf, sizeof(buf));
}
Exemple #19
0
void reloadConfig()
{
	FILE *cnf;
	wiviz_cfg *cfg = global_cfg;
	char filebuffer[512];
	char *fbptr, *p, *v, *vv;
	int fblen, val;
	int hopCfgChanged = 0;
	int newHopSeq[12];
	int newHopSeqLen = 0;

	printf("Loading config file\n");

	cnf = fopen("/tmp/wiviz2-cfg", "r");
	if (!cnf) {
		printf("Wiviz: No config file (/tmp/wiviz2-cfg) present, using defaults\n");
		return;
	}

	fblen = fread(filebuffer, 1, 512, cnf);
	fclose(cnf);
	if (fblen >= 512) {
		printf("Error reading config file\n");
		return;
	}
	filebuffer[fblen] = 0;
	printf("Read %i bytes from config file\n", fblen);

	fbptr = filebuffer;

	while (fbptr < filebuffer + fblen && *fbptr != 0) {
		p = fbptr;
		//Find end of parameter
		for (; *fbptr != '=' && *fbptr != 0; fbptr++) ;
		*fbptr = 0;
		v = ++fbptr;
		//Find end of value
		for (; *fbptr != '&' && *fbptr != 0; fbptr++) ;
		*(fbptr++) = 0;
		printf("Config: %s=%s\n", p, v);
		//Apply configuration
		if (!strcmp(p, "channelsel")) {
			//Channel selector
			cfg->channelHopping = 0;
			if (!strcmp(v, "hop")) {
				//Set channel hopping
				cfg->channelHopping = 1;
				hopCfgChanged = 1;
			} else if (!strcmp(v, "nochange")) {
				//Don't change anything, read channel from wireless card
				readWL(cfg);
			} else {
				val = atoi(v);
				if (val < 0 || val > 254) {
					printf("Channel setting in config file invalid (%i)\n", cfg->curChannel);
				} else {
					cfg->curChannel = val;
					if (cfg->readFromWl) {
#ifdef HAVE_MADWIFI
						set_channel(wl_dev, cfg->curChannel);
//          sysprintf("iwconfig %s channel %d\n",wl_dev,cfg->curChannel);
#elif HAVE_RT2880
						sysprintf("iwpriv ra0 set Channel=%d", cfg->curChannel);
#else
						if (wl_ioctl(wl_dev, WLC_SET_CHANNEL, &cfg->curChannel, 4) < 0) {
							printf("Channel set to %i failed\n", cfg->curChannel);
						}
#endif
					} else {
						printf("Can't set channel, no Broadcom wireless device present\n");
					}
				}
			}
		}
		if (!strcmp(p, "hopdwell")) {
			val = atoi(v);
			if (val < 100)
				val = 100;
			if (val > 30000)
				val = 30000;
			if (cfg->channelDwellTime != val)
				hopCfgChanged = 1;
			cfg->channelDwellTime = val;
		}
		if (!strcmp(p, "hopseq")) {
			cfg->channelHopSeqLen = 0;
			while (v < fbptr) {
				for (vv = v; *vv != ',' && *vv != 0; vv++) ;
				if (*vv == 0) {
					cfg->channelHopSeq[cfg->channelHopSeqLen++] = atoi(v);
					break;
				}
				*vv = 0;
				cfg->channelHopSeq[cfg->channelHopSeqLen++] = atoi(v);
				v = vv + 1;
			}
		}
		/*
		   if (!strcmp(p, "")) {
		   }
		 */
	}
	//Apply channel hopper settings
	if (cfg->channelHopping == 0 && cfg->channelHopperPID) {
		kill(cfg->channelHopperPID, SIGKILL);
		cfg->channelHopperPID = 0;
	}
	if (cfg->channelHopping == 1 && hopCfgChanged) {
		if (cfg->channelHopperPID)
			kill(cfg->channelHopperPID, SIGKILL);
		if ((cfg->channelHopperPID = fork()) == 0) {
			channelHopper(cfg);
		}
	}
}