summaryrefslogtreecommitdiff
path: root/include/nan.h
blob: c8b345f442c622b0d6600f8b67584ddc127c1adb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
/*
 * Fundamental types and constants relating to WFA NAN
 * (Neighbor Awareness Networking)
 *
 * Copyright (C) 2024, Broadcom.
 *
 *      Unless you and Broadcom execute a separate written software license
 * agreement governing use of this software, this software is licensed to you
 * under the terms of the GNU General Public License version 2 (the "GPL"),
 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
 * following added to such license:
 *
 *      As a special exception, the copyright holders of this software give you
 * permission to link this software with independent modules, and to copy and
 * distribute the resulting executable under terms of your choice, provided that
 * you also meet, for each linked independent module, the terms and conditions of
 * the license of that module.  An independent module is a module which is not
 * derived from this software.  The special exception does not apply to any
 * modifications of the software.
 *
 *
 * <<Broadcom-WL-IPTag/Dual:>>
 */
#ifndef _NAN_H_
#define _NAN_H_

#include <typedefs.h>
#include <802.11.h>

/* Do we want to include p2p.h for constants like P2P_WFDS_HASH_LEN and
 * maybe P2P_WFDS_MAX_SVC_NAME_LEN etc.?
 */

/* This marks the start of a packed structure section. */
#include <packed_section_start.h>

/* WiFi NAN OUI values */
#define NAN_OUI			"\x50\x6F\x9A"     /* WFA OUI. WiFi-Alliance OUI */
#define NAN_OUI_LEN		3u		/* NAN OUI length */
/* For oui_type field identifying the type and version of the NAN IE. */
#define NAN_OUI_TYPE		0x13        /* Type/Version */
#define NAN_AF_OUI_TYPE		0x18        /* Type/Version */
/* IEEE 802.11 vendor specific information element. (Same as P2P_IE_ID.) */
#define NAN_IE_ID		0xdd

#define NAN_IDENTITY_KEY_LIFETIME_SECONDS	(24u*3600u) /* 24 hours. */

/* Default cipher version for pairing NIK KDE */
#define NAN_SEC_NIK_DEFAULT_CIPHER_VER	0

/* Same as P2P_PUB_AF_CATEGORY and DOT11_ACTION_CAT_PUBLIC */
#define NAN_PUB_AF_CATEGORY	DOT11_ACTION_CAT_PUBLIC
/* Protected dual public action frame category */
#define NAN_PROT_DUAL_PUB_AF_CATEGORY	DOT11_ACTION_CAT_PDPA
/* IEEE 802.11 Public Action Frame Vendor Specific. (Same as P2P_PUB_AF_ACTION.) */
#define NAN_PUB_AF_ACTION	DOT11_PUB_ACTION_VENDOR_SPEC
/* Number of octents in hash of service name. (Same as P2P_WFDS_HASH_LEN.) */
#define NAN_SVC_HASH_LEN	6
/* Size of fixed length part of nan_pub_act_frame_t before attributes. */
#define NAN_PUB_ACT_FRAME_FIXED_LEN 6
/* Number of octents in master rank value. */
#define NAN_MASTER_RANK_LEN     8
/* NAN public action frame header size */
#define NAN_PUB_ACT_FRAME_HDR_SIZE (OFFSETOF(nan_pub_act_frame_t, data))
/* NAN network ID */
#define NAN_NETWORK_ID		"\x51\x6F\x9A\x01\x00\x00"
/* Service Control Type length */
#define NAN_SVC_CONTROL_TYPE_LEN	2
/* Binding Bitmap length */
#define NAN_BINDING_BITMAP_LEN		2
/* Service Response Filter (SRF) control field masks */
#define NAN_SRF_BLOOM_MASK		0x01
#define NAN_SRF_INCLUDE_MASK		0x02
#define NAN_SRF_INDEX_MASK		0x0C
/* SRF Bloom Filter index shift */
#define NAN_SRF_BLOOM_SHIFT	2
#define NAN_SRF_INCLUDE_SHIFT	1
/* Mask for CRC32 output, used in hash function for NAN bloom filter */
#define NAN_BLOOM_CRC32_MASK	0xFFFF

/* Attribute TLV header size */
#define NAN_ATTR_ID_OFF		0
#define NAN_ATTR_LEN_OFF	1
#define NAN_ATTR_DATA_OFF	3

#define NAN_ATTR_ID_LEN		 1u	/* ID field length */
#define NAN_ATTR_LEN_LEN	 2u	/* Length field length */
#define NAN_ATTR_HDR_LEN	 (NAN_ATTR_ID_LEN + NAN_ATTR_LEN_LEN)
#define NAN_ENTRY_CTRL_LEN       1      /* Entry control field length from FAM attribute */
#define NAN_MAP_ID_LEN           1	/* MAP ID length to signify band */
#define NAN_OPERATING_CLASS_LEN  1	/* operating class field length from NAN FAM */
#define NAN_CHANNEL_NUM_LEN      1	/* channel number field length 1 byte */

/* generic nan attribute total length */
#define NAN_ATTR_TOT_LEN(_nan_attr)	(ltoh16_ua(((const uint8 *)(_nan_attr)) + \
	NAN_ATTR_ID_LEN) + NAN_ATTR_HDR_LEN)

/* NAN slot duration / period */
#define NAN_MIN_TU		16
#define NAN_TU_PER_DW		512
#define NAN_MAX_DW		16
#define NAN_MAX_TU		(NAN_MAX_DW * NAN_TU_PER_DW)

#define NAN_SLOT_DUR_0TU	0
#define NAN_SLOT_DUR_16TU	16
#define NAN_SLOT_DUR_32TU	32
#define NAN_SLOT_DUR_64TU	64
#define NAN_SLOT_DUR_128TU	128
#define NAN_SLOT_DUR_256TU	256
#define NAN_SLOT_DUR_512TU	512
#define NAN_SLOT_DUR_1024TU	1024
#define NAN_SLOT_DUR_2048TU	2048
#define NAN_SLOT_DUR_4096TU	4096
#define NAN_SLOT_DUR_8192TU	8192

#define NAN_SOC_CHAN_2G		6	/* NAN 2.4G discovery channel */
#define NAN_SOC_CHAN_5G_CH149	149	/* NAN 5G discovery channel if upper band allowed */
#define NAN_SOC_CHAN_5G_CH44	44	/* NAN 5G discovery channel if only lower band allowed */

/* size of ndc id */
#define NAN_DATA_NDC_ID_SIZE 6

#define NAN_AVAIL_ENTRY_LEN_RES0 7      /* Avail entry len in FAM attribute for resolution 16TU */
#define NAN_AVAIL_ENTRY_LEN_RES1 5      /* Avail entry len in FAM attribute for resolution 32TU */
#define NAN_AVAIL_ENTRY_LEN_RES2 4      /* Avail entry len in FAM attribute for resolution 64TU */

/* map id field */
#define NAN_MAPID_SPECIFIC_MAP_MASK	0x01 /* apply to specific map */
#define NAN_MAPID_MAPID_MASK		0x1E
#define NAN_MAPID_MAPID_SHIFT		1
#define NAN_MAPID_SPECIFIC_MAP(_mapid)	((_mapid) & NAN_MAPID_SPECIFIC_MAP_MASK)
#define NAN_MAPID_ALL_MAPS(_mapid)	(!NAN_MAPID_SPECIFIC_MAP(_mapid))
#define NAN_MAPID_MAPID(_mapid)		(((_mapid) & NAN_MAPID_MAPID_MASK) \
		>> NAN_MAPID_MAPID_SHIFT)
#define NAN_MAPID_SET_SPECIFIC_MAPID(map_id)	((((map_id) << NAN_MAPID_MAPID_SHIFT) \
		& NAN_MAPID_MAPID_MASK) | NAN_MAPID_SPECIFIC_MAP_MASK)

/* Vendor-specific public action frame for NAN */
typedef BWL_PRE_PACKED_STRUCT struct nan_pub_act_frame_s {
	/* NAN_PUB_AF_CATEGORY 0x04 */
	uint8 category_id;
	/* NAN_PUB_AF_ACTION 0x09 */
	uint8 action_field;
	/* NAN_OUI 0x50-6F-9A */
	uint8 oui[DOT11_OUI_LEN];
	/* NAN_OUI_TYPE 0x13 */
	uint8 oui_type;
	/* One or more NAN Attributes follow */
	uint8 data[];
} BWL_POST_PACKED_STRUCT nan_pub_act_frame_t;

/* NAN attributes as defined in the nan spec */
enum {
	NAN_ATTR_MASTER_IND	= 0,
	NAN_ATTR_CLUSTER	= 1,
	NAN_ATTR_SVC_ID_LIST    = 2,
	NAN_ATTR_SVC_DESCRIPTOR = 3,
	NAN_ATTR_CONN_CAP       = 4,
	NAN_ATTR_INFRA		= 5,
	NAN_ATTR_P2P		= 6,
	NAN_ATTR_IBSS		= 7,
	NAN_ATTR_MESH		= 8,
	NAN_ATTR_FURTHER_NAN_SD = 9,
	NAN_ATTR_FURTHER_AVAIL	= 10,
	NAN_ATTR_COUNTRY_CODE	= 11,
	NAN_ATTR_RANGING	= 12,
	NAN_ATTR_CLUSTER_DISC	= 13,

	/* nan 2.0 */
	NAN_ATTR_SVC_DESC_EXTENSION		= 14,
	NAN_ATTR_NAN_DEV_CAP			= 15,
	NAN_ATTR_NAN_NDP			= 16,
	NAN_ATTR_NAN_NMSG			= 17,
	NAN_ATTR_NAN_AVAIL			= 18,
	NAN_ATTR_NAN_NDC			= 19,
	NAN_ATTR_NAN_NDL			= 20,
	NAN_ATTR_NAN_NDL_QOS			= 21,
	NAN_ATTR_MCAST_SCHED			= 22,
	NAN_ATTR_UNALIGN_SCHED			= 23,
	NAN_ATTR_PAGING_UCAST			= 24,
	NAN_ATTR_PAGING_MCAST			= 25,
	NAN_ATTR_RANGING_INFO			= 26,
	NAN_ATTR_RANGING_SETUP			= 27,
	NAN_ATTR_FTM_RANGE_REPORT		= 28,
	NAN_ATTR_ELEMENT_CONTAINER		= 29,
	NAN_ATTR_WLAN_INFRA_EXT			= 30,
	NAN_ATTR_EXT_P2P_OPER			= 31,
	NAN_ATTR_EXT_IBSS			= 32,
	NAN_ATTR_EXT_MESH			= 33,
	NAN_ATTR_CIPHER_SUITE_INFO		= 34,
	NAN_ATTR_SEC_CTX_ID_INFO		= 35,
	NAN_ATTR_SHARED_KEY_DESC		= 36,
	NAN_ATTR_MCAST_SCHED_CHANGE		= 37,
	NAN_ATTR_MCAST_SCHED_OWNER_CHANGE	= 38,
	NAN_ATTR_PUBLIC_AVAILABILITY		= 39,
	NAN_ATTR_SUB_SVC_ID_LIST		= 40,
	NAN_ATTR_NDPE				= 41,
	NAN_ATTR_DEV_CAP_EXT			= 42, /* NAN R4, Device Capability Extension */
	NAN_ATTR_NIRA				= 43, /* NAN R4, Identity Resolution Attribute */
	NAN_ATTR_NPBA				= 44, /* NAN R4, Pairing Bootstrapping Attribute */
	NAN_ATTR_S3				= 45, /* NAN R4, Sub Slot Schedule (S3) attribute */

	/* change NAN_ATTR_MAX_ID to max ids + 1, excluding NAN_ATTR_VENDOR_SPECIFIC.
	 * This is used in nan_parse.c
	 */
	NAN_ATTR_MAX_ID		= NAN_ATTR_S3 + 1,

	NAN_ATTR_VENDOR_SPECIFIC = 221
};

enum wifi_nan_avail_resolution {
	NAN_AVAIL_RES_16_TU = 0,
	NAN_AVAIL_RES_32_TU = 1,
	NAN_AVAIL_RES_64_TU = 2,
	NAN_AVAIL_RES_INVALID = 255
};

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ie_s {
	uint8	id;		/* IE ID: NAN_IE_ID 0xDD */
	uint8	len;		/* IE length */
	uint8	oui[DOT11_OUI_LEN]; /* NAN_OUI 50:6F:9A */
	uint8	oui_type;	/* NAN_OUI_TYPE 0x13 */
	uint8	attr[];	/* var len attributes */
} BWL_POST_PACKED_STRUCT wifi_nan_ie_t;

#define NAN_IE_HDR_SIZE	(OFFSETOF(wifi_nan_ie_t, attr))

/* master indication record  */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_master_ind_attr_s {
	uint8	id;
	uint16	len;
	uint8	master_preference;
	uint8	random_factor;
} BWL_POST_PACKED_STRUCT wifi_nan_master_ind_attr_t;

/* cluster attr record  */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_cluster_attr_s {
	uint8	id;
	uint16	len;
	uint8   amr[NAN_MASTER_RANK_LEN];
	uint8   hop_count;
	/* Anchor Master Beacon Transmission Time */
	uint32  ambtt;
} BWL_POST_PACKED_STRUCT wifi_nan_cluster_attr_t;

/*  container for service ID records  */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_svc_id_attr_s {
	uint8	id;
	uint16	len;
	uint8	svcid[0]; /* 6*len of srvc IDs */
} BWL_POST_PACKED_STRUCT wifi_nan_svc_id_attr_t;

/* service_control bitmap for wifi_nan_svc_descriptor_attr_t below */
#define NAN_SC_PUBLISH 0x0
#define NAN_SC_SUBSCRIBE 0x1
#define NAN_SC_FOLLOWUP 0x2
/* Set to 1 if a Matching Filter field is included in descriptors. */
#define NAN_SC_MATCHING_FILTER_PRESENT 0x4
/* Set to 1 if a Service Response Filter field is included in descriptors. */
#define NAN_SC_SR_FILTER_PRESENT 0x8
/* Set to 1 if a Service Info field is included in descriptors. */
#define NAN_SC_SVC_INFO_PRESENT 0x10
/* range is close proximity only */
#define NAN_SC_RANGE_LIMITED 0x20
/* Set to 1 if binding bitamp is present in descriptors */
#define NAN_SC_BINDING_BITMAP_PRESENT 0x40
/* Max olength used for KDK in NAN R4 */
#define NAN_SEC_MAX_KDK_LEN		32u


/* Service descriptor */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_svc_descriptor_attr_s {
	/* Attribute ID - 0x03. */
	uint8 id;
	/* Length of the following fields in the attribute */
	uint16 len;
	/* Hash of the Service Name */
	uint8 svc_hash[NAN_SVC_HASH_LEN];
	/* Publish or subscribe instance id */
	uint8 instance_id;
	/* Requestor Instance ID */
	uint8 requestor_id;
	/* Service Control Bitmask. Also determines what data follows. */
	uint8 svc_control;
	/* Optional fields follow */
} BWL_POST_PACKED_STRUCT wifi_nan_svc_descriptor_attr_t;

#define NAN_SVC_INFO_TYPE_RSVD		0u
#define NAN_SVC_INFO_TYPE_BONJOUR	1u
#define NAN_SVC_INFO_TYPE_GENERIC	2u

/* Service info field */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_svc_info_field_s {
	uint8 oui[DOT11_OUI_LEN];	/* 0x50-6F-9A */
	uint8 svc_protocol;
	uint8 svc_spec_info[];
} BWL_POST_PACKED_STRUCT wifi_nan_svc_info_field_t;

/* IBSS attribute */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ibss_attr_s {
	/* Attribute ID - 0x07. */
	uint8 id;
	/* Length of the following fields in the attribute */
	uint16 len;
	/* BSSID of the ibss */
	struct ether_addr bssid;
	/*
	 map control:, bits:
	[0-3]: Id for associated further avail map attribute
	[4-5]: avail interval duration: 0:16ms; 1:32ms; 2:64ms; 3:reserved
	[6] : repeat : 0 - applies to next DW, 1: 16 intervals max? wtf?
	[7] : reserved
	*/
	uint8 map_ctrl;
	/* avail. intervals bitmap, var len  */
	uint8 avail_bmp[BCM_FLEX_ARRAY];
} BWL_POST_PACKED_STRUCT wifi_nan_ibss_attr_t;

/* Country code attribute  */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_country_code_attr_s {
	/* Attribute ID - 0x0B. */
	uint8 id;
	/* Length of the following fields in the attribute */
	uint16 len;
	/* Condensed Country String first two octets */
	uint8 country_str[2];
} BWL_POST_PACKED_STRUCT wifi_nan_country_code_attr_t;

/* Further Availability MAP attr  */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_favail_attr_s {
	/* Attribute ID - 0x0A. */
	uint8 id;
	/* Length of the following fields in the attribute */
	uint16 len;
	/* MAP id: val [0..15], values[16-255] reserved */
	uint8 map_id;
	/*  availibility entry, var len */
	uint8 avil_entry[BCM_FLEX_ARRAY];
} BWL_POST_PACKED_STRUCT wifi_nan_favail_attr_t;

/* Further Availability MAP attr  */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_avail_entry_s {
	/*
	 entry control
	 [0-1]: avail interval duration: 0:16ms; 1:32ms; 2:64ms;
	 [2:7] reserved
	*/
	uint8 entry_ctrl;
	/* operating class: freq band etc IEEE 802.11 */
	uint8 opclass;
	/* channel number */
	uint8 chan;
	/*  avail bmp, var len */
	uint8 avail_bmp[BCM_FLEX_ARRAY];
} BWL_POST_PACKED_STRUCT wifi_nan_avail_entry_t;

/* Map control Field */
#define NAN_MAPCTRL_IDMASK	0x7
#define NAN_MAPCTRL_DURSHIFT	4
#define NAN_MAPCTRL_DURMASK	0x30
#define NAN_MAPCTRL_REPEAT	0x40
#define NAN_MAPCTRL_REPEATSHIFT	6

#define NAN_VENDOR_TYPE_RTT	0
#define NAN_VENDOR_TYPE_P2P	1

/* Vendor Specific Attribute - old definition */
/* TODO remove */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_vendor_attr_s {
	uint8	id;			/* 0xDD */
	uint16	len;			/* IE length */
	uint8	oui[DOT11_OUI_LEN]; 	/* 00-90-4C */
	uint8	type;			/* attribute type */
	uint8	attr[BCM_FLEX_ARRAY];	/* var len attributes */
} BWL_POST_PACKED_STRUCT wifi_nan_vendor_attr_t;

#define NAN_VENDOR_HDR_SIZE	(OFFSETOF(wifi_nan_vendor_attr_t, attr))

/* vendor specific attribute */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_vndr_attr_s {
	uint8	id;			/* 0xDD */
	uint16	len;			/* length of following fields */
	uint8	oui[DOT11_OUI_LEN];	/* vendor specific OUI */
	uint8	body[];
} BWL_POST_PACKED_STRUCT wifi_nan_vndr_attr_t;

/* p2p operation attribute */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_p2p_op_attr_s {
	/* Attribute ID - 0x06. */
	uint8 id;
	/* Length of the following fields in the attribute */
	uint16 len;
	/* P2P device role */
	uint8 dev_role;
	/* BSSID of the ibss */
	struct ether_addr p2p_dev_addr;
	/*
	map control:, bits:
	[0-3]: Id for associated further avail map attribute
	[4-5]: avail interval duration: 0:16ms; 1:32ms; 2:64ms; 3:reserved
	[6] : repeat : 0 - applies to next DW, 1: 16 intervals max? wtf?
	[7] : reserved
	*/
	uint8 map_ctrl;
	/* avail. intervals bitmap */
	uint8 avail_bmp[BCM_FLEX_ARRAY];
} BWL_POST_PACKED_STRUCT wifi_nan_p2p_op_attr_t;

/* ranging attribute */
#define NAN_RANGING_MAP_CTRL_ID_SHIFT 0
#define NAN_RANGING_MAP_CTRL_ID_MASK 0x0F
#define NAN_RANGING_MAP_CTRL_DUR_SHIFT 4
#define NAN_RANGING_MAP_CTRL_DUR_MASK 0x30
#define NAN_RANGING_MAP_CTRL_REPEAT_SHIFT 6
#define NAN_RANGING_MAP_CTRL_REPEAT_MASK 0x40
#define NAN_RANGING_MAP_CTRL_REPEAT_DW(_ctrl) (((_ctrl) & \
	NAN_RANGING_MAP_CTRL_DUR_MASK) ? 16 : 1)
#define NAN_RANGING_MAP_CTRL(_id, _dur, _repeat) (\
	(((_id) << NAN_RANGING_MAP_CTRL_ID_SHIFT) & \
		 NAN_RANGING_MAP_CTRL_ID_MASK) | \
	(((_dur) << NAN_RANGING_MAP_CTRL_DUR_SHIFT) & \
		NAN_RANGING_MAP_CTRL_DUR_MASK) | \
	(((_repeat) << NAN_RANGING_MAP_CTRL_REPEAT_SHIFT) & \
		 NAN_RANGING_MAP_CTRL_REPEAT_MASK))

enum {
	NAN_RANGING_PROTO_FTM = 0
};

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ranging_attr_s {
	uint8 id;			/* 0x0C */
	uint16 len;			/* length that follows */
	struct ether_addr dev_addr;	/* device mac address */

	/*
	map control:, bits:
	[0-3]: Id for associated further avail map attribute
	[4-5]: avail interval duration: 0:16ms; 1:32ms; 2:64ms; 3:reserved
	[6] : repeat : 0 - applies to next DW, 1: 16 intervals max? wtf?
	[7] : reserved
	*/
	uint8 map_ctrl;

	uint8 protocol;					/* FTM = 0 */
	uint32 avail_bmp;				/* avail interval bitmap */
} BWL_POST_PACKED_STRUCT wifi_nan_ranging_attr_t;

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ranging_info_attr_s {
	uint8 id;			/* 0x1A */
	uint16 len;			/* length that follows */
	/*
	location info availability bit map
	0: LCI Local Coordinates
	1: Geospatial LCI WGS84
	2: Civi Location
	3: Last Movement Indication
	[4-7]: reserved
	*/
	uint8 lc_info_avail;
	/*
	Last movement indication
	present if bit 3 is set in lc_info_avail
	cluster TSF[29:14] at the last detected platform movement
	*/
	uint16 last_movement;

} BWL_POST_PACKED_STRUCT wifi_nan_ranging_info_attr_t;

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ranging_setup_attr_hdr_s {
	uint8 id;			/* 0x1B */
	uint16 len;			/* length that follows */
	uint8 dialog_token;	/* Identify req and resp */
	uint8 type_status;	/* bits 0-3 type, 4-7 status */
	/* reason code
	i. when frm type = response & status = reject
	ii. frm type = termination
	*/
	uint8 reason;
} BWL_POST_PACKED_STRUCT wifi_nan_ranging_setup_attr_hdr_t;

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ranging_setup_attr_s {

	wifi_nan_ranging_setup_attr_hdr_t setup_attr_hdr;
	/* Below fields not required when frm type = termination */
	uint8 ranging_ctrl; /* Bit 0: ranging report required or not */
	uint8 ftm_params[3];
	uint8 data[];	/* schedule entry list */
} BWL_POST_PACKED_STRUCT wifi_nan_ranging_setup_attr_t;

#define NAN_RANGE_SETUP_ATTR_OFFSET_TBM_INFO (OFFSETOF(wifi_nan_ranging_setup_attr_t, data))

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ranging_report_attr_s {
	uint8 id;			/* 0x1C */
	uint16 len;			/* length that follows */
	/* FTM report format in spec.
	See definition in 9.4.2.22.18 in 802.11mc D5.0
	*/
	uint8 entry_count;
	uint8 data[]; /* Variable size range entry */
	/*
	dot11_ftm_range_entry_t entries[entry_count];
	uint8 error_count;
	dot11_ftm_error_entry_t errors[error_count];
	 */
} BWL_POST_PACKED_STRUCT wifi_nan_ranging_report_attr_t;

/* Ranging control flags */
#define NAN_RNG_REPORT_REQUIRED		0x01
#define NAN_RNG_FTM_PARAMS_PRESENT	0x02
#define NAN_RNG_SCHED_ENTRY_PRESENT	0X04

/* Location info flags */
#define NAN_RNG_LOCATION_FLAGS_LOCAL_CORD		0x1
#define NAN_RNG_LOCATION_FLAGS_GEO_SPATIAL		0x2
#define NAN_RNG_LOCATION_FLAGS_CIVIC			0x4
#define NAN_RNG_LOCATION_FLAGS_LAST_MVMT		0x8

/* Last movement mask and shift value */
#define NAN_RNG_LOCATION_MASK_LAST_MVT_TSF	0x3FFFC000
#define NAN_RNG_LOCATION_SHIFT_LAST_MVT_TSF	14

/* FTM params shift values  */
#define NAN_FTM_MAX_BURST_DUR_SHIFT	0
#define NAN_FTM_MIN_FTM_DELTA_SHIFT	4
#define NAN_FTM_NUM_FTM_SHIFT		10
#define NAN_FTM_FORMAT_BW_SHIFT		15

/* FTM params mask  */
#define NAN_FTM_MAX_BURST_DUR_MASK	0x00000F
#define NAN_FTM_MIN_FTM_DELTA_MASK	0x00003F
#define NAN_FTM_NUM_FTM_MASK		0x00001F
#define NAN_FTM_FORMAT_BW_MASK		0x00003F

#define FTM_PARAMS_BURSTTMO_FACTOR 250

/* set to value to uint32 */
#define NAN_FTM_SET_BURST_DUR(ftm, dur) (ftm |= (((dur + 2) & NAN_FTM_MAX_BURST_DUR_MASK) <<\
	NAN_FTM_MAX_BURST_DUR_SHIFT))
#define NAN_FTM_SET_FTM_DELTA(ftm, delta) (ftm |= (((delta/100) & NAN_FTM_MIN_FTM_DELTA_MASK) <<\
	NAN_FTM_MIN_FTM_DELTA_SHIFT))
#define NAN_FTM_SET_NUM_FTM(ftm, delta) (ftm |= ((delta & NAN_FTM_NUM_FTM_MASK) <<\
	NAN_FTM_NUM_FTM_SHIFT))
#define NAN_FTM_SET_FORMAT_BW(ftm, delta) (ftm |= ((delta & NAN_FTM_FORMAT_BW_MASK) <<\
	NAN_FTM_FORMAT_BW_SHIFT))
/* set uint32 to attribute */
#define NAN_FTM_PARAMS_UINT32_TO_ATTR(ftm_u32, ftm_attr) {ftm_attr[0] = ftm_u32 & 0xFF; \
			ftm_attr[1] = (ftm_u32 >> 8) & 0xFF; ftm_attr[2] = (ftm_u32 >> 16) & 0xFF;}

/* get atrribute to uint32 */
#define NAN_FTM_PARAMS_ATTR_TO_UINT32(ftm_p, ftm_u32) (ftm_u32 = ftm_p[0] | ftm_p[1] << 8 | \
	ftm_p[2] << 16)
/* get param values from uint32 */
#define NAN_FTM_GET_BURST_DUR(ftm) (((ftm >> NAN_FTM_MAX_BURST_DUR_SHIFT) &\
	NAN_FTM_MAX_BURST_DUR_MASK))
#define NAN_FTM_GET_BURST_DUR_USEC(_val) ((1 << ((_val)-2)) * FTM_PARAMS_BURSTTMO_FACTOR)
#define NAN_FTM_GET_FTM_DELTA(ftm) (((ftm >> NAN_FTM_MIN_FTM_DELTA_SHIFT) &\
	NAN_FTM_MIN_FTM_DELTA_MASK)*100)
#define NAN_FTM_GET_NUM_FTM(ftm) ((ftm >> NAN_FTM_NUM_FTM_SHIFT) &\
	NAN_FTM_NUM_FTM_MASK)
#define NAN_FTM_GET_FORMAT_BW(ftm) ((ftm >> NAN_FTM_FORMAT_BW_SHIFT) &\
	NAN_FTM_FORMAT_BW_MASK)

#define NAN_CONN_CAPABILITY_WFD		0x0001
#define NAN_CONN_CAPABILITY_WFDS	0x0002
#define NAN_CONN_CAPABILITY_TDLS	0x0004
#define NAN_CONN_CAPABILITY_INFRA	0x0008
#define NAN_CONN_CAPABILITY_IBSS	0x0010
#define NAN_CONN_CAPABILITY_MESH	0x0020

#define NAN_DEFAULT_MAP_ID		0	/* nan default map id */
#define NAN_DEFAULT_MAP_CTRL		0	/* nan default map control */

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_conn_cap_attr_s {
	/* Attribute ID - 0x04. */
	uint8 id;
	/* Length of the following fields in the attribute */
	uint16	len;
	uint16	conn_cap_bmp;	/* Connection capability bitmap */
} BWL_POST_PACKED_STRUCT wifi_nan_conn_cap_attr_t;

/* NAN Element container Attribute */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_container_attr_s {
	uint8 id;	/* id - 0x20 */
	uint16 len;	/* Total length of following IEs */
	uint8 map_id;	/* map id */
	uint8 data[BCM_FLEX_ARRAY];	/* Data pointing to one or more IEs */
} BWL_POST_PACKED_STRUCT wifi_nan_container_attr_t;

/* NAN 2.0 NAN avail attribute */

/* Availability Attribute */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_avail_attr_s {
	uint8 id;	/* id - 0x12 */
	uint16 len;	/* total length */
	uint8 seqid;	/* sequence id */
	uint16 ctrl;	/* attribute control */
	uint8 entry[BCM_FLEX_ARRAY];	/* availability entry list */
} BWL_POST_PACKED_STRUCT wifi_nan_avail_attr_t;

/* for processing/building time bitmap info in nan_avail_entry */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_time_bitmap_s {
	uint16 ctrl;		/* Time bitmap control */
	uint8 len;		/* Time bitmap length */
	uint8 bitmap[];	/* Time bitmap */
} BWL_POST_PACKED_STRUCT wifi_nan_time_bitmap_t;

/* Availability Entry format */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_avail_entry_attr_s {
	uint16 len;		/* Length */
	uint16 entry_cntrl;	/* Entry Control */
	uint8 var[];		/* Time bitmap and channel entry list */
} BWL_POST_PACKED_STRUCT wifi_nan_avail_entry_attr_t;

/* FAC Channel Entry  (section 10.7.19.1.5) */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_chan_entry_s {
	uint8 oper_class;		/* Operating Class */
	uint16 chan_bitmap;		/* Channel Bitmap */
	uint8 primary_chan_bmp;		/* Primary Channel Bitmap */
	uint8 aux_chan[0];			/* Auxiliary Channel bitmap */
} BWL_POST_PACKED_STRUCT wifi_nan_chan_entry_t;

/* Channel entry */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_channel_entry_s {
	uint8 opclass;		/* Operating class */
	uint16 chan_bitmap;	/* Channel bitmap */
	uint8 prim_bitmap;	/* Primary channel bitmap */
	uint16 aux_bitmap;	/* Time bitmap length */
} BWL_POST_PACKED_STRUCT wifi_nan_channel_entry_t;

/* Type of  Availability: committed */
#define NAN_ENTRY_CNTRL_TYPE_COMM_AVAIL_MASK	0x1
/* Type of  Availability: potential */
#define NAN_ENTRY_CNTRL_TYPE_POTEN_AVAIL_MASK	0x2
/* Type of  Availability: conditional */
#define NAN_ENTRY_CNTRL_TYPE_COND_AVAIL_MASK	0x4

#define NAN_AVAIL_CTRL_MAP_ID_MASK		0x000F
#define NAN_AVAIL_CTRL_MAP_ID(_ctrl)		((_ctrl) & NAN_AVAIL_CTRL_MAP_ID_MASK)
#define NAN_AVAIL_CTRL_COMM_CHANGED_MASK	0x0010
#define NAN_AVAIL_CTRL_COMM_CHANGED(_ctrl)	((_ctrl) & NAN_AVAIL_CTRL_COMM_CHANGED_MASK)
#define NAN_AVAIL_CTRL_POTEN_CHANGED_MASK	0x0020
#define NAN_AVAIL_CTRL_POTEN_CHANGED(_ctrl)	((_ctrl) & NAN_AVAIL_CTRL_POTEN_CHANGED_MASK)
#define NAN_AVAIL_CTRL_PUBLIC_CHANGED_MASK	0x0040
#define NAN_AVAIL_CTRL_PUBLIC_CHANGED(_ctrl)	((_ctrl) & NAN_AVAIL_CTRL_PUBLIC_CHANGED_MASK)
#define NAN_AVAIL_CTRL_NDC_CHANGED_MASK		0x0080
#define NAN_AVAIL_CTRL_NDC_CHANGED(_ctrl)	((_ctrl) & NAN_AVAIL_CTRL_NDC_CHANGED_MASK)
#define NAN_AVAIL_CTRL_MCAST_CHANGED_MASK	0x0100
#define NAN_AVAIL_CTRL_MCAST_CHANGED(_ctrl)	((_ctrl) & NAN_AVAIL_CTRL_MCAST_CHANGED_MASK)
#define NAN_AVAIL_CTRL_MCAST_CHG_CHANGED_MASK	0x0200
#define NAN_AVAIL_CTRL_MCAST_CHG_CHANGED(_ctrl)	((_ctrl) & NAN_AVAIL_CTRL_MCAST_CHG_CHANGED_MASK)
#define NAN_AVAIL_CTRL_CHANGED_FLAGS_MASK	0x03f0

#define NAN_AVAIL_ENTRY_CTRL_AVAIL_TYPE_MASK 0x07
#define NAN_AVAIL_ENTRY_CTRL_AVAIL_TYPE(_flags) ((_flags) & NAN_AVAIL_ENTRY_CTRL_AVAIL_TYPE_MASK)
#define NAN_AVAIL_ENTRY_CTRL_USAGE_MASK 0x18
#define NAN_AVAIL_ENTRY_CTRL_USAGE_SHIFT 3
#define NAN_AVAIL_ENTRY_CTRL_USAGE(_flags) (((_flags) & NAN_AVAIL_ENTRY_CTRL_USAGE_MASK) \
	>> NAN_AVAIL_ENTRY_CTRL_USAGE_SHIFT)
#define NAN_AVAIL_ENTRY_CTRL_UTIL_MASK 0xE0
#define NAN_AVAIL_ENTRY_CTRL_UTIL_SHIFT 5
#define NAN_AVAIL_ENTRY_CTRL_UTIL(_flags) (((_flags) & NAN_AVAIL_ENTRY_CTRL_UTIL_MASK) \
	>> NAN_AVAIL_ENTRY_CTRL_UTIL_SHIFT)
#define NAN_AVAIL_ENTRY_CTRL_RX_NSS_MASK 0xF00
#define NAN_AVAIL_ENTRY_CTRL_RX_NSS_SHIFT 8
#define NAN_AVAIL_ENTRY_CTRL_RX_NSS(_flags) (((_flags) & NAN_AVAIL_ENTRY_CTRL_RX_NSS_MASK) \
	>> NAN_AVAIL_ENTRY_CTRL_RX_NSS_SHIFT)
#define NAN_AVAIL_ENTRY_CTRL_BITMAP_PRESENT_MASK 0x1000
#define NAN_AVAIL_ENTRY_CTRL_BITMAP_PRESENT_SHIFT 12
#define NAN_AVAIL_ENTRY_CTRL_BITMAP_PRESENT(_flags) (((_flags) & \
	NAN_AVAIL_ENTRY_CTRL_BITMAP_PRESENT_MASK) >> NAN_AVAIL_ENTRY_CTRL_BITMAP_PRESENT_SHIFT)
#define NAN_AVAIL_ENTRY_CTRL_TIME_BITMAP_PRESENT    1
#define NAN_AVAIL_ENTRY_CTRL_USAGE_PREFERENCE	    0x3

#define NAN_TIME_BMAP_CTRL_BITDUR_MASK 0x07
#define NAN_TIME_BMAP_CTRL_BITDUR(_flags) ((_flags) & NAN_TIME_BMAP_CTRL_BITDUR_MASK)
#define NAN_TIME_BMAP_CTRL_PERIOD_MASK 0x38
#define NAN_TIME_BMAP_CTRL_PERIOD_SHIFT 3
#define NAN_TIME_BMAP_CTRL_PERIOD(_flags) (((_flags) & NAN_TIME_BMAP_CTRL_PERIOD_MASK) \
	>> NAN_TIME_BMAP_CTRL_PERIOD_SHIFT)
#define NAN_TIME_BMAP_CTRL_OFFSET_MASK 0x7FC0
#define NAN_TIME_BMAP_CTRL_OFFSET_SHIFT 6
#define NAN_TIME_BMAP_CTRL_OFFSET(_flags) (((_flags) & NAN_TIME_BMAP_CTRL_OFFSET_MASK) \
	>> NAN_TIME_BMAP_CTRL_OFFSET_SHIFT)
#define NAN_TIME_BMAP_LEN(avail_entry)	\
	(*(uint8 *)(((wifi_nan_avail_entry_attr_t *)avail_entry)->var + 2))

#define NAN_AVAIL_CHAN_LIST_HDR_LEN 1
#define NAN_AVAIL_CHAN_LIST_TYPE_BAND		0x00
#define NAN_AVAIL_CHAN_LIST_TYPE_CHANNEL	0x01
#define NAN_AVAIL_CHAN_LIST_NON_CONTIG_BW	0x02
#define NAN_AVAIL_CHAN_LIST_NUM_ENTRIES_MASK	0xF0
#define NAN_AVAIL_CHAN_LIST_NUM_ENTRIES_SHIFT	4
#define NAN_AVAIL_CHAN_LIST_NUM_ENTRIES(_ctrl) (((_ctrl) & NAN_AVAIL_CHAN_LIST_NUM_ENTRIES_MASK) \
	>> NAN_AVAIL_CHAN_LIST_NUM_ENTRIES_SHIFT)

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_channel_entry_list_s {
	uint8 chan_info;
	uint8 var[];
} BWL_POST_PACKED_STRUCT wifi_nan_channel_entry_list_t;

/* define for chan_info */
#define NAN_CHAN_OP_CLASS_MASK 0x01
#define NAN_CHAN_NON_CONT_BW_MASK 0x02
#define NAN_CHAN_RSVD_MASK 0x03
#define NAN_CHAN_NUM_ENTRIES_MASK 0xF0

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_band_entry_s {
	uint8 band[1];
} BWL_POST_PACKED_STRUCT wifi_nan_band_entry_t;

/* Type of  Availability: committed */
#define NAN_ENTRY_CNTRL_TYPE_COMM_AVAIL	        0x1
/* Type of  Availability: potential */
#define NAN_ENTRY_CNTRL_TYPE_POTEN_AVAIL	0x2
/* Type of  Availability: conditional */
#define NAN_ENTRY_CNTRL_TYPE_COND_AVAIL	        0x4
/* Committed + Potential */
#define NAN_ENTRY_CNTRL_TYPE_COMM_POTEN \
	(NAN_ENTRY_CNTRL_TYPE_COMM_AVAIL | NAN_ENTRY_CNTRL_TYPE_POTEN_AVAIL)
/* Conditional + Potential */
#define NAN_ENTRY_CNTRL_TYPE_COND_POTEN \
	(NAN_ENTRY_CNTRL_TYPE_COND_AVAIL | NAN_ENTRY_CNTRL_TYPE_POTEN_AVAIL)

/* Type of  Availability */
#define NAN_ENTRY_CNTRL_TYPE_OF_AVAIL_MASK	0x07
#define NAN_ENTRY_CNTRL_TYPE_OF_AVAIL_SHIFT	0
/* Usage Preference */
#define NAN_ENTRY_CNTRL_USAGE_PREF_MASK		0x18
#define NAN_ENTRY_CNTRL_USAGE_PREF_SHIFT	3
/* Utilization */
#define NAN_ENTRY_CNTRL_UTIL_MASK		0x1E0
#define NAN_ENTRY_CNTRL_UTIL_SHIFT		5

/* Time Bitmap Control field (section 5.7.18.2.3) */

/* Reserved */
#define NAN_TIME_BMP_CNTRL_RSVD_MASK	0x01
#define NAN_TIME_BMP_CNTRL_RSVD_SHIFT	0
/* Bitmap Len */
#define NAN_TIME_BMP_CNTRL_BMP_LEN_MASK	0x7E
#define NAN_TIME_BMP_CNTRL_BMP_LEN_SHIFT 1
/* Bit Duration */
#define NAN_TIME_BMP_CNTRL_BIT_DUR_MASK	0x380
#define NAN_TIME_BMP_CNTRL_BIT_DUR_SHIFT	7
/* Bitmap Len */
#define NAN_TIME_BMP_CNTRL_PERIOD_MASK	0x1C00
#define NAN_TIME_BMP_CNTRL_PERIOD_SHIFT	10
/* Start Offset */
#define NAN_TIME_BMP_CNTRL_START_OFFSET_MASK	0x3FE000
#define NAN_TIME_BMP_CNTRL_START_OFFSET_SHIFT	13
/* Reserved */
#define NAN_TIME_BMP_CNTRL_RESERVED_MASK	0xC00000
#define NAN_TIME_BMP_CNTRL_RESERVED_SHIFT	22

/* Time Bitmap Control field: Period */
typedef enum
{
	NAN_TIME_BMP_CTRL_PERIOD_128TU = 1,
	NAN_TIME_BMP_CTRL_PERIOD_256TU = 2,
	NAN_TIME_BMP_CTRL_PERIOD_512TU = 3,
	NAN_TIME_BMP_CTRL_PERIOD_1024TU = 4,
	NAN_TIME_BMP_CTRL_PERIOD_2048U = 5,
	NAN_TIME_BMP_CTRL_PERIOD_4096U = 6,
	NAN_TIME_BMP_CTRL_PERIOD_8192U = 7
} nan_time_bmp_ctrl_repeat_interval_t;

enum
{
	NAN_TIME_BMP_BIT_DUR_16TU_IDX = 0,
	NAN_TIME_BMP_BIT_DUR_32TU_IDX = 1,
	NAN_TIME_BMP_BIT_DUR_64TU_IDX = 2,
	NAN_TIME_BMP_BIT_DUR_128TU_IDX = 3
};

enum
{
	NAN_TIME_BMP_BIT_DUR_IDX_0 = 16,
	NAN_TIME_BMP_BIT_DUR_IDX_1 = 32,
	NAN_TIME_BMP_BIT_DUR_IDX_2 = 64,
	NAN_TIME_BMP_BIT_DUR_IDX_3 = 128
};

enum
{
	NAN_TIME_BMP_CTRL_PERIOD_IDX_1 = 128,
	NAN_TIME_BMP_CTRL_PERIOD_IDX_2 = 256,
	NAN_TIME_BMP_CTRL_PERIOD_IDX_3 = 512,
	NAN_TIME_BMP_CTRL_PERIOD_IDX_4 = 1024,
	NAN_TIME_BMP_CTRL_PERIOD_IDX_5 = 2048,
	NAN_TIME_BMP_CTRL_PERIOD_IDX_6 = 4096,
	NAN_TIME_BMP_CTRL_PERIOD_IDX_7 = 8192
};

/* Channel Entries List field */

/* Type */
#define NAN_CHAN_ENTRY_TYPE_MASK	0x01
#define NAN_CHAN_ENTRY_TYPE_SHIFT	0
/* Channel Entry Length Indication */
#define NAN_CHAN_ENTRY_LEN_IND_MASK	0x02
#define NAN_CHAN_ENTRY_LEN_IND_SHIFT	1
/* Reserved */
#define NAN_CHAN_ENTRY_RESERVED_MASK	0x0C
#define NAN_CHAN_ENTRY_RESERVED_SHIFT	2
/* Number of FAC Band or Channel Entries  */
#define NAN_CHAN_ENTRY_NO_OF_CHAN_ENTRY_MASK	0xF0
#define NAN_CHAN_ENTRY_NO_OF_CHAN_ENTRY_SHIFT	4

#define NAN_CHAN_ENTRY_TYPE_BANDS	0
#define NAN_CHAN_ENTRY_TYPE_OPCLASS_CHANS	1

#define NAN_CHAN_ENTRY_BW_LT_80MHZ	0
#define NAN_CHAN_ENTRY_BW_EQ_160MHZ	1

/* Channel bitmap field for when opclass >=131 */
#define NAN_CHAN_BITMAP_EXT_START_CHANNEL_MASK	0x00FF
#define NAN_CHAN_BITMAP_EXT_START_CHANNEL_SHIFT	0
#define NAN_CHAN_BITMAP_EXT_NUM_CHANNEL_MASK	0xFF00
#define NAN_CHAN_BITMAP_EXT_NUM_CHANNEL_SHIFT	8
#define NAN_CHAN_BITMAP_EXT_NUM_CHANNEL(bmap)	(((bmap) & NAN_CHAN_BITMAP_EXT_NUM_CHANNEL_MASK) \
		>> NAN_CHAN_BITMAP_EXT_NUM_CHANNEL_SHIFT)
#define NAN_CHAN_BITMAP_EXT_START_CHANNEL(bmap)	(((bmap) & NAN_CHAN_BITMAP_EXT_START_CHANNEL_MASK) \
		>> NAN_CHAN_BITMAP_EXT_START_CHANNEL_SHIFT)

/*
 * NDL Attribute WFA Tech. Spec ver 1.0.r12 (section 10.7.19.2)
 */
#define NDL_ATTR_IM_MAP_ID_LEN		1
#define NDL_ATTR_IM_TIME_BMP_CTRL_LEN	2
#define NDL_ATTR_IM_TIME_BMP_LEN_LEN	1

/*
 * NDL Control field - Table xx
 */
#define NDL_ATTR_CTRL_PEER_ID_PRESENT_MASK		0x01
#define NDL_ATTR_CTRL_PEER_ID_PRESENT_SHIFT		0
#define NDL_ATTR_CTRL_IM_SCHED_PRESENT_MASK		0x02
#define NDL_ATTR_CTRL_IM_SCHED_PRESENT_SHIFT	1
#define NDL_ATTR_CTRL_NDC_ATTR_PRESENT_MASK		0x04
#define NDL_ATTR_CTRL_NDC_ATTR_PRESENT_SHIFT	2
#define NDL_ATTR_CTRL_QOS_ATTR_PRESENT_MASK		0x08
#define NDL_ATTR_CTRL_QOS_ATTR_PRESENT_SHIFT	3
#define NDL_ATTR_CTRL_MAX_IDLE_PER_PRESENT_MASK		0x10	/* max idle period */
#define NDL_ATTR_CTRL_MAX_IDLE_PER_PRESENT_SHIFT	4
#define NDL_ATTR_CTRL_NDL_TYPE_MASK				0x20	/* NDL type */
#define NDL_ATTR_CTRL_NDL_TYPE_SHIFT			5
#define NDL_ATTR_CTRL_NDL_SETUP_REASON_MASK		0xC0	/* NDL Setup Reason */
#define NDL_ATTR_CTRL_NDL_SETUP_REASON_SHIFT	6

/* NDL setup Reason */
#define NDL_ATTR_CTRL_NDL_TYPE_S_NDL	0x0	/* S-NDL */
#define NDL_ATTR_CTRL_NDL_TYPE_P_NDL	0x1	/* P-NDL */

/* NDL setup Reason */
#define NDL_ATTR_CTRL_NDL_SETUP_REASON_NDP_RANG	0x0	/* NDP or Ranging */
#define NDL_ATTR_CTRL_NDL_SETUP_REASON_FSD_GAS	0x1	/* FSD using GAS */

#define NAN_NDL_TYPE_MASK				0x0F
#define NDL_ATTR_TYPE_STATUS_REQUEST	0x00
#define NDL_ATTR_TYPE_STATUS_RESPONSE	0x01
#define NDL_ATTR_TYPE_STATUS_CONFIRM	0x02
#define NDL_ATTR_TYPE_STATUS_CONTINUED	0x00
#define NDL_ATTR_TYPE_STATUS_ACCEPTED	0x10
#define NDL_ATTR_TYPE_STATUS_REJECTED	0x20

#define NAN_NDL_TYPE_CHECK(_ndl, x)	(((_ndl)->type_status & NAN_NDL_TYPE_MASK) == (x))
#define NAN_NDL_REQUEST(_ndl)		(((_ndl)->type_status & NAN_NDL_TYPE_MASK) == \
								NDL_ATTR_TYPE_STATUS_REQUEST)
#define NAN_NDL_RESPONSE(_ndl)		(((_ndl)->type_status & NAN_NDL_TYPE_MASK) == \
								NDL_ATTR_TYPE_STATUS_RESPONSE)
#define NAN_NDL_CONFIRM(_ndl)		(((_ndl)->type_status & NAN_NDL_TYPE_MASK) == \
								NDL_ATTR_TYPE_STATUS_CONFIRM)


#define NAN_NDL_STATUS_SHIFT	4
#define NAN_NDL_STATUS_MASK	0xF0
#define NAN_NDL_CONT(_ndl)	(((_ndl)->type_status & NAN_NDL_STATUS_MASK) == \
								NDL_ATTR_TYPE_STATUS_CONTINUED)
#define NAN_NDL_ACCEPT(_ndl)	(((_ndl)->type_status & NAN_NDL_STATUS_MASK) == \
								NDL_ATTR_TYPE_STATUS_ACCEPTED)
#define NAN_NDL_REJECT(_ndl)	(((_ndl)->type_status & NAN_NDL_STATUS_MASK) == \
								NDL_ATTR_TYPE_STATUS_REJECTED)
#define NAN_NDL_FRM_STATUS(_ndl) \
	(((_ndl)->type_status & NAN_NDL_STATUS_MASK) >> NAN_NDL_STATUS_SHIFT)

#define NDL_ATTR_CTRL_NONE				0
#define NDL_ATTR_CTRL_PEER_ID_PRESENT	(1 << NDL_ATTR_CTRL_PEER_ID_PRESENT_SHIFT)
#define NDL_ATTR_CTRL_IMSCHED_PRESENT	(1 << NDL_ATTR_CTRL_IM_SCHED_PRESENT_SHIFT)
#define NDL_ATTR_CTRL_NDC_PRESENT		(1 << NDL_ATTR_CTRL_NDC_ATTR_PRESENT_SHIFT)
#define NDL_ATTR_CTRL_NDL_QOS_PRESENT	(1 << NDL_ATTR_CTRL_QOS_ATTR_PRESENT_SHIFT)
#define NDL_ATTR_CTRL_MAX_IDLE_PER_PRESENT	(1 << NDL_ATTR_CTRL_MAX_IDLE_PER_PRESENT_SHIFT)

#define NA_NDL_IS_IMMUT_PRESENT(ndl) (((ndl)->ndl_ctrl) & NDL_ATTR_CTRL_IMSCHED_PRESENT)
#define NA_NDL_IS_PEER_ID_PRESENT(ndl) (((ndl)->ndl_ctrl) & NDL_ATTR_CTRL_PEER_ID_PRESENT)
#define NA_NDL_IS_MAX_IDLE_PER_PRESENT(ndl) (((ndl)->ndl_ctrl) & NDL_ATTR_CTRL_MAX_IDLE_PER_PRESENT)

#define NDL_ATTR_PEERID_LEN				1
#define NDL_ATTR_MAX_IDLE_PERIOD_LEN	2

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ndl_attr_s {
	uint8 id;		/* NAN_ATTR_NAN_NDL = 0x17 */
	uint16 len;		/* Length of the fields in the attribute */
	uint8 dialog_token;	/* Identify req and resp */
	uint8 type_status;		/* Bits[3-0] type subfield, Bits[7-4] status subfield */
	uint8 reason;		/* Identifies reject reason */
	uint8 ndl_ctrl;		/* NDL control field */
	uint8 var[];		/* Optional fields follow */
} BWL_POST_PACKED_STRUCT wifi_nan_ndl_attr_t;

/*
 * NDL QoS Attribute  WFA Tech. Spec ver r26
 */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ndl_qos_attr_s {
	uint8 id;		/* NAN_ATTR_NAN_NDL_QOS = 24 */
	uint16 len;		/* Length of the attribute field following */
	uint8 min_slots;	/* Min. number of FAW slots needed per DW interval */
	uint16 max_latency;  /* Max interval between non-cont FAW */
} BWL_POST_PACKED_STRUCT wifi_nan_ndl_qos_attr_t;

/* no preference to min time slots */
#define NAN_NDL_QOS_MIN_SLOT_NO_PREF	0
/* no preference to no. of slots between two non-contiguous slots */
#define NAN_NDL_QOS_MAX_LAT_NO_PREF		0xFFFF

/* Device Capability Attribute */

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_dev_cap_s {
	uint8 id;		/* 0x0F */
	uint16 len;		/* Length */
	uint8 map_id;		/* map id */
	uint16 commit_dw_info;	/* Committed DW Info */
	uint8 bands_supported;	/* Supported Bands */
	uint8 op_mode;		/* Operation Mode */
	uint8 num_antennas;	/* Bit 0-3 tx, 4-7 rx */
	uint16 chan_switch_time;	/* Max channel switch time in us */
	uint8 capabilities;	/* DFS Master, Extended key id etc */
} BWL_POST_PACKED_STRUCT wifi_nan_dev_cap_t;

/* Regulatory info - operation types in 6G band, Table 126, NAN R4 spec.
 * Also, see Table E-12, REVme_D1.0
 */
typedef enum nan_mac_6g_op_type {
	/* Indoor AP, i.e., LPI(Low Power Indoor) AP.
	 * AFC is not required but with some regulations to be indoor opeation.
	 */
	NAN_MAC_6G_OP_INDOOR_AP		= 0,

	/* Standard Power AP, needs AFC coordination */
	NAN_MAC_6G_OP_SP_AP		= 1,

	/* Very Low Power AP - VLP AP
	 * AFC is not required. Resticted with very low transmit power
	 * This is the default mode of all P2P devices.
	 */
	NAN_MAC_6G_OP_VLP_AP		= 2,

	/* Indoor Enabled AP.
	 * Devices capable of receiving the "enabling signal" and configures itself to use
	 * C2C power level which is 10dB Higher than VLP AP.
	 */
	NAN_MAC_6G_OP_INDOOR_ENABLED_AP	= 3,

	/* This is kind of hybrid mode (AFC in indoors).
	 * Devices opering in indoors and standard power mode with AFC.
	 */
	NAN_MAC_6G_OP_INDOOR_SP_AP	= 4
} nan_mac_6g_op_type_e;

/* First byte of the extended capabilities is the regulatory info */
typedef struct nan_mac_dev_cap_ext_reg_info_s {
	uint8 reg_info_6g_present:1;	/* bit0 */
	uint8 reg_info_6g:3;		/* bits 1-3, see nan_mac_6g_op_type_e */
	uint8 reserved:4;		/* bits 4-7 */
} nan_mac_dev_cap_ext_reg_info_t;

/* Byte1 (bits 8..15) of the extended capabilities */
typedef struct nan_mac_dev_cap_ext_byte1_s {
	uint8 pairing_setup:1;		/* 1 -> NAN pairing enabled, 0 disabled */
	uint8 npk_nik_caching:1;	/* 1 -> NPK/NIK caching enabled, 0 disabled */
	uint8 reserved:6;		/* reserved */
} nan_mac_dev_cap_ext_byte1_t;

typedef struct nan_mac_dev_cap_ext_cap_data_s {
	nan_mac_dev_cap_ext_reg_info_t reg_info; /* Byte0 (bits 0..7) in the data */
	nan_mac_dev_cap_ext_byte1_t byte1;	 /* Byte1 (bits 8..15) */
	/* add more bytes */
} nan_mac_dev_cap_ext_cap_data_t;

/* NAN R4 - Device Capability Extension Attribute */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_dev_cap_ext_s {
	uint8 id;		/* 0x2A */
	uint16 len;		/* Length */
	/* Bit field with variable length in octets as indicated in the len field */
	uint8 data[];
} BWL_POST_PACKED_STRUCT wifi_nan_dev_cap_ext_t;

/* Fixed string for the NIK (NAN Identity Key) generation algorithm */
static const uint8 nan_pairing_nik_prefix[] = "NIK Generation";

/* Caching NPK prefix */
static const uint8 nan_pairing_npk_prefix[] = "NAN Opportunistic NPK Derivation";

/* Tag prefix */
static const uint8 nan_pairing_tag_prefix[] = "NIR";

/* NAN Pairing (R4) reklated definitions */
#define NAN_PAIRING_MAX_NPK_LEN		32u		/* bytes */
#define NAN_PAIRING_NPK_PREFIXES	4u		/* Number of prefixes for NPK caching */
#define NAN_PAIRING_NIK_PREFIXES	3u		/* max number of prefixes */
#define NAN_PAIRING_TAG_PREFIXES	3u		/* Tag prefixes */
#define NAN_PAIRING_RAND_BUF_LEN	32u		/* random buffer length */
#define NAN_PAIRING_SID_MAP_FULL	0xFFFFFFFFu	/* session IDs in map are Full */

/* Cipher vesion lengths */
#define NAN_PAIRING_CIPHER_VER_0_NIK_BITS	128u	/* Number of bits */
#define NAN_PAIRING_CIPHER_VER_0_NONCE_BITS	64u
#define NAN_PAIRING_CIPHER_VER_0_TAG_BITS	64u

#define NAN_SSID "516F9A010000"		/* NAN Network ID */
#define NAN_SSID_len (sizeof(NAN_SSID) - 1)

/* map id related */

/* all maps */
#define NAN_DEV_CAP_ALL_MAPS_FLAG_MASK	0x1	/* nan default map control */
#define NAN_DEV_CAP_ALL_MAPS_FLAG_SHIFT	0
/* map id */
#define NAN_DEV_CAP_MAPID_MASK	0x1E
#define NAN_DEV_CAP_MAPID_SHIFT	1

/* Awake DW Info field format */

/* 2.4GHz DW */
#define NAN_DEV_CAP_AWAKE_DW_2G_MASK	0x07
/* 5GHz DW */
#define NAN_DEV_CAP_AWAKE_DW_5G_MASK	0x38
/* Reserved */
#define NAN_DEV_CAP_AWAKE_DW_RSVD_MASK	0xC0

/* bit shift for dev cap */
#define NAN_DEV_CAP_AWAKE_DW_2G_SHIFT	0
#define NAN_DEV_CAP_AWAKE_DW_5G_SHIFT	3

/* Device Capability Attribute Format */

/* Committed DW Info field format */
/* 2.4GHz DW */
#define NAN_DEV_CAP_COMMIT_DW_2G_MASK	0x07
#define NAN_DEV_CAP_COMMIT_DW_2G_OVERWRITE_MASK	0x3C0
/* 5GHz DW */
#define NAN_DEV_CAP_COMMIT_DW_5G_MASK	0x38
#define NAN_DEV_CAP_COMMIT_DW_5G_OVERWRITE_MASK 0x3C00
/* Reserved */
#define NAN_DEV_CAP_COMMIT_DW_RSVD_MASK	0xC000
/* Committed DW bit shift for dev cap */
#define NAN_DEV_CAP_COMMIT_DW_2G_SHIFT	0
#define NAN_DEV_CAP_COMMIT_DW_5G_SHIFT	3
#define NAN_DEV_CAP_COMMIT_DW_2G_OVERWRITE_SHIFT	6
#define NAN_DEV_CAP_COMMIT_DW_5G_OVERWRITE_SHIFT	10

/* Operation Mode */
#define NAN_DEV_CAP_OP_PHY_MODE_HT_ONLY		0x00
#define NAN_DEV_CAP_OP_PHY_MODE_VHT		0x01
#define NAN_DEV_CAP_OP_PHY_MODE_VHT_8080	0x02
#define NAN_DEV_CAP_OP_PHY_MODE_VHT_160		0x04
#define NAN_DEV_CAP_OP_PHY_MODE_HE_160		0x04
#define NAN_DEV_CAP_OP_PAGING_NDL		0x08
#define NAN_DEV_CAP_OP_PHY_MODE_HE		0x10

#define NAN_DEV_CAP_OP_MODE_VHT_MASK		0x01
#define NAN_DEV_CAP_OP_MODE_VHT_SHIFT		0
#define NAN_DEV_CAP_OP_MODE_VHT8080_MASK	0x02
#define NAN_DEV_CAP_OP_MODE_VHT8080_SHIFT	1
#define NAN_DEV_CAP_OP_MODE_VHT160_MASK		0x04
#define NAN_DEV_CAP_OP_MODE_VHT160_SHIFT	2
#define NAN_DEV_CAP_OP_MODE_PAGING_NDL_MASK	0x08
#define NAN_DEV_CAP_OP_MODE_PAGING_NDL_SHIFT	3
#define NAN_DEV_CAP_OP_MODE_HE_MASK		0x10
#define NAN_DEV_CAP_OP_MODE_HE_SHIFT		4

#define NAN_DEV_CAP_RX_ANT_SHIFT		4
#define NAN_DEV_CAP_TX_ANT_MASK			0x0F
#define NAN_DEV_CAP_RX_ANT_MASK			0xF0
#define NAN_DEV_CAP_TX_ANT(_ant)		((_ant) & NAN_DEV_CAP_TX_ANT_MASK)
#define NAN_DEV_CAP_RX_ANT(_ant)		(((_ant) & NAN_DEV_CAP_RX_ANT_MASK) \
		>> NAN_DEV_CAP_RX_ANT_SHIFT)

/* Device capabilities */

/* DFS master capability */
#define NAN_DEV_CAP_DFS_MASTER_MASK		0x01
#define NAN_DEV_CAP_DFS_MASTER_SHIFT		0u
/* extended iv cap */
#define NAN_DEV_CAP_EXT_KEYID_MASK		0x02
#define NAN_DEV_CAP_EXT_KEYID_SHIFT		1u
/* Simultaneous NDP data reception capability */
#define NAN_DEV_CAP_SIMULTANEOUS_DATA_RECV_MASK		0x04
#define NAN_DEV_CAP_SIMULTANEOUS_DATA_RECV_SHIFT	2u
/* NDPE attribute support */
#define	NAN_DEV_CAP_NDPE_ATTR_SUPPORT_MASK	0x08
#define	NAN_DEV_CAP_NDPE_ATTR_SUPPORT_SHIFT	3u
#define NAN_DEV_CAP_NDPE_ATTR_SUPPORT(_cap)	((_cap) & NAN_DEV_CAP_NDPE_ATTR_SUPPORT_MASK)
/* S3 capability */
#define	NAN_DEV_CAP_S3_CAPABLE_MASK	0x10
#define	NAN_DEV_CAP_S3_CAPABLE_SHIFT	4u
#define NAN_DEV_CAP_S3_CAPABLE(_cap)	((_cap) & NAN_DEV_CAP_S3_CAPABLE_MASK)

#ifdef NAN_REKEY
#define NAN_DEV_CAP_PTK_REKEY_SUPPORT_MASK	0x10
#define NAN_DEV_CAP_PTK_REKEY_SUPPORT_SHIFT	4u

#define NAN_DEV_CAP_GTK_REKEY_SUPPORT_MASK	0x20
#define NAN_DEV_CAP_GTK_REKEY_SUPPORT_SHIFT	5u
#endif /* NAN_REKEY */

/* Band IDs: See Table 99 in NAN R4 spec */
enum {
	NAN_BAND_ID_TVWS		= 0,
	NAN_BAND_ID_SIG			= 1,	/* Sub 1 GHz */
	NAN_BAND_ID_2G			= 2,	/* 2.4 GHz */
	NAN_BAND_ID_3G			= 3,	/* 3.6 GHz */
	NAN_BAND_ID_5G			= 4,	/* 4.9 & 5 GHz */
	NAN_BAND_ID_60G			= 5,	/* 60 GHz */
	NAN_BAND_ID_45G			= 6,	/* 45 GHz */
	NAN_BAND_ID_6G			= 7	/* 6 GHz */
};
typedef uint8 nan_band_id_t;

/* NAN supported band in device capability */
#define NAN_DEV_CAP_SUPPORTED_BANDS_2G	(1 << NAN_BAND_ID_2G)
#define NAN_DEV_CAP_SUPPORTED_BANDS_5G	(1 << NAN_BAND_ID_5G)
#define NAN_DEV_CAP_SUPPORTED_BANDS_6G	(1 << NAN_BAND_ID_6G)

/* NAN Supported Band ID bitmap, Table 72 in NAN R4 spec,
 * bitmap of supported bands in the device capability attribute.
 */
typedef enum nan_mac_supp_band_flags {
	NAN_MAC_SUPP_BAND_TV_WHITE_SPACES	= (1u << 0u),	 /* bit0 */
	NAN_MAC_SUPP_BAND_SUB_1GHZ		= (1u << 1u),
	NAN_MAC_SUPP_BAND_2G			= (1u << 2u),
	NAN_MAC_SUPP_BAND_3G			= (1u << 3u),
	NAN_MAC_SUPP_BAND_5G			= (1u << 4u),
	NAN_MAC_SUPP_BAND_60G			= (1u << 5u),
	NAN_MAC_SUPP_BAND_45G			= (1u << 6u),
	NAN_MAC_SUPP_BAND_6G			= (1u << 7u)	/* bit7 */
} nan_mac_supp_band_flags_e;
/*
 * Unaligned schedule attribute section 10.7.19.6 spec. ver r15
 */
#define NAN_ULW_ATTR_CTRL_SCHED_ID_MASK 0x000F
#define NAN_ULW_ATTR_CTRL_SCHED_ID_SHIFT 0
#define NAN_ULW_ATTR_CTRL_SEQ_ID_MASK 0xFF00
#define NAN_ULW_ATTR_CTRL_SEQ_ID_SHIFT 8

#define NAN_ULW_OVWR_ALL_MASK 0x01
#define NAN_ULW_OVWR_ALL_SHIFT 0
#define NAN_ULW_OVWR_MAP_ID_MASK 0x1E
#define NAN_ULW_OVWR_MAP_ID_SHIFT 1

#define NAN_ULW_CTRL_TYPE_MASK 0x03
#define NAN_ULW_CTRL_TYPE_SHIFT 0
#define NAN_ULW_CTRL_TYPE(ctrl)	(ctrl & NAN_ULW_CTRL_TYPE_MASK)
#define NAN_ULW_CTRL_CHAN_AVAIL_MASK 0x04
#define NAN_ULW_CTRL_CHAN_AVAIL_SHIFT 2
#define NAN_ULW_CTRL_CHAN_AVAIL(ctrl)	((ctrl & NAN_ULW_CTRL_CHAN_AVAIL_MASK) \
	>> NAN_ULW_CTRL_CHAN_AVAIL_SHIFT)
#define NAN_ULW_CTRL_RX_NSS_MASK 0x78
#define NAN_ULW_CTRL_RX_NSS_SHIFT 3

#define NAN_ULW_CTRL_TYPE_BAND		0
#define NAN_ULW_CTRL_TYPE_CHAN_NOAUX	1
#define NAN_ULW_CTRL_TYPE_CHAN_AUX	2

#define NAN_ULW_CNT_DOWN_NO_EXPIRE	0xFF	/* ULWs doen't end until next sched update */
#define NAN_ULW_CNT_DOWN_CANCEL		0x0		/* cancel remaining ulws */

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ulw_attr_s {
	uint8 id;
	uint16 len;
	uint16 ctrl;
	uint32 start; /* low 32 bits of tsf */
	uint32 dur;
	uint32 period;
	uint8 count_down;
	uint8 overwrite;
	/*
	 * ulw[0] == optional field ULW control when present.
	 * band ID or channel follows
	 */
	uint8 ulw_entry[];
} BWL_POST_PACKED_STRUCT wifi_nan_ulw_attr_t;

/* NAN2 Management Frame (section 5.6) */

/* Public action frame for NAN2 */
typedef BWL_PRE_PACKED_STRUCT struct nan2_pub_act_frame_s {
	/* NAN_PUB_AF_CATEGORY 0x04 */
	uint8 category_id;
	/* NAN_PUB_AF_ACTION 0x09 */
	uint8 action_field;
	/* NAN_OUI 0x50-6F-9A */
	uint8 oui[DOT11_OUI_LEN];
	/* NAN_OUI_TYPE TBD */
	uint8 oui_type;
	/* NAN_OUI_SUB_TYPE TBD */
	uint8 oui_sub_type;
	/* One or more NAN Attributes follow */
	uint8 data[];
} BWL_POST_PACKED_STRUCT nan2_pub_act_frame_t;

#define NAN2_PUB_ACT_FRM_SIZE	(OFFSETOF(nan2_pub_act_frame_t, data))

/* NAN Action Frame Subtypes */
/* Subtype-0 is Reserved */
#define NAN_MGMT_FRM_SUBTYPE_RESERVED		0
#define NAN_MGMT_FRM_SUBTYPE_INVALID		0
/* NAN Ranging Request */
#define NAN_MGMT_FRM_SUBTYPE_RANGING_REQ	1
/* NAN Ranging Response */
#define NAN_MGMT_FRM_SUBTYPE_RANGING_RESP	2
/* NAN Ranging Termination */
#define NAN_MGMT_FRM_SUBTYPE_RANGING_TERM	3
/* NAN Ranging Report */
#define NAN_MGMT_FRM_SUBTYPE_RANGING_RPT	4
/* NDP Request */
#define NAN_MGMT_FRM_SUBTYPE_NDP_REQ		5
/* NDP Response */
#define NAN_MGMT_FRM_SUBTYPE_NDP_RESP		6
/* NDP Confirm */
#define NAN_MGMT_FRM_SUBTYPE_NDP_CONFIRM	7
/* NDP Key Installment */
#define NAN_MGMT_FRM_SUBTYPE_NDP_KEY_INST	8
/* NDP Termination */
#define NAN_MGMT_FRM_SUBTYPE_NDP_END		9
/* Schedule Request */
#define NAN_MGMT_FRM_SUBTYPE_SCHED_REQ		10
/* Schedule Response */
#define NAN_MGMT_FRM_SUBTYPE_SCHED_RESP		11
/* Schedule Confirm */
#define NAN_MGMT_FRM_SUBTYPE_SCHED_CONF		12
/* Schedule Update */
#define NAN_MGMT_FRM_SUBTYPE_SCHED_UPD		13
#ifdef NAN_REKEY
/* Rekey Trigger  frame */
#define NAN_MGMT_FRM_SUBTYPE_REKEY_TRIGGER	14
/* Group key request frame */
#define NAN_MGMT_FRM_SUBTYPE_GRP_REKEY_REQ	15
/* Group key response frame */
#define NAN_MGMT_FRM_SUBTYPE_GRP_REKEY_RESP	16
#endif /* NAN_REKEY */

/* Vendor specific NAN OOB AF subtype */
#define NAN_MGMT_FRM_SUBTYPE_NAN_OOB_AF		0xDD

#define NAN_SCHEDULE_AF(_naf_subtype) \
	((_naf_subtype >= NAN_MGMT_FRM_SUBTYPE_SCHED_REQ) && \
	(_naf_subtype <= NAN_MGMT_FRM_SUBTYPE_SCHED_UPD))

/* Reason code defines */
#define NAN_REASON_RESERVED			0x0
#define NAN_REASON_UNSPECIFIED			0x1
#define NAN_REASON_RESOURCE_LIMIT		0x2
#define NAN_REASON_INVALID_PARAMS		0x3
#define NAN_REASON_FTM_PARAM_INCAP		0x4
#define NAN_REASON_NO_MOVEMENT			0x5
#define NAN_REASON_INVALID_AVAIL		0x6
#define NAN_REASON_IMMUT_UNACCEPT		0x7
#define NAN_REASON_SEC_POLICY			0x8
#define NAN_REASON_QOS_UNACCEPT			0x9
#define NAN_REASON_NDP_REJECT			0xa
#define NAN_REASON_NDL_UNACCEPTABLE		0xb
#define NAN_REASON_RNG_SCHED_UNACCEPTALE	0xc

/* nan 2.0 qos (not attribute) */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ndp_qos_s {
	uint8 tid;		/* traffic identifier */
	uint16 pkt_size;	/* service data pkt size */
	uint8 data_rate;	/* mean data rate */
	uint8 svc_interval;	/* max service interval */
} BWL_POST_PACKED_STRUCT wifi_nan_ndp_qos_t;

/* NDP control bitmap defines */
#define NAN_NDP_CTRL_CONFIRM_REQUIRED		0x01
#ifdef NAN_REKEY
/* 0 = NDP setup, 1 = rekey handshake */
#define NAN_NDP_CTRL_NDP_REKEY			0x02
#endif /* NAN_REKEY */
#define NAN_NDP_CTRL_SECURTIY_PRESENT		0x04
#define NAN_NDP_CTRL_PUB_ID_PRESENT		0x08
#define NAN_NDP_CTRL_RESP_NDI_PRESENT		0x10
#define NAN_NDP_CTRL_SPEC_INFO_PRESENT		0x20
#define NAN_NDP_CTRL_RESERVED			0xA0

#if defined(WL_NAN_GAF_PROTECT) || defined(NAN_GTK)
/*
 * NDPE control bitmap defines
 * currently NDP & NDPE share same control bitmap before b5
 * GTK/IGTK Required b5
 * 0: GTK/IGTK protection is not required
 * 1: GTK/IGTK protection is required
 */
#define NAN_NDPE_CTRL_GTK_REQUIRED		0x20
#endif /* WL_NAN_GAF_PROTECT || NAN_GTK */

/* Used for both NDP Attribute and NDPE Attribute, since the structures are identical */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ndp_attr_s {
	uint8 id;		/* NDP: 0x10, NDPE: 0x29 */
	uint16 len;		/* length */
	uint8 dialog_token;	/* dialog token */
	uint8 type_status;	/* bits 0-3 type, 4-7 status */
	uint8 reason;		/* reason code */
	struct ether_addr init_ndi;	/* ndp initiator's data interface address */
	uint8 ndp_id;		/* ndp identifier (created by initiator */
	uint8 control;		/* ndp control field */
	uint8 var[];		/* Optional fields follow */
} BWL_POST_PACKED_STRUCT wifi_nan_ndp_attr_t;
/* NDP attribute type and status macros */
#define NAN_NDP_TYPE_MASK	0x0F
#define NAN_NDP_TYPE_REQUEST	0x0
#define NAN_NDP_TYPE_RESPONSE	0x1
#define NAN_NDP_TYPE_CONFIRM	0x2
#define NAN_NDP_TYPE_SECURITY	0x3
#define NAN_NDP_TYPE_TERMINATE	0x4
#ifdef NAN_REKEY
#define NAN_NDP_TYPE_REKEY		0x5
#define NAN_NDP_TYPE_GRP_REKEY_REQ	0x6
#define NAN_NDP_TYPE_GRP_REKEY_RESP	0x7
#endif /* NAN_REKEY */
#define NAN_NDP_REQUEST(_ndp)	(((_ndp)->type_status & NAN_NDP_TYPE_MASK) == NAN_NDP_TYPE_REQUEST)
#define NAN_NDP_RESPONSE(_ndp)	(((_ndp)->type_status & NAN_NDP_TYPE_MASK) == NAN_NDP_TYPE_RESPONSE)
#define NAN_NDP_CONFIRM(_ndp)	(((_ndp)->type_status & NAN_NDP_TYPE_MASK) == NAN_NDP_TYPE_CONFIRM)
#define NAN_NDP_SECURITY_INST(_ndp)	(((_ndp)->type_status & NAN_NDP_TYPE_MASK) == \
						NAN_NDP_TYPE_SECURITY)
#define NAN_NDP_TERMINATE(_ndp) (((_ndp)->type_status & NAN_NDP_TYPE_MASK) == \
						NAN_NDP_TYPE_TERMINATE)
#ifdef NAN_REKEY
#define NAN_NDP_REKEY(_ndp)		(((_ndp)->type_status & NAN_NDP_TYPE_MASK) == \
						NAN_NDP_TYPE_REKEY)
#define NAN_NDP_GRP_REKEY_REQ(_ndp)	(((_ndp)->type_status & NAN_NDP_TYPE_MASK) == \
						NAN_NDP_TYPE_GRP_REKEY_REQ)
#define NAN_NDP_GRP_REKEY_RESP(_ndp)	(((_ndp)->type_status & NAN_NDP_TYPE_MASK) == \
						NAN_NDP_TYPE_GRP_REKEY_RESP)
#endif /* NAN_REKEY */
#define NAN_NDP_STATUS_SHIFT	4
#define NAN_NDP_STATUS_MASK	0xF0
#define NAN_NDP_STATUS_CONT	(0 << NAN_NDP_STATUS_SHIFT)
#define NAN_NDP_STATUS_ACCEPT	(1 << NAN_NDP_STATUS_SHIFT)
#define NAN_NDP_STATUS_REJECT	(2 << NAN_NDP_STATUS_SHIFT)
#define NAN_NDP_CONT(_ndp)	(((_ndp)->type_status & NAN_NDP_STATUS_MASK) == NAN_NDP_STATUS_CONT)
#define NAN_NDP_ACCEPT(_ndp)	(((_ndp)->type_status & NAN_NDP_STATUS_MASK) == \
									NAN_NDP_STATUS_ACCEPT)
#define NAN_NDP_REJECT(_ndp)	(((_ndp)->type_status & NAN_NDP_STATUS_MASK) == \
									NAN_NDP_STATUS_REJECT)

#define NAN_NDP_FRM_STATUS(_ndp) \
	(((_ndp)->type_status & NAN_NDP_STATUS_MASK) >> NAN_NDP_STATUS_SHIFT)

/* NDP Setup Status */
#define NAN_NDP_SETUP_STATUS_OK		1
#define NAN_NDP_SETUP_STATUS_FAIL	0
#define NAN_NDP_SETUP_STATUS_REJECT	2

/* NDPE TLV list */
#define NDPE_TLV_TYPE_IPV6		0x00
#define NDPE_TLV_TYPE_SVC_INFO		0x01
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ndpe_tlv_s {
	uint8 type;		/* Operating Class */
	uint16 length;		/* Channel Bitmap */
	uint8 data[];
} BWL_POST_PACKED_STRUCT wifi_nan_ndpe_tlv_t;

/* Rng setup attribute type and status macros */
#define NAN_RNG_TYPE_MASK	0x0F
#define NAN_RNG_TYPE_REQUEST	0x0
#define NAN_RNG_TYPE_RESPONSE	0x1
#define NAN_RNG_TYPE_TERMINATE	0x2

#define NAN_RNG_STATUS_SHIFT	4
#define NAN_RNG_STATUS_MASK	0xF0
#define NAN_RNG_STATUS_ACCEPT	(0 << NAN_RNG_STATUS_SHIFT)
#define NAN_RNG_STATUS_REJECT	(1 << NAN_RNG_STATUS_SHIFT)

#define NAN_RNG_ACCEPT(_rsua)	(((_rsua)->type_status & NAN_RNG_STATUS_MASK) == \
									NAN_RNG_STATUS_ACCEPT)
#define NAN_RNG_REJECT(_rsua)	(((_rsua)->type_status & NAN_RNG_STATUS_MASK) == \
									NAN_RNG_STATUS_REJECT)

/* schedule entry */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_sched_entry_s {
	uint8 map_id;		/* map id */
	uint16 tbmp_ctrl;	/* time bitmap control */
	uint8 tbmp_len;		/* time bitmap len */
	uint8 tbmp[];		/* time bitmap - Optional */
} BWL_POST_PACKED_STRUCT wifi_nan_sched_entry_t;

#define NAN_SCHED_ENTRY_MAPID_MASK	0x0F
#define NAN_SCHED_ENTRY_MIN_SIZE	OFFSETOF(wifi_nan_sched_entry_t, tbmp)
#define NAN_SCHED_ENTRY_SIZE(_entry)	(NAN_SCHED_ENTRY_MIN_SIZE + (_entry)->tbmp_len)

/* for dev cap, element container etc. */
#define NAN_DEV_ELE_MAPID_CTRL_MASK		0x1
#define NAN_DEV_ELE_MAPID_CTRL_SHIFT	0
#define NAN_DEV_ELE_MAPID_MASK		0x1E
#define NAN_DEV_ELE_MAPID_SHIFT		1

#define NAN_DEV_ELE_MAPID_CTRL_SET(_mapid_field, value) \
	do {(_mapid_field) &= ~NAN_DEV_ELE_MAPID_CTRL_MASK; \
		(_mapid_field) |= ((value << NAN_DEV_ELE_MAPID_CTRL_SHIFT) & \
		NAN_DEV_ELE_MAPID_CTRL_MASK); \
	} while (0);

#define NAN_DEV_ELE_MAPID_CTRL_GET(_mapid_field) \
	(((_mapid_field) & NAN_DEV_ELE_MAPID_CTRL_MASK) >> \
	NAN_DEV_ELE_MAPID_CTRL_SHIFT)

#define NAN_DEV_ELE_MAPID_SET(_mapid_field, value) \
	do {(_mapid_field) &= ~NAN_DEV_ELE_MAPID_MASK; \
		(_mapid_field) |= ((value << NAN_DEV_ELE_MAPID_SHIFT) & \
		NAN_DEV_ELE_MAPID_MASK); \
	} while (0);

#define NAN_DEV_ELE_MAPID_GET(_mapid_field) \
	(((_mapid_field) & NAN_DEV_ELE_MAPID_MASK) >> \
	NAN_DEV_ELE_MAPID_SHIFT)

/* schedule entry map id handling */
#define NAN_SCHED_ENTRY_MAPID_MASK		0x0F
#define NAN_SCHED_ENTRY_MAPID_SHIFT		0

#define NAN_SCHED_ENTRY_MAPID_SET(_mapid_field, value) \
	do {(_mapid_field) &= ~NAN_SCHED_ENTRY_MAPID_MASK; \
		(_mapid_field) |= ((value << NAN_SCHED_ENTRY_MAPID_SHIFT) & \
		NAN_SCHED_ENTRY_MAPID_MASK); \
	} while (0);

#define NAN_SCHED_ENTRY_MAPID_GET(_mapid_field) \
	(((_mapid_field) & NAN_SCHED_ENTRY_MAPID_MASK) >> \
	NAN_SCHED_ENTRY_MAPID_SHIFT)

/* NDC attribute */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_ndc_attr_s {
	uint8 id;
	uint16 len;
	uint8 ndc_id[NAN_DATA_NDC_ID_SIZE];
	uint8 attr_cntrl;
	uint8 var[];
} BWL_POST_PACKED_STRUCT wifi_nan_ndc_attr_t;

/* Attribute control subfield of NDC attr */
/* Proposed NDC */
#define NAN_NDC_ATTR_PROPOSED_NDC_MASK	0x1
#define NAN_NDC_ATTR_PROPOSED_NDC_SHIFT 0

/* get & set */
#define NAN_NDC_GET_PROPOSED_FLAG(_attr)	\
	(((_attr)->attr_cntrl & NAN_NDC_ATTR_PROPOSED_NDC_MASK) >>	\
	NAN_NDC_ATTR_PROPOSED_NDC_SHIFT)
#define NAN_NDC_SET_PROPOSED_FLAG(_attr, value) \
	do {((_attr)->attr_cntrl &= ~NAN_NDC_ATTR_PROPOSED_NDC_MASK); \
		((_attr)->attr_cntrl |=	\
		(((value) << NAN_NDC_ATTR_PROPOSED_NDC_SHIFT) & NAN_NDC_ATTR_PROPOSED_NDC_MASK)); \
	} while (0)

/* NAN Subslot attribute */
/* Subslot S3 schedule entry */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_s3_entry_s {
	uint8 entry_ctrl;	/* entry control */
	uint16 tbmp_ctrl;	/* time bitmap control */
	uint16 tbmp_len;	/* time bitmap len */
	uint8 tbmp[];		/* time bitmap */
} BWL_POST_PACKED_STRUCT wifi_nan_s3_entry_t;

typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_subslot_attr_s {
	uint8 id;
	uint16 len;
	uint8 var[];		/* One or more wifi_nan_s3_entry_t */
} BWL_POST_PACKED_STRUCT wifi_nan_s3_attr_t;

enum
{
	NAN_S3_TIME_BMP_BIT_DUR_1TU_IDX = 0,
	NAN_S3_TIME_BMP_BIT_DUR_2TU_IDX = 1,
	NAN_S3_TIME_BMP_BIT_DUR_4TU_IDX = 2,
	NAN_S3_TIME_BMP_BIT_DUR_8TU_IDX = 3
};

#define NAN_SUBSLOT_CTRL_MAP_ID_FULL		0x1F
#define NAN_SUBSLOT_CTRL_MAP_ID_MASK		0x1E
#define NAN_SUBSLOT_CTRL_MAP_ID_ALL		0x01

#define NAN_SUBSLOT_CTRL_MAP_ID(_ctrl)		(((_ctrl) & NAN_SUBSLOT_CTRL_MAP_ID_MASK) >> 1)
#define NAN_SUBSLOT_CTRL_MAP_ID_ALLMAP(_ctrl)	((_ctrl) & NAN_SUBSLOT_CTRL_MAP_ID_ALL)
#define NAN_SUBSLOT_CTRL_IMMUTABLE(_ctrl)	((_ctrl) & 0x20)
#define NAN_SUBSLOT_SET_CTRL_IMMUTABLE(_ctrl)	((_ctrl) |= ((_ctrl) | 0x20))

#define NAN_S3_TIME_BMAP_CTRL_BITDUR_MASK 0x03
#define NAN_S3_TIME_BMAP_CTRL_BITDUR(_flags) ((_flags) & NAN_S3_TIME_BMAP_CTRL_BITDUR_MASK)

#define NAN_S3_TIME_BMAP_CTRL_PERIOD_MASK 0x3C
#define NAN_S3_TIME_BMAP_CTRL_PERIOD_SHIFT 0x2
#define NAN_S3_TIME_BMAP_CTRL_PERIOD(_flags) (((_flags) & NAN_S3_TIME_BMAP_CTRL_PERIOD_MASK) \
	>> NAN_S3_TIME_BMAP_CTRL_PERIOD_SHIFT)

#define NAN_S3_TIME_BMAP_CTRL_OFFSET_MASK 0x7FC0
#define NAN_S3_TIME_BMAP_CTRL_OFFSET_SHIFT 6
#define NAN_S3_TIME_BMAP_CTRL_OFFSET(_flags) (((_flags) & NAN_S3_TIME_BMAP_CTRL_OFFSET_MASK) \
	>> NAN_S3_TIME_BMAP_CTRL_OFFSET_SHIFT)
#define NAN_S3_MIN_AVAIL_ATTR_SIZE(n)	(OFFSETOF(wifi_nan_s3_attr_t, var) + \
		((n) * OFFSETOF(wifi_nan_s3_entry_t, tbmp)))
#define NAN_S3_ENTRY_MIN_SIZE	OFFSETOF(wifi_nan_s3_entry_t, tbmp)
#define NAN_S3_ENTRY_SIZE(_entry)	(NAN_S3_ENTRY_MIN_SIZE + (_entry)->tbmp_len)

/* mandatory fields in subslot attribute for given avail entries */
#define NAN_AVAIL_MIN_SUBSLOT_ATTR_SIZE(n)	(OFFSETOF(wifi_nan_s3_attr_t, var) + \
	((n) * OFFSETOF(wifi_nan_s3_entry_t, tbmp)))
#define NAN_SUBSLOT_TIME_BITMAP_HDR_LEN		OFFSETOF(wifi_nan_s3_entry_t, bitmap)

/* Service descriptor extension attribute */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_svc_desc_ext_attr_s {
	/* Attribute ID - 0x11 */
	uint8 id;
	/* Length of the following fields in the attribute */
	uint16 len;
	/* Instance id of associated service descriptor attribute */
	uint8 instance_id;
	/* SDE control field */
	uint16 control;
	/* range limit, svc upd indicator etc. */
	uint8 var[];
} BWL_POST_PACKED_STRUCT wifi_nan_svc_desc_ext_attr_t;

#define NAN_SDE_ATTR_MIN_LEN OFFSETOF(wifi_nan_svc_desc_ext_attr_t, var)
#define	NAN_SDE_ATTR_RANGE_LEN			4
#define	NAN_SDE_ATTR_SUI_LEN			1
#define	NAN_SDE_ATTR_INFO_LEN_PARAM_LEN		2
#define	NAN_SDE_ATTR_RANGE_INGRESS_LEN		2
#define	NAN_SDE_ATTR_RANGE_EGRESS_LEN		2
#define NAN_SDE_ATTR_CTRL_LEN			2
/* max length of variable length field (matching filter, service response filter,
 * or service info) in service descriptor attribute
 */
#define NAN_DISC_SDA_FIELD_MAX_LEN	255

/* SDEA control field bit definitions and access macros */
#define NAN_SDE_CF_FSD_REQUIRED		(1 << 0)
#define NAN_SDE_CF_FSD_GAS		(1 << 1)
#define NAN_SDE_CF_DP_REQUIRED		(1 << 2)
#define NAN_SDE_CF_DP_TYPE		(1 << 3)
#define NAN_SDE_CF_MULTICAST_TYPE	(1 << 4)
#define NAN_SDE_CF_QOS_REQUIRED		(1 << 5)
#define NAN_SDE_CF_SECURITY_REQUIRED	(1 << 6)
#define NAN_SDE_CF_RANGING_REQUIRED	(1 << 7)
#define NAN_SDE_CF_RANGE_PRESENT	(1 << 8)
#define NAN_SDE_CF_SVC_UPD_IND_PRESENT	(1 << 9)
#if defined(WL_NAN_GAF_PROTECT) || defined(NAN_GTK)
#define NAN_SDE_CF_GTK_REQUIRED	        (1u << 10u)
#endif /* WL_NAN_GAF_PROTECT || NAN_GTK */
/* Using Reserved Bits as per Spec */
#define NAN_SDE_CF_LIFE_CNT_PUB_RX      (1 << 15)
#define NAN_SDE_FSD_REQUIRED(_sde)	((_sde)->control & NAN_SDE_CF_FSD_REQUIRED)
#define NAN_SDE_FSD_GAS(_sde)		((_sde)->control & NAN_SDE_CF_FSD_GAS)
#define NAN_SDE_DP_REQUIRED(_sde)	((_sde)->control & NAN_SDE_CF_DP_REQUIRED)
#define NAN_SDE_DP_MULTICAST(_sde)	((_sde)->control & NAN_SDE_CF_DP_TYPE)
#define NAN_SDE_MULTICAST_M_TO_M(_sde)	((_sde)->control & NAN_SDE_CF_MULTICAST_TYPE)
#define NAN_SDE_QOS_REQUIRED(_sde)	((_sde)->control & NAN_SDE_CF_QOS_REQUIRED)
#define NAN_SDE_SECURITY_REQUIRED(_sde)	((_sde)->control & NAN_SDE_CF_SECURITY_REQUIRED)
#define NAN_SDE_RANGING_REQUIRED(_sde)	((_sde)->control & NAN_SDE_CF_RANGING_REQUIRED)
#define NAN_SDE_RANGE_PRESENT(_sde)	((_sde)->control & NAN_SDE_CF_RANGE_PRESENT)
#define NAN_SDE_SVC_UPD_IND_PRESENT(_sde)	((_sde)->control & NAN_SDE_CF_SVC_UPD_IND_PRESENT)
#define NAN_SDE_LIFE_COUNT_FOR_PUB_RX(_sde)     (_sde & NAN_SDE_CF_LIFE_CNT_PUB_RX)

/* nan2 security */

/*
 * Cipher suite information Attribute.
 * WFA Tech. Spec ver 1.0.r21 (section 10.7.24.2)
 * Bit 0 is 0 for 4 PTKSA replay counters
 * Bit 0 is 1 for 16 PTKSA replay counters
 * Bit 1 and 2:
 * 00: GTKSA, IGTKSA, BIGTKSA are not supported;
 * 01: GTKSA and IGTKSA are supported, and BIGTKSA is not supported;
 * 10: GTKSA, IGTKSA, and BIGTKSA are supported;
 * 11: Reserved;
 * Bit 3 is 0 for 4 GTKSA replay counters, if GTKSA is supported
 * Bit 3 is 1 for 16 GTKSA replay counters, if GTKSA is supported
 * Bit 4 is 0: BIP-CMAC-128 is selected for transmit, if IGTKSA or BIGTKSA is supported
 * Bit 4 is 1: BIP-GMAC-256 is selected for transmit, if IGTKSA or BIGTKSA is supported
 * Bit 5 is 0 if IRK is not supported
 * Bit 5 is 1 if IRK is supported
 * Bit 7 is reserved
 */
#define NAN_SEC_CIPHER_SUITE_CAP_REPLAY_4	0u
#define NAN_SEC_CIPHER_SUITE_CAP_REPLAY_16	(1u << 0u)

#if defined(WL_NAN_GAF_PROTECT) || defined(NAN_GTK)
/* Defines for GTK, IGTK and BIGTK */
/*
 * Bit 1 and 2:
 * 00: GTKSA, IGTKSA, BIGTKSA are not supported;
 * 01: GTKSA and IGTKSA are supported, and BIGTKSA is not supported;
 * 10: GTKSA, IGTKSA, and BIGTKSA are supported;
 * 11: Reserved;
 */
#define NAN_SEC_CIPHER_SUITE_CAP_DIS_GTK_IGTK_BIGTK     (0 << 1)
#define NAN_SEC_CIPHER_SUITE_CAP_DIS_BIGTK		(1 << 1)
#define NAN_SEC_CIPHER_SUITE_CAP_ENAB_GTK_IGTK_BIGTK	(1 << 2)

/*
 * Bit 3 is 0 for 4 GTKSA replay counters, if GTKSA is supported
 * Bit 3 is 1 for 16 GTKSA replay counters, if GTKSA is supported
 */
#define NAN_SEC_CIPHER_SUITE_CAP_GTK_REPLAY_4		(0 << 4)
#define NAN_SEC_CIPHER_SUITE_CAP_GTK_REPLAY_16		(1 << 4)

/*
 * Bit 4 is 0: BIP-CMAC-128 is selected for transmit, if IGTKSA or BIGTKSA is supported
 * Bit 4 is 1: BIP-GMAC-256 is selected for transmit, if IGTKSA or BIGTKSA is supported
 */
#define NAN_SEC_CIPHER_SUITE_CAP_BIP_CMAC_128		(0)
#define NAN_SEC_CIPHER_SUITE_CAP_BIP_GMAC_256		(1 << 5)

#define NAN_SEC_BIP_ENABLED(cap)	((cap) & \
	(NAN_SEC_CIPHER_SUITE_CAP_ENAB_GTK_IGTK_BIGTK | \
	NAN_SEC_CIPHER_SUITE_CAP_DIS_BIGTK))

#define NAN_SEC_BIP_CAP_TO_CIPER(cap)	\
	(((cap) & NAN_SEC_CIPHER_SUITE_CAP_BIP_GMAC_256) ?\
		 CRYPTO_ALGO_BIP_GMAC256 : CRYPTO_ALGO_BIP)
#define NAN_SEC_IGTK_ENABLED(cap)	NAN_SEC_BIP_ENABLED(cap)

#define NAN_SEC_BIGTK_ENABLED(cap)	((cap) & \
	(NAN_SEC_CIPHER_SUITE_CAP_ENAB_GTK_IGTK_BIGTK))
#endif /* WL_NAN_GAF_PROTECT || NAN_GTK */

/* enum security algo. */
enum nan_sec_csid {
	NAN_SEC_ALGO_NONE			= 0,	/* default, open */
	NAN_SEC_ALGO_NCS_SK_CCM_128 = 1,     /* CCMP 128 */
	NAN_SEC_ALGO_NCS_SK_GCM_256 = 2,     /* GCMP 256 */
	NAN_SEC_ALGO_NCS_PK_CCM_128 = 3,     /* CCMP 128 */
	NAN_SEC_ALGO_NCS_PK_GCM_256 = 4,     /* GCMP 256 */
	NAN_SEC_ALGO_NCS_GK_CCM_128 = 5,     /* CCMP 128 */
	NAN_SEC_ALGO_NCS_GK_GCM_256 = 6,     /* GCMP 256 */
	NAN_SEC_ALGO_NCS_PK_PASN_CCM_128	= 7,	/* CCMP 128, NAN R4 */
	NAN_SEC_ALGO_NCS_PK_PASN_GCM_256	= 8,	/* GCMP 256, NAN R4 */
	NAN_SEC_ALGO_LAST
};
typedef uint8 nan_sec_csid_e;

/* nan2 cipher suite attribute field */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_sec_cipher_suite_field_s {
	uint8 cipher_suite_id;
	uint8 inst_id;	/* Instance Id */
} BWL_POST_PACKED_STRUCT wifi_nan_sec_cipher_suite_field_t;

/* nan2 cipher suite information attribute field */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_sec_cipher_suite_info_attr_s {
	uint8 attr_id;	/* 0x22 - NAN_ATTR_CIPHER_SUITE_INFO */
	uint16 len;
	uint8 capabilities;
	uint8 var[];	/* cipher suite list */
} BWL_POST_PACKED_STRUCT wifi_nan_sec_cipher_suite_info_attr_t;

/* Currently cipher suite list supports maximum of 2 entries */
#define NAN_SEC_CIPHER_SUITE_LIST_MAX_ENTRIES	2u
#define NAN_SEC_CIPHER_SUITE_FIELD_LEN		2u
#define NAN_SEC_CIPHER_SUITE_INFO_LEN_MIN	1u /* capabilities field only */
#define NAN_SEC_CIPHER_SUITE_INFO_LEN_MAX	(NAN_SEC_CIPHER_SUITE_INFO_LEN_MIN + \
		(NAN_SEC_CIPHER_SUITE_FIELD_LEN * NAN_SEC_CIPHER_SUITE_LIST_MAX_ENTRIES))

/*
 * Security context identifier attribute
 * WFA Tech. Spec ver 1.0.r21 (section 10.7.24.4)
 */

#define NAN_SEC_CTX_ID_TYPE_PMKID   (1 << 0)

/* nan2 security context identifier attribute field */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_sec_ctx_id_field_s {
	uint16 sec_ctx_id_type_len;	/* length of security ctx identifier */
	uint8 sec_ctx_id_type;
	uint8 inst_id;	/* Instance Id */
	uint8 var[];	/* security ctx identifier */
} BWL_POST_PACKED_STRUCT wifi_nan_sec_ctx_id_field_t;

/* nan2 security context identifier info attribute field */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_sec_ctx_id_info_attr_s {
	uint8 attr_id;	/* 0x23 - NAN_ATTR_SEC_CTX_ID_INFO */
	uint16 len;
	uint8 var[];	/* security context identifier  list */
} BWL_POST_PACKED_STRUCT wifi_nan_sec_ctx_id_info_attr_t;

/*
 * Nan shared key descriptor attribute
 * WFA Tech. Spec ver 23
 */

#define NAN_SEC_NCSSK_DESC_REPLAY_CNT_LEN	8u
#define NAN_SEC_NCSSK_DESC_KEY_NONCE_LEN	32u
#define NAN_SEC_NCSSK_DESC_KEY_IV_LEN		16u
#define NAN_SEC_NCSSK_DESC_KEY_RSC_LEN		8u

/* nan shared key descriptor attr field */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_sec_ncssk_key_desc_attr_s {
	uint8 attr_id;	/* 0x24 - NAN_ATTR_SHARED_KEY_DESC */
	uint16 len;
	uint8 inst_id;  /* Publish service instance ID */
	uint8 desc_type;
	uint16 key_info;
	uint16 key_len;
	uint8 key_replay_cntr[NAN_SEC_NCSSK_DESC_REPLAY_CNT_LEN];
	uint8 key_nonce[NAN_SEC_NCSSK_DESC_KEY_NONCE_LEN];
	uint8 key_iv[NAN_SEC_NCSSK_DESC_KEY_IV_LEN];
	uint8 key_rsc[NAN_SEC_NCSSK_DESC_KEY_RSC_LEN];
	uint8 reserved[8];
	uint8 mic[];  /* mic + key data len + key data */
} BWL_POST_PACKED_STRUCT wifi_nan_sec_ncssk_key_desc_attr_t;

/* Key Info fields */
#define NAN_SEC_NCSSK_DESC_MASK			0x7
#define NAN_SEC_NCSSK_DESC_SHIFT		0
#define NAN_SEC_NCSSK_DESC_KEY_TYPE_MASK	0x8
#define NAN_SEC_NCSSK_DESC_KEY_TYPE_SHIFT	3
#define NAN_SEC_NCSSK_DESC_KEY_INSTALL_MASK	0x40
#define NAN_SEC_NCSSK_DESC_KEY_INSTALL_SHIFT	6
#define NAN_SEC_NCSSK_DESC_KEY_ACK_MASK		0x80
#define NAN_SEC_NCSSK_DESC_KEY_ACK_SHIFT	7
#define NAN_SEC_NCSSK_DESC_KEY_MIC_MASK		0x100
#define NAN_SEC_NCSSK_DESC_KEY_MIC_SHIFT	8
#define NAN_SEC_NCSSK_DESC_KEY_SEC_MASK		0x200
#define NAN_SEC_NCSSK_DESC_KEY_SEC_SHIFT	9
#define NAN_SEC_NCSSK_DESC_KEY_ERR_MASK		0x400
#define NAN_SEC_NCSSK_DESC_KEY_ERR_SHIFT	10
#define NAN_SEC_NCSSK_DESC_KEY_REQ_MASK		0x800
#define NAN_SEC_NCSSK_DESC_KEY_REQ_SHIFT	11
#define NAN_SEC_NCSSK_DESC_KEY_ENC_KEY_MASK	0x1000
#define NAN_SEC_NCSSK_DESC_KEY_ENC_KEY_SHIFT	12
#define NAN_SEC_NCSSK_DESC_KEY_SMK_MSG_MASK	0x2000
#define NAN_SEC_NCSSK_DESC_KEY_SMK_MSG_SHIFT	13

/* Key Info get & set macros */
#define NAN_SEC_NCSSK_KEY_DESC_VER_GET(_key_info)	\
	(((_key_info) & NAN_SEC_NCSSK_DESC_MASK) >> NAN_SEC_NCSSK_DESC_SHIFT)
#define NAN_SEC_NCSSK_KEY_DESC_VER_SET(_val, _key_info)	\
	do {(_key_info) &= ~NAN_SEC_NCSSK_DESC_MASK; \
		(_key_info) |= (((_val) << NAN_SEC_NCSSK_DESC_SHIFT) & \
		NAN_SEC_NCSSK_DESC_MASK);} while (0)
#define NAN_SEC_NCSSK_DESC_KEY_TYPE_GET(_key_info)	\
	(((_key_info) & NAN_SEC_NCSSK_DESC_KEY_TYPE_MASK) >> NAN_SEC_NCSSK_DESC_KEY_TYPE_SHIFT)
#define NAN_SEC_NCSSK_DESC_KEY_TYPE_SET(_val, _key_info)	\
	do {(_key_info) &= ~NAN_SEC_NCSSK_DESC_KEY_TYPE_MASK; \
		(_key_info) |= (((_val) << NAN_SEC_NCSSK_DESC_KEY_TYPE_SHIFT) & \
		NAN_SEC_NCSSK_DESC_KEY_TYPE_MASK);} while (0)
#define NAN_SEC_NCSSK_DESC_KEY_INSTALL_GET(_key_info)	\
	(((_key_info) & NAN_SEC_NCSSK_DESC_KEY_INSTALL_MASK) >> \
	NAN_SEC_NCSSK_DESC_KEY_INSTALL_SHIFT)
#define NAN_SEC_NCSSK_DESC_KEY_INSTALL_SET(_val, _key_info)	\
	do {(_key_info) &= ~NAN_SEC_NCSSK_DESC_KEY_INSTALL_MASK; \
		(_key_info) |= (((_val) << NAN_SEC_NCSSK_DESC_KEY_INSTALL_SHIFT) & \
		NAN_SEC_NCSSK_DESC_KEY_INSTALL_MASK);} while (0)
#define NAN_SEC_NCSSK_DESC_KEY_ACK_GET(_key_info)	\
	(((_key_info) & NAN_SEC_NCSSK_DESC_KEY_ACK_MASK) >> NAN_SEC_NCSSK_DESC_KEY_ACK_SHIFT)
#define NAN_SEC_NCSSK_DESC_KEY_ACK_SET(_val, _key_info)	\
	do {(_key_info) &= ~NAN_SEC_NCSSK_DESC_KEY_ACK_MASK; \
		(_key_info) |= (((_val) << NAN_SEC_NCSSK_DESC_KEY_ACK_SHIFT) & \
		NAN_SEC_NCSSK_DESC_KEY_ACK_MASK);} while (0)
#define NAN_SEC_NCSSK_DESC_KEY_MIC_GET(_key_info)	\
	(((_key_info) & NAN_SEC_NCSSK_DESC_KEY_MIC_MASK) >> NAN_SEC_NCSSK_DESC_KEY_MIC_SHIFT)
#define NAN_SEC_NCSSK_DESC_KEY_MIC_SET(_val, _key_info)	\
	do {(_key_info) &= ~NAN_SEC_NCSSK_DESC_KEY_MIC_MASK; \
		(_key_info) |= (((_val) << NAN_SEC_NCSSK_DESC_KEY_MIC_SHIFT) & \
		NAN_SEC_NCSSK_DESC_KEY_MIC_MASK);} while (0)
#define NAN_SEC_NCSSK_DESC_KEY_SEC_GET(_key_info)	\
	(((_key_info) & NAN_SEC_NCSSK_DESC_KEY_SEC_MASK) >> NAN_SEC_NCSSK_DESC_KEY_SEC_SHIFT)
#define NAN_SEC_NCSSK_DESC_KEY_SEC_SET(_val, _key_info)	\
	do {(_key_info) &= ~NAN_SEC_NCSSK_DESC_KEY_SEC_MASK; \
		(_key_info) |= (((_val) << NAN_SEC_NCSSK_DESC_KEY_SEC_SHIFT) & \
		NAN_SEC_NCSSK_DESC_KEY_SEC_MASK);} while (0)
#define NAN_SEC_NCSSK_DESC_KEY_ERR_GET(_key_info)	\
	(((_key_info) & NAN_SEC_NCSSK_DESC_KEY_ERR_MASK) >> NAN_SEC_NCSSK_DESC_KEY_ERR_SHIFT)
#define NAN_SEC_NCSSK_DESC_KEY_ERR_SET(_val, _key_info)	\
	do {(_key_info) &= ~NAN_SEC_NCSSK_DESC_KEY_ERR_MASK; \
		(_key_info) |= (((_val) << NAN_SEC_NCSSK_DESC_KEY_ERR_SHIFT) & \
		NAN_SEC_NCSSK_DESC_KEY_ERR_MASK);} while (0)
#define NAN_SEC_NCSSK_DESC_KEY_REQ_GET(_key_info)	\
	(((_key_info) & NAN_SEC_NCSSK_DESC_KEY_REQ_MASK) >> NAN_SEC_NCSSK_DESC_KEY_REQ_SHIFT)
#define NAN_SEC_NCSSK_DESC_KEY_REQ_SET(_val, _key_info)	\
	do {(_key_info) &= ~NAN_SEC_NCSSK_DESC_KEY_REQ_MASK; \
		(_key_info) |= (((_val) << NAN_SEC_NCSSK_DESC_KEY_REQ_SHIFT) & \
		NAN_SEC_NCSSK_DESC_KEY_REQ_MASK);} while (0)
#define NAN_SEC_NCSSK_DESC_KEY_ENC_KEY_GET(_key_info)	\
	(((_key_info) & NAN_SEC_NCSSK_DESC_KEY_ENC_KEY_MASK) >> \
	NAN_SEC_NCSSK_DESC_KEY_ENC_KEY_SHIFT)
#define NAN_SEC_NCSSK_DESC_KEY_ENC_KEY_SET(_val, _key_info)	\
	do {(_key_info) &= ~NAN_SEC_NCSSK_DESC_KEY_ENC_KEY_MASK; \
		(_key_info) |= (((_val) << NAN_SEC_NCSSK_DESC_KEY_ENC_KEY_SHIFT) & \
		NAN_SEC_NCSSK_DESC_KEY_ENC_KEY_MASK);} while (0)
#define NAN_SEC_NCSSK_DESC_KEY_SMK_MSG_GET(_key_info)	\
	(((_key_info) & NAN_SEC_NCSSK_DESC_KEY_SMK_MSG_MASK) >> \
	NAN_SEC_NCSSK_DESC_KEY_SMK_MSG_SHIFT)
#define NAN_SEC_NCSSK_DESC_KEY_SMK_MSG_SET(_val, _key_info)	\
	do {(_key_info) &= ~NAN_SEC_NCSSK_DESC_KEY_SMK_MSG_MASK; \
		(_key_info) |= (((_val) << NAN_SEC_NCSSK_DESC_KEY_SMK_MSG_SHIFT) & \
		NAN_SEC_NCSSK_DESC_KEY_SMK_MSG_MASK);} while (0)

#define NAN_SEC_NCSSK_IEEE80211_KDESC_TYPE	2	/* IEEE 802.11 Key Descriptor Type */
#define NAN_SEC_NCSSK_KEY_DESC_VER			0	/* NCSSK-128/256 */
#define NAN_SEC_NCSSK_KEY_TYPE_PAIRWISE		1	/* Pairwise */
#define NAN_SEC_NCSSK_LIFETIME_KDE			7	/* Lifetime KDE type */

/* TODO include MTK related attributes */

/* NAN Multicast service group(NMSG) definitions */
/* Length of NMSG_ID -- (NDI * 2^16 + pub_id * 2^8 + Random_factor) */
#define NAN_NMSG_ID_LEN                         8

#define NAN_NMSG_TYPE_MASK			0x0F
#define NMSG_ATTR_TYPE_STATUS_REQUEST		0x00
#define NMSG_ATTR_TYPE_STATUS_RESPONSE		0x01
#define NMSG_ATTR_TYPE_STATUS_CONFIRM		0x02
#define NMSG_ATTR_TYPE_STATUS_SEC_INSTALL	0x03
#define NMSG_ATTR_TYPE_STATUS_TERMINATE		0x04
#define NMSG_ATTR_TYPE_STATUS_IMPLICIT_ENROL	0x05

#define NMSG_ATTR_TYPE_STATUS_CONTINUED	        0x00
#define NMSG_ATTR_TYPE_STATUS_ACCEPTED	        0x10
#define NMSG_ATTR_TYPE_STATUS_REJECTED	        0x20

#define NMSG_CTRL_PUB_ID_PRESENT                0x0001
#define NMSG_CTRL_NMSG_ID_PRESENT               0x0002
#define NMSG_CTRL_SECURITY_PRESENT              0x0004
#define NMSG_CTRL_MANY_TO_MANY_PRESENT          0x0008
#define NMSG_CTRL_SVC_INFO_PRESENT              0x0010

/* NMSG attribute */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_nmsg_attr_s {
	uint8 id; /* Attribute ID - 0x11 */
	uint16 len; /* Length including pubid, NMSGID and svc info */
	uint8 dialog_token;
	uint8 type_status; /* Type and Status field byte */
	uint8 reason_code;
	uint8 mc_id; /* Multicast id similar to NDPID */
	uint8 nmsg_ctrl; /* NMSG control field */
	/* Optional publish id, NMSGID and svc info are included in var[] */
	uint8 var[0];
} BWL_POST_PACKED_STRUCT wifi_nan_nmsg_attr_t;

#define NMSG_ATTR_MCAST_SCHED_MAP_ID_MASK     0x1E
#define NMSG_ATTR_MCAST_SCHED_MAP_ID_SHIFT    1
#define NMSG_ATTR_MCAST_SCHED_TIME_MAP_MASK   0x20
#define NMSG_ATTR_MCAST_SCHED_TIME_MAP_SHIFT  5

/* NAN Multicast Schedule atribute structure */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_mcast_sched_attr_s {
	uint8 id; /* 0x16 */
	uint16 len;
	uint8 nmsg_id[NAN_NMSG_ID_LEN];
	uint8 attr_cntrl;
	uint8 sched_own[ETHER_ADDR_LEN];
	uint8 var[]; /* multicast sched entry list (schedule_entry_list) */
} BWL_POST_PACKED_STRUCT wifi_nan_mcast_sched_attr_t;


/* FAC Channel Entry  (section 10.7.19.1.5) */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_fac_chan_entry_s {
	uint8 oper_class;		/* Operating Class */
	uint16 chan_bitmap;		/* Channel Bitmap */
	uint8 primary_chan_bmp;		/* Primary Channel Bitmap */
	uint16 aux_chan;			/* Auxiliary Channel bitmap */
} BWL_POST_PACKED_STRUCT wifi_nan_fac_chan_entry_t;

/* TODO move this from nan.h */
#define NAN_ALL_NAN_MGMT_FRAMES (NAN_FRM_SCHED_AF | \
	NAN_FRM_NDP_AF | NAN_FRM_NDL_AF | \
	NAN_FRM_DISC_BCN | NAN_FRM_SYNC_BCN | \
	NAN_FRM_SVC_DISC | NAN_FRM_RNG_REQ_AF | \
	NAN_FRM_RNG_RESP_AF | NAN_FRM_RNG_REPORT_AF | \
	NAN_FRM_RNG_TERM_AF)

/* Generic NAN attribute data strucutre */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_attr_s {
	uint8 id;		/* attribute id */
	uint16 len;		/* length following */
	uint8 data[];		/* attribute data */
} BWL_POST_PACKED_STRUCT wifi_nan_attr_t;

/* NIRA cipher versions */

/* Version 0 means 128-bit NIK, 64-bit Nonce, 64-bit Tag, HMAC-SHA-256 */
#define NAN_MAC_CIPHER_VERSION_0	0u

/* NIRA (NAN Identity Resolution Attribute) */
typedef BWL_PRE_PACKED_STRUCT struct wifi_nan_nira_attr_s {
	uint8 id;		/* attribute id */
	uint16 len;		/* length following */
	uint8 cipher_version;	/* cipher version */

	/* Nonce and Tag lengths are determined based on the cipher_verison */
	/* variable Nonce */
	/* variable Tag */
} BWL_POST_PACKED_STRUCT wifi_nan_nira_attr_t;

#define NAN_SEC_NCS_SK_PMKID_CONST	"NAN PMK Name"
#define NAN_SEC_NCS_SK_PTK_CONST	"NAN Pairwise key expansion"
#define NAN_SEC_NCS_PK_KEK_CONST	"NAN Management KEK Derivation"
#define NAN_SEC_NCS_PK_PMK_CONST	"NDP PMK Derivation"

#define NAN_IDENTITY_KEY_LENGTH	16u
/* NIK KDE */
typedef BWL_PRE_PACKED_STRUCT struct {
	uint8	cipher;
	uint8	nik[];
} BWL_POST_PACKED_STRUCT nan_identity_key_t;

/* Lifetime KDE */
typedef BWL_PRE_PACKED_STRUCT struct {
	uint16	key_bitmap;
	uint32	lifetime;
} BWL_POST_PACKED_STRUCT nan_key_lifetime_t;

#define NAN_KEY_DATA_SUBTYPE_NIK		36
#define NAN_KEY_DATA_SUBTYPE_LIFETIME		37

/* This marks the end of a packed structure section. */
#include <packed_section_end.h>

#endif /* _NAN_H_ */