コード例 #1
0
int madwifi_get_scanlist(const char *ifname, char *buf, int *len)
{
	int ret;
	char *res;
	DIR *proc;
	struct dirent *e;

	ret = -1;

	/* We got a wifiX device passed, try to lookup a vap on it */
	if( madwifi_iswifi(ifname) )
	{
		if( (proc = opendir("/proc/sys/net/")) != NULL )
		{
			while( (e = readdir(proc)) != NULL )
			{
				if( !!madwifi_isvap(e->d_name, ifname) )
				{
					if( iwinfo_ifup(e->d_name) )
					{
						ret = wext_get_scanlist(e->d_name, buf, len);
						break;
					}
				}
			}

			closedir(proc);
		}

		/* Still nothing found, try to create a vap */
		if( ret == -1 )
		{
			if( (res = madwifi_ifadd(ifname)) != NULL )
			{
				if( iwinfo_ifup(res) )
				{
					wext_get_scanlist(res, buf, len);
					sleep(1);

					wext_get_scanlist(res, buf, len);
					sleep(1);

					ret = wext_get_scanlist(res, buf, len);
				}

				iwinfo_ifdown(res);
				madwifi_ifdel(res);
			}
		}
	}

	/* Got athX device? */
	else if( !!madwifi_isvap(ifname, NULL) )
	{
		ret = wext_get_scanlist(ifname, buf, len);
	}

	return ret;
}
コード例 #2
0
int madwifi_get_freqlist(const char *ifname, char *buf, int *len)
{
	int i, bl;
	int rc = -1;
	char *res;
	struct ieee80211req_chaninfo chans;
	struct iwinfo_freqlist_entry entry;

	/* A wifiX device? */
	if( madwifi_iswifi(ifname) )
	{
		if( (res = madwifi_ifadd(ifname)) != NULL )
		{
			rc = get80211priv(res, IEEE80211_IOCTL_GETCHANINFO,
							  &chans, sizeof(chans));

			madwifi_ifdel(res);
		}
	}

	/* Its an athX ... */
	else if( !!madwifi_isvap(ifname, NULL) )
	{
		rc = get80211priv(ifname, IEEE80211_IOCTL_GETCHANINFO,
						  &chans, sizeof(chans));
	}


	/* Got chaninfo? */
	if( rc >= 0 )
	{
		bl = 0;

		for( i = 0; i < chans.ic_nchans; i++ )
		{
			entry.mhz        = chans.ic_chans[i].ic_freq;
			entry.channel    = chans.ic_chans[i].ic_ieee;
			entry.restricted = 0;

			memcpy(&buf[bl], &entry, sizeof(struct iwinfo_freqlist_entry));
			bl += sizeof(struct iwinfo_freqlist_entry);
		}

		*len = bl;
		return 0;
	}

	return -1;
}
コード例 #3
0
ファイル: iwinfo_madwifi.c プロジェクト: fededim/openwrt-witi
static int madwifi_get_phyname(const char *ifname, char *buf)
{
	const char *wifidev;

	wifidev = madwifi_isvap(ifname, NULL);

	if (wifidev)
	{
		strcpy(buf, wifidev);
		return 0;
	}
	else if (madwifi_iswifi(ifname))
	{
		strcpy(buf, madwifi_phyname(ifname));
		return 0;
	}

	return -1;
}
コード例 #4
0
int madwifi_get_txpwrlist(const char *ifname, char *buf, int *len)
{
	int rc = -1;
	char *res;

	/* A wifiX device? */
	if( madwifi_iswifi(ifname) )
	{
		if( (res = madwifi_ifadd(ifname)) != NULL )
		{
			rc = wext_get_txpwrlist(res, buf, len);
			madwifi_ifdel(res);
		}
	}

	/* Its an athX ... */
	else if( !!madwifi_isvap(ifname, NULL) )
	{
		rc = wext_get_txpwrlist(ifname, buf, len);
	}

	return rc;
}
コード例 #5
0
int madwifi_get_country(const char *ifname, char *buf)
{
	int i, fd, ccode = -1;
	char buffer[34];
	char *wifi = madwifi_iswifi(ifname)
		? (char *)ifname : madwifi_isvap(ifname, NULL);

	struct ISO3166_to_CCode *e;

	if( wifi )
	{
		snprintf(buffer, sizeof(buffer), "/proc/sys/dev/%s/countrycode", wifi);

		if( (fd = open(buffer, O_RDONLY)) > -1 )
		{
			memset(buffer, 0, sizeof(buffer));

			if( read(fd, buffer, sizeof(buffer)-1) > 0 )
				ccode = atoi(buffer);

			close(fd);
		}
	}

	for( i = 0; i < (sizeof(CountryCodes)/sizeof(CountryCodes[0])); i++ )
	{
		e = &CountryCodes[i];

		if( e->ccode == ccode )
		{
			sprintf(buf, "%c%c", e->iso3166 / 256, e->iso3166 % 256);
			return 0;
		}
	}

	return -1;
}
コード例 #6
0
ファイル: iwinfo_madwifi.c プロジェクト: fededim/openwrt-witi
static char * madwifi_ifadd(const char *ifname)
{
	const char *wifidev = NULL;
	struct ifreq ifr = { 0 };
	struct ieee80211_clone_params cp = { 0 };
	static char nif[IFNAMSIZ] = { 0 };

	if( !(wifidev = madwifi_isvap(ifname, NULL)) && madwifi_iswifi(ifname) )
		wifidev = madwifi_phyname(ifname);

	if( wifidev )
	{
		snprintf(nif, sizeof(nif), "tmp.%s", ifname);

		strncpy(cp.icp_name, nif, IFNAMSIZ);
		cp.icp_opmode = IEEE80211_M_STA;
		cp.icp_flags  = IEEE80211_CLONE_BSSID;

		strncpy(ifr.ifr_name, wifidev, IFNAMSIZ);
		ifr.ifr_data  = (void *)&cp;

		if( !iwinfo_ioctl(SIOC80211IFCREATE, &ifr) )
		{
			return nif;
		}
		else
		{
			cp.icp_opmode = IEEE80211_M_MONITOR;

			if( !iwinfo_ioctl(SIOC80211IFCREATE, &ifr) )
				return nif;
		}
	}

	return NULL;
}
コード例 #7
0
ファイル: iwinfo_madwifi.c プロジェクト: fededim/openwrt-witi
static int madwifi_probe(const char *ifname)
{
	return ( !!madwifi_isvap(ifname, NULL) || madwifi_iswifi(ifname) );
}