PN7462: Mifare operation in phExCcid example

cancel
Showing results for 
Search instead for 
Did you mean: 

PN7462: Mifare operation in phExCcid example

57 Views
jayyehtw
Contributor III

In the function phExCcid_Handle_USB_Process, the code would check the card status with the 
phExCcid_Check_Presence_L3A_Card function, which would hat the card and then activate the card.

And before any Mifare operations, like read, write, autheication, the same checking mechanism would be executed.

Therefore card would be frequently being halted and activated over and over again during the operations.

I would like to cancel this mechanism, so I naively comment the phExCcid_Check_Presence_L3A_Card function and the latter authentication code as the following code segment.

But after this modification, all the Mifare operations like read, write, authentication all failed.

Could someone suggest how to make the modification?

static void phExCcid_Handle_USB_Process(phacDiscLoop_Sw_DataParams_t *psDiscLoopParams)
{
    uint8_t *pp;
    uint16_t wOutLen;

    static phStatus_t status = PH_ERR_FAILED;

    volatile uint32_t dwBits = 0;
    uint32_t dwEventTimeOut = 0xF;

    uint8_t bErrorAPDU[2] = { 0x6A, 0x81 };
    uint16_t wOptions = 0;
    /** Send the Card Inserted Information to the host. */
    phExCcid_UsbCcid_CardInserted();

    while (true)
    {
		/*
		.
		.
		.
		*/

        if ((gphExCcid_sUsb_SlotInfo.bCLSlotType == PH_EXCCID_USBCCID_CL_TYPE_B) ||
            (gphExCcid_sUsb_SlotInfo.bCLSlotType == PH_EXCCID_USBCCID_CL_TYPE_A_L4))
        {
            /* Check for the Card Presence and Exit the loop if not presence is detected */
            status = phExCcid_Check_Presence_L4_Card(psDiscLoopParams);
            if (status != PH_ERR_SUCCESS)
            {
                gphExCcid_sUsb_SlotInfo.bAtrValid = 0;
                phpalI14443p4_ResetProtocol(psDiscLoopParams->pPal14443p4DataParams);
                phExCcid_UsbCcid_CardRemoved();
                break;
            }
        }
        else if ((gphExCcid_sUsb_SlotInfo.bCLSlotType == PH_EXCCID_USBCCID_CL_MIFARECLASSIC))
        {
            // status = phExCcid_Check_Presence_L3A_Card(psDiscLoopParams, 0);
            /* Check for the Card Presence and Exit the loop if not presence is detected */
            //if ((status != PH_ERR_SUCCESS) && (status != PH_ERR_INTEGRITY_ERROR))
            //{
            //    gphExCcid_sUsb_SlotInfo.bAtrValid = 0;
            //    phExCcid_UsbCcid_CardRemoved();
            //    break;
            //}
        }
		/*
		.	
		.
		.
		*/

        /** Wait for the Events for the CL Cards. */
        dwBits = phRtos_EventGroupWaitBits(gphExCcid_sUsb_EventInfo.xCL_Events,
                                           PH_EXCCID_USBCCID_CL_TRNSP_EX_CMD |
                                           PH_EXCCID_USBCCID_CL_DEACTIVATE_CARD_CMD |
                                           PH_EXCCID_USBCCID_CL_AUTH_CMD |
                                           PH_EXCCID_USBCCID_CL_READ_CARD_CMD |
                                           PH_EXCCID_USBCCID_CL_WRITE_CARD_CMD |
										   PH_EXCCID_USBCCID_CL_HALT_CMD |
										   PH_EXCCID_USBCCID_CL_DESELECT_CMD |
										   PH_EXCCID_USBCCID_CL_MIFARE_CMD,
                                           true, /* status bits should be cleared before returning. */
                                           false, /* wait for any status bit being set. */
                                           dwEventTimeOut); /* wait until the time expires. */
		/*
		.	
		.
		.
		*/

       /** Authentication Command Events. */
       if (dwBits & (uint32_t) PH_EXCCID_USBCCID_CL_AUTH_CMD)
       {
    	   LOG_TXT("CL_AUTH\n");
            if ((gphExCcid_sUsb_SlotInfo.bCLSlotType == PH_EXCCID_USBCCID_CL_MIFARECLASSIC))
            {
            	/* Put the Card in the known state */
            	//if (PH_ERR_SUCCESS != phExCcid_Check_Presence_L3A_Card(psDiscLoopParams, 1))
				//{
				//	/** Authentication Failure. */
				//	phExCcid_UsbCcid_PCSC_Send_APDU(0x6A, 0x82, 0);
				//	return;
				//}
            	/** Perform the Authentication in the Mifare Classic Card. */
                status = phExCcid_Mifare_Do_Auth(PH_EXCCID_MIFARE_AUTHENTICATE_LC);

                if (status == PH_ERR_SUCCESS)
                {
                    /** Send the Success Status on Successful Authentication. */
                    gphExCcid_sUsb_MifareInfo.bAuth = 1;
                    phExCcid_UsbCcid_PCSC_Send_APDU(0x90, 0x00, 0);
                }
                else
                {
                    /** Send the Failure Status on Authentication failure. */
                    gphExCcid_sUsb_MifareInfo.bAuth = 0;
                    phExCcid_UsbCcid_PCSC_Send_APDU(0x69, 0x82, 0);
                }
            }
       } /* - PH_EXCCID_USBCCID_CL_AUTH_CMD */
	          /** Card Read Command Events. */
       if (dwBits & (uint32_t) PH_EXCCID_USBCCID_CL_READ_CARD_CMD)
       {
    	   LOG_TXT("CL_READ\n");
            /** Check for the CL type as Mifare Classic. */
            if (gphExCcid_sUsb_SlotInfo.bCLSlotType == PH_EXCCID_USBCCID_CL_MIFARECLASSIC)
            {
            	/* Put the Card in the known state */
            	//if (PH_ERR_SUCCESS != phExCcid_Check_Presence_L3A_Card(psDiscLoopParams, 0))
                //{
                //	/** Authentication Failure. */
                //	phExCcid_UsbCcid_PCSC_Send_APDU(0x6A, 0x82, 0);
                //	return;
                //}
            	///** Check for the Authentication. */
                //if (PH_ERR_SUCCESS != phExCcid_Mifare_Do_Auth(PH_EXCCID_MIFARE_AUTHENTICATE_P2))
                //{
                //   /** Authentication Failure. */
                //    phExCcid_UsbCcid_PCSC_Send_APDU(0x69, 0x82, 0);
                //    return;
                //}

                /** Perform the Read Operation on the Mifare Classic Card. */
                phExCcid_Mifare_Read_Operations();
            }
            else if (gphExCcid_sUsb_SlotInfo.bCLSlotType == PH_EXCCID_USBCCID_CL_MIFAREULTRALIGHT)
            {
                /** Perform the Read Operation on the Mifare Ultralight Card. */
                phExCcid_Mifare_Read_Operations();
            }
       } /* - PH_EXCCID_USBCCID_CL_READ_CARD_CMD */
		/*
		.	
		.
		.
		*/
    } /* - While */
}

 

Labels (2)
Tags (2)
0 Kudos
1 Reply

34 Views
Ricardo_Zamora
NXP TechSupport
NXP TechSupport

Hi,

 

Hope you are doing well. The phExCcid_Check_Presence_L3A_Card function also Activates the card, so you cannot omit this part, to be able to read/write. In this example, the Activation is only present in this function.

 

Best Regards,

Ricardo

0 Kudos