linux_libnfc-nci-master - with PN7150 - nativeNfcTag_doFormatTag

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

linux_libnfc-nci-master - with PN7150 - nativeNfcTag_doFormatTag

1,378 Views
dieterrudolph
Contributor I

On my linux system with PN7150

nativeNfcTag_doFormatTag blocks if TAG is removed during format.

here som debug infos.

2020:01:16-10:30:43.112 NxpExtns:   Mifare : phLibNfc_GetKeyNumberMFC Key found
2020:01:16-10:30:43.113 NxpExtns:   Mifare : phLibNfc_GetKeyNumberMFC returning = 0x0 Key = 0x1
2020:01:16-10:30:43.113 NxpFunc:    Nfc: NFA_SendRawFrame () data_len:3
2020:01:16-10:30:43.114 NxpTml:     PN54X - I2C Read successful.....
2020:01:16-10:30:43.114 NxpNciR:     len =   4 > 41030100
2020:01:16-10:30:43.115 NxpTml:     PN54X - Posting read message.....
2020:01:16-10:30:43.115 NxpFunc:    Nfc: NFA got event 0x010C
2020:01:16-10:30:43.116 NxpFunc:    Nfc: nfa_dm_evt_hdlr event: 0xc
2020:01:16-10:30:43.117 NxpFunc:    Nfc: nfa_dm_act_send_raw_frame ()
2020:01:16-10:30:43.117 NxpHal:     read successful status = 0x0
2020:01:16-10:30:43.118 NxpFunc:    NfcAdaptation::HalDeviceContextDataCallback: len=4
2020:01:16-10:30:43.118 NxpFunc:    Nfc: Process Event mt:2
2020:01:16-10:30:43.119 NxpFunc:    Nfc: NFC received rsp gid:1
2020:01:16-10:30:43.119 NxpFunc:    Nfc: returning from nfa_dm_p2p_prio_logic  Disable p2p_prio_logic
2020:01:16-10:30:43.120 NxpFunc:    Nfc: nfa_dm_disc_discovery_cback (): event:0x4000
2020:01:16-10:30:43.120 NxpFunc:    Nfc: nfa_dm_disc_sm_execute(): state: 0, event:1 disc_flags: 0x21
2020:01:16-10:30:43.121 NxpFunc:    Nfc: nfa_dm_disc_new_state(): old_state: 0, new_state: 1 disc_flags: 0x1
2020:01:16-10:30:43.122 NxpFunc:    Nfc: nfa_dm_disc_sm_execute(): new state: 1,  disc_flags: 0x1
2020:01:16-10:30:43.122 NxpTml:     PN54X - Read requested.....
2020:01:16-10:30:43.122 NxpTml:     PN54X - Invoking I2C Read.....
2020:01:16-10:30:43.123 NxpFunc:    nativeNfcTag_doFormatTag:2nd try wait for completion        

what can i do ?

0 Kudos
5 Replies

1,127 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Dieter,

I hope you are doing great.

Could you please provide more information about the steps that you are following?

Are you writing some NDEF information? Are you erasing the complete tag

Regards,

Mario

0 Kudos

1,127 Views
dieterrudolph
Contributor I

Hi Mario,

thanks for your reply,

I hav a function for erasing a a tag.

the erase function hangs in the function nfcTag_formatTag.

Point 1 o.k.

Point 2 never reached if tag is removed at this time.

The callback function "onTagDeparture" is not called.

error_code ecEraseNFC( void)
{
    error_code ec = 0;
    int iRet ;
    ndef_info_t stNDEFinfo;

    do
    {
        iRet = nfcTag_isFormatable( g_tagInfos.handle);                if(!iRet) { ec =EC_NFC_NOT_FORMATABLE;    break; }

// Point 1
        iRet = nfcTag_formatTag( g_tagInfos.handle);                     if( iRet) { ec =EC_NFC_FORMAT;            break; }
// Point 2

        iRet = nfcTag_isNdef( g_tagInfos.handle, &stNDEFinfo);    if(!iRet) { ec =EC_NFC_NO_NDEF;            break; }
    }while(0); // only once ...

    return ec;
}

Initialization is done by...

.....

    pv_onAppArrival = onAppArrival;
    pv_onAppDepature = onAppDepature;

...

    {
        int iRet;
        iRet = nfcManager_doInitialize();
        if (iRet)
            return EC_NFC_IN_USE;

        g_TagCB.onTagArrival = onTagArrival;
        g_TagCB.onTagDeparture = onTagDeparture;
        nfcManager_registerTagCallback(&g_TagCB);
        nfcManager_enableDiscovery(DEFAULT_NFA_TECH_MASK, 0x01, 0, 0);
    }

Regards

Dieter

0 Kudos

1,127 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Dieter,

As my understanding all this process is working if you do not remove the tag, right?

I have a function for erasing a tag.the erase function hangs in the function nfcTag_formatTag.

Did you create this function for erasing the tag? The library has a specific time to read/write, in this case. But I am not sure if you modify something in your code if you try to read out some tag, and you remove from the PN7150, the host sends an error and keep running.

Regards,

Mario

0 Kudos

1,127 Views
dieterrudolph
Contributor I

Hi Mario,

you are right.

Yes, I created the erase function using the nfcTag_formatTag function of the linux_libnfc-nct-master library.

Reading never had a problem.

Src/services/linux_nfc_api.c

int nfcTag_formatTag(unsigned int handle)

{

int ret;

ret = nativeNfcTag_doFormatTag(handle);

return ret;

}

Src/services/interface/nativelNfcTag.cpp

I think there is a problem with the „gSyncMutex“

…..

INT32 nativeNfcTag_doFormatTag(UINT32 tagHandle)

{

NXPLOG_API_D ("%s: enter", __FUNCTION__);

tNFA_STATUS status = NFA_STATUS_FAILED;

UINT32 handle = sCurrentConnectedHandle;

#if(NFC_NXP_NOT_OPEN_INCLUDED == TRUE)

isMifare = FALSE;

#endif

gSyncMutex.lock();

if (!nativeNfcManager_isNfcActive())

{

NXPLOG_API_E ("%s: Nfc not initialized.", __FUNCTION__);

goto End;

}

if (tagHandle != sCurrentConnectedHandle)

{

NXPLOG_API_E ("%s: Wrong tag handle!\n)", __FUNCTION__);

goto End;

}

// Do not try to format if tag is already deactivated.

if (NfcTag::getInstance ().isActivated () == FALSE)

{

NXPLOG_API_D ("%s: tag already deactivated(no need to format)", __FUNCTION__);

goto End;

}

sem_init (&sFormatSem, 0, 0);

sFormatOk = FALSE;

if (NfcTag::getInstance ().mTechLibNfcTypes[handle] == NFA_PROTOCOL_MIFARE)

{

status = nativeNfcTag_doReconnect ();

#if(NFC_NXP_NOT_OPEN_INCLUDED == TRUE)

isMifare = TRUE;

NXPLOG_API_D("Format with First Key");

status = EXTNS_MfcFormatTag(key1,sizeof(key1));

#endif

}

else

{

status = NFA_RwFormatTag ();

}

if (status == NFA_STATUS_OK)

{

NXPLOG_API_D ("%s: wait for completion", __FUNCTION__);

sem_wait (&sFormatSem);

status = sFormatOk ? NFA_STATUS_OK : NFA_STATUS_FAILED;

#if(NFC_NXP_NOT_OPEN_INCLUDED == TRUE)

if(sFormatOk == TRUE && isMifare == TRUE)

{

NXPLOG_API_D ("Format with First Key Success");

}

#endif

}

else

{

NXPLOG_API_E ("%s: error status=%u", __FUNCTION__, status);

}

sem_destroy (&sFormatSem);

#if(NFC_NXP_NOT_OPEN_INCLUDED == TRUE)

if(isMifare == TRUE && sFormatOk != TRUE)

{

NXPLOG_API_D ("Format with First Key Failed");

sem_init (&sFormatSem, 0, 0);

status = nativeNfcTag_doReconnect ();

NXPLOG_API_D ("Format with Second Key");

status = EXTNS_MfcFormatTag(key2,sizeof(key2));

if (status == NFA_STATUS_OK)

{

NXPLOG_API_D ("%s:2nd try wait for completion", __FUNCTION__);

sem_wait (&sFormatSem);

status = sFormatOk ? NFA_STATUS_OK : NFA_STATUS_FAILED;

}

else

{

NXPLOG_API_E ("%s: error status=%u", __FUNCTION__, status);

}

sem_destroy (&sFormatSem);

if(sFormatOk)

{

NXPLOG_API_D ("Format with Second Key Success");

}

else

{

NXPLOG_API_D ("Format with Second Key Failed");

}

}

#endif

if (NfcTag::getInstance ().mTechLibNfcTypes[handle] == NFA_PROTOCOL_ISO_DEP)

{

nativeNfcTag_doReconnect ();

}

End:

gSyncMutex.unlock();

NXPLOG_API_D ("%s: exit", __FUNCTION__);

return sFormatOk ? NFA_STATUS_OK : NFA_STATUS_FAILED;

}

Regards

Dieter

Von: mario_castaneda <admin@community.nxp.com>

Gesendet: Mittwoch, 29. Januar 2020 19:55

An: Dieter Rudolph <Dieter.Rudolph@truetzschler.de>

Betreff: Re: - Re: linux_libnfc-nci-master - with PN7150 - nativeNfcTag_doFormatTag

NXP Community <https://community.freescale.com/resources/statics/1000/35400-NXP-Community-Email-banner-600x75.jpg>

Re: linux_libnfc-nci-master - with PN7150 - nativeNfcTag_doFormatTag

reply from Mario Ignacio Castaneda Lopez<https://community.nxp.com/people/mario_castaneda?et=watches.email.thread> in NFC - View the full discussion<https://community.nxp.com/message/1261673?commentID=1261673&et=watches.email.thread#comment-1261673>

0 Kudos

1,127 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Dieter,

I was checking your code. I am not sure if you are still facing issues with the tag, however, you could implement a thread that will be polling if the tag is still present or not.

Regards,

Mario

0 Kudos