1 /*
2  * Driver interface definition
3  * Copyright (c) 2003-2017, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  *
8  * This file defines a driver interface used by both %wpa_supplicant and
9  * hostapd. The first part of the file defines data structures used in various
10  * driver operations. This is followed by the struct wpa_driver_ops that each
11  * driver wrapper will beed to define with callback functions for requesting
12  * driver operations. After this, there are definitions for driver event
13  * reporting with wpa_supplicant_event() and some convenience helper functions
14  * that can be used to report events.
15  */
16 
17 #ifndef DRIVER_H
18 #define DRIVER_H
19 
20 #define WPA_SUPPLICANT_DRIVER_VERSION 4
21 
22 #include "common/defs.h"
23 #include "common/ieee802_11_defs.h"
24 #include "common/wpa_common.h"
25 #include "utils/list.h"
26 struct wpa_bss;
27 struct wpa_supplicant;
28 /**
29  * struct wpa_scan_res - Scan result for an BSS/IBSS
30  * @flags: information flags about the BSS/IBSS (WPA_SCAN_*)
31  * @bssid: BSSID
32  * @freq: frequency of the channel in MHz (e.g., 2412 = channel 1)
33  * @beacon_int: beacon interval in TUs (host byte order)
34  * @caps: capability information field in host byte order
35  * @qual: signal quality
36  * @noise: noise level
37  * @level: signal level
38  * @tsf: Timestamp
39  * @age: Age of the information in milliseconds (i.e., how many milliseconds
40  * ago the last Beacon or Probe Response frame was received)
41  * @snr: Signal-to-noise ratio in dB (calculated during scan result processing)
42  * @parent_tsf: Time when the Beacon/Probe Response frame was received in terms
43  * of TSF of the BSS specified by %tsf_bssid.
44  * @tsf_bssid: The BSS that %parent_tsf TSF time refers to.
45  * @ie_len: length of the following IE field in octets
46  * @beacon_ie_len: length of the following Beacon IE field in octets
47  *
48  * This structure is used as a generic format for scan results from the
49  * driver. Each driver interface implementation is responsible for converting
50  * the driver or OS specific scan results into this format.
51  *
52  * If the driver does not support reporting all IEs, the IE data structure is
53  * constructed of the IEs that are available. This field will also need to
54  * include SSID in IE format. All drivers are encouraged to be extended to
55  * report all IEs to make it easier to support future additions.
56  *
57  * This structure data is followed by ie_len octets of IEs from Probe Response
58  * frame (or if the driver does not indicate source of IEs, these may also be
59  * from Beacon frame). After the first set of IEs, another set of IEs may follow
60  * (with beacon_ie_len octets of data) if the driver provides both IE sets.
61  */
62 struct wpa_scan_res {
63 	unsigned int flags;
64 	u8 bssid[ETH_ALEN];
65 	int chan;
66 	u16 beacon_int;
67 	u16 caps;
68 	int noise;
69 	int level;
70 	u64 tsf;
71 	unsigned int age;
72 	u64 parent_tsf;
73 	u8 tsf_bssid[ETH_ALEN];
74 	size_t ie_len;
75 	size_t beacon_ie_len;
76 	/* Followed by ie_len + beacon_ie_len octets of IE data */
77 };
78 
79 /**
80  * struct wpa_scan_results - Scan results
81  * @res: Array of pointers to allocated variable length scan result entries
82  * @num: Number of entries in the scan result array
83  * @fetch_time: Time when the results were fetched from the driver
84  */
85 struct wpa_scan_results {
86 	struct wpa_scan_res **res;
87 	size_t num;
88 	struct os_reltime fetch_time;
89 };
90 
91 #define WPAS_MAX_SCAN_SSIDS 1
92 
93 /**
94  * struct wpa_driver_scan_ssid - SSIDs to scan for
95  * @ssid - specific SSID to scan for (ProbeReq)
96  *	%NULL or zero-length SSID is used to indicate active scan
97  *	with wildcard SSID.
98  * @ssid_len - Length of the SSID in octets
99  */
100 struct wpa_driver_scan_ssid {
101 	const u8 *ssid;
102 	size_t ssid_len;
103 };
104 
105 /**
106  * struct wpa_driver_scan_params - Scan parameters
107  * Data for struct wpa_driver_ops::scan2().
108  */
109 struct wpa_driver_scan_params {
110 	/**
111 	 * ssids - SSIDs to scan for
112 	 */
113 	struct wpa_driver_scan_ssid ssids[WPAS_MAX_SCAN_SSIDS];
114 
115 	/**
116 	 * num_ssids - Number of entries in ssids array
117 	 * Zero indicates a request for a passive scan.
118 	 */
119 	size_t num_ssids;
120 
121 	/**
122 	 * freqs - Array of frequencies to scan or %NULL for all frequencies
123 	 *
124 	 * The frequency is set in MHz. The array is zero-terminated.
125 	 */
126 	int channel;
127 
128 	/**
129 	 * bssid - Specific BSSID to scan for
130 	 *
131 	 * This optional parameter can be used to replace the default wildcard
132 	 * BSSID with a specific BSSID to scan for if results are needed from
133 	 * only a single BSS.
134 	 */
135 	const u8 *bssid;
136 
137 	 /**
138 	  * duration - Dwell time on each channel
139 	  *
140 	  * This optional parameter can be used to set the dwell time on each
141 	  * channel. In TUs.
142 	  */
143 	 u16 duration;
144 
145 	 unsigned int duration_mandatory;
146 	 u8 mode;
147 };
148 
149 /**
150  * struct scan_info - Optional data for EVENT_SCAN_RESULTS events
151  * @aborted: Whether the scan was aborted
152  * @freqs: Scanned frequencies in MHz (%NULL = all channels scanned)
153  * @num_freqs: Number of entries in freqs array
154  * @ssids: Scanned SSIDs (%NULL or zero-length SSID indicates wildcard
155  *	SSID)
156  * @num_ssids: Number of entries in ssids array
157  * @external_scan: Whether the scan info is for an external scan
158  * @nl_scan_event: 1 if the source of this scan event is a normal scan,
159  * 	0 if the source of the scan event is a vendor scan
160  * @scan_start_tsf: Time when the scan started in terms of TSF of the
161  *	BSS that the interface that requested the scan is connected to
162  *	(if available).
163  * @scan_start_tsf_bssid: The BSSID according to which %scan_start_tsf
164  *	is set.
165  */
166 struct scan_info {
167 	int aborted;
168 	const int *freqs;
169 	size_t num_freqs;
170 	struct wpa_driver_scan_ssid ssids[WPAS_MAX_SCAN_SSIDS];
171 	size_t num_ssids;
172 	int external_scan;
173 	int nl_scan_event;
174 	u64 scan_start_tsf;
175 	u8 scan_start_tsf_bssid[ETH_ALEN];
176 } scan_info;
177 
178 struct wpa_bss_trans_info {
179 	u8 mbo_transition_reason;
180 	u8 n_candidates;
181 	u8 *bssid;
182 };
183 
184 struct wpa_bss_candidate_info {
185 	u8 num;
186 	struct candidate_list {
187 		u8 bssid[ETH_ALEN];
188 		u8 is_accept;
189 		u32 reject_reason;
190 	} *candidates;
191 };
192 
193 /* driver_common.c */
194 void wpa_scan_results_free(struct wpa_scan_results *res);
195 
196 int wpa_drv_send_action(struct wpa_supplicant *wpa_s,
197 			unsigned int chan, unsigned int wait,
198 			const u8 *data, size_t data_len, int no_cck);
199 
200 void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
201 			    struct wpa_bss *bss, char *ssid);
202 #endif /* DRIVER_H */
203