Copying NDEF text messages from one Tag to another

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copying NDEF text messages from one Tag to another

Copying NDEF text messages from one Tag to another

Hello NFC enthusiasts,

The following topics will be covered in this document:

This document will be segmented into three parts:

  • Description.
  • Software configuration section.
  • Hardware configuration section.
  • Demonstration.

Description.

The purpose of this project is to copy the information stored from one tag to another by making use of GPIOs to decide which tag to copy from. This way, topics such as read and write NDEF, card activation and GPIOs will be implemented.

 

pastedImage_14.png

Software configuration section:

This demonstration is based on NXP NFC Reader Library v05.02.00, NfcrdlibEx3_NFCForum project for PNEV7462B, in which some modifications are going to be made in order to carry this out. These tags are compliant with NFC Forum Type 2 Tag and ISO/IEC14443 Type A specifications.

 

  •  In phacDiscLoop.h modify the max number of cards supported (two cards for this demonstration):

 

#define PHAC_DISCLOOP_CFG_MAX_CARDS_SUPPORTED 0x02U

 

 

  •  In NfcrdlibEx3_NFCForum.c add the following code in LoadDiscoveryConfiguration():

 

static phStatus_t LoadDiscoveryConfiguration()
{
...
/*Passive max typea devices*/
 status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_DEVICE_LIMIT, 2);
 CHECK_STATUS(status);
}

 

  • A fix to the SW stack has to be made (Fix will be implemented in the next release):

    open "phacDiscLoop_Sw_Int_A.c", line 511, change if statement as below.

     

     

    if((pDataParams->sTypeATargetInfo.bTotalTagsFound > 1) && ((bTypeATagIdx) < pDataParams->sTypeATargetInfo.bTotalTagsFound))

     

  • In NfcrdlibEx3_NFCForum.c add #include "phhalGpio.h" to local headers section.
/* Local headers */
#include <cards.h>
#include "phhalGpio.h"
#include "NfcrdlibEx3_NFCForum.h"‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

  • In NfcrdlibEx3_NFCForum.c define uint16_t NDEFlength = 0 and declare void InitGPIOs(void) in Global Defines section.
/*******************************************************************************
**   Global Defines
*******************************************************************************/
phacDiscLoop_Sw_DataParams_t       * pDiscLoop;       /* Discovery loop component */
void * ppalI18092mPI;
void * ppalI18092mT;
void * palTop;
/* Variables and InitGPIOs() needed for this application */
uint8_t bTagState1;
uint8_t* value;
uint8_t* value1;
uint8_t val,val1;
uint16_t NDEFlength = 0;‍‍‍‍‍‍‍‍‍‍‍‍‍‍
void InitGPIOs(void);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

  • in Main Function, initialize the following:
/*******************************************************************************
**   Main Function
*******************************************************************************/
int main (void)
{

     /* Initialize section */
     value=&val;
     value1=&val1;
     InitGPIOs();‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

  • In case of multiple devices (which is of our interest) add the following code and comment the if(wNumberOfTags > 1){...} section as follows:
else if((status & PH_ERR_MASK) == PHAC_DISCLOOP_MULTI_DEVICES_RESOLVED)
            {
                /*
                 * Multiple cards resolved. It enters here if DEVICE LIMIT > 1 and more than one devices are
                 * detected and resolved.
                 */
                DEBUG_PRINTF (" \n Multiple cards resolved: \n");

                /* Get detected technology type */
                status = phacDiscLoop_GetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TECH_DETECTED, &wTagsDetected);
                CHECK_STATUS(status);

                /* Get number of tags detected */
                status = phacDiscLoop_GetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_NR_TAGS_FOUND, &wNumberOfTags);
                CHECK_STATUS(status);

                DEBUG_PRINTF ("\tNumber of tags: %d \n",wNumberOfTags);


                /* Tag 1 information */


                DEBUG_PRINTF ("\n Tag 1 NDEF information: \n");
                status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x00);

                /* Check for NDEF presence */
                status = phalTop_CheckNdef(palTop, &bTagState1);
                DEBUG_ERROR_PRINT(status);

                status = ReadNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
                DEBUG_ERROR_PRINT(status);

                /* Tag 2 information */

                DEBUG_PRINTF ("\n Tag 2 NDEF information: \n");
                status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x01);

                /* Check for NDEF presence */
                status = phalTop_CheckNdef(palTop, &bTagState1);
                DEBUG_ERROR_PRINT(status);

                status = ReadNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
                DEBUG_ERROR_PRINT(status);


                DEBUG_PRINTF (" \n --------------------------------------------------------------------------------------- \n\n");
                DEBUG_PRINTF (" \n Options: \n\n");
                DEBUG_PRINTF (" \n 1.- Left button  -(X)-( )- To copy NDEF message from Tag 1 to Tag 2 \n\n");
                DEBUG_PRINTF (" \n 2.- Right button -( )-(X)- To copy NDEF message from Tag 2 to Tag 1 \n\n");
                DEBUG_PRINTF (" \n --------------------------------------------------------------------------------------- \n\n");



                /* Reading values from GPIOs 2 and 3 */
                do
                {
                    phhalPcr_GetGpioVal(2,value);
                    phhalPcr_GetGpioVal(3,value1);
                }while(*value==1 && *value1==1);





                /* Copy NDEF content from tag at index 0 to Tag at index 1*/
                if(*value==0 && *value1==1)
                {

                     DEBUG_PRINTF (" \n Copy NDEF from Tag 1 to Tag 2 \n");

                status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x00);

                /* Check for NDEF presence */
                status = phalTop_CheckNdef(palTop, &bTagState1);
                DEBUG_ERROR_PRINT(status);

                status = ReadNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
                DEBUG_ERROR_PRINT(status);

                status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x01);

                /* Check for NDEF presence */
                status = phalTop_CheckNdef(palTop, &bTagState1);
                DEBUG_ERROR_PRINT(status);

                    if(bTagState1 == PHAL_TOP_STATE_READWRITE)
                    {
                    status = WriteNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
                    DEBUG_ERROR_PRINT(status);
                    }
                    DEBUG_PRINTF (" \n NDEF from Tag 1 to Tag 2 already copied \n");

                }
                /* Copy NDEF content from tag at index 1 to Tag at index 0*/
                else if(*value==1 && *value1==0)
                {
                     DEBUG_PRINTF (" \n Copy NDEF from Tag 2 to Tag 1 \n");

                    /* Check for NDEF presence */
                    status = phalTop_CheckNdef(palTop, &bTagState1);

                    status = ReadNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
                    DEBUG_ERROR_PRINT(status);

                    status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x00);

                    /* Check for NDEF presence */
                    status = phalTop_CheckNdef(palTop, &bTagState1);

                        if(bTagState1 == PHAL_TOP_STATE_READWRITE)
                        {
                        status = WriteNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
                        DEBUG_ERROR_PRINT(status);
                        }
                        DEBUG_PRINTF (" \n NDEF from Tag 2 to Tag 1 already copied \n");

                }

                DEBUG_PRINTF (" \n Please remove the tags \n\n");
                DEBUG_PRINTF (" \n Press any button to continue... \n\n");
                
                /* Reading values from GPIOs 2 and 3 */
                do
                {
                    phhalPcr_GetGpioVal(2,value);
                    phhalPcr_GetGpioVal(3,value1);
                }while(*value==1 && *value1==1);




/*                if(wNumberOfTags > 1)
                {
                     Get 1st detected tag and activate device at index 0
                    for(bIndex = 0; bIndex < PHAC_DISCLOOP_PASS_POLL_MAX_TECHS_SUPPORTED; bIndex++)
                    {
                        if(PHAC_DISCLOOP_CHECK_ANDMASK(wTagsDetected, (1 << bIndex)))
                        {
                            DEBUG_PRINTF("\t Activating device @ index 0\n");
                            status = phacDiscLoop_ActivateCard(pDataParams, bIndex, 0);
                            break;
                        }
                    }

                    if( ((status & PH_ERR_MASK) == PHAC_DISCLOOP_DEVICE_ACTIVATED) ||
                            ((status & PH_ERR_MASK) == PHAC_DISCLOOP_PASSIVE_TARGET_ACTIVATED))
                    {
                         Get detected technology type
                        status = phacDiscLoop_GetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TECH_DETECTED, &wTagsDetected);
                        CHECK_STATUS(status);

                        GetTagInfo(pDataParams, 0x01, wTagsDetected);
                        DEBUG_PRINTF("\t\t Activation successful\n");
                    }
                    else
                    {
                        DEBUG_PRINTF("\t\tCard activation failed\n");
                    }
                }*/

                /* Switch to LISTEN mode if supported after POLL mode */
            }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

In NfcrdlibEx3_NFCForum.h declare WriteNdefMessage().

/**
 * Write NDEF message to a detected tag.
 * */
phStatus_t WriteNdefMessage(
    uint8_t TopTagType);      /* [in] Tag type to which write NDEF */‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

In NfcrdlibEx3_NFCForum.c define the function WriteNdefMessage().

/**
* Writes NDEF Message to a tag
*/
phStatus_t WriteNdefMessage(uint8_t TopTagType)
{
    phStatus_t status;
    uint8_t bTagState;
    uint16_t wDataLength = 0;

    /* Configure Top layer for specified tag type */
    status = phalTop_SetConfig(palTop, PHAL_TOP_CONFIG_TAG_TYPE, TopTagType);
    DEBUG_ERROR_PRINT(status);

    /* Check for NDEF presence */
    status = phalTop_CheckNdef(palTop, &bTagState);
    DEBUG_ERROR_PRINT(status);

    if(bTagState == PHAL_TOP_STATE_READWRITE)
    {
        /* Write NDEF message */
        status = phalTop_WriteNdef(palTop, baSnepAppBuffer, NDEFlength);
        DEBUG_ERROR_PRINT(status);

        /* Print NDEF message, if not NULL NDEF */
        if(NDEFlength)
        {
            DEBUG_PRINTF("\tNDEF detected...\n");
            DEBUG_PRINTF("\tNDEF length: %d\n", wDataLength);
            DEBUG_PRINTF("\tNDEF message:\n");
            //DumpBuffer(aData, wDataLength);
            DumpBuffer(baSnepAppBuffer, 50);
        }
        else
        {
            DEBUG_PRINTF("\tNDEF content is NULL...\n");
        }
    }
    else
    {
        DEBUG_PRINTF("\tNo NDEF content detected...\n");
    }

    return status;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

In NfcrdlibEx3_NFCForum.c define InitGPIOs().

void InitGPIOs(void)
{
    phhalPcr_ConfigInput(2,true,false,false,false,true,false);
    phhalPcr_ConfigInput(3,true,false,false,false,true,false);

}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Hardware configuration section:

For the Hardware set up, two push buttons will be connected to GPIO_2 and GPIO_3 of PNEV7462B as follows.

pastedImage_4.png

Vdd will be connected to 3V3 pin on the board:

pastedImage_3.png

GND can be connected to any GND on the board.

Demonstration:

Each tag was previously written with a text NDEF message respectively.

 

Tag 1:

Text: Tag1

Language: en

 

Tag 2:

Text: Tag2

Language: en

 

Writing to a tag can be done by making use of our TagWriter app available in the play store:

NFC TagWriter by NXP - Aplicaciones de Android en Google Play 

  • First both tag's NDEF text messages will be displayed:

pastedImage_9.png

  • Once the information is read, you'll be asked to select an option from the following menu:

pastedImage_10.png

  • If left button (GPIO_2) is pressed, the content from Tag 1 will be written to Tag 2:

pastedImage_11.png

  • Otherwise, If left button (GPIO_3) is pressed, the content from Tag 2 will be written to Tag 1:

pastedImage_12.png

Please find the modified files attached.

I hope this is of great help!

Best regards,

Ivan.

Attachments
No ratings
Version history
Last update:
‎09-10-2020 03:34 AM
Updated by: