P2P: Add p2p_prov_disc auto mechanism
[mech_eap.git] / wpa_supplicant / wpa_supplicant_i.h
1 /*
2  * wpa_supplicant - Internal definitions
3  * Copyright (c) 2003-2010, 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
9 #ifndef WPA_SUPPLICANT_I_H
10 #define WPA_SUPPLICANT_I_H
11
12 #include "utils/list.h"
13 #include "common/defs.h"
14 #include "config_ssid.h"
15
16 extern const char *wpa_supplicant_version;
17 extern const char *wpa_supplicant_license;
18 #ifndef CONFIG_NO_STDOUT_DEBUG
19 extern const char *wpa_supplicant_full_license1;
20 extern const char *wpa_supplicant_full_license2;
21 extern const char *wpa_supplicant_full_license3;
22 extern const char *wpa_supplicant_full_license4;
23 extern const char *wpa_supplicant_full_license5;
24 #endif /* CONFIG_NO_STDOUT_DEBUG */
25
26 struct wpa_sm;
27 struct wpa_supplicant;
28 struct ibss_rsn;
29 struct scan_info;
30 struct wpa_bss;
31 struct wpa_scan_results;
32 struct hostapd_hw_modes;
33 struct wpa_driver_associate_params;
34
35 /*
36  * Forward declarations of private structures used within the ctrl_iface
37  * backends. Other parts of wpa_supplicant do not have access to data stored in
38  * these structures.
39  */
40 struct ctrl_iface_priv;
41 struct ctrl_iface_global_priv;
42 struct wpas_dbus_priv;
43
44 /**
45  * struct wpa_interface - Parameters for wpa_supplicant_add_iface()
46  */
47 struct wpa_interface {
48         /**
49          * confname - Configuration name (file or profile) name
50          *
51          * This can also be %NULL when a configuration file is not used. In
52          * that case, ctrl_interface must be set to allow the interface to be
53          * configured.
54          */
55         const char *confname;
56
57         /**
58          * ctrl_interface - Control interface parameter
59          *
60          * If a configuration file is not used, this variable can be used to
61          * set the ctrl_interface parameter that would have otherwise been read
62          * from the configuration file. If both confname and ctrl_interface are
63          * set, ctrl_interface is used to override the value from configuration
64          * file.
65          */
66         const char *ctrl_interface;
67
68         /**
69          * driver - Driver interface name, or %NULL to use the default driver
70          */
71         const char *driver;
72
73         /**
74          * driver_param - Driver interface parameters
75          *
76          * If a configuration file is not used, this variable can be used to
77          * set the driver_param parameters that would have otherwise been read
78          * from the configuration file. If both confname and driver_param are
79          * set, driver_param is used to override the value from configuration
80          * file.
81          */
82         const char *driver_param;
83
84         /**
85          * ifname - Interface name
86          */
87         const char *ifname;
88
89         /**
90          * bridge_ifname - Optional bridge interface name
91          *
92          * If the driver interface (ifname) is included in a Linux bridge
93          * device, the bridge interface may need to be used for receiving EAPOL
94          * frames. This can be enabled by setting this variable to enable
95          * receiving of EAPOL frames from an additional interface.
96          */
97         const char *bridge_ifname;
98 };
99
100 /**
101  * struct wpa_params - Parameters for wpa_supplicant_init()
102  */
103 struct wpa_params {
104         /**
105          * daemonize - Run %wpa_supplicant in the background
106          */
107         int daemonize;
108
109         /**
110          * wait_for_monitor - Wait for a monitor program before starting
111          */
112         int wait_for_monitor;
113
114         /**
115          * pid_file - Path to a PID (process ID) file
116          *
117          * If this and daemonize are set, process ID of the background process
118          * will be written to the specified file.
119          */
120         char *pid_file;
121
122         /**
123          * wpa_debug_level - Debugging verbosity level (e.g., MSG_INFO)
124          */
125         int wpa_debug_level;
126
127         /**
128          * wpa_debug_show_keys - Whether keying material is included in debug
129          *
130          * This parameter can be used to allow keying material to be included
131          * in debug messages. This is a security risk and this option should
132          * not be enabled in normal configuration. If needed during
133          * development or while troubleshooting, this option can provide more
134          * details for figuring out what is happening.
135          */
136         int wpa_debug_show_keys;
137
138         /**
139          * wpa_debug_timestamp - Whether to include timestamp in debug messages
140          */
141         int wpa_debug_timestamp;
142
143         /**
144          * ctrl_interface - Global ctrl_iface path/parameter
145          */
146         char *ctrl_interface;
147
148         /**
149          * dbus_ctrl_interface - Enable the DBus control interface
150          */
151         int dbus_ctrl_interface;
152
153         /**
154          * wpa_debug_file_path - Path of debug file or %NULL to use stdout
155          */
156         const char *wpa_debug_file_path;
157
158         /**
159          * wpa_debug_syslog - Enable log output through syslog
160          */
161         int wpa_debug_syslog;
162
163         /**
164          * wpa_debug_tracing - Enable log output through Linux tracing
165          */
166         int wpa_debug_tracing;
167
168         /**
169          * override_driver - Optional driver parameter override
170          *
171          * This parameter can be used to override the driver parameter in
172          * dynamic interface addition to force a specific driver wrapper to be
173          * used instead.
174          */
175         char *override_driver;
176
177         /**
178          * override_ctrl_interface - Optional ctrl_interface override
179          *
180          * This parameter can be used to override the ctrl_interface parameter
181          * in dynamic interface addition to force a control interface to be
182          * created.
183          */
184         char *override_ctrl_interface;
185
186         /**
187          * entropy_file - Optional entropy file
188          *
189          * This parameter can be used to configure wpa_supplicant to maintain
190          * its internal entropy store over restarts.
191          */
192         char *entropy_file;
193 };
194
195 struct p2p_srv_bonjour {
196         struct dl_list list;
197         struct wpabuf *query;
198         struct wpabuf *resp;
199 };
200
201 struct p2p_srv_upnp {
202         struct dl_list list;
203         u8 version;
204         char *service;
205 };
206
207 struct wpa_freq_range {
208         unsigned int min;
209         unsigned int max;
210 };
211
212
213 /**
214  * struct wpa_global - Internal, global data for all %wpa_supplicant interfaces
215  *
216  * This structure is initialized by calling wpa_supplicant_init() when starting
217  * %wpa_supplicant.
218  */
219 struct wpa_global {
220         struct wpa_supplicant *ifaces;
221         struct wpa_params params;
222         struct ctrl_iface_global_priv *ctrl_iface;
223         struct wpas_dbus_priv *dbus;
224         void **drv_priv;
225         size_t drv_count;
226         struct os_time suspend_time;
227         struct p2p_data *p2p;
228         struct wpa_supplicant *p2p_group_formation;
229         u8 p2p_dev_addr[ETH_ALEN];
230         struct dl_list p2p_srv_bonjour; /* struct p2p_srv_bonjour */
231         struct dl_list p2p_srv_upnp; /* struct p2p_srv_upnp */
232         int p2p_disabled;
233         int cross_connection;
234         struct wpa_freq_range *p2p_disallow_freq;
235         unsigned int num_p2p_disallow_freq;
236 };
237
238
239 enum offchannel_send_action_result {
240         OFFCHANNEL_SEND_ACTION_SUCCESS /* Frame was send and acknowledged */,
241         OFFCHANNEL_SEND_ACTION_NO_ACK /* Frame was sent, but not acknowledged
242                                        */,
243         OFFCHANNEL_SEND_ACTION_FAILED /* Frame was not sent due to a failure */
244 };
245
246 /**
247  * struct wpa_supplicant - Internal data for wpa_supplicant interface
248  *
249  * This structure contains the internal data for core wpa_supplicant code. This
250  * should be only used directly from the core code. However, a pointer to this
251  * data is used from other files as an arbitrary context pointer in calls to
252  * core functions.
253  */
254 struct wpa_supplicant {
255         struct wpa_global *global;
256         struct wpa_supplicant *parent;
257         struct wpa_supplicant *next;
258         struct l2_packet_data *l2;
259         struct l2_packet_data *l2_br;
260         unsigned char own_addr[ETH_ALEN];
261         char ifname[100];
262 #ifdef CONFIG_CTRL_IFACE_DBUS
263         char *dbus_path;
264 #endif /* CONFIG_CTRL_IFACE_DBUS */
265 #ifdef CONFIG_CTRL_IFACE_DBUS_NEW
266         char *dbus_new_path;
267         char *dbus_groupobj_path;
268 #ifdef CONFIG_AP
269         char *preq_notify_peer;
270 #endif /* CONFIG_AP */
271 #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
272         char bridge_ifname[16];
273
274         char *confname;
275         struct wpa_config *conf;
276         int countermeasures;
277         os_time_t last_michael_mic_error;
278         u8 bssid[ETH_ALEN];
279         u8 pending_bssid[ETH_ALEN]; /* If wpa_state == WPA_ASSOCIATING, this
280                                      * field contains the target BSSID. */
281         int reassociate; /* reassociation requested */
282         int disconnected; /* all connections disabled; i.e., do no reassociate
283                            * before this has been cleared */
284         struct wpa_ssid *current_ssid;
285         struct wpa_bss *current_bss;
286         int ap_ies_from_associnfo;
287         unsigned int assoc_freq;
288
289         /* Selected configuration (based on Beacon/ProbeResp WPA IE) */
290         int pairwise_cipher;
291         int group_cipher;
292         int key_mgmt;
293         int wpa_proto;
294         int mgmt_group_cipher;
295
296         void *drv_priv; /* private data used by driver_ops */
297         void *global_drv_priv;
298
299         u8 *bssid_filter;
300         size_t bssid_filter_count;
301
302         /* previous scan was wildcard when interleaving between
303          * wildcard scans and specific SSID scan when max_ssids=1 */
304         int prev_scan_wildcard;
305         struct wpa_ssid *prev_scan_ssid; /* previously scanned SSID;
306                                           * NULL = not yet initialized (start
307                                           * with wildcard SSID)
308                                           * WILDCARD_SSID_SCAN = wildcard
309                                           * SSID was used in the previous scan
310                                           */
311 #define WILDCARD_SSID_SCAN ((struct wpa_ssid *) 1)
312
313         struct wpa_ssid *prev_sched_ssid; /* last SSID used in sched scan */
314         int sched_scan_timeout;
315         int sched_scan_interval;
316         int first_sched_scan;
317         int sched_scan_timed_out;
318
319         void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
320                                  struct wpa_scan_results *scan_res);
321         struct dl_list bss; /* struct wpa_bss::list */
322         struct dl_list bss_id; /* struct wpa_bss::list_id */
323         size_t num_bss;
324         unsigned int bss_update_idx;
325         unsigned int bss_next_id;
326
327         struct wpa_driver_ops *driver;
328         int interface_removed; /* whether the network interface has been
329                                 * removed */
330         struct wpa_sm *wpa;
331         struct eapol_sm *eapol;
332
333         struct ctrl_iface_priv *ctrl_iface;
334
335         enum wpa_states wpa_state;
336         int scanning;
337         int sched_scanning;
338         int new_connection;
339         int reassociated_connection;
340
341         int eapol_received; /* number of EAPOL packets received after the
342                              * previous association event */
343
344         struct scard_data *scard;
345 #ifdef PCSC_FUNCS
346         char imsi[20];
347         int mnc_len;
348 #endif /* PCSC_FUNCS */
349
350         unsigned char last_eapol_src[ETH_ALEN];
351
352         int keys_cleared;
353
354         struct wpa_blacklist *blacklist;
355
356         int scan_req; /* manual scan request; this forces a scan even if there
357                        * are no enabled networks in the configuration */
358         int scan_runs; /* number of scan runs since WPS was started */
359         int *next_scan_freqs;
360         int scan_interval; /* time in sec between scans to find suitable AP */
361         int normal_scans; /* normal scans run before sched_scan */
362
363         unsigned int drv_flags;
364
365         /*
366          * A bitmap of supported protocols for probe response offload. See
367          * struct wpa_driver_capa in driver.h
368          */
369         unsigned int probe_resp_offloads;
370
371         int max_scan_ssids;
372         int max_sched_scan_ssids;
373         int sched_scan_supported;
374         unsigned int max_match_sets;
375         unsigned int max_remain_on_chan;
376         unsigned int max_stations;
377
378         int pending_mic_error_report;
379         int pending_mic_error_pairwise;
380         int mic_errors_seen; /* Michael MIC errors with the current PTK */
381
382         struct wps_context *wps;
383         int wps_success; /* WPS success event received */
384         struct wps_er *wps_er;
385         int blacklist_cleared;
386
387         struct wpabuf *pending_eapol_rx;
388         struct os_time pending_eapol_rx_time;
389         u8 pending_eapol_rx_src[ETH_ALEN];
390
391         struct ibss_rsn *ibss_rsn;
392
393         int set_sta_uapsd;
394         int sta_uapsd;
395         int set_ap_uapsd;
396         int ap_uapsd;
397
398 #ifdef CONFIG_SME
399         struct {
400                 u8 ssid[32];
401                 size_t ssid_len;
402                 int freq;
403                 u8 assoc_req_ie[200];
404                 size_t assoc_req_ie_len;
405                 int mfp;
406                 int ft_used;
407                 u8 mobility_domain[2];
408                 u8 *ft_ies;
409                 size_t ft_ies_len;
410                 u8 prev_bssid[ETH_ALEN];
411                 int prev_bssid_set;
412                 int auth_alg;
413                 int proto;
414
415                 int sa_query_count; /* number of pending SA Query requests;
416                                      * 0 = no SA Query in progress */
417                 int sa_query_timed_out;
418                 u8 *sa_query_trans_id; /* buffer of WLAN_SA_QUERY_TR_ID_LEN *
419                                         * sa_query_count octets of pending
420                                         * SA Query transaction identifiers */
421                 struct os_time sa_query_start;
422         } sme;
423 #endif /* CONFIG_SME */
424
425 #ifdef CONFIG_AP
426         struct hostapd_iface *ap_iface;
427         void (*ap_configured_cb)(void *ctx, void *data);
428         void *ap_configured_cb_ctx;
429         void *ap_configured_cb_data;
430 #endif /* CONFIG_AP */
431
432         unsigned int off_channel_freq;
433         struct wpabuf *pending_action_tx;
434         u8 pending_action_src[ETH_ALEN];
435         u8 pending_action_dst[ETH_ALEN];
436         u8 pending_action_bssid[ETH_ALEN];
437         unsigned int pending_action_freq;
438         int pending_action_no_cck;
439         int pending_action_without_roc;
440         void (*pending_action_tx_status_cb)(struct wpa_supplicant *wpa_s,
441                                             unsigned int freq, const u8 *dst,
442                                             const u8 *src, const u8 *bssid,
443                                             const u8 *data, size_t data_len,
444                                             enum offchannel_send_action_result
445                                             result);
446         unsigned int roc_waiting_drv_freq;
447         int action_tx_wait_time;
448
449 #ifdef CONFIG_P2P
450         struct p2p_go_neg_results *go_params;
451         int create_p2p_iface;
452         u8 pending_interface_addr[ETH_ALEN];
453         char pending_interface_name[100];
454         int pending_interface_type;
455         int p2p_group_idx;
456         unsigned int pending_listen_freq;
457         unsigned int pending_listen_duration;
458         enum {
459                 NOT_P2P_GROUP_INTERFACE,
460                 P2P_GROUP_INTERFACE_PENDING,
461                 P2P_GROUP_INTERFACE_GO,
462                 P2P_GROUP_INTERFACE_CLIENT
463         } p2p_group_interface;
464         struct p2p_group *p2p_group;
465         int p2p_long_listen; /* remaining time in long Listen state in ms */
466         char p2p_pin[10];
467         int p2p_wps_method;
468         u8 p2p_auth_invite[ETH_ALEN];
469         int p2p_sd_over_ctrl_iface;
470         int p2p_in_provisioning;
471         int pending_invite_ssid_id;
472         int show_group_started;
473         u8 go_dev_addr[ETH_ALEN];
474         int pending_pd_before_join;
475         u8 pending_join_iface_addr[ETH_ALEN];
476         u8 pending_join_dev_addr[ETH_ALEN];
477         int pending_join_wps_method;
478         int p2p_join_scan_count;
479         int force_long_sd;
480         u16 pending_pd_config_methods;
481         enum {
482                 NORMAL_PD, AUTO_PD_GO_NEG, AUTO_PD_JOIN
483         } pending_pd_use;
484
485         /*
486          * Whether cross connection is disallowed by the AP to which this
487          * interface is associated (only valid if there is an association).
488          */
489         int cross_connect_disallowed;
490
491         /*
492          * Whether this P2P group is configured to use cross connection (only
493          * valid if this is P2P GO interface). The actual cross connect packet
494          * forwarding may not be configured depending on the uplink status.
495          */
496         int cross_connect_enabled;
497
498         /* Whether cross connection forwarding is in use at the moment. */
499         int cross_connect_in_use;
500
501         /*
502          * Uplink interface name for cross connection
503          */
504         char cross_connect_uplink[100];
505
506         enum {
507                 P2P_GROUP_REMOVAL_UNKNOWN,
508                 P2P_GROUP_REMOVAL_REQUESTED,
509                 P2P_GROUP_REMOVAL_IDLE_TIMEOUT,
510                 P2P_GROUP_REMOVAL_UNAVAILABLE,
511                 P2P_GROUP_REMOVAL_GO_ENDING_SESSION
512         } removal_reason;
513
514         unsigned int p2p_cb_on_scan_complete:1;
515         unsigned int p2p_auto_join:1;
516         unsigned int p2p_auto_pd:1;
517         unsigned int p2p_persistent_group:1;
518         int p2p_go_intent;
519         int p2p_connect_freq;
520         struct os_time p2p_auto_started;
521 #endif /* CONFIG_P2P */
522
523         struct wpa_ssid *bgscan_ssid;
524         const struct bgscan_ops *bgscan;
525         void *bgscan_priv;
526
527         struct wpa_ssid *connect_without_scan;
528
529         int after_wps;
530         int known_wps_freq;
531         unsigned int wps_freq;
532         int wps_fragment_size;
533         int auto_reconnect_disabled;
534
535          /* Channel preferences for AP/P2P GO use */
536         int best_24_freq;
537         int best_5_freq;
538         int best_overall_freq;
539
540         struct gas_query *gas;
541
542 #ifdef CONFIG_INTERWORKING
543         unsigned int fetch_anqp_in_progress:1;
544         unsigned int network_select:1;
545         unsigned int auto_select:1;
546 #endif /* CONFIG_INTERWORKING */
547         unsigned int drv_capa_known;
548
549         struct {
550                 struct hostapd_hw_modes *modes;
551                 u16 num_modes;
552                 u16 flags;
553         } hw;
554
555         int pno;
556 };
557
558
559 /* wpa_supplicant.c */
560 void wpa_supplicant_apply_ht_overrides(
561         struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
562         struct wpa_driver_associate_params *params);
563
564 int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid);
565
566 int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s);
567
568 const char * wpa_supplicant_state_txt(enum wpa_states state);
569 int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s);
570 int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s);
571 int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
572                               struct wpa_bss *bss, struct wpa_ssid *ssid,
573                               u8 *wpa_ie, size_t *wpa_ie_len);
574 void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
575                               struct wpa_bss *bss,
576                               struct wpa_ssid *ssid);
577 void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s,
578                                        struct wpa_ssid *ssid);
579 void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s);
580 void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr);
581 void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
582                                      int sec, int usec);
583 void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
584                               enum wpa_states state);
585 struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s);
586 const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant *wpa_s);
587 void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s);
588 void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
589                                    int reason_code);
590 void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
591                                  int reason_code);
592
593 void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s,
594                                    struct wpa_ssid *ssid);
595 void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
596                                     struct wpa_ssid *ssid);
597 void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
598                                    struct wpa_ssid *ssid);
599 int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s,
600                                int ap_scan);
601 int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant *wpa_s,
602                                           unsigned int expire_age);
603 int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant *wpa_s,
604                                             unsigned int expire_count);
605 int wpa_supplicant_set_scan_interval(struct wpa_supplicant *wpa_s,
606                                      int scan_interval);
607 int wpa_supplicant_set_debug_params(struct wpa_global *global,
608                                     int debug_level, int debug_timestamp,
609                                     int debug_show_keys);
610 void free_hw_features(struct wpa_supplicant *wpa_s);
611
612 void wpa_show_license(void);
613
614 struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
615                                                  struct wpa_interface *iface);
616 int wpa_supplicant_remove_iface(struct wpa_global *global,
617                                 struct wpa_supplicant *wpa_s,
618                                 int terminate);
619 struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global,
620                                                  const char *ifname);
621 struct wpa_global * wpa_supplicant_init(struct wpa_params *params);
622 int wpa_supplicant_run(struct wpa_global *global);
623 void wpa_supplicant_deinit(struct wpa_global *global);
624
625 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
626                               struct wpa_ssid *ssid);
627 void wpa_supplicant_terminate_proc(struct wpa_global *global);
628 void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
629                              const u8 *buf, size_t len);
630 enum wpa_key_mgmt key_mgmt2driver(int key_mgmt);
631 enum wpa_cipher cipher_suite2driver(int cipher);
632 void wpa_supplicant_update_config(struct wpa_supplicant *wpa_s);
633 void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s);
634 void wpas_connection_failed(struct wpa_supplicant *wpa_s, const u8 *bssid);
635 int wpas_driver_bss_selection(struct wpa_supplicant *wpa_s);
636
637 /* events.c */
638 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s);
639 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
640                            struct wpa_bss *selected,
641                            struct wpa_ssid *ssid);
642 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx);
643 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx);
644
645 /* eap_register.c */
646 int eap_register_methods(void);
647
648 /**
649  * Utility method to tell if a given network is a persistent group
650  * @ssid: Network object
651  * Returns: 1 if network is a persistent group, 0 otherwise
652  */
653 static inline int network_is_persistent_group(struct wpa_ssid *ssid)
654 {
655         return ((ssid->disabled == 2) || ssid->p2p_persistent_group);
656 }
657
658 #endif /* WPA_SUPPLICANT_I_H */