xref: /freebsd/contrib/wpa/src/common/nan_defs.h (revision 71e72c9e91c4b8007a4292e09669e8b549c29e97)
1 /*
2  * NAN (Wi-Fi Aware) definitions
3  * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4  * Copyright (c) 2026, Intel Corporation
5  *
6  * This software may be distributed under the terms of the BSD license.
7  * See README for more details.
8  */
9 
10 #ifndef NAN_DEFS_H
11 #define NAN_DEFS_H
12 
13 /* Wi-Fi Aware spec v4.0, Table 35 (NAI Action frame subtypes) */
14 enum nan_subtype {
15 	NAN_SUBTYPE_INVALID			= 0,
16 	NAN_SUBTYPE_RANGING_REQUEST		= 1,
17 	NAN_SUBTYPE_RANGING_RESPONSE		= 2,
18 	NAN_SUBTYPE_RANGING_TERMINATION		= 3,
19 	NAN_SUBTYPE_RANGING_REPORT		= 4,
20 	NAN_SUBTYPE_DATA_PATH_REQUEST		= 5,
21 	NAN_SUBTYPE_DATA_PATH_RESPONSE		= 6,
22 	NAN_SUBTYPE_DATA_PATH_CONFIRM		= 7,
23 	NAN_SUBTYPE_DATA_PATH_KEY_INSTALL	= 8,
24 	NAN_SUBTYPE_DATA_PATH_TERMINATION	= 9,
25 	NAN_SUBTYPE_SCHEDULE_REQUEST		= 10,
26 	NAN_SUBTYPE_SCHEDULE_RESPONSE		= 11,
27 	NAN_SUBTYPE_SCHEDULE_CONFIRM		= 12,
28 	NAN_SUBTYPE_SCHEDULE_UPDATE_NOTIF	= 13,
29 };
30 
31 enum nan_attr_id {
32 	NAN_ATTR_MASTER_INDICATION = 0x00,
33 	NAN_ATTR_CLUSTER = 0x01,
34 	NAN_ATTR_NAN_ATTR_SERVICE_ID_LIST = 0x02,
35 	NAN_ATTR_SDA = 0x03, /* Service Descriptor attribute */
36 	NAN_ATTR_CONN_CAPA = 0x04,
37 	NAN_ATTR_WLAN_INFRA = 0x05,
38 	NAN_ATTR_P2P_OPER = 0x06,
39 	NAN_ATTR_IBSS = 0x07,
40 	NAN_ATTR_MESH = 0x08,
41 	NAN_ATTR_FURTHER_NAN_SD = 0x09,
42 	NAN_ATTR_FURTHER_AVAIL_MAP = 0x0A,
43 	NAN_ATTR_COUNTRY_CODE = 0x0B,
44 	NAN_ATTR_RANGING = 0x0C,
45 	NAN_ATTR_CLUSTER_DISCOVERY = 0x0D,
46 	NAN_ATTR_SDEA = 0x0E, /* Service Descriptor Extension attribute */
47 	NAN_ATTR_DEVICE_CAPABILITY = 0x0F,
48 	NAN_ATTR_NDP = 0x10,
49 	NAN_ATTR_NAN_AVAILABILITY = 0x12,
50 	NAN_ATTR_NDC = 0x13,
51 	NAN_ATTR_NDL = 0x14,
52 	NAN_ATTR_NDL_QOS = 0x15,
53 	NAN_ATTR_UNALIGNED_SCHEDULE = 0x17,
54 	NAN_ATTR_RANGING_INFO = 0x1A,
55 	NAN_ATTR_RANGING_SETUP = 0x1B,
56 	NAN_ATTR_FTM_RANGING_REPORT = 0x1C,
57 	NAN_ATTR_ELEM_CONTAINER = 0x1D,
58 	NAN_ATTR_EXT_WLAN_INFRA = 0x1E,
59 	NAN_ATTR_EXT_P2P_OPER = 0x1F,
60 	NAN_ATTR_EXT_IBSS = 0x20,
61 	NAN_ATTR_EXT_MESH = 0x21,
62 	NAN_ATTR_CSIA = 0x22, /* Cipher Suite Info attribute */
63 	NAN_ATTR_SCIA = 0x23, /* Security Context Info attribute */
64 	NAN_ATTR_SHARED_KEY_DESCR = 0x24,
65 	NAN_ATTR_PUBLIC_AVAILABILITY = 0x27,
66 	NAN_ATTR_SUBSC_SERVICE_ID_LIST = 0x28,
67 	NAN_ATTR_NDP_EXT = 0x29,
68 	NAN_ATTR_DCEA = 0x2A, /* Device Capability Extension attribute */
69 	NAN_ATTR_NIRA = 0x2B, /* NAN Identity Resolution attribute */
70 	NAN_ATTR_NPBA = 0x2C, /* NAN Pairing Bootstrapping attribute */
71 	NAN_ATTR_S3 = 0x2D,
72 	NAN_ATTR_TPEA = 0x2E, /* Transmit Power Envelope attribute */
73 	NAN_ATTR_VENDOR_SPECIFIC = 0xDD,
74 };
75 
76 /* Wi-Fi Aware spec v4.0, Table 43 (Reason Code field) */
77 enum nan_reason {
78 	NAN_REASON_RESERVED                 = 0,
79 	NAN_REASON_UNSPECIFIED_REASON       = 1,
80 	NAN_REASON_RESOURCE_LIMITATION      = 2,
81 	NAN_REASON_INVALID_PARAMETERS       = 3,
82 	NAN_REASON_FTM_PARAMETERS_INCAPABLE = 4,
83 	NAN_REASON_NO_MOVEMENT              = 5,
84 	NAN_REASON_INVALID_AVAILABILITY     = 6,
85 	NAN_REASON_IMMUTABLE_UNACCEPTABLE   = 7,
86 	NAN_REASON_SECURITY_POLICY          = 8,
87 	NAN_REASON_QOS_UNACCEPTABLE         = 9,
88 	NAN_REASON_NDP_REJECTED             = 10,
89 	NAN_REASON_NDL_UNACCEPTABLE         = 11,
90 	NAN_REASON_RANGING_SCHED_NOT_ACCEPT = 12,
91 	NAN_REASON_PAIR_BOOTSTRAP_REJECTED  = 13,
92 };
93 
94 /* Service Descriptor attribute (SDA) */
95 
96 /* Service Control field */
97 #define NAN_SRV_CTRL_TYPE_MASK                (BIT(0) | BIT(1))
98 #define NAN_SRV_CTRL_MATCHING_FILTER          BIT(2)
99 #define NAN_SRV_CTRL_RESP_FILTER              BIT(3)
100 #define NAN_SRV_CTRL_SRV_INFO                 BIT(4)
101 #define NAN_SRV_CTRL_DISCOVERY_RANGE_LIMITED  BIT(5)
102 #define NAN_SRV_CTRL_BINDING_BITMAP           BIT(6)
103 
104 enum nan_service_control_type {
105 	NAN_SRV_CTRL_PUBLISH = 0,
106 	NAN_SRV_CTRL_SUBSCRIBE = 1,
107 	NAN_SRV_CTRL_FOLLOW_UP = 2,
108 };
109 
110 /* Service Descriptor Extension attribute (SDEA) */
111 
112 /* SDEA Control field */
113 #define NAN_SDEA_CTRL_FSD_REQ        BIT(0)
114 #define NAN_SDEA_CTRL_FSD_GAS        BIT(1)
115 #define NAN_SDEA_CTRL_DATA_PATH_REQ  BIT(2)
116 #define NAN_SDEA_CTRL_DATA_PATH_TYPE BIT(3)
117 #define NAN_SDEA_CTRL_QOS_REQ        BIT(5)
118 #define NAN_SDEA_CTRL_SECURITY_REQ   BIT(6)
119 #define NAN_SDEA_CTRL_RANGING_REQ    BIT(7)
120 #define NAN_SDEA_CTRL_RANGE_LIMIT    BIT(8)
121 #define NAN_SDEA_CTRL_SRV_UPD_INDIC  BIT(9)
122 #define NAN_SDEA_CTRL_GTK_REQ        BIT(10)
123 
124 enum nan_service_protocol_type {
125 	NAN_SRV_PROTO_BONJOUR = 1,
126 	NAN_SRV_PROTO_GENERIC = 2,
127 	NAN_SRV_PROTO_CSA_MATTER = 3,
128 };
129 
130 /* SRF Control field */
131 /* bit 0 = 0: Address Set is a sequence of MAC Addresses
132  * bit 0 = 1: Address Set is a Bloom filter */
133 #define NAN_SRF_CTRL_BF 	BIT(0)
134 #define NAN_SRF_CTRL_INCLUDE 	BIT(1)
135 
136 /* bit 2-3: Bloom Filter Index */
137 #define NAN_SRF_CTRL_BF_IDX_MSK (BIT(0) | BIT(1))
138 #define NAN_SRF_CTRL_BF_IDX_POS 2
139 
140 /* Wi-Fi Aware spec v4.0, Table 128 (NPBA format)  */
141 #define NAN_PBA_TYPE_MASK 0xf
142 #define NAN_PBA_STATUS_MASK 0xf
143 #define NAN_PBA_STATUS_POS 4
144 
145 enum nan_pba_type {
146 	NAN_PBA_TYPE_ADVERTISE = 0,
147 	NAN_PBA_TYPE_REQUEST   = 1,
148 	NAN_PBA_TYPE_RESPONSE  = 2,
149 };
150 
151 enum nan_pba_status {
152 	NAN_PBA_STATUS_ACCEPTED = 0,
153 	NAN_PBA_STATUS_REJECTED = 1,
154 	NAN_PBA_STATUS_COMEBACK = 2,
155 };
156 
157 enum nan_pairing_bootstrapping_method {
158 	NAN_PBA_METHOD_OPPORTUNISTIC      = BIT(0),
159 	NAN_PBA_METHOD_PIN_DISPLAY        = BIT(1),
160 	NAN_PBA_METHOD_PASSPHRASE_DISPLAY = BIT(2),
161 	NAN_PBA_METHOD_QR_DISPLAY         = BIT(3),
162 	NAN_PBA_METHOD_NFC_TAG            = BIT(4),
163 	NAN_PBA_METHOD_PIN_KEYPAD         = BIT(5),
164 	NAN_PBA_METHOD_PASSPHRASE_KEYPAD  = BIT(6),
165 	NAN_PBA_METHOD_QR_SCAN            = BIT(7),
166 	NAN_PBA_METHOD_NFC_READER         = BIT(8),
167 	NAN_PBA_METHOD_SERVICE_MANAGED    = BIT(14),
168 	NAN_PBA_METHOD_HANDSHAKE_SKIPPED  = BIT(15),
169 };
170 
171 #define NAN_ATTR_HDR_LEN 3
172 #define NAN_SERVICE_ID_LEN 6
173 
174 #define NAN_USD_DEFAULT_FREQ 2437
175 
176 /* Map ID
177  * Wi-Fi Aware spec v4.0, Table 79 (Device Capability attribute format) */
178 #define NAN_DEV_CAPA_MAP_ID_DONT_APPLY_ALL BIT(0)
179 #define NAN_DEV_CAPA_MAP_ID_POS            1
180 #define NAN_DEV_CAPA_MAP_ID_MASK          (BIT(1) | BIT(2) | BIT(3) \
181 					   BIT(4))
182 
183 /* Supported Bands:
184  * Wi-Fi Aware spec v4.0, Table 79 (Device Capability attribute format) */
185 #define NAN_DEV_CAPA_SBAND_SUB_1G BIT(1)
186 #define NAN_DEV_CAPA_SBAND_2G     BIT(2)
187 #define NAN_DEV_CAPA_SBAND_5G     BIT(4)
188 #define NAN_DEV_CAPA_SBAND_6G     BIT(7)
189 
190 /* Wi-Fi Aware spec v4.0, Table 80 (Committed DW Information field format) */
191 #define NAN_CDW_INFO_2G_POS            0
192 #define NAN_CDW_INFO_2G_MASK           (BIT(0) | BIT(1) | BIT(2))
193 #define NAN_CDW_INFO_5G_POS            3
194 #define NAN_CDW_INFO_5G_MASK           (BIT(3) | BIT(4) | BIT(5))
195 #define NAN_CDW_INFO_2G_OVERRIDE_POS   6
196 #define NAN_CDW_INFO_2G_OVERRIDE_MASK  (BIT(6) | BIT(7) | BIT(8) | BIT(9))
197 #define NAN_CDW_INFO_5G_OVERRIDE_POS   10
198 #define NAN_CDW_INFO_5G_OVERRIDE_MASK  (BIT(10) | BIT(11) | BIT(12) | BIT(13))
199 
200 /* Wi-Fi Aware spec v4.0, Table 81 (Operation Mode field format) */
201 #define NAN_DEV_CAPA_OP_MODE_PHY_MODE     (BIT(0) | BIT(4))
202 #define NAN_DEV_CAPA_OP_MODE_PHY_MODE_VHT BIT(0)
203 #define NAN_DEV_CAPA_OP_MODE_HE_VHT_80P80 BIT(1)
204 #define NAN_DEV_CAPA_OP_MODE_HE_VHT_160   BIT(2)
205 #define NAN_DEV_CAPA_OP_MODE_PHY_MODE_HE  BIT(4)
206 
207 /* Number of Antennas
208  * Wi-Fi Aware spec v4.0, Table 79 (Device Capability attribute format) */
209 #define NAN_DEV_CAPA_TX_ANT_POS   0
210 #define NAN_DEV_CAPA_TX_ANT_MASK  0x0f
211 #define NAN_DEV_CAPA_RX_ANT_POS   4
212 #define NAN_DEV_CAPA_RX_ANT_MASK  0xf0
213 
214 /* Capabilities
215  * Wi-Fi Aware spec v4.0, Table 79 (Device Capability attribute format) */
216 #define NAN_DEV_CAPA_DFS_MASTER     BIT(0)
217 #define NAN_DEV_CAPA_EXT_KEY_ID     BIT(1)
218 #define NAN_DEV_CAPA_SIM_NDP_RX     BIT(2)
219 #define NAN_DEV_CAPA_NDPE_ATTR_SUPP BIT(3)
220 #define NAN_DEV_CAPA_S3             BIT(4)
221 
222 /* Device Capability attribute
223  * Wi-Fi Aware spec v4.0, Table 79 (Device Capability attribute format) */
224 struct nan_device_capa {
225 	u8 map_id; /* Map ID */
226 	le16 cdw_info; /* Committed DW Info */
227 	u8 supported_bands; /* Supported Bands */
228 	u8 op_mode; /* Operation Mode */
229 	u8 ant; /* Number of Antennas */
230 	le16 channel_switch_time; /* Max Channel Switch Time */
231 	u8 capa; /* Capabilities */
232 } STRUCT_PACKED;
233 
234 /* NAN Data Path (NDP) attribute
235  * Wi-Fi Aware spec v4.0, Table 82 (NDP attribute format) */
236 #define NAN_NDP_TYPE_POS    0
237 #define NAN_NDP_TYPE_MASK   (BIT(0) | BIT(1) | BIT(2) | BIT(3))
238 #define NAN_NDP_STATUS_POS  4
239 #define NAN_NDP_STATUS_MASK (BIT(4) | BIT(5) | BIT(6) | BIT(7))
240 
241 /* NDP type (in Type and Status field) */
242 enum nan_ndp_type {
243 	NAN_NDP_TYPE_REQUEST		= 0,
244 	NAN_NDP_TYPE_RESPONSE		= 1,
245 	NAN_NDP_TYPE_CONFIRM		= 2,
246 	NAN_NDP_TYPE_SECURITY_INSTALL	= 3,
247 	NAN_NDP_TYPE_TERMINATE		= 4,
248 };
249 
250 /* NDP status (in Type and Status field) */
251 enum nan_ndp_status {
252 	NAN_NDP_STATUS_CONTINUED = 0,
253 	NAN_NDP_STATUS_ACCEPTED  = 1,
254 	NAN_NDP_STATUS_REJECTED  = 2,
255 };
256 
257 /* Wi-Fi Aware spec v4.0, Table 84 (NDP Control field) and Table 87 (Subfields
258  * of NDPE Control field format).
259  * Bits 0-4 are identical for NDP and NDPE. The only differences are in
260  * Bit 5.
261  */
262 #define NAN_NDP_CTRL_CONFIRM_REQUIRED       BIT(0)
263 #define NAN_NDP_CTRL_SECURITY_PRESENT       BIT(2)
264 #define NAN_NDP_CTRL_PUBLISH_ID_PRESENT     BIT(3)
265 #define NAN_NDP_CTRL_RESPONDER_NDI_PRESENT  BIT(4)
266 
267 #define NAN_NDP_CTRL_SPEC_INFO_PRESENT      BIT(5)
268 #define NAN_NDPE_CTRL_GTK_REQUIRED          BIT(5)
269 
270 /* Wi-Fi Aware spec v4.0, Table 82 (NDP attribute format) and
271  * Table 86 (NAN Data Path Extension attribute format)
272  * Note: The structure does not include the Attribute ID and Length fields. */
273 struct ieee80211_ndp {
274 	u8 dialog_token; /* Dialog Token */
275 	u8 type_and_status; /* Type and Status */
276 	u8 reason_code; /* Reason Code */
277 	u8 initiator_ndi[ETH_ALEN]; /* Initiator NDI */
278 	u8 ndp_id; /* NDP ID */
279 	u8 ndp_ctrl; /* NDP Control */
280 
281 	/* followed by optional fields based on ndp_ctrl */
282 	u8 optional[0];
283 } STRUCT_PACKED;
284 
285 /* Wi-Fi Aware spec v4.0, Table 89 (List of TLV types for the NDPE attribute) */
286 enum nan_ndpe_tlv_type {
287 	NAN_NDPE_TLV_IPV6_LINK_LOCAL = 0,
288 	NAN_NDPE_TLV_SRV_INFO        = 1,
289 };
290 
291 #define NAN_NDPE_TLV_IPV6_LINK_LOCAL_LEN 8
292 
293 /* Wi-Fi Aware spec v4.0, Table 97 (Time Bitmap Control field format for the
294  * NAN Availability attribute) */
295 #define NAN_TIME_BM_CTRL_BIT_DURATION_POS  0
296 #define NAN_TIME_BM_CTRL_BIT_DURATION_MASK (BIT(0) | BIT(1) | BIT(2))
297 #define NAN_TIME_BM_CTRL_BIT_DURATION_16_TU   0
298 #define NAN_TIME_BM_CTRL_BIT_DURATION_32_TU   1
299 #define NAN_TIME_BM_CTRL_BIT_DURATION_64_TU   2
300 #define NAN_TIME_BM_CTRL_BIT_DURATION_128_TU  3
301 
302 #define NAN_TIME_BM_CTRL_PERIOD_POS        3
303 #define NAN_TIME_BM_CTRL_PERIOD_MASK       (BIT(3) | BIT(4) | BIT(5))
304 #define NAN_TIME_BM_CTRL_PERIOD_NONE    0
305 
306 #define NAN_TIME_BM_CTRL_START_OFFSET_POS  6
307 #define NAN_TIME_BM_CTRL_START_OFFSET_MASK (BIT(6) | BIT(7) | BIT(8) |  \
308 					    BIT(9) | BIT(10) | BIT(11) | \
309 					    BIT(12) | BIT(13) | BIT(14))
310 
311 /* Wi-Fi Aware spec v4.0, Table 96 (Entry Control field format for the
312  * NAN Availability attribute) */
313 #define NAN_AVAIL_ENTRY_CTRL_TYPE_COMMITTED   BIT(0)
314 #define NAN_AVAIL_ENTRY_CTRL_TYPE_POTENTIAL   BIT(1)
315 #define NAN_AVAIL_ENTRY_CTRL_TYPE_COND        BIT(2)
316 #define NAN_AVAIL_ENTRY_CTRL_TYPE_MASK        (BIT(0) | BIT(1) | BIT(2))
317 
318 #define NAN_AVAIL_ENTRY_CTRL_USAGE_PREF_POS   3
319 #define NAN_AVAIL_ENTRY_CTRL_USAGE_PREF_MASK  (BIT(3) | BIT(4))
320 #define NAN_AVAIL_ENTRY_CTRL_UTIL_UNKNOWN     7
321 #define NAN_AVAIL_ENTRY_CTRL_UTIL_MAX         5
322 #define NAN_AVAIL_ENTRY_CTRL_UTIL_POS         5
323 #define NAN_AVAIL_ENTRY_CTRL_UTIL_MASK        (BIT(5) | BIT(6) | BIT(7))
324 #define NAN_AVAIL_ENTRY_CTRL_RX_NSS_POS       8
325 #define NAN_AVAIL_ENTRY_CTRL_RX_NSS_MASK      (BIT(8) | BIT(9) | BIT(10) | \
326 					       BIT(11))
327 #define NAN_AVAIL_ENTRY_CTRL_TBM_PRESENT      BIT(12)
328 
329 /* Wi-Fi Aware spec v4.0, Table 99 (List of Band Entries) */
330 enum nan_band_entry {
331 	NAN_BAND_ENTRY_SUB_1G       = 1,
332 	NAN_BAND_ENTRY_2G           = 2,
333 	NAN_BAND_ENTRY_5G           = 4,
334 	NAN_BAND_ENTRY_6G           = 7,
335 };
336 
337 /* Wi-Fi Aware spec v4.0, Table 100 (Channel Entry format for the
338  * NAN Availability attribute) */
339 struct nan_chan_entry {
340 	u8 op_class; /* Operating Class */
341 	le16 chan_bitmap; /* Channel Bitmap */
342 	u8 pri_chan_bitmap; /* Primary Channel Bitmap */
343 
344 	/* This field is optional. It is present only if
345 	 * NAN_BAND_CHAN_CTRL_NON_CONT_BW is set
346 	 */
347 	le16 aux_chan_bitmap; /* Auxiliary Channel Bitmap */
348 } STRUCT_PACKED;
349 
350 /* Channel entry only contains the aux_chan_bitmap field for 80+80 MHz operating
351  * class. See Table 100. */
352 #define NAN_CHAN_ENTRY_MIN_LEN   4
353 #define NAN_CHAN_ENTRY_80P80_LEN 6
354 
355 /* Wi-Fi Aware spec v4.0, Table 98 (Band/Channel Entries List field format for
356  * the NAN Availability attribute) */
357 #define NAN_BAND_CHAN_CTRL_TYPE             BIT(0)
358 #define NAN_BAND_CHAN_CTRL_NON_CONT_BW      BIT(1)
359 #define NAN_BAND_CHAN_CTRL_NUM_ENTRIES_POS  4
360 #define NAN_BAND_CHAN_CTRL_NUM_ENTRIES_MASK (BIT(4) | BIT(5) | BIT(6) | BIT(7))
361 
362 struct nan_band_chan_list {
363 	u8 ctrl;
364 	u8 entries[0];
365 } STRUCT_PACKED;
366 
367 /* Wi-Fi Aware spec v4.0, Table 95 (Availability Entry field format for the
368  * NAN Availability attribute)
369  */
370 struct nan_avail_ent {
371 	le16 len;
372 	le16 ctrl; /* Entry Control */
373 
374 	/* followed by optional fields based on ctrl. Note that this also
375 	 * includes the inclusion of Time Bitmap Control and Length fields
376 	 */
377 	u8 optional[0];
378 } STRUCT_PACKED;
379 
380 #define MIN_AVAIL_ENTRY_LEN 2
381 
382 /* This structure represents a time bitmap related fields in the NAN
383  * Availability entry. */
384 struct nan_tbm {
385 	le16 ctrl;
386 	u8 len;
387 	u8 bitmap[0];
388 } STRUCT_PACKED;
389 
390 /* Wi-Fi Aware spec v4.0, Table 94 (Attribute Control field format for the
391  * NAN Availability attribute) */
392 #define NAN_AVAIL_CTRL_MAP_ID_POS             0
393 #define NAN_AVAIL_CTRL_MAP_ID_MASK            0xf
394 #define NAN_AVAIL_CTRL_COMMITTED_CHANGED      BIT(4)
395 #define NAN_AVAIL_CTRL_POTENTIAL_CHANGED      BIT(5)
396 #define NAN_AVAIL_CTRL_PUB_AVAIL_ATTR_CHANGED BIT(6)
397 #define NAN_AVAIL_CTRL_NDC_ATTR_CHANGED       BIT(7)
398 
399 /* Wi-Fi Aware spec v4.0, Table 93 (NAN Availability attribute format).
400  * Attribute ID and Length fields not included. */
401 struct nan_avail {
402 	u8 seq_id; /* Sequence ID */
403 	le16 ctrl; /* Attribute Control */
404 
405 	/* followed by Availability Entry List */
406 	u8 optional[0];
407 } STRUCT_PACKED;
408 
409 /* Wi-Fi Aware spec v4.0, Table 110 (Attribute Control field format for the
410  * Unaligned Schedule attribute)
411  */
412 #define NAN_UNALIGNED_SCHED_CTRL_SCHED_ID_MASK (BIT(0) | BIT(1) | BIT(2) | \
413 						BIT(3))
414 
415 /* Wi-Fi Aware spec v4.0, Table 111 (ULW Overwrite field format) */
416 #define NAN_ULW_OVERWRITE_ALL        BIT(0)
417 #define NAN_ULW_OVERWRITE_MAP_ID_POS 1
418 #define NAN_ULW_OVERWRITE_MAP_ID_MASK (BIT(1) | BIT(2) | BIT(3) | BIT(4))
419 
420 /* Wi-Fi Aware spec v4.0, Table 112 (ULW Control field format) */
421 #define NAN_ULW_CTRL_TYPE_POS                0
422 #define NAN_ULW_CTRL_TYPE_MASK               (BIT(0) | BIT(1))
423 #define NAN_ULW_CTRL_TYPE_BAND_ID            0
424 #define NAN_ULW_CTRL_TYPE_CHAN_ENTRY         1
425 #define NAN_ULW_CTRL_TYPE_CHAN_ENTRY_WITH_AUX 2
426 #define NAN_ULW_CTRL_CHAN_AVAIL              BIT(2)
427 #define NAN_ULW_CTRL_RX_NSS_POS              3
428 #define NAN_ULW_CTRL_RX_NSS_MASK             (BIT(3) | BIT(4) | BIT(5) | BIT(6))
429 
430 /* Wi-Fi Aware spec v4.0, Table 109 (Unaligned Schedule attribute format).
431  * ID and length are not included.
432  */
433 struct nan_unaligned_sched {
434 	u8 sched_id;
435 	u8 seq_id;
436 	le32 start_time;
437 	le32 duration;
438 	le32 period;
439 	u8 count_down;
440 	u8 ulw_overwrite;
441 
442 	/* followed by optional fields (ULW Control and Band ID or Channel
443 	 * Entry) */
444 	u8 optional[0];
445 } STRUCT_PACKED;
446 
447 #define NAN_SCHED_ENTRY_MAP_MASK (BIT(0) | BIT(1) | BIT(2) | BIT(3))
448 
449 /* Wi-Fi Aware spec v4.0, Table 104 (Schedule Entry format for the NDC
450  * attribute) */
451 struct nan_sched_entry {
452 	u8 map_id; /* Map ID */
453 	le16 control; /* Time Bitmap Control */
454 	u8 len; /* Time Bitmap Length */
455 	u8 bm[0]; /* Time Bitmap */
456 } STRUCT_PACKED;
457 
458 /* Wi-Fi Aware spec v4.0, Table 103 (Attribute Control field format for the NDC
459  * attribute) */
460 #define NAN_NDC_CTRL_SELECTED BIT(0)
461 
462 /* Wi-Fi Aware spec v4.0, Table 102 (NDC attribute format).
463  * Attribute ID and Length fields not included */
464 struct ieee80211_ndc {
465 	u8 ndc_id[ETH_ALEN]; /* NDC ID */
466 	u8 ctrl; /* Attribute Control */
467 	u8 sched_entries[0]; /* Schedule Entry List */
468 } STRUCT_PACKED;
469 
470 /* Wi-Fi Aware spec v4.0, Table 105 (NDL attribute format) */
471 #define NAN_NDL_TYPE_POS    0
472 #define NAN_NDL_TYPE_MASK   (BIT(0) | BIT(1) | BIT(2) | BIT(3))
473 #define NAN_NDL_STATUS_POS  4
474 #define NAN_NDL_STATUS_MASK (BIT(4) | BIT(5) | BIT(6) | BIT(7))
475 
476 enum nan_ndl_type {
477 	NAN_NDL_TYPE_REQUEST  = 0,
478 	NAN_NDL_TYPE_RESPONSE = 1,
479 	NAN_NDL_TYPE_CONFIRM  = 2,
480 };
481 
482 enum nan_ndl_status {
483 	NAN_NDL_STATUS_CONTINUED = 0,
484 	NAN_NDL_STATUS_ACCEPTED	 = 1,
485 	NAN_NDL_STATUS_REJECTED	 = 2,
486 };
487 
488 /* Wi-Fi Aware spec v4.0, Table 107 (NDL Control field format) */
489 #define NAN_NDL_CTRL_PEER_ID_PRESENT          BIT(0)
490 #define NAN_NDL_CTRL_IMMUT_SCHED_PRESENT      BIT(1)
491 #define NAN_NDL_CTRL_NDC_ATTR_PRESENT         BIT(2)
492 #define NAN_NDL_CTRL_NDL_QOS_ATTR_PRESENT     BIT(3)
493 #define NAN_NDL_CTRL_MAX_IDLE_PERIOD_PRESENT  BIT(4)
494 #define NAN_NDL_CTRL_NDL_TYPE                 BIT(5)
495 #define NAN_NDL_CTRL_NDL_SETUP_REASON_POS     6
496 #define NAN_NDL_CTRL_NDL_SETUP_REASON_MASK    (BIT(6) | BIT(7))
497 
498 #define NAN_NDL_CTRL_NDL_SETUP_REASON_NDP     0x0
499 #define NAN_NDL_CTRL_NDL_SETUP_REASON_FSD_GAS 0x1
500 
501 /* Wi-Fi Aware spec v4.0, Table 105 (NDL attribute format) */
502 struct ieee80211_ndl {
503 	u8 dialog_token; /* Dialog Token */
504 	u8 type_and_status; /* Type and Status */
505 	u8 reason_code; /* Reason Code */
506 	u8 ctrl; /* NDL Control */
507 
508 	/* followed by optional fields based on ndl_ctrl */
509 	u8 optional[0];
510 } STRUCT_PACKED;
511 
512 /* Wi-Fi Aware spec v4.0, Table 130 (Element Container attribute format) */
513 #define NAN_ELEMENT_CONTAINER_MAP_ID_VALID_POS  0
514 #define NAN_ELEMENT_CONTAINER_MAP_ID_VALID_MASK BIT(0)
515 #define NAN_ELEMENT_CONTAINER_MAP_ID_POS        1
516 #define NAN_ELEMENT_CONTAINER_MAP_ID_MASK       (BIT(1) | BIT(2) | BIT(3) |\
517 						 BIT(4))
518 
519 struct ieee80211_elemc {
520 	u8 map_id; /* Map ID */
521 	u8 variable[0]; /* Elements */
522 } STRUCT_PACKED;
523 
524 /* Wi-Fi Aware spec v4.0, Table 108 (NDL QoS attribute format) */
525 struct ieee80211_nan_qos {
526 	u8 min_slots; /* Minimum time slots */
527 	le16 max_latency; /* Maximum latency */
528 } STRUCT_PACKED;
529 
530 #define NAN_QOS_MIN_SLOTS_NO_PREF   0
531 #define NAN_QOS_MAX_LATENCY_NO_PREF 0xffff
532 
533 #define NAN_AUTH_TOKEN_LEN 16
534 #define NAN_KEY_MIC_LEN    16
535 #define NAN_KEY_MIC_24_LEN 24
536 
537 /* Wi-Fi Aware spec v4.0, Table 121 (Cipher Suite attribute field format) */
538 enum nan_cipher_suite_id {
539 	NAN_CS_NONE         = 0,
540 	NAN_CS_SK_CCM_128   = 1,
541 	NAN_CS_SK_GCM_256   = 2,
542 	NAN_CS_PK_2WDH_128  = 3,
543 	NAN_CS_PK_2WDH_256  = 4,
544 	NAN_CS_GTK_CCMP_128 = 5,
545 	NAN_CS_GTK_GCMP_256 = 6,
546 	NAN_CS_PK_PASN_128  = 7,
547 	NAN_CS_PK_PASN_256  = 8,
548 	/* Keep last */
549 	NAN_CS_MAX
550 };
551 
552 /* Helper macros to check CSID properties */
553 #define NAN_CS_IS_128(csid) \
554 	((csid) == NAN_CS_SK_CCM_128 || (csid) == NAN_CS_PK_PASN_128)
555 #define NAN_CS_IS_256(csid) \
556 	((csid) == NAN_CS_SK_GCM_256 || (csid) == NAN_CS_PK_PASN_256)
557 #define NAN_CS_IS_VALID_NDP(csid) \
558 	(NAN_CS_IS_128(csid) || NAN_CS_IS_256(csid))
559 #define NAN_CS_IS_PASN(csid) \
560 	((csid) == NAN_CS_PK_PASN_128 || (csid) == NAN_CS_PK_PASN_256)
561 
562 struct nan_cipher_suite {
563 	u8 csid; /* Cipher Suite ID */
564 	u8 instance_id; /* Publish ID */
565 } STRUCT_PACKED;
566 
567 /* Wi-Fi Aware spec v4.0, Table 122 (Cipher Suite Information attribute (CSIA)
568  * field format) */
569 #define NAN_CS_INFO_CAPA_16_ND_TKSA_REPLAY_COUNTERS BIT(0)
570 #define NAN_CS_INFO_CAPA_GTK_SUPP_POS               1
571 #define NAN_CS_INFO_CAPA_GTK_SUPP_MASK              (BIT(1) | BIT(2))
572 #define NAN_CS_INFO_CAPA_GTK_SUPP_NONE              0
573 #define NAN_CS_INFO_CAPA_GTK_SUPP_NO_BIGTK          1
574 #define NAN_CS_INFO_CAPA_GTK_SUPP_ALL               2
575 #define NAN_CS_INFO_CAPA_16_REPLAY_COUNTERS         BIT(3)
576 #define NAN_CS_INFO_CAPA_IGTK_USE_NCS_BIP_GMAC_256  BIT(4)
577 
578 struct nan_cipher_suite_info {
579 	u8 capab; /* Capabilities */
580 	u8 cs[0]; /* Cipher Suite List */
581 } STRUCT_PACKED;
582 
583 /* Wi-Fi Aware spec v4.0, Table 123 (Security Context Identifier (SCID) field
584  * format) */
585 enum nan_sec_ctx_type {
586 	NAN_SEC_CTX_TYPE_ND_PMKID = 1,
587 };
588 
589 struct nan_sec_ctxt {
590 	le16 len; /* Security Context Identifier Type Length */
591 	u8 scid; /* Security Context Identifier Type */
592 	u8 instance_id; /* Publish ID */
593 	u8 ctxt[0]; /* Security Context Identifier */
594 } STRUCT_PACKED;
595 
596 /* Only key descriptor type 2 is supported */
597 #define NAN_KEY_DESC 2
598 
599 /* Wi-Fi Aware spec v4.0, Table 125 (NAN Shared Key Descriptor attribute field
600  * format) */
601 struct nan_shared_key {
602 	u8 publish_id; /* Publish ID */
603 
604 	/*
605 	 * The format of the key is as defined in the IEEE 802.11 standard,
606 	 * starting with the Descriptor Type field. See struct wpa_eapol_key.
607 	 */
608 	u8 key[0]; /* IEEE 802.11 RSNA Key Descriptor */
609 } STRUCT_PACKED;
610 
611 /* Wi-Fi Aware spec v4.0, Table 141 (Capability Info field) */
612 #define NAN_DEV_CAPA_EXT_INFO_0_REG_VALID         BIT(0)
613 #define NAN_DEV_CAPA_EXT_INFO_0_AP_TYPE_POS       1
614 #define NAN_DEV_CAPA_EXT_INFO_0_AP_TYPE_MASK      (BIT(1) | BIT(2) | BIT(3))
615 #define NAN_DEV_CAPA_EXT_INFO_INDOOR_AP           0
616 #define NAN_DEV_CAPA_EXT_INFO_SP_AP               1
617 #define NAN_DEV_CAPA_EXT_INFO_VLP_AP              2
618 #define NAN_DEV_CAPA_EXT_INFO_INDOOR_ENABLED_AP   3
619 #define NAN_DEV_CAPA_EXT_INFO_INDOOR_SP_AP        4
620 
621 #define NAN_DEV_CAPA_EXT_INFO_1_PAIRING_SETUP     BIT(0)
622 #define NAN_DEV_CAPA_EXT_INFO_1_NPK_NIK_CACHING   BIT(1)
623 
624 /* Wi-Fi Aware spec v4.0, Table 22 (NIRA Cryptographic Parameters and Methods)
625  */
626 #define NAN_NIRA_NONCE_LEN	8
627 #define NAN_NIRA_TAG_LEN	8
628 #define NAN_NIRA_STR		"NIR"
629 #define NAN_NIRA_STR_LEN	3
630 #define NAN_NIRA_CIPHER_VER_128	0
631 #define NAN_NIK_LEN		16
632 
633 #define NAN_PASN_SSID "516F9A010000"
634 
635 /* Wi-Fi Aware spec v4.0, Table 126 (NAN KDE field format) */
636 #define NAN_KEY_DATA_NIK RSN_SELECTOR(0x50, 0x6f, 0x9a, 36)
637 #define NAN_KEY_DATA_LIFETIME RSN_SELECTOR(0x50, 0x6f, 0x9a, 37)
638 
639 /* Wi-Fi Aware spec v4.0, Figure 61 (NIK KDE format)
640  * Note: The NIK field is defined with a variable length in Figure 61, but
641  * since only one cipher version is defined for now (which determines the
642  * length), use a fixed length here.
643  */
644 struct nan_nik_kde {
645 	u8 cipher_ver;
646 	u8 nik[NAN_NIK_LEN];
647 } STRUCT_PACKED;
648 
649 /* Wi-Fi Aware spec v4.0, Figure 63 (Key Bitmap format) */
650 #define NAN_KEY_LIFETIME_GTK    BIT(0)
651 #define NAN_KEY_LIFETIME_IGTK   BIT(1)
652 #define NAN_KEY_LIFETIME_BIGTK  BIT(2)
653 #define NAN_KEY_LIFETIME_NIK    BIT(3)
654 #define NAN_KEY_LIFETIME_ND_TK  BIT(4)
655 #define NAN_KEY_LIFETIME_NM_TK  BIT(5)
656 
657 /* Wi-Fi Aware spec v4.0, Figure 62 (NAN Key Lifetime KDE format) */
658 struct nan_key_lifetime_kde {
659 	le16 key_bitmap;
660 	be32 lifetime_sec;
661 } STRUCT_PACKED;
662 
663 #endif /* NAN_DEFS_H */
664