Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/wtap/wtap_hal/hal.c
Show All 39 Lines | hal_tx_proc(void *arg, int npending) | ||||
struct wtap_hal *hal = (struct wtap_hal *)arg; | struct wtap_hal *hal = (struct wtap_hal *)arg; | ||||
struct packet *p; | struct packet *p; | ||||
#if 0 | #if 0 | ||||
DWTAP_PRINTF("%s\n", __func__); | DWTAP_PRINTF("%s\n", __func__); | ||||
#endif | #endif | ||||
hal = (struct wtap_hal *)arg; | hal = (struct wtap_hal *)arg; | ||||
for(;;){ | for (;;) { | ||||
p = medium_get_next_packet(hal->hal_md); | p = medium_get_next_packet(hal->hal_md); | ||||
if(p == NULL) | if (p == NULL) | ||||
return; | return; | ||||
hal->plugin->work(hal->plugin, p); | hal->plugin->work(hal->plugin, p); | ||||
#if 0 | #if 0 | ||||
DWTAP_PRINTF("[%d] freeing m=%p\n", p->id, p->m); | DWTAP_PRINTF("[%d] freeing m=%p\n", p->id, p->m); | ||||
#endif | #endif | ||||
m_free(p->m); | m_free(p->m); | ||||
free(p, M_WTAP_PACKET); | free(p, M_WTAP_PACKET); | ||||
} | } | ||||
} | } | ||||
void | void | ||||
init_hal(struct wtap_hal *hal) | init_hal(struct wtap_hal *hal) | ||||
{ | { | ||||
DWTAP_PRINTF("%s\n", __func__); | DWTAP_PRINTF("%s\n", __func__); | ||||
mtx_init(&hal->hal_mtx, "wtap_hal mtx", NULL, MTX_DEF | MTX_RECURSE); | mtx_init(&hal->hal_mtx, "wtap_hal mtx", NULL, MTX_DEF | MTX_RECURSE); | ||||
hal->hal_md = (struct wtap_medium *)malloc(sizeof(struct wtap_medium), | hal->hal_md = (struct wtap_medium *)malloc(sizeof(struct wtap_medium), | ||||
M_WTAP, M_NOWAIT | M_ZERO); | M_WTAP, M_NOWAIT | M_ZERO); | ||||
bzero(hal->hal_md, sizeof(struct wtap_medium)); | |||||
init_medium(hal->hal_md); | init_medium(hal->hal_md); | ||||
/* register event handler for packets */ | /* register event handler for packets */ | ||||
TASK_INIT(&hal->hal_md->tx_handler->proc, 0, hal_tx_proc, hal); | TASK_INIT(&hal->hal_md->tx_handler->proc, 0, hal_tx_proc, hal); | ||||
} | } | ||||
void | void | ||||
register_plugin(struct wtap_hal *hal, struct wtap_plugin *plugin) | register_plugin(struct wtap_hal *hal, struct wtap_plugin *plugin) | ||||
Show All 20 Lines | deinit_hal(struct wtap_hal *hal) | ||||
free(hal->hal_md, M_WTAP); | free(hal->hal_md, M_WTAP); | ||||
mtx_destroy(&hal->hal_mtx); | mtx_destroy(&hal->hal_mtx); | ||||
} | } | ||||
int32_t | int32_t | ||||
new_wtap(struct wtap_hal *hal, int32_t id) | new_wtap(struct wtap_hal *hal, int32_t id) | ||||
{ | { | ||||
static const uint8_t mac_pool[64][IEEE80211_ADDR_LEN] = { | static const uint8_t mac_pool[64][IEEE80211_ADDR_LEN] = { | ||||
{0,152,154,152,150,151}, | { 0, 152, 154, 152, 150, 151 }, { 0, 152, 154, 152, 150, 152 }, | ||||
{0,152,154,152,150,152}, | { 0, 152, 154, 152, 150, 153 }, { 0, 152, 154, 152, 150, 154 }, | ||||
{0,152,154,152,150,153}, | { 0, 152, 154, 152, 150, 155 }, { 0, 152, 154, 152, 150, 156 }, | ||||
{0,152,154,152,150,154}, | { 0, 152, 154, 152, 150, 157 }, { 0, 152, 154, 152, 150, 158 }, | ||||
{0,152,154,152,150,155}, | { 0, 152, 154, 152, 151, 151 }, { 0, 152, 154, 152, 151, 152 }, | ||||
{0,152,154,152,150,156}, | { 0, 152, 154, 152, 151, 153 }, { 0, 152, 154, 152, 151, 154 }, | ||||
{0,152,154,152,150,157}, | { 0, 152, 154, 152, 151, 155 }, { 0, 152, 154, 152, 151, 156 }, | ||||
{0,152,154,152,150,158}, | { 0, 152, 154, 152, 151, 157 }, { 0, 152, 154, 152, 151, 158 }, | ||||
{0,152,154,152,151,151}, | { 0, 152, 154, 152, 152, 151 }, { 0, 152, 154, 152, 152, 152 }, | ||||
{0,152,154,152,151,152}, | { 0, 152, 154, 152, 152, 153 }, { 0, 152, 154, 152, 152, 154 }, | ||||
{0,152,154,152,151,153}, | { 0, 152, 154, 152, 152, 155 }, { 0, 152, 154, 152, 152, 156 }, | ||||
{0,152,154,152,151,154}, | { 0, 152, 154, 152, 152, 157 }, { 0, 152, 154, 152, 152, 158 }, | ||||
{0,152,154,152,151,155}, | { 0, 152, 154, 152, 153, 151 }, { 0, 152, 154, 152, 153, 152 }, | ||||
{0,152,154,152,151,156}, | { 0, 152, 154, 152, 153, 153 }, { 0, 152, 154, 152, 153, 154 }, | ||||
{0,152,154,152,151,157}, | { 0, 152, 154, 152, 153, 155 }, { 0, 152, 154, 152, 153, 156 }, | ||||
{0,152,154,152,151,158}, | { 0, 152, 154, 152, 153, 157 }, { 0, 152, 154, 152, 153, 158 }, | ||||
{0,152,154,152,152,151}, | { 0, 152, 154, 152, 154, 151 }, { 0, 152, 154, 152, 154, 152 }, | ||||
{0,152,154,152,152,152}, | { 0, 152, 154, 152, 154, 153 }, { 0, 152, 154, 152, 154, 154 }, | ||||
{0,152,154,152,152,153}, | { 0, 152, 154, 152, 154, 155 }, { 0, 152, 154, 152, 154, 156 }, | ||||
{0,152,154,152,152,154}, | { 0, 152, 154, 152, 154, 157 }, { 0, 152, 154, 152, 154, 158 }, | ||||
{0,152,154,152,152,155}, | { 0, 152, 154, 152, 155, 151 }, { 0, 152, 154, 152, 155, 152 }, | ||||
{0,152,154,152,152,156}, | { 0, 152, 154, 152, 155, 153 }, { 0, 152, 154, 152, 155, 154 }, | ||||
{0,152,154,152,152,157}, | { 0, 152, 154, 152, 155, 155 }, { 0, 152, 154, 152, 155, 156 }, | ||||
{0,152,154,152,152,158}, | { 0, 152, 154, 152, 155, 157 }, { 0, 152, 154, 152, 155, 158 }, | ||||
{0,152,154,152,153,151}, | { 0, 152, 154, 152, 156, 151 }, { 0, 152, 154, 152, 156, 152 }, | ||||
{0,152,154,152,153,152}, | { 0, 152, 154, 152, 156, 153 }, { 0, 152, 154, 152, 156, 154 }, | ||||
{0,152,154,152,153,153}, | { 0, 152, 154, 152, 156, 155 }, { 0, 152, 154, 152, 156, 156 }, | ||||
{0,152,154,152,153,154}, | { 0, 152, 154, 152, 156, 157 }, { 0, 152, 154, 152, 156, 158 }, | ||||
{0,152,154,152,153,155}, | { 0, 152, 154, 152, 157, 151 }, { 0, 152, 154, 152, 157, 152 }, | ||||
{0,152,154,152,153,156}, | { 0, 152, 154, 152, 157, 153 }, { 0, 152, 154, 152, 157, 154 }, | ||||
{0,152,154,152,153,157}, | { 0, 152, 154, 152, 157, 155 }, { 0, 152, 154, 152, 157, 156 }, | ||||
{0,152,154,152,153,158}, | { 0, 152, 154, 152, 157, 157 }, { 0, 152, 154, 152, 157, 158 } | ||||
{0,152,154,152,154,151}, | |||||
{0,152,154,152,154,152}, | |||||
{0,152,154,152,154,153}, | |||||
{0,152,154,152,154,154}, | |||||
{0,152,154,152,154,155}, | |||||
{0,152,154,152,154,156}, | |||||
{0,152,154,152,154,157}, | |||||
{0,152,154,152,154,158}, | |||||
{0,152,154,152,155,151}, | |||||
{0,152,154,152,155,152}, | |||||
{0,152,154,152,155,153}, | |||||
{0,152,154,152,155,154}, | |||||
{0,152,154,152,155,155}, | |||||
{0,152,154,152,155,156}, | |||||
{0,152,154,152,155,157}, | |||||
{0,152,154,152,155,158}, | |||||
{0,152,154,152,156,151}, | |||||
{0,152,154,152,156,152}, | |||||
{0,152,154,152,156,153}, | |||||
{0,152,154,152,156,154}, | |||||
{0,152,154,152,156,155}, | |||||
{0,152,154,152,156,156}, | |||||
{0,152,154,152,156,157}, | |||||
{0,152,154,152,156,158}, | |||||
{0,152,154,152,157,151}, | |||||
{0,152,154,152,157,152}, | |||||
{0,152,154,152,157,153}, | |||||
{0,152,154,152,157,154}, | |||||
{0,152,154,152,157,155}, | |||||
{0,152,154,152,157,156}, | |||||
{0,152,154,152,157,157}, | |||||
{0,152,154,152,157,158} | |||||
}; | }; | ||||
DWTAP_PRINTF("%s\n", __func__); | DWTAP_PRINTF("%s\n", __func__); | ||||
uint8_t const *macaddr = mac_pool[id]; | uint8_t const *macaddr = mac_pool[id]; | ||||
if(hal->hal_devs[id] != NULL){ | if (hal->hal_devs[id] != NULL) { | ||||
printf("error, wtap_id=%d already created\n", id); | printf("error, wtap_id=%d already created\n", id); | ||||
return -1; | return -1; | ||||
} | } | ||||
hal->hal_devs[id] = (struct wtap_softc *)malloc( | hal->hal_devs[id] = (struct wtap_softc *)malloc(sizeof( | ||||
sizeof(struct wtap_softc), M_WTAP, M_NOWAIT | M_ZERO); | struct wtap_softc), | ||||
bzero(hal->hal_devs[id], sizeof(struct wtap_softc)); | M_WTAP, M_NOWAIT | M_ZERO); | ||||
hal->hal_devs[id]->sc_md = hal->hal_md; | hal->hal_devs[id]->sc_md = hal->hal_md; | ||||
hal->hal_devs[id]->id = id; | hal->hal_devs[id]->id = id; | ||||
snprintf(hal->hal_devs[id]->name, sizeof(hal->hal_devs[id]->name), | snprintf(hal->hal_devs[id]->name, sizeof(hal->hal_devs[id]->name), | ||||
"wlan%d", id); | "wtap%d", id); | ||||
mtx_init(&hal->hal_devs[id]->sc_mtx, "wtap_softc mtx", NULL, | mtx_init(&hal->hal_devs[id]->sc_mtx, "wtap_softc mtx", NULL, | ||||
MTX_DEF | MTX_RECURSE); | MTX_DEF | MTX_RECURSE); | ||||
if(wtap_attach(hal->hal_devs[id], macaddr)){ | if (wtap_attach(hal->hal_devs[id], macaddr)) { | ||||
printf("%s, cant alloc new wtap\n", __func__); | printf("%s, cant alloc new wtap\n", __func__); | ||||
return -1; | return -1; | ||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
int32_t | int32_t | ||||
free_wtap(struct wtap_hal *hal, int32_t id) | free_wtap(struct wtap_hal *hal, int32_t id) | ||||
{ | { | ||||
DWTAP_PRINTF("%s\n", __func__); | DWTAP_PRINTF("%s\n", __func__); | ||||
if(hal->hal_devs[id] == NULL){ | if (hal->hal_devs[id] == NULL) { | ||||
printf("error, wtap_id=%d never created\n", id); | printf("error, wtap_id=%d never created\n", id); | ||||
return -1; | return -1; | ||||
} | } | ||||
if(wtap_detach(hal->hal_devs[id])) | if (wtap_detach(hal->hal_devs[id])) | ||||
printf("%s, cant alloc new wtap\n", __func__); | printf("%s, cant alloc new wtap\n", __func__); | ||||
mtx_destroy(&hal->hal_devs[id]->sc_mtx); | mtx_destroy(&hal->hal_devs[id]->sc_mtx); | ||||
free(hal->hal_devs[id], M_WTAP); | free(hal->hal_devs[id], M_WTAP); | ||||
hal->hal_devs[id] = NULL; | hal->hal_devs[id] = NULL; | ||||
return 0; | return 0; | ||||
} | } |