xref: /freebsd/contrib/wpa/src/nan/nan_i.h (revision 71e72c9e91c4b8007a4292e09669e8b549c29e97)
1 /*
2  * Wi-Fi Aware - Internal definitions for NAN module
3  * Copyright (C) 2025 Intel Corporation
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #ifndef NAN_I_H
10 #define NAN_I_H
11 
12 #include "list.h"
13 #include "common/ieee802_11_defs.h"
14 #include "common/nan_defs.h"
15 #include "common/wpa_common.h"
16 #include "nan.h"
17 
18 struct bitfield;
19 struct nan_config;
20 
21 #define NAN_INVALID_MAP_ID 0xff
22 
23 #define NAN_KCK_MAX_LEN 24
24 #define NAN_KEK_MAX_LEN 32
25 #define NAN_TK_MAX_LEN  32
26 #define NAN_NPK_LEN  32
27 
28 #define NAN_ELEMENT_MAX_SIZE 1024
29 
30 /**
31  * struct nan_ptk - NAN Pairwise Transient Key
32  * @kck: Key Confirmation Key
33  * @kek: Key Encryption Key
34  * @tk: Transient Key
35  * @kck_len: Length of &kck in octets
36  * @kek_len: Length of &kek in octets
37  * @tk_len: Length of &tk in octets
38  */
39 struct nan_ptk {
40 	u8 kck[NAN_KCK_MAX_LEN];
41 	u8 kek[NAN_KEK_MAX_LEN];
42 	u8 tk[NAN_TK_MAX_LEN];
43 
44 	size_t kck_len;
45 	size_t kek_len;
46 	size_t tk_len;
47 };
48 
49 /**
50  * struct nan_ndp_sec - NAN ndp security state
51  * @present: Whether NDP setup exchange includes security
52  * @valid: Whether the security configuration is valid
53  * @replaycnt_ok: Whether replay count ok
54  * @replaycnt: Current replay count
55  * @i_nonce: Initiator nonce
56  * @i_capab: Initiator capabilities
57  * @i_csid: Initiator cipher suite ID
58  * @i_instance_id: Initiator publish instance ID
59  * @i_pmkid: Initiator PMKID
60  * @r_nonce: Responder nonce
61  * @r_capab: Responder capabilities
62  * @r_csid: Responder cipher suite ID
63  * @r_instance_id: Responder instance ID
64  * @r_pmkid: Responder PMKID
65  * @auth_token: Authentication token
66  * @pmk: PMK used for the secure NDP establishment
67  * @ptk: Derived PTK
68  * @local_gtk: Group Temporal Key information of the local NDI
69  * @peer_gtk: Group Temporal Key information of the peer NDI
70  * @peer_gtk_rsc: Receive sequence counter of the peer NDI GTK
71  */
72 struct nan_ndp_sec {
73 	bool present;
74 	bool valid;
75 
76 	bool replaycnt_ok;
77 	u8 replaycnt[8];
78 
79 	/* Initiator data */
80 	u8 i_nonce[WPA_NONCE_LEN];
81 	u8 i_capab;
82 	u8 i_csid;
83 	u8 i_instance_id;
84 	u8 i_pmkid[PMKID_LEN];
85 
86 	/* Responder data */
87 	u8 r_nonce[WPA_NONCE_LEN];
88 	u8 r_capab;
89 	u8 r_csid;
90 	u8 r_instance_id;
91 	u8 r_pmkid[PMKID_LEN];
92 
93 	u8 auth_token[NAN_AUTH_TOKEN_LEN];
94 	u8 pmk[PMK_LEN];
95 
96 	struct nan_ptk ptk;
97 
98 	struct nan_gtk local_gtk;
99 	struct nan_gtk peer_gtk;
100 	u8 peer_gtk_rsc[WPA_KEY_RSC_LEN];
101 };
102 
103 /*
104  * enum nan_ndp_state - State of NDP establishment
105  * @NAN_NDP_STATE_NONE: No NDP establishment in progress
106  * @NAN_NDP_STATE_START: Starting NDP establishment
107  * @NAN_NDP_STATE_REQ_SENT: NDP request was sent
108  * @NAN_NDP_STATE_REQ_RECV: NDP response was received and processed
109  * @NAN_NDP_STATE_RES_SENT: NDP response was sent and NDP is not accepted yet
110  * @NAN_NDP_STATE_RES_RECV: NDP response was received and NDP was not accepted
111  *     yet (security is negotiated or confirmation is required)
112  * @NAN_NDP_STATE_CON_SENT: NDP confirm was sent and NDP was not done yet, as
113  *     security is negotiated
114  * @NAN_NDP_STATE_CON_RECV: NDP confirm received and NDP was not done yet, as
115  *     security is negotiated
116  * @NAN_NDP_STATE_DONE: NDP establishment is done (either success or reject).
117  *     In this state the NAN module handles actions such as notification to the
118  *     encapsulating logic, etc. Once processing is done the NDP should either
119  *     be cleared (rejected) or moved to the list of NDPs associated with the
120  *     peer.
121  */
122 enum nan_ndp_state {
123 	NAN_NDP_STATE_NONE,
124 	NAN_NDP_STATE_START,
125 	NAN_NDP_STATE_REQ_SENT,
126 	NAN_NDP_STATE_REQ_RECV,
127 	NAN_NDP_STATE_RES_SENT,
128 	NAN_NDP_STATE_RES_RECV,
129 	NAN_NDP_STATE_CON_SENT,
130 	NAN_NDP_STATE_CON_RECV,
131 	NAN_NDP_STATE_DONE,
132 };
133 
134 /*
135  * struct nan_ndp - NDP information
136  *
137  * Used to maintain the NDP as an object in a peer's list of NDPs.
138  *
139  * @list: Used for linking in the NDPs list
140  * @peer: Pointer to the peer data structure
141  * @initiator: True iff the local device is the initiator
142  * @ndp_id: NDP ID
143  * @init_ndi: Initiator NDI
144  * @resp_ndi: Responder NDI. Might not always be set (as this depends on the
145  *     state of NDP establishment and the status).
146  * @qos: QoS requirements for this NDP
147  * @gtk_id: GTK key ID used for this NDP; 0 if GTK is not used
148  */
149 struct nan_ndp {
150 	/* for nan_peer ndps list */
151 	struct dl_list list;
152 	struct nan_peer *peer;
153 	bool initiator;
154 	u8 ndp_id;
155 	u8 init_ndi[ETH_ALEN];
156 	u8 resp_ndi[ETH_ALEN];
157 
158 	struct nan_qos qos;
159 	u8 gtk_id;
160 };
161 
162 /*
163  * struct nan_ndp_setup - Holds the state of the NDP setup
164  * @ndp: NDP information
165  * @state: Current state
166  * @status: Current status
167  * @dialog_token: Setup dialog token
168  * @publisher_inst_id: Publish function instance ID
169  * @conf_req: True iff the NDP exchange requires confirm message
170  * @reason: Reject reason. Only valid when status is rejected.
171  * @ssi: Service specific information
172  * @ssi_len: Service specific information length
173  * @service_id: Service ID of the service used for NDP setup
174  * @sec: NDP security data
175  * @local_interface_id_valid: Indicates whether the &local_interface_id
176  *      field is valid.
177  * @local_interface_id: The local interface identifier to be used for the NDP
178  * @peer_interface_id_valid: Indicates whether the &peer_interface_id
179  *      field is valid.
180  * @peer_interface_id: The peer interface identifier to be used for the NDP
181  */
182 struct nan_ndp_setup {
183 	struct nan_ndp *ndp;
184 	enum nan_ndp_state state;
185 	enum nan_ndp_status status;
186 	u8 dialog_token;
187 	u8 publish_inst_id;
188 	bool conf_req;
189 	enum nan_reason reason;
190 	u8 *ssi;
191 	u16 ssi_len;
192 
193 	u8 service_id[NAN_SERVICE_ID_LEN];
194 	struct nan_ndp_sec sec;
195 
196 	bool local_interface_id_valid;
197 	u8 local_interface_id[NAN_NDPE_TLV_IPV6_LINK_LOCAL_LEN];
198 	bool peer_interface_id_valid;
199 	u8 peer_interface_id[NAN_NDPE_TLV_IPV6_LINK_LOCAL_LEN];
200 };
201 
202 /**
203  * struct nan_band_chan - NAN channel/band entry
204  *
205  * @band_id: Band ID as specified by enum nan_band_entry
206  * @chan: Channel entry as specified by &struct nan_chan_entry
207  */
208 struct nan_band_chan {
209 	union {
210 		u8 band_id;
211 		struct nan_chan_entry chan;
212 	} u;
213 };
214 
215 /**
216  * enum nan_band_chan_type - NAN band or channel
217  *
218  * @NAN_TYPE_BAND: The entry is a band entry
219  * @NAN_TYPE_CHANNEL: The entry is a channel entry
220  */
221 enum nan_band_chan_type {
222 	NAN_TYPE_BAND,
223 	NAN_TYPE_CHANNEL,
224 };
225 
226 /* Default availability entry parameter values */
227 #define NAN_AVAIL_ENTRY_DEF_UTIL NAN_AVAIL_ENTRY_CTRL_UTIL_UNKNOWN
228 #define NAN_AVAIL_ENTRY_DEF_NSS  2
229 #define NAN_AVAIL_ENTRY_DEF_PREF 3
230 
231 /**
232  * struct nan_avail_entry - NAN availability entry
233  *
234  * @list: Used for linking in the availability entries list
235  * @map_id: Map ID of the availability attribute that this entry belongs to
236  * @type: Availability type. One of NAN_AVAIL_ENTRY_CTRL_TYPE_*.
237  * @preference: Preference of being available in the NAN slots specified by
238  *	the associated time bitmap. The preference is higher when the value is
239  *	set larger. Valid values are 0 - 3.
240  * @utilization: Indicating proportion within the NAN slots specified by the
241  *	associated time bitmap that are already utilized for other purposes,
242  *	quantized to 20%. Valid values are 0 - 5.
243  * @rx_nss: Maximum number of special streams the NAN device can receive during
244  *	the NAN slots specified by the associated time bitmap
245  * @tbm: Time bitmap specifying the NAN slots in which the device will be
246  *	available for NAN operations
247  * @band_chan_type: Type of entries in &band_chan array, as specified by
248  *	enum nan_band_chan_type
249  * @n_band_chan: Number of entries in &band_chan array
250  * @band_chan: Array of bands/channels on which the NAN device will be
251  *	available
252  */
253 struct nan_avail_entry {
254 	struct dl_list list;
255 	u8 map_id;
256 	u8 type;
257 	u8 preference;
258 	u8 utilization;
259 	u8 rx_nss;
260 	struct nan_time_bitmap tbm;
261 	enum nan_band_chan_type band_chan_type;
262 	u8 n_band_chan;
263 	struct nan_band_chan *band_chan;
264 };
265 
266 /**
267  * struct nan_dev_capa_entry - NAN Device Capability entry
268  *
269  * @list: Used for linking in the device capabilities list
270  *	(in struct nan_peer_info::dev_capa)
271  * @map_id: Map ID of the device capabilities
272  * @capa: Device capabilities as specified by &struct nan_device_capabilities
273  */
274 struct nan_dev_capa_entry {
275 	struct dl_list list;
276 	u8 map_id;
277 	struct nan_device_capabilities capa;
278 };
279 
280 /**
281  * struct nan_elem_container_entry - NAN element container entry
282  *
283  * @list: Used for linking in the element container entries list
284  *	(in struct nan_peer_info::element_container)
285  * @map_id: Map ID of the element container
286  * @len: Length of data
287  * @data: Pointer to the data
288  */
289 struct nan_elem_container_entry {
290 	struct dl_list list;
291 	u8 map_id;
292 	u16 len;
293 	u8 data[];
294 };
295 
296 /**
297  * struct nan_ulw_entry - NAN Unaligned Schedule attribute entry
298  * @list: Used for linking in the ULW entries list in struct nan_peer_info::ulw
299  * @len: Length of the ULW attribute payload
300  * @data: Pointer to the ULW attribute payload
301  */
302 struct nan_ulw_entry {
303 	struct dl_list list;
304 	u16 len;
305 	u8 data[];
306 };
307 
308 /**
309  * struct nan_peer_sec_info_entry - NAN peer security information entry
310  *
311  * Maintains the latest security information for an NDI pair.
312  *
313  * @list: Used for linking in the peer security info list
314  *	(struct nan_peer_info::sec)
315  * @peer_ndi: Peer NDI address
316  * @local_ndi: Local NDI address
317  * @csid: Cipher Suite ID used for the secure NAN communication
318  * @pmk: PMK shared with the peer
319  * @pmkid: PMKID shared with the peer
320  * @ptk: PTK shared with the peer
321  * @pairing_akmp: AKMP used for the pairing (see See WPA_KEY_MGMT_*) or
322  * 	zero if PASN pairing was not used for NDP establishment
323  */
324 struct nan_peer_sec_info_entry {
325 	struct dl_list list;
326 
327 	u8 peer_ndi[ETH_ALEN];
328 	u8 local_ndi[ETH_ALEN];
329 
330 	enum nan_cipher_suite_id csid;
331 	u8 pmk[PMK_LEN];
332 	u8 pmkid[PMKID_LEN];
333 	struct nan_ptk ptk;
334 	int pairing_akmp;
335 };
336 
337 /**
338  * struct nan_peer_info - NAN peer information
339  *
340  * @last_seen: Timestamp of the last update of the peer info
341  * @seq_id: Sequence id of the last availability update
342  * @avail_entries: List of availability entries of the peer
343  * @ulw: List of Unaligned Schedule attribute payloads of the peer
344  *	(struct nan_ulw_entry::list entries)
345  * @dev_capa: List of device capabilities of the peer
346  *	(struct nan_dev_capa_entry::list entries)
347  * @element_container: List of element container entries of the peer
348  *	(struct nan_elem_container_entry::list entries)
349  * @sec: List of security information entries of the peer
350  *	(struct nan_peer_sec_info_entry::list entries)
351  */
352 struct nan_peer_info {
353 	struct os_reltime last_seen;
354 	u8 seq_id;
355 	struct dl_list avail_entries;
356 	struct dl_list ulw;
357 	struct dl_list dev_capa;
358 	struct dl_list element_container;
359 	struct dl_list sec;
360 };
361 
362 /**
363  * enum nan_ndl_state - State of NDL establishment
364  *
365  * @NAN_NDL_STATE_NONE: No NDL with the peer
366  * @NAN_NDL_STATE_START: NDL setup initiated by local device
367  * @NAN_NDL_STATE_REQ_SENT: Sent NDL request
368  * @NAN_NDL_STATE_REQ_RECV: Got NDL request
369  * @NAN_NDL_STATE_RES_SENT: Sent NDL response
370  * @NAN_NDL_STATE_RES_RECV: Got NDL response
371  * @NAN_NDL_STATE_CON_SENT: Sent NDL confirm
372  * @NAN_NDL_STATE_CON_RECV: Got NDL confirm
373  * @NAN_NDL_STATE_DONE: NDL establishment is done (either success or reject).
374  */
375 enum nan_ndl_state {
376 	NAN_NDL_STATE_NONE,
377 	NAN_NDL_STATE_START,
378 	NAN_NDL_STATE_REQ_SENT,
379 	NAN_NDL_STATE_REQ_RECV,
380 	NAN_NDL_STATE_RES_SENT,
381 	NAN_NDL_STATE_RES_RECV,
382 	NAN_NDL_STATE_CON_SENT,
383 	NAN_NDL_STATE_CON_RECV,
384 	NAN_NDL_STATE_DONE,
385 };
386 
387 /**
388  * enum nan_ndl_setup_reason - NAN NDL setup reason
389  * @NAN_NDL_SETUP_REASON_NONE: none
390  * @NAN_NDL_SETUP_REASON_NDP: NDL setup request for NDP operation
391  */
392 enum nan_ndl_setup_reason {
393 	NAN_NDL_SETUP_REASON_NONE,
394 	NAN_NDL_SETUP_REASON_NDP,
395 };
396 
397 /**
398  * struct nan_ndl - NAN NDL data
399  *
400  * @state: Current state
401  * @status: Current status
402  * @send_naf_on_error: When set, indicates that in case that the NDL processing
403  *     returned an error, a NAF still needs to be sent to the peer, i.e., the
404  *     error cannot be silently ignored.
405  * @reason: In case of status == NAN_NDL_STATUS_REJECTED, indicates the reason.
406  * @dialog_token: The dialog token for the current NDL negotiation.
407  * @max_idle_period: Indicate a period of time in units of 1024 TU during which
408  *     the peer device can refrain from transmitting over the NDL without
409  *     being terminated.
410  * @setup_reason: The reason for the NDL setup
411  * @ndc_id: NDC identifier
412  * @peer_qos: Peer QoS requirements
413  * @local_qos: Local QoS requirements (for the current NDP establishment)
414  * @ndc_sched: The NDC schedule entries. See &struct nan_sched_entry
415  * @ndc_sched_len: The length in octets of ndc_sched.
416  * @immut_sched: The immutable schedule entries. See &enum nan_sched_entry
417  * @immut_sched_len: The length in octets of immut_sched.
418  */
419 struct nan_ndl {
420 	enum nan_ndl_state state;
421 	enum nan_ndl_status status;
422 	u8 send_naf_on_error;
423 	enum nan_reason reason;
424 
425 	u8 dialog_token;
426 	u16 max_idle_period;
427 	enum nan_ndl_setup_reason setup_reason;
428 
429 	u8 ndc_id[ETH_ALEN];
430 
431 	struct nan_qos peer_qos, local_qos;
432 
433 	u8 *ndc_sched;
434 	u16 ndc_sched_len;
435 
436 	u8 *immut_sched;
437 	u16 immut_sched_len;
438 };
439 
440 /**
441  * struct nan_bootstrap - NAN bootstrap information
442  * @supported_methods: Bitmap of supported bootstrap methods. See
443  *     &enum nan_pairing_bootstrapping_method.
444  * @initiator: Whether this device is the initiator
445  * @requested_pbm: Bitmap of requested bootstrap methods. See
446  *     &enum nan_pairing_bootstrapping_method.
447  * @dialog_token: Dialog token of the bootstrap exchange
448  * @status: Status of the bootstrap exchange. See &enum nan_pba_status.
449  * @reason_code: Reason code for the bootstrap exchange. See &enum nan_reason.
450  * @comeback_required: Whether the peer requested a comeback
451  * @comeback_after: Time after which the comeback is requested
452  * @cookie: Pointer to the cookie received from the peer
453  * @cookie_len: Length of the cookie
454  * @authorized: Authorized bootstrap method. See &enum
455  *     nan_pairing_bootstrapping_method.
456  * @in_progress: Whether a bootstrap exchange is in progress
457  * @handle: Follow-up context handle for the ongoing bootstrap request
458  * @req_instance_id: Instance ID of the bootstrap request
459  * @npba: The NPBA from the last successful bootstrap
460  */
461 struct nan_bootstrap {
462 	u16 supported_methods;
463 	bool initiator;
464 	u16 requested_pbm;
465 	u8 dialog_token;
466 	u8 status;
467 	u8 reason_code;
468 
469 	bool comeback_required;
470 	u16 comeback_after;
471 	u8 *cookie;
472 	u8 cookie_len;
473 
474 	u16 authorized;
475 	bool in_progress;
476 
477 	int handle;
478 	u8 req_instance_id;
479 
480 	struct wpabuf *npba;
481 };
482 
483 /**
484  * enum nan_pasn_auth_mode - NAN pairing authentication modes
485  * @NAN_PASN_AUTH_MODE_PASN: Unauthenticated PASN
486  * @NAN_PASN_AUTH_MODE_SAE: PASN authentication with SAE tunneling
487  * @NAN_PASN_AUTH_MODE_PMK: PASN authentication with PMK caching
488  */
489 enum nan_pasn_auth_mode {
490 	NAN_PASN_AUTH_MODE_PASN = 0,
491 	NAN_PASN_AUTH_MODE_SAE = 1,
492 	NAN_PASN_AUTH_MODE_PMK = 2,
493 };
494 
495 /**
496  * enum nan_pairing_role - NAN pairing role types
497  * @NAN_PAIRING_ROLE_IDLE: No active pairing role
498  * @NAN_PAIRING_ROLE_INITIATOR: Device acting as pairing initiator
499  * @NAN_PAIRING_ROLE_RESPONDER: Device acting as pairing responder
500  */
501 enum nan_pairing_role {
502 	NAN_PAIRING_ROLE_IDLE,
503 	NAN_PAIRING_ROLE_INITIATOR,
504 	NAN_PAIRING_ROLE_RESPONDER,
505 };
506 
507 
508 /* Current pairing uses pairing verification */
509 #define NAN_PAIRING_FLAG_NPK_VERIFICATION BIT(0)
510 /* Peer is paired */
511 #define NAN_PAIRING_FLAG_PAIRED BIT(1)
512 
513 /**
514  * struct nan_pairing_peer_data - NAN pairing peer information
515  * @pairing_cfg: NAN pairing configuration parameters
516  * @self_pairing_role: Role of this device in the pairing process
517  * @pasn: Pointer to PASN data
518  * @handle: Handle of the local service instance
519  * @peer_instance_id: Instance ID of the peer service
520  * @nonce_tag_valid: Indicates if the nonce and tag fields are valid
521  * @nonce: Nonce from peer's NIRA
522  * @tag: Tag from peer's NIRA
523  * @flags: Bitmap of pairing flags. See NAN_PAIRING_FLAG_*
524  * @pending_auth1: Pending PASN Authentication frame 1 to be processed
525  * @pairing_csid: Cipher suite ID used for the pairing
526  * @pairing_akmp: AKMP used for the pairing. See WPA_KEY_MGMT_*.
527  */
528 struct nan_pairing_peer_data {
529 	struct nan_pairing_cfg pairing_cfg;
530 	enum nan_pairing_role self_pairing_role;
531 	struct pasn_data *pasn;
532 	int handle;
533 	int peer_instance_id;
534 	bool nonce_tag_valid;
535 	u8 nonce[NAN_NIRA_NONCE_LEN];
536 	u8 tag[NAN_NIRA_TAG_LEN];
537 	u32 flags;
538 	struct wpabuf *pending_auth1;
539 	enum nan_cipher_suite_id pairing_csid;
540 	int pairing_akmp;
541 };
542 
543 /**
544  * struct nan_peer - Represents a known NAN peer
545  * @list: List node for linking peers
546  * @nmi_addr: NMI of the peer
547  * @configured: Indicates if the peer has been configured to the device
548  * @last_seen: Timestamp of the last time this peer was seen
549  * @info: Information about the peer
550  * @ndps: List of NDPs associated with this peer
551  * @ndp_setup: Used to hold an NDP object while NDP establishment is in
552  *     progress
553  * @ndl: NDL data associated with this peer
554  * @bootstrap: Bootstrap information of the peer
555  * @pairing: Pairing data associated with this peer
556  * @igtk_id: IGTK key ID used with this peer. Zero if IGTK is not used.
557  * @bigtk_id: BIGTK key ID used with this peer. Zero if BIGTK is not used.
558  */
559 struct nan_peer {
560 	struct dl_list list;
561 	u8 nmi_addr[ETH_ALEN];
562 	bool configured;
563 	struct os_reltime last_seen;
564 	struct nan_peer_info info;
565 
566 	struct dl_list ndps;
567 
568 	struct nan_ndp_setup ndp_setup;
569 
570 	struct nan_ndl *ndl;
571 
572 	struct nan_bootstrap bootstrap;
573 
574 	struct nan_pairing_peer_data pairing;
575 
576 	u8 igtk_id;
577 	u8 bigtk_id;
578 };
579 
580 /**
581  * struct nan_data - Internal data structure for NAN
582  * @cfg: Pointer to the NAN configuration structure
583  * @nan_started: Flag indicating if NAN has been started
584  * @sched_update_pending: Local schedule update is pending driver confirmation
585  * @peer_list: List of known peers
586  * @ndp_id_counter: NDP identifier counter. Incremented for each NDP request,
587  *     and is used to set ndp_id in &struct nan_ndp.
588  * @next_dialog_token: Dialog token for NDP and NDL negotiations. Incremented
589  *     for each NDP and NDL request.
590  * @sched: The local schedule
591  * @cluster_id: Current cluster ID
592  * @nira_nonce: Nonce for NAN Identity Resolution attribute (NIRA)
593  * @nira_tag: Tag for NAN Identity Resolution attribute (NIRA)
594  * @initiator_pmksa: PMKSA cache for PASN-PMK authentication as an initiator
595  * @responder_pmksa: PMKSA cache for PASN-PMK authentication as a responder
596  * @igtk: IGTK for NAN secure NDP
597  * @igtk_id: Key ID of the IGTK
598  * @bigtk: BIGTK for NAN secure NDP
599  * @bigtk_id: Key ID of the BIGTK
600  */
601 struct nan_data {
602 	struct nan_config *cfg;
603 	u8 nan_started:1;
604 	u8 sched_update_pending:1;
605 	struct dl_list peer_list;
606 
607 	u8 ndp_id_counter;
608 	u8 next_dialog_token;
609 	struct nan_schedule sched;
610 
611 	u8 cluster_id[ETH_ALEN];
612 
613 	u8 nira_nonce[NAN_NIRA_NONCE_LEN];
614 	u8 nira_tag[NAN_NIRA_TAG_LEN];
615 
616 	struct rsn_pmksa_cache *initiator_pmksa;
617 	struct rsn_pmksa_cache *responder_pmksa;
618 
619 	struct wpa_igtk igtk;
620 	u8 igtk_id;
621 
622 	struct wpa_bigtk bigtk;
623 	u8 bigtk_id;
624 };
625 
626 struct nan_attrs_entry {
627 	struct dl_list list;
628 	const u8 *ptr;
629 	u16 len;
630 };
631 
632 struct nan_attrs {
633 	struct dl_list serv_desc_ext;
634 	struct dl_list avail;
635 	struct dl_list ndc;
636 	struct dl_list ulw;
637 	struct dl_list dev_capa;
638 	struct dl_list element_container;
639 
640 	const u8 *ndp;
641 	const u8 *ndl;
642 	const u8 *ndl_qos;
643 	const u8 *cipher_suite_info;
644 	const u8 *sec_ctxt_info;
645 	const u8 *shared_key_desc;
646 	const u8 *dev_capa_ext;
647 	const u8 *npba;
648 	const u8 *nira;
649 	const u8 *ndpe;
650 
651 	u16 ndp_len;
652 	u16 ndl_len;
653 	u16 ndl_qos_len;
654 	u16 cipher_suite_info_len;
655 	u16 sec_ctxt_info_len;
656 	u16 shared_key_desc_len;
657 	u16 dev_capa_ext_len;
658 	u16 npba_len;
659 	u16 nira_len;
660 	u16 ndpe_len;
661 };
662 
663 struct nan_msg {
664 	u8 oui_type;
665 	u8 oui_subtype;
666 	struct nan_attrs attrs;
667 
668 	/* The full frame is required for the NDP security flows, that compute
669 	 * the NDP authentication token over the entire frame body. */
670 	const struct ieee80211_mgmt *mgmt;
671 	size_t len;
672 };
673 
674 
675 /**
676  * nan_get_next_dialog_token - Allocate the next nonzero dialog token
677  *
678  * Wi-Fi Aware Specification v4.0, Tables 82, 86, 105: Dialog Token must be
679  * set to a nonzero value.
680  */
nan_get_next_dialog_token(struct nan_data * nan)681 static inline u8 nan_get_next_dialog_token(struct nan_data *nan)
682 {
683 	if (++nan->next_dialog_token == 0)
684 		nan->next_dialog_token++;
685 	return nan->next_dialog_token;
686 }
687 
688 
689 /**
690  * nan_get_next_ndp_id - Allocate next nonzero NDP identifier
691  *
692  * Wi-Fi Aware Specification v4.0, Table 82: NDP ID range is 1-255,
693  * value zero is reserved.
694  */
nan_get_next_ndp_id(struct nan_data * nan)695 static inline u8 nan_get_next_ndp_id(struct nan_data *nan)
696 {
697 	if (++nan->ndp_id_counter == 0)
698 		nan->ndp_id_counter++;
699 	return nan->ndp_id_counter;
700 }
701 
702 
703 struct nan_peer * nan_get_peer(struct nan_data *nan, const u8 *addr);
704 bool nan_is_naf(const struct ieee80211_mgmt *mgmt, size_t len);
705 int nan_parse_attrs(struct nan_data *nan, const u8 *data, size_t len,
706 		    struct nan_attrs *attrs);
707 int nan_parse_naf(struct nan_data *nan, const struct ieee80211_mgmt *mgmt,
708 		  size_t len, struct nan_msg *msg);
709 void nan_attrs_clear(struct nan_data *nan, struct nan_attrs *attrs);
710 
711 int nan_ndp_setup_req(struct nan_data *nan, struct nan_peer *peer,
712 		      struct nan_ndp_params *params);
713 int nan_ndp_setup_resp(struct nan_data *nan, struct nan_peer *peer,
714 		       struct nan_ndp_params *params);
715 int nan_ndp_handle_ndp_attr(struct nan_data *nan, struct nan_peer *peer,
716 			    struct nan_msg *msg);
717 int nan_ndp_add_ndp_attr(struct nan_data *nan, struct nan_peer *peer,
718 			 struct wpabuf *buf);
719 void nan_ndp_setup_reset(struct nan_data *nan, struct nan_peer *peer);
720 void nan_ndp_setup_failure(struct nan_data *nan, struct nan_peer *peer,
721 			   enum nan_reason reason, bool reset_state);
722 int nan_ndp_naf_sent(struct nan_data *nan, struct nan_peer *peer,
723 		     enum nan_subtype subtype);
724 int nan_parse_device_attrs(struct nan_data *nan, struct nan_peer *peer,
725 			   const u8 *attrs_data, size_t attrs_len);
726 int nan_ndp_term_req(struct nan_data *nan, struct nan_peer *peer,
727 		     struct nan_ndp_id *ndp_id);
728 int nan_ndl_setup(struct nan_data *nan, struct nan_peer *peer,
729 		  const struct nan_ndp_params *params, u8 dialog_token);
730 void nan_ndl_setup_failure(struct nan_data *nan, struct nan_peer *peer,
731 			   enum nan_reason reason, bool reset_state);
732 void nan_ndl_reset(struct nan_data *nan, struct nan_peer *peer);
733 int nan_ndl_handle_ndl_attr(struct nan_data *nan, struct nan_peer *peer,
734 			    struct nan_msg *msg);
735 int nan_ndl_add_ndl_attr(struct nan_data *nan, const struct nan_peer *peer,
736 			 struct wpabuf *buf);
737 int nan_ndl_add_ndc_attr(struct nan_data *nan, const struct nan_peer *peer,
738 			 struct wpabuf *buf);
739 int nan_ndl_add_qos_attr(struct nan_data *nan, const struct nan_peer *peer,
740 			 struct wpabuf *buf);
741 int nan_chan_to_chan_idx_map(struct nan_data *nan,
742 			     u8 op_class, u8 channel, u16 *chan_idx_map);
743 int nan_ndl_naf_sent(struct nan_data *nan, struct nan_peer *peer,
744 		     enum nan_subtype subtype);
745 int nan_ndl_add_avail_attrs(struct nan_data *nan, const struct nan_peer *peer,
746 			    struct wpabuf *buf);
747 void nan_ndl_add_elem_container_attr(const struct nan_data *nan,
748 				     const struct nan_peer *peer,
749 				     struct wpabuf *buf);
750 struct bitfield * nan_peer_schedule_intersection(
751 	struct nan_data *nan, const struct nan_peer *peer,
752 	const struct nan_schedule *sched);
753 bool nan_ndl_meets_qos(struct nan_data *nan, const struct nan_peer *peer,
754 		       const struct bitfield *common_bf);
755 bool nan_ndl_validate_peer_avail(struct nan_data *nan, struct nan_peer *peer);
756 int nan_convert_chan_sched_to_bf(struct nan_data *nan,
757 				 const struct nan_chan_schedule *chan,
758 				 struct bitfield **avail_bf, u8 *map_id,
759 				 u8 *op_class, u16 *cbm, u16 *pcbm);
760 int nan_get_chan_bm(struct nan_data *nan, const struct nan_sched_chan *chan,
761 		    u8 *op_class, u16 *chan_bm, u16 *pri_chan_bm);
762 int nan_add_avail_attrs(struct nan_data *nan, u8 sequence_id,
763 			u32 map_ids_bitmap, u8 type_for_conditional,
764 			size_t n_chans, struct nan_chan_schedule *chans,
765 			struct wpabuf *buf, bool include_potential);
766 void nan_del_avail_entry(struct nan_avail_entry *entry);
767 void nan_flush_avail_entries(struct dl_list *avail_entries);
768 int nan_sched_entries_to_avail_entries(struct nan_data *nan,
769 				       struct dl_list *avail_entries,
770 				       const u8 *sched_entries,
771 				       u16 sched_entries_len);
772 struct bitfield * nan_tbm_to_bf(struct nan_data *nan,
773 				const struct nan_time_bitmap *tbm);
774 struct bitfield * nan_sched_to_bf(struct nan_data *nan, struct dl_list *sched,
775 				  u8 *map_id, enum nan_reason *reason);
776 bool nan_sched_covered_by_avail_entry(struct nan_data *nan,
777 				      struct nan_avail_entry *avail,
778 				      struct bitfield *sched_bf, u8 map_id);
779 bool nan_sched_covered_by_avail_entries(struct nan_data *nan,
780 					struct dl_list *avail_entries,
781 					const u8 *sched, size_t sched_len);
782 bool nan_sched_bf_covered_by_avail_entries_and_chan(
783 	struct nan_data *nan, const struct dl_list *avail_entries,
784 	struct bitfield *sched_bf, u8 map_id, u8 op_class, u16 cbm);
785 struct bitfield * nan_avail_entries_to_bf(struct nan_data *nan,
786 					  const struct dl_list *avail_entries,
787 					  u8 op_class, u16 cbm, u16 pri_cbm);
788 void nan_ndp_terminated(struct nan_data *nan, struct nan_peer *peer,
789 			struct nan_ndp_id *ndp_id, const u8 *local_ndi,
790 			const u8 *peer_ndi, enum nan_reason reason, u8 gtk_id);
791 int nan_crypto_pmk_to_ptk(const u8 *pmk, const u8 *iaddr, const u8 *raddr,
792 			  const u8 *inonce, const u8 *rnonce,
793 			  struct nan_ptk *ptk,
794 			  enum nan_cipher_suite_id cipher);
795 int nan_crypto_calc_pmkid(const u8 *pmk, const u8 *iaddr, const u8 *raddr,
796 			  const u8 *serv_id,
797 			  enum nan_cipher_suite_id cipher, u8 *pmkid);
798 int nan_crypto_calc_auth_token(enum nan_cipher_suite_id cipher,
799 			       const u8 *buf, size_t len, u8 *token);
800 int nan_crypto_key_mic(const u8 *buf, size_t len, const u8 *kck,
801 		       size_t kck_len, u8 cipher, u8 *mic);
802 int nan_crypto_derive_npk(const u8 *kdk, size_t kdk_len,
803 			  enum nan_cipher_suite_id cipher,
804 			  const u8 *initiator_nmi, const u8 *responder_nmi,
805 			  u8 *buf, size_t buf_len);
806 int nan_crypto_derive_kek(const u8 *kdk, size_t kdk_len,
807 			  enum nan_cipher_suite_id cipher,
808 			  const u8 *initiator_nmi, const u8 *responder_nmi,
809 			  struct wpa_ptk *ptk);
810 int nan_crypto_derive_nd_pmk_from_kdk(const u8 *kdk, size_t kdk_len,
811 				      enum nan_cipher_suite_id cipher,
812 				      const u8 *initiator_nmi,
813 				      const u8 *responder_nmi, u8 *nd_pmk);
814 struct wpabuf * nan_crypto_encrypt_key_data(const struct wpabuf *key_data,
815 					    const u8 *kek, size_t kek_len);
816 struct wpabuf * nan_crypto_decrypt_key_data(const u8 *kek, size_t kek_len,
817 					    const u8 *encrypted_data,
818 					    size_t encrypted_len);
819 void nan_sec_reset(struct nan_data *nan, struct nan_ndp_sec *ndp_sec);
820 int nan_sec_rx(struct nan_data *nan, struct nan_peer *peer,
821 	       struct nan_msg *msg);
822 int nan_add_csia(struct wpabuf *buf, u8 capab, size_t cs_list_len,
823 		 const struct nan_cipher_suite *cs_list);
824 int nan_sec_add_attrs(struct nan_data *nan, struct nan_peer *peer,
825 		      enum nan_subtype subtype, struct wpabuf *buf);
826 int nan_sec_init_resp(struct nan_data *nan, struct nan_peer *peer);
827 int nan_sec_pre_tx(struct nan_data *nan, struct nan_peer *peer,
828 		   struct wpabuf *buf);
829 bool nan_sec_ndp_store_keys(struct nan_data *nan, struct nan_peer *peer,
830 			    const u8 *peer_ndi, const u8 *local_ndi);
831 int nan_sec_get_tk(struct nan_data *nan, struct nan_peer *peer,
832 		   const u8 *peer_ndi, const u8 *local_ndi,
833 		   u8 *tk, size_t *tk_len, enum nan_cipher_suite_id *csid);
834 void nan_add_dev_capa_ext_attr(struct nan_data *nan, struct wpabuf *buf);
835 
836 void nan_bootstrap_reset(struct nan_data *nan, struct nan_peer *peer);
837 bool nan_bootstrap_handle_rx(struct nan_data *nan, const u8 *peer_nmi,
838 			     const u8 *npba, u16 npba_len,
839 			     const u8 *buf, size_t len,
840 			     int handle, u8 req_instance_id);
841 int nan_add_nira(struct wpabuf *buf, const u8 *tag, const u8 *nonce);
842 void nan_parse_peer_dev_capa_ext(struct nan_data *nan, struct nan_peer *peer,
843 				 struct nan_attrs *attrs);
844 int nan_configure_peer_schedule(struct nan_data *nan, struct nan_peer *peer,
845 				const struct nan_schedule *local_sched);
846 bool nan_is_ndpe_supported(struct nan_data *nan, const struct nan_peer *peer);
847 void nan_add_kde_hdr(struct wpabuf *buf, u32 kde, size_t data_len);
848 int nan_clear_peer_schedule(struct nan_data *nan, struct nan_peer *peer);
849 #ifdef CONFIG_PASN
850 int nan_nira_get_tag_nonce(const struct nan_config *nan, u8 *nonce, u8 *tag);
851 void nan_pairing_deinit_peer(struct nan_peer *peer);
852 bool nan_pairing_followup_rx(struct nan_data *nan_data, const u8 *peer_addr,
853 			     const struct nan_shared_key *shared_key_descr,
854 			     size_t attr_len);
855 #else /* CONFIG_PASN */
856 static inline
nan_nira_get_tag_nonce(const struct nan_config * nan,u8 * nonce,u8 * tag)857 int nan_nira_get_tag_nonce(const struct nan_config *nan, u8 *nonce, u8 *tag)
858 {
859 	return -1;
860 }
861 
nan_pairing_deinit_peer(struct nan_peer * peer)862 static inline void nan_pairing_deinit_peer(struct nan_peer *peer)
863 {
864 }
865 #endif /* CONFIG_PASN */
866 
867 #endif /* NAN_I_H */
868