Fix MCS set field to be based on driver info
[libeap.git] / src / drivers / driver.h
1 /*
2  * WPA Supplicant - driver interface definition
3  * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #ifndef DRIVER_H
16 #define DRIVER_H
17
18 #define WPA_SUPPLICANT_DRIVER_VERSION 3
19
20 #include "defs.h"
21
22 #define HOSTAPD_CHAN_DISABLED 0x00000001
23 #define HOSTAPD_CHAN_PASSIVE_SCAN 0x00000002
24 #define HOSTAPD_CHAN_NO_IBSS 0x00000004
25 #define HOSTAPD_CHAN_RADAR 0x00000008
26
27 struct hostapd_channel_data {
28         short chan; /* channel number (IEEE 802.11) */
29         short freq; /* frequency in MHz */
30         int flag; /* flag for hostapd use (HOSTAPD_CHAN_*) */
31         u8 max_tx_power; /* maximum transmit power in dBm */
32 };
33
34 #define HOSTAPD_RATE_ERP 0x00000001
35 #define HOSTAPD_RATE_BASIC 0x00000002
36 #define HOSTAPD_RATE_PREAMBLE2 0x00000004
37 #define HOSTAPD_RATE_SUPPORTED 0x00000010
38 #define HOSTAPD_RATE_OFDM 0x00000020
39 #define HOSTAPD_RATE_CCK 0x00000040
40 #define HOSTAPD_RATE_MANDATORY 0x00000100
41
42 struct hostapd_rate_data {
43         int rate; /* rate in 100 kbps */
44         int flags; /* HOSTAPD_RATE_ flags */
45 };
46
47 struct hostapd_hw_modes {
48         hostapd_hw_mode mode;
49         int num_channels;
50         struct hostapd_channel_data *channels;
51         int num_rates;
52         struct hostapd_rate_data *rates;
53         u16 ht_capab;
54         u8 mcs_set[16];
55 };
56
57
58 #define AUTH_ALG_OPEN_SYSTEM    0x01
59 #define AUTH_ALG_SHARED_KEY     0x02
60 #define AUTH_ALG_LEAP           0x04
61 #define AUTH_ALG_FT             0x08
62
63 #define IEEE80211_MODE_INFRA    0
64 #define IEEE80211_MODE_IBSS     1
65 #define IEEE80211_MODE_AP       2
66
67 #define IEEE80211_CAP_ESS       0x0001
68 #define IEEE80211_CAP_IBSS      0x0002
69 #define IEEE80211_CAP_PRIVACY   0x0010
70
71 #define SSID_MAX_WPA_IE_LEN 40
72 /**
73  * struct wpa_scan_result - Scan results (old structure)
74  * @bssid: BSSID
75  * @ssid: SSID
76  * @ssid_len: length of the ssid
77  * @wpa_ie: WPA IE
78  * @wpa_ie_len: length of the wpa_ie
79  * @rsn_ie: RSN IE
80  * @rsn_ie_len: length of the RSN IE
81  * @freq: frequency of the channel in MHz (e.g., 2412 = channel 1)
82  * @caps: capability information field in host byte order
83  * @qual: signal quality
84  * @noise: noise level
85  * @level: signal level
86  * @maxrate: maximum supported rate
87  * @mdie_present: Whether MDIE was included in Beacon/ProbeRsp frame
88  * @mdie: Mobility domain identifier IE (IEEE 802.11r MDIE) (starting from
89  * IE type field)
90  * @tsf: Timestamp
91  *
92  * This structure is used as a generic format for scan results from the
93  * driver. Each driver interface implementation is responsible for converting
94  * the driver or OS specific scan results into this format.
95  *
96  * This structure is the old data structure used for scan results. It is
97  * obsoleted by the new struct wpa_scan_res structure and the old version is
98  * only included for backwards compatibility with existing driver wrapper
99  * implementations. New implementations are encouraged to implement for struct
100  * wpa_scan_res. The old structure will be removed at some point.
101  */
102 struct wpa_scan_result {
103         u8 bssid[ETH_ALEN];
104         u8 ssid[32];
105         size_t ssid_len;
106         u8 wpa_ie[SSID_MAX_WPA_IE_LEN];
107         size_t wpa_ie_len;
108         u8 rsn_ie[SSID_MAX_WPA_IE_LEN];
109         size_t rsn_ie_len;
110         int freq;
111         u16 caps;
112         int qual;
113         int noise;
114         int level;
115         int maxrate;
116         int mdie_present;
117         u8 mdie[5];
118         u64 tsf;
119 };
120
121
122 #define WPA_SCAN_QUAL_INVALID           BIT(0)
123 #define WPA_SCAN_NOISE_INVALID          BIT(1)
124 #define WPA_SCAN_LEVEL_INVALID          BIT(2)
125 #define WPA_SCAN_LEVEL_DBM              BIT(3)
126
127 /**
128  * struct wpa_scan_res - Scan result for an BSS/IBSS
129  * @flags: information flags about the BSS/IBSS (WPA_SCAN_*)
130  * @bssid: BSSID
131  * @freq: frequency of the channel in MHz (e.g., 2412 = channel 1)
132  * @beacon_int: beacon interval in TUs (host byte order)
133  * @caps: capability information field in host byte order
134  * @qual: signal quality
135  * @noise: noise level
136  * @level: signal level
137  * @tsf: Timestamp
138  * @age: Age of the information in milliseconds (i.e., how many milliseconds
139  * ago the last Beacon or Probe Response frame was received)
140  * @ie_len: length of the following IE field in octets
141  *
142  * This structure is used as a generic format for scan results from the
143  * driver. Each driver interface implementation is responsible for converting
144  * the driver or OS specific scan results into this format.
145  *
146  * If the driver does not support reporting all IEs, the IE data structure is
147  * constructed of the IEs that are available. This field will also need to
148  * include SSID in IE format. All drivers are encouraged to be extended to
149  * report all IEs to make it easier to support future additions.
150  */
151 struct wpa_scan_res {
152         unsigned int flags;
153         u8 bssid[ETH_ALEN];
154         int freq;
155         u16 beacon_int;
156         u16 caps;
157         int qual;
158         int noise;
159         int level;
160         u64 tsf;
161         unsigned int age;
162         size_t ie_len;
163         /* followed by ie_len octets of IEs */
164 };
165
166 /**
167  * struct wpa_scan_results - Scan results
168  * @res: Array of pointers to allocated variable length scan result entries
169  * @num: Number of entries in the scan result array
170  */
171 struct wpa_scan_results {
172         struct wpa_scan_res **res;
173         size_t num;
174 };
175
176 /**
177  * struct wpa_interface_info - Network interface information
178  * @next: Pointer to the next interface or NULL if this is the last one
179  * @ifname: Interface name that can be used with init() or init2()
180  * @desc: Human readable adapter description (e.g., vendor/model) or NULL if
181  *      not available
182  * @drv_bame: struct wpa_driver_ops::name (note: unlike other strings, this one
183  *      is not an allocated copy, i.e., get_interfaces() caller will not free
184  *      this)
185  */
186 struct wpa_interface_info {
187         struct wpa_interface_info *next;
188         char *ifname;
189         char *desc;
190         const char *drv_name;
191 };
192
193 #define WPAS_MAX_SCAN_SSIDS 4
194
195 /**
196  * struct wpa_driver_scan_params - Scan parameters
197  * Data for struct wpa_driver_ops::scan2().
198  */
199 struct wpa_driver_scan_params {
200         /**
201          * ssids - SSIDs to scan for
202          */
203         struct wpa_driver_scan_ssid {
204                 /**
205                  * ssid - specific SSID to scan for (ProbeReq)
206                  * %NULL or zero-length SSID is used to indicate active scan
207                  * with wildcard SSID.
208                  */
209                 const u8 *ssid;
210                 /**
211                  * ssid_len: Length of the SSID in octets
212                  */
213                 size_t ssid_len;
214         } ssids[WPAS_MAX_SCAN_SSIDS];
215
216         /**
217          * num_ssids - Number of entries in ssids array
218          * Zero indicates a request for a passive scan.
219          */
220         size_t num_ssids;
221
222         /**
223          * extra_ies - Extra IE(s) to add into Probe Request or %NULL
224          */
225         const u8 *extra_ies;
226
227         /**
228          * extra_ies_len - Length of extra_ies in octets
229          */
230         size_t extra_ies_len;
231
232         /**
233          * freqs - Array of frequencies to scan or %NULL for all frequencies
234          *
235          * The frequency is set in MHz. The array is zero-terminated.
236          */
237         int *freqs;
238 };
239
240 /**
241  * struct wpa_driver_auth_params - Authentication parameters
242  * Data for struct wpa_driver_ops::authenticate().
243  */
244 struct wpa_driver_auth_params {
245         int freq;
246         const u8 *bssid;
247         const u8 *ssid;
248         size_t ssid_len;
249         int auth_alg;
250         const u8 *ie;
251         size_t ie_len;
252         const u8 *wep_key[4];
253         size_t wep_key_len[4];
254         int wep_tx_keyidx;
255 };
256
257 /**
258  * struct wpa_driver_associate_params - Association parameters
259  * Data for struct wpa_driver_ops::associate().
260  */
261 struct wpa_driver_associate_params {
262         /**
263          * bssid - BSSID of the selected AP
264          * This can be %NULL, if ap_scan=2 mode is used and the driver is
265          * responsible for selecting with which BSS to associate. */
266         const u8 *bssid;
267
268         /**
269          * ssid - The selected SSID
270          */
271         const u8 *ssid;
272         size_t ssid_len;
273
274         /**
275          * freq - Frequency of the channel the selected AP is using
276          * Frequency that the selected AP is using (in MHz as
277          * reported in the scan results)
278          */
279         int freq;
280
281         /**
282          * wpa_ie - WPA information element for (Re)Association Request
283          * WPA information element to be included in (Re)Association
284          * Request (including information element id and length). Use
285          * of this WPA IE is optional. If the driver generates the WPA
286          * IE, it can use pairwise_suite, group_suite, and
287          * key_mgmt_suite to select proper algorithms. In this case,
288          * the driver has to notify wpa_supplicant about the used WPA
289          * IE by generating an event that the interface code will
290          * convert into EVENT_ASSOCINFO data (see below).
291          *
292          * When using WPA2/IEEE 802.11i, wpa_ie is used for RSN IE
293          * instead. The driver can determine which version is used by
294          * looking at the first byte of the IE (0xdd for WPA, 0x30 for
295          * WPA2/RSN).
296          *
297          * When using WPS, wpa_ie is used for WPS IE instead of WPA/RSN IE.
298          */
299         const u8 *wpa_ie;
300         /**
301          * wpa_ie_len - length of the wpa_ie
302          */
303         size_t wpa_ie_len;
304
305         /* The selected pairwise/group cipher and key management
306          * suites. These are usually ignored if @wpa_ie is used. */
307         wpa_cipher pairwise_suite;
308         wpa_cipher group_suite;
309         wpa_key_mgmt key_mgmt_suite;
310
311         /**
312          * auth_alg - Allowed authentication algorithms
313          * Bit field of AUTH_ALG_*
314          */
315         int auth_alg;
316
317         /**
318          * mode - Operation mode (infra/ibss) IEEE80211_MODE_*
319          */
320         int mode;
321
322         /**
323          * wep_key - WEP keys for static WEP configuration
324          */
325         const u8 *wep_key[4];
326
327         /**
328          * wep_key_len - WEP key length for static WEP configuration
329          */
330         size_t wep_key_len[4];
331
332         /**
333          * wep_tx_keyidx - WEP TX key index for static WEP configuration
334          */
335         int wep_tx_keyidx;
336
337         /**
338          * mgmt_frame_protection - IEEE 802.11w management frame protection
339          */
340         enum {
341                 NO_MGMT_FRAME_PROTECTION,
342                 MGMT_FRAME_PROTECTION_OPTIONAL,
343                 MGMT_FRAME_PROTECTION_REQUIRED
344         } mgmt_frame_protection;
345
346         /**
347          * ft_ies - IEEE 802.11r / FT information elements
348          * If the supplicant is using IEEE 802.11r (FT) and has the needed keys
349          * for fast transition, this parameter is set to include the IEs that
350          * are to be sent in the next FT Authentication Request message.
351          * update_ft_ies() handler is called to update the IEs for further
352          * FT messages in the sequence.
353          *
354          * The driver should use these IEs only if the target AP is advertising
355          * the same mobility domain as the one included in the MDIE here.
356          *
357          * In ap_scan=2 mode, the driver can use these IEs when moving to a new
358          * AP after the initial association. These IEs can only be used if the
359          * target AP is advertising support for FT and is using the same MDIE
360          * and SSID as the current AP.
361          *
362          * The driver is responsible for reporting the FT IEs received from the
363          * AP's response using wpa_supplicant_event() with EVENT_FT_RESPONSE
364          * type. update_ft_ies() handler will then be called with the FT IEs to
365          * include in the next frame in the authentication sequence.
366          */
367         const u8 *ft_ies;
368
369         /**
370          * ft_ies_len - Length of ft_ies in bytes
371          */
372         size_t ft_ies_len;
373
374         /**
375          * ft_md - FT Mobility domain (6 octets) (also included inside ft_ies)
376          *
377          * This value is provided to allow the driver interface easier access
378          * to the current mobility domain. This value is set to %NULL if no
379          * mobility domain is currently active.
380          */
381         const u8 *ft_md;
382
383         /**
384          * passphrase - RSN passphrase for PSK
385          *
386          * This value is made available only for WPA/WPA2-Personal (PSK) and
387          * only for drivers that set WPA_DRIVER_FLAGS_4WAY_HANDSHAKE. This is
388          * the 8..63 character ASCII passphrase, if available. Please note that
389          * this can be %NULL if passphrase was not used to generate the PSK. In
390          * that case, the psk field must be used to fetch the PSK.
391          */
392         const char *passphrase;
393
394         /**
395          * psk - RSN PSK (alternative for passphrase for PSK)
396          *
397          * This value is made available only for WPA/WPA2-Personal (PSK) and
398          * only for drivers that set WPA_DRIVER_FLAGS_4WAY_HANDSHAKE. This is
399          * the 32-octet (256-bit) PSK, if available. The driver wrapper should
400          * be prepared to handle %NULL value as an error.
401          */
402         const u8 *psk;
403
404         /**
405          * drop_unencrypted - Enable/disable unencrypted frame filtering
406          *
407          * Configure the driver to drop all non-EAPOL frames (both receive and
408          * transmit paths). Unencrypted EAPOL frames (ethertype 0x888e) must
409          * still be allowed for key negotiation.
410          */
411         int drop_unencrypted;
412 };
413
414 /**
415  * struct wpa_driver_capa - Driver capability information
416  */
417 struct wpa_driver_capa {
418 #define WPA_DRIVER_CAPA_KEY_MGMT_WPA            0x00000001
419 #define WPA_DRIVER_CAPA_KEY_MGMT_WPA2           0x00000002
420 #define WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK        0x00000004
421 #define WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK       0x00000008
422 #define WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE       0x00000010
423 #define WPA_DRIVER_CAPA_KEY_MGMT_FT             0x00000020
424 #define WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK         0x00000040
425         unsigned int key_mgmt;
426
427 #define WPA_DRIVER_CAPA_ENC_WEP40       0x00000001
428 #define WPA_DRIVER_CAPA_ENC_WEP104      0x00000002
429 #define WPA_DRIVER_CAPA_ENC_TKIP        0x00000004
430 #define WPA_DRIVER_CAPA_ENC_CCMP        0x00000008
431         unsigned int enc;
432
433 #define WPA_DRIVER_AUTH_OPEN            0x00000001
434 #define WPA_DRIVER_AUTH_SHARED          0x00000002
435 #define WPA_DRIVER_AUTH_LEAP            0x00000004
436         unsigned int auth;
437
438 /* Driver generated WPA/RSN IE */
439 #define WPA_DRIVER_FLAGS_DRIVER_IE      0x00000001
440 /* Driver needs static WEP key setup after association command */
441 #define WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC 0x00000002
442 #define WPA_DRIVER_FLAGS_USER_SPACE_MLME 0x00000004
443 /* Driver takes care of RSN 4-way handshake internally; PMK is configured with
444  * struct wpa_driver_ops::set_key using alg = WPA_ALG_PMK */
445 #define WPA_DRIVER_FLAGS_4WAY_HANDSHAKE 0x00000008
446 #define WPA_DRIVER_FLAGS_WIRED          0x00000010
447 /* Driver provides separate commands for authentication and association (SME in
448  * wpa_supplicant). */
449 #define WPA_DRIVER_FLAGS_SME            0x00000020
450 /* Driver supports AP mode */
451 #define WPA_DRIVER_FLAGS_AP             0x00000040
452 /* Driver needs static WEP key setup after association has been completed */
453 #define WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE      0x00000080
454         unsigned int flags;
455
456         int max_scan_ssids;
457 };
458
459
460 struct ieee80211_rx_status {
461         int channel;
462         int ssi;
463 };
464
465
466 struct hostapd_data;
467
468 struct hostap_sta_driver_data {
469         unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes;
470         unsigned long current_tx_rate;
471         unsigned long inactive_msec;
472         unsigned long flags;
473         unsigned long num_ps_buf_frames;
474         unsigned long tx_retry_failed;
475         unsigned long tx_retry_count;
476         int last_rssi;
477         int last_ack_rssi;
478 };
479
480 struct hostapd_sta_add_params {
481         const u8 *addr;
482         u16 aid;
483         u16 capability;
484         const u8 *supp_rates;
485         size_t supp_rates_len;
486         int flags;
487         u16 listen_interval;
488         const struct ht_cap_ie *ht_capabilities;
489 };
490
491 struct hostapd_freq_params {
492         int mode;
493         int freq;
494         int channel;
495         int ht_enabled;
496         int sec_channel_offset; /* 0 = HT40 disabled, -1 = HT40 enabled,
497                                  * secondary channel below primary, 1 = HT40
498                                  * enabled, secondary channel above primary */
499 };
500
501 enum hostapd_driver_if_type {
502         HOSTAPD_IF_VLAN
503 };
504
505 struct wpa_init_params {
506         const u8 *bssid;
507         const char *ifname;
508         const u8 *ssid;
509         size_t ssid_len;
510         const char *test_socket;
511         int use_pae_group_addr;
512         char **bridge;
513         size_t num_bridge;
514
515         u8 *own_addr; /* buffer for writing own MAC address */
516 };
517
518
519 /**
520  * struct wpa_driver_ops - Driver interface API definition
521  *
522  * This structure defines the API that each driver interface needs to implement
523  * for core wpa_supplicant code. All driver specific functionality is captured
524  * in this wrapper.
525  */
526 struct wpa_driver_ops {
527         /** Name of the driver interface */
528         const char *name;
529         /** One line description of the driver interface */
530         const char *desc;
531
532         /**
533          * get_bssid - Get the current BSSID
534          * @priv: private driver interface data
535          * @bssid: buffer for BSSID (ETH_ALEN = 6 bytes)
536          *
537          * Returns: 0 on success, -1 on failure
538          *
539          * Query kernel driver for the current BSSID and copy it to bssid.
540          * Setting bssid to 00:00:00:00:00:00 is recommended if the STA is not
541          * associated.
542          */
543         int (*get_bssid)(void *priv, u8 *bssid);
544
545         /**
546          * get_ssid - Get the current SSID
547          * @priv: private driver interface data
548          * @ssid: buffer for SSID (at least 32 bytes)
549          *
550          * Returns: Length of the SSID on success, -1 on failure
551          *
552          * Query kernel driver for the current SSID and copy it to ssid.
553          * Returning zero is recommended if the STA is not associated.
554          *
555          * Note: SSID is an array of octets, i.e., it is not nul terminated and
556          * can, at least in theory, contain control characters (including nul)
557          * and as such, should be processed as binary data, not a printable
558          * string.
559          */
560         int (*get_ssid)(void *priv, u8 *ssid);
561
562         /**
563          * set_wpa - Enable/disable WPA support (OBSOLETE)
564          * @priv: private driver interface data
565          * @enabled: 1 = enable, 0 = disable
566          *
567          * Returns: 0 on success, -1 on failure
568          *
569          * Note: This function is included for backwards compatibility. This is
570          * called only just after init and just before deinit, so these
571          * functions can be used to implement same functionality and the driver
572          * interface need not define this function.
573          *
574          * Configure the kernel driver to enable/disable WPA support. This may
575          * be empty function, if WPA support is always enabled. Common
576          * configuration items are WPA IE (clearing it when WPA support is
577          * disabled), Privacy flag configuration for capability field (note:
578          * this the value need to set in associate handler to allow plaintext
579          * mode to be used) when trying to associate with, roaming mode (can
580          * allow wpa_supplicant to control roaming if ap_scan=1 is used;
581          * however, drivers can also implement roaming if desired, especially
582          * ap_scan=2 mode is used for this).
583          */
584         int (*set_wpa)(void *priv, int enabled);
585
586         /**
587          * set_key - Configure encryption key
588          * @priv: private driver interface data
589          * @alg: encryption algorithm (%WPA_ALG_NONE, %WPA_ALG_WEP,
590          *      %WPA_ALG_TKIP, %WPA_ALG_CCMP, %WPA_ALG_IGTK, %WPA_ALG_PMK);
591          *      %WPA_ALG_NONE clears the key.
592          * @addr: address of the peer STA or ff:ff:ff:ff:ff:ff for
593          *      broadcast/default keys
594          * @key_idx: key index (0..3), usually 0 for unicast keys; 0..4095 for
595          *      IGTK
596          * @set_tx: configure this key as the default Tx key (only used when
597          *      driver does not support separate unicast/individual key
598          * @seq: sequence number/packet number, seq_len octets, the next
599          *      packet number to be used for in replay protection; configured
600          *      for Rx keys (in most cases, this is only used with broadcast
601          *      keys and set to zero for unicast keys)
602          * @seq_len: length of the seq, depends on the algorithm:
603          *      TKIP: 6 octets, CCMP: 6 octets, IGTK: 6 octets
604          * @key: key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key,
605          *      8-byte Rx Mic Key
606          * @key_len: length of the key buffer in octets (WEP: 5 or 13,
607          *      TKIP: 32, CCMP: 16, IGTK: 16)
608          *
609          * Returns: 0 on success, -1 on failure
610          *
611          * Configure the given key for the kernel driver. If the driver
612          * supports separate individual keys (4 default keys + 1 individual),
613          * addr can be used to determine whether the key is default or
614          * individual. If only 4 keys are supported, the default key with key
615          * index 0 is used as the individual key. STA must be configured to use
616          * it as the default Tx key (set_tx is set) and accept Rx for all the
617          * key indexes. In most cases, WPA uses only key indexes 1 and 2 for
618          * broadcast keys, so key index 0 is available for this kind of
619          * configuration.
620          *
621          * Please note that TKIP keys include separate TX and RX MIC keys and
622          * some drivers may expect them in different order than wpa_supplicant
623          * is using. If the TX/RX keys are swapped, all TKIP encrypted packets
624          * will tricker Michael MIC errors. This can be fixed by changing the
625          * order of MIC keys by swapping te bytes 16..23 and 24..31 of the key
626          * in driver_*.c set_key() implementation, see driver_ndis.c for an
627          * example on how this can be done.
628          */
629         int (*set_key)(void *priv, wpa_alg alg, const u8 *addr,
630                        int key_idx, int set_tx, const u8 *seq, size_t seq_len,
631                        const u8 *key, size_t key_len);
632
633         /**
634          * init - Initialize driver interface
635          * @ctx: context to be used when calling wpa_supplicant functions,
636          * e.g., wpa_supplicant_event()
637          * @ifname: interface name, e.g., wlan0
638          *
639          * Returns: Pointer to private data, %NULL on failure
640          *
641          * Initialize driver interface, including event processing for kernel
642          * driver events (e.g., associated, scan results, Michael MIC failure).
643          * This function can allocate a private configuration data area for
644          * @ctx, file descriptor, interface name, etc. information that may be
645          * needed in future driver operations. If this is not used, non-NULL
646          * value will need to be returned because %NULL is used to indicate
647          * failure. The returned value will be used as 'void *priv' data for
648          * all other driver_ops functions.
649          *
650          * The main event loop (eloop.c) of wpa_supplicant can be used to
651          * register callback for read sockets (eloop_register_read_sock()).
652          *
653          * See below for more information about events and
654          * wpa_supplicant_event() function.
655          */
656         void * (*init)(void *ctx, const char *ifname);
657
658         /**
659          * deinit - Deinitialize driver interface
660          * @priv: private driver interface data from init()
661          *
662          * Shut down driver interface and processing of driver events. Free
663          * private data buffer if one was allocated in init() handler.
664          */
665         void (*deinit)(void *priv);
666
667         /**
668          * set_param - Set driver configuration parameters
669          * @priv: private driver interface data from init()
670          * @param: driver specific configuration parameters
671          *
672          * Returns: 0 on success, -1 on failure
673          *
674          * Optional handler for notifying driver interface about configuration
675          * parameters (driver_param).
676          */
677         int (*set_param)(void *priv, const char *param);
678
679         /**
680          * set_countermeasures - Enable/disable TKIP countermeasures
681          * @priv: private driver interface data
682          * @enabled: 1 = countermeasures enabled, 0 = disabled
683          *
684          * Returns: 0 on success, -1 on failure
685          *
686          * Configure TKIP countermeasures. When these are enabled, the driver
687          * should drop all received and queued frames that are using TKIP.
688          */
689         int (*set_countermeasures)(void *priv, int enabled);
690
691         /**
692          * set_drop_unencrypted - Enable/disable unencrypted frame filtering
693          * @priv: private driver interface data
694          * @enabled: 1 = unencrypted Tx/Rx frames will be dropped, 0 = disabled
695          *
696          * Returns: 0 on success, -1 on failure
697          *
698          * Configure the driver to drop all non-EAPOL frames (both receive and
699          * transmit paths). Unencrypted EAPOL frames (ethertype 0x888e) must
700          * still be allowed for key negotiation.
701          *
702          * This function is deprecated. New driver wrapper implementations
703          * should use associate() parameter drop_unencrypted instead.
704          */
705         int (*set_drop_unencrypted)(void *priv, int enabled);
706
707         /**
708          * scan - Request the driver to initiate scan (old version)
709          * @priv: private driver interface data
710          * @ssid: specific SSID to scan for (ProbeReq) or %NULL to scan for
711          *      all SSIDs (either active scan with wildcard SSID or passive
712          *      scan)
713          * @ssid_len: length of the SSID
714          *
715          * Returns: 0 on success, -1 on failure
716          *
717          * Once the scan results are ready, the driver should report scan
718          * results event for wpa_supplicant which will eventually request the
719          * results with wpa_driver_get_scan_results().
720          *
721          * This function is deprecated. New driver wrapper implementations
722          * should implement support for scan2().
723          */
724         int (*scan)(void *priv, const u8 *ssid, size_t ssid_len);
725
726         /**
727          * get_scan_results - Fetch the latest scan results (old version)
728          * @priv: private driver interface data
729          * @results: pointer to buffer for scan results
730          * @max_size: maximum number of entries (buffer size)
731          *
732          * Returns: Number of scan result entries used on success, -1 on
733          * failure
734          *
735          * If scan results include more than max_size BSSes, max_size will be
736          * returned and the remaining entries will not be included in the
737          * buffer.
738          *
739          * This function is deprecated. New driver wrapper implementations
740          * should implement support for get_scan_results2().
741          */
742         int (*get_scan_results)(void *priv,
743                                 struct wpa_scan_result *results,
744                                 size_t max_size);
745
746         /**
747          * deauthenticate - Request driver to deauthenticate
748          * @priv: private driver interface data
749          * @addr: peer address (BSSID of the AP)
750          * @reason_code: 16-bit reason code to be sent in the deauthentication
751          *      frame
752          *
753          * Returns: 0 on success, -1 on failure
754          */
755         int (*deauthenticate)(void *priv, const u8 *addr, int reason_code);
756
757         /**
758          * disassociate - Request driver to disassociate
759          * @priv: private driver interface data
760          * @addr: peer address (BSSID of the AP)
761          * @reason_code: 16-bit reason code to be sent in the disassociation
762          *      frame
763          *
764          * Returns: 0 on success, -1 on failure
765          */
766         int (*disassociate)(void *priv, const u8 *addr, int reason_code);
767
768         /**
769          * associate - Request driver to associate
770          * @priv: private driver interface data
771          * @params: association parameters
772          *
773          * Returns: 0 on success, -1 on failure
774          */
775         int (*associate)(void *priv,
776                          struct wpa_driver_associate_params *params);
777
778         /**
779          * set_auth_alg - Set IEEE 802.11 authentication algorithm
780          * @priv: private driver interface data
781          * @auth_alg: bit field of AUTH_ALG_*
782          *
783          * If the driver supports more than one authentication algorithm at the
784          * same time, it should configure all supported algorithms. If not, one
785          * algorithm needs to be selected arbitrarily. Open System
786          * authentication should be ok for most cases and it is recommended to
787          * be used if other options are not supported. Static WEP configuration
788          * may also use Shared Key authentication and LEAP requires its own
789          * algorithm number. For LEAP, user can make sure that only one
790          * algorithm is used at a time by configuring LEAP as the only
791          * supported EAP method. This information is also available in
792          * associate() params, so set_auth_alg may not be needed in case of
793          * most drivers.
794          *
795          * This function is deprecated. New driver wrapper implementations
796          * should use associate() parameter auth_alg instead.
797          *
798          * Returns: 0 on success, -1 on failure
799          */
800         int (*set_auth_alg)(void *priv, int auth_alg);
801
802         /**
803          * add_pmkid - Add PMKSA cache entry to the driver
804          * @priv: private driver interface data
805          * @bssid: BSSID for the PMKSA cache entry
806          * @pmkid: PMKID for the PMKSA cache entry
807          *
808          * Returns: 0 on success, -1 on failure
809          *
810          * This function is called when a new PMK is received, as a result of
811          * either normal authentication or RSN pre-authentication.
812          *
813          * If the driver generates RSN IE, i.e., it does not use wpa_ie in
814          * associate(), add_pmkid() can be used to add new PMKSA cache entries
815          * in the driver. If the driver uses wpa_ie from wpa_supplicant, this
816          * driver_ops function does not need to be implemented. Likewise, if
817          * the driver does not support WPA, this function is not needed.
818          */
819         int (*add_pmkid)(void *priv, const u8 *bssid, const u8 *pmkid);
820
821         /**
822          * remove_pmkid - Remove PMKSA cache entry to the driver
823          * @priv: private driver interface data
824          * @bssid: BSSID for the PMKSA cache entry
825          * @pmkid: PMKID for the PMKSA cache entry
826          *
827          * Returns: 0 on success, -1 on failure
828          *
829          * This function is called when the supplicant drops a PMKSA cache
830          * entry for any reason.
831          *
832          * If the driver generates RSN IE, i.e., it does not use wpa_ie in
833          * associate(), remove_pmkid() can be used to synchronize PMKSA caches
834          * between the driver and wpa_supplicant. If the driver uses wpa_ie
835          * from wpa_supplicant, this driver_ops function does not need to be
836          * implemented. Likewise, if the driver does not support WPA, this
837          * function is not needed.
838          */
839         int (*remove_pmkid)(void *priv, const u8 *bssid, const u8 *pmkid);
840
841         /**
842          * flush_pmkid - Flush PMKSA cache
843          * @priv: private driver interface data
844          *
845          * Returns: 0 on success, -1 on failure
846          *
847          * This function is called when the supplicant drops all PMKSA cache
848          * entries for any reason.
849          *
850          * If the driver generates RSN IE, i.e., it does not use wpa_ie in
851          * associate(), remove_pmkid() can be used to synchronize PMKSA caches
852          * between the driver and wpa_supplicant. If the driver uses wpa_ie
853          * from wpa_supplicant, this driver_ops function does not need to be
854          * implemented. Likewise, if the driver does not support WPA, this
855          * function is not needed.
856          */
857         int (*flush_pmkid)(void *priv);
858
859         /**
860          * get_capa - Get driver capabilities
861          * @priv: private driver interface data
862          *
863          * Returns: 0 on success, -1 on failure
864          *
865          * Get driver/firmware/hardware capabilities.
866          */
867         int (*get_capa)(void *priv, struct wpa_driver_capa *capa);
868
869         /**
870          * poll - Poll driver for association information
871          * @priv: private driver interface data
872          *
873          * This is an option callback that can be used when the driver does not
874          * provide event mechanism for association events. This is called when
875          * receiving WPA EAPOL-Key messages that require association
876          * information. The driver interface is supposed to generate associnfo
877          * event before returning from this callback function. In addition, the
878          * driver interface should generate an association event after having
879          * sent out associnfo.
880          */
881         void (*poll)(void *priv);
882
883         /**
884          * get_ifname - Get interface name
885          * @priv: private driver interface data
886          *
887          * Returns: Pointer to the interface name. This can differ from the
888          * interface name used in init() call. Init() is called first.
889          *
890          * This optional function can be used to allow the driver interface to
891          * replace the interface name with something else, e.g., based on an
892          * interface mapping from a more descriptive name.
893          */
894         const char * (*get_ifname)(void *priv);
895
896         /**
897          * get_mac_addr - Get own MAC address
898          * @priv: private driver interface data
899          *
900          * Returns: Pointer to own MAC address or %NULL on failure
901          *
902          * This optional function can be used to get the own MAC address of the
903          * device from the driver interface code. This is only needed if the
904          * l2_packet implementation for the OS does not provide easy access to
905          * a MAC address. */
906         const u8 * (*get_mac_addr)(void *priv);
907
908         /**
909          * send_eapol - Optional function for sending EAPOL packets
910          * @priv: private driver interface data
911          * @dest: Destination MAC address
912          * @proto: Ethertype
913          * @data: EAPOL packet starting with IEEE 802.1X header
914          * @data_len: Size of the EAPOL packet
915          *
916          * Returns: 0 on success, -1 on failure
917          *
918          * This optional function can be used to override l2_packet operations
919          * with driver specific functionality. If this function pointer is set,
920          * l2_packet module is not used at all and the driver interface code is
921          * responsible for receiving and sending all EAPOL packets. The
922          * received EAPOL packets are sent to core code by calling
923          * wpa_supplicant_rx_eapol(). The driver interface is required to
924          * implement get_mac_addr() handler if send_eapol() is used.
925          */
926         int (*send_eapol)(void *priv, const u8 *dest, u16 proto,
927                           const u8 *data, size_t data_len);
928
929         /**
930          * set_operstate - Sets device operating state to DORMANT or UP
931          * @priv: private driver interface data
932          * @state: 0 = dormant, 1 = up
933          * Returns: 0 on success, -1 on failure
934          *
935          * This is an optional function that can be used on operating systems
936          * that support a concept of controlling network device state from user
937          * space applications. This function, if set, gets called with
938          * state = 1 when authentication has been completed and with state = 0
939          * when connection is lost.
940          */
941         int (*set_operstate)(void *priv, int state);
942
943         /**
944          * mlme_setprotection - MLME-SETPROTECTION.request primitive
945          * @priv: Private driver interface data
946          * @addr: Address of the station for which to set protection (may be
947          * %NULL for group keys)
948          * @protect_type: MLME_SETPROTECTION_PROTECT_TYPE_*
949          * @key_type: MLME_SETPROTECTION_KEY_TYPE_*
950          * Returns: 0 on success, -1 on failure
951          *
952          * This is an optional function that can be used to set the driver to
953          * require protection for Tx and/or Rx frames. This uses the layer
954          * interface defined in IEEE 802.11i-2004 clause 10.3.22.1
955          * (MLME-SETPROTECTION.request). Many drivers do not use explicit
956          * set protection operation; instead, they set protection implicitly
957          * based on configured keys.
958          */
959         int (*mlme_setprotection)(void *priv, const u8 *addr, int protect_type,
960                                   int key_type);
961
962         /**
963          * get_hw_feature_data - Get hardware support data (channels and rates)
964          * @priv: Private driver interface data
965          * @num_modes: Variable for returning the number of returned modes
966          * flags: Variable for returning hardware feature flags
967          * Returns: Pointer to allocated hardware data on success or %NULL on
968          * failure. Caller is responsible for freeing this.
969          *
970          * This function is only needed for drivers that export MLME
971          * (management frame processing) to wpa_supplicant.
972          */
973         struct hostapd_hw_modes * (*get_hw_feature_data)(void *priv,
974                                                          u16 *num_modes,
975                                                          u16 *flags);
976
977         /**
978          * set_channel - Set channel
979          * @priv: Private driver interface data
980          * @phymode: HOSTAPD_MODE_IEEE80211B, ..
981          * @chan: IEEE 802.11 channel number
982          * @freq: Frequency of the channel in MHz
983          * Returns: 0 on success, -1 on failure
984          *
985          * This function is only needed for drivers that export MLME
986          * (management frame processing) to wpa_supplicant.
987          */
988         int (*set_channel)(void *priv, hostapd_hw_mode phymode, int chan,
989                            int freq);
990
991         /**
992          * set_ssid - Set SSID
993          * @priv: Private driver interface data
994          * @ssid: SSID
995          * @ssid_len: SSID length
996          * Returns: 0 on success, -1 on failure
997          *
998          * This function is only needed for drivers that export MLME
999          * (management frame processing) to wpa_supplicant.
1000          */
1001         int (*set_ssid)(void *priv, const u8 *ssid, size_t ssid_len);
1002
1003         /**
1004          * set_bssid - Set BSSID
1005          * @priv: Private driver interface data
1006          * @bssid: BSSID
1007          * Returns: 0 on success, -1 on failure
1008          *
1009          * This function is only needed for drivers that export MLME
1010          * (management frame processing) to wpa_supplicant.
1011          */
1012         int (*set_bssid)(void *priv, const u8 *bssid);
1013
1014         /**
1015          * send_mlme - Send management frame from MLME
1016          * @priv: Private driver interface data
1017          * @data: IEEE 802.11 management frame with IEEE 802.11 header
1018          * @data_len: Size of the management frame
1019          * Returns: 0 on success, -1 on failure
1020          *
1021          * This function is only needed for drivers that export MLME
1022          * (management frame processing) to wpa_supplicant.
1023          */
1024         int (*send_mlme)(void *priv, const u8 *data, size_t data_len);
1025
1026         /**
1027          * mlme_add_sta - Add a STA entry into the driver/netstack
1028          * @priv: Private driver interface data
1029          * @addr: MAC address of the STA (e.g., BSSID of the AP)
1030          * @supp_rates: Supported rate set (from (Re)AssocResp); in IEEE 802.11
1031          * format (one octet per rate, 1 = 0.5 Mbps)
1032          * @supp_rates_len: Number of entries in supp_rates
1033          * Returns: 0 on success, -1 on failure
1034          *
1035          * This function is only needed for drivers that export MLME
1036          * (management frame processing) to wpa_supplicant. When the MLME code
1037          * completes association with an AP, this function is called to
1038          * configure the driver/netstack with a STA entry for data frame
1039          * processing (TX rate control, encryption/decryption).
1040          */
1041         int (*mlme_add_sta)(void *priv, const u8 *addr, const u8 *supp_rates,
1042                             size_t supp_rates_len);
1043
1044         /**
1045          * mlme_remove_sta - Remove a STA entry from the driver/netstack
1046          * @priv: Private driver interface data
1047          * @addr: MAC address of the STA (e.g., BSSID of the AP)
1048          * Returns: 0 on success, -1 on failure
1049          *
1050          * This function is only needed for drivers that export MLME
1051          * (management frame processing) to wpa_supplicant.
1052          */
1053         int (*mlme_remove_sta)(void *priv, const u8 *addr);
1054
1055         /**
1056          * update_ft_ies - Update FT (IEEE 802.11r) IEs
1057          * @priv: Private driver interface data
1058          * @md: Mobility domain (2 octets) (also included inside ies)
1059          * @ies: FT IEs (MDIE, FTIE, ...) or %NULL to remove IEs
1060          * @ies_len: Length of FT IEs in bytes
1061          * Returns: 0 on success, -1 on failure
1062          *
1063          * The supplicant uses this callback to let the driver know that keying
1064          * material for FT is available and that the driver can use the
1065          * provided IEs in the next message in FT authentication sequence.
1066          *
1067          * This function is only needed for driver that support IEEE 802.11r
1068          * (Fast BSS Transition).
1069          */
1070         int (*update_ft_ies)(void *priv, const u8 *md, const u8 *ies,
1071                              size_t ies_len);
1072
1073         /**
1074          * send_ft_action - Send FT Action frame (IEEE 802.11r)
1075          * @priv: Private driver interface data
1076          * @action: Action field value
1077          * @target_ap: Target AP address
1078          * @ies: FT IEs (MDIE, FTIE, ...) (FT Request action frame body)
1079          * @ies_len: Length of FT IEs in bytes
1080          * Returns: 0 on success, -1 on failure
1081          *
1082          * The supplicant uses this callback to request the driver to transmit
1083          * an FT Action frame (action category 6) for over-the-DS fast BSS
1084          * transition.
1085          */
1086         int (*send_ft_action)(void *priv, u8 action, const u8 *target_ap,
1087                               const u8 *ies, size_t ies_len);
1088
1089         /**
1090          * get_scan_results2 - Fetch the latest scan results
1091          * @priv: private driver interface data
1092          *
1093          * Returns: Allocated buffer of scan results (caller is responsible for
1094          * freeing the data structure) on success, NULL on failure
1095          */
1096          struct wpa_scan_results * (*get_scan_results2)(void *priv);
1097
1098         /**
1099          * set_probe_req_ie - Set information element(s) for Probe Request
1100          * @priv: private driver interface data
1101          * @ies: Information elements to append or %NULL to remove extra IEs
1102          * @ies_len: Length of the IE buffer in octets
1103          * Returns: 0 on success, -1 on failure
1104          */
1105         int (*set_probe_req_ie)(void *priv, const u8 *ies, size_t ies_len);
1106
1107         /**
1108          * set_mode - Request driver to set the operating mode
1109          * @priv: private driver interface data
1110          * @mode: Operation mode (infra/ibss) IEEE80211_MODE_*
1111          *
1112          * This handler will be called before any key configuration and call to
1113          * associate() handler in order to allow the operation mode to be
1114          * configured as early as possible. This information is also available
1115          * in associate() params and as such, driver wrappers may not need
1116          * to implement set_mode() handler.
1117          *
1118          * This function is deprecated. New driver wrapper implementations
1119          * should use associate() parameter mode instead.
1120          *
1121          * Returns: 0 on success, -1 on failure
1122          */
1123         int (*set_mode)(void *priv, int mode);
1124
1125         /**
1126          * set_country - Set country
1127          * @priv: Private driver interface data
1128          * @alpha2: country to which to switch to
1129          * Returns: 0 on success, -1 on failure
1130          *
1131          * This function is for drivers which support some form
1132          * of setting a regulatory domain.
1133          */
1134         int (*set_country)(void *priv, const char *alpha2);
1135
1136         /**
1137          * global_init - Global driver initialization
1138          * Returns: Pointer to private data (global), %NULL on failure
1139          *
1140          * This optional function is called to initialize the driver wrapper
1141          * for global data, i.e., data that applies to all interfaces. If this
1142          * function is implemented, global_deinit() will also need to be
1143          * implemented to free the private data. The driver will also likely
1144          * use init2() function instead of init() to get the pointer to global
1145          * data available to per-interface initializer.
1146          */
1147         void * (*global_init)(void);
1148
1149         /**
1150          * global_deinit - Global driver deinitialization
1151          * @priv: private driver global data from global_init()
1152          *
1153          * Terminate any global driver related functionality and free the
1154          * global data structure.
1155          */
1156         void (*global_deinit)(void *priv);
1157
1158         /**
1159          * init2 - Initialize driver interface (with global data)
1160          * @ctx: context to be used when calling wpa_supplicant functions,
1161          * e.g., wpa_supplicant_event()
1162          * @ifname: interface name, e.g., wlan0
1163          * @global_priv: private driver global data from global_init()
1164          * Returns: Pointer to private data, %NULL on failure
1165          *
1166          * This function can be used instead of init() if the driver wrapper
1167          * uses global data.
1168          */
1169         void * (*init2)(void *ctx, const char *ifname, void *global_priv);
1170
1171         /**
1172          * get_interfaces - Get information about available interfaces
1173          * @global_priv: private driver global data from global_init()
1174          * Returns: Allocated buffer of interface information (caller is
1175          * responsible for freeing the data structure) on success, NULL on
1176          * failure
1177          */
1178         struct wpa_interface_info * (*get_interfaces)(void *global_priv);
1179
1180         /**
1181          * scan2 - Request the driver to initiate scan
1182          * @priv: private driver interface data
1183          * @params: Scan parameters
1184          *
1185          * Returns: 0 on success, -1 on failure
1186          *
1187          * Once the scan results are ready, the driver should report scan
1188          * results event for wpa_supplicant which will eventually request the
1189          * results with wpa_driver_get_scan_results2().
1190          */
1191         int (*scan2)(void *priv, struct wpa_driver_scan_params *params);
1192
1193         /**
1194          * authenticate - Request driver to authenticate
1195          * @priv: private driver interface data
1196          * @params: authentication parameters
1197          * Returns: 0 on success, -1 on failure
1198          *
1199          * This is an optional function that can be used with drivers that
1200          * support separate authentication and association steps, i.e., when
1201          * wpa_supplicant can act as the SME. If not implemented, associate()
1202          * function is expected to take care of IEEE 802.11 authentication,
1203          * too.
1204          */
1205         int (*authenticate)(void *priv,
1206                             struct wpa_driver_auth_params *params);
1207
1208         int (*set_beacon)(void *priv, const u8 *head, size_t head_len,
1209                           const u8 *tail, size_t tail_len, int dtim_period);
1210
1211         int (*set_beacon_int)(void *priv, int value);
1212
1213         void * (*hapd_init)(struct hostapd_data *hapd,
1214                             struct wpa_init_params *params);
1215         void (*hapd_deinit)(void *priv);
1216
1217         /**
1218          * set_8021x - enable/disable IEEE 802.1X support
1219          * @ifname: Interface name (for multi-SSID/VLAN support)
1220          * @priv: driver private data
1221          * @enabled: 1 = enable, 0 = disable
1222          *
1223          * Returns: 0 on success, -1 on failure
1224          *
1225          * Configure the kernel driver to enable/disable 802.1X support.
1226          * This may be an empty function if 802.1X support is always enabled.
1227          */
1228         int (*set_ieee8021x)(const char *ifname, void *priv, int enabled);
1229
1230         /**
1231          * set_privacy - enable/disable privacy
1232          * @priv: driver private data
1233          * @enabled: 1 = privacy enabled, 0 = disabled
1234          *
1235          * Return: 0 on success, -1 on failure
1236          *
1237          * Configure privacy.
1238          */
1239         int (*set_privacy)(const char *ifname, void *priv, int enabled);
1240
1241         int (*hapd_set_key)(const char *ifname, void *priv, wpa_alg alg,
1242                             const u8 *addr, int key_idx, int set_tx,
1243                             const u8 *seq, size_t seq_len,
1244                             const u8 *key, size_t key_len);
1245         int (*get_seqnum)(const char *ifname, void *priv, const u8 *addr,
1246                           int idx, u8 *seq);
1247         int (*get_seqnum_igtk)(const char *ifname, void *priv, const u8 *addr,
1248                                int idx, u8 *seq);
1249         int (*flush)(void *priv);
1250         int (*set_generic_elem)(const char *ifname, void *priv, const u8 *elem,
1251                                 size_t elem_len);
1252
1253         int (*read_sta_data)(void *priv, struct hostap_sta_driver_data *data,
1254                              const u8 *addr);
1255         int (*hapd_send_eapol)(void *priv, const u8 *addr, const u8 *data,
1256                                size_t data_len, int encrypt,
1257                                const u8 *own_addr);
1258         int (*sta_deauth)(void *priv, const u8 *own_addr, const u8 *addr,
1259                           int reason);
1260         int (*sta_disassoc)(void *priv, const u8 *own_addr, const u8 *addr,
1261                             int reason);
1262         int (*sta_remove)(void *priv, const u8 *addr);
1263         int (*hapd_get_ssid)(const char *ifname, void *priv, u8 *buf, int len);
1264         int (*hapd_set_ssid)(const char *ifname, void *priv, const u8 *buf,
1265                              int len);
1266         int (*hapd_set_countermeasures)(void *priv, int enabled);
1267         int (*sta_add)(const char *ifname, void *priv,
1268                        struct hostapd_sta_add_params *params);
1269         int (*get_inact_sec)(void *priv, const u8 *addr);
1270         int (*sta_clear_stats)(void *priv, const u8 *addr);
1271
1272         int (*set_freq)(void *priv, struct hostapd_freq_params *freq);
1273         int (*set_rts)(void *priv, int rts);
1274         int (*set_frag)(void *priv, int frag);
1275
1276         int (*sta_set_flags)(void *priv, const u8 *addr,
1277                              int total_flags, int flags_or, int flags_and);
1278         int (*set_rate_sets)(void *priv, int *supp_rates, int *basic_rates,
1279                              int mode);
1280         int (*hapd_set_beacon)(const char *ifname, void *priv,
1281                                const u8 *head, size_t head_len,
1282                                const u8 *tail, size_t tail_len,
1283                                int dtim_period);
1284
1285         /* Configure internal bridge:
1286          * 0 = disabled, i.e., client separation is enabled (no bridging of
1287          *     packets between associated STAs
1288          * 1 = enabled, i.e., bridge packets between associated STAs (default)
1289          */
1290         int (*set_internal_bridge)(void *priv, int value);
1291         int (*set_cts_protect)(void *priv, int value);
1292         int (*set_preamble)(void *priv, int value);
1293         int (*set_short_slot_time)(void *priv, int value);
1294         int (*set_tx_queue_params)(void *priv, int queue, int aifs, int cw_min,
1295                                    int cw_max, int burst_time);
1296         int (*bss_add)(void *priv, const char *ifname, const u8 *bssid);
1297         int (*bss_remove)(void *priv, const char *ifname);
1298         int (*valid_bss_mask)(void *priv, const u8 *addr, const u8 *mask);
1299         int (*if_add)(const char *iface, void *priv,
1300                       enum hostapd_driver_if_type type, char *ifname,
1301                       const u8 *addr);
1302         int (*if_update)(void *priv, enum hostapd_driver_if_type type,
1303                          char *ifname, const u8 *addr);
1304         int (*if_remove)(void *priv, enum hostapd_driver_if_type type,
1305                          const char *ifname, const u8 *addr);
1306         int (*set_sta_vlan)(void *priv, const u8 *addr, const char *ifname,
1307                             int vlan_id);
1308         /**
1309          * commit - Optional commit changes handler
1310          * @priv: driver private data
1311          * Returns: 0 on success, -1 on failure
1312          *
1313          * This optional handler function can be registered if the driver
1314          * interface implementation needs to commit changes (e.g., by setting
1315          * network interface up) at the end of initial configuration. If set,
1316          * this handler will be called after initial setup has been completed.
1317          */
1318         int (*commit)(void *priv);
1319
1320         int (*send_ether)(void *priv, const u8 *dst, const u8 *src, u16 proto,
1321                           const u8 *data, size_t data_len);
1322
1323         int (*set_radius_acl_auth)(void *priv, const u8 *mac, int accepted, 
1324                                    u32 session_timeout);
1325         int (*set_radius_acl_expire)(void *priv, const u8 *mac);
1326
1327         int (*set_ht_params)(const char *ifname, void *priv,
1328                              const u8 *ht_capab, size_t ht_capab_len,
1329                              const u8 *ht_oper, size_t ht_oper_len);
1330
1331         int (*set_wps_beacon_ie)(const char *ifname, void *priv,
1332                                  const u8 *ie, size_t len);
1333         int (*set_wps_probe_resp_ie)(const char *ifname, void *priv,
1334                                      const u8 *ie, size_t len);
1335
1336         /**
1337          * set_supp_port - Set IEEE 802.1X Supplicant Port status
1338          * @priv: Private driver interface data
1339          * @authorized: Whether the port is authorized
1340          * Returns: 0 on success, -1 on failure
1341          */
1342         int (*set_supp_port)(void *priv, int authorized);
1343 };
1344
1345 /**
1346  * enum wpa_event_type - Event type for wpa_supplicant_event() calls
1347  */
1348 typedef enum wpa_event_type {
1349         /**
1350          * EVENT_ASSOC - Association completed
1351          *
1352          * This event needs to be delivered when the driver completes IEEE
1353          * 802.11 association or reassociation successfully.
1354          * wpa_driver_ops::get_bssid() is expected to provide the current BSSID
1355          * after this event has been generated. In addition, optional
1356          * EVENT_ASSOCINFO may be generated just before EVENT_ASSOC to provide
1357          * more information about the association. If the driver interface gets
1358          * both of these events at the same time, it can also include the
1359          * assoc_info data in EVENT_ASSOC call.
1360          */
1361         EVENT_ASSOC,
1362
1363         /**
1364          * EVENT_DISASSOC - Association lost
1365          *
1366          * This event should be called when association is lost either due to
1367          * receiving deauthenticate or disassociate frame from the AP or when
1368          * sending either of these frames to the current AP. If the driver
1369          * supports separate deauthentication event, EVENT_DISASSOC should only
1370          * be used for disassociation and EVENT_DEAUTH for deauthentication.
1371          */
1372         EVENT_DISASSOC,
1373
1374         /**
1375          * EVENT_MICHAEL_MIC_FAILURE - Michael MIC (TKIP) detected
1376          *
1377          * This event must be delivered when a Michael MIC error is detected by
1378          * the local driver. Additional data for event processing is
1379          * provided with union wpa_event_data::michael_mic_failure. This
1380          * information is used to request new encyption key and to initiate
1381          * TKIP countermeasures if needed.
1382          */
1383         EVENT_MICHAEL_MIC_FAILURE,
1384
1385         /**
1386          * EVENT_SCAN_RESULTS - Scan results available
1387          *
1388          * This event must be called whenever scan results are available to be
1389          * fetched with struct wpa_driver_ops::get_scan_results(). This event
1390          * is expected to be used some time after struct wpa_driver_ops::scan()
1391          * is called. If the driver provides an unsolicited event when the scan
1392          * has been completed, this event can be used to trigger
1393          * EVENT_SCAN_RESULTS call. If such event is not available from the
1394          * driver, the driver wrapper code is expected to use a registered
1395          * timeout to generate EVENT_SCAN_RESULTS call after the time that the
1396          * scan is expected to be completed.
1397          */
1398         EVENT_SCAN_RESULTS,
1399
1400         /**
1401          * EVENT_ASSOCINFO - Report optional extra information for association
1402          *
1403          * This event can be used to report extra association information for
1404          * EVENT_ASSOC processing. This extra information includes IEs from
1405          * association frames and Beacon/Probe Response frames in union
1406          * wpa_event_data::assoc_info. EVENT_ASSOCINFO must be send just before
1407          * EVENT_ASSOC. Alternatively, the driver interface can include
1408          * assoc_info data in the EVENT_ASSOC call if it has all the
1409          * information available at the same point.
1410          */
1411         EVENT_ASSOCINFO,
1412
1413         /**
1414          * EVENT_INTERFACE_STATUS - Report interface status changes
1415          *
1416          * This optional event can be used to report changes in interface
1417          * status (interface added/removed) using union
1418          * wpa_event_data::interface_status. This can be used to trigger
1419          * wpa_supplicant to stop and re-start processing for the interface,
1420          * e.g., when a cardbus card is ejected/inserted.
1421          */
1422         EVENT_INTERFACE_STATUS,
1423
1424         /**
1425          * EVENT_PMKID_CANDIDATE - Report a candidate AP for pre-authentication
1426          *
1427          * This event can be used to inform wpa_supplicant about candidates for
1428          * RSN (WPA2) pre-authentication. If wpa_supplicant is not responsible
1429          * for scan request (ap_scan=2 mode), this event is required for
1430          * pre-authentication. If wpa_supplicant is performing scan request
1431          * (ap_scan=1), this event is optional since scan results can be used
1432          * to add pre-authentication candidates. union
1433          * wpa_event_data::pmkid_candidate is used to report the BSSID of the
1434          * candidate and priority of the candidate, e.g., based on the signal
1435          * strength, in order to try to pre-authenticate first with candidates
1436          * that are most likely targets for re-association.
1437          *
1438          * EVENT_PMKID_CANDIDATE can be called whenever the driver has updates
1439          * on the candidate list. In addition, it can be called for the current
1440          * AP and APs that have existing PMKSA cache entries. wpa_supplicant
1441          * will automatically skip pre-authentication in cases where a valid
1442          * PMKSA exists. When more than one candidate exists, this event should
1443          * be generated once for each candidate.
1444          *
1445          * Driver will be notified about successful pre-authentication with
1446          * struct wpa_driver_ops::add_pmkid() calls.
1447          */
1448         EVENT_PMKID_CANDIDATE,
1449
1450         /**
1451          * EVENT_STKSTART - Request STK handshake (MLME-STKSTART.request)
1452          *
1453          * This event can be used to inform wpa_supplicant about desire to set
1454          * up secure direct link connection between two stations as defined in
1455          * IEEE 802.11e with a new PeerKey mechanism that replaced the original
1456          * STAKey negotiation. The caller will need to set peer address for the
1457          * event.
1458          */
1459         EVENT_STKSTART,
1460
1461         /**
1462          * EVENT_FT_RESPONSE - Report FT (IEEE 802.11r) response IEs
1463          *
1464          * The driver is expected to report the received FT IEs from
1465          * FT authentication sequence from the AP. The FT IEs are included in
1466          * the extra information in union wpa_event_data::ft_ies.
1467          */
1468         EVENT_FT_RESPONSE,
1469
1470         /**
1471          * EVENT_IBSS_RSN_START - Request RSN authentication in IBSS
1472          *
1473          * The driver can use this event to inform wpa_supplicant about a STA
1474          * in an IBSS with which protected frames could be exchanged. This
1475          * event starts RSN authentication with the other STA to authenticate
1476          * the STA and set up encryption keys with it.
1477          */
1478         EVENT_IBSS_RSN_START,
1479
1480         /**
1481          * EVENT_AUTH - Authentication result
1482          *
1483          * This event should be called when authentication attempt has been
1484          * completed. This is only used if the driver supports separate
1485          * authentication step (struct wpa_driver_ops::authenticate).
1486          * Information about authentication result is included in
1487          * union wpa_event_data::auth.
1488          */
1489         EVENT_AUTH,
1490
1491         /**
1492          * EVENT_DEAUTH - Authentication lost
1493          *
1494          * This event should be called when authentication is lost either due
1495          * to receiving deauthenticate frame from the AP or when sending that
1496          * frame to the current AP.
1497          */
1498         EVENT_DEAUTH,
1499
1500         /**
1501          * EVENT_ASSOC_REJECT - Association rejected
1502          *
1503          * This event should be called when (re)association attempt has been
1504          * rejected by the AP. Information about authentication result is
1505          * included in union wpa_event_data::assoc_reject.
1506          */
1507         EVENT_ASSOC_REJECT,
1508
1509         /**
1510          * EVENT_AUTH_TIMED_OUT - Authentication timed out
1511          */
1512         EVENT_AUTH_TIMED_OUT,
1513
1514         /**
1515          * EVENT_ASSOC_TIMED_OUT - Association timed out
1516          */
1517         EVENT_ASSOC_TIMED_OUT
1518 } wpa_event_type;
1519
1520
1521 /**
1522  * union wpa_event_data - Additional data for wpa_supplicant_event() calls
1523  */
1524 union wpa_event_data {
1525         /**
1526          * struct assoc_info - Data for EVENT_ASSOC and EVENT_ASSOCINFO events
1527          *
1528          * This structure is optional for EVENT_ASSOC calls and required for
1529          * EVENT_ASSOCINFO calls. By using EVENT_ASSOC with this data, the
1530          * driver interface does not need to generate separate EVENT_ASSOCINFO
1531          * calls.
1532          */
1533         struct assoc_info {
1534                 /**
1535                  * req_ies - (Re)Association Request IEs
1536                  *
1537                  * If the driver generates WPA/RSN IE, this event data must be
1538                  * returned for WPA handshake to have needed information. If
1539                  * wpa_supplicant-generated WPA/RSN IE is used, this
1540                  * information event is optional.
1541                  *
1542                  * This should start with the first IE (fixed fields before IEs
1543                  * are not included).
1544                  */
1545                 u8 *req_ies;
1546
1547                 /**
1548                  * req_ies_len - Length of req_ies in bytes
1549                  */
1550                 size_t req_ies_len;
1551
1552                 /**
1553                  * resp_ies - (Re)Association Response IEs
1554                  *
1555                  * Optional association data from the driver. This data is not
1556                  * required WPA, but may be useful for some protocols and as
1557                  * such, should be reported if this is available to the driver
1558                  * interface.
1559                  *
1560                  * This should start with the first IE (fixed fields before IEs
1561                  * are not included).
1562                  */
1563                 u8 *resp_ies;
1564
1565                 /**
1566                  * resp_ies_len - Length of resp_ies in bytes
1567                  */
1568                 size_t resp_ies_len;
1569
1570                 /**
1571                  * beacon_ies - Beacon or Probe Response IEs
1572                  *
1573                  * Optional Beacon/ProbeResp data: IEs included in Beacon or
1574                  * Probe Response frames from the current AP (i.e., the one
1575                  * that the client just associated with). This information is
1576                  * used to update WPA/RSN IE for the AP. If this field is not
1577                  * set, the results from previous scan will be used. If no
1578                  * data for the new AP is found, scan results will be requested
1579                  * again (without scan request). At this point, the driver is
1580                  * expected to provide WPA/RSN IE for the AP (if WPA/WPA2 is
1581                  * used).
1582                  *
1583                  * This should start with the first IE (fixed fields before IEs
1584                  * are not included).
1585                  */
1586                 u8 *beacon_ies;
1587
1588                 /**
1589                  * beacon_ies_len - Length of beacon_ies */
1590                 size_t beacon_ies_len;
1591         } assoc_info;
1592
1593         /**
1594          * struct michael_mic_failure - Data for EVENT_MICHAEL_MIC_FAILURE
1595          */
1596         struct michael_mic_failure {
1597                 int unicast;
1598                 const u8 *src;
1599         } michael_mic_failure;
1600
1601         /**
1602          * struct interface_status - Data for EVENT_INTERFACE_STATUS
1603          */
1604         struct interface_status {
1605                 char ifname[100];
1606                 enum {
1607                         EVENT_INTERFACE_ADDED, EVENT_INTERFACE_REMOVED
1608                 } ievent;
1609         } interface_status;
1610
1611         /**
1612          * struct pmkid_candidate - Data for EVENT_PMKID_CANDIDATE
1613          */
1614         struct pmkid_candidate {
1615                 /** BSSID of the PMKID candidate */
1616                 u8 bssid[ETH_ALEN];
1617                 /** Smaller the index, higher the priority */
1618                 int index;
1619                 /** Whether RSN IE includes pre-authenticate flag */
1620                 int preauth;
1621         } pmkid_candidate;
1622
1623         /**
1624          * struct stkstart - Data for EVENT_STKSTART
1625          */
1626         struct stkstart {
1627                 u8 peer[ETH_ALEN];
1628         } stkstart;
1629
1630         /**
1631          * struct ft_ies - FT information elements (EVENT_FT_RESPONSE)
1632          *
1633          * During FT (IEEE 802.11r) authentication sequence, the driver is
1634          * expected to use this event to report received FT IEs (MDIE, FTIE,
1635          * RSN IE, TIE, possible resource request) to the supplicant. The FT
1636          * IEs for the next message will be delivered through the
1637          * struct wpa_driver_ops::update_ft_ies() callback.
1638          */
1639         struct ft_ies {
1640                 const u8 *ies;
1641                 size_t ies_len;
1642                 int ft_action;
1643                 u8 target_ap[ETH_ALEN];
1644                 /** Optional IE(s), e.g., WMM TSPEC(s), for RIC-Request */
1645                 const u8 *ric_ies;
1646                 /** Length of ric_ies buffer in octets */
1647                 size_t ric_ies_len;
1648         } ft_ies;
1649
1650         /**
1651          * struct ibss_rsn_start - Data for EVENT_IBSS_RSN_START
1652          */
1653         struct ibss_rsn_start {
1654                 u8 peer[ETH_ALEN];
1655         } ibss_rsn_start;
1656
1657         /**
1658          * struct auth_info - Data for EVENT_AUTH events
1659          */
1660         struct auth_info {
1661                 u8 peer[ETH_ALEN];
1662                 u16 auth_type;
1663                 u16 status_code;
1664                 const u8 *ies;
1665                 size_t ies_len;
1666         } auth;
1667
1668         /**
1669          * struct assoc_reject - Data for EVENT_ASSOC_REJECT events
1670          */
1671         struct assoc_reject {
1672                 /**
1673                  * resp_ies - (Re)Association Response IEs
1674                  *
1675                  * Optional association data from the driver. This data is not
1676                  * required WPA, but may be useful for some protocols and as
1677                  * such, should be reported if this is available to the driver
1678                  * interface.
1679                  *
1680                  * This should start with the first IE (fixed fields before IEs
1681                  * are not included).
1682                  */
1683                 u8 *resp_ies;
1684
1685                 /**
1686                  * resp_ies_len - Length of resp_ies in bytes
1687                  */
1688                 size_t resp_ies_len;
1689
1690                 /**
1691                  * status_code - Status Code from (Re)association Response
1692                  */
1693                 u16 status_code;
1694         } assoc_reject;
1695
1696         struct timeout_event {
1697                 u8 addr[ETH_ALEN];
1698         } timeout_event;
1699 };
1700
1701 /**
1702  * wpa_supplicant_event - Report a driver event for wpa_supplicant
1703  * @ctx: Context pointer (wpa_s); this is the ctx variable registered
1704  *      with struct wpa_driver_ops::init()
1705  * @event: event type (defined above)
1706  * @data: possible extra data for the event
1707  *
1708  * Driver wrapper code should call this function whenever an event is received
1709  * from the driver.
1710  */
1711 void wpa_supplicant_event(void *ctx, wpa_event_type event,
1712                           union wpa_event_data *data);
1713
1714 /**
1715  * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
1716  * @ctx: Context pointer (wpa_s); this is the ctx variable registered
1717  *      with struct wpa_driver_ops::init()
1718  * @src_addr: Source address of the EAPOL frame
1719  * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
1720  * @len: Length of the EAPOL data
1721  *
1722  * This function is called for each received EAPOL frame. Most driver
1723  * interfaces rely on more generic OS mechanism for receiving frames through
1724  * l2_packet, but if such a mechanism is not available, the driver wrapper may
1725  * take care of received EAPOL frames and deliver them to the core supplicant
1726  * code by calling this function.
1727  */
1728 void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
1729                              const u8 *buf, size_t len);
1730
1731 void wpa_supplicant_sta_rx(void *ctx, const u8 *buf, size_t len,
1732                            struct ieee80211_rx_status *rx_status);
1733
1734 const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie);
1735 #define WPA_IE_VENDOR_TYPE 0x0050f201
1736 #define WPS_IE_VENDOR_TYPE 0x0050f204
1737 const u8 * wpa_scan_get_vendor_ie(const struct wpa_scan_res *res,
1738                                   u32 vendor_type);
1739 struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res,
1740                                              u32 vendor_type);
1741 int wpa_scan_get_max_rate(const struct wpa_scan_res *res);
1742 void wpa_scan_results_free(struct wpa_scan_results *res);
1743 void wpa_scan_sort_results(struct wpa_scan_results *res);
1744
1745 /* hostapd functions for driver wrappers */
1746
1747 struct sta_info;
1748 struct ieee80211_hdr;
1749
1750 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
1751                            int reassoc);
1752 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
1753                        const u8 *buf, size_t len, int ack);
1754 void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
1755                                  const struct ieee80211_hdr *hdr, size_t len);
1756 int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
1757                         const u8 *ie, size_t ielen);
1758 void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
1759 void hostapd_eapol_receive(struct hostapd_data *hapd, const u8 *sa,
1760                            const u8 *buf, size_t len);
1761
1762 struct hostapd_frame_info {
1763         u32 phytype;
1764         u32 channel;
1765         u32 datarate;
1766         u32 ssi_signal;
1767 };
1768
1769 void hostapd_mgmt_rx(struct hostapd_data *hapd, u8 *buf, size_t len,
1770                      u16 stype, struct hostapd_frame_info *fi);
1771 void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
1772                         u16 stype, int ok);
1773 void hostapd_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr);
1774 struct hostapd_data * hostapd_sta_get_bss(struct hostapd_data *hapd,
1775                                           const u8 *addr);
1776 void hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa,
1777                           const u8 *ie, size_t ie_len);
1778
1779 #endif /* DRIVER_H */