File:  [ELWIX - Embedded LightWeight unIX -] / embedtools / src / vap.c
Revision 1.1.2.3: download - view: text, annotated - select for diffs - revision graph
Wed Oct 27 16:35:54 2010 UTC (13 years, 8 months ago) by misho
Branches: tools1_0
added new funcs

    1: #include "global.h"
    2: #include "dwds.h"
    3: 
    4: 
    5: static inline int
    6: wifi_getParent(const char *csVAP, char *psParent, size_t plen)
    7: {
    8: 	char szOID[STRSIZ] = { 0 };
    9: 
   10: 	FTRACE(5);
   11: 
   12: 	assert(csVAP);
   13: 	assert(psParent);
   14: 
   15: 	memset(psParent, 0, plen);
   16: 	snprintf(szOID, STRSIZ, "net.wlan.%s.%%parent", csVAP + 4);
   17: 	if (sysctlbyname(szOID, psParent, &plen, NULL, 0) == -1) {
   18: 		syslog(LOG_ERR, "Error:: can`t get parent #%d - %s\n", errno, strerror(errno));
   19: 		return -1;
   20: 	} else
   21: 		psParent[plen] = 0;
   22: 
   23: 	return 0;
   24: }
   25: 
   26: static inline int
   27: wifi_chkIface(const char *csVAP, char **ppsIF, int nIF)
   28: {
   29: 	char szParent[IFNAMSIZ];
   30: 	register int i;
   31: 
   32: 	FTRACE(5);
   33: 
   34: 	assert(csVAP);
   35: 
   36: 	if (wifi_getParent(csVAP, szParent, IFNAMSIZ) == -1)
   37: 		return -1;
   38: 
   39: 	for (i = 0; i < nIF; i++)
   40: 		if (!strcasecmp(ppsIF[i], "any") || !strcmp(ppsIF[i], szParent))
   41: 			return 1; /* OK, vap is child */
   42: 
   43: 	syslog(LOG_ERR, "Error:: Interface %s parent %s not being monitored", csVAP, szParent);
   44: 	return 0;
   45: }
   46: 
   47: static inline int
   48: wifi_isWDS(int fd, const char *csVAP)
   49: {
   50: 	struct ifmediareq ifmr;
   51: 
   52: 	FTRACE(5);
   53: 
   54: 	assert(csVAP);
   55: 
   56: 	memset(&ifmr, 0, sizeof ifmr);
   57: 	strlcpy(ifmr.ifm_name, csVAP, sizeof ifmr.ifm_name);
   58: 	if (ioctl(fd, SIOCGIFMEDIA, &ifmr) == -1) {
   59: 		syslog(LOG_ERR, "Error:: can`t get media for %s #%d - %s\n", csVAP, 
   60: 				errno, strerror(errno));
   61: 		return -1;
   62: 	}
   63: 
   64: 	return (ifmr.ifm_current & IFM_IEEE80211_WDS) != 0;
   65: }
   66: 
   67: static inline int
   68: wifi_getBSSID(int fd, const char *csVAP, uint8_t *psBSSID, int len)
   69: {
   70: 	struct ieee80211req ireq;
   71: 
   72: 	FTRACE(5);
   73: 
   74: 	assert(csVAP);
   75: 	assert(psBSSID);
   76: 
   77: 	memset(&ireq, 0, sizeof ireq);
   78: 	strlcpy(ireq.i_name, csVAP, sizeof ireq.i_name);
   79: 	ireq.i_type = IEEE80211_IOC_BSSID;
   80: 	ireq.i_data = psBSSID;
   81: 	ireq.i_len = len;
   82: 	if (ioctl(fd, SIOCG80211, &ireq) == -1) {
   83: 		syslog(LOG_ERR, "Error:: can`t get BSSID for %s #%d - %s\n", csVAP, 
   84: 				errno, strerror(errno));
   85: 		return -1;
   86: 	}
   87: 
   88: 	return 0;
   89: }
   90: 
   91: struct dwds_if *
   92: wifi_buildWDS(int fd, char **ppsIF, int nIF)
   93: {
   94: 	struct dwds_if *p, *wds = NULL;
   95: 	char szVAP[IFNAMSIZ];
   96: 	struct ether_addr bssid;
   97: 	register int i;
   98: 
   99: 	for (i = 0; i < 128; i++) {
  100: 		memset(szVAP, 0, IFNAMSIZ);
  101: 		snprintf(szVAP, IFNAMSIZ, "wlan%d", i);
  102: 		if (wifi_chkIface(szVAP, ppsIF, nIF) > 0 && wifi_isWDS(fd, szVAP) > 0) {
  103: 			p = malloc(sizeof(struct dwds_if));
  104: 			if (!p) {
  105: 				syslog(LOG_ERR, "Error:: can`t allocate memory #%d - %s\n", 
  106: 						errno, strerror(errno));
  107: 				i = -1;
  108: 				break;
  109: 			}
  110: 			strlcpy(p->if_name, szVAP, IFNAMSIZ);
  111: 			if (wifi_getBSSID(fd, szVAP, p->if_bssid, IEEE80211_ADDR_LEN) == -1) {
  112: 				free(p);
  113: 				i = -1;
  114: 				break;
  115: 			}
  116: 			p->if_next = wds;
  117: 			wds = p;
  118: 
  119: 			memcpy(&bssid, p->if_bssid, ETHER_ADDR_LEN);
  120: 			syslog(LOG_INFO, "BSSID:%s discover WDS vap %s\n", ether_ntoa(&bssid), szVAP);
  121: 		}
  122: 	}
  123: 
  124: 	if (i == -1)
  125: 		while ((p = wds)) {
  126: 			wds = wds->if_next;
  127: 			free(p);
  128: 		}
  129: 
  130: 	return wds;
  131: }

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