xref: /freebsd/sys/net80211/ieee80211_scan.h (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
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$
26  */
27 #ifndef _NET80211_IEEE80211_SCAN_H_
28 #define _NET80211_IEEE80211_SCAN_H_
29 
30 #define	IEEE80211_SCAN_MAX	IEEE80211_CHAN_MAX
31 
32 struct ieee80211_scanner;
33 
34 struct 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 
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 */
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 
71 struct ieee80211com;
72 void	ieee80211_scan_attach(struct ieee80211com *);
73 void	ieee80211_scan_detach(struct ieee80211com *);
74 
75 void	ieee80211_scan_dump_channels(const struct ieee80211_scan_state *);
76 
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 *);
87 
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 *);
94 
95 void	ieee80211_scan_assoc_success(struct ieee80211com *,
96 		const uint8_t mac[IEEE80211_ADDR_LEN]);
97 enum {
98 	IEEE80211_SCAN_FAIL_TIMEOUT	= 1,	/* no response to mgmt frame */
99 	IEEE80211_SCAN_FAIL_STATUS	= 2	/* negative response to " " */
100 };
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 *);
104 
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 *);
110 
111 /*
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.
117  */
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 */
123 	uint8_t		fhindex;
124 	uint8_t		erp;
125 	uint16_t	bintval;
126 	uint8_t		timoff;
127 	uint8_t		*tim;
128 	uint8_t		*tstamp;
129 	uint8_t		*country;
130 	uint8_t		*ssid;
131 	uint8_t		*rates;
132 	uint8_t		*xrates;
133 	uint8_t		*doth;
134 	uint8_t		*wpa;
135 	uint8_t		*rsn;
136 	uint8_t		*wme;
137 	uint8_t		*htcap;
138 	uint8_t		*htinfo;
139 	uint8_t		*ath;
140 };
141 
142 /*
143  * Scan cache entry format used when exporting data from a policy
144  * module; this data may be represented some other way internally.
145  */
146 struct ieee80211_scan_entry {
147 	uint8_t		se_macaddr[IEEE80211_ADDR_LEN];
148 	uint8_t		se_bssid[IEEE80211_ADDR_LEN];
149 	uint8_t		se_ssid[2+IEEE80211_NWID_LEN];
150 	uint8_t		se_rates[2+IEEE80211_RATE_MAXSIZE];
151 	uint8_t		se_xrates[2+IEEE80211_RATE_MAXSIZE];
152 	uint32_t	se_rstamp;	/* recv timestamp */
153 	union {
154 		uint8_t		data[8];
155 		uint64_t	tsf;
156 	} se_tstamp;			/* from last rcv'd beacon */
157 	uint16_t	se_intval;	/* beacon interval (host byte order) */
158 	uint16_t	se_capinfo;	/* capabilities (host byte order) */
159 	struct ieee80211_channel *se_chan;/* channel where sta found */
160 	uint16_t	se_timoff;	/* byte offset to TIM ie */
161 	uint16_t	se_fhdwell;	/* FH only (host byte order) */
162 	uint8_t		se_fhindex;	/* FH only */
163 	uint8_t		se_erp;		/* ERP from beacon/probe resp */
164 	int8_t		se_rssi;	/* avg'd recv ssi */
165 	int8_t		se_noise;	/* noise floor */
166 	uint8_t		se_dtimperiod;	/* DTIM period */
167 	uint8_t		*se_wpa_ie;	/* captured WPA ie */
168 	uint8_t		*se_rsn_ie;	/* captured RSN ie */
169 	uint8_t		*se_wme_ie;	/* captured WME ie */
170 	uint8_t		*se_htcap_ie;	/* captured HTP cap ie */
171 	uint8_t		*se_htinfo_ie;	/* captured HTP info ie */
172 	uint8_t		*se_ath_ie;	/* captured Atheros ie */
173 	u_int		se_age;		/* age of entry (0 on create) */
174 };
175 MALLOC_DECLARE(M_80211_SCAN);
176 
177 /*
178  * Template for an in-kernel scan policy module.
179  * Modules register with the scanning code and are
180  * typically loaded as needed.
181  */
182 struct ieee80211_scanner {
183 	const char *scan_name;		/* printable name */
184 	int	(*scan_attach)(struct ieee80211_scan_state *);
185 	int	(*scan_detach)(struct ieee80211_scan_state *);
186 	int	(*scan_start)(struct ieee80211_scan_state *,
187 			struct ieee80211com *);
188 	int	(*scan_restart)(struct ieee80211_scan_state *,
189 			struct ieee80211com *);
190 	int	(*scan_cancel)(struct ieee80211_scan_state *,
191 			struct ieee80211com *);
192 	int	(*scan_end)(struct ieee80211_scan_state *,
193 			struct ieee80211com *);
194 	int	(*scan_flush)(struct ieee80211_scan_state *);
195 	/* add an entry to the cache */
196 	int	(*scan_add)(struct ieee80211_scan_state *,
197 			const struct ieee80211_scanparams *,
198 			const struct ieee80211_frame *,
199 			int subtype, int rssi, int noise, int rstamp);
200 	/* age and/or purge entries in the cache */
201 	void	(*scan_age)(struct ieee80211_scan_state *);
202 	/* note that association failed for an entry */
203 	void	(*scan_assoc_fail)(struct ieee80211_scan_state *,
204 			const uint8_t macaddr[IEEE80211_ADDR_LEN],
205 			int reason);
206 	/* note that association succeed for an entry */
207 	void	(*scan_assoc_success)(struct ieee80211_scan_state *,
208 			const uint8_t macaddr[IEEE80211_ADDR_LEN]);
209 	/* iterate over entries in the scan cache */
210 	void	(*scan_iterate)(struct ieee80211_scan_state *,
211 			ieee80211_scan_iter_func *, void *);
212 };
213 void	ieee80211_scanner_register(enum ieee80211_opmode,
214 		const struct ieee80211_scanner *);
215 void	ieee80211_scanner_unregister(enum ieee80211_opmode,
216 		const struct ieee80211_scanner *);
217 void	ieee80211_scanner_unregister_all(const struct ieee80211_scanner *);
218 const struct ieee80211_scanner *ieee80211_scanner_get(enum ieee80211_opmode);
219 #endif /* _NET80211_IEEE80211_SCAN_H_ */
220