Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/wlandebug/wlandebug.c
Show All 28 Lines | |||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
/* | /* | ||||
* wlandebug [-i interface] flags | * wlandebug [-i interface] flags | ||||
* (default interface is wlan.0). | * (default interface is wlan.0). | ||||
*/ | */ | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/socket.h> | |||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <net/if.h> | |||||
#include <net80211/ieee80211_ioctl.h> | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <getopt.h> | #include <getopt.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <unistd.h> | |||||
#include <lib80211/lib80211_ioctl.h> | |||||
#define N(a) (sizeof(a)/sizeof(a[0])) | #define N(a) (sizeof(a)/sizeof(a[0])) | ||||
const char *progname; | const char *progname; | ||||
#define IEEE80211_MSG_11N 0x80000000 /* 11n mode debug */ | #define IEEE80211_MSG_11N 0x80000000 /* 11n mode debug */ | ||||
#define IEEE80211_MSG_DEBUG 0x40000000 /* IFF_DEBUG equivalent */ | #define IEEE80211_MSG_DEBUG 0x40000000 /* IFF_DEBUG equivalent */ | ||||
#define IEEE80211_MSG_DUMPPKTS 0x20000000 /* IFF_LINK2 equivalant */ | #define IEEE80211_MSG_DUMPPKTS 0x20000000 /* IFF_LINK2 equivalant */ | ||||
#define IEEE80211_MSG_CRYPTO 0x10000000 /* crypto work */ | #define IEEE80211_MSG_CRYPTO 0x10000000 /* crypto work */ | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
setoid(char oid[], size_t oidlen, const char *wlan) | setoid(char oid[], size_t oidlen, const char *wlan) | ||||
{ | { | ||||
#ifdef __linux__ | #ifdef __linux__ | ||||
if (wlan) | if (wlan) | ||||
snprintf(oid, oidlen, "net.%s.debug", wlan); | snprintf(oid, oidlen, "net.%s.debug", wlan); | ||||
#elif __FreeBSD__ | #elif __FreeBSD__ | ||||
if (wlan) | if (wlan) | ||||
snprintf(oid, oidlen, "net.wlan.%s.debug", wlan+4); | snprintf(oid, oidlen, "net.wlan.%s.debug", wlan); | ||||
else | else | ||||
snprintf(oid, oidlen, "net.wlan.debug"); | snprintf(oid, oidlen, "net.wlan.debug"); | ||||
#elif __NetBSD__ | #elif __NetBSD__ | ||||
if (wlan) | if (wlan) | ||||
snprintf(oid, oidlen, "net.link.ieee80211.%s.debug", wlan); | snprintf(oid, oidlen, "net.link.ieee80211.%s.debug", wlan); | ||||
else | else | ||||
snprintf(oid, oidlen, "net.link.ieee80211.debug"); | snprintf(oid, oidlen, "net.link.ieee80211.debug"); | ||||
#else | #else | ||||
#error "No support for this system" | #error "No support for this system" | ||||
#endif | #endif | ||||
} | } | ||||
static void | |||||
adrian: hm, should we put this in lib80211?
| |||||
avosAuthorUnsubmitted Not Done Inline Actionsinterface name -> unit translation? avos: interface name -> unit translation? | |||||
change_iface_unit(char *oid, size_t oid_size, char *name) | |||||
{ | |||||
int s, val; | |||||
char *unit_str; | |||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0 || | |||||
lib80211_get80211val(s, name, IEEE80211_IOC_UNIT, &val) || | |||||
asprintf(&unit_str, "%d", val) < 0) { | |||||
/* fall back to the old method */ | |||||
if (strncmp(name, "wlan", 4) != 0) | |||||
errx(1, "expecting a wlan interface name"); | |||||
setoid(oid, oid_size, &name[4]); | |||||
} else { | |||||
setoid(oid, oid_size, unit_str); | |||||
free(unit_str); | |||||
} | |||||
close(s); | |||||
} | |||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
const char *cp, *tp; | const char *cp, *tp; | ||||
const char *sep; | const char *sep; | ||||
int op, i; | int op, i; | ||||
u_int32_t debug, ndebug; | u_int32_t debug, ndebug; | ||||
size_t debuglen; | size_t debuglen; | ||||
char oid[256]; | char oid[256]; | ||||
progname = argv[0]; | progname = argv[0]; | ||||
setoid(oid, sizeof(oid), "wlan0"); | setoid(oid, sizeof(oid), "0"); | ||||
if (argc > 1) { | if (argc > 1) { | ||||
if (strcmp(argv[1], "-d") == 0) { | if (strcmp(argv[1], "-d") == 0) { | ||||
setoid(oid, sizeof(oid), NULL); | setoid(oid, sizeof(oid), NULL); | ||||
argc -= 1, argv += 1; | argc -= 1, argv += 1; | ||||
} else if (strcmp(argv[1], "-i") == 0) { | } else if (strcmp(argv[1], "-i") == 0) { | ||||
if (argc <= 2) | if (argc <= 2) | ||||
errx(1, "missing interface name for -i option"); | errx(1, "missing interface name for -i option"); | ||||
if (strncmp(argv[2], "wlan", 4) != 0) | change_iface_unit(oid, sizeof(oid), argv[2]); | ||||
errx(1, "expecting a wlan interface name"); | |||||
setoid(oid, sizeof(oid), argv[2]); | |||||
argc -= 2, argv += 2; | argc -= 2, argv += 2; | ||||
} else if (strcmp(argv[1], "-?") == 0) | } else if (strcmp(argv[1], "-?") == 0) | ||||
usage(); | usage(); | ||||
} | } | ||||
debuglen = sizeof(debug); | debuglen = sizeof(debug); | ||||
if (sysctlbyname(oid, &debug, &debuglen, NULL, 0) < 0) | if (sysctlbyname(oid, &debug, &debuglen, NULL, 0) < 0) | ||||
err(1, "sysctl-get(%s)", oid); | err(1, "sysctl-get(%s)", oid); | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |
hm, should we put this in lib80211?