Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/wtap/if_wtap_module.c
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
#include <net/vnet.h> | #include <net/vnet.h> | ||||
#include <net80211/ieee80211_var.h> | #include <net80211/ieee80211_var.h> | ||||
#include <net80211/ieee80211_regdomain.h> | #include <net80211/ieee80211_regdomain.h> | ||||
#include <net/bpf.h> | #include <net/bpf.h> | ||||
#include <sys/errno.h> | #include <sys/errno.h> | ||||
#include <sys/conf.h> /* cdevsw struct */ | #include <sys/conf.h> /* cdevsw struct */ | ||||
#include <sys/uio.h> /* uio struct */ | #include <sys/uio.h> /* uio struct */ | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#include <netinet/if_ether.h> | #include <netinet/if_ether.h> | ||||
#include "if_wtapvar.h" | #include "if_wtapvar.h" | ||||
#include "if_wtapioctl.h" | #include "if_wtapioctl.h" | ||||
#include "if_medium.h" | #include "if_medium.h" | ||||
#include "wtap_hal/hal.h" | #include "wtap_hal/hal.h" | ||||
/* WTAP PLUGINS */ | /* WTAP PLUGINS */ | ||||
#include "plugins/visibility.h" | #include "plugins/visibility.h" | ||||
MALLOC_DEFINE(M_WTAP, "wtap", "wtap wireless simulator"); | MALLOC_DEFINE(M_WTAP, "wtap", "wtap wireless simulator"); | ||||
MALLOC_DEFINE(M_WTAP_PACKET, "wtap packet", "wtap wireless simulator packet"); | MALLOC_DEFINE(M_WTAP_PACKET, "wtap packet", "wtap wireless simulator packet"); | ||||
MALLOC_DEFINE(M_WTAP_RXBUF, "wtap rxbuf", | MALLOC_DEFINE(M_WTAP_RXBUF, "wtap rxbuf", | ||||
"wtap wireless simulator receive buffer"); | "wtap wireless simulator receive buffer"); | ||||
MALLOC_DEFINE(M_WTAP_PLUGIN, "wtap plugin", "wtap wireless simulator plugin"); | MALLOC_DEFINE(M_WTAP_PLUGIN, "wtap plugin", "wtap wireless simulator plugin"); | ||||
static struct wtap_hal *hal; | static struct wtap_hal *hal; | ||||
/* Function prototypes */ | /* Function prototypes */ | ||||
static d_ioctl_t wtap_ioctl; | static d_ioctl_t wtap_ioctl; | ||||
static struct cdev *sdev; | static struct cdev *sdev; | ||||
static struct cdevsw wtap_cdevsw = { | static struct cdevsw wtap_cdevsw = { | ||||
.d_version = D_VERSION, | .d_version = D_VERSION, | ||||
.d_flags = 0, | .d_flags = 0, | ||||
.d_ioctl = wtap_ioctl, | .d_ioctl = wtap_ioctl, | ||||
.d_name = "wtapctl", | .d_name = "wtapctl", | ||||
}; | }; | ||||
int | int | ||||
wtap_ioctl(struct cdev *dev, u_long cmd, caddr_t data, | wtap_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, | ||||
int fflag, struct thread *td) | struct thread *td) | ||||
{ | { | ||||
int error = 0; | int error = 0; | ||||
CURVNET_SET(CRED_TO_VNET(curthread->td_ucred)); | CURVNET_SET(CRED_TO_VNET(curthread->td_ucred)); | ||||
switch(cmd) { | switch (cmd) { | ||||
case WTAPIOCTLCRT: | case WTAPIOCTLCRT: | ||||
if(new_wtap(hal, *(int *)data)) | if (new_wtap(hal, *(int *)data)) | ||||
error = EINVAL; | error = EINVAL; | ||||
break; | break; | ||||
case WTAPIOCTLDEL: | case WTAPIOCTLDEL: | ||||
if(free_wtap(hal, *(int *)data)) | if (free_wtap(hal, *(int *)data)) | ||||
error = EINVAL; | error = EINVAL; | ||||
break; | break; | ||||
default: | default: | ||||
DWTAP_PRINTF("Unknown WTAP IOCTL\n"); | DWTAP_PRINTF("Unknown WTAP IOCTL\n"); | ||||
error = EINVAL; | error = EINVAL; | ||||
} | } | ||||
CURVNET_RESTORE(); | CURVNET_RESTORE(); | ||||
return error; | return error; | ||||
} | } | ||||
/* The function called at load/unload. */ | /* The function called at load/unload. */ | ||||
static int | static int | ||||
event_handler(module_t module, int event, void *arg) | event_handler(module_t module, int event, void *arg) | ||||
{ | { | ||||
struct visibility_plugin *plugin; | struct visibility_plugin *plugin; | ||||
int e = 0; /* Error, 0 for normal return status */ | int e = 0; /* Error, 0 for normal return status */ | ||||
switch (event) { | switch (event) { | ||||
case MOD_LOAD: | case MOD_LOAD: | ||||
sdev = make_dev(&wtap_cdevsw,0,UID_ROOT, | sdev = make_dev(&wtap_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, | ||||
GID_WHEEL,0600,(const char *)"wtapctl"); | (const char *)"wtapctl"); | ||||
hal = (struct wtap_hal *)malloc(sizeof(struct wtap_hal), | hal = (struct wtap_hal *)malloc(sizeof(struct wtap_hal), M_WTAP, | ||||
M_WTAP, M_NOWAIT | M_ZERO); | M_NOWAIT | M_ZERO); | ||||
bzero(hal, sizeof(struct wtap_hal)); | |||||
init_hal(hal); | init_hal(hal); | ||||
/* Setting up a simple plugin */ | /* Setting up a simple plugin */ | ||||
plugin = (struct visibility_plugin *)malloc | plugin = (struct visibility_plugin *) | ||||
(sizeof(struct visibility_plugin), M_WTAP_PLUGIN, | malloc(sizeof(struct visibility_plugin), M_WTAP_PLUGIN, | ||||
M_NOWAIT | M_ZERO); | M_NOWAIT | M_ZERO); | ||||
plugin->base.wp_hal = hal; | plugin->base.wp_hal = hal; | ||||
plugin->base.init = visibility_init; | plugin->base.init = visibility_init; | ||||
plugin->base.deinit = visibility_deinit; | plugin->base.deinit = visibility_deinit; | ||||
plugin->base.work = visibility_work; | plugin->base.work = visibility_work; | ||||
register_plugin(hal, (struct wtap_plugin *)plugin); | register_plugin(hal, (struct wtap_plugin *)plugin); | ||||
printf("Loaded wtap wireless simulator\n"); | printf("Loaded wtap wireless simulator\n"); | ||||
break; | break; | ||||
case MOD_UNLOAD: | case MOD_UNLOAD: | ||||
destroy_dev(sdev); | destroy_dev(sdev); | ||||
deregister_plugin(hal); | deregister_plugin(hal); | ||||
deinit_hal(hal); | deinit_hal(hal); | ||||
free(hal, M_WTAP); | free(hal, M_WTAP); | ||||
printf("Unloading wtap wireless simulator\n"); | printf("Unloading wtap wireless simulator\n"); | ||||
break; | break; | ||||
default: | default: | ||||
e = EOPNOTSUPP; /* Error, Operation Not Supported */ | e = EOPNOTSUPP; /* Error, Operation Not Supported */ | ||||
break; | break; | ||||
} | } | ||||
return(e); | return (e); | ||||
} | } | ||||
/* The second argument of DECLARE_MODULE. */ | /* The second argument of DECLARE_MODULE. */ | ||||
static moduledata_t wtap_conf = { | static moduledata_t wtap_conf = { | ||||
"wtap", /* module name */ | "wtap", /* module name */ | ||||
event_handler, /* event handler */ | event_handler, /* event handler */ | ||||
NULL /* extra data */ | NULL /* extra data */ | ||||
}; | }; | ||||
DECLARE_MODULE(wtap, wtap_conf, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); | DECLARE_MODULE(wtap, wtap_conf, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); | ||||
MODULE_DEPEND(wtap, wlan, 1, 1, 1); /* 802.11 media layer */ | MODULE_DEPEND(wtap, wlan, 1, 1, 1); /* 802.11 media layer */ |