summaryrefslogtreecommitdiff
path: root/nfclib/nfc_p2p.h
blob: d0a7136e0ea436c8b34a0de20fdb93f3696b4dc5 (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
//*****************************************************************************
//
// nfc_p2p.h - contains P2P State Machine NDEF P2P Record Type Structures
//
// Copyright (c) 2014 Texas Instruments Incorporated.  All rights reserved.
// Software License Agreement
// 
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
// 
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
// 
// This is part of revision 2.1.0.12573 of the Tiva Firmware Development Package.
//
//*****************************************************************************
#ifndef __NFC_P2P_H__
#define __NFC_P2P_H__

//*****************************************************************************
//
//! \addtogroup nfc_p2p_api
//! @{
//
//*****************************************************************************

//*****************************************************************************
//
// NFC Protocol Headers
//
//*****************************************************************************
#include "nfc_f.h"
#include "nfc_dep.h"
#include "llcp.h"
#include "snep.h"

//*****************************************************************************
//
// TRF7970 Header
//
//*****************************************************************************
#include "trf79x0.h"

//*****************************************************************************
//
//! Enumeration for 4 possible states for NFC P2P State Machine.
//
//*****************************************************************************
typedef enum {
    //
    //! Polling/Listening for SENSF_REQ / SENSF_RES.
    //
    NFC_P2P_PROTOCOL_ACTIVATION = 0,

    //
    //! Setting the NFCIDs and bit rate
    //
    NFC_P2P_PARAMETER_SELECTION,

    //
    //! Data exchange using the LLCP layer
    //
    NFC_P2P_DATA_EXCHANGE_PROTOCOL,

    //
    //! Technology deactivation
    //
    NFC_P2P_DEACTIVATION

} tNFCP2PState;

//*****************************************************************************
//
//! This structure defines the status of the received payload.
//
//*****************************************************************************
typedef struct{

    //
    //! SNEP RX Packet Status
    //
    tPacketStatus eDataReceivedStatus;

    //
    //! SNEP Number of bytes received
    //
    uint8_t ui8DataReceivedLength;

    //
    //! Pointer to data received
    //
    uint8_t *pui8RxDataPtr;

}sNFCP2PRxStatus;

//*****************************************************************************
//
// Programmers Note: NDEF message layout
//
// The fields in an NDEF header are as follows:
//  ______________________________
// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0|  Notes:
// |------------------------------|
// | MB| ME| CF| SR| IL|    TNF   |  NDEF StatusByte
// |------------------------------|
// |        TYPE_LENGTH           |  1 byte, hex value
// |------------------------------|
// |        PAYLOAD_LENGTH        |  1 or 4 bytes (determined by SR) (LSB first)
// |------------------------------|
// |        ID_LENGTH             |  0 or 1 bytes (determined by IL)
// |------------------------------|
// |        TYPE                  |  2 or 5 bytes (determined by TYPE_LENGTH)
// |------------------------------|
// |        ID                    |  0 or 1 byte  (determined by IL & ID_LENGTH)
// |------------------------------|
// |        PAYLOAD               |  X bytes (determined by PAYLOAD_LENGTH)
// |------------------------------|
// NDEF messages NDEF messages can be considered as two parts:
// The Header (everything except the last field), and the Payload.
//
// **********
//   HEADER
// **********
// The Header encompases Everything in the above diagram except the PAYLOAD
// The Header can vary in length from 5-13 bytes.
// The PAYLOAD_LENGTH, ID_LENGTH, ID, and TYPE fields can all very in length.
//
// Field Name      |   Length Depends On | Length
// ------------------------------------------------
// PAYLOAD LENGTH  |   SR                | SR = 1 => 1 byte , SR = 0 => 4 bytes
// ID_LENGTH       |   IL                | IL = 0 (if IL = 0 Both ID_LENGTH and
//                                                  ID fields are excluded.
//                                                  If IL = 1 then ID_LENGTH
//                                                  exists. If ID_LENGTH = 0x0
//                                                  then the ID field is
//                                                  not included)
// TYPE            |   TYPE_LENGTH       | 2-5 bytes (hex value of TYPE_LENGTH)
//                                               (In special cases there can be
//                                                a TYPE_LENGTH of 0, in which
//                                                case there is no TYPE field.)
//
// Note: PAYLOAD_LENGTH only gives the length of the PAYLOAD in its message.
//       The PAYLOAD_LENGTH does NOT give the length of the record across
//       multiple messages..
//
// ***********
//   PAYLOAD
// ***********
// The Payload can have a wide range of formats depending on the TNF and TYPE
// specified. (IE a TNF of 0x01 aka WELL_KNOWN_TYPE and a TYPE of 'T' would
// indicate a plain text payload, which has its own syntax). The user can even
// implement their own PAYLOAD type, providing handlers are provided on both the
// sending and receiving devices.
//
//*****************************************************************************

//*****************************************************************************
//
// NDEF message header definitions
// SET macros are used to set the bit (encoder)
// GET macros are used to read the bit (decoder)
//
//*****************************************************************************

//
//! This macro is used to set the MB field in the StatusByte of the NFC message header by
//! shifting a bit into position. This define should be ORed together with other StatusByte
//! Fields.
//!
//! \param ui8x is the binary value to be shifted into place
//!
//! \b Example: Set the MB field in a StatusByte
//!
//! <tt>sNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte |
//! NDEF_STATUSBYTE_SET_MB(0x1) </tt>
//!
//! \b Example: Clear the MB field in a StatusByte
//!
//! <tt>sNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte &
//! NDEF_STATUSBYTE_SET_MB(0x0) </tt>
//!
//
#define NDEF_STATUSBYTE_SET_MB(ui8x)         ((ui8x & 0x01) << 7)

//
//! This macro is used to set the ME field in the StatusByte of the NFC message
//! header by shifting a bit into position. This define should be ORed together
//! with other StatusByte Fields.
//!
//! \param ui8x is the binary value to be shifted into place
//!
//! \b Example: Set the ME field in a StatusByte
//!
//! <tt>sNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte |
//! NDEF_STATUSBYTE_SET_ME(0x1) </tt>
//!
//! \b Example: Clear the ME field in a StatusByte
//!
//! <tt>sNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte &
//! NDEF_STATUSBYTE_SET_ME(0x0) </tt>
//!
//
#define NDEF_STATUSBYTE_SET_ME(ui8x)         ((ui8x & 0x01) << 6)

//
//! This Macro is used to set the CF field in the StatusByte of the NFC message
//! header by shifting a bit into position. This define should be ORed together
//! with other StatusByte Fields.
//!
//! \param ui8x is the binary value to be shifted into place
//!
//! \b Example: Set the CF field in a StatusByte
//!
//! <tt>sNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte |
//! NDEF_STATUSBYTE_SET_CF(0x1) </tt>
//!
//! \b Example: Clear the CF field in a StatusByte
//!
//! <tt>sNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte &
//! NDEF_STATUSBYTE_SET_CF(0x0) </tt>
//!
//
#define NDEF_STATUSBYTE_SET_CF(ui8x)         ((ui8x & 0x01) << 5)

//
//! This macro is used to set the SR field in the StatusByte of the NFC message
//! header by shifting a bit into position. This define should be ORed together
//! with other StatusByte Fields.
//!
//! \param ui8x is the binary value to be shifted into place
//!
//! \b Example: Set the SR field in a StatusByte
//!
//! <tt>sNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte |
//! NDEF_STATUSBYTE_SET_SR(0x1) </tt>
//!
//! \b Example: Clear the SR field in a StatusByte
//!
//! <tt>sNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte &
//! NDEF_STATUSBYTE_SET_SR(0x0) </tt>
//!
//
#define NDEF_STATUSBYTE_SET_SR(ui8x)         ((ui8x & 0x01) << 4)

//
//! This macro is used to set the IL field in the StatusByte of the NFC message header by
//! shifting a bit into position. This define should be ORed together with other StatusByte
//! Fields.
//!
//! \param ui8x is the binary value to be shifted into place
//!
//! \b Example: Set the IL field in a StatusByte
//!
//! <tt>sNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte |
//! NDEF_STATUSBYTE_SET_IL(0x1) </tt>
//!
//! \b Example: Clear the IL field in a StatusByte
//!
//! <tt>sNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte &
//! NDEF_STATUSBYTE_SET_IL(0x0) </tt>
//!
//
#define NDEF_STATUSBYTE_SET_IL(ui8x)         ((ui8x & 0x01) << 3)

//
//! This macro is used to set the TNF field in the StatusByte of the NFC message
//! header by shifting a bit into position. This define should be ORed together
//! with other StatusByte Fields.
//!
//! \param ui8x is the 3-bit value to be shifted into place
//!
//! \b Example: Set the TNF field to Well Known Type in a StatusByte
//!
//! <tt>NsNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte |
//! NDEF_STATUSBYTE_SET_TNF(0x1) </tt>
//!
//! \b Example: Set the TNF field to Unknown Type in a StatusByte
//!
//! <tt>sNDEFMessage.sStatusByte = sNDEFMessage.sStatusByte &
//! NDEF_STATUSBYTE_SET_TNF(0x5) </tt>
//!
//
#define NDEF_STATUSBYTE_SET_TNF(ui8x)         ((ui8x & 0x07) << 0)

//
//! Macro used to get the MB field value from the StatusByte of the NFC message
//! header.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! \b Example: Get the MB field from the StatusByte into variable x
//!
//! <tt>x = NDEF_STATUSBYTE_GET_MB(sNDEFMessageData.sStatusByte) </tt>
//!
//
#define NDEF_STATUSBYTE_GET_MB(ui8x)         ((ui8x >> 7) & 0x01)

//
//! Macro used to get the ME field value from the StatusByte of the NFC message
//! header.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! \b Example: Get the ME field from the StatusByte into variable x
//!
//! <tt>x = NDEF_STATUSBYTE_GET_ME(sNDEFMessageData.sStatusByte) </tt>
//!
//
#define NDEF_STATUSBYTE_GET_ME(ui8x)         ((ui8x >> 6) & 0x01)

//
//! Macro used to get the CF field value from the StatusByte of the NFC message
//! header.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! \b Example: Get the CF field from the StatusByte into variable x
//!
//! <tt>x = NDEF_STATUSBYTE_GET_CF(sNDEFMessageData.sStatusByte) </tt>
//!
//
#define NDEF_STATUSBYTE_GET_CF(ui8x)         ((ui8x >> 5) & 0x01)

//
//! Macro used to get the SR field value from the StatusByte of the NFC message
//! header.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! \b Example: Get the SR field from the StatusByte into variable x
//!
//! <tt>x = NDEF_STATUSBYTE_GET_SR(sNDEFMessageData.sStatusByte) </tt>
//!
//
#define NDEF_STATUSBYTE_GET_SR(ui8x)         ((ui8x >> 4) & 0x01)

//
//! Macro used to get the IL field value from the StatusByte of the NFC message
//! header.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! \b Example: Get the IL field from the StatusByte into variable x
//!
//! <tt>x = NDEF_STATUSBYTE_GET_IL(sNDEFMessageData.sStatusByte) </tt>
//!
//
#define NDEF_STATUSBYTE_GET_IL(ui8x)         ((ui8x >> 3) & 0x01)

//
//! Macro used to get the TNF field value from the StatusByte of the NFC message
//! header.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! \b Example: Get the TNF field from the StatusByte into variable x
//!
//! <tt>x = NDEF_STATUSBYTE_GET_TNF(sNDEFMessageData.sStatusByte) </tt>
//!
//
#define NDEF_STATUSBYTE_GET_TNF(ui8x)         ((ui8x >> 0) & 0x07)

//*****************************************************************************
//
// Defines to check Header StatusByte field meaning. Some cases left out
// because they are irrelevant (ie only care when MB is 1 or not 1, dont care
// about 0)
//
//*****************************************************************************

//
//! Flag used to check the MB field in the StatusByte. If MB is set then this is
//! the first Record.
//!
//! \b Example: Check for Message Begin flag
//!
//! <tt>if(NDEF_STATUSBYTE_GET_MB(ui8StatusByte) ==
//! NDEF_STATUSBYTE_MB_FIRSTBYTE){} </tt>
//
#define NDEF_STATUSBYTE_MB_FIRSTBYTE        1

//
//! Flag used to check the ME field in the StatusByte. If ME is set, then this
//! is the last Record.
//!
//! \b Example: Check for Message End flag
//!
//! <tt>if(NDEF_STATUSBYTE_GET_ME(ui8StatusByte) == NDEF_STATUSBYTE_ME_LASTBYTE)
//!         {} </tt>
//
#define NDEF_STATUSBYTE_ME_LASTBYTE         1

//
//! Flag used to check the CF field in the StatusByte. If CF is set, then the
//! message is a chunked message spread out across multiple transactions.
//!
//! \b Example: Check for Chunked Flag
//!
//! <tt>if(NDEF_STATUSBYTE_GET_CF(ui8StatusByte) == NDEF_STATUSBYTE_CF_CHUNK)
//!         {} </tt>
//
#define NDEF_STATUSBYTE_CF_CHUNK            1

//
//! Flag used to check the SR field in the StatusByte. If SR is set, then
//! the message is a short record with a payload length field of 1 byte instead
//! of 4 bytes.
//!
//! \b Example: Check the Short Record flag
//!
//! <tt>if(NDEF_STATUSBYTE_GET_SR(ui8StatusByte) ==
//!         NDEF_STATUSBYTE_SR_1BYTEPAYLOADSIZE){} </tt>
//
#define NDEF_STATUSBYTE_SR_1BYTEPAYLOADSIZE         1

//
//! Flag used to check the SR field in the StatusByte. If SR is not set, then
//! the message is a normal record with a payload length field of 4 bytes
//! instead of 1 byte.
//!
//! \b Example: Check the Short Record flag
//!
//! <tt>if(NDEF_STATUSBYTE_GET_SR(ui8StatusByte) ==
//!         NDEF_STATUSBYTE_SR_4BYTEPAYLOADSIZE){} </tt>
//
#define NDEF_STATUSBYTE_SR_4BYTEPAYLOADSIZE         0

//
//! Flag used to check the IL field in the StatusByte. If IL is set, then the ID
//! and IDLength fields are present in the message.
//!
//! \b Example: Check for the presence of the ID Length and ID name field
//!
//! <tt>if(NDEF_STATUSBYTE_GET_IL(ui8StatusByte) ==
//!                                 NDEF_STATUSBYTE_IL_IDLENGTHPRESENT) {} </tt>
//
#define NDEF_STATUSBYTE_IL_IDLENGTHPRESENT         1

//
//! Flag used to check the IL field in the StatusByte. If IL is not set, then
//! there is no ID or IDLength fields included in the message.
//!
//! \b Example: Check for the presence of the ID Length and ID name field
//!
//! <tt>if(NDEF_STATUSBYTE_GET_IL(ui8StatusByte) ==
//!                                 NDEF_STATUSBYTE_IL_IDLENGTHABSENT) {} </tt>
//
#define NDEF_STATUSBYTE_IL_IDLENGTHABSENT         0

//*****************************************************************************
//
// Defines to set maximum field lengths in bytes
//
//*****************************************************************************

//
//! Maximum size of Type field in StatusByte. This define is used to declare the
//! length of the buffer in the structure and thus can be changed to allow
//! larger Type names.
//!
//! \b Example: Copy the Type from raw buffer to structure using
//!             NDEF_TYPE_MAXSIZE to prevent overflowing buffer in the
//!             structure
//!
//! <tt>
//! \verbatim
//! //
//! // Assume that TypeLength is already decoded from the raw buffer and is
//! // stored in sNDEFMessageData.ui8TypeLength. Assume ui8RawBuffer is a
//! // pointer to the beginning of the Type field in the raw data stream.
//! //
//! int x = 0;
//! for(x = 0; (x<NDEF_TYPE_MAXSIZE) & (x<sNDEFMessageData.ui8TypeLength); x++)
//! {
//!     sNDEFMessageData.pui8Type[x]=ui8RawBuffer[x];
//! }
//! \endverbatim
//! </tt>
//
#define NDEF_TYPE_MAXSIZE                   10           // can be changed

//
//! Maximum size of the ID field in StatusByte, which can be modified to support
//! larger ID names.
//!
//! \b Example: Copy the ID from the raw buffer to the structure using
//!             NDEF_ID_MAXSIZE to prevent overflowing buffer in the structure
//!
//! <tt>
//! \verbatim
//! //
//! // Assume IDLength already decoded from the raw buffer is stored in
//! // sNDEFMessageData.ui8IDLength. Assume ui8RawBuffer is a pointer to
//! // the beginning of the ID field in the raw data stream.
//! //
//! int x = 0;
//! for(x = 0; (x<NDEF_ID_MAXSIZE) & (x<sNDEFMessageData.ui8IDLength); x++)
//! {
//!     sNDEFMessageData.pui8pui8ID[x] = ui8RawBuffer[x];
//! }
//! \endverbatim
//! </tt>
//
#define NDEF_ID_MAXSIZE                     10           // can be changed

//*****************************************************************************
//
// Defines to check NDEF ID type
//
//*****************************************************************************

//
//! NFC Message TypeID hex representation for TEXT records.
//! 0x54 == 'T'   in UTF-8
//!
//! \b Example: Check if tag type is TEXT
//!
//! <tt>
//! \verbatim
//! //
//! // Assume the Tag Type has already decoded into sNDEFMessageData.pui8Type
//! //
//! if(sNDEFMessageData.pui8Type == NDEF_TYPE_TEXT)
//! {
//!     // The Tag is a TEXT record, handle it appropriately
//! }
//! \endverbatim
//! </tt>
//
#define NDEF_TYPE_TEXT                      0x54        // 'T'   in UTF-8

//
//! NFC Message TypeID hex representation for URI records.
//! 0x55 == 'U'   in UTF-8
//!
//! \b Example: Check if tag type is URI
//!
//! <tt>
//! \verbatim
//! //
//! // Assume the Tag Type has already decoded into sNDEFMessageData.pui8Type
//! //
//! if(sNDEFMessageData.pui8Type == NDEF_TYPE_URI)
//! {
//!     // The Tag is a URI record, handle it appropriately
//! }
//! \endverbatim
//! </tt>
//
#define NDEF_TYPE_URI                       0x55        // 'U'   in UTF-8

//
//! NFC Message TypeID hex representation for SMARTPOSTER records.
//! 0x5370 == "Sp"   in UTF-8
//!
//! \b Example: Check if tag type is SMARTPOSTER
//!
//! <tt>
//! \verbatim
//! //
//! // Assume the Tag Type has already decoded into sNDEFMessageData.pui8Type
//! //
//! if(sNDEFMessageData.pui8Type == NDEF_TYPE_SMARTPOSTER)
//! {
//!     // The Tag is a SMARTPOSTER record, handle it appropriately
//! }
//! \endverbatim
//! </tt>
//
#define NDEF_TYPE_SMARTPOSTER               0x5370      //"Sp"   in UTF-8

//
//! NFC Message TypeID hex representation for SIGNATURE records.
//! 0x536967 == "Sig"  in UTF-8
//!
//! \b Example: Check if tag type is SIGNATURE
//!
//! <tt>
//! \verbatim
//! //
//! // Assume the Tag Type has already decoded into sNDEFMessageData.pui8Type
//! //
//! if(sNDEFMessageData.pui8Type == NDEF_TYPE_SIGNATURE)
//! {
//!     // The Tag is a SIGNATURE record, handle it appropriately
//! }
//! \endverbatim
//! </tt>
//
#define NDEF_TYPE_SIGNATURE                 0x536967    //"Sig"  in UTF-8

//
//! NFC Message TypeID hex representation for SIZE records.
//! 0x73 == 's'   in UTF-8
//!
//! \b Example: Check if tag type is SIZE
//!
//! <tt>
//! \verbatim
//! //
//! // Assume the Tag Type has already decoded into sNDEFMessageData.pui8Type
//! //
//! if(sNDEFMessageData.pui8Type == NDEF_TYPE_SIZE)
//! {
//!     // The Tag is a SIZE record. Handle it appropriately
//! }
//! \endverbatim
//! </tt>
//
#define NDEF_TYPE_SIZE                      0x73        // 's'   in UTF-8

//
//! NFC Message TypeID hex representation for ACTION records.
//! 0x616374 == "act"  in UTF-8
//!
//! \b Example: Check if tag type is ACTION
//!
//! <tt>
//! \verbatim
//! //
//! // Assume the Tag Type has already decoded into sNDEFMessageData.pui8Type
//! //
//! if(sNDEFMessageData.pui8Type == NDEF_TYPE_ACTION)
//! {
//!     // The Tag is a ACTION record, handle it appropriately
//! }
//! \endverbatim
//! </tt>
//
#define NDEF_TYPE_ACTION                    0x616374    //"act"  in UTF-8



//*****************************************************************************
//
//! Enumeration for Type Name Format (TNF) field in NDEF header StatusByte.
//! TNF values are 3 bits. Most records are of the Well Known Type format
//! (0x01).
//
// TNF = Type Name Format: 3bit field, indicates structure of TYPE field
//          Acceptable Values are:
//          0x00 Empty
//          0x01 NFC Forum well-known type [NFC RTD]
//              NDEF Record Type    Description         Full URI Reference
//                      'Sp'        Smart Poster        urn:nfc:wkt:Sp
//                      'T'         Text                urn:nfc:wkt:T
//                      'U'         URI                 urn:nfc:wkt:U
//                      'Hr'        Handover Request    urn:nfc:wkt:Hr
//                      'Hs'        Handover Select     urn:nfc:wkt:Hs
//                      'Hc'        Handover Carrier    urn:nfc:wkt:Hc
//                      'Sig'       Signature           urn:nfc:wkt:Sig
//          0x02 Media-type as defined in RFC 2046 [RFC 2046]
//          0x03 Absolute URI as defined in RFC 3986 [RFC 3986]
//          0x04 NFC Forum external type [NFC RTD]
//          0x05 Unknown
//          0x06 Unchanged (used with single message across multiple chunks)
//          0x07 Reserved
//
//*****************************************************************************
typedef enum
{
    //
    //! Empty Format
    //
    TNF_EMPTY           = 0x00,

    //
    //! NFC Forum Well Known Type [NFC RTD]
    //
    TNF_WELLKNOWNTYPE   = 0x01,

    //
    //! Media-type as defined in RFC 2046 [RFC 2046]
    //
    TNF_MEDIA_TYPE      = 0x02,

    //
    //! Absolute URI as defined in RFC 3986 [RFC 3986]
    //
    TNF_ABSOLUTE_URI    = 0x03,

    //
    //! NFC Forum external type [NFC RTD]
    //
    TNF_EXTERNAL_TYPE   = 0x04,

    //
    //! Unknown
    //
    TNF_UNKNOWN         = 0x05,

    //
    //! Unchanged (used with single message across multiple chunks)
    //
    TNF_UNCHANGED       = 0x06,

    //
    //! Reserved
    //
    TNF_RESERVED        = 0x07
} tTNF;

//*****************************************************************************
//
//! NFC NDEF message header StatusByte structure. Included in this structure
//! are fields for Message Begin (MB), Message End (ME), Chunk Flag (CF), Short
//! Record (SR), IDLength (IL) and Type Name Format (TNF). The purpose of this
//! structure is to make the fields readily available for message processing.
//  ______________________________
// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0|
// |------------------------------|
// | MB| ME| CF| SR| IL|    TNF   |
// |------------------------------|
//
// MB = Message Begin : marks start of NDEF message
// ME = Message End   : marks end of NDEF message
// CF = Chunk Flag    : indicate first or middle record chunk of chunked payload
// SR = Short Record  : if == 1 PAYLOAD_LENGTH is 1 byte, else it is 4 bytes
// IL = ID Length     : indicate presence of ID_LENGTH byte
//                      (1 =included, 0 = not)
// TNF = Type Name Format: 3bit field, indicates structure of TYPE field
//
// Note: for a record that only takes up 1 NDEF message both the MB and ME
//       fields would be set on the same message. It is likely that the SR
//       field would be set as well to save space, but not required.
//
//*****************************************************************************
typedef struct
{
    //
    //! Message Begin flag
    //
    bool MB;

    //
    //! Message End flag
    //
    bool ME;

    //
    //! Chunk Flag
    //
    bool CF;

    //
    //! Short Record flag
    //
    bool SR;

    //
    //! ID Length flag
    //
    bool IL;

    //
    //! Type Name Field. An enumeration specifying the general tag type.
    //
    tTNF TNF;

} sNDEFStatusByte;

//*****************************************************************************
//
//! Structure to hold NDEF Message header data. The message header encapsulates
//! and contains metadata about the payload message. This structure is used
//! with the NFCP2P_NDEFMessageEncoder and NFCP2P_NDEFMessageDecoder functions.
//! For detailed information on the NDEF message header data, please see the NFC
//! specification.
//
// NDEF Record Layout
//  _________________
// |   StatusByte    |  1 byte
// |-----------------|
// |   TYPE_LENGTH   |  1 byte, hex value
// |---------------- |
// |  PAYLOAD_LENGTH |  1 or 4 bytes
// |---------------- |
// |   ID_LENGTH     |  0 or 1 bytes
// |---------------- |
// |     TYPE        |  2 or 5 bytes
// |---------------- |
// |      ID         |  0 or 1 byte
// |---------------- |
// |                 |
// |     PAYLOAD     |  Multiple Bytes
// |                 |
// |-----------------|
//
// Note: The Type and ID field lengths are arbitrarily set and can be expanded
// if desired. The PayloadLength field is set to the standard maximum.
// The Payload is set as a pointer into the received buffer.
//
//*****************************************************************************
typedef struct
{

    //
    //! Metadata about the message
    //
    sNDEFStatusByte sStatusByte;

    //
    //! Length of the Type field in bytes
    //
    uint8_t   ui8TypeLength;

    //
    //! Length of the payload in bytes
    //
    uint32_t  ui32PayloadLength;

    //
    //! Length of ID field in bytes. Optional field
    //
    uint8_t   ui8IDLength;

    //
    //! Contains message type
    //
    uint8_t   pui8Type[NDEF_TYPE_MAXSIZE];

    //
    //! Contains message ID. Optional field
    //
    uint8_t   pui8ID[NDEF_ID_MAXSIZE];

    //
    //! Pointer to the encoded payload buffer
    //
    uint8_t *pui8PayloadPtr;

} sNDEFMessageData;

//*****************************************************************************
//
// General defines used to interpret data / set limits on buffer sizes
//
//*****************************************************************************
//
//! Check text record bit in the StatusByte to determine if text record is UTF8
//! format.
//!
//! \b Example: Check Text Record for UTF8 format
//!
//! <tt> if(sNDEFTextRecord.bUTFcode == NDEF_TEXTRECORD_STATUSBYTE_UTF8){}</tt>
//
#define NDEF_TEXTRECORD_STATUSBYTE_UTF8         0       // DO NOT CHANGE

//
//! Check text record bit in the StatusByte to determine if text record is UTF16
//! format.
//!
//! \b Example: Check Text Record for UTF16 format
//!
//! <tt> if(sNDEFTextRecord.bUTFcode == NDEF_TEXTRECORD_STATUSBYTE_UTF16){}</tt>
//
#define NDEF_TEXTRECORD_STATUSBYTE_UTF16        1       // DO NOT CHANGE

//
//! Define the size of the Text Record Language Code Buffer. This can be changed
//! by the user to fit larger language codes that may develop in the future.
//! Current language codes are 2 or 5 bits, but users can use larger sizes
//! if they are adopted in the future.
//
#define NDEF_TEXTRECORD_LANGUAGECODE_MAXSIZE    5       // can be changed

//*****************************************************************************
//
// Set Values into Raw StatusByte by | together
//
//*****************************************************************************

//
//! Set UTF bit field in TextRecord StatusByte field. This define should be ORed
//! together with other StatusByte fields and set into StatusByte.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! \b Example: Set UTF bit field to UTF8
//!
//! <tt> ui8StatusByte = (NDEF_TEXTRECORD_STATUSBYTE_SET_UTF(
//!                                     NDEF_TEXTRECORD_STATUSBYTE_UTF8) |
//!                       NDEF_TEXTRECORD_STATUSBYTE_SET_LENGTHLANGCODE(...))
//! </tt>
//!
//
#define NDEF_TEXTRECORD_STATUSBYTE_SET_UTF(ui8x)            ((ui8x & 0x01) << 7)

//
//! Set the RFU bit field in the TextRecord StatusByte field. Should be ORed
//! together with other StatusByte fields and set into StatusByte. The RFU field
//! is reserved for future use by the NFC specification and should not be used
//! by normal applications.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! <tt> ui8StatusByte = (NDEF_TEXTRECORD_STATUSBYTE_SET_RFU(0)|
//!                      (NDEF_TEXTRECORD_STATUSBYTE_SET_LENGTHLANGCODE(...)))
//! </tt>
//!
//
#define NDEF_TEXTRECORD_STATUSBYTE_SET_RFU(ui8x)            ((ui8x & 0x01) << 6)

//
//! Set the Language Code Length field in the TextRecord StatusByte field.
//! This define should be ORed together with other StatusByte fields and set
//! into StatusByte.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! <tt> ui8StatusByte = (NDEF_TEXTRECORD_STATUSBYTE_SET_LENGTHLANGCODE(5) |
//!                       NDEF_TEXTRECORD_STATUSBYTE_SET_LENGTHLANGCODE(...))
//! </tt>
//!
//
#define NDEF_TEXTRECORD_STATUSBYTE_SET_LENGTHLANGCODE(ui8x) ((ui8x & 0x3F) << 0)

//*****************************************************************************
//
// Get values from Raw StatusByte
//
//*****************************************************************************

//
//! This macro extracts the UTF bit value from the raw StatusByte.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! \b Example: Fill the UTF boolean value in the data structure from the raw
//! buffer byte
//!
//! <tt> sNDEFTextRecord.bUTFcode = NDEF_TEXTRECORD_STATUSBYTE_GET_UTF(
//!                                             ui8StatusByte)
//! </tt>
//!
//
#define NDEF_TEXTRECORD_STATUSBYTE_GET_UTF(ui8x)            ((ui8x >> 7) & 0x01)

//
//! This macro extracts the RFU bit value from raw StatusByte. According to the
//! NFC specification, this value must be zero.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! \b Example: Fill the RFU boolean value in the data structure from the raw
//! buffer byte
//!
//! <tt> sNDEFTextRecord.bRFU = NDEF_TEXTRECORD_STATUSBYTE_GET_RFU(
//!                                             ui8StatusByte)
//! </tt>
//!
//
#define NDEF_TEXTRECORD_STATUSBYTE_GET_RFU(ui8x)            ((ui8x >> 6) & 0x01)

//
//! This macro extracts the Language Code Length field from the raw StatusByte.
//!
//! \param ui8x is the 8-bit StatusByte
//!
//! \b Example: Fill the Language Code Length field in the data structure from
//! the raw buffer byte
//!
//! <tt>
//! sNDEFTextRecord.ui5LengthLangCode =
//! NDEF_TEXTRECORD_STATUSBYTE_GET_LENGTHLANGCODE(ui8StatusByte)
//! </tt>
//!
//
#define NDEF_TEXTRECORD_STATUSBYTE_GET_LENGTHLANGCODE(ui8x) ((ui8x >> 0) & 0x3F)

//*****************************************************************************
//
//! This structure defines the text record status byte.
//! bUTFcode determines if the Text Record is encoded with UTF8 (0) or
//! UTF16 (1). bRFU is reserved for future use by the NFC specification.
//! ui5LengthLangCode holds the length of the language code. Currently
//! language code lengths are either 2 or 5 bytes.
//  ______________________________
// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0|
// |------------------------------|
// |UTF|RFU|  Length of Lang Code | = StatusByte
// |------------------------------|
//
// UTF = UTF8 or UTF16 text string formatting (0 = UTF8, 1 = UTF16)
// RFU = 0, no exceptions, its reserved for future use
// LenLangCode = 6 bytes to determine the Length of Language Code (next field)
//
//*****************************************************************************
typedef struct
{
    //
    //! Flag for UTF Code. 0 = UTF8, 1 = UTF16
    //
    bool bUTFcode;

    //
    //! Reserved for future use by NFC specification
    //
    bool bRFU;

    //
    //! Length of Text Record language code
    //
    uint8_t ui5LengthLangCode;

} sNDEFTextRecordStatusByte;

//*****************************************************************************
//
//! This structure defines the text record. sStatusByte contains the length of
//! the language code and the formatting for the Text (UTF8/UTF16).
//! pui8LanguageCode is a buffer that contains the language code; the buffer
//! size can be changed at compile time by modifying the
//! NDEF_TEXTRECORD_LANGUAGECODE_MAXSIZE define. pui8Text is a pointer to the
//! text payload of the Text Record. These three fields are defined in the
//! NFC specification. In addition, ui32TextLength has been added for
//! convenience to keep track of the Text buffer length. For example, a
//! text record with the Text "hello world" would have a StatusByte of 0x02
//! (UTF = 0 (UTF8), LenLangCode = 0x2), a Language Code of "en"
//! (for English, note that it is 2 bytes long just as the ui5LengthLangCode
//! field of the Text Record StatusByte denoted), pui8Text points to
//! a buffer holding "hello world", and ui32TextLength has a value of 11,
//! which is the number of chars in "hello world".
//
// NDEF message Text Record Payload Layout
//  _________________
// |   StatusByte    |  = 1 byte
// |-----------------|
// |   Language Code |  = 2-5 bytes
// |-----------------|
// |                 |
// |      Text       |  = Multiple Bytes
// |                 |
// |-----------------|
//
// Note: the contents of a text record are freeform plain text in either
//       UTF8 or UTF16 format.
//
// Note: the TextRecordLength is used in lieu of a terminiating sentinel on
//       the puiText buffer.
//
//*****************************************************************************
typedef struct
{

    //
    //! Structure to hold StatusByte information
    //
    sNDEFTextRecordStatusByte sStatusByte;

    //
    //! Buffer that holds the Language Code
    //
    uint8_t   pui8LanguageCode[NDEF_TEXTRECORD_LANGUAGECODE_MAXSIZE];

    //
    //! Pointer to the Text Buffer
    //
    uint8_t *pui8Text;

    //
    //! Length of text in Text Buffer
    //
    uint32_t  ui32TextLength;

} sNDEFTextRecord;

//*****************************************************************************
//
//! Define used to mark end of well-defined URI Record ID Codes. Any code
//! greater than this value is not defined by the NFC specification.
//!
//! \b Example: Check if ID Code of Tag is known defined value
//!
//! <tt>
//! \verbatim
//! if(sNDEFURIRecord.eIDCode < NDEF_URIRECORD_IDCODE_RFU)
//!         {
//!             //process tag
//!         }
//! \endverbatim
//! </tt>
//
//*****************************************************************************
#define NDEF_URIRECORD_IDCODE_RFU               0x24

//*****************************************************************************
//
//! Enumeration of all possible URI Record ID Codes defined by the NFC
//! specification.
//! For the complete list, please see the enumeration definition in nfc_p2p.h.
//! Defined values range from 0x00 (no prepending) to 0x23 ('urn:nfc:').
//! Values 0x24 and above are reserved for future use.
//
//      Acceptable Prepending values are:
//          0x00  N/A. No prepending is done
//          0x01  http://www.
//          0x02  https://www.
//          0x03  http://
//          0x04  https://
//          0x05  tel:
//          0x06  mailto:
//          0x07  ftp://anonymous:anonymous@
//          0x08  ftp://ftp.
//          0x09  ftps://
//          0x0A  sftp://
//          0x0B  smb://
//          0x0C  nfs://
//          0x0D  ftp://
//          0x0E  dav://
//          0x0F  news:
//          0x10  telnet://
//          0x11  imap:
//          0x12  rtsp://
//          0x13  urn:
//          0x14  pop:
//          0x15  sip:
//          0x16  sips:
//          0x17  tftp:
//          0x18  btspp://
//          0x19  btl2cap://
//          0x1A  btgoep://
//          0x1B  tcpobex://
//          0x1C  irdaobex://
//          0x1D  file://
//          0x1E  urn:epc:id:
//          0x1F  urn:epc:tag:
//          0x20  urn:epc:pat:
//          0x21  urn:epc:raw:
//          0x22  urn:epc:
//          0x23  urn:nfc:
//
//          0x24-0xFF RFU Reserved for Future Use, Not Valid Inputs
//
//*****************************************************************************
typedef enum
{

    //
    //! Nothing is prepended to puiUTF8String
    //
    unabridged      =       0x00,

    //
    //! 'http://www.' is prepended to puiUTF8String
    //
    http_www        =       0x01,

    //
    //! 'https://www.' is prepended to puiUTF8String
    //
    https_www       =       0x02,

    //
    //! 'http://' is prepended to puiUTF8String
    //
    http            =       0x03,

    //
    //! 'https://' is prepended to puiUTF8String
    //
    https           =       0x04,

    //
    //! 'tel:' is prepended to puiUTF8String
    //
    tel             =       0x05,

    //
    //! 'mailto:' is prepended to puiUTF8String
    //
    mailto          =       0x06,

    //
    //! 'ftp://anonymous:anonymous@' is prepended to puiUTF8String
    //
    ftp_anonymous   =       0x07,

    //
    //! 'ftp://ftp.' is prepended to puiUTF8String
    //
    ftp_ftp         =       0x08,

    //
    //! 'ftps://' is prepended to puiUTF8String
    //
    ftps            =       0x09,

    //
    //! 'sftp://' is prepended to puiUTF8String
    //
    sftp            =       0x0A,

    //
    //! 'smb://' is prepended to puiUTF8String
    //
    smb             =       0x0B,

    //
    //! 'nfs://' is prepended to puiUTF8String
    //
    nfs             =       0x0C,

    //
    //! 'ftp://' is prepended to puiUTF8String
    //
    ftp             =       0x0D,

    //
    //! 'dav://' is prepended to puiUTF8String
    //
    dav             =       0x0E,

    //
    //! 'news:' is prepended to puiUTF8String
    //
    news            =       0x0F,

    //
    //! 'telnet://' is prepended to puiUTF8String
    //
    telnet          =       0x10,

    //
    //! 'imap:' is prepended to puiUTF8String
    //
    imap            =       0x11,

    //
    //! 'rtsp://' is prepended to puiUTF8String
    //
    rtsp            =       0x12,

    //
    //! 'urn:' is prepended to puiUTF8String
    //
    urn             =       0x13,

    //
    //! 'pop:' is prepended to puiUTF8String
    //
    pop             =       0x14,

    //
    //! 'sip:' is prepended to puiUTF8String
    //
    sip             =       0x15,

    //
    //! 'sips:' is prepended to puiUTF8String
    //
    sips            =       0x16,

    //
    //! 'tftp:' is prepended to puiUTF8String
    //
    tftp            =       0x17,

    //
    //! 'btspp://' is prepended to puiUTF8String
    //
    btspp           =       0x18,

    //
    //! 'btl2cap://' is prepended to puiUTF8String
    //
    btl2cap         =       0x19,

    //
    //! 'btgoep://' is prepended to puiUTF8String
    //
    btgoep          =       0x1A,

    //
    //! 'tcpobex://' is prepended to puiUTF8String
    //
    tcpobex         =       0x1B,

    //
    //! 'irdaobex://' is prepended to puiUTF8String
    //
    irdaobex        =       0x1C,

    //
    //! 'file://' is prepended to puiUTF8String
    //
    file            =       0x1D,

    //
    //! 'urn:epc:id:' is prepended to puiUTF8String
    //
    urn_epc_id      =       0x1E,

    //
    //! 'urn:epc:tag:' is prepended to puiUTF8String
    //
    urn_epc_tag     =       0x1F,

    //
    //! 'urn:epc:pat:' is prepended to puiUTF8String
    //
    urn_epc_pat     =       0x20,

    //
    //! 'urn:epc:raw:' is prepended to puiUTF8String
    //
    urn_epc_raw     =       0x21,

    //
    //! 'urn:epc:' is prepended to puiUTF8String
    //
    urn_epc         =       0x22,

    //
    //! 'urn:nfc:' is prepended to puiUTF8String
    //
    urn_nfc         =       0x23,

    //
    //! Values equal to and above this are reserved for future use (RFU)
    //
    RFU             =       0x24

} eNDEF_URIRecord_IDCode;

//*****************************************************************************
//
//! This structure defines the URI record type. The URI Record Type has two
//! fields; the ID code and the UTF8 URI string. The IDCode is used to
//! determine the URI type. For example, IDcode of 0x06 is 'mailto:'
//! and usually triggers an email event. IDcode 0x01 is 'http://www.' and
//! usually triggers a webpage to open. The IDcode values are prepended to
//! the UTF8 string. ui32URILength is used to determine the length of the
//! puiUTF8String buffer. For example, to direct a user to 'http://www.ti.com'
//! the IDcode is 0x01, the UTF8 string is 'ti.com', and the ui32URILength is
//! 0x6.
//
// NDEF message URI Record Payload Layout
//  _________________
// |     ID Code     |  1 byte
// |-----------------|
// |                 |
// |   UTF8 String   |  Multiple Bytes
// |                 |
// |-----------------|
//
// The URI string is multiple bytes of UTF8 format text with a possible
// prepended value depending on the ID Code
//
//*****************************************************************************
typedef struct
{
    //
    //! Enumeration of all possible ID codes
    //
    eNDEF_URIRecord_IDCode eIDCode;

    //
    //! Buffer that holds the URI character string
    //
    uint8_t *puiUTF8String;

    //
    //! Length of URI Character String
    //
    uint32_t  ui32URILength;

} sNDEFURIRecord;

//*****************************************************************************
//
//! Enumeration of the three actions that can be associated with an Action
//! Record.
//
//*****************************************************************************
typedef enum
{

    //
    //! Do Action on Record
    //
    DO_ACTION           = 0x00,

    //
    //! Save Record for Later
    //
    SAVE_FOR_LATER      = 0x01,

    //
    //! Open Record for Editing
    //
    OPEN_FOR_EDITING    = 0x02

} tAction;

//*****************************************************************************
//
//! This structure defines an Action Record
//
//*****************************************************************************
typedef struct
{

    //
    //! Action Record type enumeration
    //
    tAction eAction;

} sNDEFActionRecord;

//*****************************************************************************
//
//! This structure defines the SmartPoster record type.
//! The SmartPoster Record is essentially
//! a URI Record with other records included for metadata. Thus
//! the SmartPoster must include at least a URI Record and may also include a
//! Text Record for a Title record, an Action record to do actions on the URI,
//! an Icon Record with a small icon, a Size record that holds the size of the
//! externally referenced entity, and a Type record that denotes the type of the
//! externally referenced entity. It should be noted that while the SmartPoster
//! specification can include all these records, this library only provides
//! support for Title, URI and Action records. All other records are ignored
//! by the default handler.
//
// NDEF message SmartPoster Record Payload consists of multiple fully wrapped
// NDEF records. The basic layout is a URI record with subsequent records as
// metadata on size, type, icon, title, and action associated with record.
//
// The possible record types are :
//  Title Record  : multiple possible in different languages (Text Record)
//  URI Record    : 1 and only 1, core of Smart Poster record
//  Action Record : how to treat the URI (Do, Save for later, Open for edit)
//  Icon Record   : MIME type image record [optional]
//  Size Record   : size of external referenced entity (web link) [optional]
//  Type Record   : MIME type of external referenced entity [optional
//
//
// Note: Currently only Title,URI, and Action records are supported.
// Image, Type and size records are not implemented.
//
//*****************************************************************************
typedef struct
{

    //
    //! message header for Text Record
    //
    sNDEFMessageData    sTextHeader;

    //
    //! Text Record payload structure
    //
    sNDEFTextRecord     sTextPayload;

    //
    //! message header for URI Record
    //
    sNDEFMessageData    sURIHeader;

    //
    //! URI Record payload strucutre
    //
    sNDEFURIRecord      sURIPayload;

    //
    //! Flag to signal if Action Record is part of Smart Poster
    //
    bool bActionExists;

    //
    //! message header for Action Record
    //
    sNDEFMessageData    sActionHeader;

    //
    //! Action Record payload strucutre
    //
    sNDEFActionRecord   sActionPayload;

} sNDEFSmartPosterRecord;

//*****************************************************************************
//
// Function Prototypes
//
//*****************************************************************************
void NFCP2P_init(tTRF79x0TRFMode eMode,tTRF79x0Frequency eFrequency);
tNFCP2PState NFCP2P_proccessStateMachine(void);
tStatus NFCP2P_sendPacket(uint8_t *pui8DataPtr, uint32_t ui32DataLength);
sNFCP2PRxStatus NFCP2P_getReceiveState(void);

bool NFCP2P_NDEFMessageEncoder(sNDEFMessageData sNDEFDataToSend,
                                        uint8_t  *pui8Buffer,
                                        uint16_t ui16BufferMaxLength,
                                        uint32_t *pui32BufferLength);
bool NFCP2P_NDEFMessageDecoder(sNDEFMessageData *psNDEFDataDecoded,
                                        uint8_t *pui8Buffer,
                                        uint16_t ui16BufferMaxLength);
bool NFCP2P_NDEFTextRecordEncoder(sNDEFTextRecord sTextRecord,
                                        uint8_t  *pui8Buffer,
                                        uint16_t ui16BufferMaxLength,
                                        uint32_t *ui32BufferLength);
bool NFCP2P_NDEFTextRecordDecoder(sNDEFTextRecord *sTextRecord,
                                        uint8_t *pui8Buffer,
                                        uint32_t  ui32BufferLength);
bool NFCP2P_NDEFURIRecordEncoder(sNDEFURIRecord sURIRecord,
                                        uint8_t  *pui8Buffer,
                                        uint16_t ui16BufferMaxLength,
                                        uint32_t *ui32BufferLength);
bool NFCP2P_NDEFURIRecordDecoder(sNDEFURIRecord *sURIRecord,
                                        uint8_t *pui8Buffer,
                                        uint32_t  ui32BufferLength);
bool NFCP2P_NDEFSmartPosterRecordEncoder(sNDEFSmartPosterRecord sSmartPoster,
                                        uint8_t  *pui8Buffer,
                                        uint16_t ui16BufferMaxLength,
                                        uint32_t *ui32BufferLength);
bool NFCP2P_NDEFSmartPosterRecordDecoder(sNDEFSmartPosterRecord *sSmartPoster,
                                        uint8_t *pui8Buffer,
                                        uint16_t ui16BufferMaxLength,
                                        uint32_t  ui32BufferLength);

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************

#endif //__NFC_P2P_H__