In related to my question above, the code I tried to implement after terminating the field as given below. I can get phhalHw_Autocoll() to return success but I get 0x020A for phhalHw_Pn5190_Instr_ExchangeRFData().
phhalHw_Pn5190_Autocoll() is also updated with the below.
phhalHw_Pn5190_Instr_SwitchModeAutocoll(pDataParams,bRfTechnology,PHHAL_HW_PN5190_AUTOCOLL_MODE_AUTONOMOUS_WITH_STANDBY))
int card_emulator_main_cutdown(void)
{
do
{
int ret;
phStatus_t status;
pHal_Hce = phNfcLib_GetDataParams(PH_COMP_HAL);
TRACE0("NfcLib data params pointers set successfully");
/* ================================================================= */
/* STEP 3: STAGE EMULATION PROFILE AND LOAD URL PAYLOAD */
/* ================================================================= */
TRACE0("Configuring hardware target layers and loading URL buffer...");
/* Configure target mode HAL parameters */
status = phAppHce_HALConfigAutoColl();
CHECK_STATUS(status);
if (status != PH_ERR_SUCCESS) {
TRACE1("phhalHw_TargetInit failed: 0x%04X", status);
return status;
}
/* ================================================================= */
/* STEP 4: ENGAGE AUTOCOLL (Autonomous Listening State) */
/* ================================================================= */
TRACE0("Entering sub-100ms Autonomous Listen mode...");
// CRITICAL FIX: Allocate valid storage memory to prevent PH_ASSERT_NULL crashes
uint8_t * pRxBufferPtr = NULL;
uint16_t wRxLengthData = 0;
uint16_t wProtocolParams = 0;
// Execute the function mapping strictly to your HAL's parameter footprint.
// We pass 'A_MODE' to tell the switch code to select Passive NFC-A Technology.
status = phhalHw_Autocoll(
pHal_Hce,
A_MODE, // Bitmask flag forcing NFC-A technology profiling
&pRxBufferPtr, // Passed as a valid pointer reference to a pointer
&wRxLengthData, // Passed as a valid pointer reference to length
&wProtocolParams // Passed as a valid pointer reference to parameters
);
if ((status & PH_ERR_MASK) == PH_ERR_SUCCESS) {
TRACE0(" Tap-to-URL switch executed perfectly! Phone hit the antenna field.");
TRACE1("De-wrapped Activation Protocol Parameters: 0x%04X", wProtocolParams);
/* ================================================================= */
/* STEP 5: PROCESS INCOMING APDU COMMANDS FROM THE PHONE */
/* ================================================================= */
TRACE0("Listening for phone file system read commands...");
// Allocate data exchange buffers
uint8_t * pDataIn = NULL;
uint16_t wDataInLen = 0;
// Retrieve the initial data packet the phone transmitted right upon activation
// Your Autocoll snippet already stores the address in pRxBufferPtr / wRxLengthData
pDataIn = pRxBufferPtr;
wDataInLen = wRxLengthData;
// Enter a rapid loop to process the phone's Read commands
// The phone will send "Select NDEF Application" -> "Select NDEF File" -> "Read Binary"
//while (1)
{
//Use the correct Target Emulation transmit function to bypass the 0x0225 check
//PH_RECEIVE_RF_ENABLE_EVT_STATUS enables event tracking for the transfer
status = phhalHw_Pn5190_Instr_ExchangeRFData(
pHal_Hce,
PH_EXCHANGE_DEFAULT, // wOption
0, // bTxLastBits (0 indicates complete 8-bit byte layout)
0x05, // bRespControl: Bitmask 0x04 (Event Status) | 0x01 (Rx Status)
aNdefFile, // Your URL array structure
23, // Size of your URL data payload
&pRxBufferPtr, // Address of your response data pointer
&wRxLengthData // Address of your incoming length tracker
);
if (status == PH_ERR_SUCCESS) {
TRACE0(" Single-shot URL packet injected successfully. Task complete!");
} else {
TRACE1("Injection status / timeout: 0x%04X (Phone likely disconnected cleanly)", status);
}
}
} else {
TRACE1("Autocoll exited, timed out, or dropped with status: 0x%04X", status);
}
} while(0);
return 0;
}
// /* Mandatory NDEF file. It's set using phceT4T_SetElementaryFile. */
uint8_t aNdefFile[] = {
/* --- MANDATORY CONTACTLESS TRANSPORT HEADER --- */
//0x02, // 1. PCB Byte: Configures this frame as a Part 4 I-Block (Block Number 0)
0x00, 0x13, // 1. T4T Container Length Indicator (19 bytes total payload)
0xD1, // 2. NDEF Record Header (MB=1, ME=1, SR=1, TNF=0x01 Well-Known Type)
0x01, // 3. Type Length (1 byte long name)
0x0F, // 4. Payload Length (15 bytes for prefix + string)
0x55, // 5. Record Type: 'U' (0x55 for URI record)
0x02, // 6. URI Identifier Prefix: Code 0x02 maps to "https://www."
// 7. URI Payload String of 14bytes
0xww, 0xww, 0xww, 0xww, 0xww, 0xww, 0xww, 0xww, 0xww, 0xww, 0xww, 0xww, 0xww, 0xww,
/* --- MANDATORY SMART CARD STATUS TRAILER --- */
0x90, 0x00 // 21-22. APDU Success Status (tells Android the data read is complete)
};
Log output:
06-16 17:34:31.600 26047 27687 E nfc : [card_emulator_main_cutdown] NfcLib data params pointers set successfully
06-16 17:34:31.600 26047 27687 E nfc : [card_emulator_main_cutdown] Configuring hardware target layers and loading URL buffer...
06-16 17:34:31.605 26047 27687 E nfc : [card_emulator_main_cutdown] Entering sub-100ms Autonomous Listen mode...
06-16 17:34:31.607 26047 27999 V nfc : [socket_send_thread] Entered socketSend
06-16 17:34:31.607 26047 27999 V nfc :
06-16 17:34:32.456 26047 27687 E nfc : [card_emulator_main_cutdown] Tap-to-URL switch executed perfectly! Phone hit the antenna field.
06-16 17:34:32.456 26047 27687 W nfc : [card_emulator_main_cutdown] De-wrapped Activation Protocol Parameters: 0x0100
06-16 17:34:32.456 26047 27687 E nfc : [card_emulator_main_cutdown] Listening for phone file system read commands...
06-16 17:34:32.456 26047 27687 W nfc : [card_emulator_main_cutdown] Injection status / timeout: 0x020A (Phone likely disconnected cleanly)