1/*- 2 * Copyright (c) 2010-2011 Monthadar Al Jaberi, TerraNet AB 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer, 10 * without modification. 11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13 * redistribution must be conditioned upon including a substantially 14 * similar Disclaimer requirement for further binary redistribution. 15 * 16 * NO WARRANTY 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGES. 28 * 29 * $FreeBSD$ 30 */ 31 32#ifndef _DEV_WTAP_WTAPVAR_H 33#define _DEV_WTAP_WTAPVAR_H 34 35#include <sys/param.h> 36#include <sys/conf.h> 37#include <sys/module.h> 38#include <sys/kernel.h> 39#include <sys/systm.h> 40#include <sys/sysctl.h> 41#include <sys/mbuf.h> 42#include <sys/malloc.h> 43#include <sys/lock.h> 44#include <sys/mutex.h> 45 46#include <sys/sockio.h> 47#include <sys/socket.h> 48#include <sys/socketvar.h> 49#include <sys/errno.h> 50#include <sys/callout.h> 51#include <sys/endian.h> 52#include <sys/kthread.h> 53#include <sys/taskqueue.h> 54#include <sys/priv.h> 55#include <sys/sysctl.h> 56 57#include <machine/bus.h> 58 59#include <net/if.h> 60#include <net/if_dl.h> 61#include <net/if_media.h> 62#include <net/if_types.h> 63#include <net/if_arp.h> 64#include <net/ethernet.h> 65#include <net/if_llc.h> 66 67#include <net80211/ieee80211_var.h> 68#include <net80211/ieee80211_regdomain.h> 69 70#include <net/bpf.h> 71 72#include <net/vnet.h> 73 74#include <netinet/in.h> 75#include <netinet/if_ether.h> 76 77#if 0 78#define DWTAP_PRINTF(...) printf(__VA_ARGS__) 79#else 80#define DWTAP_PRINTF(...) 81#endif 82 83#include "if_wtapioctl.h" 84 85#define MAX_NBR_WTAP (64) 86#define BEACON_INTRERVAL (1000) 87 88MALLOC_DECLARE(M_WTAP); 89MALLOC_DECLARE(M_WTAP_PACKET); 90MALLOC_DECLARE(M_WTAP_BEACON); 91MALLOC_DECLARE(M_WTAP_RXBUF); 92MALLOC_DECLARE(M_WTAP_PLUGIN); 93 94/* driver-specific node state */ 95struct wtap_node { 96 struct ieee80211_node an_node; /* base class */ 97 /* future addons */ 98}; 99#define WTAP_NODE(ni) ((struct ath_node *)(ni)) 100#define WTAP_NODE_CONST(ni) ((const struct ath_node *)(ni)) 101 102struct wtap_buf { 103 STAILQ_ENTRY(wtap_buf) bf_list; 104 struct mbuf *m; /* mbuf for buf */ 105}; 106typedef STAILQ_HEAD(, wtap_buf) wtap_bufhead; 107 108#define WTAP_BUF_BUSY 0x00000002 /* (tx) desc owned by h/w */ 109 110struct wtap_vap { 111 struct ieee80211vap av_vap; /* base class */ 112 int32_t id; /* wtap id */ 113 struct cdev *av_dev; /* userspace injecting frames */ 114 struct wtap_medium *av_md; /* back pointer */ 115 struct mbuf *beacon; /* beacon */ 116 struct ieee80211_node *bf_node; /* pointer to the node */ 117 struct callout av_swba; /* software beacon alert */ 118 uint32_t av_bcinterval; /* beacon interval */ 119 void (*av_recv_mgmt)(struct ieee80211_node *, 120 struct mbuf *, int, const struct ieee80211_rx_stats *, int, int); 121 int (*av_newstate)(struct ieee80211vap *, 122 enum ieee80211_state, int); 123 void (*av_bmiss)(struct ieee80211vap *); 124}; 125#define WTAP_VAP(vap) ((struct wtap_vap *)(vap)) 126 127struct taskqueue; 128 129struct wtap_softc { 130 struct ieee80211com sc_ic; 131 char name[7]; /* wtapXX\0 */ 132 int32_t id; 133 int32_t up; 134 struct wtap_medium *sc_md; /* interface medium */ 135 struct ieee80211_node* (* sc_node_alloc) 136 (struct ieee80211vap *, const uint8_t [IEEE80211_ADDR_LEN]); 137 void (*sc_node_free)(struct ieee80211_node *); 138 struct mtx sc_mtx; /* master lock (recursive) */ 139 struct taskqueue *sc_tq; /* private task queue */ 140 wtap_bufhead sc_rxbuf; /* receive buffer */ 141 struct task sc_rxtask; /* rx int processing */ 142 struct wtap_tx_radiotap_header sc_tx_th; 143 int sc_tx_th_len; 144 struct wtap_rx_radiotap_header sc_rx_th; 145 int sc_rx_th_len; 146}; 147 148int32_t wtap_attach(struct wtap_softc *, const uint8_t *macaddr); 149int32_t wtap_detach(struct wtap_softc *); 150void wtap_resume(struct wtap_softc *); 151void wtap_suspend(struct wtap_softc *); 152void wtap_shutdown(struct wtap_softc *); 153void wtap_intr(struct wtap_softc *); 154void wtap_inject(struct wtap_softc *, struct mbuf *); 155void wtap_rx_deliver(struct wtap_softc *, struct mbuf *); 156 157#endif 158