summaryrefslogtreecommitdiffstats
path: root/src/phFriNfc_NdefReg.c
blob: b39bf04a1857b5f45f5873d66f8ae35bd10da0f2 (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
/*
 * Copyright (C) 2010 NXP Semiconductors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*!
 * \file  phFriNfc_NdefReg.c
 * \Contains Registry and module functions.
 *
 * Project: NDEFT
 *
 * $Date: Mon May 25 13:59:32 2009 $
 * $Author: ing08150 $
 * $Revision: 1.4 $
 * $Aliases: NFC_FRI1.1_WK920_R25_1,NFC_FRI1.1_WK922_PREP1,NFC_FRI1.1_WK922_R26_1,NFC_FRI1.1_WK924_PREP1,NFC_FRI1.1_WK924_R27_1,NFC_FRI1.1_WK926_R28_1,NFC_FRI1.1_WK928_R29_1,NFC_FRI1.1_WK930_R30_1,NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
 *
 */


#include "phNfcTypes.h"
#include "phNfcStatus.h"
#include "phNfcCompId.h"
#include "phNfcHalTypes.h"
#include "phFriNfc.h"
#include "phFriNfc_NdefReg.h"
#include "phFriNfc_NdefRecord.h"

/* Harsha: To Fix: 0000358: phFriNfc_NdefRecord.h: includes should be moved */
#include <string.h>
static int16_t phFriNfc_NdefReg_Strncmp (const int8_t *s1, const int8_t *s2, uint32_t count);

/*********  String functions *********/

static int16_t phFriNfc_NdefReg_Strncmp (const int8_t *s1, const int8_t *s2, uint32_t count)
{
    return (int16_t)strncmp((const char*)s1,(const char*)s2, count);
}
int16_t  phFriNfc_NdefReg_Strnicmp(const int8_t *s1, const int8_t *s2, uint32_t count)
{
    int8_t c1, c2;
    int16_t returnvalue;
    do
    {
        c1 = *s1;
        s1++;
        if (c1 >=97)
            c1 = (c1 - 32);
        c2 = *s2;
        s2++;
        if (c2 >=97)
            c2 = (c2 - 32);
        --count;
    }
    while ( (c1 == c2) && (c1 != '\0') && (c2 != '\0') && (count > 0) );

    if ( (count == 0) || (c1 == c2) )
        returnvalue = 0;

    else if ( (c1 > c2) )
        returnvalue = 1;
    else
        returnvalue = -1;

    return(returnvalue);
}

/*********  REGISTRY AND LISTENER MODULE *********/

NFCSTATUS phFriNfc_NdefReg_Reset(phFriNfc_NdefReg_t         *NdefReg,
                                 uint8_t                    **NdefTypesarray,
                                 phFriNfc_NdefRecord_t      *RecordsExtracted,
                                 phFriNfc_NdefReg_CbParam_t *CbParam,
                                 uint8_t                    *ChunkedRecordsarray,
                                 uint32_t                   NumberOfRecords)
{
    NFCSTATUS status = NFCSTATUS_SUCCESS;

    /* Reset/Initialise the values of the Context structure */
    /* Store the required pointers in the context structure */
    if(NdefReg == NULL || NdefTypesarray == NULL || RecordsExtracted == NULL || CbParam == NULL)
    {
        status = PHNFCSTVAL(CID_FRI_NFC_NDEF_REGISTRY, NFCSTATUS_INVALID_PARAMETER);
    }
    else
    {
        NdefReg->State=PH_FRINFC_NDEFREG_STATE_INIT;
        NdefReg->NdefData=NULL;
        NdefReg->NdefDataLength=0;
        NdefReg->NdefTypeList=NULL;
        NdefReg->NdefTypes = NdefTypesarray ;
        NdefReg->RecordsExtracted = RecordsExtracted;
        NdefReg->CbParam = CbParam;
        NdefReg->validPreviousTnf = 0xff;
        NdefReg->IsChunked = ChunkedRecordsarray;
        NdefReg->NumberOfRecords = NumberOfRecords;
        NdefReg->newRecordextracted = 0;
        NdefReg->MainTnfFound = 0;
    }
    return(status);
}

/* Adds a NDEF type listener to the internal list of listeners*/
/*Libraray does no allocation of the memory*/
NFCSTATUS phFriNfc_NdefReg_AddCb(phFriNfc_NdefReg_t     *NdefReg,
                                 phFriNfc_NdefReg_Cb_t  *NdefCb)
{
    NFCSTATUS status = NFCSTATUS_SUCCESS;

    if(  NdefReg == NULL || NdefCb ==NULL)
    {
        status = PHNFCSTVAL(CID_FRI_NFC_NDEF_REGISTRY, NFCSTATUS_INVALID_PARAMETER);
    }
    else
    {
        /*  Check whether we can accomodate all these records in a single node */
        if(NdefCb->NumberOfRTDs <= PH_FRINFC_NDEFREG_MAX_RTD_REGISTERED)
        {
            /*  Yes, all these Records can be accomodated in a single node */
            /* No existing node. This will be the first Node    */
            if(NdefReg->NdefTypeList==NULL)
            {
                NdefCb->Previous =NULL;
                NdefCb->Next =NULL;
                NdefReg->NdefTypeList = NdefCb;
            }
            else
            {
                /*  Some nodes are existing. Add the new CB node at the front
                    of the List and update pointers */
                NdefCb->Next = NdefReg->NdefTypeList;
                NdefCb->Previous = NULL;
                NdefReg->NdefTypeList->Previous = NdefCb;
                NdefReg->NdefTypeList = NdefReg->NdefTypeList->Previous;
            }
        }
        else
        {
            /*  We cannot accomodate more records than PH_FRINFC_NDEFREG_MAX_RTD_REGISTERED
                in this node.
                So return warning NFCSTATUS_INVALID_PARAMETER. */
            status = PHNFCSTVAL(CID_FRI_NFC_NDEF_REGISTRY,
                                NFCSTATUS_INVALID_PARAMETER);
        }
    }

    return(status);
}

/*Removes a specific listener from the list. The element to remove is specified by its address.*/
/*Libraray does no deallocation of the memory*/
NFCSTATUS phFriNfc_NdefReg_RmCb(phFriNfc_NdefReg_t    *NdefReg,
                                phFriNfc_NdefReg_Cb_t *NdefCb)
{
    NFCSTATUS               status = NFCSTATUS_SUCCESS;
    phFriNfc_NdefReg_Cb_t   *tempNode;
    uint8_t                 found=0;/* to check for the node present or not */

    if(  NdefReg==NULL || NdefCb ==NULL)
    {
        status = PHNFCSTVAL(CID_FRI_NFC_NDEF_REGISTRY, NFCSTATUS_INVALID_PARAMETER);
    }
    else
    {
        tempNode = NdefReg->NdefTypeList;
        /* if the list is empty */
        if(NdefReg->NdefTypeList == NULL)
        {
            status = PHNFCSTVAL(CID_FRI_NFC_NDEF_REGISTRY, NFCSTATUS_NOT_REGISTERED);
        }
        else
        {
            while(tempNode!=NULL)
            {
                if(NdefCb == tempNode)
                {
                    found=1;/* if the node is present */

                    /* node is present in the front of the list so
                    update the NdefReg->NdefTypeList pointer */
                    if(tempNode->Previous==NULL && tempNode->Next!=NULL)
                    {
                        NdefReg->NdefTypeList =NdefReg->NdefTypeList->Next;
                        NdefReg->NdefTypeList->Previous = NULL;
                        break;
                    }
                    /* only one node in the list so update the head node */
                    if(tempNode->Next==NULL && tempNode->Previous==NULL)
                    {
                          NdefReg->NdefTypeList=NULL;
                          break;
                    }
                    if (tempNode->Previous != NULL)
                    {
                        tempNode->Previous->Next = tempNode->Next;
                    }
                    if (tempNode->Next != NULL)
                    {
                        tempNode->Next->Previous = tempNode->Previous;
                    }
                    break;
                }
                /* move to the next node */
                tempNode = tempNode->Next;
            }
        }
        if(!found )
        {
            status = PHNFCSTVAL(CID_FRI_NFC_NDEF_REGISTRY, NFCSTATUS_NOT_REGISTERED);
        }
    }
    return(status);
}

/* Copy the relevant pointers to the context structure, change the
FSM state, so as to trigger the process and return pending. This function is non-blocking,
it returns once the operation is initiated or an error occurs */

NFCSTATUS phFriNfc_NdefReg_DispatchPacket(phFriNfc_NdefReg_t   *NdefReg,
                                          uint8_t              *PacketData,
                                          uint16_t              PacketDataLength)
{
    NFCSTATUS status = NFCSTATUS_SUCCESS;

    if(NdefReg==NULL ||PacketData==NULL || PacketDataLength==0)
    {
        status = PHNFCSTVAL(CID_FRI_NFC_NDEF_REGISTRY, NFCSTATUS_INVALID_PARAMETER);
    }
    else
    {
        NdefReg->NdefData = PacketData;
        NdefReg->NdefDataLength = PacketDataLength;
        NdefReg->State = PH_FRINFC_NDEFREG_STATE_DIS_PKT;
        NdefReg->NumberOfNdefTypes = 0;
        NdefReg->RecordIndex = 0;
        NdefReg->RtdIndex = 0;
        status = PHNFCSTVAL(CID_NFC_NONE, NFCSTATUS_SUCCESS);
    }
    return(status);
}

/* Copy the relevant pointers to the context structure, change the
FSM state, so as to trigger the process and return pending */
NFCSTATUS phFriNfc_NdefReg_DispatchRecord(phFriNfc_NdefReg_t     *NdefReg,
                                          phFriNfc_NdefRecord_t  *RecordsExtracted)
{
    NFCSTATUS status = NFCSTATUS_SUCCESS;
    if(NdefReg==NULL || RecordsExtracted==NULL)
    {
        status = PHNFCSTVAL(CID_FRI_NFC_NDEF_REGISTRY, NFCSTATUS_INVALID_PARAMETER);
    }
    else
    {
        NdefReg->RecordsExtracted = RecordsExtracted;
        NdefReg->State = PH_FRINFC_NDEFREG_STATE_DIS_RCD;

        status = PHNFCSTVAL(CID_NFC_NONE, NFCSTATUS_SUCCESS);
    }
    return(status);
}

uint8_t phFriNfc_NdefReg_Process(phFriNfc_NdefReg_t  *NdefReg,
                                 NFCSTATUS           *Status)
{
    uint8_t     count = 0,
                ret_val=0,
                TnfMatchFound = 0,
                index = 0,
                matchFound = 0;



    if(NdefReg->NdefTypeList == NULL)
    {
        /*  No Nodes added. Return error  */
        *Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_REGISTRY, NFCSTATUS_NOT_REGISTERED);
        return(1);
    }

    *Status = NFCSTATUS_SUCCESS;
    switch(NdefReg->State)
    {
        case PH_FRINFC_NDEFREG_STATE_DIS_RCD:

        /* for START ( each node in the list NdefReg->NdefTypeList), do the following */
        for(index=0;index<NdefReg->NdefTypeList->NumberOfRTDs;index++)
        {
            /* First, Match should be done with The TNF*/
            if( (NdefReg->NdefTypeList->Tnf[index] & PH_FRINFC_NDEFRECORD_TNF_MASK ) ==
                (NdefReg->RecordsExtracted->Tnf & PH_FRINFC_NDEFRECORD_TNF_MASK ) )
            {
                /* Second, Match should be done with The Typelength*/
                if( NdefReg->NdefTypeList->NdeftypeLength[index] == \
                    NdefReg->RecordsExtracted->TypeLength )
                {
                    /* Third, Match should be done with The Type*/
                    matchFound = 0;
                    switch(NdefReg->NdefTypeList->Tnf[index])
                    {
                        case 1:
                            /*  TNF = 0X01 NFC Forum well-known type : Case sensitive  */
                            /*  comparison is to be made. */
                            if( !phFriNfc_NdefReg_Strncmp( (const int8_t *)NdefReg->NdefTypeList->NdefType[index] ,
                                (const int8_t *)(NdefReg->RecordsExtracted->Type),
                                NdefReg->RecordsExtracted->TypeLength))
                            {
                                matchFound = 1;
                            }
                        break;

                        case 2:
                        case 4:
                            /*  For TNF = 0X02 Media-type as defined in RFC 2046
                                From iana.org, it has never been found any registered media type
                                with non-ascii character ==> Comparison to be used for *types* in
                                *registry*: case INSENSITIVE comparison.

                                For TNF = 0X04 NFC Forum external type : ==> Comparison to be used
                                for *types* in *registry* : case INSENSITIVE comparison */
                            if( !phFriNfc_NdefReg_Strnicmp( (int8_t *)NdefReg->NdefTypeList->NdefType[index] ,
                                (int8_t *)(NdefReg->RecordsExtracted->Type),
                                NdefReg->RecordsExtracted->TypeLength))
                            {
                                matchFound = 1;
                            }
                        break;

                        case 3:
                            /*  TNF = 0X03 Absolute URI as defined in RFC 3986 [RFC 3986]
                                Big issue concerning the Encoding, which is actually determined
                                by the application.Conclusion is that: Comparison to be used for
                                *types* in *registry*: NONE. only TNF ; type should be ignored,
                                and its comparison shall be done by the application. */
                            matchFound = 1;
                        break;
                        default:
                            break;
                    }
                    if(matchFound)
                    {
                        /*  Copy the chunked flag info to the callback parameter */
                        NdefReg->CbParam->Chunked[count] = (NdefReg->RecordsExtracted->Flags & \
                                                            PH_FRINFC_NDEFRECORD_FLAGS_CF );

                        /*  NOTE: Raw record and the raw record size cannot be
                            copied as this itself is an extracted record ! */

                        /*  Copy the record in the format phFriNfc_NdefRecord_t
                            to the callback parameter */
                            (void) memcpy( &NdefReg->CbParam->Records[count],
                                                    NdefReg->RecordsExtracted,
                                                    sizeof(phFriNfc_NdefRecord_t));
                            count++;
                    }
                }
            }
        }

        /*  now, we have all the matching entries for the RTDs present
            in this particular node NdefReg->NdefTypeList.
            call the callback */
        if(count>0)
        {
            NdefReg->CbParam->Count = count;
            NdefReg->CbParam->CbContext = NdefReg->NdefTypeList->CbContext;
            NdefReg->NdefTypeList->NdefCallback (NdefReg->CbParam);
        }
        else
        {
            NdefReg->CbParam->Count = 0;
        }

        /* for END ( each node in the list NdefReg->NdefTypeList), do the following */
        if(NdefReg->NdefTypeList->Next==NULL)
        {
            NdefReg->State = PH_FRINFC_NDEFREG_STATE_INIT;
            while(NdefReg->NdefTypeList->Previous!=NULL)
            {
                NdefReg->NdefTypeList = NdefReg->NdefTypeList->Previous;
            }
            /* No further node present in the list. End of process function call */
            ret_val=1;
        }
        else
        {
            /* Move the linked list by one node.*/
            NdefReg->NdefTypeList = NdefReg->NdefTypeList->Next;
            /* list is not empty so come again */
            ret_val=0;
        }
        break;

        case PH_FRINFC_NDEFREG_STATE_DIS_PKT:

        if(NdefReg->NumberOfNdefTypes == 0)
        {
            /*  First, Get all the records present in the data packet NdefReg->NdefData
                using NDEF tool library */
            /*  and, get the NumberOfNdefTypes from NdefData */
            *Status = phFriNfc_NdefRecord_GetRecords(   NdefReg->NdefData,
                                                        NdefReg->NdefDataLength,
                                                        NULL,
                                                        NdefReg->IsChunked,
                                                        &NdefReg->NumberOfNdefTypes);
            if((*Status)!= NFCSTATUS_SUCCESS)
            {
                /* Error in the Packet. Exit from the process */
                ret_val = 1;
                NdefReg->NumberOfNdefTypes = 0;
                break;
            }

            if(NdefReg->NumberOfNdefTypes > NdefReg->NumberOfRecords)
            {
                /*  There is not enough space in the arrays NdefReg->NdefTypes
                    and NdefReg->IsChunked, to write NdefReg->NumberOfRecords
                    number of records. Return error. */
                *Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_REGISTRY, NFCSTATUS_BUFFER_TOO_SMALL);
                ret_val = 1;
                NdefReg->NumberOfNdefTypes = 0;
                break;
            }

            /* Now, get the NdefTypes */
            *Status = phFriNfc_NdefRecord_GetRecords(   NdefReg->NdefData,
                                                        NdefReg->NdefDataLength,
                                                        NdefReg->NdefTypes,
                                                        NdefReg->IsChunked,
                                                        &NdefReg->NumberOfNdefTypes);
            if((*Status)!= NFCSTATUS_SUCCESS)
            {
                /* Error in the Packet. Exit from the process */
                ret_val = 1;
                NdefReg->NumberOfNdefTypes = 0;
                break;
            }
        }

        /*  For each record, in the arry NdefReg->NdefTypes, check
            whether it matches with any of the registered RTD in the
            present node. If it matches, copy this to the Callback
            parameter array and increment count.
            If count is 8, call the callback function.
            Remember the record index that we last processed, before
            calling the callback.   */

        /*  for each record in the Message  */
        while(NdefReg->RecordIndex < NdefReg->NumberOfNdefTypes)
        {
            /*  Extract a record from the Message */
            *Status = phFriNfc_NdefRecord_Parse(NdefReg->RecordsExtracted,
                                                NdefReg->NdefTypes[NdefReg->RecordIndex]);
            if((*Status)!= NFCSTATUS_SUCCESS)
            {
                /* Error in the Record. Exit from the process */
                NdefReg->NumberOfNdefTypes = 0;
                return 1;
            }

            NdefReg->newRecordextracted = 1;

            /*  for each RTD in the present node */
            while(NdefReg->RtdIndex < NdefReg->NdefTypeList->NumberOfRTDs)
            {
                /*  Harsha: Fix for 0000243: [JF] phFriNfc_NdefReg_Process
                    won't parse correctly chunked records   */

                /*  Check whether the TNF = 0x06
                    PH_FRINFC_NDEFRECORD_TNF_UNCHANGED */

                if((NdefReg->RecordsExtracted->Tnf & PH_FRINFC_NDEFRECORD_TNF_MASK ) ==
                    PH_FRINFC_NDEFRECORD_TNF_UNCHANGED)
                {
                    if(NdefReg->MainTnfFound == 1)
                    {
                        /*  Matching RTD is there  */
                        TnfMatchFound = 1;
                    }
                }
                else
                {
                    if(NdefReg->newRecordextracted)
                    {
                        NdefReg->MainTnfFound  = 0;
                    }
                    /*  This is a tnf other than 0x06.
                        that means, this is a valid tnf */
                    NdefReg->validPreviousTnf = NdefReg->RecordsExtracted->Tnf;

                    /* First, Match should be done with The TNF*/
                    /* Second, Match should be done with The Typelength*/
                        /* Third, Match should be done with The Type*/
                    if((NdefReg->NdefTypeList->Tnf[NdefReg->RtdIndex] &
                        PH_FRINFC_NDEFRECORD_TNF_MASK ) ==
                        (NdefReg->RecordsExtracted->Tnf & PH_FRINFC_NDEFRECORD_TNF_MASK ) &&
                        (NdefReg->NdefTypeList->NdeftypeLength[NdefReg->RtdIndex] ==
                        NdefReg->RecordsExtracted->TypeLength))
                    {
                        matchFound = 0;
                        switch(NdefReg->NdefTypeList->Tnf[NdefReg->RtdIndex])
                        {
                            case 1:
                                /*  TNF = 0X01 NFC Forum well-known type : Case sensitive
                                    comparison is to be made. */
                                if(!phFriNfc_NdefReg_Strncmp((const int8_t *)NdefReg->NdefTypeList->NdefType[NdefReg->RtdIndex],
                                            (const int8_t *)(NdefReg->RecordsExtracted->Type),
                                            NdefReg->RecordsExtracted->TypeLength))
                                {
                                    matchFound = 1;
                                }
                            break;

                            case 2:
                            case 4:
                                /*  For TNF = 0X02 Media-type as defined in RFC 2046
                                    From iana.org, it has never been found any registered media type
                                    with non-ascii character ==> Comparison to be used for *types* in
                                    *registry*: case INSENSITIVE comparison. */

                                /*  For TNF = 0X04 NFC Forum external type : ==> Comparison to be used
                                    for *types* in *registry* : case INSENSITIVE comparison */
                                if( !phFriNfc_NdefReg_Strnicmp(  (int8_t *)NdefReg->NdefTypeList->NdefType[NdefReg->RtdIndex],
                                                (int8_t *)(NdefReg->RecordsExtracted->Type),
                                                NdefReg->RecordsExtracted->TypeLength))
                                {
                                    matchFound = 1;
                                }
                            break;

                            case 3:
                                /*  TNF = 0X03 Absolute URI as defined in RFC 3986 [RFC 3986]
                                    Big issue concerning the Encoding, which is actually determined
                                    by the application.Conclusion is that: Comparison to be used for
                                    *types* in *registry*: NONE. only TNF ; type should be ignored,
                                    and its comparison shall be done by the application. */
                                matchFound = 1;
                            break;
                            default:
                            break;
                        }
                        if(matchFound == 1)
                        {
                            TnfMatchFound = 1;
                            NdefReg->MainTnfFound  = 1;
                        }
                        else
                        {
                            TnfMatchFound = 0;
                        }
                    }
                    else
                    {
                        TnfMatchFound = 0;
                    }
                }

                /*  we have found a matching TNF  */
                if(TnfMatchFound == 1)
                {
                    /*  Copy the chunked flag info to the callback parameter */
                    NdefReg->CbParam->Chunked[count] = NdefReg->IsChunked[NdefReg->RecordIndex];

                    /*  Copy the raw record to the callback parameter */
                    NdefReg->CbParam->RawRecord[count] = NdefReg->NdefTypes[NdefReg->RecordIndex];

                    /*  Copy the raw record size to the callback parameter */
                    NdefReg->CbParam->RawRecordSize[count] = phFriNfc_NdefRecord_GetLength(NdefReg->RecordsExtracted);

                    /*  Copy the record in the format phFriNfc_NdefRecord_t
                        to the callback parameter */
                    (void)  memcpy( &NdefReg->CbParam->Records[count],
                                            NdefReg->RecordsExtracted,
                                            sizeof(phFriNfc_NdefRecord_t));


                    /*if count is greater than PH_FRINFC_NDEFREG_MAX_RTD (presently 8)
                    then call the callback since there can be more than
                    PH_FRINFC_NDEFREG_MAX_RTD of a single type with in the packet,as a result
                    call the callback and initialize count to zero.This may also happen
                    when there are chunked records */

                    count++;
                    if(count >= PH_FRINFC_NDEFREG_MAX_RTD )
                    {
                        NdefReg->CbParam->Count = count;
                        NdefReg->CbParam->CbContext = NdefReg->NdefTypeList->CbContext;
                        NdefReg->NdefTypeList->NdefCallback (NdefReg->CbParam);
                        count=0;
                        /*  Only one callback per node. */
                        NdefReg->RecordIndex++;
                        return(0);
                    }
                }

                /*  If the match is already found for the UNCHANGED_TNF,
                    don't comapre it again */
                if((NdefReg->RecordsExtracted->Tnf & PH_FRINFC_NDEFRECORD_TNF_MASK )
                    == PH_FRINFC_NDEFRECORD_TNF_UNCHANGED &&
                    TnfMatchFound == 1)
                {
                    TnfMatchFound = 0;
                    break;
                }

                NdefReg->RtdIndex++;

                NdefReg->newRecordextracted = 0;
            }   /*  for each RTD in the present node
                    while(NdefReg->RtdIndex < NdefReg->NdefTypeList->NumberOfRTDs) */

            /*   One Record processing done for this node */

            NdefReg->RtdIndex = 0;
            NdefReg->RecordIndex++;
        }   /*  while(NdefReg->RecordIndex<NdefReg->NumberOfNdefTypes)  */

        /*  One node has been checked. Move to the next node  */

        if(count>0)
        {
            NdefReg->CbParam->Count = count;
            NdefReg->CbParam->CbContext = NdefReg->NdefTypeList->CbContext;
            NdefReg->NdefTypeList->NdefCallback (NdefReg->CbParam);
        }
        else
        {
            NdefReg->CbParam->Count = 0;
        }

        if(NdefReg->NdefTypeList->Next==NULL)
        {
            /*  All the nodes have been checked. Return */
            NdefReg->State = PH_FRINFC_NDEFREG_STATE_INIT;
            while(NdefReg->NdefTypeList->Previous!=NULL)
            {
                NdefReg->NdefTypeList = NdefReg->NdefTypeList->Previous;
            }
            /*  No further node present in the list.
                End of Dispatch packet function. Return TRUE*/
            ret_val = 1;
        }
        else
        {
            /* Move the linked list by one node.*/
            NdefReg->NdefTypeList = NdefReg->NdefTypeList->Next;
            /* list is not empty so come again */
            ret_val = 0;
        }

        /*  Start from the first record again. */
        NdefReg->RecordIndex = 0;
        NdefReg->RtdIndex = 0;

        break;

        default:
            /* return error */
            *Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_REGISTRY, NFCSTATUS_INVALID_DEVICE_REQUEST);
            /* Unknown state Error exit from the process function */
            ret_val= 1;
        break;

    }

    return(ret_val);

}