File:  [ELWIX - Embedded LightWeight unIX -] / embedtools / src / vap.c
Revision 1.1.2.2: download - view: text, annotated - select for diffs - revision graph
Wed Oct 27 16:04:52 2010 UTC (14 years ago) by misho
Branches: tools1_0
add some wifi api

#include "global.h"
#include "dwds.h"


inline int
wifi_getParent(const char *csVAP, char *psParent, size_t plen)
{
	char szOID[STRSIZ] = { 0 };

	FTRACE(5);

	assert(csVAP);
	assert(psParent);

	memset(psParent, 0, plen);
	snprintf(szOID, STRSIZ, "net.wlan.%s.%%parent", csVAP + 4);
	if (sysctlbyname(szOID, psParent, &plen, NULL, 0) == -1) {
		syslog(LOG_ERR, "Error:: can`t get parent #%d - %s\n", errno, strerror(errno));
		return -1;
	} else
		psParent[plen] = 0;

	return 0;
}

inline int
wifi_chkIface(const char *csIface, char **ppsIF, int nIF)
{
	char szParent[IFNAMSIZ];
	register int i;

	FTRACE(5);

	assert(csIface);

	if (wifi_getParent(csIface, szParent, IFNAMSIZ) == -1)
		return -1;

	for (i = 0; i < nIF; i++)
		if (!strcasecmp(ppsIF[i], "any") || !strcmp(ppsIF[i], szParent))
			return 1; /* OK, vap is child */

	syslog(LOG_ERR, "Error:: Interface %s parent %s not being monitored", csIface, szParent);
	return 0;
}

inline int
wifi_isWDS(int fd, const char *csVAP)
{
	struct ifmediareq ifmr;

	FTRACE(5);

	assert(csVAP);

	memset(&ifmr, 0, sizeof ifmr);
	strlcpy(ifmr.ifm_name, csVAP, sizeof ifmr.ifm_name);
	if (ioctl(fd, SIOCGIFMEDIA, &ifmr) == -1) {
		syslog(LOG_ERR, "Error:: can`t get media for %s #%d - %s\n", csVAP, 
				errno, strerror(errno));
		return -1;
	}

	return (ifmr.ifm_current & IFM_IEEE80211_WDS) != 0;
}

inline int
wifi_getBSSID(int fd, const char *csVAP, uint8_t *psBSSID, int len)
{
	struct ieee80211req ireq;

	FTRACE(5);

	assert(csVAP);
	assert(psBSSID);

	memset(&ireq, 0, sizeof ireq);
	strlcpy(ireq.i_name, csVAP, sizeof ireq.i_name);
	ireq.i_type = IEEE80211_IOC_BSSID;
	ireq.i_data = psBSSID;
	ireq.i_len = len;
	if (ioctl(fd, SIOCG80211, &ireq) == -1) {
		syslog(LOG_ERR, "Error:: can`t get BSSID for %s #%d - %s\n", csVAP, 
				errno, strerror(errno));
		return -1;
	}

	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>