1 /* $FreeBSD$ */ 2 3 /*- 4 * Copyright (c) 2005 5 * Damien Bergamini <damien.bergamini@free.fr> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #define RAL_TX_LIST_COUNT 8 21 #define RAL_TX_MINFREE 2 22 23 #define URAL_SCAN_START 1 24 #define URAL_SCAN_END 2 25 #define URAL_SET_CHANNEL 3 26 27 28 struct ural_rx_radiotap_header { 29 struct ieee80211_radiotap_header wr_ihdr; 30 uint8_t wr_flags; 31 uint8_t wr_rate; 32 uint16_t wr_chan_freq; 33 uint16_t wr_chan_flags; 34 uint8_t wr_antenna; 35 uint8_t wr_antsignal; 36 }; 37 38 #define RAL_RX_RADIOTAP_PRESENT \ 39 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 40 (1 << IEEE80211_RADIOTAP_RATE) | \ 41 (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 42 (1 << IEEE80211_RADIOTAP_ANTENNA) | \ 43 (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL)) 44 45 struct ural_tx_radiotap_header { 46 struct ieee80211_radiotap_header wt_ihdr; 47 uint8_t wt_flags; 48 uint8_t wt_rate; 49 uint16_t wt_chan_freq; 50 uint16_t wt_chan_flags; 51 uint8_t wt_antenna; 52 }; 53 54 #define RAL_TX_RADIOTAP_PRESENT \ 55 ((1 << IEEE80211_RADIOTAP_FLAGS) | \ 56 (1 << IEEE80211_RADIOTAP_RATE) | \ 57 (1 << IEEE80211_RADIOTAP_CHANNEL) | \ 58 (1 << IEEE80211_RADIOTAP_ANTENNA)) 59 60 struct ural_softc; 61 62 struct ural_task { 63 struct usb2_proc_msg hdr; 64 struct ural_softc *sc; 65 }; 66 67 struct ural_tx_data { 68 STAILQ_ENTRY(ural_tx_data) next; 69 struct ural_softc *sc; 70 struct ural_tx_desc desc; 71 struct mbuf *m; 72 struct ieee80211_node *ni; 73 int rate; 74 }; 75 typedef STAILQ_HEAD(, ural_tx_data) ural_txdhead; 76 77 struct ural_node { 78 struct ieee80211_node ni; 79 struct ieee80211_amrr_node amn; 80 }; 81 #define URAL_NODE(ni) ((struct ural_node *)(ni)) 82 83 struct ural_vap { 84 struct ieee80211vap vap; 85 struct ural_softc *sc; 86 struct ieee80211_beacon_offsets bo; 87 struct ieee80211_amrr amrr; 88 struct usb2_callout amrr_ch; 89 struct ural_task amrr_task[2]; 90 91 int (*newstate)(struct ieee80211vap *, 92 enum ieee80211_state, int); 93 }; 94 #define URAL_VAP(vap) ((struct ural_vap *)(vap)) 95 96 enum { 97 URAL_BULK_WR, 98 URAL_BULK_RD, 99 URAL_N_TRANSFER = 2, 100 }; 101 102 struct ural_softc { 103 struct ifnet *sc_ifp; 104 device_t sc_dev; 105 struct usb2_device *sc_udev; 106 struct usb2_process sc_tq; 107 108 const struct ieee80211_rate_table *sc_rates; 109 110 uint32_t asic_rev; 111 uint8_t rf_rev; 112 113 struct usb2_xfer *sc_xfer[URAL_N_TRANSFER]; 114 115 enum ieee80211_state sc_state; 116 int sc_arg; 117 int sc_scan_action; /* should be an enum */ 118 struct ural_task sc_synctask[2]; 119 struct ural_task sc_task[2]; 120 struct ural_task sc_promisctask[2]; 121 struct ural_task sc_scantask[2]; 122 123 struct ural_tx_data tx_data[RAL_TX_LIST_COUNT]; 124 ural_txdhead tx_q; 125 ural_txdhead tx_free; 126 int tx_nfree; 127 struct ural_rx_desc sc_rx_desc; 128 129 struct mtx sc_mtx; 130 131 uint16_t sta[11]; 132 uint32_t rf_regs[4]; 133 uint8_t txpow[14]; 134 uint8_t sc_bssid[6]; 135 136 struct { 137 uint8_t val; 138 uint8_t reg; 139 } __packed bbp_prom[16]; 140 141 int led_mode; 142 int hw_radio; 143 int rx_ant; 144 int tx_ant; 145 int nb_ant; 146 147 struct ural_rx_radiotap_header sc_rxtap; 148 int sc_rxtap_len; 149 150 struct ural_tx_radiotap_header sc_txtap; 151 int sc_txtap_len; 152 }; 153 154 #define RAL_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 155 #define RAL_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 156 #define RAL_LOCK_ASSERT(sc, t) mtx_assert(&(sc)->sc_mtx, t) 157