Personal Health Device Communication

phdc-test-manager.py

This program implements an NFC device that provides a PHDC manager with the well-known service name urn:nfc:sn:phdc and a non-standard PHDC manager with the experimental service name urn:nfc:xsn:nfc-forum.org:phdc-validation.

Usage

$ phdc-test-manager.py [-h|--help] [OPTION]...

Options

--loop, -l

Repeat the command endlessly, use Control-C to abort.

--mode {t,i}

Restrict the choice of NFC-DEP connection setup role to either Target (only listen) or Initiator (only poll). If this option is not given the dafault is to alternate between both roles with a randomized listen time.

--miu INT

Set a specific value for the LLCP Link MIU. The dafault value is 2175 octets.

--lto INT

Set a specific LLCP Link Timeout value. The default link timeout is 500 milliseconds.

--listen-time INT

Set the time to listen for initialization command from an NFC-DEP Initiator. The default listen time is 250 milliseconds.

--no-aggregation

Disable outbound packet aggregation for LLCP, i.e. do not generate LLCP AGF PDUs if multiple packets are waiting to be send. This is mostly to achieve communication with some older/buggy implementations.

--wait

After reading or writing a tag wait until it is removed before returning. This option is implicit when the option --loop is set. Only relevant for reader/writer mode.

-q

Do not print log messages except for errors and warnings.

-d MODULE

Output debug messages for MODULE to the log facility. Logs are written to <stderr> unless a log file is set with -f. MODULE is a string that corresponds to an nfcpy module or individual file, with dots between path components. For example, -d nfc enables all nfcpy debug logs, -d nfc.tag enables debug logs for all tag types, and -d nfc.tag.tt3 enables debug logs only for type 3 tags. This option may be given multiple times to enable debug logs for several modules.

-f LOGFILE

Write debug log messages to <LOGFILE> instead of <stderr>. Info, warning and error logs will still be printed to <stderr> unless -q is set to supress info messages on <stderr>.

--nolog-symm

When operating in peer mode this option prevents logging of LLCP Symmetry PDUs from the nfc.llcp.llc module. Symmetry PDUs are exchanged regularly and quite frequently over an LLCP Link and are logged by default if debug output is enabled for the llcp module.

--device PATH

Use a specific reader or search only for a subset of readers. The syntax for PATH is:

  • usb[:vendor[:product]] with optional vendor and product as four digit hexadecimal numbers, like usb:054c:06c3 would open the first Sony RC-S380 reader and usb:054c the first Sony reader.
  • usb[:bus[:device]] with optional bus and device number as three-digit decimal numbers, like usb:001:023 would specifically mean the usb device with bus number 1 and device id 23 whereas usb:001 would mean to use the first available reader on bus number 1.
  • tty:port:driver with mandatory port and driver name should be used on Posix systems to open the serial port at device node /dev/tty<port> and load the driver from module nfc/dev/<driver>.py. A typical example would be tty:USB0:arygon for the Arygon APPx/ADRx at /dev/ttyUSB0.
  • com:port:driver with mandatory port and driver name should be used on Windows systems to open the serial port COM<port> and load the nfc/dev/<driver>.py driver module.
  • udp[:host][:port] with optional host name or address and port number will use a fake communication channel over UDP/IP. Either value may be omitted in which case host defaults to ‘localhost’ and port defaults to 54321.

phdc-test-agent.py p2p

Usage

$ phdc-test-agent.py p2p [-h|--help] [OPTION]...

Options

-t N, --test N

Run test number N. May be set more than once.

-T, --test-all

Run all tests.

--loop, -l

Repeat the command endlessly, use Control-C to abort.

--mode {t,i}

Restrict the choice of NFC-DEP connection setup role to either Target (only listen) or Initiator (only poll). If this option is not given the dafault is to alternate between both roles with a randomized listen time.

--miu INT

Set a specific value for the LLCP Link MIU. The dafault value is 2175 octets.

--lto INT

Set a specific LLCP Link Timeout value. The default link timeout is 500 milliseconds.

--listen-time INT

Set the time to listen for initialization command from an NFC-DEP Initiator. The default listen time is 250 milliseconds.

--no-aggregation

Disable outbound packet aggregation for LLCP, i.e. do not generate LLCP AGF PDUs if multiple packets are waiting to be send. This is mostly to achieve communication with some older/buggy implementations.

-q

Do not print log messages except for errors and warnings.

-d MODULE

Output debug messages for MODULE to the log facility. Logs are written to <stderr> unless a log file is set with -f. MODULE is a string that corresponds to an nfcpy module or individual file, with dots between path components. For example, -d nfc enables all nfcpy debug logs, -d nfc.tag enables debug logs for all tag types, and -d nfc.tag.tt3 enables debug logs only for type 3 tags. This option may be given multiple times to enable debug logs for several modules.

-f LOGFILE

Write debug log messages to <LOGFILE> instead of <stderr>. Info, warning and error logs will still be printed to <stderr> unless -q is set to supress info messages on <stderr>.

--nolog-symm

When operating in peer mode this option prevents logging of LLCP Symmetry PDUs from the nfc.llcp.llc module. Symmetry PDUs are exchanged regularly and quite frequently over an LLCP Link and are logged by default if debug output is enabled for the llcp module.

--device PATH

Use a specific reader or search only for a subset of readers. The syntax for PATH is:

  • usb[:vendor[:product]] with optional vendor and product as four digit hexadecimal numbers, like usb:054c:06c3 would open the first Sony RC-S380 reader and usb:054c the first Sony reader.
  • usb[:bus[:device]] with optional bus and device number as three-digit decimal numbers, like usb:001:023 would specifically mean the usb device with bus number 1 and device id 23 whereas usb:001 would mean to use the first available reader on bus number 1.
  • tty:port:driver with mandatory port and driver name should be used on Posix systems to open the serial port at device node /dev/tty<port> and load the driver from module nfc/dev/<driver>.py. A typical example would be tty:USB0:arygon for the Arygon APPx/ADRx at /dev/ttyUSB0.
  • com:port:driver with mandatory port and driver name should be used on Windows systems to open the serial port COM<port> and load the nfc/dev/<driver>.py driver module.
  • udp[:host][:port] with optional host name or address and port number will use a fake communication channel over UDP/IP. Either value may be omitted in which case host defaults to ‘localhost’ and port defaults to 54321.

Test Scenarios

Connect, Associate and Release

$ phdc-test-agent.py p2p -t 1

Verify that the Agent can connect to the PHDC Manager, associate with the IEEE Manager and finally release the association.

  1. Establish communication distance between the Thermometer Peer Agent and the Manager device.
  2. Connect to the urn:nfc:sn:phdc service.
  3. Send a Thermometer Association Request.
  4. Verify that the Manager sends a Thermometer Association Response.
  5. Wait 3 seconds not sending any IEEE APDU, then send an Association Release Request.
  6. Verify that the Manager sends an Association Release Response
  7. Disconnect from the urn:nfc:sn:phdc service.
  8. Move Agent and Manager device out of communication range.

Association after Release

$ phdc-test-agent.py p2p -t 2

Verify that the Agent can again associate with the Manager after a first association has been established and released.

  1. Establish communication distance between the Thermometer Peer Agent and the Manager device.
  2. Connect to the urn:nfc:sn:phdc service.
  3. Send a Thermometer Association Request.
  4. Verify that the Manager sends a Thermometer Association Response.
  5. Disconnect from the urn:nfc:sn:phdc service.
  6. Connect to the urn:nfc:sn:phdc service.
  7. Send a Thermometer Association Request.
  8. Verify that the Manager sends a Thermometer Association Response.
  9. Send a Association Release Request.
  10. Verify that the Manager sends a Association Release Response.
  11. Disconnect from the urn:nfc:sn:phdc service.
  12. Move Agent and Manager device out of communication range.

PHDC PDU Fragmentation and Reassembly

$ phdc-test-agent.py p2p -t 3

Verify that large PHDC PDUs are correctly fragmented and reassembled.

  1. Establish communication distance between the Validation Agent and the Manager device.
  2. Connect to the urn:nfc:xsn:nfc-forum.org:phdc-validation service.
  3. Send a PHDC PDU with an Information field of 2176 random octets.
  4. Verify to receive an PHDC PDU that contains the same random octets in reversed order.
  5. Disconnect from the urn:nfc:xsn:nfc-forum.org:phdc-validation service.
  6. Move Agent and Manager device out of communication range.

phdc-test-agent.py tag

Usage

$ phdc-test-agent.py tag [-h|--help] [OPTION]...

Options

-t N, --test N

Run test number N. May be set more than once.

-T, --test-all

Run all tests.

--loop, -l

Repeat the command endlessly, use Control-C to abort.

-q

Do not print log messages except for errors and warnings.

-d MODULE

Output debug messages for MODULE to the log facility. Logs are written to <stderr> unless a log file is set with -f. MODULE is a string that corresponds to an nfcpy module or individual file, with dots between path components. For example, -d nfc enables all nfcpy debug logs, -d nfc.tag enables debug logs for all tag types, and -d nfc.tag.tt3 enables debug logs only for type 3 tags. This option may be given multiple times to enable debug logs for several modules.

-f LOGFILE

Write debug log messages to <LOGFILE> instead of <stderr>. Info, warning and error logs will still be printed to <stderr> unless -q is set to supress info messages on <stderr>.

--nolog-symm

When operating in peer mode this option prevents logging of LLCP Symmetry PDUs from the nfc.llcp.llc module. Symmetry PDUs are exchanged regularly and quite frequently over an LLCP Link and are logged by default if debug output is enabled for the llcp module.

--device PATH

Use a specific reader or search only for a subset of readers. The syntax for PATH is:

  • usb[:vendor[:product]] with optional vendor and product as four digit hexadecimal numbers, like usb:054c:06c3 would open the first Sony RC-S380 reader and usb:054c the first Sony reader.
  • usb[:bus[:device]] with optional bus and device number as three-digit decimal numbers, like usb:001:023 would specifically mean the usb device with bus number 1 and device id 23 whereas usb:001 would mean to use the first available reader on bus number 1.
  • tty:port:driver with mandatory port and driver name should be used on Posix systems to open the serial port at device node /dev/tty<port> and load the driver from module nfc/dev/<driver>.py. A typical example would be tty:USB0:arygon for the Arygon APPx/ADRx at /dev/ttyUSB0.
  • com:port:driver with mandatory port and driver name should be used on Windows systems to open the serial port COM<port> and load the nfc/dev/<driver>.py driver module.
  • udp[:host][:port] with optional host name or address and port number will use a fake communication channel over UDP/IP. Either value may be omitted in which case host defaults to ‘localhost’ and port defaults to 54321.

Test Scenarios

Discovery, Association and Release

$ phdc-test-agent.py tag -t 1

Verify that a PHDC Tag Agent is discovered by a PHDC Manager and IEEE APDU exchange is successful.

  1. Establish communication distance between the Thermometer Tag Agent and the Manager.
  2. Send a Thermometer Association Request.
  3. Verify that the Manager sends a Thermometer Association Response.
  4. Wait 3 seconds not sending any IEEE APDU, then send an Association Release Request.
  5. Verify that the Manager sends a Association Release Response.
  6. Move Thermometer Tag Agent and Manager out of communication range.

Association after Release

$ phdc-test-agent.py tag -t 2

Verify that a Tag Agent can again associate with the Manager after a first association has been established and released.

  1. Establish communication distance between the Thermometer Tag Agent and the Manager.
  2. Send a Thermometer Association Request.
  3. Verify that the Manager sends a Thermometer Association Response.
  4. Send an Association Release Request.
  5. Verify that the Manager sends a Association Release Response.
  6. Wait 3 seconds not sending any IEEE APDU, then send a Thermometer Association Request.
  7. Verify that the Manager sends a Thermometer Association Response.
  8. Move Thermometer Tag Agent and Manager out of communication range.

Activation with invalid settings

$ phdc-test-agent.py tag -t 3

Verify that a PHDC Manager refuses communication with a Tag Agent that presents an invalid PHDC record payload during activation.

  1. Establish communication distance between the Tag Agent and the Manager.
  2. Send the first PHDC PDU with invalid settings in one or any of the MC, LC or MD fields.
  3. Verify that the Manager stops further PHDC communication with the Tag Agent.

Activation with invalid RFU value

$ phdc-test-agent.py tag -t 4

Verify that a PHDC Manager communicates with a Tag Agent that presents a PHDC record payload with an invalid RFU value during activation.

  1. Establish communication distance between the Tag Agent and the Manager.
  2. Send the first PHDC PDU with an invalid value in the RFU field.
  3. Verify that the Manager continues PHDC communication with the Tag Agent.