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) orInitiator
(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.
-
--technology
{A,B,F}
¶ Poll only for tags of a specific technology. The technologies NFC-A, NFC-B, and NFC-F are defined in the NFC Forum Digital Specification. The technology indicator is case insensitive. The default is to poll for all technologies.
-
-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, likeusb:054c:06c3
would open the first Sony RC-S380 reader andusb:054c
the first Sony reader.usb[:bus[:device]]
with optional bus and device number as three-digit decimal numbers, likeusb:001:023
would specifically mean the usb device with bus number 1 and device id 23 whereasusb: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 modulenfc/dev/<driver>.py
. A typical example would betty: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 portCOM<port>
and load thenfc/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) orInitiator
(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, likeusb:054c:06c3
would open the first Sony RC-S380 reader andusb:054c
the first Sony reader.usb[:bus[:device]]
with optional bus and device number as three-digit decimal numbers, likeusb:001:023
would specifically mean the usb device with bus number 1 and device id 23 whereasusb: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 modulenfc/dev/<driver>.py
. A typical example would betty: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 portCOM<port>
and load thenfc/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.
- Establish communication distance between the Thermometer Peer Agent and the Manager device.
- Connect to the
urn:nfc:sn:phdc
service. - Send a Thermometer Association Request.
- Verify that the Manager sends a Thermometer Association Response.
- Wait 3 seconds not sending any IEEE APDU, then send an Association Release Request.
- Verify that the Manager sends an Association Release Response
- Disconnect from the
urn:nfc:sn:phdc
service. - 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.
- Establish communication distance between the Thermometer Peer Agent and the Manager device.
- Connect to the
urn:nfc:sn:phdc
service. - Send a Thermometer Association Request.
- Verify that the Manager sends a Thermometer Association Response.
- Disconnect from the
urn:nfc:sn:phdc
service. - Connect to the
urn:nfc:sn:phdc
service. - Send a Thermometer Association Request.
- Verify that the Manager sends a Thermometer Association Response.
- Send a Association Release Request.
- Verify that the Manager sends a Association Release Response.
- Disconnect from the
urn:nfc:sn:phdc
service. - 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.
- Establish communication distance between the Validation Agent and the Manager device.
- Connect to the
urn:nfc:xsn:nfc-forum.org:phdc-validation
service. - Send a PHDC PDU with an Information field of 2176 random octets.
- Verify to receive an PHDC PDU that contains the same random octets in reversed order.
- Disconnect from the
urn:nfc:xsn:nfc-forum.org:phdc-validation
service. - 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, likeusb:054c:06c3
would open the first Sony RC-S380 reader andusb:054c
the first Sony reader.usb[:bus[:device]]
with optional bus and device number as three-digit decimal numbers, likeusb:001:023
would specifically mean the usb device with bus number 1 and device id 23 whereasusb: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 modulenfc/dev/<driver>.py
. A typical example would betty: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 portCOM<port>
and load thenfc/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.
- Establish communication distance between the Thermometer Tag Agent and the Manager.
- Send a Thermometer Association Request.
- Verify that the Manager sends a Thermometer Association Response.
- Wait 3 seconds not sending any IEEE APDU, then send an Association Release Request.
- Verify that the Manager sends a Association Release Response.
- 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.
- Establish communication distance between the Thermometer Tag Agent and the Manager.
- Send a Thermometer Association Request.
- Verify that the Manager sends a Thermometer Association Response.
- Send an Association Release Request.
- Verify that the Manager sends a Association Release Response.
- Wait 3 seconds not sending any IEEE APDU, then send a Thermometer Association Request.
- Verify that the Manager sends a Thermometer Association Response.
- 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.
- Establish communication distance between the Tag Agent and the Manager.
- Send the first PHDC PDU with invalid settings in one or any of the MC, LC or MD fields.
- 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.
- Establish communication distance between the Tag Agent and the Manager.
- Send the first PHDC PDU with an invalid value in the RFU field.
- Verify that the Manager continues PHDC communication with the Tag Agent.