ieee80211_scan.h revision 170530
1/*- 2 * Copyright (c) 2005-2007 Sam Leffler, Errno Consulting 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 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * 25 * $FreeBSD: head/sys/net80211/ieee80211_scan.h 170530 2007-06-11 03:36:55Z sam $ 26 */ 27#ifndef _NET80211_IEEE80211_SCAN_H_ 28#define _NET80211_IEEE80211_SCAN_H_ 29 30#define IEEE80211_SCAN_MAX IEEE80211_CHAN_MAX 31 32struct ieee80211_scanner; 33 34struct ieee80211_scan_ssid { 35 int len; /* length in bytes */ 36 uint8_t ssid[IEEE80211_NWID_LEN]; /* ssid contents */ 37}; 38#define IEEE80211_SCAN_MAX_SSID 1 39 40struct ieee80211_scan_state { 41 struct ieee80211com *ss_ic; 42 const struct ieee80211_scanner *ss_ops; /* policy hookup, see below */ 43 void *ss_priv; /* scanner private state */ 44 uint16_t ss_flags; 45#define IEEE80211_SCAN_NOPICK 0x0001 /* scan only, no selection */ 46#define IEEE80211_SCAN_ACTIVE 0x0002 /* active scan (probe req) */ 47#define IEEE80211_SCAN_PICK1ST 0x0004 /* ``hey sailor'' mode */ 48#define IEEE80211_SCAN_BGSCAN 0x0008 /* bg scan, exit ps at end */ 49#define IEEE80211_SCAN_ONCE 0x0010 /* do one complete pass */ 50#define IEEE80211_SCAN_GOTPICK 0x1000 /* got candidate, can stop */ 51 uint8_t ss_nssid; /* # ssid's to probe/match */ 52 struct ieee80211_scan_ssid ss_ssid[IEEE80211_SCAN_MAX_SSID]; 53 /* ssid's to probe/match */ 54 /* ordered channel set */ 55 struct ieee80211_channel *ss_chans[IEEE80211_SCAN_MAX]; 56 uint16_t ss_next; /* ix of next chan to scan */ 57 uint16_t ss_last; /* ix+1 of last chan to scan */ 58 unsigned long ss_mindwell; /* min dwell on channel */ 59 unsigned long ss_maxdwell; /* max dwell on channel */ 60}; 61 62/* 63 * The upper 16 bits of the flags word is used to communicate 64 * information to the scanning code that is NOT recorded in 65 * ss_flags. It might be better to split this stuff out into 66 * a separate variable to avoid confusion. 67 */ 68#define IEEE80211_SCAN_FLUSH 0x10000 /* flush candidate table */ 69#define IEEE80211_SCAN_NOSSID 0x20000 /* don't update ssid list */ 70 71struct ieee80211com; 72void ieee80211_scan_attach(struct ieee80211com *); 73void ieee80211_scan_detach(struct ieee80211com *); 74 75void ieee80211_scan_dump_channels(const struct ieee80211_scan_state *); 76 77int ieee80211_scan_update(struct ieee80211com *); 78#define IEEE80211_SCAN_FOREVER 0x7fffffff 79int ieee80211_start_scan(struct ieee80211com *, int flags, u_int duration, 80 u_int nssid, const struct ieee80211_scan_ssid ssids[]); 81int ieee80211_check_scan(struct ieee80211com *, int flags, u_int duration, 82 u_int nssid, const struct ieee80211_scan_ssid ssids[]); 83int ieee80211_bg_scan(struct ieee80211com *); 84void ieee80211_cancel_scan(struct ieee80211com *); 85void ieee80211_scan_next(struct ieee80211com *); 86 87struct ieee80211_scanparams; 88void ieee80211_add_scan(struct ieee80211com *, 89 const struct ieee80211_scanparams *, 90 const struct ieee80211_frame *, 91 int subtype, int rssi, int noise, int rstamp); 92void ieee80211_scan_timeout(struct ieee80211com *); 93 94void ieee80211_scan_assoc_success(struct ieee80211com *, 95 const uint8_t mac[IEEE80211_ADDR_LEN]); 96enum { 97 IEEE80211_SCAN_FAIL_TIMEOUT = 1, /* no response to mgmt frame */ 98 IEEE80211_SCAN_FAIL_STATUS = 2 /* negative response to " " */ 99}; 100void ieee80211_scan_assoc_fail(struct ieee80211com *, 101 const uint8_t mac[IEEE80211_ADDR_LEN], int reason); 102void ieee80211_scan_flush(struct ieee80211com *); 103 104struct ieee80211_scan_entry; 105typedef void ieee80211_scan_iter_func(void *, 106 const struct ieee80211_scan_entry *); 107void ieee80211_scan_iterate(struct ieee80211com *, 108 ieee80211_scan_iter_func, void *); 109 110/* 111 * Parameters supplied when adding/updating an entry in a 112 * scan cache. Pointer variables should be set to NULL 113 * if no data is available. Pointer references can be to 114 * local data; any information that is saved will be copied. 115 * All multi-byte values must be in host byte order. 116 */ 117struct ieee80211_scanparams { 118 uint16_t capinfo; /* 802.11 capabilities */ 119 uint16_t fhdwell; /* FHSS dwell interval */ 120 uint8_t chan; /* */ 121 uint8_t bchan; 122 uint8_t fhindex; 123 uint8_t erp; 124 uint16_t bintval; 125 uint8_t timoff; 126 uint8_t *tim; 127 uint8_t *tstamp; 128 uint8_t *country; 129 uint8_t *ssid; 130 uint8_t *rates; 131 uint8_t *xrates; 132 uint8_t *doth; 133 uint8_t *wpa; 134 uint8_t *rsn; 135 uint8_t *wme; 136 uint8_t *htcap; 137 uint8_t *htinfo; 138 uint8_t *ath; 139}; 140 141/* 142 * Scan cache entry format used when exporting data from a policy 143 * module; this data may be represented some other way internally. 144 */ 145struct ieee80211_scan_entry { 146 uint8_t se_macaddr[IEEE80211_ADDR_LEN]; 147 uint8_t se_bssid[IEEE80211_ADDR_LEN]; 148 uint8_t se_ssid[2+IEEE80211_NWID_LEN]; 149 uint8_t se_rates[2+IEEE80211_RATE_MAXSIZE]; 150 uint8_t se_xrates[2+IEEE80211_RATE_MAXSIZE]; 151 uint32_t se_rstamp; /* recv timestamp */ 152 union { 153 uint8_t data[8]; 154 uint64_t tsf; 155 } se_tstamp; /* from last rcv'd beacon */ 156 uint16_t se_intval; /* beacon interval (host byte order) */ 157 uint16_t se_capinfo; /* capabilities (host byte order) */ 158 struct ieee80211_channel *se_chan;/* channel where sta found */ 159 uint16_t se_timoff; /* byte offset to TIM ie */ 160 uint16_t se_fhdwell; /* FH only (host byte order) */ 161 uint8_t se_fhindex; /* FH only */ 162 uint8_t se_erp; /* ERP from beacon/probe resp */ 163 int8_t se_rssi; /* avg'd recv ssi */ 164 int8_t se_noise; /* noise floor */ 165 uint8_t se_dtimperiod; /* DTIM period */ 166 uint8_t *se_wpa_ie; /* captured WPA ie */ 167 uint8_t *se_rsn_ie; /* captured RSN ie */ 168 uint8_t *se_wme_ie; /* captured WME ie */ 169 uint8_t *se_htcap_ie; /* captured HTP cap ie */ 170 uint8_t *se_htinfo_ie; /* captured HTP info ie */ 171 uint8_t *se_ath_ie; /* captured Atheros ie */ 172 u_int se_age; /* age of entry (0 on create) */ 173}; 174MALLOC_DECLARE(M_80211_SCAN); 175 176/* 177 * Template for an in-kernel scan policy module. 178 * Modules register with the scanning code and are 179 * typically loaded as needed. 180 */ 181struct ieee80211_scanner { 182 const char *scan_name; /* printable name */ 183 int (*scan_attach)(struct ieee80211_scan_state *); 184 int (*scan_detach)(struct ieee80211_scan_state *); 185 int (*scan_start)(struct ieee80211_scan_state *, 186 struct ieee80211com *); 187 int (*scan_restart)(struct ieee80211_scan_state *, 188 struct ieee80211com *); 189 int (*scan_cancel)(struct ieee80211_scan_state *, 190 struct ieee80211com *); 191 int (*scan_end)(struct ieee80211_scan_state *, 192 struct ieee80211com *); 193 int (*scan_flush)(struct ieee80211_scan_state *); 194 /* add an entry to the cache */ 195 int (*scan_add)(struct ieee80211_scan_state *, 196 const struct ieee80211_scanparams *, 197 const struct ieee80211_frame *, 198 int subtype, int rssi, int noise, int rstamp); 199 /* age and/or purge entries in the cache */ 200 void (*scan_age)(struct ieee80211_scan_state *); 201 /* note that association failed for an entry */ 202 void (*scan_assoc_fail)(struct ieee80211_scan_state *, 203 const uint8_t macaddr[IEEE80211_ADDR_LEN], 204 int reason); 205 /* note that association succeed for an entry */ 206 void (*scan_assoc_success)(struct ieee80211_scan_state *, 207 const uint8_t macaddr[IEEE80211_ADDR_LEN]); 208 /* iterate over entries in the scan cache */ 209 void (*scan_iterate)(struct ieee80211_scan_state *, 210 ieee80211_scan_iter_func *, void *); 211}; 212void ieee80211_scanner_register(enum ieee80211_opmode, 213 const struct ieee80211_scanner *); 214void ieee80211_scanner_unregister(enum ieee80211_opmode, 215 const struct ieee80211_scanner *); 216void ieee80211_scanner_unregister_all(const struct ieee80211_scanner *); 217const struct ieee80211_scanner *ieee80211_scanner_get(enum ieee80211_opmode); 218#endif /* _NET80211_IEEE80211_SCAN_H_ */ 219