This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NFC - communicaiton problem

Dear Nordic,

  • I am using nrf52DK
  • I modified "examples\nfc\writable_ndef_msg"
  • I am using an ingenico POS payment terminal

The working flow is ;

  • pos sends apdu-1,  nrf52dk  receives and  responds
  • pos sends apdu-2,  nrf52dk receives and responds
  • pos sends apdu-3,  nrf52dk receives and responds
  • and transaction flow is finished.

below you can find we respond to pos terminal ;

case NFC_T4T_EVENT_DATA_TRANSMITTED:
NRF_LOG_DEBUG("Data Transmitted!");
break;

default:
bsp_board_led_on(BSP_BOARD_LED_1);
NRF_LOG_DEBUG("Default event!");
NRF_LOG_DEBUG("Data length: %u bytes.", dataLength);
NRF_LOG_HEXDUMP_DEBUG(data, dataLength);

if (memcmp(data, PPSE, 20) == 0) {
uint8_t tmpData[] = { 0x6F, 0x23, 0x84, 0x0E, 0x32, 0x50, 0x41, 0x59, 0x2E, 0x53,
0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31, 0xA5, 0x11,
0xBF, 0x0C, 0x0E, 0x61, 0x0C, 0x4F, 0x07, 0xa0, 0x00, 0x00,
0x06, 0x72, 0x30, 0x10, 0x87, 0x01, 0x01, 0x90, 0x00};
uint8_t tmpDataLen = 39;

nfc_t4t_response_pdu_send(tmpData,tmpDataLen);


} else if (memcmp(data, PPSE, 3) == 0) {
uint8_t tmpData1[] = { 0x6F, 0x4C, 0x84, 0x07, 0xA0, 0x00, 0x00, 0x06, 0x72, 0x30,
0x10, 0xA5, 0x41, 0x50, 0x10, 0x54, 0x52, 0x4F, 0x59, 0x20,
0x42, 0x41, 0x4E, 0x4B, 0x41, 0x20, 0x4B, 0x41, 0x52, 0x54,
0x49, 0x87, 0x01, 0x01, 0x9F, 0x38, 0x16, 0x9F, 0x66, 0x04,
0x9F, 0x02, 0x06, 0x9F, 0x03, 0x06, 0x9F, 0x1A, 0x02, 0x5F,
0x2A, 0x02, 0x9A, 0x03, 0x9C, 0x01, 0x9F, 0x37, 0x04, 0x5F,
0x2D, 0x08, 0x74, 0x72, 0x65, 0x6E, 0x64, 0x65, 0x66, 0x72,
0xBF, 0x0C, 0x05, 0x9F, 0x4D, 0x02, 0x0B, 0x04, 0x90, 0x00};
uint8_t tmpDataLen1 = 80;

nfc_t4t_response_pdu_send(tmpData1,tmpDataLen1);


} else if (memcmp(data, GPO, 3) == 0) {
uint8_t tmpData2[] = { 0x77, 0x5F, 0x82, 0x02, 0x18, 0x00, 0x9F, 0x26, 0x08, 0x0F,
0xED, 0x72, 0xAA, 0x6C, 0xA9, 0x37, 0xA0, 0x9F, 0x36, 0x02,
0x00, 0x01, 0x9F, 0x10, 0x11, 0x01, 0x15, 0x20, 0x10, 0x00,
0x00, 0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x9F, 0x27, 0x01, 0x80, 0x9F, 0x71, 0x02, 0x00,
0x08, 0x57, 0x13, 0x97, 0x92, 0x48, 0x84, 0x34, 0x05, 0x39,
0x22, 0xD2, 0x70, 0x56, 0x26, 0x00, 0x00, 0x07, 0x07, 0x00,
0x00, 0x0F, 0x5F, 0x34, 0x01, 0x01, 0x5F, 0x25, 0x03, 0x18,
0x11, 0x01, 0x9F, 0x07, 0x02, 0xAB, 0x00, 0x5F, 0x28, 0x02,
0x07, 0x92, 0x9F, 0x08, 0x02, 0x00, 0x01, 0x90, 0x00};
uint8_t tmpDataLen2 = 99;

nfc_t4t_response_pdu_send(tmpData2,tmpDataLen2);
}

break;

The non-working flow is (with delays);

  • pos sends apdu-1,   nrf52dk receives apdu-1, 100 ms delay and then responds

in this case pos does not receive the response and sends first apdu-1again and again...

case NFC_T4T_EVENT_DATA_TRANSMITTED:
NRF_LOG_DEBUG("Data Transmitted!");
break;

default:
bsp_board_led_on(BSP_BOARD_LED_1);
NRF_LOG_DEBUG("Default event!");
NRF_LOG_DEBUG("Data length: %u bytes.", dataLength);
NRF_LOG_HEXDUMP_DEBUG(data, dataLength);

if (memcmp(data, PPSE, 20) == 0) {
uint8_t tmpData[] = { 0x6F, 0x23, 0x84, 0x0E, 0x32, 0x50, 0x41, 0x59, 0x2E, 0x53, 
0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31, 0xA5, 0x11, 
0xBF, 0x0C, 0x0E, 0x61, 0x0C, 0x4F, 0x07, 0xa0, 0x00, 0x00, 
0x06, 0x72, 0x30, 0x10, 0x87, 0x01, 0x01, 0x90, 0x00};
uint8_t tmpDataLen = 39;

nfc_t4t_response_pdu_send(tmpData,tmpDataLen);
} else if (memcmp(data, PPSE, 3) == 0) {
uint8_t tmpData1[] = { 0x6F, 0x4C, 0x84, 0x07, 0xA0, 0x00, 0x00, 0x06, 0x72, 0x30,
0x10, 0xA5, 0x41, 0x50, 0x10, 0x54, 0x52, 0x4F, 0x59, 0x20, 
0x42, 0x41, 0x4E, 0x4B, 0x41, 0x20, 0x4B, 0x41, 0x52, 0x54, 
0x49, 0x87, 0x01, 0x01, 0x9F, 0x38, 0x16, 0x9F, 0x66, 0x04, 
0x9F, 0x02, 0x06, 0x9F, 0x03, 0x06, 0x9F, 0x1A, 0x02, 0x5F, 
0x2A, 0x02, 0x9A, 0x03, 0x9C, 0x01, 0x9F, 0x37, 0x04, 0x5F, 
0x2D, 0x08, 0x74, 0x72, 0x65, 0x6E, 0x64, 0x65, 0x66, 0x72, 
0xBF, 0x0C, 0x05, 0x9F, 0x4D, 0x02, 0x0B, 0x04, 0x90, 0x00};
uint8_t tmpDataLen1 = 80;

nfc_t4t_response_pdu_send(tmpData1,tmpDataLen1);
} else if (memcmp(data, GPO, 3) == 0) {
uint8_t tmpData2[] = { 0x77, 0x5F, 0x82, 0x02, 0x18, 0x00, 0x9F, 0x26, 0x08, 0x0F, 
0xED, 0x72, 0xAA, 0x6C, 0xA9, 0x37, 0xA0, 0x9F, 0x36, 0x02, 
0x00, 0x01, 0x9F, 0x10, 0x11, 0x01, 0x15, 0x20, 0x10, 0x00, 
0x00, 0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x9F, 0x27, 0x01, 0x80, 0x9F, 0x71, 0x02, 0x00, 
0x08, 0x57, 0x13, 0x97, 0x92, 0x48, 0x84, 0x34, 0x05, 0x39, 
0x22, 0xD2, 0x70, 0x56, 0x26, 0x00, 0x00, 0x07, 0x07, 0x00, 
0x00, 0x0F, 0x5F, 0x34, 0x01, 0x01, 0x5F, 0x25, 0x03, 0x18, 
0x11, 0x01, 0x9F, 0x07, 0x02, 0xAB, 0x00, 0x5F, 0x28, 0x02, 
0x07, 0x92, 0x9F, 0x08, 0x02, 0x00, 0x01, 0x90, 0x00};
uint8_t tmpDataLen2 = 99;

nfc_t4t_response_pdu_send(tmpData2,tmpDataLen2);
}

break;

I attached the followings ;

  • working log 
  • <debug> app: Field On!
    <debug> app: Default event!
    <debug> app: Data length: 20 bytes.
    <debug> app:  00 A4 04 00 0E 32 50 41|.....2PA
    <debug> app:  59 2E 53 59 53 2E 44 44|Y.SYS.DD
    <debug> app:  46 30 31 00            |F01.
    <debug> app: Data Transmitted!
    <debug> app: Default event!
    <debug> app: Data length: 13 bytes.
    <debug> app:  00 A4 04 00 07 A0 00 00|........
    <debug> app:  06 72 30 10 00         |.r0..
    <debug> app: Data Transmitted!
    <debug> app: Default event!
    <debug> app: Data length: 36 bytes.
    <debug> app:  80 A8 00 00 1E 83 1C 36|.......6
    <debug> app:  00 40 00 00 00 00 00 00|.@......
    <debug> app:  01 00 00 00 00 00 00 07|........
    <debug> app:  92 09 49 19 01 17 00 54|. I....T
    <debug> app:  E6 31 9E 00            |.1..
    <debug> app: Data Transmitted!
    <debug> app: Field Off!
    <debug> app: Field Off!
    
    
    
  • non-working log
  • <debug> app: Default event!
    <debug> app: Data length: 20 bytes.
    <debug> app:  00 A4 04 00 0E 32 50 41|.....2PA
    <debug> app:  59 2E 53 59 53 2E 44 44|Y.SYS.DD
    <debug> app:  46 30 31 00            |F01.
    <debug> app: Data Transmitted!
    <debug> app: Field Off!
    <debug> app: Field Off!
    <debug> app: Field On!
    <debug> app: Default event!
    <debug> app: Data length: 20 bytes.
    <debug> app:  00 A4 04 00 0E 32 50 41|.....2PA
    <debug> app:  59 2E 53 59 53 2E 44 44|Y.SYS.DD
    <debug> app:  46 30 31 00            |F01.
    <debug> app: Data Transmitted!
    <debug> app: Field Off!
    <debug> app: Field Off!
    <debug> app: Field On!
    <debug> app: Default event!
    <debug> app: Data length: 20 bytes.
    <debug> app:  00 A4 04 00 0E 32 50 41|.....2PA
    <debug> app:  59 2E 53 59 53 2E 44 44|Y.SYS.DD
    <debug> app:  46 30 31 00            |F01.
    <debug> app: Data Transmitted!
    <debug> app: Field Off!
    <debug> app: Field Off!
    <debug> app: Field On!
    <debug> app: Default event!
    <debug> app: Data length: 20 bytes.
    <debug> app:  00 A4 04 00 0E 32 50 41|.....2PA
    <debug> app:  59 2E 53 59 53 2E 44 44|Y.SYS.DD
    <debug> app:  46 30 31 00            |F01.
    <debug> app: Data Transmitted!
    <debug> app: Field Off!
    <debug> app: Field Off!
    <debug> app: Field On!
    <debug> app: Default event!
    <debug> app: Data length: 20 bytes.
    <debug> app:  00 A4 04 00 0E 32 50 41|.....2PA
    <debug> app:  59 2E 53 59 53 2E 44 44|Y.SYS.DD
    <debug> app:  46 30 31 00            |F01.
    <debug> app: Data Transmitted!
    <debug> app: Field Off!
    <debug> app: Field Off!
    <debug> app: Field Off!
    <debug> app: Field On!
    <debug> app: Field Off!
    <debug> app: Field On!
    <debug> app: Default event!
    <debug> app: Data length: 20 bytes.
    <debug> app:  00 A4 04 00 0E 32 50 41|.....2PA
    <debug> app:  59 2E 53 59 53 2E 44 44|Y.SYS.DD
    <debug> app:  46 30 31 00            |F01.
    <debug> app: Data Transmitted!
    <debug> app: Field Off!
    <debug> app: Field Off!
    <debug> app: Field Off!
    <debug> app: Field Off!
    <debug> app: Field Off!
    <debug> app: Field Off!
    <debug> app: Field Off!
    
    
  • main.c 
  • /**
     * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    
    /** @file
     *
     * @defgroup nfc_writable_ndef_msg_example_main main.c
     * @{
     * @ingroup nfc_writable_ndef_msg_example
     * @brief The application main file of NFC writable NDEF message example.
     *
     */
    
    #include <stdint.h>
    #include <stdbool.h>
    #include "app_error.h"
    #include "app_scheduler.h"
    #include "boards.h"
    #include "nfc_t4t_lib.h"
    #include "nrf_log_ctrl.h"
    #include "ndef_file_m.h"
    #include "nfc_ndef_msg.h"
    
    #include "nrf_delay.h"
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    #define APP_SCHED_MAX_EVENT_SIZE 0                  /**< Maximum size of scheduler events. */
    #define APP_SCHED_QUEUE_SIZE     4                  /**< Maximum number of events in the scheduler queue. */
    #define APP_DEFAULT_BTN          BSP_BOARD_BUTTON_0 /**< Button used to set default NDEF message. */
    
    static uint8_t m_ndef_msg_buf[NDEF_FILE_SIZE];      /**< Buffer for NDEF file. */
    static uint8_t m_ndef_msg_len;                      /**< Length of the NDEF message. */
    
    
    /**
     * @brief Function for updating NDEF message in the flash file.
     */
    static void scheduler_ndef_file_update(void * p_event_data, uint16_t event_size)
    {
        ret_code_t err_code;
    
        UNUSED_PARAMETER(p_event_data);
        UNUSED_PARAMETER(event_size);
    
        // Update flash file with new NDEF message.
        err_code = ndef_file_update(m_ndef_msg_buf, m_ndef_msg_len + NLEN_FIELD_SIZE);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_INFO("NDEF message updated!");
    }
    
    
    /**
     * @brief Callback function for handling NFC events.
     */
    static void nfc_callback(void          * context,
                             nfc_t4t_event_t event,
                             const uint8_t * data,
                             size_t          dataLength,
                             uint32_t        flags)
    {
        uint8_t PPSE[] = {0x00, 0xA4, 0x04, 0x00, 0x0E, 0x32, 0x50, 0x41, 0x59, 0x2E, 
                          0x53, 0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31, 0x00};
        uint8_t GPO[] = {0x80, 0xA8, 0x00};
    
        (void)context;
    
        switch (event)
        {
            case NFC_T4T_EVENT_FIELD_ON:
                NRF_LOG_DEBUG("Field On!");
                bsp_board_led_on(BSP_BOARD_LED_0);
                break;
    
            case NFC_T4T_EVENT_FIELD_OFF:
                NRF_LOG_DEBUG("Field Off!");
                bsp_board_leds_off();
                break;
    
            case NFC_T4T_EVENT_NDEF_READ:
                NRF_LOG_DEBUG("NDEF Read!");
                bsp_board_led_on(BSP_BOARD_LED_3);
                break;
    
            case NFC_T4T_EVENT_NDEF_UPDATED:
                NRF_LOG_DEBUG("NDef Updated!");
                if (dataLength > 0)
                {
                    ret_code_t err_code;
    
                    bsp_board_led_on(BSP_BOARD_LED_1);
    
                    // Schedule update of NDEF message in the flash file.
                    m_ndef_msg_len = dataLength;
                    err_code       = app_sched_event_put(NULL, 0, scheduler_ndef_file_update);
                    APP_ERROR_CHECK(err_code);
                }
                break;
    
            case NFC_T4T_EVENT_DATA_TRANSMITTED:
                NRF_LOG_DEBUG("Data Transmitted!");
                break;
    
            default:
               bsp_board_led_on(BSP_BOARD_LED_1);
               NRF_LOG_DEBUG("Default event!");
               NRF_LOG_DEBUG("Data length: %u bytes.", dataLength);
               NRF_LOG_HEXDUMP_DEBUG(data, dataLength);
    
               if (memcmp(data, PPSE, 20) == 0) {
                   uint8_t tmpData[] = { 0x6F, 0x23, 0x84, 0x0E, 0x32, 0x50, 0x41, 0x59, 0x2E, 0x53, 
                                         0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31, 0xA5, 0x11, 
                                         0xBF, 0x0C, 0x0E, 0x61, 0x0C, 0x4F, 0x07, 0xa0, 0x00, 0x00, 
                                         0x06, 0x72, 0x30, 0x10, 0x87, 0x01, 0x01, 0x90, 0x00};
                   uint8_t tmpDataLen = 39;
    
                   nrf_delay_ms(100);
    
                   nfc_t4t_response_pdu_send(tmpData,tmpDataLen);
               } else if (memcmp(data, PPSE, 3) == 0) {
                   uint8_t tmpData1[] = { 0x6F, 0x4C, 0x84, 0x07, 0xA0, 0x00, 0x00, 0x06, 0x72, 0x30,
                                          0x10, 0xA5, 0x41, 0x50, 0x10, 0x54, 0x52, 0x4F, 0x59, 0x20, 
                                          0x42, 0x41, 0x4E, 0x4B, 0x41, 0x20, 0x4B, 0x41, 0x52, 0x54, 
                                          0x49, 0x87, 0x01, 0x01, 0x9F, 0x38, 0x16, 0x9F, 0x66, 0x04, 
                                          0x9F, 0x02, 0x06, 0x9F, 0x03, 0x06, 0x9F, 0x1A, 0x02, 0x5F, 
                                          0x2A, 0x02, 0x9A, 0x03, 0x9C, 0x01, 0x9F, 0x37, 0x04, 0x5F, 
                                          0x2D, 0x08, 0x74, 0x72, 0x65, 0x6E, 0x64, 0x65, 0x66, 0x72, 
                                          0xBF, 0x0C, 0x05, 0x9F, 0x4D, 0x02, 0x0B, 0x04, 0x90, 0x00};
                   uint8_t tmpDataLen1 = 80;
    
                   nrf_delay_ms(100);
    
                   nfc_t4t_response_pdu_send(tmpData1,tmpDataLen1);
               } else if (memcmp(data, GPO, 3) == 0) {
                   uint8_t tmpData2[] = { 0x77, 0x5F, 0x82, 0x02, 0x18, 0x00, 0x9F, 0x26, 0x08, 0x0F, 
                                          0xED, 0x72, 0xAA, 0x6C, 0xA9, 0x37, 0xA0, 0x9F, 0x36, 0x02, 
                                          0x00, 0x01, 0x9F, 0x10, 0x11, 0x01, 0x15, 0x20, 0x10, 0x00, 
                                          0x00, 0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
                                          0x00, 0x00, 0x9F, 0x27, 0x01, 0x80, 0x9F, 0x71, 0x02, 0x00, 
                                          0x08, 0x57, 0x13, 0x97, 0x92, 0x48, 0x84, 0x34, 0x05, 0x39, 
                                          0x22, 0xD2, 0x70, 0x56, 0x26, 0x00, 0x00, 0x07, 0x07, 0x00, 
                                          0x00, 0x0F, 0x5F, 0x34, 0x01, 0x01, 0x5F, 0x25, 0x03, 0x18, 
                                          0x11, 0x01, 0x9F, 0x07, 0x02, 0xAB, 0x00, 0x5F, 0x28, 0x02, 
                                          0x07, 0x92, 0x9F, 0x08, 0x02, 0x00, 0x01, 0x90, 0x00};
                   uint8_t tmpDataLen2 = 99;
    
                   nrf_delay_ms(100);
    
                   nfc_t4t_response_pdu_send(tmpData2,tmpDataLen2);
               }
      
               break;
        }
    }
    
    
    /**
     *@brief Function for initializing logging.
     */
    static void log_init(void)
    {
        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    }
    
    
    /**
     * @brief   Function for application main entry.
     */
    int main(void)
     {
        ret_code_t err_code;
    
        log_init();
    
        /* Configure LED-pins as outputs */
        bsp_board_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS);
    
        /* Initialize App Scheduler. */
        APP_SCHED_INIT(APP_SCHED_MAX_EVENT_SIZE, APP_SCHED_QUEUE_SIZE);
    
        /* Set up NFC */
        /* Initialize FDS. */
        //err_code = ndef_file_setup();
        //APP_ERROR_CHECK(err_code);
    
        err_code = nfc_t4t_setup(nfc_callback, NULL);
        APP_ERROR_CHECK(err_code);
    
        /* Start sensing NFC field */
        err_code = nfc_t4t_emulation_start();
        APP_ERROR_CHECK(err_code);
    
        
        while (1)
        {
            NRF_LOG_FLUSH();
            __WFE();
        }
    
    }
    
    
    /** @} */
    

Can you help with this issue please ?

Kind Regards 

Sami

Parents Reply
  • Have you tried shorter delays (10ms, 20ms, ... 90ms) to find the sweet spot where the field fails? I still think there is a timeout occurring for the transaction that cause the peer to turn OFF the field (this is not controlled by the nRF), and thereby you need to have two transaction in your case (the first will need to fail or you may consider send an empty packet for your first transaction). 

    Best regards,
    Kenneth

Children
No Data
Related