NDEFTOOL

Create, modify or print NFC Data Exchange Format Records.

Synopsis

ndeftool [OPTIONS] COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...

Description

The ndeftool provides a number of commands to create, modify or print NDEF records. Commands can be chained together to successively extend or modify the list of records that are generated. Except for save and print, all records forwarded by the last command are send to standard output as binary NDEF message data. The save and print commands implicitly consume all records unless the --keep option is set. They also, unlike all other commands, do not start an empty record list but read from standard input when given as the first command (the same behavior can be achieved for the load command by setting the file path to -).

By default, NDEF records read from disk or standard input must be correctly formatted NDEF message data (for example, the first and the last record must have the message begin and end flag set). The --relax makes the decoder accept correctable data errors and the --ignore option will additionally skip records with uncorrectable errors.

Options

--version

Show the version and exit.

--relax

Ignore some errors when decoding.

--ignore

Ignore all errors when decoding.

--silent

Suppress all progress information.

--debug

Output debug progress information.

--help

Show this message and exit.

Examples

Any NDEF Record can be constructed with the payload, typename and identifier commands.

$ ndeftool payload '\02ensample text' typename 'urn:nfc:wkt:T' id 'r1' print
NDEF Text Record ID 'r1' Text 'sample text' Language 'en' Encoding 'UTF-8'

The same record can be created with the text command. Here the output goes to stdout and is then printed with a separate ndeftool process call.

$ ndeftool text 'sample text' id 'r1' | ndeftool print
Reading data from standard input
NDEF Text Record ID 'r1' Text 'sample text' Language 'en' Encoding 'UTF-8'

The save command writes the records to disk or <stdout> for path name -. The following example creates an NDEF message with three NFC Forum Text Records, the first and last record with the message begin and message end flags set.

$ ndeftool text ONE text TWO text THREE save - | hd
/bin/sh: 1: hd: not found
Saving 3 records to <stdout>.

The save command can be used to write intermediate results, here immediately after a text record has been created. Note that by writing to <stdout> the result is a sequence of three individual NDEF messages of one record each. This would not be a proper NDEF message file.

$ ndeftool text ONE save - text TWO save - text THREE save - | hd
/bin/sh: 1: hd: not found
Saving 1 record to <stdout>.
Saving 1 record to <stdout>.
Saving 1 record to <stdout>.

The load command reads records from disk or <stdin> for path name -.

$ ndeftool text ONE text TWO text THREE | ndeftool load - print
loaded 3 record(s) from <stdin>
NDEF Text Record ID '' Text 'ONE' Language 'en' Encoding 'UTF-8'
NDEF Text Record ID '' Text 'TWO' Language 'en' Encoding 'UTF-8'
NDEF Text Record ID '' Text 'THREE' Language 'en' Encoding 'UTF-8'

An empty NDEF Record can be created with an empty type name string. The first octet 11010000b sets the Message Begin (MB) and Message End (ME) flags in the two most signifant bits. The Type Name Format (TNF) value 0 in the least significant three bits indicates that there is no type or payload associated with this record and thus the TYPE LENGTH and PAYLOAD LENGTH fields must be zero.

$ ndeftool typename '' | hd
/bin/sh: 1: hd: not found

The default decoding of an NDEF message requires correct data format. Data with minor format errors can be decoded with the --relax option. The following example creates two empty records with invalid MB and ME flags that do only decode with --relax.

$ python3 -c "import sys; sys.stdout.buffer.write(b'\x10\0\0\x10\0\0')" | ndeftool --relax print
Reading data from standard input
NDEF Record TYPE '' ID '' PAYLOAD 0 byte
NDEF Record TYPE '' ID '' PAYLOAD 0 byte

NDEF message data with uncorrectable errors can be skipped with the --ignore option. The payload length 1 in the second record is an invalid value for an empty record.

$ python3 -c "import sys; sys.stdout.buffer.write(b'\x10\0\0\x10\1\0')" | ndeftool --ignore print
Reading data from standard input
NDEF Record TYPE '' ID '' PAYLOAD 0 byte