version 1.1.2.2, 2010/10/27 16:04:52
|
version 1.1.2.5, 2010/10/28 09:08:58
|
Line 2
|
Line 2
|
#include "dwds.h" |
#include "dwds.h" |
|
|
|
|
inline int | static inline int |
wifi_getParent(const char *csVAP, char *psParent, size_t plen) |
wifi_getParent(const char *csVAP, char *psParent, size_t plen) |
{ |
{ |
char szOID[STRSIZ] = { 0 }; |
char szOID[STRSIZ] = { 0 }; |
Line 15 wifi_getParent(const char *csVAP, char *psParent, size
|
Line 15 wifi_getParent(const char *csVAP, char *psParent, size
|
memset(psParent, 0, plen); |
memset(psParent, 0, plen); |
snprintf(szOID, STRSIZ, "net.wlan.%s.%%parent", csVAP + 4); |
snprintf(szOID, STRSIZ, "net.wlan.%s.%%parent", csVAP + 4); |
if (sysctlbyname(szOID, psParent, &plen, NULL, 0) == -1) { |
if (sysctlbyname(szOID, psParent, &plen, NULL, 0) == -1) { |
syslog(LOG_ERR, "Error:: can`t get parent #%d - %s\n", errno, strerror(errno)); | // syslog(LOG_ERR, "Error:: can`t get parent #%d - %s\n", errno, strerror(errno)); |
return -1; |
return -1; |
} else |
} else |
psParent[plen] = 0; |
psParent[plen] = 0; |
Line 23 wifi_getParent(const char *csVAP, char *psParent, size
|
Line 23 wifi_getParent(const char *csVAP, char *psParent, size
|
return 0; |
return 0; |
} |
} |
|
|
inline int | static inline int |
wifi_chkIface(const char *csIface, char **ppsIF, int nIF) | wifi_chkIface(const char *csVAP, char **ppsIF, int nIF) |
{ |
{ |
char szParent[IFNAMSIZ]; |
char szParent[IFNAMSIZ]; |
register int i; |
register int i; |
|
|
FTRACE(5); |
FTRACE(5); |
|
|
assert(csIface); | assert(csVAP); |
|
|
if (wifi_getParent(csIface, szParent, IFNAMSIZ) == -1) | if (wifi_getParent(csVAP, szParent, IFNAMSIZ) == -1) |
return -1; |
return -1; |
|
|
for (i = 0; i < nIF; i++) |
for (i = 0; i < nIF; i++) |
if (!strcasecmp(ppsIF[i], "any") || !strcmp(ppsIF[i], szParent)) |
if (!strcasecmp(ppsIF[i], "any") || !strcmp(ppsIF[i], szParent)) |
return 1; /* OK, vap is child */ |
return 1; /* OK, vap is child */ |
|
|
syslog(LOG_ERR, "Error:: Interface %s parent %s not being monitored", csIface, szParent); | syslog(LOG_ERR, "Error:: Interface %s parent %s not being monitored", csVAP, szParent); |
return 0; |
return 0; |
} |
} |
|
|
inline int | static inline int |
wifi_isWDS(int fd, const char *csVAP) |
wifi_isWDS(int fd, const char *csVAP) |
{ |
{ |
struct ifmediareq ifmr; |
struct ifmediareq ifmr; |
Line 64 wifi_isWDS(int fd, const char *csVAP)
|
Line 64 wifi_isWDS(int fd, const char *csVAP)
|
return (ifmr.ifm_current & IFM_IEEE80211_WDS) != 0; |
return (ifmr.ifm_current & IFM_IEEE80211_WDS) != 0; |
} |
} |
|
|
inline int | static inline int |
wifi_getBSSID(int fd, const char *csVAP, uint8_t *psBSSID, int len) |
wifi_getBSSID(int fd, const char *csVAP, uint8_t *psBSSID, int len) |
{ |
{ |
struct ieee80211req ireq; |
struct ieee80211req ireq; |
Line 86 wifi_getBSSID(int fd, const char *csVAP, uint8_t *psBS
|
Line 86 wifi_getBSSID(int fd, const char *csVAP, uint8_t *psBS
|
} |
} |
|
|
return 0; |
return 0; |
|
} |
|
|
|
struct dwds_if * |
|
wifi_buildWDS(int fd, char **ppsIF, int nIF) |
|
{ |
|
struct dwds_if *p, *wds = NULL; |
|
char szVAP[IFNAMSIZ]; |
|
struct ether_addr bssid; |
|
register int i; |
|
|
|
for (i = 0; i < 128; i++) { |
|
memset(szVAP, 0, IFNAMSIZ); |
|
snprintf(szVAP, IFNAMSIZ, "wlan%d", i); |
|
if (wifi_chkIface(szVAP, ppsIF, nIF) > 0 && wifi_isWDS(fd, szVAP) > 0) { |
|
p = malloc(sizeof(struct dwds_if)); |
|
if (!p) { |
|
syslog(LOG_ERR, "Error:: can`t allocate memory #%d - %s\n", |
|
errno, strerror(errno)); |
|
i = -1; |
|
break; |
|
} |
|
strlcpy(p->if_name, szVAP, IFNAMSIZ); |
|
if (wifi_getBSSID(fd, szVAP, p->if_bssid, IEEE80211_ADDR_LEN) == -1) { |
|
free(p); |
|
i = -1; |
|
break; |
|
} |
|
p->if_next = wds; |
|
wds = p; |
|
|
|
memcpy(&bssid, p->if_bssid, ETHER_ADDR_LEN); |
|
syslog(LOG_INFO, "BSSID:%s discover WDS vap %s\n", ether_ntoa(&bssid), szVAP); |
|
} |
|
} |
|
|
|
if (i == -1) |
|
while ((p = wds)) { |
|
wds = wds->if_next; |
|
free(p); |
|
} |
|
|
|
return wds; |
|
} |
|
|
|
inline void |
|
wifi_destroyWDS(const char *csIface, struct dwds_if **wds) |
|
{ |
|
struct dwds_if *p, **pp; |
|
|
|
assert(csIface); |
|
assert(wds); |
|
|
|
for (pp = wds; (p = *pp); pp = &p->if_next) |
|
if (!strncmp(p->if_name, csIface, IFNAMSIZ)) |
|
break; |
|
if (p) { |
|
*pp = p->if_next; |
|
free(p); |
|
} |
} |
} |