#include <sys/param.h>
#include <sys/module.h>
#include <sys/malloc.h>
#include <sys/jail.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_media.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include "if_wtapvar.h"
#include "if_wtapioctl.h"
#include "if_medium.h"
#include "wtap_hal/hal.h"
#include "plugins/visibility.h"
MALLOC_DEFINE(M_WTAP, "wtap", "wtap wireless simulator");
MALLOC_DEFINE(M_WTAP_PACKET, "wtap packet", "wtap wireless simulator packet");
MALLOC_DEFINE(M_WTAP_RXBUF, "wtap rxbuf",
"wtap wireless simulator receive buffer");
MALLOC_DEFINE(M_WTAP_PLUGIN, "wtap plugin", "wtap wireless simulator plugin");
static struct wtap_hal *hal;
static d_ioctl_t wtap_ioctl;
static struct cdev *sdev;
static struct cdevsw wtap_cdevsw = {
.d_version = D_VERSION,
.d_flags = 0,
.d_ioctl = wtap_ioctl,
.d_name = "wtapctl",
};
int
wtap_ioctl(struct cdev *dev, u_long cmd, caddr_t data,
int fflag, struct thread *td)
{
int error = 0;
CURVNET_SET(CRED_TO_VNET(curthread->td_ucred));
switch(cmd) {
case WTAPIOCTLCRT:
if(new_wtap(hal, *(int *)data))
error = EINVAL;
break;
case WTAPIOCTLDEL:
if(free_wtap(hal, *(int *)data))
error = EINVAL;
break;
default:
DWTAP_PRINTF("Unknown WTAP IOCTL\n");
error = EINVAL;
}
CURVNET_RESTORE();
return error;
}
static int
event_handler(module_t module, int event, void *arg)
{
struct visibility_plugin *plugin;
int e = 0;
switch (event) {
case MOD_LOAD:
sdev = make_dev(&wtap_cdevsw,0,UID_ROOT,
GID_WHEEL,0600,(const char *)"wtapctl");
hal = (struct wtap_hal *)malloc(sizeof(struct wtap_hal),
M_WTAP, M_NOWAIT | M_ZERO);
init_hal(hal);
plugin = (struct visibility_plugin *)malloc
(sizeof(struct visibility_plugin), M_WTAP_PLUGIN,
M_NOWAIT | M_ZERO);
plugin->base.wp_hal = hal;
plugin->base.init = visibility_init;
plugin->base.deinit = visibility_deinit;
plugin->base.work = visibility_work;
register_plugin(hal, (struct wtap_plugin *)plugin);
printf("Loaded wtap wireless simulator\n");
break;
case MOD_UNLOAD:
destroy_dev(sdev);
deregister_plugin(hal);
deinit_hal(hal);
free(hal, M_WTAP);
printf("Unloading wtap wireless simulator\n");
break;
default:
e = EOPNOTSUPP;
break;
}
return(e);
}
static moduledata_t wtap_conf = {
"wtap",
event_handler,
NULL
};
DECLARE_MODULE(wtap, wtap_conf, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
MODULE_DEPEND(wtap, wlan, 1, 1, 1);