2 * Copyright (c) 2005-2007 Sam Leffler, Errno Consulting
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef _NET80211_IEEE80211_SCAN_H_
28 #define _NET80211_IEEE80211_SCAN_H_
30 #define IEEE80211_SCAN_MAX IEEE80211_CHAN_MAX
32 struct ieee80211_scanner;
34 struct ieee80211_scan_ssid {
35 int len; /* length in bytes */
36 uint8_t ssid[IEEE80211_NWID_LEN]; /* ssid contents */
38 #define IEEE80211_SCAN_MAX_SSID 1
40 struct 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 */
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 */
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.
68 #define IEEE80211_SCAN_FLUSH 0x10000 /* flush candidate table */
69 #define IEEE80211_SCAN_NOSSID 0x20000 /* don't update ssid list */
72 void ieee80211_scan_attach(struct ieee80211com *);
73 void ieee80211_scan_detach(struct ieee80211com *);
75 void ieee80211_scan_dump_channels(const struct ieee80211_scan_state *);
77 int ieee80211_scan_update(struct ieee80211com *);
78 #define IEEE80211_SCAN_FOREVER 0x7fffffff
79 int ieee80211_start_scan(struct ieee80211com *, int flags, u_int duration,
80 u_int nssid, const struct ieee80211_scan_ssid ssids[]);
81 int ieee80211_check_scan(struct ieee80211com *, int flags, u_int duration,
82 u_int nssid, const struct ieee80211_scan_ssid ssids[]);
83 int ieee80211_bg_scan(struct ieee80211com *);
84 void ieee80211_cancel_scan(struct ieee80211com *);
85 void ieee80211_scan_next(struct ieee80211com *);
86 void ieee80211_scan_done(struct ieee80211com *);
88 struct ieee80211_scanparams;
89 void ieee80211_add_scan(struct ieee80211com *,
90 const struct ieee80211_scanparams *,
91 const struct ieee80211_frame *,
92 int subtype, int rssi, int noise, int rstamp);
93 void ieee80211_scan_timeout(struct ieee80211com *);
95 void ieee80211_scan_assoc_success(struct ieee80211com *,
96 const uint8_t mac[IEEE80211_ADDR_LEN]);
98 IEEE80211_SCAN_FAIL_TIMEOUT = 1, /* no response to mgmt frame */
99 IEEE80211_SCAN_FAIL_STATUS = 2 /* negative response to " " */
101 void ieee80211_scan_assoc_fail(struct ieee80211com *,
102 const uint8_t mac[IEEE80211_ADDR_LEN], int reason);
103 void ieee80211_scan_flush(struct ieee80211com *);
105 struct ieee80211_scan_entry;
106 typedef void ieee80211_scan_iter_func(void *,
107 const struct ieee80211_scan_entry *);
108 void ieee80211_scan_iterate(struct ieee80211com *,
109 ieee80211_scan_iter_func, void *);
112 * Parameters supplied when adding/updating an entry in a
113 * scan cache. Pointer variables should be set to NULL
114 * if no data is available. Pointer references can be to
115 * local data; any information that is saved will be copied.
116 * All multi-byte values must be in host byte order.
118 struct ieee80211_scanparams {
119 uint16_t capinfo; /* 802.11 capabilities */
120 uint16_t fhdwell; /* FHSS dwell interval */
121 struct ieee80211_channel *curchan;
122 uint8_t bchan; /* chan# advertised inside beacon */
127 uint8_t *ies; /* all captured ies */
128 size_t ies_len; /* length of all captured ies */
145 * Scan cache entry format used when exporting data from a policy
146 * module; this data may be represented some other way internally.
148 struct ieee80211_scan_entry {
149 uint8_t se_macaddr[IEEE80211_ADDR_LEN];
150 uint8_t se_bssid[IEEE80211_ADDR_LEN];
151 /* XXX can point inside se_ies */
152 uint8_t se_ssid[2+IEEE80211_NWID_LEN];
153 uint8_t se_rates[2+IEEE80211_RATE_MAXSIZE];
154 uint8_t se_xrates[2+IEEE80211_RATE_MAXSIZE];
155 uint32_t se_rstamp; /* recv timestamp */
159 } se_tstamp; /* from last rcv'd beacon */
160 uint16_t se_intval; /* beacon interval (host byte order) */
161 uint16_t se_capinfo; /* capabilities (host byte order) */
162 struct ieee80211_channel *se_chan;/* channel where sta found */
163 uint16_t se_timoff; /* byte offset to TIM ie */
164 uint16_t se_fhdwell; /* FH only (host byte order) */
165 uint8_t se_fhindex; /* FH only */
166 uint8_t se_erp; /* ERP from beacon/probe resp */
167 int8_t se_rssi; /* avg'd recv ssi */
168 int8_t se_noise; /* noise floor */
169 uint8_t se_dtimperiod; /* DTIM period */
170 struct ieee80211_ies se_ies; /* captured ie's */
171 u_int se_age; /* age of entry (0 on create) */
173 MALLOC_DECLARE(M_80211_SCAN);
176 * Template for an in-kernel scan policy module.
177 * Modules register with the scanning code and are
178 * typically loaded as needed.
180 struct ieee80211_scanner {
181 const char *scan_name; /* printable name */
182 int (*scan_attach)(struct ieee80211_scan_state *);
183 int (*scan_detach)(struct ieee80211_scan_state *);
184 int (*scan_start)(struct ieee80211_scan_state *,
185 struct ieee80211com *);
186 int (*scan_restart)(struct ieee80211_scan_state *,
187 struct ieee80211com *);
188 int (*scan_cancel)(struct ieee80211_scan_state *,
189 struct ieee80211com *);
190 int (*scan_end)(struct ieee80211_scan_state *,
191 struct ieee80211com *);
192 int (*scan_flush)(struct ieee80211_scan_state *);
193 /* add an entry to the cache */
194 int (*scan_add)(struct ieee80211_scan_state *,
195 const struct ieee80211_scanparams *,
196 const struct ieee80211_frame *,
197 int subtype, int rssi, int noise, int rstamp);
198 /* age and/or purge entries in the cache */
199 void (*scan_age)(struct ieee80211_scan_state *);
200 /* note that association failed for an entry */
201 void (*scan_assoc_fail)(struct ieee80211_scan_state *,
202 const uint8_t macaddr[IEEE80211_ADDR_LEN],
204 /* note that association succeed for an entry */
205 void (*scan_assoc_success)(struct ieee80211_scan_state *,
206 const uint8_t macaddr[IEEE80211_ADDR_LEN]);
207 /* iterate over entries in the scan cache */
208 void (*scan_iterate)(struct ieee80211_scan_state *,
209 ieee80211_scan_iter_func *, void *);
211 void ieee80211_scanner_register(enum ieee80211_opmode,
212 const struct ieee80211_scanner *);
213 void ieee80211_scanner_unregister(enum ieee80211_opmode,
214 const struct ieee80211_scanner *);
215 void ieee80211_scanner_unregister_all(const struct ieee80211_scanner *);
216 const struct ieee80211_scanner *ieee80211_scanner_get(enum ieee80211_opmode);
217 #endif /* _NET80211_IEEE80211_SCAN_H_ */