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