Monday, March 10, 2025

NDEF Commands


So, as far as I can see, almost completely separate from ATRs and APDUs is another standard for NFC called NDEF, and this is what Android seems to think of when you mention NFC. Having said that, now I am more familiar with the alphabet soup of NFC operations, I can see that in the section on Host Card Emulation it talks about ISO 7816 and "APDUs".

My instinct has been - and remains - that what I really want to do is to use NDEFs, and that means that I still need to figure out how to get my card reader to issue NDEF requests. Interestingly, Appendix A of the ACR 1552U reference guide which is on the very last page gives a sample "NDEF Message". Apart from being largely context-free, not to mention confusing by seeming to have two NDEF messages wrapped inside each other, it suggests that my reader does know something about NDEF.

Searching through the document for NDEF turns up Section 6.1.13.10 (I kid you not) which has the following to say for itself:

6.1.13.10. Example Command Set of Emulating NFC Forum Type 2 Tag Mode

The command set is to trigger ACS website https://www.acs.com.hk by using ACR1552U to emulate as the NFC forum type 2 tag mode. The steps are showed below:

1. Enter the card emulation mode with below command:

Send Enter Card Emulation Mode

E0 00 00 40 03 02 00 00

2. Write the NDEF data with below command:

Send Write Card Emulation Data (NFC Forum Type 2 Tag)

E0 00 00 60 1C 01 02 00 18 E1 10 F4 00 03 0F D1 01 0B 55 02 61 63 73 2E 63 6F 6D 2E 68 6B FE 00 00

Notes:

For more detailed information and specifications related to the NDEF (NFC Data Exchange Format), I would recommend referring to the NDEF specification. It provides comprehensive guidelines and details about the structure and usage of NDEF records, which are commonly used in NFC data exchange. The NDEF specification will provide a deeper understanding of how to interpret and utilize the NDEF command and data in the context of the ACR1552U device.

Now, I don't know about you, but I am bored with copying and pasting all these command strings and not being able to run programs in VSCode. I have noticed that the "usage" for apdu has an argument -script which takes a script file. I'm not quite sure how this works, but looking at the code, it would seem that if the script is provided it reads it line by line as if the commands were typed on the console:
        if script == "" {
                return runInteractive(card)
        }
        return runScript(card, script)
where runScript does the following:
        scanner := bufio.NewScanner(file)
        for scanner.Scan() {
                fmt.Println("")
                err := processCommand(card, scanner.Text(), true)
                if err != nil {
                        fmt.Printf("error: %s\n", err)
                        continue
                }
        }
So, I created a new directory scripts and then put the following in the file scripts/launchWeb.apdu:
E0 00 00 40 03 02 00 00
E0 00 00 60 1C 01 02 00 18 E1 10 F4 00 03 0F D1 01 0B 55 02 61 63 73 2E 63 6F 6D 2E 68 6B FE 00 00
And then I can update my launch.json:
>> E0 00 00 40 03 020000
<< 6E00


>> E0 00 00 60 1C 01020018E110F400030FD1010B55026163732E636F6D2E686BFE0000
<< 6E00
Oh, well. 6E00 means "class not supported". Not that I'm sure what that actually means in this context. It seems bizarre that it would complain when I believe the first command is just to ask the reader to go into emulation mode and that is what the documentation for my reader says should be supported.

On the other hand, it's possible that this is coming indirectly from the phone. Let's try it with another card and see what happens:
>> E0 00 00 40 03 020000
<< 6A81


>> E0 00 00 60 1C 01020018E110F400030FD1010B55026163732E636F6D2E686BFE0000
<< 6A81
So, indeed, with my phone I have "class not supported" but with the room key I get "function not supported". So it must be making a round trip. So the next thing would be to understand what is meant by "class not supported". But I'm not really sure I'm getting anywhere here.

Conclusion

Although it would seem that the reader "supports" NDEF in some sense, it feels like a blind alley. Instead of continually to flail around with the reader, I think the time has come to flail around with the phone.

No comments:

Post a Comment