1  /*
2   * P2P - Internal definitions for P2P module
3   * Copyright (c) 2009-2010, Atheros Communications
4   *
5   * This software may be distributed under the terms of the BSD license.
6   * See README for more details.
7   */
8  
9  #ifndef P2P_I_H
10  #define P2P_I_H
11  
12  #include "utils/list.h"
13  #include "drivers/driver.h"
14  #include "p2p.h"
15  
16  #define P2P_GO_NEG_CNF_MAX_RETRY_COUNT 1
17  
18  /*
19   * A threshold (in seconds) to prefer a direct Probe Response frame from a P2P
20   * Device over the P2P Client Info received from a GO.
21   */
22  #define P2P_DEV_GROUP_CLIENT_RESP_THRESHOLD 1
23  
24  enum p2p_role_indication;
25  
26  /*
27   * To force Service Instances to fit within a single P2P Tag, MAX_SVC_ADV_LEN
28   * must equal 248 or less. Must have a minimum size of 19.
29   */
30  #define MAX_SVC_ADV_LEN	600
31  #define MAX_SVC_ADV_IE_LEN (9 + MAX_SVC_ADV_LEN + (5 * (MAX_SVC_ADV_LEN / 240)))
32  
33  enum p2p_go_state {
34  	UNKNOWN_GO,
35  	LOCAL_GO,
36  	REMOTE_GO
37  };
38  
39  /* Enumeration for P2P device current role */
40  enum p2p_role {
41  	P2P_ROLE_IDLE = 0,
42  	P2P_ROLE_PAIRING_INITIATOR,
43  	P2P_ROLE_PAIRING_RESPONDER,
44  };
45  
46  /**
47   * struct bootstrap_params - P2P Device bootstrap request parameters
48   */
49  struct p2p_bootstrap_params {
50  	/* Bootstrap method */
51  	u16 bootstrap_method;
52  
53  	/* Status code */
54  	enum p2p_status_code status;
55  
56  	/* Cookie for comeback */
57  	u8 cookie[50];
58  
59  	/* Cookie length */
60  	size_t cookie_len;
61  
62  	/* Comeback time in TUs after which receiver is requested to retry */
63  	int comeback_after;
64  };
65  
66  /**
67   * struct p2p_device - P2P Device data (internal to P2P module)
68   */
69  struct p2p_device {
70  	struct dl_list list;
71  	struct os_reltime last_seen;
72  	int listen_freq;
73  	int oob_go_neg_freq;
74  	enum p2p_wps_method wps_method;
75  	u16 oob_pw_id;
76  
77  	struct p2p_peer_info info;
78  
79  	/*
80  	 * If the peer was discovered based on an interface address (e.g., GO
81  	 * from Beacon/Probe Response), the interface address is stored here.
82  	 * p2p_device_addr must still be set in such a case to the unique
83  	 * identifier for the P2P Device.
84  	 *
85  	 * This field is also used during P2PS PD to store the intended GO
86  	 * address of the peer.
87  	 */
88  	u8 interface_addr[ETH_ALEN];
89  
90  	/*
91  	 * P2P Device Address of the GO in whose group this P2P Device is a
92  	 * client.
93  	 */
94  	u8 member_in_go_dev[ETH_ALEN];
95  
96  	/*
97  	 * P2P Interface Address of the GO in whose group this P2P Device is a
98  	 * client.
99  	 */
100  	u8 member_in_go_iface[ETH_ALEN];
101  
102  	int go_neg_req_sent;
103  	enum p2p_go_state go_state;
104  	u8 dialog_token;
105  	u8 tie_breaker;
106  	u8 intended_addr[ETH_ALEN];
107  
108  	char country[3];
109  	struct p2p_channels channels;
110  	int oper_freq;
111  	u8 oper_ssid[SSID_MAX_LEN];
112  	size_t oper_ssid_len;
113  
114  	/**
115  	 * req_config_methods - Pending provision discovery methods
116  	 */
117  	u16 req_config_methods;
118  
119  	/**
120  	 * wps_prov_info - Stored provisioning WPS config method
121  	 *
122  	 * This is used to store pending WPS config method between Provisioning
123  	 * Discovery and connection to a running group.
124  	 */
125  	u16 wps_prov_info;
126  
127  #define P2P_DEV_PROBE_REQ_ONLY BIT(0)
128  #define P2P_DEV_REPORTED BIT(1)
129  #define P2P_DEV_NOT_YET_READY BIT(2)
130  #define P2P_DEV_PD_PEER_DISPLAY BIT(5)
131  #define P2P_DEV_PD_PEER_KEYPAD BIT(6)
132  #define P2P_DEV_USER_REJECTED BIT(7)
133  #define P2P_DEV_PEER_WAITING_RESPONSE BIT(8)
134  #define P2P_DEV_PREFER_PERSISTENT_GROUP BIT(9)
135  #define P2P_DEV_WAIT_GO_NEG_RESPONSE BIT(10)
136  #define P2P_DEV_WAIT_GO_NEG_CONFIRM BIT(11)
137  #define P2P_DEV_GROUP_CLIENT_ONLY BIT(12)
138  #define P2P_DEV_FORCE_FREQ BIT(13)
139  #define P2P_DEV_PD_FOR_JOIN BIT(14)
140  #define P2P_DEV_REPORTED_ONCE BIT(15)
141  #define P2P_DEV_PREFER_PERSISTENT_RECONN BIT(16)
142  #define P2P_DEV_PD_BEFORE_GO_NEG BIT(17)
143  #define P2P_DEV_NO_PREF_CHAN BIT(18)
144  #define P2P_DEV_WAIT_INV_REQ_ACK BIT(19)
145  #define P2P_DEV_P2PS_REPORTED BIT(20)
146  #define P2P_DEV_PD_PEER_P2PS BIT(21)
147  #define P2P_DEV_LAST_SEEN_AS_GROUP_CLIENT BIT(22)
148  
149  	unsigned int flags;
150  
151  	int status; /* enum p2p_status_code */
152  	unsigned int wait_count;
153  	unsigned int connect_reqs;
154  	unsigned int invitation_reqs;
155  	unsigned int sd_reqs;
156  
157  	u16 ext_listen_period;
158  	u16 ext_listen_interval;
159  
160  	u8 go_timeout;
161  	u8 client_timeout;
162  
163  	/**
164  	 * go_neg_conf_sent - Number of GO Negotiation Confirmation retries
165  	 */
166  	u8 go_neg_conf_sent;
167  
168  	/**
169  	 * freq - Frquency on which the GO Negotiation Confirmation is sent
170  	 */
171  	int go_neg_conf_freq;
172  
173  	/**
174  	 * go_neg_conf - GO Negotiation Confirmation frame
175  	 */
176  	struct wpabuf *go_neg_conf;
177  
178  	int sd_pending_bcast_queries;
179  	bool support_6ghz;
180  
181  	/* Supports P2P2 */
182  	bool p2p2;
183  
184  	/* Requested bootstrap method */
185  	u16 req_bootstrap_method;
186  
187  	/* Bootstrap parameters received from peer */
188  	struct p2p_bootstrap_params *bootstrap_params;
189  
190  	/* Password for P2P2 GO negotiation */
191  	char password[100];
192  
193  	/* PASN data structure */
194  	struct pasn_data *pasn;
195  	struct wpabuf *action_frame_wrapper;
196  
197  	/* Device role */
198  	enum p2p_role role;
199  
200  	/* Invitation parameters for P2P2 */
201  	bool inv_reject;
202  	u8 inv_status;
203  	int inv_freq;
204  	int inv_peer_oper_freq;
205  	u8 inv_bssid[ETH_ALEN];
206  	u8 inv_ssid[SSID_MAX_LEN];
207  	size_t inv_ssid_len;
208  	bool inv_all_channels;
209  };
210  
211  struct p2p_sd_query {
212  	struct p2p_sd_query *next;
213  	u8 peer[ETH_ALEN];
214  	int for_all_peers;
215  	int wsd; /* Wi-Fi Display Service Discovery Request */
216  	struct wpabuf *tlvs;
217  };
218  
219  /* P2P Device Identity Key parameters */
220  struct p2p_id_key {
221  	/* AKMP used for DevIK derviation */
222  	int akmp;
223  	/* Cipher version type */
224  	int cipher_version;
225  	/* DevIK expiration time in hours */
226  	u32 expiration;
227  	/* Buffer to hold the DevIK */
228  	u8 dik_data[DEVICE_IDENTITY_KEY_MAX_LEN];
229  	/* Length of DevIK */
230  	size_t dik_len;
231  	/* Nonce used in DIRA attribute */
232  	u8 dira_nonce[DEVICE_IDENTITY_NONCE_LEN];
233  	/* Length of nonce */
234  	size_t dira_nonce_len;
235  	/* Tag computed for nonce using NIK */
236  	u8 dira_tag[DEVICE_IDENTITY_TAG_LEN];
237  	/* Length of tag in octets */
238  	size_t dira_tag_len;
239  };
240  
241  struct p2p_pairing_info {
242  	/* P2P device own address */
243  	u8 own_addr[ETH_ALEN];
244  	/* device capability to enable pairing setup */
245  	bool enable_pairing_setup;
246  	/* device capability to enable pairing cache */
247  	bool enable_pairing_cache;
248  	/* device supported bootstrapping */
249  	u16 supported_bootstrap;
250  	/* P2P Device Identity Key info */
251  	struct p2p_id_key dev_ik;
252  };
253  
254  /**
255   * struct p2p_data - P2P module data (internal to P2P module)
256   */
257  struct p2p_data {
258  	/**
259  	 * cfg - P2P module configuration
260  	 *
261  	 * This is included in the same memory allocation with the
262  	 * struct p2p_data and as such, must not be freed separately.
263  	 */
264  	struct p2p_config *cfg;
265  
266  	/**
267  	 * state - The current P2P state
268  	 */
269  	enum p2p_state {
270  		/**
271  		 * P2P_IDLE - Idle
272  		 */
273  		P2P_IDLE,
274  
275  		/**
276  		 * P2P_SEARCH - Search (Device Discovery)
277  		 */
278  		P2P_SEARCH,
279  
280  		/**
281  		 * P2P_CONNECT - Trying to start GO Negotiation
282  		 */
283  		P2P_CONNECT,
284  
285  		/**
286  		 * P2P_CONNECT_LISTEN - Listen during GO Negotiation start
287  		 */
288  		P2P_CONNECT_LISTEN,
289  
290  		/**
291  		 * P2P_GO_NEG - In GO Negotiation
292  		 */
293  		P2P_GO_NEG,
294  
295  		/**
296  		 * P2P_LISTEN_ONLY - Listen only
297  		 */
298  		P2P_LISTEN_ONLY,
299  
300  		/**
301  		 * P2P_WAIT_PEER_CONNECT - Waiting peer in List for GO Neg
302  		 */
303  		P2P_WAIT_PEER_CONNECT,
304  
305  		/**
306  		 * P2P_WAIT_PEER_IDLE - Waiting peer idle for GO Neg
307  		 */
308  		P2P_WAIT_PEER_IDLE,
309  
310  		/**
311  		 * P2P_SD_DURING_FIND - Service Discovery during find
312  		 */
313  		P2P_SD_DURING_FIND,
314  
315  		/**
316  		 * P2P_PROVISIONING - Provisioning (during group formation)
317  		 */
318  		P2P_PROVISIONING,
319  
320  		/**
321  		 * P2P_PD_DURING_FIND - Provision Discovery during find
322  		 */
323  		P2P_PD_DURING_FIND,
324  
325  		/**
326  		 * P2P_INVITE - Trying to start Invite
327  		 */
328  		P2P_INVITE,
329  
330  		/**
331  		 * P2P_INVITE_LISTEN - Listen during Invite
332  		 */
333  		P2P_INVITE_LISTEN,
334  	} state;
335  
336  	/**
337  	 * min_disc_int - minDiscoverableInterval
338  	 */
339  	int min_disc_int;
340  
341  	/**
342  	 * max_disc_int - maxDiscoverableInterval
343  	 */
344  	int max_disc_int;
345  
346  	/**
347  	 * max_disc_tu - Maximum number of TUs for discoverable interval
348  	 */
349  	int max_disc_tu;
350  
351  	/**
352  	 * devices - List of known P2P Device peers
353  	 */
354  	struct dl_list devices;
355  
356  	/**
357  	 * go_neg_peer - Pointer to GO Negotiation peer
358  	 */
359  	struct p2p_device *go_neg_peer;
360  
361  	/**
362  	 * invite_peer - Pointer to Invite peer
363  	 */
364  	struct p2p_device *invite_peer;
365  
366  	/**
367  	 * last_p2p_find_oper - Pointer to last pre-find operation peer
368  	 */
369  	struct p2p_device *last_p2p_find_oper;
370  
371  	const u8 *invite_go_dev_addr;
372  	u8 invite_go_dev_addr_buf[ETH_ALEN];
373  	int invite_dev_pw_id;
374  
375  	unsigned int retry_invite_req:1;
376  	unsigned int retry_invite_req_sent:1;
377  
378  	/**
379  	 * sd_peer - Pointer to Service Discovery peer
380  	 */
381  	struct p2p_device *sd_peer;
382  
383  	/**
384  	 * sd_query - Pointer to Service Discovery query
385  	 */
386  	struct p2p_sd_query *sd_query;
387  
388  	/**
389  	 * num_p2p_sd_queries - Total number of broadcast SD queries present in
390  	 * the list
391  	 */
392  	int num_p2p_sd_queries;
393  
394  	/**
395  	 * sd_query_no_ack - The first peer (Dev Addr) that did not ACK SD Query
396  	 *
397  	 * This is used to track the first peer that did not ACK an SD Query
398  	 * within a single P2P Search iteration. All zeros address means no such
399  	 * peer was yet seen. This information is used to allow a new Listen and
400  	 * Search phases to be once every pending SD Query has been sent once to
401  	 * each peer instead of looping all pending attempts continuously until
402  	 * running out of retry maximums.
403  	 */
404  	u8 sd_query_no_ack[ETH_ALEN];
405  
406  	/* GO Negotiation data */
407  
408  	/**
409  	 * intended_addr - Local Intended P2P Interface Address
410  	 *
411  	 * This address is used during group owner negotiation as the Intended
412  	 * P2P Interface Address and the group interface will be created with
413  	 * address as the local address in case of successfully completed
414  	 * negotiation.
415  	 */
416  	u8 intended_addr[ETH_ALEN];
417  
418  	/**
419  	 * go_intent - Local GO Intent to be used during GO Negotiation
420  	 */
421  	u8 go_intent;
422  
423  	/**
424  	 * next_tie_breaker - Next tie-breaker value to use in GO Negotiation
425  	 */
426  	u8 next_tie_breaker;
427  
428  	/**
429  	 * ssid - Selected SSID for GO Negotiation (if local end will be GO)
430  	 */
431  	u8 ssid[SSID_MAX_LEN];
432  
433  	/**
434  	 * ssid_len - ssid length in octets
435  	 */
436  	size_t ssid_len;
437  
438  	/**
439  	 * ssid_set - Whether SSID is already set for GO Negotiation
440  	 */
441  	int ssid_set;
442  
443  	/**
444  	 * Regulatory class for own operational channel
445  	 */
446  	u8 op_reg_class;
447  
448  	/**
449  	 * op_channel - Own operational channel
450  	 */
451  	u8 op_channel;
452  
453  	/**
454  	 * channels - Own supported regulatory classes and channels
455  	 *
456  	 * List of supposerted channels per regulatory class. The regulatory
457  	 * classes are defined in IEEE Std 802.11-2007 Annex J and the
458  	 * numbering of the clases depends on the configured country code.
459  	 */
460  	struct p2p_channels channels;
461  
462  	struct wpa_freq_range_list no_go_freq;
463  
464  	enum p2p_pending_action_state {
465  		P2P_NO_PENDING_ACTION,
466  		P2P_PENDING_GO_NEG_REQUEST,
467  		P2P_PENDING_GO_NEG_RESPONSE,
468  		P2P_PENDING_GO_NEG_RESPONSE_FAILURE,
469  		P2P_PENDING_GO_NEG_CONFIRM,
470  		P2P_PENDING_SD,
471  		P2P_PENDING_PD,
472  		P2P_PENDING_PD_RESPONSE,
473  		P2P_PENDING_INVITATION_REQUEST,
474  		P2P_PENDING_INVITATION_RESPONSE,
475  		P2P_PENDING_DEV_DISC_REQUEST,
476  		P2P_PENDING_DEV_DISC_RESPONSE,
477  		P2P_PENDING_GO_DISC_REQ
478  	} pending_action_state;
479  
480  	unsigned int pending_listen_freq;
481  	unsigned int pending_listen_sec;
482  	unsigned int pending_listen_usec;
483  	bool pending_listen_wait_drv;
484  
485  	u8 dev_capab;
486  
487  	int in_listen;
488  	int drv_in_listen;
489  
490  	/**
491  	 * sd_queries - Pending service discovery queries
492  	 */
493  	struct p2p_sd_query *sd_queries;
494  
495  	/**
496  	 * srv_update_indic - Service Update Indicator for local services
497  	 */
498  	u16 srv_update_indic;
499  
500  	struct wpabuf *sd_resp; /* Fragmented SD response */
501  	u8 sd_resp_addr[ETH_ALEN];
502  	u8 sd_resp_dialog_token;
503  	size_t sd_resp_pos; /* Offset in sd_resp */
504  	u8 sd_frag_id;
505  
506  	struct wpabuf *sd_rx_resp; /* Reassembled SD response */
507  	u16 sd_rx_update_indic;
508  
509  	/* P2P Invitation data */
510  	enum p2p_invite_role inv_role;
511  	u8 inv_bssid[ETH_ALEN];
512  	int inv_bssid_set;
513  	u8 inv_ssid[SSID_MAX_LEN];
514  	size_t inv_ssid_len;
515  	u8 inv_sa[ETH_ALEN];
516  	u8 inv_group_bssid[ETH_ALEN];
517  	u8 *inv_group_bssid_ptr;
518  	u8 inv_go_dev_addr[ETH_ALEN];
519  	u8 inv_status;
520  	int inv_op_freq;
521  	int inv_persistent;
522  
523  	enum p2p_discovery_type find_type;
524  	int find_specified_freq;
525  	unsigned int last_p2p_find_timeout;
526  	u8 last_prog_scan_class;
527  	u8 last_prog_scan_chan;
528  	unsigned int find_pending_full:1;
529  	int p2p_scan_running;
530  	enum p2p_after_scan {
531  		P2P_AFTER_SCAN_NOTHING,
532  		P2P_AFTER_SCAN_LISTEN,
533  		P2P_AFTER_SCAN_CONNECT
534  	} start_after_scan;
535  	u8 after_scan_peer[ETH_ALEN];
536  	unsigned int send_action_in_progress:1;
537  
538  	/* Requested device types for find/search */
539  	unsigned int num_req_dev_types;
540  	u8 *req_dev_types;
541  	u8 *find_dev_id;
542  	u8 find_dev_id_buf[ETH_ALEN];
543  
544  	struct os_reltime find_start; /* time of last p2p_find start */
545  
546  	struct p2p_group **groups;
547  	size_t num_groups;
548  
549  	struct p2p_device *pending_client_disc_go;
550  	u8 pending_client_disc_addr[ETH_ALEN];
551  	u8 pending_dev_disc_dialog_token;
552  	u8 pending_dev_disc_addr[ETH_ALEN];
553  	int pending_dev_disc_freq;
554  	unsigned int pending_client_disc_freq;
555  
556  	int ext_listen_only;
557  	unsigned int ext_listen_period;
558  	unsigned int ext_listen_interval;
559  	unsigned int ext_listen_interval_sec;
560  	unsigned int ext_listen_interval_usec;
561  
562  	u8 peer_filter[ETH_ALEN];
563  
564  	int cross_connect;
565  
566  	int best_freq_24;
567  	int best_freq_5;
568  	int best_freq_overall;
569  	int own_freq_preference;
570  
571  	/**
572  	 * wps_vendor_ext - WPS Vendor Extensions to add
573  	 */
574  	struct wpabuf *wps_vendor_ext[P2P_MAX_WPS_VENDOR_EXT];
575  
576  	/*
577  	 * user_initiated_pd - Whether a PD request is user initiated or not.
578  	 */
579  	u8 user_initiated_pd;
580  
581  	/*
582  	 * Keep track of which peer a given PD request was sent to.
583  	 * Used to raise a timeout alert in case there is no response.
584  	 */
585  	u8 pending_pd_devaddr[ETH_ALEN];
586  
587  	/*
588  	 * Retry counter for provision discovery requests when issued
589  	 * in IDLE state.
590  	 */
591  	int pd_retries;
592  
593  	/**
594  	 * pd_force_freq - Forced frequency for PD retries or 0 to auto-select
595  	 *
596  	 * This is is used during PD retries for join-a-group case to use the
597  	 * correct operating frequency determined from a BSS entry for the GO.
598  	 */
599  	int pd_force_freq;
600  
601  	u8 go_timeout;
602  	u8 client_timeout;
603  
604  	/* Extra delay in milliseconds between search iterations */
605  	unsigned int search_delay;
606  	int in_search_delay;
607  
608  	u8 pending_reg_class;
609  	u8 pending_channel;
610  	u8 pending_channel_forced;
611  
612  	/* ASP Support */
613  	struct p2ps_advertisement *p2ps_adv_list;
614  	struct p2ps_provision *p2ps_prov;
615  	u8 wild_card_hash[P2PS_HASH_LEN];
616  	u8 p2ps_seek;
617  	u8 p2ps_seek_hash[P2P_MAX_QUERY_HASH * P2PS_HASH_LEN];
618  	u8 p2ps_seek_count;
619  
620  #ifdef CONFIG_WIFI_DISPLAY
621  	struct wpabuf *wfd_ie_beacon;
622  	struct wpabuf *wfd_ie_probe_req;
623  	struct wpabuf *wfd_ie_probe_resp;
624  	struct wpabuf *wfd_ie_assoc_req;
625  	struct wpabuf *wfd_ie_invitation;
626  	struct wpabuf *wfd_ie_prov_disc_req;
627  	struct wpabuf *wfd_ie_prov_disc_resp;
628  	struct wpabuf *wfd_ie_go_neg;
629  	struct wpabuf *wfd_dev_info;
630  	struct wpabuf *wfd_assoc_bssid;
631  	struct wpabuf *wfd_coupled_sink_info;
632  	struct wpabuf *wfd_r2_dev_info;
633  #endif /* CONFIG_WIFI_DISPLAY */
634  
635  	u16 authorized_oob_dev_pw_id;
636  
637  	struct wpabuf **vendor_elem;
638  
639  	struct weighted_pcl pref_freq_list[P2P_MAX_PREF_CHANNELS];
640  	unsigned int num_pref_freq;
641  
642  	/* Override option for preferred operating channel in GO Negotiation */
643  	u8 override_pref_op_class;
644  	u8 override_pref_channel;
645  	bool p2p_6ghz_capable;
646  	bool include_6ghz;
647  	bool allow_6ghz;
648  
649  	struct p2p_pairing_info *pairing_info;
650  
651  	/* Pairing initiator PMKSA cache */
652  	struct rsn_pmksa_cache *initiator_pmksa;
653  	/* Pairing responder PMKSA cache */
654  	struct rsn_pmksa_cache *responder_pmksa;
655  
656  	/* DevIK variables: Cipher version, DevIK, and its lifetime
657  	 * These are fetched from the P2P2 included in the PASN Encrypted Data
658  	 * element during P2P2 group negotiation with PASN Authentication
659  	 * frames. These values are stored in struct p2p_data for an ongoing GO
660  	 * negotiation or join-a-group operation with the assumption that these
661  	 * operations cannot happen in parallel with multiple peers. After
662  	 * successful group formation and connection, these are moved to
663  	 * wpa_supplicant configuration if the connection is persistent. */
664  	u8 dik_cipher_version;
665  	u8 peer_dik_data[DEVICE_IDENTITY_KEY_MAX_LEN];
666  	size_t peer_dik_len;
667  	unsigned int peer_dik_lifetime;
668  
669  	/* Password used during an ongoing group formation after opportunistic
670  	 * PASN authentication or while joining an existing group. This will be
671  	 * moved to a more permanent location from struct p2p_data at the
672  	 * conclusion of a successful pairing. */
673  	char dev_sae_password[100];
674  	char peer_sae_password[100];
675  
676  	/* Variable used to know the role of the device in a given instance.
677  	 * go_role variable is set while authorizing a P2P Client for PASN
678  	 * authentication with predefined GO intent value for GO (15 for
679  	 * P2P-GO). Once the authentication is completed and security
680  	 * configuration is done, this variable is reset to false.
681  	 */
682  	bool go_role;
683  
684  #ifdef CONFIG_TESTING_OPTIONS
685  	/**
686  	 * PASN PTK of recent auth
687  	 */
688  	u8 pasn_ptk[128];
689  
690  	/**
691  	 * PASN PTK length
692  	 */
693  	size_t pasn_ptk_len;
694  #endif /* CONFIG_TESTING_OPTIONS */
695  
696  	bool usd_service;
697  	u8 p2p_service_hash[P2PS_HASH_LEN];
698  };
699  
700  /**
701   * struct p2p_message - Parsed P2P message (or P2P IE)
702   */
703  struct p2p_message {
704  	struct wpabuf *p2p_attributes;
705  	struct wpabuf *p2p2_attributes;
706  	struct wpabuf *wps_attributes;
707  	struct wpabuf *wfd_subelems;
708  
709  	u8 dialog_token;
710  
711  	const u8 *capability;
712  	const u8 *go_intent;
713  	const u8 *status;
714  	const u8 *listen_channel;
715  	const u8 *operating_channel;
716  	const u8 *channel_list;
717  	u8 channel_list_len;
718  	const u8 *config_timeout;
719  	const u8 *intended_addr;
720  	const u8 *group_bssid;
721  	const u8 *invitation_flags;
722  
723  	const u8 *group_info;
724  	size_t group_info_len;
725  
726  	const u8 *group_id;
727  	size_t group_id_len;
728  
729  	const u8 *device_id;
730  
731  	const u8 *manageability;
732  
733  	const u8 *noa;
734  	size_t noa_len;
735  
736  	const u8 *ext_listen_timing;
737  
738  	const u8 *minor_reason_code;
739  
740  	const u8 *oob_go_neg_channel;
741  
742  	/* P2P Device Info */
743  	const u8 *p2p_device_info;
744  	size_t p2p_device_info_len;
745  	const u8 *p2p_device_addr;
746  	const u8 *pri_dev_type;
747  	u8 num_sec_dev_types;
748  	char device_name[WPS_DEV_NAME_MAX_LEN + 1];
749  	u16 config_methods;
750  
751  	/* WPS IE */
752  	u16 dev_password_id;
753  	int dev_password_id_present;
754  	u16 wps_config_methods;
755  	const u8 *wps_pri_dev_type;
756  	const u8 *wps_sec_dev_type_list;
757  	size_t wps_sec_dev_type_list_len;
758  	const u8 *wps_vendor_ext[P2P_MAX_WPS_VENDOR_EXT];
759  	size_t wps_vendor_ext_len[P2P_MAX_WPS_VENDOR_EXT];
760  	const u8 *manufacturer;
761  	size_t manufacturer_len;
762  	const u8 *model_name;
763  	size_t model_name_len;
764  	const u8 *model_number;
765  	size_t model_number_len;
766  	const u8 *serial_number;
767  	size_t serial_number_len;
768  	const u8 *oob_dev_password;
769  	size_t oob_dev_password_len;
770  
771  	/* DS Parameter Set IE */
772  	const u8 *ds_params;
773  
774  	/* SSID IE */
775  	const u8 *ssid;
776  
777  	/* P2PS */
778  	u8 service_hash_count;
779  	const u8 *service_hash;
780  
781  	const u8 *session_info;
782  	size_t session_info_len;
783  
784  	const u8 *conn_cap;
785  
786  	const u8 *adv_id;
787  	const u8 *adv_mac;
788  
789  	const u8 *adv_service_instance;
790  	size_t adv_service_instance_len;
791  
792  	const u8 *session_id;
793  	const u8 *session_mac;
794  
795  	const u8 *feature_cap;
796  	size_t feature_cap_len;
797  
798  	const u8 *persistent_dev;
799  	const u8 *persistent_ssid;
800  	size_t persistent_ssid_len;
801  
802  	const u8 *pref_freq_list;
803  	size_t pref_freq_list_len;
804  
805  	const u8 *pcea_info;
806  	size_t pcea_info_len;
807  
808  	const u8 *pbma_info;
809  	size_t pbma_info_len;
810  
811  	const u8 *action_frame_wrapper;
812  	size_t action_frame_wrapper_len;
813  
814  	const u8 *dira;
815  	size_t dira_len;
816  
817  	const u8 *wlan_ap_info;
818  	size_t wlan_ap_info_len;
819  };
820  
821  
822  #define P2P_MAX_GROUP_ENTRIES 50
823  
824  struct p2p_group_info {
825  	unsigned int num_clients;
826  	struct p2p_client_info {
827  		const u8 *p2p_device_addr;
828  		const u8 *p2p_interface_addr;
829  		u8 dev_capab;
830  		u16 config_methods;
831  		const u8 *pri_dev_type;
832  		u8 num_sec_dev_types;
833  		const u8 *sec_dev_types;
834  		const char *dev_name;
835  		size_t dev_name_len;
836  	} client[P2P_MAX_GROUP_ENTRIES];
837  };
838  
839  
840  /* p2p_utils.c */
841  int p2p_random(char *buf, size_t len);
842  int p2p_freq_to_channel(unsigned int freq, u8 *op_class, u8 *channel);
843  void p2p_channels_intersect(const struct p2p_channels *a,
844  			    const struct p2p_channels *b,
845  			    struct p2p_channels *res);
846  void p2p_channels_union_inplace(struct p2p_channels *res,
847  				const struct p2p_channels *b);
848  void p2p_channels_union(const struct p2p_channels *a,
849  			const struct p2p_channels *b,
850  			struct p2p_channels *res);
851  void p2p_channels_remove_freqs(struct p2p_channels *chan,
852  			       const struct wpa_freq_range_list *list);
853  int p2p_channels_includes(const struct p2p_channels *channels, u8 reg_class,
854  			  u8 channel);
855  void p2p_channels_dump(struct p2p_data *p2p, const char *title,
856  		       const struct p2p_channels *chan);
857  int p2p_channel_select(struct p2p_channels *chans, const int *classes,
858  		       u8 *op_class, u8 *op_channel);
859  int p2p_channel_random_social(struct p2p_channels *chans, u8 *op_class,
860  			      u8 *op_channel,
861  			      struct wpa_freq_range_list *avoid_list,
862  			      struct wpa_freq_range_list *disallow_list);
863  void p2p_copy_channels(struct p2p_channels *dst, const struct p2p_channels *src,
864  		       bool allow_6ghz);
865  
866  /* p2p_parse.c */
867  void p2p_copy_filter_devname(char *dst, size_t dst_len,
868  			     const void *src, size_t src_len);
869  int p2p_parse_p2p_ie(const struct wpabuf *buf, struct p2p_message *msg);
870  int p2p_parse_ies(const u8 *data, size_t len, struct p2p_message *msg);
871  int p2p_parse(const u8 *data, size_t len, struct p2p_message *msg);
872  int p2p_parse_ies_separate(const u8 *wsc, size_t wsc_len, const u8 *p2p,
873  			   size_t p2p_len, struct p2p_message *msg);
874  void p2p_parse_free(struct p2p_message *msg);
875  int p2p_attr_text(struct wpabuf *data, char *buf, char *end);
876  int p2p_group_info_parse(const u8 *gi, size_t gi_len,
877  			 struct p2p_group_info *info);
878  
879  /* p2p_build.c */
880  
881  struct p2p_noa_desc {
882  	u8 count_type;
883  	u32 duration;
884  	u32 interval;
885  	u32 start_time;
886  };
887  
888  /* p2p_group.c */
889  const u8 * p2p_group_get_interface_addr(struct p2p_group *group);
890  u8 p2p_group_presence_req(struct p2p_group *group,
891  			  const u8 *client_interface_addr,
892  			  const u8 *noa, size_t noa_len);
893  int p2p_group_is_group_id_match(struct p2p_group *group, const u8 *group_id,
894  				size_t group_id_len);
895  void p2p_group_update_ies(struct p2p_group *group);
896  void p2p_group_force_beacon_update_ies(struct p2p_group *group);
897  struct wpabuf * p2p_group_get_wfd_ie(struct p2p_group *g);
898  void p2p_buf_add_group_info(struct p2p_group *group, struct wpabuf *buf,
899  			    int max_clients);
900  void p2p_group_buf_add_id(struct p2p_group *group, struct wpabuf *buf);
901  int p2p_group_get_freq(struct p2p_group *group);
902  
903  
904  void p2p_buf_add_action_hdr(struct wpabuf *buf, u8 subtype, u8 dialog_token);
905  void p2p_buf_add_public_action_hdr(struct wpabuf *buf, u8 subtype,
906  				   u8 dialog_token);
907  u8 * p2p_buf_add_ie_hdr(struct wpabuf *buf);
908  u8 * p2p_buf_add_p2p2_ie_hdr(struct wpabuf *buf);
909  void p2p_buf_add_status(struct wpabuf *buf, u8 status);
910  void p2p_buf_add_device_info(struct wpabuf *buf, struct p2p_data *p2p,
911  			     struct p2p_device *peer);
912  void p2p_buf_add_device_id(struct wpabuf *buf, const u8 *dev_addr);
913  void p2p_buf_update_ie_hdr(struct wpabuf *buf, u8 *len);
914  void p2p_buf_add_capability(struct wpabuf *buf, u8 dev_capab, u8 group_capab);
915  void p2p_buf_add_go_intent(struct wpabuf *buf, u8 go_intent);
916  void p2p_buf_add_listen_channel(struct wpabuf *buf, const char *country,
917  				u8 reg_class, u8 channel);
918  void p2p_buf_add_operating_channel(struct wpabuf *buf, const char *country,
919  				   u8 reg_class, u8 channel);
920  void p2p_buf_add_channel_list(struct wpabuf *buf, const char *country,
921  			      struct p2p_channels *chan, bool is_6ghz_capab);
922  void p2p_buf_add_config_timeout(struct wpabuf *buf, u8 go_timeout,
923  				u8 client_timeout);
924  void p2p_buf_add_intended_addr(struct wpabuf *buf, const u8 *interface_addr);
925  void p2p_buf_add_group_bssid(struct wpabuf *buf, const u8 *bssid);
926  void p2p_buf_add_group_id(struct wpabuf *buf, const u8 *dev_addr,
927  			  const u8 *ssid, size_t ssid_len);
928  void p2p_buf_add_invitation_flags(struct wpabuf *buf, u8 flags);
929  void p2p_buf_add_noa(struct wpabuf *buf, u8 noa_index, u8 opp_ps, u8 ctwindow,
930  		     struct p2p_noa_desc *desc1, struct p2p_noa_desc *desc2);
931  void p2p_buf_add_ext_listen_timing(struct wpabuf *buf, u16 period,
932  				   u16 interval);
933  void p2p_buf_add_p2p_interface(struct wpabuf *buf, struct p2p_data *p2p);
934  void p2p_buf_add_oob_go_neg_channel(struct wpabuf *buf, const char *country,
935  				    u8 oper_class, u8 channel,
936  				    enum p2p_role_indication role);
937  void p2p_buf_add_service_hash(struct wpabuf *buf, struct p2p_data *p2p);
938  void p2p_buf_add_session_info(struct wpabuf *buf, const char *info);
939  void p2p_buf_add_connection_capability(struct wpabuf *buf, u8 connection_cap);
940  void p2p_buf_add_advertisement_id(struct wpabuf *buf, u32 id, const u8 *mac);
941  void p2p_buf_add_service_instance(struct wpabuf *buf, struct p2p_data *p2p,
942  				  u8 count, const u8 *hash,
943  				  struct p2ps_advertisement *adv_list);
944  void p2p_buf_add_session_id(struct wpabuf *buf, u32 id, const u8 *mac);
945  void p2p_buf_add_feature_capability(struct wpabuf *buf, u16 len,
946  				    const u8 *mask);
947  void p2p_buf_add_persistent_group_info(struct wpabuf *buf, const u8 *dev_addr,
948  				       const u8 *ssid, size_t ssid_len);
949  void p2p_buf_add_pcea(struct wpabuf *buf, struct p2p_data *p2p);
950  void p2p_buf_add_pbma(struct wpabuf *buf, u16 bootstrap, const u8 *cookie,
951  		      size_t cookie_len, int comeback_after);
952  void p2p_buf_add_dira(struct wpabuf *buf, struct p2p_data *p2p);
953  int p2p_build_wps_ie(struct p2p_data *p2p, struct wpabuf *buf, int pw_id,
954  		     int all_attr);
955  void p2p_buf_add_pref_channel_list(struct wpabuf *buf,
956  				   const struct weighted_pcl *pref_freq_list,
957  				   unsigned int size);
958  struct wpabuf * p2p_encaps_ie(const struct wpabuf *subelems, u32 ie_type);
959  struct wpabuf * p2p_group_build_p2p2_ie(struct p2p_data *p2p,
960  					struct wpabuf *p2p2_ie, int freq);
961  
962  /* p2p_sd.c */
963  struct p2p_sd_query * p2p_pending_sd_req(struct p2p_data *p2p,
964  					 struct p2p_device *dev);
965  void p2p_free_sd_queries(struct p2p_data *p2p);
966  void p2p_rx_gas_initial_req(struct p2p_data *p2p, const u8 *sa,
967  			    const u8 *data, size_t len, int rx_freq);
968  void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
969  			     const u8 *data, size_t len, int rx_freq);
970  void p2p_rx_gas_comeback_req(struct p2p_data *p2p, const u8 *sa,
971  			     const u8 *data, size_t len, int rx_freq);
972  void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa,
973  			      const u8 *data, size_t len, int rx_freq);
974  int p2p_start_sd(struct p2p_data *p2p, struct p2p_device *dev);
975  
976  /* p2p_go_neg.c */
977  struct wpabuf * p2p_build_go_neg_req(struct p2p_data *p2p,
978  				     struct p2p_device *peer);
979  int p2p_peer_channels_check(struct p2p_data *p2p, struct p2p_channels *own,
980  			    struct p2p_device *dev,
981  			    const u8 *channel_list, size_t channel_list_len);
982  void p2p_handle_go_neg_req(struct p2p_data *p2p, const u8 *sa, const u8 *data,
983  			   size_t len, int rx_freq);
984  void p2p_handle_go_neg_resp(struct p2p_data *p2p, const u8 *sa, const u8 *data,
985  			    size_t len, int rx_freq);
986  void p2p_handle_go_neg_conf(struct p2p_data *p2p, const u8 *sa, const u8 *data,
987  			    size_t len, bool p2p2);
988  struct wpabuf * p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
989  				       const u8 *data, size_t len, int rx_freq,
990  				       bool p2p2);
991  struct wpabuf * p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
992  					const u8 *data, size_t len,
993  					int rx_freq, bool p2p2);
994  int p2p_connect_send(struct p2p_data *p2p, struct p2p_device *dev);
995  u16 p2p_wps_method_pw_id(enum p2p_wps_method wps_method);
996  void p2p_reselect_channel(struct p2p_data *p2p,
997  			  struct p2p_channels *intersection);
998  void p2p_check_pref_chan(struct p2p_data *p2p, int go,
999  			 struct p2p_device *dev, struct p2p_message *msg);
1000  
1001  /* p2p_pd.c */
1002  void p2p_handle_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
1003  			      const u8 *data, size_t len, int rx_freq);
1004  void p2p_handle_prov_disc_resp(struct p2p_data *p2p, const u8 *sa,
1005  			       const u8 *data, size_t len, int rx_freq);
1006  int p2p_send_prov_disc_req(struct p2p_data *p2p, struct p2p_device *dev,
1007  			   int join, int force_freq);
1008  void p2p_reset_pending_pd(struct p2p_data *p2p);
1009  void p2ps_prov_free(struct p2p_data *p2p);
1010  void p2p_process_pcea(struct p2p_data *p2p, struct p2p_message *msg,
1011  		      struct p2p_device *dev);
1012  
1013  /* p2p_invitation.c */
1014  struct wpabuf * p2p_build_invitation_req(struct p2p_data *p2p,
1015  					 struct p2p_device *peer,
1016  					 const u8 *go_dev_addr, int dev_pw_id);
1017  void p2p_handle_invitation_req(struct p2p_data *p2p, const u8 *sa,
1018  			       const u8 *data, size_t len, int rx_freq);
1019  void p2p_handle_invitation_resp(struct p2p_data *p2p, const u8 *sa,
1020  				const u8 *data, size_t len);
1021  struct wpabuf * p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
1022  					   const u8 *data, size_t len,
1023  					   int rx_freq, bool p2p2);
1024  void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa,
1025  				 const u8 *data, size_t len);
1026  int p2p_invite_send(struct p2p_data *p2p, struct p2p_device *dev,
1027  		    const u8 *go_dev_addr, int dev_pw_id);
1028  void p2p_invitation_req_cb(struct p2p_data *p2p, int success);
1029  void p2p_invitation_resp_cb(struct p2p_data *p2p, const u8 *dst, int success);
1030  void p2p_start_invitation_connect(struct p2p_data *p2p, struct p2p_device *dev);
1031  
1032  /* p2p_dev_disc.c */
1033  void p2p_process_dev_disc_req(struct p2p_data *p2p, const u8 *sa,
1034  			      const u8 *data, size_t len, int rx_freq);
1035  void p2p_dev_disc_req_cb(struct p2p_data *p2p, int success);
1036  int p2p_send_dev_disc_req(struct p2p_data *p2p, struct p2p_device *dev);
1037  void p2p_dev_disc_resp_cb(struct p2p_data *p2p, int success);
1038  void p2p_process_dev_disc_resp(struct p2p_data *p2p, const u8 *sa,
1039  			       const u8 *data, size_t len);
1040  void p2p_go_disc_req_cb(struct p2p_data *p2p, int success);
1041  void p2p_process_go_disc_req(struct p2p_data *p2p, const u8 *da, const u8 *sa,
1042  			     const u8 *data, size_t len, int rx_freq);
1043  
1044  /* p2p.c */
1045  void p2p_set_state(struct p2p_data *p2p, int new_state);
1046  void p2p_set_timeout(struct p2p_data *p2p, unsigned int sec,
1047  		     unsigned int usec);
1048  void p2p_clear_timeout(struct p2p_data *p2p);
1049  void p2p_continue_find(struct p2p_data *p2p);
1050  struct p2p_device * p2p_add_dev_from_go_neg_req(struct p2p_data *p2p,
1051  						const u8 *addr,
1052  						struct p2p_message *msg);
1053  void p2p_update_peer_6ghz_capab(struct p2p_device *dev,
1054  				const struct p2p_message *msg);
1055  void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr,
1056  		      struct p2p_device *dev, struct p2p_message *msg);
1057  int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq,
1058  		   struct os_reltime *rx_time, int level, const u8 *ies,
1059  		   size_t ies_len, int scan_res);
1060  struct p2p_device * p2p_get_device(struct p2p_data *p2p, const u8 *addr);
1061  struct p2p_device * p2p_get_device_interface(struct p2p_data *p2p,
1062  					     const u8 *addr);
1063  void p2p_go_neg_failed(struct p2p_data *p2p, int status);
1064  void p2p_go_complete(struct p2p_data *p2p, struct p2p_device *peer);
1065  int p2p_match_dev_type(struct p2p_data *p2p, struct wpabuf *wps);
1066  int dev_type_list_match(const u8 *dev_type, const u8 *req_dev_type[],
1067  			size_t num_req_dev_type);
1068  struct wpabuf * p2p_build_probe_resp_ies(struct p2p_data *p2p,
1069  					 const u8 *query_hash,
1070  					 u8 query_count);
1071  int p2p_send_action(struct p2p_data *p2p, unsigned int freq, const u8 *dst,
1072  		    const u8 *src, const u8 *bssid, const u8 *buf,
1073  		    size_t len, unsigned int wait_time);
1074  void p2p_stop_listen_for_freq(struct p2p_data *p2p, int freq);
1075  int p2p_prepare_channel(struct p2p_data *p2p, struct p2p_device *dev,
1076  			unsigned int force_freq, unsigned int pref_freq,
1077  			int go);
1078  void p2p_go_neg_wait_timeout(void *eloop_ctx, void *timeout_ctx);
1079  int p2p_go_select_channel(struct p2p_data *p2p, struct p2p_device *dev,
1080  			  u8 *status);
1081  void p2p_pref_channel_filter(const struct p2p_channels *a,
1082  			     const struct weighted_pcl *freq_list,
1083  			     unsigned int num_channels,
1084  			     struct p2p_channels *res, bool go);
1085  
1086  void p2p_sd_query_cb(struct p2p_data *p2p, int success);
1087  void p2p_pasn_initialize(struct p2p_data *p2p, struct p2p_device *dev,
1088  			 const u8 *addr, int freq, bool verify,
1089  			 bool derive_kek);
1090  void p2p_buf_add_usd_service_hash(struct wpabuf *buf, struct p2p_data *p2p);
1091  
1092  void p2p_dbg(struct p2p_data *p2p, const char *fmt, ...)
1093  PRINTF_FORMAT(2, 3);
1094  void p2p_info(struct p2p_data *p2p, const char *fmt, ...)
1095  PRINTF_FORMAT(2, 3);
1096  void p2p_err(struct p2p_data *p2p, const char *fmt, ...)
1097  PRINTF_FORMAT(2, 3);
1098  
1099  #endif /* P2P_I_H */
1100