How to run into function tnep_svc_one_selected()?

As the title, in the project "ncs\v3.2.1\nrf\samples\nfc\tnep_tag", how to runt into  function tnep_svc_one_selected()?

I use the NFC tools, Send the hex data, want to select the servive, what hex data must be send? Is there a complete example or debugging method?

Parents
  • Hi

    I'm sorry, but I don't understand what you mean here I'm afraid. Are you using a phone, Android or similar running an NFC debugger app of sorts or a dedicated NFC debugger device? I think the NFC TNEP polling device. 

    Is the issue here that you are not able to switch back to the svc_one service with a button press? If so, I think that is because the sample only lets you switch from 1 to 2 and not back with the same button press, so you need to change this in the source code.

    Or is the issue that you aren't able to change/poll the service from the phone? If so, I think you should look at how the TNEP poller sample does this and implement something like that on the NFC tools on your end.

    Best regards,

    Simon

  • It's like this: I plan to use TNEP for data exchange. What I imagine is being able to use tool software, like NFC TOOL, similar to a serial port debugging assistant, to send and receive hexadecimal data for manual debugging.

  • Hello,

    Sorry for the late reply. Simon is currently out of office, so I will look into your ticket. 

    So the question is "how to run the tnep_svc_one_selected()"? 

    Do you see tnep_svc_two_selected() being called?

    Currently, the button_pressed() callback is being used to set the svc_two_rec, and enabling it using nfc_ndef_msg_record_add() and nfc_tnep_tag_tx_msg_app_data(). So if you see the record being switched to svc_two_rec, then this is working. Try adding something like this:

    static void button_pressed(uint32_t button_state, uint32_t has_changed)
    {
    	int err;
    	uint32_t button = button_state & has_changed;
    	const char svc_two_msg[] = "Service e  = 2.71828182845904523536";
    
    	if (button & DK_BTN1_MSK) {
    		NFC_TNEP_TAG_APP_MSG_DEF(app_msg, 1);
    		NFC_NDEF_TEXT_RECORD_DESC_DEF(svc_two_rec, UTF_8, en_code,
    					      sizeof(en_code), svc_two_msg,
    					      strlen(svc_two_msg));
    
    		err = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(app_msg),
    					      &NFC_NDEF_TEXT_RECORD_DESC(svc_two_rec));
    
    		err = nfc_tnep_tag_tx_msg_app_data(&NFC_NDEF_MSG(app_msg),
    						   NFC_TNEP_STATUS_SUCCESS);
    		if (err == -EACCES) {
    			printk("Service is not in selected state. App data cannot be set\n");
    		} else {
    			printk("Service app data set err: %d\n", err);
    		}
    	}
    	else if (button & DK_BTN2_MSK) {
    	    NFC_TNEP_TAG_APP_MSG_DEF(app_msg, 1);
    		NFC_NDEF_TEXT_RECORD_DESC_DEF(svc_one_rec, UTF_8, en_code,
    					      sizeof(en_code), svc_one_msg,
    					      strlen(svc_one_msg));
    
    		err = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(app_msg),
    					      &NFC_NDEF_TEXT_RECORD_DESC(svc_one_rec));
    
    		err = nfc_tnep_tag_tx_msg_app_data(&NFC_NDEF_MSG(app_msg),
    						   NFC_TNEP_STATUS_SUCCESS);
    		if (err == -EACCES) {
    			printk("Service is not in selected state. App data cannot be set\n");
    		} else {
    			printk("Service app data set err: %d\n", err);
    		}
    	}
    }

    Best regards,

    Edvin

Reply
  • Hello,

    Sorry for the late reply. Simon is currently out of office, so I will look into your ticket. 

    So the question is "how to run the tnep_svc_one_selected()"? 

    Do you see tnep_svc_two_selected() being called?

    Currently, the button_pressed() callback is being used to set the svc_two_rec, and enabling it using nfc_ndef_msg_record_add() and nfc_tnep_tag_tx_msg_app_data(). So if you see the record being switched to svc_two_rec, then this is working. Try adding something like this:

    static void button_pressed(uint32_t button_state, uint32_t has_changed)
    {
    	int err;
    	uint32_t button = button_state & has_changed;
    	const char svc_two_msg[] = "Service e  = 2.71828182845904523536";
    
    	if (button & DK_BTN1_MSK) {
    		NFC_TNEP_TAG_APP_MSG_DEF(app_msg, 1);
    		NFC_NDEF_TEXT_RECORD_DESC_DEF(svc_two_rec, UTF_8, en_code,
    					      sizeof(en_code), svc_two_msg,
    					      strlen(svc_two_msg));
    
    		err = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(app_msg),
    					      &NFC_NDEF_TEXT_RECORD_DESC(svc_two_rec));
    
    		err = nfc_tnep_tag_tx_msg_app_data(&NFC_NDEF_MSG(app_msg),
    						   NFC_TNEP_STATUS_SUCCESS);
    		if (err == -EACCES) {
    			printk("Service is not in selected state. App data cannot be set\n");
    		} else {
    			printk("Service app data set err: %d\n", err);
    		}
    	}
    	else if (button & DK_BTN2_MSK) {
    	    NFC_TNEP_TAG_APP_MSG_DEF(app_msg, 1);
    		NFC_NDEF_TEXT_RECORD_DESC_DEF(svc_one_rec, UTF_8, en_code,
    					      sizeof(en_code), svc_one_msg,
    					      strlen(svc_one_msg));
    
    		err = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(app_msg),
    					      &NFC_NDEF_TEXT_RECORD_DESC(svc_one_rec));
    
    		err = nfc_tnep_tag_tx_msg_app_data(&NFC_NDEF_MSG(app_msg),
    						   NFC_TNEP_STATUS_SUCCESS);
    		if (err == -EACCES) {
    			printk("Service is not in selected state. App data cannot be set\n");
    		} else {
    			printk("Service app data set err: %d\n", err);
    		}
    	}
    }

    Best regards,

    Edvin

Children
  • What I'm thinking now is if there is a simple way to implement TNEP interaction, allowing data transmission and reception to be as easy as using a serial port. Right now, I'm using the NFC TOOL mobile app for debugging. This app supports NFCA and ISODEP and does not allow manual command sending. When the code executes tnep_svc_one_selected(), there is no tnep_svc_two_selected() in the code because I only used one service. You don't need two sets of services for data transmission and reception, right? The demo program is meant to demonstrate service switching, correct? I just need to implement TNEP data transmission and reception.

  • Is there a bug in t4t? I send 00D600000411223344, program jump to case

    NFC_T4T_EVENT_NDEF_UPDATED,

    the lenth is 4386 ,the  hex 1122 ,dec is 4386. the lenth is not 4?

    the lenth in callback, is 4386

        err = nfc_t4t_setup(nfc_callback, NULL);
        if (err) {
            LOG_ERR("NFC T4T setup err: %d", err);
            return;
        }
    static void nfc_callback(void *context, nfc_t4t_event_t event,
                 const uint8_t *data, size_t data_length, uint32_t flags)

  • Hello,

    It could possibly be a bug. I believe this means "write to file, offset 0x0000, length 0x04, data 0x11223344", if I am not mistaken. But it is also dependent that you have already told the receiver what file it is up front. Did you?

    Regarding NFC Tools and this TNEP feature, I am not sure (ChatGPT says that it does not, and it is a fairly new protocol). The sample is tailored to work together with the sample tnep_poller, which can run on another DK, with an NFC Reader connected to it (usually an SPI/I2C device, such as "NFC Reader ST25R3911B Nucleo expansion board (X-NUCLEO-NFC05A1)")

    Best regards,

    Edvin

  • So, give me a solution. I just want to tap my phone on the NFC antenna, and then I can continuously exchange data, with the higher application layer working like a serial port.

  • I am sorry, but I don't know how to do that. You need to figure out whether the reason it is not working for the NFC Tools app is because it is a restriction in the OS, or if it is just a lacking feature in the NFC Tools application. If it is the last one, then you may need to write your own NFC application for the phone. I don't have any experience with phone app development, unfortunately. 

    If TNEP is not supported in the Android OS, then I am afraid you need to find another way of transporting the data, like BLE, USB or some other communication protocol. 

    I know it is probably not the answer you are hoping for, but it seems like this is not possible.

    Best regards,

    Edvin

Related