1 /*
2 * Wi-Fi Aware - 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_H
10 #define NAN_H
11
12 #include "common/nan_defs.h"
13 #include "common/wpa_common.h"
14 #include "utils/list.h"
15
16 struct nan_cluster_config;
17 enum nan_reason;
18 struct ieee80211_mgmt;
19
20 struct nan_de_pmkid {
21 struct dl_list list;
22 u8 pmkid[PMKID_LEN];
23 };
24
25 /*
26 * struct nan_device_capabilities - NAN device capabilities
27 * @cdw_info: Committed DW information
28 * @supported_bands: Supported bands
29 * @op_mode: Operation mode
30 * @n_antennas: Number of antennas
31 * @channel_switch_time: Maximal channel switch time
32 * @capa: Device capabilities
33 */
34 struct nan_device_capabilities {
35 u16 cdw_info;
36 u8 supported_bands;
37 u8 op_mode;
38 u8 n_antennas;
39 u16 channel_switch_time;
40 u8 capa;
41 };
42
43 /**
44 * struct nan_qos - NAN QoS requirements
45 * @min_slots: Minimal number of slots
46 * @max_latency: Maximum allowed NAN slots between every two non-contiguous
47 * NAN Data Link (NDL) Common Resource Blocks (CRB)
48 */
49 struct nan_qos {
50 u8 min_slots;
51 u16 max_latency;
52 };
53
54 /**
55 * enum nan_ndp_action - NDP action
56 * @NAN_NDP_ACTION_REQ: Request NDP establishment
57 * @NAN_NDP_ACTION_RESP: Response to NDP establishment request
58 * @NAN_NDP_ACTION_CONF: Confirm NDP establishment
59 * @NAN_NDP_ACTION_TERM: Request NDP termination
60 */
61 enum nan_ndp_action {
62 NAN_NDP_ACTION_REQ,
63 NAN_NDP_ACTION_RESP,
64 NAN_NDP_ACTION_CONF,
65 NAN_NDP_ACTION_TERM,
66 };
67
68 /**
69 * struct nan_ndp_id - Unique identifier of an NDP
70 *
71 * @peer_nmi: Peer NAN Management Interface (NMI)
72 * @init_ndi: Initiator NAN Data Interface (NDI)
73 * @id: NDP identifier
74 */
75 struct nan_ndp_id {
76 u8 peer_nmi[ETH_ALEN];
77 u8 init_ndi[ETH_ALEN];
78 u8 id;
79 };
80
81 /*
82 * The maximal period of a NAN schedule is 8192 TUs. With time slots of 16 TUs,
83 * need 64 octets to represent a complete schedule bitmap.
84 */
85 #define NAN_MAX_PERIOD_TUS 8192
86 #define NAN_MAX_TIME_BITMAP_SLOTS (NAN_MAX_PERIOD_TUS / 16)
87 #define NAN_TIME_BITMAP_MAX_LEN (NAN_MAX_TIME_BITMAP_SLOTS / 8)
88
89 /**
90 * struct nan_time_bitmap - NAN time bitmap
91 *
92 * @duration: Slot duration represented by each bit in the bitmap. Valid values
93 * are as defined in nan_defs.h and Wi-Fi Aware spec v4.0, Table 97 (Time
94 * Bitmap Control field format for the NAN Availability attribute).
95 * @period: Indicates the repeat interval of the bitmap.
96 * When set to zero, the bitmap is not repeated. Valid values are
97 * as defined in nan_defs.h and Wi-Fi Aware spec v4.0, Table 97 (Time
98 * Bitmap Control field format for the NAN Availability attribute).
99 * @offset: The time period specified by the %bitmap field starts at
100 * 16 * offset TUs after DW0.
101 * @len: Length of the %bitmap field, in bytes. If this is zero, the NAN device
102 * is available for 512 NAN slots beginning after the immediate previous
103 * DW0.
104 * @bitmap: Each bit in the time bitmap corresponds to a time duration indicated
105 * by the value of the %duration field. When a bit is set to 1, the NAN
106 * device is available (or conditionally or potentially available)
107 * for any NAN operations for the time associated with the bit.
108 */
109 struct nan_time_bitmap {
110 u8 duration;
111 u16 period;
112 u16 offset;
113 u8 len;
114 u8 bitmap[NAN_TIME_BITMAP_MAX_LEN];
115 };
116
117 /**
118 * struct nan_sched_chan - NAN scheduled channel
119 *
120 * @freq: Primary channel center frequency of the 20 MHz
121 * @center_freq1: Center frequency of the first segment
122 * @center_freq2: Center frequency of the second segment, if any
123 * @bandwidth: The channel bandwidth in MHz
124 */
125 struct nan_sched_chan {
126 int freq;
127 int center_freq1;
128 int center_freq2;
129 int bandwidth;
130 };
131
132 /**
133 * struct nan_chan_schedule - NAN channel schedule
134 *
135 * @chan: The channel associated with the schedule
136 * @committed: Committed schedule time bitmap
137 * @conditonal: Conditional schedule time bitmap
138 * @map_id: The map_id of the availability attribute where this schedule is
139 * represented
140 */
141 struct nan_chan_schedule {
142 struct nan_sched_chan chan;
143 struct nan_time_bitmap committed;
144 struct nan_time_bitmap conditional;
145 u8 map_id;
146 };
147
148 /**
149 * struct nan_sched_qos - QoS requirements in units of 16 TUs per 512 TUs
150 *
151 * @required_slots: Number of required slots
152 * @min_slots: Minimum number of CRB slots needed for this NDL. If this amount
153 * of CRB slots can't be scheduled the NDL should fail.
154 * @max_gap: Maximum allowed latency (in slots) of the CRB schedule
155 */
156 struct nan_sched_qos {
157 u8 required_slots;
158 u8 min_slots;
159 u8 max_gap;
160 };
161
162 #define NAN_SCHEDULE_MAX_CHANNELS 6
163
164 /**
165 * struct nan_schedule - NAN schedule
166 *
167 * @map_ids_bitmap: Bitmap of map IDs included in this schedule. Not all map IDs
168 * are covered by &chans. For map IDs that are not covered, when building
169 * NAFs, NAN availability attributes would be added with potential
170 * availability entries.
171 * @n_chans: Number of channels for this schedule.
172 * @chans: The channels included in the schedule. The channels must be sorted
173 * such that the map IDs (in struct nan_chan_schedule) are in ascending
174 * order.
175 * @ndc: NDC bitmap schedule
176 * @ndc_map_id: The NDC map ID
177 * @sequence_id: Schedule sequence ID
178 * @elems: Additional elements to be set in an element container attribute
179 */
180 struct nan_schedule {
181 u32 map_ids_bitmap;
182 u8 n_chans;
183 struct nan_chan_schedule chans[NAN_SCHEDULE_MAX_CHANNELS];
184 struct nan_time_bitmap ndc;
185 u8 ndc_map_id;
186 u8 sequence_id;
187 struct wpabuf *elems;
188 };
189
190 /**
191 * struct nan_gtk - NAN GTK information
192
193 * @gtk: Group Temporal Key (GTK)
194 * @id: GTK key ID
195 * @csid: GTK Cipher suite ID. See &enum nan_cipher_suite_id
196 */
197 struct nan_gtk {
198 struct wpa_gtk gtk;
199 u8 id;
200 u8 csid;
201 };
202
203 /**
204 * struct nan_ndp_sec_params - NAN NDP security parameters
205 * @csid: Cipher suite ID
206 * @pmk: NAN Pairwise Master Key (PMK)
207 * @gtk: Group Temporal Key (GTK) information
208 */
209 struct nan_ndp_sec_params {
210 enum nan_cipher_suite_id csid;
211 u8 pmk[PMK_LEN];
212 struct nan_gtk gtk;
213 };
214
215 /**
216 * struct nan_ndp_params - Holds the NDP parameters for setting up or
217 * terminating an NDP.
218 *
219 * @type: The request type. See &enum nan_ndp_action
220 * @ndp_id: The NDP identifier
221 * @qos: The NDP QoS parameters. In case there is no requirement for
222 * max_latency, max_latency should be set to NAN_QOS_MAX_LATENCY_NO_PREF.
223 * Should be set only with NAN_NDP_ACTION_REQ and NAN_NDP_ACTION_RESP.
224 * Ignored for other types.
225 * @sec: NDP security parameters. Should be set only with NAN_NDP_ACTION_REQ
226 * and NAN_NDP_ACTION_RESP. Ignored for other types.
227 * @ssi: Service specific information. Should be set only with
228 * NAN_NDP_ACTION_REQ and NAN_NDP_ACTION_RESP. Ignored for other types.
229 * @ssi_len: Service specific information length
230 * @publish_inst_id: Identifier for the instance of the Publisher function
231 * associated with the data path setup request.
232 * @service_id: Service identifier of the service associated with the data path
233 * setup request.
234 * @resp_ndi: In case of successful response, the responder's NDI. In case of
235 * response to a counter proposal, the initiator's NDI (the one used with
236 * NAN_NDP_ACTION_REQ).
237 * @status: Response status
238 * @reason_code: In case of rejected response, the rejection reason.
239 * @sched_valid: Indicates whether the schedule field is valid
240 * @sched: The NAN schedule associated with the NDP parameters
241 * @interface_id: The interface identifier to be used for the NDP. The interface
242 * identifier is used to derive the IPv6 link-local address as specified in
243 * Wi-Fi Aware specification v4.0, Table 90 (IPv6 Link Local TLV format).
244 */
245 struct nan_ndp_params {
246 enum nan_ndp_action type;
247
248 struct nan_ndp_id ndp_id;
249 struct nan_qos qos;
250 struct nan_ndp_sec_params sec;
251 const u8 *ssi;
252 u16 ssi_len;
253
254 union {
255 struct nan_ndp_setup_req {
256 u8 publish_inst_id;
257 u8 service_id[NAN_SERVICE_ID_LEN];
258 } req;
259
260 /*
261 * Used with both NAN_NDP_ACTION_RESP (as a response to an NDP
262 * request) and NAN_NDP_ACTION_CONF (as a response to an NDP
263 * response with a counter).
264 */
265 struct nan_ndp_setup_resp {
266 u8 resp_ndi[ETH_ALEN];
267 u8 status;
268 u8 reason_code;
269 } resp;
270 } u;
271
272 bool sched_valid;
273 struct nan_schedule sched;
274 const u8 *interface_id;
275 };
276
277 /**
278 * struct nan_channel_info - Channel information for NAN channel selection
279 * @op_class: Operating class
280 * @channel: Control channel index
281 * @pref: Channel Preference (higher is preferred). Valid values are 0-3.
282 */
283 struct nan_channel_info {
284 u8 op_class;
285 u8 channel;
286 u8 pref;
287 };
288
289 /**
290 * struct nan_channels - Array of channel information entries
291 *
292 * @n_chans: Number of channel information entries
293 * @chans: Array of channel information. Sorted by preference.
294 */
295 struct nan_channels {
296 unsigned int n_chans;
297 struct nan_channel_info *chans;
298 };
299
300 /**
301 * struct nan_ndp_connection_params - Parameters for NDP connection
302 * @ndp_id: NDP identifier
303 * @peer_ndi: Peer NDI MAC address
304 * @local_ndi: Local NDI MAC address
305 * @ssi: Service specific information
306 * @ssi_len: Service specific information length
307 * @install_keys: Whether the new keys should be installed
308 * @first_ndp: Whether this is the first NDP with the peer
309 * @new_ndi_sta: Whether a new NDI station needs to be added (peer_ndi not
310 * already used by another NDP with this peer)
311 * @interface_id: The interface identifier to be used by the peer for the NDP
312 * @local_gtk: Pointer to local GTK info. NULL if local GTK is
313 * not to be installed
314 * @peer_gtk: Pointer to peer GTK info. NULL if peer GTK is
315 * not to be installed
316 * @peer_gtk_rsc: Pointer to the peer GTK receive sequence counter
317 */
318 struct nan_ndp_connection_params {
319 struct nan_ndp_id ndp_id;
320 const u8 *peer_ndi;
321 const u8 *local_ndi;
322 const u8 *ssi;
323 size_t ssi_len;
324 bool install_keys;
325 bool first_ndp;
326 bool new_ndi_sta;
327 const u8 *interface_id;
328
329 const struct nan_gtk *local_gtk;
330 const struct nan_gtk *peer_gtk;
331 const u8 *peer_gtk_rsc;
332 };
333
334 /**
335 * struct nan_ndp_action_notif_params - Parameters for NDP action notification
336 * @ndp_id: NDP identifier
337 * @is_request: Whether the data is associated with an NDP request frame (true)
338 * or with an NDP response (false).
339 * @ndp_status: NDP status
340 * @ndl_status: NDL status
341 * @publish_inst_id: Identifier for the publish instance function
342 * @ssi: Service specific information
343 * @ssi_len: Service specific information length
344 * @csid: NAN cipher suite identifier
345 * @pmkid: NAN PMK identifier; can be NULL if security is not negotiated
346 */
347 struct nan_ndp_action_notif_params {
348 struct nan_ndp_id ndp_id;
349 bool is_request;
350
351 enum nan_ndp_status ndp_status;
352 enum nan_ndl_status ndl_status;
353
354 u8 publish_inst_id;
355 const u8 *ssi;
356 size_t ssi_len;
357 enum nan_cipher_suite_id csid;
358 const u8 *pmkid;
359 };
360
361 #define NAN_MAX_MAPS 8
362 #define NAN_MAX_CHAN_ENTRIES 16
363
364 /**
365 * struct nan_peer_schedule - NAN peer schedule information
366 * @n_maps: Number of maps
367 * @maps: Array of maps
368 * @map_id: Map ID
369 * @n_chans: Number of channels in the map
370 * @chans: Array of channels in the map
371 * @committed: Committed schedule bitmap for the channel
372 * @rx_nss: Number of spatial streams supported by the peer for RX on this
373 * channel
374 * @chan: Channel information
375 * @tbm: Time bitmap for the channel
376 * @ndc: NDC time bitmap for the map
377 * @immutable: Immutable time bitmap for the map
378 * @max_idle_period: Maximal NDL idle period in seconds that the peer indicated
379 */
380 struct nan_peer_schedule {
381 u8 n_maps;
382 struct nan_map {
383 u8 map_id;
384 u8 n_chans;
385 struct nan_map_chan{
386 bool committed;
387 u8 rx_nss;
388 struct nan_sched_chan chan;
389 struct nan_time_bitmap tbm;
390 } chans[NAN_MAX_CHAN_ENTRIES];
391
392 struct nan_time_bitmap ndc;
393 struct nan_time_bitmap immutable;
394 } maps[NAN_MAX_MAPS];
395
396 u16 max_idle_period;
397 };
398
399 /**
400 * struct nan_peer_potential_avail - NAN peer potential availability
401 * @n_maps: Number of maps
402 * @maps: Array of maps
403 * @is_band: Indicates whether the entries are bands (true) or channels (false)
404 * @preference: Preference value for the availability entry
405 * @utilization: Utilization value for the availability entry
406 * @rx_nss: Number of spatial streams supported by the peer for RX during
407 * the time indicated by the availability entry
408 * @n_band_chan: Number of band/channel entries
409 * @entries: Array of band/channel entries
410 */
411 struct nan_peer_potential_avail {
412 unsigned int n_maps;
413 struct pot_entry {
414 bool is_band;
415 u8 preference;
416 u8 utilization;
417 u8 rx_nss;
418
419 u8 n_band_chan;
420 union pot_band_chan{
421 u8 band_id;
422 struct {
423 u8 op_class;
424 u16 chan_bitmap;
425 };
426 } entries[NAN_MAX_CHAN_ENTRIES];
427 } maps[NAN_MAX_MAPS];
428 };
429
430 #define NAN_PAIRING_PASN_128 BIT(0)
431 #define NAN_PAIRING_PASN_256 BIT(1)
432
433 /**
434 * struct nan_pairing_cfg - NAN pairing configuration parameters
435 * @pairing_setup: Whether pairing setup is enabled
436 * @npk_caching: Whether NPK caching is enabled
437 * @pairing_verification: Whether pairing verification is enabled
438 * @cipher_suites: Bitmap of supported cipher suites (NAN_PAIRING_PASN_*)
439 */
440 struct nan_pairing_cfg {
441 bool pairing_setup;
442 bool npk_caching;
443 bool pairing_verification;
444 u32 cipher_suites;
445 };
446
447 struct nan_config {
448 void *cb_ctx;
449 u8 nmi_addr[ETH_ALEN];
450
451 struct nan_device_capabilities dev_capa;
452
453 /* Wi-Fi Aware spec v4.0, Table 141 (Capability Info field) */
454 u8 dev_capa_ext_reg_info; /* NAN_DEV_CAPA_EXT_INFO_0_* */
455
456 struct nan_pairing_cfg pairing_cfg;
457 u8 nik[NAN_NIK_LEN];
458
459 /* in seconds */
460 u32 nik_lifetime;
461
462 /*
463 * The local maximal NDL idle period in seconds. This value should be
464 * set in the NDL attribute included in NAFs to indicate to the peers
465 * that the NDL (and all corresponding NDPs) may be terminated if there
466 * is no data traffic with the peer for max_ndl_idle_period seconds.
467 */
468 u16 max_ndl_idle_period;
469
470 /*
471 * Supported Pairing Bootstrapping Methods (PBM).
472 * See Wi-Fi Aware spec v4.0, Table 128 (NPBA format).
473 */
474 u16 supported_bootstrap_methods;
475
476 /* Auto-accepted bootstrapping methods.
477 * See Wi-Fi Aware spec v4.0, Table 128 (NPBA format). */
478 u16 auto_accept_bootstrap_methods;
479
480 /*
481 * Bootstrap comeback timeout in TUs. This value is used to indicate to
482 * the peer NAN device requesting bootstrapping to be performed, when
483 * to send the bootstrapping request again.
484 */
485 u16 bootstrap_comeback_timeout;
486
487 /* Security capabilities. See Wi-Fi Aware spec v4.0, Table 122 (Cipher
488 * Suite Information attribute (CSIA) field format), Capabilities field.
489 */
490 u8 security_capab;
491
492 /**
493 * start - Start NAN
494 * @ctx: Callback context from cb_ctx
495 * @config: NAN cluster configuration
496 */
497 int (*start)(void *ctx, const struct nan_cluster_config *config);
498
499 /**
500 * stop - Stop NAN
501 * @ctx: Callback context from cb_ctx
502 */
503 void (*stop)(void *ctx);
504
505 /**
506 * update_config - Update NAN configuration
507 * @ctx: Callback context from cb_ctx
508 * @config: NAN cluster configuration
509 */
510 int (*update_config)(void *ctx,
511 const struct nan_cluster_config *config);
512
513 /**
514 * ndp_action_notif - Notify NDP action is required
515 * @ctx: Callback context from cb_ctx
516 * @params: NDP action notification parameters
517 *
518 * A notification sent when an NDP establishment frame is received, and
519 * upper layer input is required to continue the flow.
520 */
521 void (*ndp_action_notif)(void *ctx,
522 struct nan_ndp_action_notif_params *params);
523
524 /**
525 * ndp_connected - Notify that NDP was successfully connected
526 * @ctx: Callback context from cb_ctx
527 * @params: NDP connection parameters
528 * Returns: 0 on success, negative on failure. Note that new NDPs
529 * may trigger security upgrade for the peer NDI station. If this fails,
530 * -2 is returned and the caller should clean up all the existing NDPs
531 * with this peer NDI.
532 */
533 int (*ndp_connected)(void *ctx,
534 struct nan_ndp_connection_params *params);
535
536 /**
537 * ndp_disconnected - Notify that NDP was disconnected
538 * @ctx: Callback context from cb_ctx
539 * @ndp_id: NDP identifier
540 * @local_ndi: Local NDI MAC address
541 * @peer_ndi: Peer NDI MAC address
542 * @reason: Disconnection reason
543 * @locally_generated: true if the disconnection was locally generated,
544 * false if triggered by the peer
545 * @remove_sta: true if the NDI station should be removed (no other NDPs
546 * using the same peer NDI)
547 * @failure: true if NDP setup failed (before connected), false if
548 * graceful disconnection after NDP was established
549 * @gtk_id: GTK key ID used for the NDP; 0 if no GTK should be removed
550 *
551 * This callback notifies that an NDP has been disconnected. When
552 * @failure is true, NDP setup failed before connection was established.
553 * When @failure is false, it indicates graceful termination after NDP
554 * was successfully connected.
555 */
556 void (*ndp_disconnected)(void *ctx, struct nan_ndp_id *ndp_id,
557 const u8 *local_ndi, const u8 *peer_ndi,
558 enum nan_reason reason,
559 bool locally_generated, bool remove_sta,
560 bool failure, u8 gtk_id);
561
562 /**
563 * get_chans - Get the prioritized allowed channel information to be
564 * used for building the potential availability entries associated with
565 * the given map ID.
566 *
567 * @ctx: Callback context from cb_ctx
568 * @map_id: Map ID of the availability attribute for which the channels
569 * are requested.
570 * @chans: Pointer to a nan_channels structure that should be filled
571 * with the prioritized frequencies. On successful return the
572 * channels should be sorted having the higher priority channels
573 * first.
574 * Returns: 0 on success, -1 on failure.
575 *
576 * Note: The callback is responsible for allocating chans->chans as
577 * needed. The caller (the NAN module) is responsible for freeing the
578 * memory allocated for the chans->chans.
579 *
580 * Note: The callback should add all channels that are considered valid
581 * for use by the NAN module for the given map.
582 */
583 int (*get_chans)(void *ctx, u8 map_id, struct nan_channels *chans);
584
585 /**
586 * send_naf - Transmit a NAN Action frame
587 * @ctx: Callback context from cb_ctx
588 * @dst: Destination MAC address
589 * @src: Source MAC address. Can be NULL.
590 * @cluster_id: The cluster ID
591 * @buf: Frame body (starting from the Category field)
592 * Returns: 0 on success, -1 on failure
593 */
594 int (*send_naf)(void *ctx, const u8 *dst, const u8 *src,
595 const u8 *cluster_id, struct wpabuf *buf);
596
597 /**
598 * is_valid_publish_id - Check if a publish instance ID is valid
599 * @ctx: Callback context from cb_ctx
600 * @instance_id: The instance ID to check
601 * @service_id: On return, holds the service ID if the instance ID is
602 * valid
603 * Returns: true if there is a local publish service ID with the given
604 * instance ID; false otherse
605 */
606 bool (*is_valid_publish_id)(void *ctx, u8 instance_id, u8 *service_id);
607
608 /**
609 * set_peer_schedule - Configure peer schedule
610 * @ctx: Callback context from cb_ctx
611 * @nmi_addr: NAN Management Interface address of the peer
612 * @new_sta: Indicates whether this is a new STA (true) or an existing
613 * STA that is being re-configured (false)
614 * @cdw: Committed DW information (from device capabilities)
615 * @sequence_id: Schedule sequence ID
616 * @max_channel_switch_time: Maximum channel switch time
617 * @sched: Peer schedule information; can be NULL
618 * @ulw_elems: ULW elements buffer; can be NULL
619 * Returns: 0 on success, -1 on failure
620 */
621 int (*set_peer_schedule)(void *ctx, const u8 *nmi_addr, bool new_sta,
622 u16 cdw, u8 sequence_id,
623 u16 max_channel_switch_time,
624 const struct nan_peer_schedule *sched,
625 const struct wpabuf *ulw_elems);
626 /**
627 * bootstrap_request - Notify about received bootstrap request
628 * @ctx: Callback context from cb_ctx
629 * @peer_nmi: Peer NMI address
630 * @pbm: Pairing Bootstrapping Methods from the request. As defined in
631 * Wi-Fi Aware spec v4.0, Table 128 (NPBA format).
632 * @handle: Service handle
633 * @requestor_instance_id: Requestor instance ID
634 */
635 void (*bootstrap_request)(void *ctx, const u8 *peer_nmi, u16 pbm,
636 int handle, u8 requestor_instance_id);
637
638 /**
639 * bootstrap_completed - Notify about completed bootstrap
640 * @ctx: Callback context from cb_ctx
641 * @peer_nmi: Peer NMI address
642 * @pbm: Pairing Bootstrapping Method used. As defined in Wi-Fi Aware
643 * spec v4.0, Table 128 (NPBA format).
644 * @success: Whether bootstrap was successful
645 * @reason_code: Reason code for failure (0 if success is true)
646 * @handle: Service handle
647 * @requestor_instance_id: Requestor instance ID
648 */
649 void (*bootstrap_completed)(void *ctx, const u8 *peer_nmi, u16 pbm,
650 bool success, u8 reason_code,
651 int handle, u8 requestor_instance_id);
652
653 /**
654 * transmit_followup - Transmit Follow-up message to the peer
655 * @ctx: Callback context from cb_ctx
656 * @peer_nmi: Peer NMI address
657 * @attrs: Attributes to include in the Follow-up message
658 * @handle: Service handle for which the follow-up is sent
659 * @req_instance_id: Peer's service instance ID
660 */
661 int (*transmit_followup)(void *ctx, const u8 *peer_nmi,
662 const struct wpabuf *attrs, int handle,
663 u8 req_instance_id);
664
665 /**
666 * get_supported_bootstrap_methods - Get supported bootstrap methods
667 * @ctx: Callback context from cb_ctx
668 * @handle: Service handle for which PBM should have been defined
669 * Returns: Supported Pairing Bootstrapping Methods (PBM) bitfield as
670 * configured for the service or 0 if service is not found.
671 */
672 u16 (*get_supported_bootstrap_methods)(void *ctx, int handle);
673
674 /**
675 * send_pasn - Transmit a PASN Authentication frame
676 * @ctx: Callback context from cb_ctx
677 * @data: Frame to transmit
678 * @data_len: Length of frame to transmit
679 * Returns: 0 on success, -1 on failure
680 */
681 int (*send_pasn)(void *ctx, const u8 *data, size_t data_len);
682
683 /**
684 * pairing_status_cb - Callback for reporting NAN pairing result
685 * @ctx: Callback context from cb_ctx
686 * @peer_addr: Peer NAN device address
687 * @akmp: AKMP used in the pairing
688 * @cipher: Cipher used in the pairing
689 * @status: Status of the pairing (WLAN_STATUS_* )
690 * @ptk: Derived PTK for the pairing (valid only if status is success)
691 * @nd_pmk: ND-PMK from the pairing (valid only if status is success)
692 * Returns: 0 if status is WLAN_STATUS_SUCCESS and the key was
693 * installed successfully or status is
694 * WLAN_STATUS_UNSPECIFIED_FAILURE, -1 otherwise
695 */
696 int (*pairing_result_cb)(void *ctx, const u8 *peer_addr, int akmp,
697 int cipher, u16 status, struct wpa_ptk *ptk,
698 const u8 *nd_pmk);
699
700 /**
701 * update_pairing_credentials - Report received NIK and NPK for a peer
702 * @ctx: Callback context from cb_ctx
703 * @nik: NAN Identity Key received from peer
704 * @nik_len: Length of the NIK
705 * @cipher_ver: Cipher version of the NIK
706 * @nik_lifetime: Lifetime of the NIK in seconds
707 * @akmp: AKMP suite used to establish the NPKSA
708 * @npk: The NPK associated with the received NIK
709 * @npk_len: Length of the NPK
710 * Returns: 0 on success, -1 on failure
711 */
712 int (*update_pairing_credentials)(void *ctx, const u8 *nik,
713 size_t nik_len, int cipher_ver,
714 int nik_lifetime, int akmp,
715 const u8 *npk, size_t npk_len);
716
717 /**
718 * get_npk_akmp - Get the cached NPK and AKMP for a peer
719 * @ctx: Callback context from cb_ctx
720 * @peer_nmi: Peer NMI address
721 * @nonce: Nonce from the peer's NIRA
722 * @tag: Tag from the peer's NIRA
723 * @akmp: On success, set to the AKMP suite used to establish the NPKSA
724 * Returns: The NPK on success, NULL on failure
725 */
726 const struct wpabuf * (*get_npk_akmp)(void *ctx, const u8 *peer_nmi,
727 const u8 *nonce, const u8 *tag,
728 int *akmp);
729
730 /**
731 * pairing_request - Notify about received pairing request
732 * @ctx: Callback context from cb_ctx
733 * @peer_nmi: Peer NMI address
734 * @csid: Cipher suite ID requested by the peer
735 * @instance_id: Service instance ID for which the pairing is requested
736 * @rsn_data: Parsed RSNE data from peer's Authentication frame
737 */
738 void (*pairing_request)(void *ctx, const u8 *peer_nmi, u8 csid,
739 u8 instance_id,
740 const struct wpa_ie_data *rsn_data);
741
742 /**
743 * set_group_key - Install a group key
744 * @ctx: Callback context from cb_ctx
745 * @alg: Encryption algorithm (WPA_ALG_* )
746 * @addr: Address of the peer STA for Rx group keys, ff:ff:ff:ff:ff:ff
747 * for Tx keys; when clearing keys, %NULL is used to indicate that
748 * both the broadcast-only and default key of the specified key
749 * index is to be cleared
750 * @key_idx: Key index
751 * @seq: Packet number, the next packet number to be used for in replay
752 * protection; %NULL if not set
753 * @key: Key buffer
754 * @key_len: Length of the key buffer in octets
755 * @key_flags: bitwise OR of KEY_FLAG_*
756 * Returns: 0 on success, -1 on failure
757 */
758 int (*set_group_key)(void *ctx, enum wpa_alg alg, const u8 *addr,
759 int key_idx, const u8 *seq,
760 const u8 *key, size_t key_len,
761 enum key_flag key_flags);
762
763 /**
764 * get_seqnum - Get the current PN for a group key
765 * @ctx: Callback context from cb_ctx
766 * @key_idx: Key index
767 * @seq: Buffer for returning the latest used PN value
768 * @ndi_addr: For NDI group keys, the NDI MAC address; %NULL for
769 * NMI group keys
770 * Returns: 0 on success, -1 on failure
771 */
772 int (*get_seqnum)(void *ctx, int key_idx, u8 *seq, const u8 *ndi_addr);
773
774 /**
775 * get_peer_inactivity - Get the inactivity time for a peer
776 * @ctx: Callback context from cb_ctx
777 * @local_ndi: Local NDI address
778 * @peer_ndi: Peer NDI address
779 * Returns: Peer inactivity in seconds, negative value on failure
780 */
781 int (*get_peer_inactivity)(void *ctx, const u8 *local_ndi,
782 const u8 *peer_ndi);
783
784 /**
785 * schedule_changed - Notify about peer schedule change
786 * @ctx: Callback context from cb_ctx
787 * @peer_nmi: Peer NMI address
788 */
789 void (*schedule_changed)(void *ctx, const u8 *peer_nmi);
790 };
791
792 struct nan_data * nan_init(const struct nan_config *cfg);
793 void nan_deinit(struct nan_data *nan);
794 int nan_start(struct nan_data *nan, const struct nan_cluster_config *config);
795 int nan_update_config(struct nan_data *nan,
796 const struct nan_cluster_config *config);
797 void nan_set_cdw_overwrite(struct nan_data *nan, int map_id_2g, int map_id_5g);
798 void nan_stop(struct nan_data *nan);
799 void nan_flush(struct nan_data *nan);
800
801 int nan_add_peer(struct nan_data *nan, const u8 *addr,
802 const u8 *device_attrs, size_t device_attrs_len);
803 bool nan_process_followup(struct nan_data *nan, const u8 *addr, const u8 *buf,
804 size_t len, u8 req_instance_id, int handle);
805 int nan_bootstrap_request(struct nan_data *nan, int handle,
806 const u8 *peer_addr, u8 req_instance_id, u16 pbm,
807 bool auth);
808 int nan_bootstrap_peer_reset(struct nan_data *nan, const u8 *peer_nmi);
809 int nan_bootstrap_get_supported_methods(struct nan_data *nan,
810 const u8 *peer_nmi,
811 u16 *supported_methods);
812
813 bool nan_publish_instance_id_valid(struct nan_data *nan, u8 instance_id,
814 u8 *service_id);
815 void nan_set_cluster_id(struct nan_data *nan, const u8 *cluster_id);
816 int nan_action_rx(struct nan_data *nan, const struct ieee80211_mgmt *mgmt,
817 size_t len);
818 int nan_tx_status(struct nan_data *nan, const u8 *dst, const u8 *data,
819 size_t data_len, bool acked);
820 int nan_handle_ndp_setup(struct nan_data *nan, struct nan_ndp_params *params);
821 struct nan_device_capabilities *
822 nan_peer_get_device_capabilities(struct nan_data *nan, const u8 *addr,
823 u8 map_id);
824 int nan_peer_get_tk(struct nan_data *nan, const u8 *addr,
825 const u8 *peer_ndi, const u8 *local_ndi,
826 u8 *tk, size_t *tk_len, enum nan_cipher_suite_id *csid);
827 int nan_peer_get_schedule_info(struct nan_data *nan, const u8 *addr,
828 struct nan_peer_schedule *sched);
829 int nan_peer_dump_sched_to_buf(struct nan_peer_schedule *sched,
830 char *buf, size_t buflen);
831 int nan_peer_get_pot_avail(struct nan_data *nan, const u8 *addr,
832 struct nan_peer_potential_avail *pot_avail);
833 int nan_peer_dump_pot_avail_to_buf(struct nan_peer_potential_avail *pot_avail,
834 char *buf, size_t buflen);
835 const struct nan_pairing_cfg * nan_peer_get_pairing_cfg(struct nan_data *nan,
836 const u8 *addr,
837 const u8 **nonce,
838 const u8 **tag);
839 int nan_convert_sched_to_avail_attrs(struct nan_data *nan, u8 sequence_id,
840 u32 map_ids_bitmap,
841 size_t n_chans,
842 struct nan_chan_schedule *chans,
843 struct wpabuf *buf,
844 bool include_potential);
845 void nan_local_sched_update(struct nan_data *nan, struct nan_schedule *sched);
846 void nan_set_sched_update_pending(struct nan_data *nan, bool pending);
847 bool nan_peer_pairing_supported(struct nan_data *nan, const u8 *addr);
848 bool nan_peer_npk_nik_caching_supported(struct nan_data *nan, const u8 *addr);
849 int nan_get_peer_ndc_freq(struct nan_data *nan,
850 const struct nan_peer_schedule *peer_sched,
851 u8 map_idx);
852 int nan_crypto_derive_nd_pmk(const char *pwd, const u8 *service_id,
853 enum nan_cipher_suite_id csid,
854 const u8 *peer_nmi, u8 *nd_pmk);
855 int nan_crypto_pmkid_list(struct dl_list *pmkid_list, const u8 *raddr,
856 const u8 *srv_id, const int *cipher_suites_list,
857 const u8 *pmk);
858 void nan_crypto_clear_pmkid_list(struct dl_list *pmkid_list);
859 void nan_add_dev_capa_attr(struct nan_data *nan, struct wpabuf *buf);
860 int nan_peer_del_all_ndps(struct nan_data *nan, const u8 *addr);
861 int nan_get_chan_entry(struct nan_data *nan, const struct nan_sched_chan *chan,
862 struct nan_chan_entry *chan_entry);
863 int nan_get_peer_elems(struct nan_data *nan, const u8 *addr, u8 **elems);
864 int nan_set_bootstrap_configuration(struct nan_data *nan,
865 u16 supported_bootstrap_methods,
866 u16 auto_accept_bootstrap_methods,
867 u16 bootstrap_comeback_timeout);
868 struct wpabuf * nan_crypto_derive_nira_tag(const u8 *nik, size_t nik_len,
869 const u8 *nmi_addr,
870 const u8 *nira_nonce);
871 int nan_ndp_requested_gtk_csid(struct nan_data *nan,
872 const struct nan_ndp_id *ndp_id);
873 int nan_set_mgmt_group_cipher(struct nan_data *nan, int cipher);
874 int nan_set_beacon_prot(struct nan_data *nan, bool enable);
875 int nan_set_max_ndl_idle_period(struct nan_data *nan, u16 max_idle_period);
876 bool nan_has_active_ndp(struct nan_data *nan);
877 int nan_get_status(struct nan_data *nan, char *buf, size_t buflen);
878 int nan_peer_dump_ndps_to_buf(struct nan_data *nan, const u8 *addr,
879 char *buf, size_t buflen);
880 void nan_terminate_ndi_ndps(struct nan_data *nan, const u8 *ndi_addr);
881
882 #ifdef CONFIG_PASN
883 int nan_pairing_add_attrs(struct nan_data *nan_data, struct wpabuf *buf);
884 int nan_pairing_initiate_pasn_auth(struct nan_data *nan_data, const u8 *addr,
885 u8 auth_mode, int cipher, int handle,
886 u8 peer_instance_id, bool responder,
887 const char *password,
888 const struct nan_schedule *sched);
889 int nan_pairing_pasn_auth_tx_status(struct nan_data *nan, const u8 *data,
890 size_t data_len, bool acked);
891 int nan_pairing_auth_rx(struct nan_data *nan_data,
892 const struct ieee80211_mgmt *mgmt, size_t len);
893 int nan_pairing_set_pairing_setup(struct nan_data *nan_data, bool value);
894 int nan_pairing_set_npk_caching(struct nan_data *nan_data, bool value);
895 int nan_pairing_set_pairing_verification(struct nan_data *nan_data, bool value);
896 int nan_pairing_set_cipher_suites(struct nan_data *nan_data, u32 value);
897 int nan_pairing_set_nik(struct nan_data *nan, const u8 *nik, size_t nik_len);
898 int nan_pairing_set_nik_lifetime(struct nan_data *nan, u32 lifetime);
899 bool nan_pairing_is_peer_paired(struct nan_data *nan_data, const u8 *peer_addr);
900 int nan_pairing_abort(struct nan_data *nan_data, const u8 *peer_addr);
901 void nan_pairing_unpair_peer(struct nan_data *nan_data, const u8 *peer_addr);
902 #else /* CONFIG_PASN */
nan_pairing_add_attrs(struct nan_data * nan_data,struct wpabuf * buf)903 static inline int nan_pairing_add_attrs(struct nan_data *nan_data,
904 struct wpabuf *buf)
905 {
906 return 0;
907 }
908
909 static inline
nan_pairing_initiate_pasn_auth(struct nan_data * nan_data,const u8 * addr,u8 auth_mode,int cipher,int handle,u8 peer_instance_id,bool responder,const char * password,const struct nan_schedule * sched)910 int nan_pairing_initiate_pasn_auth(struct nan_data *nan_data, const u8 *addr,
911 u8 auth_mode, int cipher, int handle,
912 u8 peer_instance_id, bool responder,
913 const char *password,
914 const struct nan_schedule *sched)
915 {
916 return -1;
917 }
918
nan_pairing_pasn_auth_tx_status(struct nan_data * nan,const u8 * data,size_t data_len,bool acked)919 static inline int nan_pairing_pasn_auth_tx_status(struct nan_data *nan,
920 const u8 *data,
921 size_t data_len, bool acked)
922 {
923 return -1;
924 }
925
nan_pairing_auth_rx(struct nan_data * nan_data,const struct ieee80211_mgmt * mgmt,size_t len)926 static inline int nan_pairing_auth_rx(struct nan_data *nan_data,
927 const struct ieee80211_mgmt *mgmt,
928 size_t len)
929 {
930 return -1;
931 }
932
933 static inline
nan_pairing_is_peer_paired(struct nan_data * nan_data,const u8 * peer_addr)934 bool nan_pairing_is_peer_paired(struct nan_data *nan_data, const u8 *peer_addr)
935 {
936 return false;
937 }
938
939 static inline
nan_pairing_unpair_peer(struct nan_data * nan_data,const u8 * peer_addr)940 void nan_pairing_unpair_peer(struct nan_data *nan_data, const u8 *peer_addr)
941 {
942 }
943
944 #endif /* CONFIG_PASN */
945
946 #endif /* NAN_H */
947