Topic: Problem with TLV in Type 2 tags

Hi,

Im Using a SCL3711 usb stick to emulate Forum type 2 tags, and testing with a Nexus S. I've used the emulate_forum_tag2 example for guidance.
The actual emulation is going quite well except when trying to emulate a tag with payload (an Ndef message) that exceeds 0xFF in size.

I read the Forum Tag Type 2 specification, and under the section about TLV, it says the length (L) part should be represented in a 3-byte format when size is between 0x00FF - 0xFFFE, and I have done this according to the specification. the tag I'm trying to emmulate is the following:

0x0, 0x0, 0x0, 0x0,      |
0x0, 0x0, 0x0, 0x0,      | This is the tag type 2 header, and should be fine.
0x0, 0x0, 0xff, 0xff,     |
0xe1, 0x10, 0xff, 0xf    |  I set the size to 2040 so it can fit my message.

0x3, 0xff, 0x1, 0x35,    | The first four bytes here are the TL part of the TLV. 0x03 is Ndef. 0xFF should indicat the next two bytes represent the size 0x135. The value is stored MSB first.
0xc1, 0x1, 0x0, 0x0,    | This is the Ndef header and so on. Seems to be correct, and works for smaller sizes just fine.
0x1, 0x31, 0x54, 0x2,  |
...Ndef message

So what I'm asking is : Have I mesunderstood the TLV part of the type 2 tags? are there any other small details I haven't  got from the type 2 tag specification?

Any help is highly appreciated

Tor

Re: Problem with TLV in Type 2 tags

Hello,

I have no Google Nexus S phone to test your case now, but your modifications seems correct to me.

To be able to help you without the phone, could you post a diff between original and final file and a debug log during example run ?

Romuald Conty

Re: Problem with TLV in Type 2 tags

I just have an idea of problem nature: I think that's around the READ command.
Your block is too large to be readed using only READ command, the SELECT command is needed in case of ByteAddress > BlockNo*4.

Have a look to "5.1.1 READ" chapter in the NFC Forum Tag Type 2 specification.

You will have to implement SELECT command in the example. Please share your result wink

Romuald Conty

Re: Problem with TLV in Type 2 tags

Thanks for answer,

here's what pops out in the terminal:

Connected to NFC device: SCM Micro / SCL3711-NFC&RW - PN533 v2.7 (0x07)
Emulating NDEF tag now, please touch it with a second NFC device
    In: 30  02  
    Out: 00  00  ff  ff  e1  10  ff  0f  03  ff  01  35  c1  01  00  00  
    In: 30  04  
    Out: 03  ff  01  35  c1  01  00  00  01  31  54  02  65  6e  3c  3d  
    In: 30  04  
    Out: 03  ff  01  35  c1  01  00  00  01  31  54  02  65  6e  3c  3d  
    In: 30  04  
    Out: 03  ff  01  35  c1  01  00  00  01  31  54  02  65  6e  3c  3d  
    In: 30  08  
    Out: 3e  3f  40  41  42  43  44  45  46  47  48  49  4a  4b  4c  4d  
    In: 30  0c  
    Out: 4e  4f  50  51  52  53  54  55  56  57  58  59  3c  3d  3e  3f  
    In: 30  10  
    Out: 40  41  42  43  44  45  46  47  48  49  4a  4b  4c  4d  4e  4f  
    In: 30  14  
    Out: 50  51  52  53  54  55  56  57  58  59  3c  3d  3e  3f  40  41  
    In: 30  18  
    Out: 42  43  44  45  46  47  48  49  4a  4b  4c  4d  4e  4f  50  51  
    In: 30  1c  
    Out: 52  53  54  55  56  57  58  59  3c  3d  3e  3f  40  41  42  43  
    In: 30  20  
    Out: 44  45  46  47  48  49  4a  4b  4c  4d  4e  4f  50  51  52  53  
    In: 30  24  
    Out: 54  55  56  57  58  59  3c  3d  3e  3f  40  41  42  43  44  45  
    In: 30  28  
    Out: 46  47  48  49  4a  4b  4c  4d  4e  4f  50  51  52  53  54  55  
    In: 30  2c  
    Out: 56  57  58  59  3c  3d  3e  3f  40  41  42  43  44  45  46  47  
    In: 30  30  
    Out: 48  49  4a  4b  4c  4d  4e  4f  50  51  52  53  54  55  56  57  
    In: 30  34  
    Out: 58  59  3c  3d  3e  3f  40  41  42  43  44  45  46  47  48  49  
    In: 30  38  
    Out: 4a  4b  4c  4d  4e  4f  50  51  52  53  54  55  56  57  58  59  
    In: 30  3c  
    Out: 3c  3d  3e  3f  40  41  42  43  44  45  46  47  48  49  4a  4b  
    In: 30  40  
    Out: 4c  4d  4e  4f  50  51  52  53  54  55  56  57  58  59  3c  3d  
    In: 30  44  
    Out: 3e  3f  40  41  42  43  44  45  46  47  48  49  4a  4b  4c  4d  
    In: 30  48  
    Out: 4e  4f  50  51  52  53  54  55  56  57  58  59  3c  3d  3e  3f  
    In: 30  4c  
    Out: 40  41  42  43  44  45  46  47  48  49  4a  4b  4c  4d  4e  4f  
    In: 30  50  
    Out: 50  51  52  53  54  55  56  57  58  00  00  00  11  00  00  00  
    In: 50  00  

Seems like the Nexus S is issuing only READ commands, but looking into SELECT now
Not sure what you meant with the original and final file. The Nexus S doesn't recognize the message as Ndef at all. It says its 0 bytes i length...

Tor

Last edited by nfcgief (2011-07-21 11:21:35)

Re: Problem with TLV in Type 2 tags

Also, just to add some info.

From the log you see that the Nexus S sends a 0x50 (HALT) command. It always does that... Even if all is fine, and the message is transferred to the handset, I still get this:

In: 50  00  
HALT sent
TagEmulation: ERROR ../tag/emulator.c:68
TagEmulation:     Software caused connection abort (103)

and line 68: 

67    if (res < 0) {
68       ERR ("%s (%d)", strerror (-res), -res);
69      } else {
70        printf ("    Out: ");
71        print_hex (data_out, res);
72      }

This is straight from the example code emulate_forum_tag2.

Is there a known reason for this? I get this even when I run the example.
I'm running r1120 in Ubuntu 11.04 if it helps.

Last edited by nfcgief (2011-07-21 11:49:02)

Re: Problem with TLV in Type 2 tags

nfcgief wrote:

Not sure what you meant with the original and final file.

I mean original file is nfc-emulate-forum-tag2.c from svn trunk and final file is yours (TagEmulation.c ?).

A diff between theses files show diffenrences, that helps to understand what can failed.

Romuald Conty

Re: Problem with TLV in Type 2 tags

When the initatiator send HALT to a tag, that mean the tag should halted (stopped, powerdown). So the emulation should be aborted due to a software abort from initiator.

Maybe the error is not clear, but that's not a bug, that's a feature smile

Romuald Conty

Re: Problem with TLV in Type 2 tags

Sorry, but my code isn't build like the example code. It will make no sence to make a difference between them. But I'll try to show:

I have a Ndef implementation that creates Ndef messages and this works fine.
( ndef.c , ndef.h, ndef_record.c , ndef_record.h )

I also have a tag type 2 implementation that creates a type 2 tag with an ndef message. You told the output looked fine, so this too works ok.
( tag_type2.c , tag_type2.h, tlv.c , tlv.h )

Then I have the emulator, which is a copy paste-ish version nfc-emulate-forum-tag2.c that calls the example code as a function with a byte array as input, the byte array being the tag to be emulated. Much like the static array from the example.
( emulator.cemulator.h ) only real change is to have the data (byte_t array of the tag) as nfc_emulator.user_data...

This is then tested in a test file.
( test.c )

Last edited by nfcgief (2011-07-21 13:04:46)

Re: Problem with TLV in Type 2 tags

nfcgief wrote:

The Nexus S doesn't recognize the message as Ndef at all. It says its 0 bytes i length...

Nexus S seems to read correctly the device according to your needs:
- ff  01  35 in NDEF file means an 309 bytes length NDEF message
- Nexus S send READ command from block 0x4 to block 0x50 so 79 (0x50 - 0x04 + 3) blocks, each block contains 4 bytes: 79 * 4 = 316 bytes readed
So, the Nexus S read all data and nfc-emulate-forum-tag2 do its job.

I think you should double check your NDEF file.

Romuald Conty

Re: Problem with TLV in Type 2 tags

Seems you were right. I had a bug when calculating the Ndef message size. So now I need to implement SECTOR SELECT to get it working for even larger payloads.
Thanks for the help smile

Tor

Re: Problem with TLV in Type 2 tags

Great!
It should be really nice if you could improve directly the code of the example rather than just made your program works wink

So let us know how you progress and feel free to send patches smile

Romuald Conty

Re: Problem with TLV in Type 2 tags

Shouldn't be too much work to make it work, but I think nfc-emulation.c needs to be implemented using nfc_target_send_bits instead of nfc_target_send_bytes to be able to send an ACK response.

I don't have time to look in to it atm, so maybe sometime later. But with that sorted, implementing SECTOR SELECT should be a walk in the park.