• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1### NFC Replay Utility
2
3The NFC Replay tool allows a PN 532 module to reenact a NFC transaction from a
4snoop log. Currently, the tool is capable of replaying polling loop transactions
5and APDU exchanges. Once the transaction has been replayed, a test can
6optionally be generated based on the interaction between the module and
7emulator.
8
9The detailed design for this feature can be found at go/nfc-replay-utility-dd.
10
11### Using the tool
12
13#### Generating and replaying a test
14
151\. Obtain a snoop log from the device (see instructions below for how to do this).
16
172\. Connect the PN532 module via a serial port.
18
193\. To replay the transaction, substitute the name of the snoop file and the
20serial port that the PN 532 module is using.
21
22```
23python3 nfcreplay.py -f $SNOOP_FILE -p $READER_PATH
24```
25
26Alternatively, to replay a specific section of the snoop log, additional
27arguments should be added to denote the desired start and end time frame of the
28transaction. For instance:
29
30```
31python3 nfcreplay.py -f $SNOOP_FILE -p $READER_PATH --start "2024-07-17 12:00:00" --end "2024-07-17 15:00:00"
32```
33
34Information about the transaction will be printed out to console, including a
35list of all polling loop and APDU exchanges that took place.
36
375\. To generate and run a test from the snoop log, use the command:
38```
39python3 nfcreplay.py -f $SNOOP_FILE -p $READER_PATH --generate_and_replay_test
40```
41
42A Python file will be created, representing the test, along with a JSON file
43that contains all information pertaining to APDUs transacted.
44
45#### Using the Emulator App
46
47The generated test will always involve the installation of the emulator app
48(located at src/com/android/nfc/emulatorapp/) onto the emulator. The app handles
49APDU transactions in cases where the replayed transaction involves a third party
50app that the emulator does not access to. To guarantee that the emulator app is
51able to handle the transaction, all AIDs sent in the original transaction will
52be replaced with AIDs that the app is registered to handle (the specific values
53are located in @xml/aids).
54
55When the transaction is replayed, you should be able to see a list of APDU
56commands and responses received and sent by the Host APDU service displayed on
57the emulator app.
58
59To use the emulator app outside of a generated test, perform the following steps:
60
611\. To prepare a snoop log to be replayed with the app:
62
63```
64python3 nfcreplay.py -f $SNOOP_FILE --parse_only
65```
66
67The script will produce the name of the parsed log, which will be located within
68the folder emulatorapp/parsed_files. Save the name for Step 3.
69
702\. Build and install the emulator app. The following commands are specific to
71the Pixel 6 Pro (Raven). Non-Raven devices should substitute "raven" for the
72appropriate value.
73
74```
75mma NfcEmulatorApduAppNonTest
76adb install -r -g ~/aosp-main-with-phones/out/target/product/raven/system/app/emulatorapp/NfcEmulatorApduAppNonTest.apk
77
78```
79
803\. Start the activity. Make sure that $PARSED_SNOOP_FILE is the name of the
81file, rather than its path. It is assumed that this file is located within
82emulatorapp/parsed_files, where it was originally created.
83
84```
85adb shell am start -n com.android.nfc.emulatorapp/.MainActivity --es "snoop_file" "$PARSED_SNOOP_FILE"
86```
87
88When you are ready to start the transaction, press the "Start Host APDU Service"
89button.
90
914\. To replay the transaction with the PN532 module, follow the steps above to
92generate and replay a test case, though you should make sure to append the flag
93`--replay_with_app` to the end of each command.
94
95When the transaction is replayed, you should be able to see a list of APDU
96commands and responses received and sent by the Host APDU service displayed on
97the emulator app. Additionally, the replay script will output similar
98information.
99
100### Creating a Snoop Log
101
102To create a snoop log from your Android device, you should first go to Developer
103Options in Settings to make sure that "NFC NCI unfiltered log" is enabled. This
104will ensure that the data packets sent during NFC transactions are not truncated
105in the snoop log.
106
107After the NFC transaction is complete, enter the command `adb shell dumpsys
108nfc`. This will output the snoop log, which will begin with the line `---
109BEGIN:NFCSNOOP_VS_LOG_SUMMARY` and end with the line `---
110END:NFCSNOOP_VS_LOG_SUMMARY ---`. Copy the snoop log into a text file, and make
111sure to include both the start and end lines.