104d19802SAdrian Chadd /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 404d19802SAdrian Chadd * Copyright (c) 2010-2011 Monthadar Al Jaberi, TerraNet AB 504d19802SAdrian Chadd * All rights reserved. 604d19802SAdrian Chadd * 704d19802SAdrian Chadd * Redistribution and use in source and binary forms, with or without 804d19802SAdrian Chadd * modification, are permitted provided that the following conditions 904d19802SAdrian Chadd * are met: 1004d19802SAdrian Chadd * 1. Redistributions of source code must retain the above copyright 1104d19802SAdrian Chadd * notice, this list of conditions and the following disclaimer, 1204d19802SAdrian Chadd * without modification. 1304d19802SAdrian Chadd * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1404d19802SAdrian Chadd * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 1504d19802SAdrian Chadd * redistribution must be conditioned upon including a substantially 1604d19802SAdrian Chadd * similar Disclaimer requirement for further binary redistribution. 1704d19802SAdrian Chadd * 1804d19802SAdrian Chadd * NO WARRANTY 1904d19802SAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2004d19802SAdrian Chadd * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2104d19802SAdrian Chadd * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 2204d19802SAdrian Chadd * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 2304d19802SAdrian Chadd * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 2404d19802SAdrian Chadd * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2504d19802SAdrian Chadd * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2604d19802SAdrian Chadd * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 2704d19802SAdrian Chadd * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2804d19802SAdrian Chadd * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 2904d19802SAdrian Chadd * THE POSSIBILITY OF SUCH DAMAGES. 3004d19802SAdrian Chadd */ 3104d19802SAdrian Chadd 3204d19802SAdrian Chadd #ifndef _DEV_WTAP_WTAPVAR_H 3304d19802SAdrian Chadd #define _DEV_WTAP_WTAPVAR_H 3404d19802SAdrian Chadd 3504d19802SAdrian Chadd #include <sys/param.h> 3604d19802SAdrian Chadd #include <sys/conf.h> 3704d19802SAdrian Chadd #include <sys/malloc.h> 3804d19802SAdrian Chadd 3904d19802SAdrian Chadd #include <sys/sockio.h> 4004d19802SAdrian Chadd #include <sys/socket.h> 4104d19802SAdrian Chadd 4204d19802SAdrian Chadd #include <net/if.h> 4304d19802SAdrian Chadd #include <net/if_media.h> 4404d19802SAdrian Chadd #include <net/ethernet.h> 4504d19802SAdrian Chadd 4604d19802SAdrian Chadd #include <net80211/ieee80211_var.h> 4704d19802SAdrian Chadd #include <net80211/ieee80211_regdomain.h> 4804d19802SAdrian Chadd 4904d19802SAdrian Chadd #if 0 5004d19802SAdrian Chadd #define DWTAP_PRINTF(...) printf(__VA_ARGS__) 5104d19802SAdrian Chadd #else 5204d19802SAdrian Chadd #define DWTAP_PRINTF(...) 5304d19802SAdrian Chadd #endif 5404d19802SAdrian Chadd 5504d19802SAdrian Chadd #include "if_wtapioctl.h" 5604d19802SAdrian Chadd 5704d19802SAdrian Chadd #define MAX_NBR_WTAP (64) 5804d19802SAdrian Chadd #define BEACON_INTRERVAL (1000) 5904d19802SAdrian Chadd 6004d19802SAdrian Chadd MALLOC_DECLARE(M_WTAP); 6104d19802SAdrian Chadd MALLOC_DECLARE(M_WTAP_PACKET); 6204d19802SAdrian Chadd MALLOC_DECLARE(M_WTAP_BEACON); 6304d19802SAdrian Chadd MALLOC_DECLARE(M_WTAP_RXBUF); 6404d19802SAdrian Chadd MALLOC_DECLARE(M_WTAP_PLUGIN); 6504d19802SAdrian Chadd 6604d19802SAdrian Chadd /* driver-specific node state */ 6704d19802SAdrian Chadd struct wtap_node { 6804d19802SAdrian Chadd struct ieee80211_node an_node; /* base class */ 6904d19802SAdrian Chadd /* future addons */ 7004d19802SAdrian Chadd }; 7104d19802SAdrian Chadd #define WTAP_NODE(ni) ((struct ath_node *)(ni)) 7204d19802SAdrian Chadd #define WTAP_NODE_CONST(ni) ((const struct ath_node *)(ni)) 7304d19802SAdrian Chadd 7404d19802SAdrian Chadd struct wtap_buf { 7504d19802SAdrian Chadd STAILQ_ENTRY(wtap_buf) bf_list; 7604d19802SAdrian Chadd struct mbuf *m; /* mbuf for buf */ 7704d19802SAdrian Chadd }; 7804d19802SAdrian Chadd typedef STAILQ_HEAD(, wtap_buf) wtap_bufhead; 7904d19802SAdrian Chadd 8004d19802SAdrian Chadd #define WTAP_BUF_BUSY 0x00000002 /* (tx) desc owned by h/w */ 8104d19802SAdrian Chadd 8204d19802SAdrian Chadd struct wtap_vap { 8304d19802SAdrian Chadd struct ieee80211vap av_vap; /* base class */ 8404d19802SAdrian Chadd int32_t id; /* wtap id */ 8504d19802SAdrian Chadd struct cdev *av_dev; /* userspace injecting frames */ 8604d19802SAdrian Chadd struct wtap_medium *av_md; /* back pointer */ 8704d19802SAdrian Chadd struct mbuf *beacon; /* beacon */ 8804d19802SAdrian Chadd struct ieee80211_node *bf_node; /* pointer to the node */ 8904d19802SAdrian Chadd struct callout av_swba; /* software beacon alert */ 9004d19802SAdrian Chadd uint32_t av_bcinterval; /* beacon interval */ 9104d19802SAdrian Chadd void (*av_recv_mgmt)(struct ieee80211_node *, 92e369e734SGleb Smirnoff struct mbuf *, int, const struct ieee80211_rx_stats *, int, int); 9304d19802SAdrian Chadd int (*av_newstate)(struct ieee80211vap *, 9404d19802SAdrian Chadd enum ieee80211_state, int); 9504d19802SAdrian Chadd void (*av_bmiss)(struct ieee80211vap *); 9604d19802SAdrian Chadd }; 9704d19802SAdrian Chadd #define WTAP_VAP(vap) ((struct wtap_vap *)(vap)) 9804d19802SAdrian Chadd 9904d19802SAdrian Chadd struct taskqueue; 10004d19802SAdrian Chadd 10104d19802SAdrian Chadd struct wtap_softc { 1027a79cebfSGleb Smirnoff struct ieee80211com sc_ic; 103c8550c02SGleb Smirnoff char name[7]; /* wtapXX\0 */ 10404d19802SAdrian Chadd int32_t id; 10504d19802SAdrian Chadd int32_t up; 10604d19802SAdrian Chadd struct wtap_medium *sc_md; /* interface medium */ 107c0b65123SEn-Wei Wu struct wtap_hal *hal; 10804d19802SAdrian Chadd struct ieee80211_node* (* sc_node_alloc) 10904d19802SAdrian Chadd (struct ieee80211vap *, const uint8_t [IEEE80211_ADDR_LEN]); 11004d19802SAdrian Chadd void (*sc_node_free)(struct ieee80211_node *); 11104d19802SAdrian Chadd struct mtx sc_mtx; /* master lock (recursive) */ 11204d19802SAdrian Chadd struct taskqueue *sc_tq; /* private task queue */ 11304d19802SAdrian Chadd wtap_bufhead sc_rxbuf; /* receive buffer */ 11404d19802SAdrian Chadd struct task sc_rxtask; /* rx int processing */ 11504d19802SAdrian Chadd struct wtap_tx_radiotap_header sc_tx_th; 11604d19802SAdrian Chadd int sc_tx_th_len; 11704d19802SAdrian Chadd struct wtap_rx_radiotap_header sc_rx_th; 11804d19802SAdrian Chadd int sc_rx_th_len; 11904d19802SAdrian Chadd }; 12004d19802SAdrian Chadd 12104d19802SAdrian Chadd int32_t wtap_attach(struct wtap_softc *, const uint8_t *macaddr); 12204d19802SAdrian Chadd int32_t wtap_detach(struct wtap_softc *); 12304d19802SAdrian Chadd void wtap_resume(struct wtap_softc *); 12404d19802SAdrian Chadd void wtap_suspend(struct wtap_softc *); 12504d19802SAdrian Chadd void wtap_shutdown(struct wtap_softc *); 12604d19802SAdrian Chadd void wtap_intr(struct wtap_softc *); 12704d19802SAdrian Chadd void wtap_inject(struct wtap_softc *, struct mbuf *); 12804d19802SAdrian Chadd 12904d19802SAdrian Chadd #endif 130