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 emulator app (located at src/com/android/nfc/emulatorapp/) is meant to 48handle APDU transactions between the PN 532 reader and the Android emulator in 49cases where the replayed transaction involves a third party app that the 50emulator does not access to. To guarantee that the emulator app is able to 51handle the transaction, all AIDs sent in the original transaction will be 52replaced with AIDs that the app is registered to handle (the specific values 53are located in @xml/aids). To use the app in conjunction with the replay tool, 54enter the following commands. 55 561\. To prepare a snoop log to be replayed with the app: 57 58``` 59python3 nfcreplay.py -f $SNOOP_FILE --parse_only 60``` 61 62The script will produce the name of the parsed log, which will be located within 63the folder emulatorapp/parsed_files. Save the name for Step 3. 64 652\. Build and install the emulator app. The following commands are specific to 66the Pixel 6 Pro (Raven). Non-Raven devices should substitute "raven" for the 67appropriate value. 68 69``` 70mma emulatorapp 71adb install -r -g ~/aosp-main-with-phones/out/target/product/raven/system/app/emulatorapp/emulatorapp.apk 72 73``` 74 753\. Start the activity. Make sure that $PARSED_SNOOP_FILE is the name of the 76file, rather than its path. It is assumed that this file is located within 77emulatorapp/parsed_files, where it was originally created. 78 79``` 80adb shell am start -n com.android.nfc.emulatorapp/.MainActivity --es "snoop_file" "$PARSED_SNOOP_FILE" 81``` 82 83When you are ready to start the transaction, press the "Start Host APDU Service" 84button. 85 864\. To replay the transaction with the PN532 module, follow the steps above to 87generate and replay a test case, though you should make sure to append the flag 88`--replay_with_app` to the end of each command. 89 90When the transaction is replayed, you should be able to see a list of APDU 91commands and responses received and sent by the Host APDU service displayed on 92the emulator app. Additionally, the replay script will output similar 93information. 94 95### Creating a Snoop Log 96 97To create a snoop log from your Android device, you should first go to Developer 98Options in Settings to make sure that "NFC NCI unfiltered log" is enabled. This 99will ensure that the data packets sent during NFC transactions are not truncated 100in the snoop log. 101 102After the NFC transaction is complete, enter the command `adb shell dumpsys 103nfc`. This will output the snoop log, which will begin with the line `--- 104BEGIN:NFCSNOOP_VS_LOG_SUMMARY` and end with the line `--- 105END:NFCSNOOP_VS_LOG_SUMMARY ---`. Copy the snoop log into a text file, and make 106sure to include both the start and end lines.